Skip to content

Commit

Permalink
Algebraic operators for SparseMatrixCSCView
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Oct 13, 2023
1 parent 0f8bbda commit c093c1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Base: map, map!, broadcast, copy, copyto!

using Base: front, tail, to_shape

using ..SparseArrays: SparseVector, SparseMatrixCSC, FixedSparseCSC,
using ..SparseArrays: SparseVector, SparseMatrixCSC, FixedSparseCSC, SparseMatrixCSCView,
AbstractCompressedVector, AbstractSparseVector, AbstractSparseMatrixCSC,
AbstractSparseMatrix, AbstractSparseArray,
SparseVectorUnion, AdjOrTransSparseVectorUnion,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ _sparsifystructured(x) = x


# (12) map[!] over combinations of sparse and structured matrices
SparseOrStructuredMatrix = Union{FixedSparseCSC,SparseMatrixCSC,LinearAlgebra.StructuredMatrix}
SparseOrStructuredMatrix = Union{FixedSparseCSC,SparseMatrixCSC,SparseMatrixCSCView,LinearAlgebra.StructuredMatrix}
map(f::Tf, A::SparseOrStructuredMatrix, Bs::Vararg{SparseOrStructuredMatrix,N}) where {Tf,N} =
(_checksameshape(A, Bs...); _noshapecheck_map(f, _sparsifystructured(A), map(_sparsifystructured, Bs)...))
map!(f::Tf, C::AbstractSparseMatrixCSC, A::SparseOrStructuredMatrix, Bs::Vararg{SparseOrStructuredMatrix,N}) where {Tf,N} =
Expand Down
14 changes: 7 additions & 7 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2236,16 +2236,16 @@ function conj(A::AbstractSparseMatrixCSC{<:Complex})
map!(conj, view(nzval, 1:nnz(A)), nzvalview(A))
return SparseMatrixCSC(size(A, 1), size(A, 2), copy(getcolptr(A)), copy(rowvals(A)), nzval)
end
imag(A::AbstractSparseMatrixCSC{Tv,Ti}) where {Tv<:Real,Ti} = spzeros(Tv, Ti, size(A, 1), size(A, 2))
imag(A::SparseMatrixCSCView{Tv,Ti}) where {Tv<:Real,Ti} = spzeros(Tv, Ti, size(A, 1), size(A, 2))

## Binary arithmetic and boolean operators
(+)(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC) = map(+, A, B)
(-)(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC) = map(-, A, B)
(+)(A::SparseMatrixCSCView, B::SparseMatrixCSCView) = map(+, A, B)
(-)(A::SparseMatrixCSCView, B::SparseMatrixCSCView) = map(-, A, B)

(+)(A::AbstractSparseMatrixCSC, B::Array) = Array(A) + B
(+)(A::Array, B::AbstractSparseMatrixCSC) = A + Array(B)
(-)(A::AbstractSparseMatrixCSC, B::Array) = Array(A) - B
(-)(A::Array, B::AbstractSparseMatrixCSC) = A - Array(B)
(+)(A::SparseMatrixCSCView, B::Array) = Array(A) + B
(+)(A::Array, B::SparseMatrixCSCView) = A + Array(B)
(-)(A::SparseMatrixCSCView, B::Array) = Array(A) - B
(-)(A::Array, B::SparseMatrixCSCView) = A - Array(B)

## full equality
function ==(A1::AbstractSparseMatrixCSC, A2::AbstractSparseMatrixCSC)
Expand Down

0 comments on commit c093c1b

Please sign in to comment.