GithubHelp home page GithubHelp logo

Comments (7)

odow avatar odow commented on July 1, 2024 1

text/latex has a special check for Symmetric. We don't have the check in text/plain. But that's also because we defer the printing to Base.show, so I'm not sure this is easy to fix.

JuMP.jl/src/print.jl

Lines 884 to 919 in 56b186f

function function_string(
::MIME"text/plain",
A::AbstractMatrix{<:AbstractJuMPScalar},
)
str = sprint() do io
return show(IOContext(io, :limit => true), MIME("text/plain"), A)
end
lines = split(str, '\n')
# We drop the first line with the signature "m×n Array{...}:"
popfirst!(lines)
# We replace the first space by an opening `[`
lines[1] = '[' * lines[1][2:end]
return join(lines, "\n") * "]"
end
function function_string(
mode::MIME"text/latex",
A::AbstractMatrix{<:AbstractJuMPScalar},
)
str = "\\begin{bmatrix}\n"
for i in axes(A, 1)
line = ""
for j in axes(A, 2)
if j != 1
line *= " & "
end
if A isa LinearAlgebra.Symmetric && i > j
line *= "\\cdot"
else
line *= function_string(mode, A[i, j])
end
end
str *= line * "\\\\\n"
end
return str * "\\end{bmatrix}"
end

In the REPL, Julia prints the full symmetric matrix:

julia> using LinearAlgebra

julia> Symmetric([1 2; 2 3])
2×2 Symmetric{Int64, Matrix{Int64}}:
 1  2
 2  3

from jump.jl.

LebedevRI avatar LebedevRI commented on July 1, 2024

In the REPL, Julia prints the full symmetric matrix:

Right, i just saw that too. I thought it didn't, but apparently it does.

from jump.jl.

odow avatar odow commented on July 1, 2024

Arguably someone might interpret out current text/latex printing as the upper triangular, with zeros in the lower.

Here's what UpperTriangular prints.

julia> UpperTriangular([1 2; 2 3])
2×2 UpperTriangular{Int64, Matrix{Int64}}:
 1  2
   3

I don't even know if the current text/latex approach is a good idea.

from jump.jl.

LebedevRI avatar LebedevRI commented on July 1, 2024

IMHO, the text/latex approach is generally the right way to do it. Perhaps a different symbol should be used?

from jump.jl.

odow avatar odow commented on July 1, 2024

Thoughts @blegat? I would err on the side of sticking to Base.

from jump.jl.

odow avatar odow commented on July 1, 2024

See #3768

from jump.jl.

LebedevRI avatar LebedevRI commented on July 1, 2024

@odow thank you!

from jump.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.