From a65570eabef3af2c0cdecce99b0076a6294b0003 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Fri, 21 Feb 2025 18:43:33 +0100 Subject: [PATCH 1/3] Fix `WrappedMap` constructor for vectors --- Project.toml | 2 +- src/wrappedmap.jl | 14 ++++---------- test/wrappedmap.jl | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index e50d768c..d99c20de 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "LinearMaps" uuid = "7a12625a-238d-50fd-b39a-03d52299707e" -version = "3.11.3" +version = "3.12.1" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/wrappedmap.jl b/src/wrappedmap.jl index e5f2d220..39318a14 100644 --- a/src/wrappedmap.jl +++ b/src/wrappedmap.jl @@ -4,36 +4,30 @@ struct WrappedMap{T, A<:MapOrVecOrMat} <: LinearMap{T} _ishermitian::Bool _isposdef::Bool end -function WrappedMap{T}(lmap::MapOrMatrix; +function WrappedMap{T}(lmap::MapOrVecOrMat; issymmetric::Bool = _issymmetric(lmap), ishermitian::Bool = _ishermitian(lmap), isposdef::Bool = _isposdef(lmap)) where {T} WrappedMap{T, typeof(lmap)}(lmap, issymmetric, ishermitian, isposdef) end -function WrappedMap{T}(lmap::AbstractVector; - issym::Bool = false, - isherm::Bool = false, - ispd::Bool = false) where {T} - WrappedMap{T, typeof(lmap)}(lmap, - length(lmap) == 1 && issymmetric(first(lmap)), - length(lmap) == 1 && ishermitian(first(lmap)), - length(lmap) == 1 && isposdef(first(lmap))) -end WrappedMap(lmap::MapOrVecOrMat{T}; kwargs...) where {T} = WrappedMap{T}(lmap; kwargs...) # cheap property checks (usually by type) +_issymmetric(A::AbstractVector) = length(A) == 1 && issymmetric(first(A)) _issymmetric(A::AbstractMatrix) = false _issymmetric(A::AbstractQ) = false _issymmetric(A::LinearMap) = issymmetric(A) _issymmetric(A::LinearAlgebra.RealHermSymComplexSym) = issymmetric(A) _issymmetric(A::Union{Bidiagonal,Diagonal,SymTridiagonal,Tridiagonal}) = issymmetric(A) +_ishermitian(A::AbstractVector) = length(A) == 1 && ishermitian(first(A)) _ishermitian(A::AbstractMatrix) = false _ishermitian(A::AbstractQ) = false _ishermitian(A::LinearMap) = ishermitian(A) _ishermitian(A::LinearAlgebra.RealHermSymComplexHerm) = ishermitian(A) _ishermitian(A::Union{Bidiagonal,Diagonal,SymTridiagonal,Tridiagonal}) = ishermitian(A) +_isposdef(A::AbstractVector) = length(A) == 1 && isposdef(first(A)) _isposdef(A::AbstractMatrix) = false _isposdef(A::AbstractQ) = false _isposdef(A::LinearMap) = isposdef(A) diff --git a/test/wrappedmap.jl b/test/wrappedmap.jl index b9b7bc31..33a34d55 100644 --- a/test/wrappedmap.jl +++ b/test/wrappedmap.jl @@ -1,4 +1,4 @@ -using Test, LinearMaps, LinearAlgebra +using Test, LinearMaps, LinearAlgebra, SparseArrays @testset "wrapped maps" begin A = rand(10, 20) From c0a67627992baefab7e020fa9334789083e271e0 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Fri, 21 Feb 2025 19:18:32 +0100 Subject: [PATCH 2/3] bump lower BlockArrays compat in tests --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 9d85356c..300b3c94 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -15,7 +15,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Aqua = "0.8" -BlockArrays = "0.16" +BlockArrays = "1" ChainRulesCore = "1" ChainRulesTestUtils = "1.9" Documenter = "1" From 9015413a5b133c24fc3ec64371d2de5ee231740e Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Fri, 21 Feb 2025 19:33:40 +0100 Subject: [PATCH 3/3] fix BlockArray-related tests --- test/nontradaxes.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/nontradaxes.jl b/test/nontradaxes.jl index f4d999e5..66adf110 100644 --- a/test/nontradaxes.jl +++ b/test/nontradaxes.jl @@ -3,7 +3,7 @@ using Test, LinearMaps, LinearAlgebra, BlockArrays @testset "Non-traditional axes" begin A = rand(ComplexF64,2,4) - B = PseudoBlockMatrix{ComplexF64}(undef, [2,3], [3,4]) + B = BlockMatrix{ComplexF64}(undef, [2,3], [3,4]) ax1 = axes(B)[1] ax2 = axes(B)[2] @@ -19,7 +19,7 @@ using Test, LinearMaps, LinearAlgebra, BlockArrays @test eltype(N) == eltype(B) u = similar(Array{ComplexF64}, ax2) - v = PseudoBlockVector{ComplexF64}(undef, [3,5]) + v = BlockVector{ComplexF64}(undef, [3,5]) w = similar(Array{ComplexF64}, ax1) for i in eachindex(u) u[i] = rand(ComplexF64) end @@ -54,7 +54,7 @@ using Test, LinearMaps, LinearAlgebra, BlockArrays @test blocklengths(axes(C)[1]) == blocklengths(ax1) A = rand(ComplexF64,2,2) - B = PseudoBlockMatrix{ComplexF64}(undef, [2,2], [2,2]) + B = BlockMatrix{ComplexF64}(undef, [2,2], [2,2]) ax1 = axes(B)[1] ax2 = axes(B)[2] fill!(B,0) @@ -75,12 +75,12 @@ using Test, LinearMaps, LinearAlgebra, BlockArrays D2 = rand(5,3) D3 = rand(3,6) D4 = rand(6,6) - A1 = PseudoBlockMatrix(D1, [1,3], [2,3]) - A2 = PseudoBlockMatrix(D2, [2,3], [2,1]) - A3 = PseudoBlockMatrix(D3, [2,1], [3,2,1]) - A4 = PseudoBlockMatrix(D4, [3,2,1], [3,2,1]) + A1 = BlockMatrix(D1, [1,3], [2,3]) + A2 = BlockMatrix(D2, [2,3], [2,1]) + A3 = BlockMatrix(D3, [2,1], [3,2,1]) + A4 = BlockMatrix(D4, [3,2,1], [3,2,1]) u = rand(6) - x = PseudoBlockVector(u, [3,2,1]) + x = BlockVector(u, [3,2,1]) L = LinearMap(A1) * LinearMap(A2) * LinearMap(A3) * LinearMap(A4) y = L * x v = Vector(y)