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

Symbolic (symmetric-toepltiz)matrix-vector multiplication doesn't work for higher dimensions of matrix #109

Open
yewalenikhil65 opened this issue Jul 28, 2023 · 4 comments

Comments

@yewalenikhil65
Copy link

yewalenikhil65 commented Jul 28, 2023

I am trying following , and this works okay! I am raising this issue both on Symbolics and ToeplitzMatrices

using Symbolics, ToeplitzMatrices

N =250

a = Symbolics.variables(:a, 0:N);

b= [1; (1:N).*a[2:end]]

A  = SymmetricToeplitz(a)
F_expr = A*b;

However, the code fails if i increase the code to N=280, even with FFTW

using Symbolics, ToeplitzMatrices,FFTW

N =280

a = Symbolics.variables(:a, 0:N);

b= [1; (1:N).*a[2:end]]

A  = SymmetricToeplitz(a)
F_expr = A*b;


ERROR: MethodError: no method matching plan_fft!(::Vector{Complex{Num}}, ::UnitRange{Int64})

Closest candidates are:
  plan_fft!(::StridedArray{T, N}, ::Any; flags, timelimit, num_threads) where {T<:Union{ComplexF64, ComplexF32}, N}
   @ FFTW ~/.julia/packages/FFTW/HfEjB/src/fft.jl:786
  plan_fft!(::AbstractArray; kws...)
   @ AbstractFFTs ~/.julia/packages/AbstractFFTs/hJ0Fz/src/definitions.jl:65

Stacktrace:
 [1] plan_fft!(x::Vector{Complex{Num}}; kws::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ AbstractFFTs ~/.julia/packages/AbstractFFTs/hJ0Fz/src/definitions.jl:65
 [2] plan_fft!(x::Vector{Complex{Num}})
   @ AbstractFFTs ~/.julia/packages/AbstractFFTs/hJ0Fz/src/definitions.jl:65
 [3] factorize(A::SymmetricToeplitz{Num, Vector{Num}})
   @ ToeplitzMatrices ~/.julia/packages/ToeplitzMatrices/5gW1c/src/linearalgebra.jl:150
 [4] mul!(y::Vector{Num}, A::SymmetricToeplitz{Num, Vector{Num}}, x::Vector{Num}, α::Bool, β::Bool)
   @ ToeplitzMatrices ~/.julia/packages/ToeplitzMatrices/5gW1c/src/linearalgebra.jl:37
 [5] mul!
   @ ~/software/julia-1.9.2/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:276 [inlined]
 [6] *(A::SymmetricToeplitz{Num, Vector{Num}}, x::Vector{Num})
   @ LinearAlgebra ~/software/julia-1.9.2/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:56
 [7] top-level scope
   @ REPL[36]:1

@nsajko
Copy link

nsajko commented Jul 30, 2023

This seems to be the culprit:

# Small case: don't use FFT
N = m + n - 1
if N < 512
# Scale/initialize y
if iszero(β)
fill!(y, 0)
else
rmul!(y, β)
end
@inbounds for j in 1:n
tmp = α * x[j]
for i in 1:m
y[i] = muladd(tmp, A[i,j], y[i])
end
end
else
# Large case: use FFT
mul!(y, factorize(A), x, α, β)
end

Modifying the code so the small case branch is taken unconditionally fixes the issue.

@yewalenikhil65
Copy link
Author

@nsajko shouldn't this issue be fixed by maintainers of ToeplitzMatrices.jl ? Or is it something that is expected to be done in isolation by users in their own compiled package of ToeplitzMatrices.jl ?

@nsajko
Copy link

nsajko commented Jul 31, 2023

shouldn't this issue be fixed by maintainers of ToeplitzMatrices.jl

I guess so. I'm not a maintainer, though, so don't ask me.

@yewalenikhil65
Copy link
Author

shouldn't this issue be fixed by maintainers of ToeplitzMatrices.jl

I guess so. I'm not a maintainer, though, so don't ask me.

Thanks for the help with that smaller case condition. It helped a lot

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

2 participants