Skip to content

Commit

Permalink
fix getindex bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Jan 30, 2019
1 parent 5d9754a commit 8f2e313
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/linalg/mul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ getindex(M::MatMulMat, kj::CartesianIndex{2}) = M[kj[1], kj[2]]
# MulArray
#####

_mul(A) = A
_mul(A,B,C...) = Mul(A,B,C...)

function getindex(M::Mul, k)
A,Bs = first(M.factors), tail(M.factors)
B = Mul(Bs)
B = _mul(Bs...)
ret = zero(eltype(M))
for j = rowsupport(A, k)
ret += A[k,j] * B[j]
Expand All @@ -178,7 +181,7 @@ end

function getindex(M::Mul, k, j)
A,Bs = first(M.factors), tail(M.factors)
B = Mul(Bs)
B = _mul(Bs...)
ret = zero(eltype(M))
@inbounds forin (rowsupport(A,k) colsupport(B,j))
ret += A[k,ℓ] * B[ℓ,j]
Expand Down
9 changes: 9 additions & 0 deletions test/multests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,18 @@ import Base.Broadcast: materialize, materialize!
M = MulArray(A,A)
@test Matrix(M) A^2
end

@testset "Bug in getindex" begin
M = MulArray([1,2,3],Ones(1,20))
@test M[1,1] == 1
@test M[2,1] == 2
end
end





@testset "Add" begin
@testset "gemv Float64" begin
for A in (Add(randn(5,5), randn(5,5)),
Expand Down

0 comments on commit 8f2e313

Please sign in to comment.