Skip to content

Commit 0baa17d

Browse files
committed
KroneckerArraysTensorProductsExt
1 parent 9a8951f commit 0baa17d

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
1616
[weakdeps]
1717
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
1818
BlockSparseArrays = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
19+
TensorProducts = "decf83d6-1968-43f4-96dc-fdb3fe15fc6d"
1920

2021
[extensions]
2122
KroneckerArraysBlockSparseArraysExt = ["BlockArrays", "BlockSparseArrays"]
23+
KroneckerArraysTensorProductsExt = "TensorProducts"
2224

2325
[compat]
2426
Adapt = "4.3"
@@ -31,4 +33,5 @@ GPUArraysCore = "0.2"
3133
LinearAlgebra = "1.10"
3234
MapBroadcast = "0.1.9"
3335
MatrixAlgebraKit = "0.2"
36+
TensorProducts = "0.1.7"
3437
julia = "1.10"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module KroneckerArraysTensorProductsExt
22

3-
using KroneckerArrays: CartesianProductOneTo, ×, arg1, arg2, cartesianrange
3+
using KroneckerArrays: CartesianProductOneTo, ×, arg1, arg2, cartesianrange, unproduct
44
using TensorProducts: TensorProducts, tensor_product
55
function TensorProducts.tensor_product(a1::CartesianProductOneTo, a2::CartesianProductOneTo)
6-
return cartesianrange(
7-
tensor_product(arg1(a1), arg1(a2)) × tensor_product(arg2(a1), arg2(a2))
8-
)
6+
prod = tensor_product(arg1(a1), arg1(a2)) × tensor_product(arg2(a1), arg2(a2))
7+
range = tensor_product(unproduct(a1), unproduct(a2))
8+
return cartesianrange(prod, range)
99
end
1010

1111
end

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
1414
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1515
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1616
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
17+
TensorProducts = "decf83d6-1968-43f4-96dc-fdb3fe15fc6d"
1718
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1819
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
1920

@@ -33,5 +34,6 @@ MatrixAlgebraKit = "0.2"
3334
SafeTestsets = "0.1"
3435
StableRNGs = "1.0"
3536
Suppressor = "0.2"
37+
TensorProducts = "0.1.7"
3638
Test = "1.10"
3739
TestExtras = "0.3"

test/test_tensorproducts.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using KroneckerArrays: ×, arg1, arg2, cartesianrange, unproduct
2+
using TensorProducts: tensor_product
3+
using Test: @test, @testset
4+
5+
@testset "KroneckerArraysTensorProductsExt" begin
6+
r1 = cartesianrange(2, 3)
7+
r2 = cartesianrange(4, 5)
8+
r = tensor_product(r1, r2)
9+
@test r cartesianrange(8, 15)
10+
@test arg1(r) Base.OneTo(8)
11+
@test arg2(r) Base.OneTo(15)
12+
@test unproduct(r) Base.OneTo(120)
13+
end

0 commit comments

Comments
 (0)