From e30bef3cfdb9a7500e0b68435b28e9046c41fd5d Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Tue, 19 Oct 2021 17:12:57 +0100 Subject: [PATCH 01/17] Add \ --- src/functions_linearalgebra.jl | 34 +++++++++++++++++++++++++++++++++ test/functions_linearalgebra.jl | 25 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index caa1c93..a256c6c 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -118,3 +118,37 @@ function Base.getproperty( return inner end end + +function LinearAlgebra.:\( + fact::NamedFactorization{L, T, F}, + nda::NamedDimsArray, +) where {L, T, F<:Factorization{T}} + n1, n2 = L + return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) +end + +function LinearAlgebra.:\( + fact::NamedFactorization{L, T, F}, + nda::AbstractVector, +) where {L, T, F<:Factorization{T}} + n1, n2 = L + return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), nda)) +end + +# Specialised routines for \ often do in-place ops that result in the nameddim populated from B +# Leading to an incorrect named-dim +for S in (UpperTriangular, LowerTriangular) + @eval begin + function LinearAlgebra.:\(A::$S{T, <:NamedDimsArray{L}}, B::NamedDimsArray) where {L, T} + n1, n2 = L + NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), parent(B))) + end + function LinearAlgebra.:\(A::$S{T, <:NamedDimsArray{L}}, B::AbstractVector) where {L, T} + n1, n2 = L + NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), parent(B))) + end + end +end + +# Diagonal on a nameddim loses its nameddimsness +LinearAlgebra.:\(A::Diagonal, B::NamedDimsArray) = LinearAlgebra.:\(A, parent(B)) diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 454fece..368a76b 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -1,3 +1,4 @@ +using Test: approx_full using LinearAlgebra using NamedDims using NamedDims: dimnames @@ -141,3 +142,27 @@ end nda = NamedDimsArray{(:foo, :bar)}([1 2 3; 4 5 6; 7 8 9]) # Int eltype @test qr(nda) isa NamedDims.NamedFactorization{(:foo, :bar), Float64} end + +@testset "LinearAlgebra.:ldiv " begin + + b = rand(5,) + b_nda = NamedDimsArray{(:blah,)}(b) + + for A = (rand(5,5), rand(5,3)) + (m, n) = size(A) + issquare = m == n + fn = issquare ? (identity, triu, tril, Diagonal) : (identity,) + for f in fn + for B in (b_nda, b) + nda = NamedDimsArray{(:foo, :bar)}(f(A)) + x = nda \ B + @test parent(x) ≈ f(A) \ parent(B) + f != Diagonal && @test dimnames(x) == (:bar,) + # Do we want to test the results? + issquare && @test parent(f(A) * x) ≈ parent(B) + end + end + end + +end + From 5c7b03f72adaa4f84f7e895a80ffa2dc56abe906 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Tue, 19 Oct 2021 17:48:28 +0100 Subject: [PATCH 02/17] Some corrections. Add Exception --- src/functions_linearalgebra.jl | 9 +++++---- test/functions_linearalgebra.jl | 11 +++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index a256c6c..2df3640 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -121,9 +121,10 @@ end function LinearAlgebra.:\( fact::NamedFactorization{L, T, F}, - nda::NamedDimsArray, -) where {L, T, F<:Factorization{T}} + nda::NamedDimsArray{W}, +) where {L, T, F<:Factorization{T}, W} n1, n2 = L + n1 != only(W) && throw(ArgumentError("Dimension mismatch with dimensions $L and $W")) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end @@ -145,10 +146,10 @@ for S in (UpperTriangular, LowerTriangular) end function LinearAlgebra.:\(A::$S{T, <:NamedDimsArray{L}}, B::AbstractVector) where {L, T} n1, n2 = L - NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), parent(B))) + NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), B)) end end end -# Diagonal on a nameddim loses its nameddimsness +# Diagonal on a nameddim presently loses its nameddimsness. So just pass through for now. LinearAlgebra.:\(A::Diagonal, B::NamedDimsArray) = LinearAlgebra.:\(A, parent(B)) diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 368a76b..45b6fe1 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -145,10 +145,10 @@ end @testset "LinearAlgebra.:ldiv " begin - b = rand(5,) - b_nda = NamedDimsArray{(:blah,)}(b) - - for A = (rand(5,5), rand(5,3)) + r1, r2, b = rand(5,5), rand(5,3), rand(5,) + b_nda = NamedDimsArray{(:foo,)}(b) + + for A = (r1, r2) (m, n) = size(A) issquare = m == n fn = issquare ? (identity, triu, tril, Diagonal) : (identity,) @@ -157,6 +157,7 @@ end nda = NamedDimsArray{(:foo, :bar)}(f(A)) x = nda \ B @test parent(x) ≈ f(A) \ parent(B) + # TODO: Remove Diagonal specialcase once Diagonal(NamedDim) maintains NamedDimsness. f != Diagonal && @test dimnames(x) == (:bar,) # Do we want to test the results? issquare && @test parent(f(A) * x) ≈ parent(B) @@ -164,5 +165,7 @@ end end end + @test_throws ArgumentError NamedDimsArray{(:A, :B)}(r1) \ NamedDimsArray{(:NotA,)}(r2) + end From 512feb47dbc263fabe4aac162e1dc5a1448ee8d6 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Tue, 19 Oct 2021 18:14:19 +0100 Subject: [PATCH 03/17] only -> [1] --- src/functions_linearalgebra.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index 2df3640..d77c67e 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -124,7 +124,7 @@ function LinearAlgebra.:\( nda::NamedDimsArray{W}, ) where {L, T, F<:Factorization{T}, W} n1, n2 = L - n1 != only(W) && throw(ArgumentError("Dimension mismatch with dimensions $L and $W")) + n1 != W[1] && throw(ArgumentError("Dimension mismatch with dimensions $L and $W")) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end From 66a1fca232df0de00b8986f6a479379c482ea142 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 20 Oct 2021 13:57:29 +0100 Subject: [PATCH 04/17] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/functions_linearalgebra.jl | 22 ++++++++++++---------- test/functions_linearalgebra.jl | 9 +++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index d77c67e..1b4d471 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -120,18 +120,16 @@ function Base.getproperty( end function LinearAlgebra.:\( - fact::NamedFactorization{L, T, F}, - nda::NamedDimsArray{W}, -) where {L, T, F<:Factorization{T}, W} + fact::NamedFactorization{L,T,F}, nda::NamedDimsArray{W} +) where {L,T,F<:Factorization{T},W} n1, n2 = L n1 != W[1] && throw(ArgumentError("Dimension mismatch with dimensions $L and $W")) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end function LinearAlgebra.:\( - fact::NamedFactorization{L, T, F}, - nda::AbstractVector, -) where {L, T, F<:Factorization{T}} + fact::NamedFactorization{L,T,F}, nda::AbstractVector +) where {L,T,F<:Factorization{T}} n1, n2 = L return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), nda)) end @@ -140,13 +138,17 @@ end # Leading to an incorrect named-dim for S in (UpperTriangular, LowerTriangular) @eval begin - function LinearAlgebra.:\(A::$S{T, <:NamedDimsArray{L}}, B::NamedDimsArray) where {L, T} + function LinearAlgebra.:\( + A::$S{T,<:NamedDimsArray{L}}, B::NamedDimsArray + ) where {L,T} n1, n2 = L - NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), parent(B))) + return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), parent(B))) end - function LinearAlgebra.:\(A::$S{T, <:NamedDimsArray{L}}, B::AbstractVector) where {L, T} + function LinearAlgebra.:\( + A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector + ) where {L,T} n1, n2 = L - NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), B)) + return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), B)) end end end diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 45b6fe1..d2398e9 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -144,11 +144,10 @@ end end @testset "LinearAlgebra.:ldiv " begin - - r1, r2, b = rand(5,5), rand(5,3), rand(5,) + r1, r2, b = rand(5, 5), rand(5, 3), rand(5) b_nda = NamedDimsArray{(:foo,)}(b) - - for A = (r1, r2) + + for A in (r1, r2) (m, n) = size(A) issquare = m == n fn = issquare ? (identity, triu, tril, Diagonal) : (identity,) @@ -166,6 +165,4 @@ end end @test_throws ArgumentError NamedDimsArray{(:A, :B)}(r1) \ NamedDimsArray{(:NotA,)}(r2) - end - From 2a98f108d396f7ef3169c229ef82f0c359f5c4d3 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 20 Oct 2021 16:33:36 +0100 Subject: [PATCH 05/17] ArgumentERror -> DimensionMismatch and add nested unname --- src/functions_linearalgebra.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index 1b4d471..0638498 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -123,7 +123,7 @@ function LinearAlgebra.:\( fact::NamedFactorization{L,T,F}, nda::NamedDimsArray{W} ) where {L,T,F<:Factorization{T},W} n1, n2 = L - n1 != W[1] && throw(ArgumentError("Dimension mismatch with dimensions $L and $W")) + n1 != W[1] && throw(DimensionMismatch("Mismatched dimensions with fact: $L and nda: $W")) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end @@ -136,19 +136,20 @@ end # Specialised routines for \ often do in-place ops that result in the nameddim populated from B # Leading to an incorrect named-dim +# We use unname here because that handles wrapper types for S in (UpperTriangular, LowerTriangular) @eval begin function LinearAlgebra.:\( A::$S{T,<:NamedDimsArray{L}}, B::NamedDimsArray ) where {L,T} n1, n2 = L - return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), parent(B))) + return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(unname(A)), parent(B))) end function LinearAlgebra.:\( A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector ) where {L,T} n1, n2 = L - return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(parent(parent(A))), B)) + return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(unname(A)), B)) end end end From c6831830f32bac807fa100d6c32e7cba782f666b Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 20 Oct 2021 16:34:25 +0100 Subject: [PATCH 06/17] Add unname for LinearAlgebra operations --- src/name_operations.jl | 8 ++++++++ test/name_operations.jl | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/name_operations.jl b/src/name_operations.jl index a5283ee..9b19dcf 100644 --- a/src/name_operations.jl +++ b/src/name_operations.jl @@ -41,9 +41,17 @@ Return the input array `A` without any dimension names. For `NamedDimsArray`s this returns the parent array, equivalent to calling `parent`, but for anything else it simply returns the input. + +Supports some LinearAlgebra wrappers LowerTriangular, UpperTriangular such that +`unname(x::UpperTriangular{T, <:NamedDimsArray}) == unname(parent(x)) + """ unname(x::NamedDimsArray) = parent(x) unname(x) = x +# Unwrap LinearAlgebra wrappers +for W in (LowerTriangular, UpperTriangular,) + @eval unname(x::$W{T, <:NamedDimsArray}) where {T} = unname(parent(x)) +end """ dimnames(A) -> Tuple diff --git a/test/name_operations.jl b/test/name_operations.jl index 870901a..53be9e5 100644 --- a/test/name_operations.jl +++ b/test/name_operations.jl @@ -1,9 +1,16 @@ +using LinearAlgebra: LowerTriangular, UpperTriangular + @testset "unname" begin for orig in ([1 2; 3 4], spzeros(2, 2)) @test unname(NamedDimsArray(orig, (:x, :y))) === orig @test unname(orig) === orig end @test unname((1,2,3)) === (1,2,3) + + for wrapper in (LowerTriangular, UpperTriangular,) + orig = [1 2; 3 4] + @test unname(wrapper(NamedDimsArray(orig, (:x, :y)))) === orig + end end From 90d2b139913960f98bf2c53ba7f72223b8e7deb8 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 20 Oct 2021 16:35:01 +0100 Subject: [PATCH 07/17] Fix up incorrect test. Add test for rectangular matrix --- test/functions_linearalgebra.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index d2398e9..54002b2 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -140,11 +140,13 @@ end @testset "#164 factorization eltype not same as input eltype" begin # https://github.com/invenia/NamedDims.jl/issues/164 nda = NamedDimsArray{(:foo, :bar)}([1 2 3; 4 5 6; 7 8 9]) # Int eltype - @test qr(nda) isa NamedDims.NamedFactorization{(:foo, :bar), Float64} + @test qr(nda) isa NamedDims.NamedFactorization{(:foo, :bar),Float64} end @testset "LinearAlgebra.:ldiv " begin - r1, r2, b = rand(5, 5), rand(5, 3), rand(5) + r1 = [2 3 5; 7 11 13; 17 19 23] + r2 = r1[:, 1:2] + b = [29, 31, 37] b_nda = NamedDimsArray{(:foo,)}(b) for A in (r1, r2) @@ -156,13 +158,14 @@ end nda = NamedDimsArray{(:foo, :bar)}(f(A)) x = nda \ B @test parent(x) ≈ f(A) \ parent(B) - # TODO: Remove Diagonal specialcase once Diagonal(NamedDim) maintains NamedDimsness. + # NOTE: Diagonal loses NamedDimness so specialcase f != Diagonal && @test dimnames(x) == (:bar,) # Do we want to test the results? issquare && @test parent(f(A) * x) ≈ parent(B) + !issquare && @test pinv(f(A)) * parent(b) ≈ parent(x) end end end - @test_throws ArgumentError NamedDimsArray{(:A, :B)}(r1) \ NamedDimsArray{(:NotA,)}(r2) + @test_throws DimensionMismatch NamedDimsArray{(:A, :B)}(r1) \ NamedDimsArray{(:NotA,)}(b) end From f73daf0fbcbd9e39264ed2f6d1085463c4a0f596 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 20 Oct 2021 16:39:54 +0100 Subject: [PATCH 08/17] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/functions_linearalgebra.jl | 3 ++- src/name_operations.jl | 4 ++-- test/functions_linearalgebra.jl | 3 ++- test/name_operations.jl | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index 0638498..9abe523 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -123,7 +123,8 @@ function LinearAlgebra.:\( fact::NamedFactorization{L,T,F}, nda::NamedDimsArray{W} ) where {L,T,F<:Factorization{T},W} n1, n2 = L - n1 != W[1] && throw(DimensionMismatch("Mismatched dimensions with fact: $L and nda: $W")) + n1 != W[1] && + throw(DimensionMismatch("Mismatched dimensions with fact: $L and nda: $W")) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end diff --git a/src/name_operations.jl b/src/name_operations.jl index 9b19dcf..eb8e96a 100644 --- a/src/name_operations.jl +++ b/src/name_operations.jl @@ -49,8 +49,8 @@ Supports some LinearAlgebra wrappers LowerTriangular, UpperTriangular such that unname(x::NamedDimsArray) = parent(x) unname(x) = x # Unwrap LinearAlgebra wrappers -for W in (LowerTriangular, UpperTriangular,) - @eval unname(x::$W{T, <:NamedDimsArray}) where {T} = unname(parent(x)) +for W in (LowerTriangular, UpperTriangular) + @eval unname(x::$W{T,<:NamedDimsArray}) where {T} = unname(parent(x)) end """ diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 54002b2..7f4c06a 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -167,5 +167,6 @@ end end end - @test_throws DimensionMismatch NamedDimsArray{(:A, :B)}(r1) \ NamedDimsArray{(:NotA,)}(b) + @test_throws DimensionMismatch NamedDimsArray{(:A, :B)}(r1) \ + NamedDimsArray{(:NotA,)}(b) end diff --git a/test/name_operations.jl b/test/name_operations.jl index 53be9e5..9f6519b 100644 --- a/test/name_operations.jl +++ b/test/name_operations.jl @@ -5,9 +5,9 @@ using LinearAlgebra: LowerTriangular, UpperTriangular @test unname(NamedDimsArray(orig, (:x, :y))) === orig @test unname(orig) === orig end - @test unname((1,2,3)) === (1,2,3) + @test unname((1, 2, 3)) === (1, 2, 3) - for wrapper in (LowerTriangular, UpperTriangular,) + for wrapper in (LowerTriangular, UpperTriangular) orig = [1 2; 3 4] @test unname(wrapper(NamedDimsArray(orig, (:x, :y)))) === orig end From 1fc0175ac8abb519399c27a316bda1b9e339a37e Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 20 Oct 2021 16:40:19 +0100 Subject: [PATCH 09/17] Update test/name_operations.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/name_operations.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/name_operations.jl b/test/name_operations.jl index 9f6519b..e56819a 100644 --- a/test/name_operations.jl +++ b/test/name_operations.jl @@ -13,7 +13,6 @@ using LinearAlgebra: LowerTriangular, UpperTriangular end end - @testset "dimnames" begin nda = NamedDimsArray([10 20; 30 40], (:x, :y)) From f69f82a59667db30915d84d43f58712b612e1340 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 11:04:05 +0100 Subject: [PATCH 10/17] Consolidate methods --- src/functions_linearalgebra.jl | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index 9abe523..55257f4 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -140,18 +140,10 @@ end # We use unname here because that handles wrapper types for S in (UpperTriangular, LowerTriangular) @eval begin - function LinearAlgebra.:\( - A::$S{T,<:NamedDimsArray{L}}, B::NamedDimsArray - ) where {L,T} + function LinearAlgebra.:\(A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector) where {L,T} n1, n2 = L return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(unname(A)), parent(B))) end - function LinearAlgebra.:\( - A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector - ) where {L,T} - n1, n2 = L - return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(unname(A)), B)) - end end end From 35eee8b4156d6662a5459197eda8846818247f3a Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 11:03:22 +0100 Subject: [PATCH 11/17] Apply suggestions from code review Co-authored-by: Glenn Moynihan --- Project.toml | 2 +- test/functions_linearalgebra.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index e42c704..f82dce3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NamedDims" uuid = "356022a1-0364-5f58-8944-0da4b18d706f" authors = ["Invenia Technical Computing Corporation"] -version = "0.2.40" +version = "0.2.41" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 7f4c06a..0379962 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -167,6 +167,8 @@ end end end - @test_throws DimensionMismatch NamedDimsArray{(:A, :B)}(r1) \ + @test_throws DimensionMismatch \( + NamedDimsArray{(:A, :B)}(r1), NamedDimsArray{(:NotA,)}(b) + ) end From a9a05dc1e2fa49b6ce0b17d82bcbf619ba6e3217 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 11:16:58 +0100 Subject: [PATCH 12/17] Fix test syntax --- test/functions_linearalgebra.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 0379962..79f08eb 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -160,14 +160,11 @@ end @test parent(x) ≈ f(A) \ parent(B) # NOTE: Diagonal loses NamedDimness so specialcase f != Diagonal && @test dimnames(x) == (:bar,) - # Do we want to test the results? - issquare && @test parent(f(A) * x) ≈ parent(B) - !issquare && @test pinv(f(A)) * parent(b) ≈ parent(x) end end end - @test_throws DimensionMismatch \( + @test_throws DimensionMismatch (\)( NamedDimsArray{(:A, :B)}(r1), NamedDimsArray{(:NotA,)}(b) ) From 07c905e4136687a1e57c82d924f6d219f189488c Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 11:47:05 +0100 Subject: [PATCH 13/17] Actually update message text --- src/functions_linearalgebra.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index 55257f4..b00f8ec 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -124,7 +124,9 @@ function LinearAlgebra.:\( ) where {L,T,F<:Factorization{T},W} n1, n2 = L n1 != W[1] && - throw(DimensionMismatch("Mismatched dimensions with fact: $L and nda: $W")) + throw(DimensionMismatch( + "Mismatched dimensions with factorization: $L and NamedDimsArray: $W") + ) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end From f5681418b0353b5bbfce0a94b45a30832a979432 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 13:02:20 +0100 Subject: [PATCH 14/17] Small change to retrigger CI --- src/functions_linearalgebra.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index b00f8ec..5b93ed1 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -139,7 +139,7 @@ end # Specialised routines for \ often do in-place ops that result in the nameddim populated from B # Leading to an incorrect named-dim -# We use unname here because that handles wrapper types +# We also unname here because that handles wrapper types for S in (UpperTriangular, LowerTriangular) @eval begin function LinearAlgebra.:\(A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector) where {L,T} From 74e2850f28f16e2738659fa7e8164e2428b1e810 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 13:16:10 +0100 Subject: [PATCH 15/17] Update test/functions_linearalgebra.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/functions_linearalgebra.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/functions_linearalgebra.jl b/test/functions_linearalgebra.jl index 79f08eb..13ebd29 100644 --- a/test/functions_linearalgebra.jl +++ b/test/functions_linearalgebra.jl @@ -165,7 +165,6 @@ end end @test_throws DimensionMismatch (\)( - NamedDimsArray{(:A, :B)}(r1), - NamedDimsArray{(:NotA,)}(b) + NamedDimsArray{(:A, :B)}(r1), NamedDimsArray{(:NotA,)}(b) ) end From f4e7dc9ed5a2c99c3e5e29dc601add2620131f45 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 13:16:18 +0100 Subject: [PATCH 16/17] Update src/functions_linearalgebra.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/functions_linearalgebra.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index 5b93ed1..de4acf1 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -123,10 +123,11 @@ function LinearAlgebra.:\( fact::NamedFactorization{L,T,F}, nda::NamedDimsArray{W} ) where {L,T,F<:Factorization{T},W} n1, n2 = L - n1 != W[1] && - throw(DimensionMismatch( - "Mismatched dimensions with factorization: $L and NamedDimsArray: $W") - ) + n1 != W[1] && throw( + DimensionMismatch( + "Mismatched dimensions with factorization: $L and NamedDimsArray: $W" + ), + ) return NamedDimsArray{(n2,)}(LinearAlgebra.:\(parent(fact), parent(nda))) end From f9874a9366c44c361999bcb16fcbe7e9d5112041 Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Wed, 27 Oct 2021 13:16:25 +0100 Subject: [PATCH 17/17] Update src/functions_linearalgebra.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/functions_linearalgebra.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/functions_linearalgebra.jl b/src/functions_linearalgebra.jl index de4acf1..310b29d 100644 --- a/src/functions_linearalgebra.jl +++ b/src/functions_linearalgebra.jl @@ -143,7 +143,9 @@ end # We also unname here because that handles wrapper types for S in (UpperTriangular, LowerTriangular) @eval begin - function LinearAlgebra.:\(A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector) where {L,T} + function LinearAlgebra.:\( + A::$S{T,<:NamedDimsArray{L}}, B::AbstractVector + ) where {L,T} n1, n2 = L return NamedDimsArray{(n2,)}(LinearAlgebra.:\($S(unname(A)), parent(B))) end