|
| 1 | +using TensorAlgebra: TensorAlgebra as TA, FusionStyle, Matricize, ReshapeFusion |
| 2 | +using Test: @test, @testset |
| 3 | + |
| 4 | +module FusionStyleTestUtils |
| 5 | + using TensorAlgebra: TensorAlgebra as TA |
| 6 | + struct MyArray{T, N, A <: AbstractArray{T, N}} <: AbstractArray{T, N} |
| 7 | + parent::A |
| 8 | + end |
| 9 | + struct MyArrayFusion <: TA.FusionStyle end |
| 10 | + TA.FusionStyle(::Type{<:MyArray}) = MyArrayFusion() |
| 11 | +end |
| 12 | +using .FusionStyleTestUtils: MyArray, MyArrayFusion |
| 13 | + |
| 14 | +@testset "FusionStyle" begin |
| 15 | + a1 = randn(2, 2) |
| 16 | + a2 = MyArray(randn(2, 2)) |
| 17 | + @test FusionStyle(a1) ≡ ReshapeFusion() |
| 18 | + @test FusionStyle(a2) ≡ MyArrayFusion() |
| 19 | + @test FusionStyle(typeof(a1)) ≡ ReshapeFusion() |
| 20 | + @test FusionStyle(ReshapeFusion(), ReshapeFusion()) ≡ ReshapeFusion() |
| 21 | + @test FusionStyle(MyArrayFusion(), MyArrayFusion()) ≡ MyArrayFusion() |
| 22 | + @test FusionStyle(MyArrayFusion(), ReshapeFusion()) ≡ ReshapeFusion() |
| 23 | + @test FusionStyle(ReshapeFusion(), MyArrayFusion()) ≡ ReshapeFusion() |
| 24 | + @test TA.default_contract_algorithm(typeof(a1), typeof(a1)) ≡ Matricize(ReshapeFusion()) |
| 25 | + @test TA.default_contract_algorithm(typeof(a1), typeof(a2)) ≡ Matricize(ReshapeFusion()) |
| 26 | + @test TA.default_contract_algorithm(typeof(a2), typeof(a1)) ≡ Matricize(ReshapeFusion()) |
| 27 | + @test TA.default_contract_algorithm(typeof(a2), typeof(a2)) ≡ Matricize(MyArrayFusion()) |
| 28 | +end |
0 commit comments