Skip to content

Commit

Permalink
Added copyto!() and similar()
Browse files Browse the repository at this point in the history
  • Loading branch information
jlbosse committed Dec 1, 2022
1 parent 9f7bf90 commit 1d7ff11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FLOYao"
uuid = "6d9310a3-f1d0-41b7-8edb-11c1cf57cd2d"
authors = ["janlukas.bosse <[email protected]> and contributors"]
version = "1.2.0"
version = "1.2.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
14 changes: 10 additions & 4 deletions src/majorana_reg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ Yao.nqudits(reg::MajoranaReg) = size(reg.state, 1) ÷ 2
Yao.nactive(reg::MajoranaReg) = Yao.nqubits(reg)
Yao.nbatch(reg::MajoranaReg) = 1
Yao.nremain(reg::MajoranaReg) = 0
Base.copy(reg::MajoranaReg) = MajoranaReg(copy(reg.state))
Yao.state(reg::MajoranaReg) = reg.state
Base.eltype(::MajoranaReg{T}) where {T} = T
Yao.datatype(::MajoranaReg{T}) where {T} = T
Yao.state(reg::MajoranaReg) = reg.state
Base.copy(reg::MajoranaReg) = MajoranaReg(copy(reg.state))
Base.similar(reg::MajoranaReg) = MajoranaReg(similar(reg.state))

function Base.copyto!(dst::MajoranaReg, src::MajoranaReg)
nqubits(dst) != nqubits(src) && throw(DimensionMismatch("nqubits(dst) = $(nqubits(dst)) != nqubits(src) = $(nqubits(src))"))
copyto!(state(dst), state(src))
end


function Base.:(==)(lhs::MajoranaReg, rhs::MajoranaReg)
return nqubits(lhs) == nqubits(rhs) && state(lhs) == state(rhs)
Expand All @@ -59,15 +66,14 @@ end
# the jupyter cell output
function Base.show(io::IO, ::MIME"text/plain", reg::MajoranaReg)
println(io, typeof(reg), " with $(Yao.nqubits(reg)) qubits:")
Base.print_array(io, reg.state)
Base.print_array(io, state(reg))
end

# Less detailed version that is used e.g. in string interpolations
function Base.show(io::IO, reg::MajoranaReg)
print(io, typeof(reg), "($(nqubits(reg)))")
end


"""
majorana2arrayreg(reg::MajoranaReg)
Expand Down

0 comments on commit 1d7ff11

Please sign in to comment.