Skip to content

Commit

Permalink
Deprecate a few remaining vectorized methods over SparseVectors. (And…
Browse files Browse the repository at this point in the history
… associated cleanup.)
  • Loading branch information
Sacha0 committed Dec 31, 2016
1 parent 77e98d3 commit f488610
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
1 change: 0 additions & 1 deletion base/sparse/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ end
return SparseMatrixCSC(shape..., pointers, storedinds, storedvals)
end
# Ambiguity killers, TODO: nix conflicting specializations
broadcast(::typeof(abs), x::SparseVector) = _noshapecheck_map(abs, x) # base/sparse/sparevectors.jl: 921
ambiguityfunnel{Tf}(f::Tf, x, y) = _aresameshape(x, y) ? _noshapecheck_map(f, x, y) : _diffshape_broadcast(f, x, y)
broadcast(::typeof(+), x::SparseVector, y::SparseVector) = ambiguityfunnel(+, x, y) # base/sparse/sparsevectors.jl:1266
broadcast(::typeof(-), x::SparseVector, y::SparseVector) = ambiguityfunnel(-, x, y) # base/sparse/sparsevectors.jl:1266
Expand Down
33 changes: 13 additions & 20 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,8 @@ hvcat{T}(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) = Base.type
### Unary Map

# zero-preserving functions (z->z, nz->nz)
broadcast(::typeof(abs), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs.(nonzeros(x)))
for op in [:conj]
@eval begin
$(op)(x::AbstractSparseVector) =
SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x)))
end
end
-(x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), -(nonzeros(x)))
conj(x::SparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), conj(nonzeros(x)))
-(x::SparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), -(nonzeros(x)))

# functions f, such that
# f(x) can be zero or non-zero when x != 0
Expand Down Expand Up @@ -1271,18 +1265,17 @@ end

# definition of other binary functions

for (op, TF, mode) in [(:max, :Real, 2),
(:min, :Real, 2),
(:complex, :Real, 1)]
@eval begin
$(op){Tx<:$(TF),Ty<:$(TF)}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) =
_binarymap($(op), x, y, $mode)
$(op){Tx<:$(TF),Ty<:$(TF)}(x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) =
_binarymap($(op), x, y, $mode)
$(op){Tx<:$(TF),Ty<:$(TF)}(x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) =
_binarymap($(op), x, y, $mode)
end
end
broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2)
broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::StridedVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2)
broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2)

broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2)
broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::StridedVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2)
broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2)

complex{Tx<:Real,Ty<:Real}(x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(complex, x, y, 1)
complex{Tx<:Real,Ty<:Real}(x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) = _binarymap(complex, x, y, 1)
complex{Tx<:Real,Ty<:Real}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(complex, x, y, 1)

### Reduction

Expand Down
8 changes: 4 additions & 4 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,11 @@ let x = spv_x1, x2 = spv_x2
@test x .* Array(x2) == Array(xm)

# max & min
@test exact_equal(max(x, x), x)
@test exact_equal(min(x, x), x)
@test exact_equal(max(x, x2),
@test exact_equal(max.(x, x), x)
@test exact_equal(min.(x, x), x)
@test exact_equal(max.(x, x2),
SparseVector(8, Int[1, 2, 6], Float64[3.25, 4.0, 3.5]))
@test exact_equal(min(x, x2),
@test exact_equal(min.(x, x2),
SparseVector(8, Int[2, 5, 6, 7], Float64[1.25, -0.75, -5.5, -6.0]))
end

Expand Down

0 comments on commit f488610

Please sign in to comment.