Using ToeplitzMatrices

using ToeplitzMatrices
Hankel([1.,2.,3.], 3:5)

Hankel([1,2,3], 3:5)

The first example work, but the second fails with this message:
ERROR: LoadError: TypeError: in new, expected Toeplitz{Int64,S} where S<:Number, got a value of type Toeplitz{Float32,Complex{Float32}}
Stacktrace:
[1] _Hankel at C:\Users\bupandit.julia\packages\ToeplitzMatrices\JiFWS\src\ToeplitzMatrices.jl:667 [inlined]
[2] Hankel{Int64}(::Array{Int64,1}, ::UnitRange{Int64}) at C:\Users\bupandit.julia\packages\ToeplitzMatrices\JiFWS\src\ToeplitzMatrices.jl:677
[3] Hankel(::Array{Int64,1}, ::UnitRange{Int64}) at C:\Users\bupandit.julia\packages\ToeplitzMatrices\JiFWS\src\ToeplitzMatrices.jl:680
[4] top-level scope at C:\Projects\PHYBUDGET\pam4_j\hankel_example.jl:4
[5] include(::String) at .\client.jl:457
[6] top-level scope at REPL[113]:1
in expression starting at C:\Projects\PHYBUDGET\pam4_j\hankel_example.jl:4

It looks like a bug in ToeplitzMatrices.jl, at least this conversion looks suspicious

julia> convert(Toeplitz{Int}, Toeplitz{Int}([3, 4, 5], [3, 2, 1]))
3×3 Toeplitz{Float32, ComplexF32}:
 3.0  2.0  1.0
 4.0  3.0  2.0
 5.0  4.0  3.0

I think it makes sense to open an issue in ToeplitzMatrices.jl repository.

If you can allow yourself type piracy, you can override current behaviour with

import ToeplitzMatrices

ToeplitzMatrices.Toeplitz(vc::AbstractVector, vr::AbstractVector) = Toeplitz{promote_type(eltype(vc), eltype(vr))}(vc, vr)
1 Like