@@ -2,9 +2,84 @@ module KroneckerArraysBlockSparseArraysExt
22
33using BlockSparseArrays: BlockSparseArrays, blockrange
44using KroneckerArrays: CartesianProduct, cartesianrange
5-
65function BlockSparseArrays. blockrange (bs:: Vector{<:CartesianProduct} )
76 return blockrange (map (cartesianrange, bs))
87end
98
9+ using BlockArrays: AbstractBlockedUnitRange
10+ using BlockSparseArrays: Block, GetUnstoredBlock, eachblockaxis, mortar_axis
11+ using DerivableInterfaces: zero!
12+ using FillArrays: Eye
13+ using KroneckerArrays:
14+ KroneckerArrays,
15+ EyeEye,
16+ EyeKronecker,
17+ KroneckerEye,
18+ KroneckerMatrix,
19+ ⊗ ,
20+ arg1,
21+ arg2,
22+ _similar
23+
24+ function KroneckerArrays. arg1 (r:: AbstractBlockedUnitRange )
25+ return mortar_axis (arg2 .(eachblockaxis (r)))
26+ end
27+ function KroneckerArrays. arg2 (r:: AbstractBlockedUnitRange )
28+ return mortar_axis (arg2 .(eachblockaxis (r)))
29+ end
30+
31+ function block_axes (
32+ ax:: NTuple{N,AbstractUnitRange{<:Integer}} , I:: Vararg{Block{1},N}
33+ ) where {N}
34+ return ntuple (N) do d
35+ return only (axes (ax[d][I[d]]))
36+ end
37+ end
38+ function block_axes (ax:: NTuple{N,AbstractUnitRange{<:Integer}} , I:: Block{N} ) where {N}
39+ return block_axes (ax, Tuple (I)... )
40+ end
41+
42+ function (f:: GetUnstoredBlock )(
43+ :: Type{<:AbstractMatrix{KroneckerMatrix{T,A,B}}} , I:: Vararg{Int,2}
44+ ) where {T,A<: AbstractMatrix{T} ,B<: AbstractMatrix{T} }
45+ ax_a = arg1 .(f. axes)
46+ f_a = GetUnstoredBlock (ax_a)
47+ a = f_a (AbstractMatrix{A}, I... )
48+
49+ ax_b = arg2 .(f. axes)
50+ f_b = GetUnstoredBlock (ax_b)
51+ b = f_b (AbstractMatrix{B}, I... )
52+
53+ return a ⊗ b
54+ end
55+ function (f:: GetUnstoredBlock )(
56+ :: Type{<:AbstractMatrix{EyeKronecker{T,A,B}}} , I:: Vararg{Int,2}
57+ ) where {T,A<: Eye{T} ,B<: AbstractMatrix{T} }
58+ block_ax_a = arg1 .(block_axes (f. axes, Block (I)))
59+ a = _similar (A, block_ax_a)
60+
61+ ax_b = arg2 .(f. axes)
62+ f_b = GetUnstoredBlock (ax_b)
63+ b = f_b (AbstractMatrix{B}, I... )
64+
65+ return a ⊗ b
66+ end
67+ function (f:: GetUnstoredBlock )(
68+ :: Type{<:AbstractMatrix{KroneckerEye{T,A,B}}} , I:: Vararg{Int,2}
69+ ) where {T,A<: AbstractMatrix{T} ,B<: Eye{T} }
70+ ax_a = arg1 .(f. axes)
71+ f_a = GetUnstoredBlock (ax_a)
72+ a = f_a (AbstractMatrix{A}, I... )
73+
74+ block_ax_b = arg2 .(block_axes (f. axes, Block (I)))
75+ b = _similar (B, block_ax_b)
76+
77+ return a ⊗ b
78+ end
79+ function (f:: GetUnstoredBlock )(
80+ :: Type{<:AbstractMatrix{EyeEye{T,A,B}}} , I:: Vararg{Int,2}
81+ ) where {T,A<: Eye{T} ,B<: Eye{T} }
82+ return error (" Not implemented." )
83+ end
84+
1085end
0 commit comments