Skip to content

Commit da19801

Browse files
committed
v0.14.3
1 parent 7088d65 commit da19801

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "0.14.2"
3+
version = "0.14.3"
44

55

66
[deps]

src/lazyoperations.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,29 @@ function tr(K::Kron{<:Any, 2})
5959
end
6060

6161

62-
getindex(K::Kron{T,1,<:Tuple{<:AbstractVector}}, k::Int) where T =
63-
first(K.args)[k]
64-
65-
function getindex(K::Kron{T,1,<:Tuple{<:AbstractVector,<:AbstractVector}}, k::Int) where T
66-
A,B = K.args
62+
kron_getindex((A,)::Tuple{AbstractVector}, k::Integer) = A[k]
63+
function kron_getindex((A,B)::NTuple{2,AbstractVector}, k::Integer)
6764
K,κ = divrem(k-1, length(B))
6865
A[K+1]*B[κ+1]
6966
end
70-
71-
getindex(K::Kron{T,2,<:Tuple{<:AbstractMatrix}}, k::Int, j::Int) where T =
72-
first(K.args)[k,j]
73-
74-
function getindex(K::Kron{T,2,<:Tuple{<:AbstractArray,<:AbstractArray}}, k::Int, j::Int) where T
75-
A,B = K.args
67+
kron_getindex((A,)::Tuple{AbstractMatrix}, k::Integer, j::Integer) = A[k,j]
68+
function kron_getindex((A,B)::NTuple{2,AbstractArray}, k::Integer, j::Integer)
7669
K,κ = divrem(k-1, size(B,1))
7770
J,ξ = divrem(j-1, size(B,2))
7871
A[K+1,J+1]*B[κ+1+1]
7972
end
8073

74+
kron_getindex(args::Tuple, k::Integer, j::Integer) = kron_getindex(tuple(Kron(args[1:2]...), args[3:end]...), k, j)
75+
kron_getindex(args::Tuple, k::Integer) = kron_getindex(tuple(Kron(args[1:2]...), args[3:end]...), k)
76+
77+
getindex(K::Kron{<:Any,1}, k::Integer) = kron_getindex(K.args, k)
78+
getindex(K::Kron{<:Any,2}, k::Integer, j::Integer) = kron_getindex(K.args, k, j)
79+
getindex(K::Applied{DefaultArrayApplyStyle,typeof(kron)}, k::Integer) = kron_getindex(K.args, k)
80+
getindex(K::Applied{DefaultArrayApplyStyle,typeof(kron)}, k::Integer, j::Integer) = kron_getindex(K.args, k, j)
81+
82+
83+
84+
8185
## Adapted from julia/stdlib/LinearAlgebra/src/dense.jl kron definition
8286
function _kron2!(R, K)
8387
size(R) == size(K) || throw(DimensionMismatch("Matrices have wrong dimensions"))

test/runtests.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ include("broadcasttests.jl")
104104

105105
K = @inferred(Kron{Float64}(Eye{Float64}(1), zeros(4)))
106106
@test Array(K) == zeros(4,1)
107+
108+
@testset "Applied bug" begin
109+
A = randn(5,5)
110+
K = Kron(A,A)
111+
k = applied(kron,A,A)
112+
@test K[1,1] == k[1,1] == A[1,1]^2
113+
x = randn(5)
114+
K = Kron(A,x)
115+
k = applied(kron,A,x)
116+
@test K[1,1] == k[1,1] == A[1,1]*x[1]
117+
K = Kron(x,x)
118+
k = applied(kron,x,x)
119+
@test K[1] == k[1] == x[1]^2
120+
K = Kron(A)
121+
k = applied(kron,A)
122+
@test K[1,1] == k[1,1] == A[1,1]
123+
K = Kron(x)
124+
k = applied(kron,x)
125+
@test K[1] == k[1] == x[1]
126+
end
127+
128+
@testset "triple vector" begin
129+
x = randn(5)
130+
y = randn(6)
131+
z = randn(4)
132+
K = Kron(x,y,z)
133+
@test K[1] == K[1,1] == x[1]y[1]z[1]
134+
@test K == kron(x,y,z)
135+
end
107136
end
108137

109138
@testset "Cache" begin

0 commit comments

Comments
 (0)