Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix show() method to reshape a copy #328

Closed
kescobo opened this issue Oct 22, 2018 · 6 comments
Closed

Fix show() method to reshape a copy #328

kescobo opened this issue Oct 22, 2018 · 6 comments

Comments

@kescobo
Copy link
Contributor

kescobo commented Oct 22, 2018

Per discussion in Slack with @pfitzseb in #juno-bridged on slack, there's an issue with the show() method that causes weird errors in Juno. He suggested that this line should instead be:

show(io, MIME"image/svg+xml"(), reshape(copy(cs), (1, length(cs))))
@timholy
Copy link
Member

timholy commented Oct 23, 2018

Won't change this without clearer justification: what's the error on Juno and why can't it be fixed within Juno?

@pfitzseb
Copy link

This isn't a Juno specific issue:

λ j1 --quiet
julia> using Colors, ColorBrewer

julia> colors = ColorBrewer.palette("Set1", 9);

julia> show(stdout, MIME"image/svg+xml"(), colors)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
     width="180.0mm" height="25.0mm"
     shape-rendering="crispEdges">
<rect x="0.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#E41A1C" stroke="none" />
<rect x="20.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#377EB8" stroke="none" />
<rect x="40.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#4DAF4A" stroke="none" />
<rect x="60.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#984EA3" stroke="none" />
<rect x="80.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#FF7F00" stroke="none" />
<rect x="100.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#FFFF33" stroke="none" />
<rect x="120.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#A65628" stroke="none" />
<rect x="140.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#F781BF" stroke="none" />
<rect x="160.0mm" y="0.0mm"
      width="19.0mm" height="24.0mm"
      fill="#999999" stroke="none" />
</svg>6

julia> append!(colors, [colorant"white"])
ERROR: cannot resize array with shared data
Stacktrace:
 [1] _growend! at ./array.jl:814 [inlined]
 [2] append!(::Array{RGB{FixedPointNumbers.Normed{UInt8,8}},1}, ::Array{RGB{FixedPointNumbers.Normed{UInt8,8}},1}) at ./array.jl:897
 [3] top-level scope at none:0

@timholy
Copy link
Member

timholy commented Oct 23, 2018

I'd suggest transpose instead, since it doesn't prevent growth:

julia> a = [1,2]
2-element Array{Int64,1}:
 1
 2

julia> b = transpose(a)
1×2 LinearAlgebra.Transpose{Int64,Array{Int64,1}}:
 1  2

julia> push!(a, 3)
3-element Array{Int64,1}:
 1
 2
 3

Though I guess colors don't support transpose, so make that Base.ReshapedArray(colors, (1, length(colors)), ()).

PR welcome.

@kescobo
Copy link
Contributor Author

kescobo commented Oct 23, 2018

@timholy sorry for the terseness and thanks @pfitzseb for jumping in. TBH I wasn't really sure what was going on, but wanted to plant the flag after discussing it on slack, since @pfitzseb said he couldn't get to it right away.

@timholy
Copy link
Member

timholy commented Oct 23, 2018

Want to try a pull request? The answer is right above you, just needs someone to push it over the finish line.

@kescobo
Copy link
Contributor Author

kescobo commented Oct 23, 2018

Sure! ☝️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants