Skip to content

Commit

Permalink
Merge pull request #29 from ytdHuang/dev/eltype
Browse files Browse the repository at this point in the history
support `Base.eltype` for `QuantumObject`
  • Loading branch information
albertomercurio authored Mar 18, 2024
2 parents 09d2b0b + 8f4926c commit c744b15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ isket
isoper
issuper
size
eltype
length
LinearAlgebra.tr
LinearAlgebra.norm
Expand Down
7 changes: 7 additions & 0 deletions src/quantum_object.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ Base.size(A::QuantumObject{<:AbstractArray{T},OpType}, inds...) where {T,OpType<
Base.getindex(A::QuantumObject{<:AbstractArray{T},OpType}, inds...) where {T,OpType<:QuantumObjectType} = getindex(A.data, inds...)
Base.setindex!(A::QuantumObject{<:AbstractArray{T},OpType}, val, inds...) where {T,OpType<:QuantumObjectType} = setindex!(A.data, val, inds...)

"""
eltype(A::QuantumObject)
Returns the elements type of the matrix or vector corresponding to the [`QuantumObject`](@ref) `A`.
"""
Base.eltype(A::QuantumObject) = eltype(A.data)

# Broadcasting
Base.broadcastable(x::QuantumObject) = x.data
for op in (:(+), :(-), :(*), :(/), :(^))
Expand Down

0 comments on commit c744b15

Please sign in to comment.