From 9f45d9b6dee858459ab2cc92168d07d9c8aabfd4 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 1 Feb 2024 18:28:57 +0530 Subject: [PATCH] Tests for OneElementMatrix multiplication --- Project.toml | 2 +- test/test_linalg.jl | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index 82fd2e86..a566b424 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ BandedMatricesSparseArraysExt = "SparseArrays" [compat] Aqua = "0.8" -ArrayLayouts = "1.1" +ArrayLayouts = "1.5.3" Documenter = "1" FillArrays = "1.3" GenericLinearAlgebra = "0.3" diff --git a/test/test_linalg.jl b/test/test_linalg.jl index 39efd9c2..3908523c 100644 --- a/test/test_linalg.jl +++ b/test/test_linalg.jl @@ -8,19 +8,6 @@ using Test import Base.Broadcast: materialize, broadcasted import BandedMatrices: BandedColumns, _BandedMatrix -# wrap a OneElement to dispatch without type-piracy - -struct MyOneElement{T,N,A<:OneElement{T,N}} <: AbstractArray{T,N} - arr :: A -end -Base.size(M::MyOneElement) = size(M.arr) -Base.axes(M::MyOneElement) = axes(M.arr) -Base.getindex(M::MyOneElement{<:Any,N}, inds::Vararg{Int,N}) where {N} = - getindex(M.arr, inds...) - -ArrayLayouts.colsupport(::UnknownLayout, A::MyOneElement{<:Any,1}, _) = - intersect(axes(A,1), A.arr.ind[1]:A.arr.ind[1]) - @testset "Linear Algebra" begin @testset "Matrix types" begin A = brand(5,5,1,2) @@ -128,13 +115,23 @@ ArrayLayouts.colsupport(::UnknownLayout, A::MyOneElement{<:Any,1}, _) = @testset "BandedMatrix * sparse" begin B = brand(6,6,2,2) - x = MyOneElement(OneElement(2, 4, 6)) + x = OneElement(2, 4, 6) y = Array(x) @test B * x ≈ B * y @test B' * x ≈ B' * y - B = brand(Complex{Int8}, 6,6,2,2) - @test B' * x ≈ B' * y + C = brand(Complex{Int8}, 6,6,2,2) + @test C' * x == C' * y + + O = OneElement(2, (4,4), size(B)) + OA = Array(O) + @test B * O ≈ B * OA + @test B' * O ≈ B' * OA + @test O * B ≈ OA * B + @test O * B' ≈ OA * B' + + @test C' * O == C' * OA + @test O * C' == OA * C' end @testset "gbmm!" begin