Skip to content

Commit d194f98

Browse files
authored
Fix for StaticArrays in multiplication (#142)
1 parent 8f56f20 commit d194f98

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/implementations/LinearAlgebra.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ function undef_array(::Type{Array{T,N}}, axes::Vararg{Base.OneTo,N}) where {T,N}
357357
return Array{T,N}(undef, length.(axes))
358358
end
359359

360+
# This method is for things like StaticArrays which return something other than
361+
# Base.OneTo for their axes. It isn't typed because there can be a mix of axes
362+
# in the call.
363+
function undef_array(::Type{T}, axes...) where {T}
364+
return undef_array(T, convert.(Base.OneTo, axes)...)
365+
end
366+
360367
# Does what `LinearAlgebra/src/matmul.jl` does for abstract matrices and
361368
# vectors: estimate the resulting element type, allocate the resulting array but
362369
# it redirects to `mul_to!` instead of `LinearAlgebra.mul!`.

test/matmul.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,23 @@ end
296296
MA.operate!!(MA.add_mul, x, A, y)
297297
@test x == [13, 13]
298298
end
299+
300+
struct Issue65Matrix <: AbstractMatrix{Float64}
301+
x::Matrix{Float64}
302+
end
303+
304+
struct Issue65OneTo
305+
N::Int
306+
end
307+
308+
Base.size(x::Issue65Matrix) = size(x.x)
309+
Base.getindex(x::Issue65Matrix, args...) = getindex(x.x, args...)
310+
Base.axes(x::Issue65Matrix, n) = Issue65OneTo(size(x.x, n))
311+
Base.convert(::Type{Base.OneTo}, x::Issue65OneTo) = Base.OneTo(x.N)
312+
313+
@testset "Issue #65" begin
314+
x = [1.0 2.0; 3.0 4.0]
315+
A = Issue65Matrix(x)
316+
@test MA.operate(*, A, x[:, 1]) == x * x[:, 1]
317+
@test MA.operate(*, A, x) == x * x
318+
end

0 commit comments

Comments
 (0)