Skip to content

Commit aff1d9e

Browse files
committed
Sparse support for AbstractQuMatrix.
1 parent c8fdb89 commit aff1d9e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/arrays/arraymath.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,23 @@ normalize(qarr::AbstractQuArray) = normalize!(copy(qarr))
153153
# matrix operations returning an array
154154
# sparse to dense
155155
function Base.full(qarr::AbstractQuMatrix)
156-
fc = full(rawcoeffs(qarr))
156+
fc = full(coeffs(qarr))
157157
QAT = similar_type(qarr)
158158
return QAT(fc, bases(qarr))
159159
end
160+
161+
# convert to a sparse matrix
162+
function Base.sparse(qarr::AbstractQuMatrix)
163+
sc = sparse(coeffs(qarr))
164+
QAT = similar_type(qarr)
165+
return QAT(sc, bases(qarr))
166+
end
167+
160168
#Base.full(ct::CTranspose) = full(ct.qarr)'
161169

162170
# exponential of dense matrix
163171
function Base.expm(qarr::AbstractQuMatrix)
164-
fc = expm(full(rawcoeffs(qarr)))
172+
fc = expm(full(coeffs(qarr)))
165173
QAT = similar_type(qarr)
166174
return QAT(fc, bases(qarr))
167175
end

test/multest.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ qv1 = normalize!(QuArray(v1))
5555

5656
# Vectorize
5757
@assert vec(qv) == vec(qv')
58+
59+
# Sparse matrix
60+
@assert sparse(sigmax)*sparse(sigmax) == sparse(QuArray(eye(2)))

0 commit comments

Comments
 (0)