0

I can do the following fine before my last update to Julia 1.8.5. Now I get an error message. I can concatenate normal (randomly generated) matrices OK.

julia> using ToeplitzMatrices

julia> B1 = Toeplitz([1, 2, 4], [1, 3, 5])
3×3 Toeplitz{Int64, Vector{Int64}, Vector{Int64}}:
 1  3  5
 2  1  3
 4  2  1

julia> B2 = B1 .+ 3
3×3 Matrix{Int64}:
 4  6  8
 5  4  6
 7  5  4

julia> hcat(B1, B2)
ERROR: CanonicalIndexError: setindex! not defined for Toeplitz{Int64, Vector{Int64}, Vector{Int64}}
Stacktrace:
  [1] error_if_canonical_setindex(::IndexCartesian, ::Toeplitz{Int64, Vector{Int64}, Vector{Int64}}, ::Int64, ::Int64)
    @ Base ./abstractarray.jl:1354
  [2] setindex!
    @ ./abstractarray.jl:1343 [inlined]
  [3] macro expansion
    @ ./multidimensional.jl:946 [inlined]
  [4] macro expansion
    @ ./cartesian.jl:64 [inlined]
  [5] _unsafe_setindex!(::IndexCartesian, ::Toeplitz{Int64, Vector{Int64}, Vector{Int64}}, ::Toeplitz{Int64, Vector{Int64}, Vector{Int64}}, ::Base.Slice{Base.OneTo{Int64}}, ::UnitRange{Int64})
    @ Base ./multidimensional.jl:941
  [6] _setindex!
    @ ./multidimensional.jl:930 [inlined]
  [7] setindex!
    @ ./abstractarray.jl:1344 [inlined]
  [8] _typed_hcat(#unused#::Type{Int64}, A::Tuple{Toeplitz{Int64, Vector{Int64}, Vector{Int64}}, Matrix{Int64}})
    @ Base ./abstractarray.jl:1618
  [9] typed_hcat
    @ ./abstractarray.jl:1586 [inlined]
 [10] hcat(::Toeplitz{Int64, Vector{Int64}, Vector{Int64}}, ::Matrix{Int64})
    @ Base ./abstractarray.jl:1589
 [11] top-level scope
    @ REPL[4]:1

I expect the output to be

1 3 5 11 13 15 2 1 3 12 11 13 4 2 1 14 12 11

TD TL
  • 3
  • 2
  • It works on 1.8.5 on my machine (with the specified output as a 3x6 matrix) – Dan Getz Apr 04 '23 at 17:04
  • Thank you for the reply. Could it be my setup then? Is there anyone running the Julia version that comes with the Linux Manjaro distribution (which I last updated a few days ago). I use the REPL inside Code-OSS (also from the distribution). – TD TL Apr 04 '23 at 17:29
  • OS provided Julias are very often broken – Oscar Smith Apr 04 '23 at 18:31
  • You should use the official downloads (and use Juliaup if you want easy updating) – Oscar Smith Apr 04 '23 at 18:31
  • I get the same error with a separate Julia installation from the official downloads. – TD TL Apr 05 '23 at 01:39
  • The code snippet in the OP is edited (obviously, since the Julia prompt is missing, yet the exception message appears). This edit has removed the actual cause of the error. Please update the question, even if the answer is obvious considering the original code (and start with a fresh Julia session). – Dan Getz Apr 05 '23 at 14:27
  • I see the same error as the OP when I try with both 1.8.5 and 1.9.0-rc2, so I think it's real. It makes sense that it's real, given how `hcat` behaves for array types `T` that do not satisfy `isa(T, Array)`. – PaSTE Apr 05 '23 at 15:01

1 Answers1

1

Okay sorry @PaSTE and @TDTL for doubting the existence of the error. The reason for it is in ToeplitzMatrices version 0.8.0 (I had 0.7.1 installed).

Specifically, the addition of a specialized definition for similar(...) for Toeplitz matrices is breaking this, as the resulting matrix isn't actually a Toeplitz matrix (while the new similar definition returns a Toeplitz matrix).

Solutions:

  1. revert to 0.7.1 (by add ToeplitzMatrices@0.7.1 in pkg prompt and restart), or
  2. use hcat(collect(B1), B2)

An issue about this glitch should be noted for the developer of the package. Not sure what the correct fix is, as it might be nice to have compatible Toeplits matrices hcated well, or to use similar to create a new Toeplitz matrix.

Dan Getz
  • 17,002
  • 2
  • 23
  • 41