Skip to content

Commit

Permalink
rename SparseMatrixCSC -> SparseMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 18, 2017
1 parent 7fb5d27 commit a676cc6
Show file tree
Hide file tree
Showing 34 changed files with 851 additions and 980 deletions.
12 changes: 7 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,21 +645,21 @@ Deprecated or removed

* `full` has been deprecated in favor of more specific, better defined alternatives.
On structured matrices `A`, consider instead `Matrix(A)`, `Array(A)`,
`SparseMatrixCSC(A)`, or `sparse(A)`. On sparse arrays `S`, consider instead
`SparseMatrix(A)`, or `sparse(A)`. On sparse arrays `S`, consider instead
`Vector(S)`, `Matrix(S)`, or `Array(S)` as appropriate. On factorizations `F`,
consider instead `Matrix(F)`, `Array(F)`, `AbstractMatrix(F)`, or `AbstractArray(F)`.
On implicit orthogonal factors `Q`, consider instead `Matrix(Q)` or `Array(Q)`; for
implicit orthogonal factors that can be recovered in square or truncated form,
see the deprecation message for square recovery instructions. On `Symmetric`,
`Hermitian`, or `AbstractTriangular` matrices `A`, consider instead `Matrix(S)`,
`Array(S)`, `SparseMatrixCSC(S)`, or `sparse(S)`. On `Symmetric` matrices `A`
`Array(S)`, `SparseMatrix(S)`, or `sparse(S)`. On `Symmetric` matrices `A`
particularly, consider instead `LinAlg.copytri!(copy(parent(A)), A.uplo)`. On
`Hermitian` matrices `A` particularly, consider instead
`LinAlg.copytri!(copy(parent(A)), A.uplo, true)`. On `UpperTriangular` matrices `A`
particularly, consider instead `triu!(copy(parent(A)))`. On `LowerTriangular` matrices
`A` particularly, consider instead `tril!(copy(parent(A)))` ([#24250]).

* `speye` has been deprecated in favor of `I`, `sparse`, and `SparseMatrixCSC`
* `speye` has been deprecated in favor of `I`, `sparse`, and `SparseMatrix`
constructor methods ([#24356]).

* Calling `union` with no arguments is deprecated; construct an empty set with an appropriate
Expand Down Expand Up @@ -690,7 +690,7 @@ Deprecated or removed

* `diagm(x::Number)` has been deprecated in favor of `fill(x, 1, 1)` ([#24047]).

* `diagm(A::SparseMatrixCSC)` has been deprecated in favor of
* `diagm(A::SparseMatrix)` has been deprecated in favor of
`spdiagm(sparsevec(A))` ([#23341]).

* `diagm(A::BitMatrix)` has been deprecated, use `diagm(0 => vec(A))` or
Expand Down Expand Up @@ -810,6 +810,8 @@ Deprecated or removed

* `Associative` has been deprecated in favor of `AbstractDict` ([#25012]).

* `SparseMatrixCSC` has been renamed `SparseMatrix` ([#25151]).

* `Nullable{T}` has been deprecated and moved to the Nullables package ([#23642]).
Use `Union{T, Void}` instead, or `Union{Some{T}, Void}` if `nothing` is a possible value
(i.e. `Void <: T`). `isnull(x)` can be replaced with `x === nothing`
Expand Down Expand Up @@ -1248,7 +1250,7 @@ Library improvements
* `map[!]` and `broadcast[!]` now have dedicated methods for sparse/structured
vectors/matrices. Specifically, `map[!]` and `broadcast[!]` over combinations including
one or more `SparseVector`, `SparseMatrixCSC`, `Diagonal`, `Bidiagonal`, `Tridiagonal`,
one or more `SparseVector`, `SparseMatrix`, `Diagonal`, `Bidiagonal`, `Tridiagonal`,
or `SymTridiagonal`, and any number of `broadcast` scalars, `Vector`s, or `Matrix`s,
now efficiently yield `SparseVector`s or `SparseMatrix`s as appropriate ([#19239],
[#19371], [#19518], [#19438], [#19690], [#19724], [#19926], [#19934], [#20009]).
Expand Down
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ Example for a sparse 2-d array:
```jldoctest
julia> A = sparse([1, 1, 2], [1, 3, 1], [1, 2, -5])
2×3 SparseMatrixCSC{Int64,Int64} with 3 stored entries:
2×3 SparseMatrix{Int64,Int64} with 3 stored entries:
[1, 1] = 1
[2, 1] = -5
[1, 3] = 2
Expand Down
2 changes: 1 addition & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The `N` parameter is the dimensionality, which can be handy for AbstractArray ty
that only support specific dimensionalities:
struct SparseMatrixStyle <: Broadcast.AbstractArrayStyle{2} end
Base.BroadcastStyle(::Type{<:SparseMatrixCSC}) = SparseMatrixStyle()
Base.BroadcastStyle(::Type{<:SparseMatrix}) = SparseMatrixStyle()
For AbstractArray types that support arbitrary dimensionality, `N` can be set to `Any`:
Expand Down
289 changes: 79 additions & 210 deletions base/deprecated.jl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ Similarly, if `T` is a composite type and `x` a related instance, the result of
julia> x = sparse(1.0I, 5, 5);
julia> typeof(x)
SparseMatrixCSC{Float64,Int64}
SparseMatrix{Float64,Int64}
julia> y = convert(SparseMatrixCSC{Float64,Int64}, x);
julia> y = convert(SparseMatrix{Float64,Int64}, x);
julia> z = convert(SparseMatrixCSC{Float32,Int64}, y);
julia> z = convert(SparseMatrix{Float32,Int64}, y);
julia> y === x
true
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ export
AbstractSparseArray,
AbstractSparseMatrix,
AbstractSparseVector,
SparseMatrixCSC,
SparseMatrix,
SparseVector,
issparse,
sparse,
Expand Down
4 changes: 2 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ Get the name of field `i` of a `DataType`.
# Examples
```jldoctest
julia> fieldname(SparseMatrixCSC, 1)
julia> fieldname(SparseMatrix, 1)
:m
julia> fieldname(SparseMatrixCSC, 5)
julia> fieldname(SparseMatrix, 5)
:nzval
```
"""
Expand Down
58 changes: 29 additions & 29 deletions base/sparse/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
module HigherOrderFns

# This module provides higher order functions specialized for sparse arrays,
# particularly map[!]/broadcast[!] for SparseVectors and SparseMatrixCSCs at present.
# particularly map[!]/broadcast[!] for SparseVectors and SparseMatrixs at present.
import Base: map, map!, broadcast, broadcast!

using Base: front, tail, to_shape
using ..SparseArrays: SparseVector, SparseMatrixCSC, AbstractSparseVector,
using ..SparseArrays: SparseVector, SparseMatrix, AbstractSparseVector,
AbstractSparseMatrix, AbstractSparseArray, indtype, nnz, nzrange
using Base.Broadcast: BroadcastStyle

# This module is organized as follows:
# (1) Define a common interface to SparseVectors and SparseMatrixCSCs sufficient for
# (1) Define a common interface to SparseVectors and SparseMatrixs sufficient for
# map[!]/broadcast[!]'s purposes. The methods below are written against this interface.
# (2) Define entry points for map[!] (short children of _map_[not]zeropres!).
# (3) Define entry points for broadcast[!] (short children of _broadcast_[not]zeropres!).
Expand All @@ -32,25 +32,25 @@ using Base.Broadcast: BroadcastStyle
# sufficient for the purposes of map[!]/broadcast[!]. This interface treats sparse vectors
# as n-by-one sparse matrices which, though technically incorrect, is how broacast[!] views
# sparse vectors in practice.
SparseVecOrMat = Union{SparseVector,SparseMatrixCSC}
SparseVecOrMat = Union{SparseVector,SparseMatrix}
@inline numrows(A::SparseVector) = A.n
@inline numrows(A::SparseMatrixCSC) = A.m
@inline numrows(A::SparseMatrix) = A.m
@inline numcols(A::SparseVector) = 1
@inline numcols(A::SparseMatrixCSC) = A.n
@inline numcols(A::SparseMatrix) = A.n
# numrows and numcols respectively yield size(A, 1) and size(A, 2), but avoid a branch
@inline columns(A::SparseVector) = 1
@inline columns(A::SparseMatrixCSC) = 1:A.n
@inline columns(A::SparseMatrix) = 1:A.n
@inline colrange(A::SparseVector, j) = 1:length(A.nzind)
@inline colrange(A::SparseMatrixCSC, j) = nzrange(A, j)
@inline colrange(A::SparseMatrix, j) = nzrange(A, j)
@inline colstartind(A::SparseVector, j) = one(indtype(A))
@inline colboundind(A::SparseVector, j) = convert(indtype(A), length(A.nzind) + 1)
@inline colstartind(A::SparseMatrixCSC, j) = A.colptr[j]
@inline colboundind(A::SparseMatrixCSC, j) = A.colptr[j + 1]
@inline colstartind(A::SparseMatrix, j) = A.colptr[j]
@inline colboundind(A::SparseMatrix, j) = A.colptr[j + 1]
@inline storedinds(A::SparseVector) = A.nzind
@inline storedinds(A::SparseMatrixCSC) = A.rowval
@inline storedinds(A::SparseMatrix) = A.rowval
@inline storedvals(A::SparseVecOrMat) = A.nzval
@inline setcolptr!(A::SparseVector, j, val) = val
@inline setcolptr!(A::SparseMatrixCSC, j, val) = A.colptr[j] = val
@inline setcolptr!(A::SparseMatrix, j, val) = A.colptr[j] = val
function trimstorage!(A::SparseVecOrMat, maxstored)
resize!(storedinds(A), maxstored)
resize!(storedvals(A), maxstored)
Expand All @@ -65,12 +65,12 @@ end

# (2) map[!] entry points
map(f::Tf, A::SparseVector) where {Tf} = _noshapecheck_map(f, A)
map(f::Tf, A::SparseMatrixCSC) where {Tf} = _noshapecheck_map(f, A)
map(f::Tf, A::SparseMatrixCSC, Bs::Vararg{SparseMatrixCSC,N}) where {Tf,N} =
map(f::Tf, A::SparseMatrix) where {Tf} = _noshapecheck_map(f, A)
map(f::Tf, A::SparseMatrix, Bs::Vararg{SparseMatrix,N}) where {Tf,N} =
(_checksameshape(A, Bs...); _noshapecheck_map(f, A, Bs...))
map(f::Tf, A::SparseVecOrMat, Bs::Vararg{SparseVecOrMat,N}) where {Tf,N} =
(_checksameshape(A, Bs...); _noshapecheck_map(f, A, Bs...))
map!(f::Tf, C::SparseMatrixCSC, A::SparseMatrixCSC, Bs::Vararg{SparseMatrixCSC,N}) where {Tf,N} =
map!(f::Tf, C::SparseMatrix, A::SparseMatrix, Bs::Vararg{SparseMatrix,N}) where {Tf,N} =
(_checksameshape(C, A, Bs...); _noshapecheck_map!(f, C, A, Bs...))
map!(f::Tf, C::SparseVecOrMat, A::SparseVecOrMat, Bs::Vararg{SparseVecOrMat,N}) where {Tf,N} =
(_checksameshape(C, A, Bs...); _noshapecheck_map!(f, C, A, Bs...))
Expand All @@ -92,7 +92,7 @@ function _noshapecheck_map(f::Tf, A::SparseVecOrMat, Bs::Vararg{SparseVecOrMat,N
end
# (3) broadcast[!] entry points
broadcast(f::Tf, A::SparseVector) where {Tf} = _noshapecheck_map(f, A)
broadcast(f::Tf, A::SparseMatrixCSC) where {Tf} = _noshapecheck_map(f, A)
broadcast(f::Tf, A::SparseMatrix) where {Tf} = _noshapecheck_map(f, A)
function broadcast!(f::Tf, C::SparseVecOrMat) where Tf
isempty(C) && return _finishempty!(C)
fofnoargs = f()
Expand All @@ -117,7 +117,7 @@ end
# the following three similar defs are necessary for type stability in the mixed vector/matrix case
broadcast(f::Tf, A::SparseVector, Bs::Vararg{SparseVector,N}) where {Tf,N} =
_aresameshape(A, Bs...) ? _noshapecheck_map(f, A, Bs...) : _diffshape_broadcast(f, A, Bs...)
broadcast(f::Tf, A::SparseMatrixCSC, Bs::Vararg{SparseMatrixCSC,N}) where {Tf,N} =
broadcast(f::Tf, A::SparseMatrix, Bs::Vararg{SparseMatrix,N}) where {Tf,N} =
_aresameshape(A, Bs...) ? _noshapecheck_map(f, A, Bs...) : _diffshape_broadcast(f, A, Bs...)
broadcast(f::Tf, A::SparseVecOrMat, Bs::Vararg{SparseVecOrMat,N}) where {Tf,N} =
_diffshape_broadcast(f, A, Bs...)
Expand Down Expand Up @@ -150,7 +150,7 @@ end
@inline _densennz(shape::NTuple{2}) = shape[1] * shape[2]
_maxnnzfrom(shape::NTuple{1}, A) = nnz(A) * div(shape[1], A.n)
_maxnnzfrom(shape::NTuple{2}, A::SparseVector) = nnz(A) * div(shape[1], A.n) * shape[2]
_maxnnzfrom(shape::NTuple{2}, A::SparseMatrixCSC) = nnz(A) * div(shape[1], A.m) * div(shape[2], A.n)
_maxnnzfrom(shape::NTuple{2}, A::SparseMatrix) = nnz(A) * div(shape[1], A.m) * div(shape[2], A.n)
@inline _maxnnzfrom_each(shape, ::Tuple{}) = ()
@inline _maxnnzfrom_each(shape, As) = (_maxnnzfrom(shape, first(As)), _maxnnzfrom_each(shape, tail(As))...)
@inline _unchecked_maxnnzbcres(shape, As::Tuple) = min(_densennz(shape), sum(_maxnnzfrom_each(shape, As)))
Expand All @@ -166,7 +166,7 @@ end
pointers = Vector{indextype}(uninitialized, shape[2] + 1)
storedinds = Vector{indextype}(uninitialized, maxnnz)
storedvals = Vector{entrytype}(uninitialized, maxnnz)
return SparseMatrixCSC(shape..., pointers, storedinds, storedvals)
return SparseMatrix(shape..., pointers, storedinds, storedvals)
end
# Ambiguity killers, TODO: nix conflicting specializations
ambiguityfunnel(f::Tf, x, y) where {Tf} = _aresameshape(x, y) ? _noshapecheck_map(f, x, y) : _diffshape_broadcast(f, x, y)
Expand Down Expand Up @@ -217,13 +217,13 @@ function _map_notzeropres!(f::Tf, fillvalue, C::SparseVecOrMat, A::SparseVecOrMa
end
# helper functions for these methods and some of those below
@inline _densecoloffsets(A::SparseVector) = 0
@inline _densecoloffsets(A::SparseMatrixCSC) = 0:A.m:(A.m*(A.n - 1))
@inline _densecoloffsets(A::SparseMatrix) = 0:A.m:(A.m*(A.n - 1))
function _densestructure!(A::SparseVector)
expandstorage!(A, A.n)
copyto!(A.nzind, 1:A.n)
return A
end
function _densestructure!(A::SparseMatrixCSC)
function _densestructure!(A::SparseMatrix)
nnzA = A.m * A.n
expandstorage!(A, nnzA)
copyto!(A.colptr, 1:A.m:(nnzA + 1))
Expand Down Expand Up @@ -747,7 +747,7 @@ function _broadcast_notzeropres!(f::Tf, fillvalue, C::SparseVecOrMat, A::SparseV
return C
end
_finishempty!(C::SparseVector) = C
_finishempty!(C::SparseMatrixCSC) = (fill!(C.colptr, 1); C)
_finishempty!(C::SparseMatrix) = (fill!(C.colptr, 1); C)


# (9) _broadcast_zeropres!/_broadcast_notzeropres! for more than two (input) sparse vectors/matrices
Expand Down Expand Up @@ -902,7 +902,7 @@ end
struct SparseVecStyle <: Broadcast.AbstractArrayStyle{1} end
struct SparseMatStyle <: Broadcast.AbstractArrayStyle{2} end
Broadcast.BroadcastStyle(::Type{<:SparseVector}) = SparseVecStyle()
Broadcast.BroadcastStyle(::Type{<:SparseMatrixCSC}) = SparseMatStyle()
Broadcast.BroadcastStyle(::Type{<:SparseMatrix}) = SparseMatStyle()
const SPVM = Union{SparseVecStyle,SparseMatStyle}

# SparseVecStyle handles 0-1 dimensions, SparseMatStyle 0-2 dimensions.
Expand Down Expand Up @@ -966,8 +966,8 @@ end
end

# NOTE: The following two method definitions work around #19096.
broadcast(f::Tf, ::Type{T}, A::SparseMatrixCSC) where {Tf,T} = broadcast(y -> f(T, y), A)
broadcast(f::Tf, A::SparseMatrixCSC, ::Type{T}) where {Tf,T} = broadcast(x -> f(x, T), A)
broadcast(f::Tf, ::Type{T}, A::SparseMatrix) where {Tf,T} = broadcast(y -> f(T, y), A)
broadcast(f::Tf, A::SparseMatrix, ::Type{T}) where {Tf,T} = broadcast(x -> f(x, T), A)


# (11) broadcast[!] over combinations of scalars, sparse vectors/matrices, structured matrices,
Expand Down Expand Up @@ -1030,21 +1030,21 @@ function spbroadcast_args!(f, dest, ::Any, mixedsrcargs::Vararg{Any,N}) where N
Broadcast._broadcast!(f, dest, mixedsrcargs...)
end

_sparsifystructured(M::AbstractMatrix) = SparseMatrixCSC(M)
_sparsifystructured(M::AbstractMatrix) = SparseMatrix(M)
_sparsifystructured(V::AbstractVector) = SparseVector(V)
_sparsifystructured(P::AbstractArray{<:Any,0}) = SparseVector(reshape(P, 1))
_sparsifystructured(M::AbstractSparseMatrix) = SparseMatrixCSC(M)
_sparsifystructured(M::AbstractSparseMatrix) = SparseMatrix(M)
_sparsifystructured(V::AbstractSparseVector) = SparseVector(V)
_sparsifystructured(S::SparseVecOrMat) = S
_sparsifystructured(x) = x


# (12) map[!] over combinations of sparse and structured matrices
SparseOrStructuredMatrix = Union{SparseMatrixCSC,StructuredMatrix}
SparseOrStructuredMatrix = Union{SparseMatrix,StructuredMatrix}
map(f::Tf, A::StructuredMatrix) where {Tf} = _noshapecheck_map(f, _sparsifystructured(A))
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::SparseMatrixCSC, A::SparseOrStructuredMatrix, Bs::Vararg{SparseOrStructuredMatrix,N}) where {Tf,N} =
map!(f::Tf, C::SparseMatrix, A::SparseOrStructuredMatrix, Bs::Vararg{SparseOrStructuredMatrix,N}) where {Tf,N} =
(_checksameshape(C, A, Bs...); _noshapecheck_map!(f, C, _sparsifystructured(A), map(_sparsifystructured, Bs)...))

end
Loading

0 comments on commit a676cc6

Please sign in to comment.