Skip to content

Commit afe6847

Browse files
authored
float(S) and complex(S) should not copy data unnecessarily (#340)
1 parent fee88bb commit afe6847

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/sparsematrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@ convert(T::Type{<:LowerTriangular}, m::AbstractSparseMatrixCSC) = m isa T ? m :
970970
convert(T::Type{<:UpperTriangular}, m::AbstractSparseMatrixCSC) = m isa T ? m :
971971
istriu(m) ? T(m) : throw(ArgumentError("matrix cannot be represented as UpperTriangular"))
972972

973-
float(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), float.(nonzeros(S)))
974-
complex(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), copy(getcolptr(S)), copy(rowvals(S)), complex(copy(nonzeros(S))))
973+
float(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), getcolptr(S), rowvals(S), float(nonzeros(S)))
974+
complex(S::SparseMatrixCSC) = SparseMatrixCSC(size(S, 1), size(S, 2), getcolptr(S), rowvals(S), complex(nonzeros(S)))
975975

976976
"""
977977
sparse(A)

src/sparsevector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,11 +1086,11 @@ copy(x::AbstractSparseVector) = if _is_fixed(x)
10861086

10871087
float(x::AbstractSparseVector{<:AbstractFloat}) = x
10881088
float(x::AbstractSparseVector) =
1089-
SparseVector(length(x), copy(nonzeroinds(x)), float(nonzeros(x)))
1089+
SparseVector(length(x), nonzeroinds(x), float(nonzeros(x)))
10901090

10911091
complex(x::AbstractSparseVector{<:Complex}) = x
10921092
complex(x::AbstractSparseVector) =
1093-
SparseVector(length(x), copy(nonzeroinds(x)), complex(nonzeros(x)))
1093+
SparseVector(length(x), nonzeroinds(x), complex(nonzeros(x)))
10941094

10951095

10961096
### Concatenation

0 commit comments

Comments
 (0)