From 2993cbd3e9d24db90a7245b2651099fd07ec43e2 Mon Sep 17 00:00:00 2001 From: Sebastian Flassbeck Date: Tue, 24 Sep 2024 15:31:02 -0400 Subject: [PATCH 1/2] DiagOp should now work with @view on linear operator --- src/DiagOp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiagOp.jl b/src/DiagOp.jl index 73fdfa5..5e6ed3e 100644 --- a/src/DiagOp.jl +++ b/src/DiagOp.jl @@ -53,7 +53,7 @@ function DiagOp(ops) (res,y) -> (diagOpTProd(res,y,ncol,yIdx,xIdx,ops)), (res,y) -> (diagOpCTProd(res,y,ncol,yIdx,xIdx,ops)), 0, 0, 0, false, false, false, S(undef, 0), S(undef, 0), - [ops...], false, xIdx, yIdx) + ops, false, xIdx, yIdx) return Op end From 18f1227123a684acc62fdcc2b88cf1aed89ac929 Mon Sep 17 00:00:00 2001 From: Sebastian Flassbeck Date: Fri, 27 Sep 2024 14:10:57 -0400 Subject: [PATCH 2/2] Add test for DiagOp with @view --- test/testOperators.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/testOperators.jl b/test/testOperators.jl index 3268a5d..fa887a4 100644 --- a/test/testOperators.jl +++ b/test/testOperators.jl @@ -317,6 +317,8 @@ function testDiagOp(N=32,K=2;arrayType = Array) op1 = DiagOp(blocks) op2 = DiagOp(blocks...) op3 = DiagOp(block, K) + op4 = DiagOp(@view blocks[1:K]) + # Operations @testset "Diag Prod" begin @@ -324,10 +326,14 @@ function testDiagOp(N=32,K=2;arrayType = Array) y1 = Array(op1 * x) y2 = Array(op2 * x) y3 = Array(op3 * x) + y4 = Array(op4 * x) + @test y ≈ y1 rtol = 1e-2 @test y1 ≈ y2 rtol = 1e-2 @test y2 ≈ y3 rtol = 1e-2 + @test y4 ≈ y1 rtol = 1e-2 + end @testset "Diag Transpose" begin @@ -335,10 +341,12 @@ function testDiagOp(N=32,K=2;arrayType = Array) y1 = Array(transpose(op1) * x) y2 = Array(transpose(op2) * x) y3 = Array(transpose(op3) * x) + y4 = Array(transpose(op4) * x) @test y ≈ y1 rtol = 1e-2 @test y1 ≈ y2 rtol = 1e-2 @test y2 ≈ y3 rtol = 1e-2 + @test y4 ≈ y1 rtol = 1e-2 end @testset "Diag Adjoint" begin @@ -346,10 +354,12 @@ function testDiagOp(N=32,K=2;arrayType = Array) y1 = Array(adjoint(op1) * x) y2 = Array(adjoint(op2) * x) y3 = Array(adjoint(op3) * x) + y4 = Array(adjoint(op4) * x) @test y ≈ y1 rtol = 1e-2 @test y1 ≈ y2 rtol = 1e-2 @test y2 ≈ y3 rtol = 1e-2 + @test y4 ≈ y1 rtol = 1e-2 end @testset "Diag Normal" begin @@ -357,10 +367,13 @@ function testDiagOp(N=32,K=2;arrayType = Array) y1 = Array(normalOperator(op1) * x) y2 = Array(normalOperator(op2) * x) y3 = Array(normalOperator(op3) * x) + y4 = Array(normalOperator(op4) * x) @test y ≈ y1 rtol = 1e-2 @test y1 ≈ y2 rtol = 1e-2 @test y2 ≈ y3 rtol = 1e-2 + @test y4 ≈ y1 rtol = 1e-2 + end @testset "Weighted Diag Normal" begin @@ -369,15 +382,19 @@ function testDiagOp(N=32,K=2;arrayType = Array) prod1 = ProdOp(wop, op1) prod2 = ProdOp(wop, op2) prod3 = ProdOp(wop, op3) + prod4 = ProdOp(wop, op4) y = Array(adjoint(F) * adjoint(wop) * wop * F* x) y1 = Array(normalOperator(prod1) * x) y2 = Array(normalOperator(prod2) * x) y3 = Array(normalOperator(prod3) * x) + y4 = Array(normalOperator(prod4) * x) @test y ≈ y1 rtol = 1e-2 @test y1 ≈ y2 rtol = 1e-2 @test y2 ≈ y3 rtol = 1e-2 + @test y4 ≈ y1 rtol = 1e-2 + end end