Skip to content

Commit 13f4e79

Browse files
committed
add abstractkroneckerarray
1 parent 06d9939 commit 13f4e79

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/kroneckerarray.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
"""
2+
abstract type AbstractKroneckerArray{T, N} <: AbstractArray{T, N} end
3+
4+
Abstract supertype for arrays that have a kronecker product structure,
5+
i.e. that can be written as `AB = A ⊗ B`.
6+
"""
7+
abstract type AbstractKroneckerArray{T, N} <: AbstractArray{T, N} end
8+
9+
@doc """
10+
arg1(AB::AbstractKroneckerArray{T, N})
11+
12+
Extract the first factor (`A`) of the Kronecker array `AB = A ⊗ B`.
13+
""" arg1
14+
15+
@doc """
16+
arg2(AB::AbstractKroneckerArray{T, N})
17+
18+
Extract the second factor (`B`) of the Kronecker array `AB = A ⊗ B`.
19+
""" arg2
20+
21+
arg1type(x::AbstractKroneckerArray) = arg1type(typeof(x))
22+
arg1type(::Type{<:AbstractKroneckerArray}) = error("`AbstractKroneckerArray` subtypes have to implement `arg1type`.")
23+
arg2type(x::AbstractKroneckerArray) = arg2type(typeof(x))
24+
arg2type(::Type{<:AbstractKroneckerArray}) = error("`AbstractKroneckerArray` subtypes have to implement `arg2type`.")
25+
126
function unwrap_array(a::AbstractArray)
227
p = parent(a)
328
p a && return a
@@ -26,7 +51,7 @@ function _convert(A::Type{<:Diagonal}, a::AbstractMatrix)
2651
end
2752

2853
struct KroneckerArray{T, N, A1 <: AbstractArray{T, N}, A2 <: AbstractArray{T, N}} <:
29-
AbstractArray{T, N}
54+
AbstractKroneckerArray{T, N, A1, A2}
3055
arg1::A1
3156
arg2::A2
3257
end
@@ -48,6 +73,8 @@ const KroneckerVector{T, A1 <: AbstractVector{T}, A2 <: AbstractVector{T}} = Kro
4873

4974
@inline arg1(a::KroneckerArray) = getfield(a, :arg1)
5075
@inline arg2(a::KroneckerArray) = getfield(a, :arg2)
76+
arg1type(::Type{KroneckerArray{T, N, A1, A2}}) where {T, N, A1, A2} = A1
77+
arg2type(::Type{KroneckerArray{T, N, A1, A2}}) where {T, N, A1, A2} = A2
5178

5279
function mutate_active_args!(f!, f, dest, src)
5380
(isactive(arg1(dest)) || isactive(arg2(dest))) ||

0 commit comments

Comments
 (0)