A case where FixedSizedArrays seems way slower than Vectors #156
-
Hi, struct HollowSymmetricCDS{Tv, Ti<:Integer} <: AbstractMatrix{Tv}
n::Int
offsets::Vector{Ti}
nzval::Vector{Tv}
diag_ptrs::Vector{Ti}
end and a specialized version of function LinearAlgebra.mul!(y::AbstractVector, A::HollowSymmetricCDS, x::AbstractVector)
n = A.n
if length(y) != n || length(x) != n
throw(DimensionMismatch("Vectors must have length $n."))
end
fill!(y, 0)
@inbounds for diag_idx in 1:length(A.offsets)
offset = A.offsets[diag_idx]
start_ptr = A.diag_ptrs[diag_idx]
# The length of this diagonal is n - offset
len = A.diag_ptrs[diag_idx + 1] - start_ptr
for i in 1:len
j = i + offset
val = A.nzval[start_ptr + i - 1]
y[i] += val * x[j]
y[j] += val * x[i]
end
end
return y
end Can reduce the computation time by a factor of two (In this case is a 100000x100000 matrix with only 2 nonzero superdiagonals)
However, something strange happens when I use your library to store the nonzero elements struct HollowSymmetricCDS{Tv, Ti<:Integer} <: AbstractMatrix{Tv}
n::Int
offsets::FixedSizeVector{Ti}
nzval::FixedSizeVector{Tv}
diag_ptrs::FixedSizeVector{Ti}
end
I did not touch the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I can't look at this right now, but what version of Julia are you using? If it isn't nightly, can you try that? If that solves the performance issue that's likely a duplicate of #152 and #70. (edit: but you already have an explicit inbounds annotation, so that's probably not the same issue) |
Beta Was this translation helpful? Give feedback.
-
Oh, note that |
Beta Was this translation helpful? Give feedback.
-
Changing to concrete type makes performance in line with standard Vectors!
|
Beta Was this translation helpful? Give feedback.
Changing to concrete type makes performance in line with standard Vectors!