Skip to content

Commit a5288ad

Browse files
committed
Add missing checks in expect
1 parent 350ad9c commit a5288ad

File tree

5 files changed

+6
-1
lines changed

5 files changed

+6
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "QuantumOpticsBase"
22
uuid = "4f57444f-1401-5e15-980d-4471b28d5678"
3-
version = "v0.2.5"
3+
version = "v0.2.6"
44

55
[deps]
66
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"

src/operators_dense.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function expect(op::DataOperator{B,B}, state::Ket{B}) where B<:Basis
152152
end
153153

154154
function expect(op::DataOperator{B1,B2}, state::DataOperator{B2,B2}) where {B1<:Basis,B2<:Basis}
155+
check_samebases(op, state)
155156
result = zero(promote_type(eltype(op),eltype(state)))
156157
@inbounds for i=1:size(op.data, 1), j=1:size(op.data,2)
157158
result += op.data[i,j]*state.data[j,i]

src/operators_sparse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function ptrace(op::SparseOpPureType, indices::Vector{Int})
4040
end
4141

4242
function expect(op::SparseOpPureType{B1,B2}, state::Operator{B2,B2}) where {B1<:Basis,B2<:Basis}
43+
check_samebases(op, state)
4344
result = zero(promote_type(eltype(op),eltype(state)))
4445
@inbounds for colindex = 1:op.data.n
4546
for i=op.data.colptr[colindex]:op.data.colptr[colindex+1]-1

test/test_operators_dense.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ state = randoperator(b_l)
249249
@test expect(2, op2, state) expect(op2, ptrace(state, [1, 3]))
250250
@test expect(3, op3, state) expect(op3, ptrace(state, [1, 2]))
251251

252+
@test_throws QuantumOpticsBase.IncompatibleBases expect(op2, op1)
253+
252254
# Permute systems
253255
op1 = randoperator(b1a, b1b)
254256
op2 = randoperator(b2a, b2b)

test/test_operators_sparse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ state = randstate(b_l)
150150
state = randoperator(b_l)
151151
@test expect(op123, state) expect(op123_, state)
152152

153+
@test_throws QuantumOpticsBase.IncompatibleBases expect(op1, op2)
153154

154155
# Tensor product
155156
# ==============

0 commit comments

Comments
 (0)