1+ using Adapt: adapt
12using DerivableInterfaces: zero!
3+ using DiagonalArrays: δ
24using FillArrays: Eye, Zeros
5+ using JLArrays: JLArray, jl
36using KroneckerArrays: KroneckerArrays, KroneckerArray, ⊗ , × , arg1, arg2
47using LinearAlgebra: det, norm, pinv
58using StableRNGs: StableRNG
69using Test: @test , @test_throws , @testset
710using TestExtras: @constinferred
811
9- @testset " FillArrays.Eye" begin
12+ @testset " FillArrays.Eye, DiagonalArrays.Delta " begin
1013 MATRIX_FUNCTIONS = KroneckerArrays. MATRIX_FUNCTIONS
1114 if VERSION < v " 1.11-"
1215 # `cbrt(::AbstractMatrix{<:Real})` was implemented in Julia 1.11.
@@ -15,9 +18,46 @@ using TestExtras: @constinferred
1518
1619 a = Eye (2 ) ⊗ randn (3 , 3 )
1720 @test size (a) == (6 , 6 )
18- @test a + a == Eye (2 ) ⊗ (2 a. b)
19- @test 2 a == Eye (2 ) ⊗ (2 a. b)
20- @test a * a == Eye (2 ) ⊗ (a. b * a. b)
21+ @test a + a == Eye (2 ) ⊗ (2 * arg2 (a))
22+ @test 2 a == Eye (2 ) ⊗ (2 * arg2 (a))
23+ @test a * a == Eye (2 ) ⊗ (arg2 (a) * arg2 (a))
24+ @test arg1 (a[(:) × (:), (:) × (:)]) ≡ Eye (2 )
25+ @test arg1 (view (a, (:) × (:), (:) × (:))) ≡ Eye (2 )
26+ @test arg1 (a[Base. Slice (Base. OneTo (2 )) × (:), (:) × (:)]) ≡ Eye (2 )
27+ @test arg1 (view (a, Base. Slice (Base. OneTo (2 )) × (:), (:) × (:))) ≡ Eye (2 )
28+ @test arg1 (a[(:) × (:), Base. Slice (Base. OneTo (2 )) × (:)]) ≡ Eye (2 )
29+ @test arg1 (view (a, (:) × (:), Base. Slice (Base. OneTo (2 )) × (:))) ≡ Eye (2 )
30+ @test arg1 (a[Base. Slice (Base. OneTo (2 )) × (:), Base. Slice (Base. OneTo (2 )) × (:)]) ≡ Eye (2 )
31+ @test arg1 (view (a, Base. Slice (Base. OneTo (2 )) × (:), Base. Slice (Base. OneTo (2 )) × (:))) ≡
32+ Eye (2 )
33+ @test arg1 (adapt (JLArray, a)) ≡ Eye (2 )
34+ @test arg2 (adapt (JLArray, a)) == jl (arg2 (a))
35+ @test arg2 (adapt (JLArray, a)) isa JLArray
36+ @test arg1 (similar (a, (cartesianrange (3 × 2 ), cartesianrange (3 × 2 )))) ≡ Eye (3 )
37+ @test arg1 (similar (typeof (a), (cartesianrange (3 × 2 ), cartesianrange (3 × 2 )))) ≡ Eye (3 )
38+ @test arg1 (similar (a, Float32, (cartesianrange (3 × 2 ), cartesianrange (3 × 2 )))) ≡
39+ Eye {Float32} (3 )
40+
41+ a = δ (2 , 2 ) ⊗ randn (3 , 3 )
42+ @test size (a) == (6 , 6 )
43+ @test a + a == δ (2 , 2 ) ⊗ (2 * arg2 (a))
44+ @test 2 a == δ (2 , 2 ) ⊗ (2 * arg2 (a))
45+ @test a * a == δ (2 , 2 ) ⊗ (arg2 (a) * arg2 (a))
46+ @test arg1 (a[(:) × (:), (:) × (:)]) ≡ δ (2 , 2 )
47+ @test arg1 (a[Base. Slice (Base. OneTo (2 )) × (:), (:) × (:)]) ≡ δ (2 , 2 )
48+ @test arg1 (view (a, Base. Slice (Base. OneTo (2 )) × (:), (:) × (:))) ≡ δ (2 , 2 )
49+ @test arg1 (a[(:) × (:), Base. Slice (Base. OneTo (2 )) × (:)]) ≡ δ (2 , 2 )
50+ @test arg1 (view (a, (:) × (:), Base. Slice (Base. OneTo (2 )) × (:))) ≡ δ (2 , 2 )
51+ @test arg1 (a[Base. Slice (Base. OneTo (2 )) × (:), Base. Slice (Base. OneTo (2 )) × (:)]) ≡ δ (2 , 2 )
52+ @test arg1 (view (a, Base. Slice (Base. OneTo (2 )) × (:), Base. Slice (Base. OneTo (2 )) × (:))) ≡
53+ δ (2 , 2 )
54+ @test arg1 (adapt (JLArray, a)) ≡ δ (2 , 2 )
55+ @test arg2 (adapt (JLArray, a)) == jl (arg2 (a))
56+ @test arg2 (adapt (JLArray, a)) isa JLArray
57+ @test arg1 (similar (a, (cartesianrange (3 × 2 ), cartesianrange (3 × 2 )))) ≡ δ (3 , 3 )
58+ @test arg1 (similar (typeof (a), (cartesianrange (3 × 2 ), cartesianrange (3 × 2 )))) ≡ δ (3 , 3 )
59+ @test arg1 (similar (a, Float32, (cartesianrange (3 × 2 ), cartesianrange (3 × 2 )))) ≡
60+ δ (Float32, 3 , 3 )
2161
2262 # Views
2363 a = @constinferred (Eye (2 ) ⊗ randn (3 , 3 ))
0 commit comments