From 07a2d36c25dcb5b9c06ab185fbf4676cb8fc53df Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Fri, 14 Sep 2018 19:35:59 +0100 Subject: [PATCH] Define ' on Operator as dagger (#235) --- src/operators.jl | 1 + test/test_operators.jl | 1 + test/test_operators_dense.jl | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/src/operators.jl b/src/operators.jl index 7825b22e..c0c1a309 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -50,6 +50,7 @@ basis(a::Operator) = (check_samebases(a); a.basis_l) dagger(a::Operator) = arithmetic_unary_error("Hermitian conjugate", a) +Base.adjoint(a::Operator) = dagger(a) conj(a::Operator) = arithmetic_unary_error("Complex conjugate", a) conj!(a::Operator) = conj(a::Operator) diff --git a/test/test_operators.jl b/test/test_operators.jl index 6cfe14c7..586f815b 100644 --- a/test/test_operators.jl +++ b/test/test_operators.jl @@ -36,6 +36,7 @@ op_test3 = test_operators(b1 ⊗ b2, b2 ⊗ b1, randoperator(b, b).data) @test_throws ArgumentError op_test - 1 @test_throws ArgumentError dagger(op_test) +@test_throws ArgumentError op_test' @test_throws ArgumentError identityoperator(test_operators, b, b) @test_throws ArgumentError tr(op_test) @test_throws ArgumentError ptrace(op_test, [1]) diff --git a/test/test_operators_dense.jl b/test/test_operators_dense.jl index 2cda56fa..4cd5e3c0 100644 --- a/test/test_operators_dense.jl +++ b/test/test_operators_dense.jl @@ -26,6 +26,9 @@ op1 = DenseOperator(b1a, b1b, [1 1 1; 1 1 1]) op2 = DenseOperator(b1b, b1a, [1 1; 1 1; 1 1]) @test op1 == dagger(op2) +# Test ' shorthand +@test dagger(op2) == op2' + # Test copy op1 = randoperator(b1a) op2 = copy(op1) @@ -120,6 +123,7 @@ op123 = op1a ⊗ op2a ⊗ op3a # Transpose @test 1e-13 > D(dagger(op1a ⊗ op2a), dagger(op1a) ⊗ dagger(op2a)) +@test 1e-13 > D(dagger(op1a ⊗ op2a), dagger(op1a) ⊗ dagger(op2a)) # Internal layout a = Ket(b1a, rand(ComplexF64, length(b1a)))