Skip to content

Commit 85c46b1

Browse files
committed
Deprecate remaining not-zero-preserving vectorized methods over SparseVectors.
1 parent f94f8eb commit 85c46b1

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

base/deprecated.jl

+8
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,14 @@ for op in (:floor, :ceil, :trunc, :round,
15771577
:sinh, :tanh, :asinh, :atanh)
15781578
@eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x)
15791579
end
1580+
# deprecate remaining vectorized methods over SparseVectors (not-zero-preserving)
1581+
for op in (:exp, :exp2, :exp10, :log, :log2, :log10,
1582+
:cos, :cosd, :acos, :cosh, :cospi,
1583+
:csc, :cscd, :acot, :csch, :acsch,
1584+
:cot, :cotd, :acosd, :coth,
1585+
:sec, :secd, :acotd, :sech, :asech)
1586+
@eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x)
1587+
end
15801588

15811589
# PR #22182
15821590
@deprecate is_apple Sys.isapple

base/sparse/sparsevector.jl

-10
Original file line numberDiff line numberDiff line change
@@ -1083,16 +1083,6 @@ macro unarymap_z2nz(op, TF)
10831083
end)
10841084
end
10851085

1086-
for op in [:exp, :exp2, :exp10, :log, :log2, :log10,
1087-
:cos, :csc, :cot, :sec, :cospi,
1088-
:cosd, :cscd, :cotd, :secd,
1089-
:acos, :acot, :acosd, :acotd,
1090-
:cosh, :csch, :coth, :sech,
1091-
:acsch, :asech]
1092-
@eval @unarymap_z2nz $(op) Number
1093-
end
1094-
1095-
10961086
### Binary Map
10971087

10981088
# mode:

test/sparse/sparsevector.jl

+12-14
Original file line numberDiff line numberDiff line change
@@ -677,20 +677,18 @@ end
677677

678678
### Non-zero-preserving math functions: sparse -> dense
679679

680-
function check_z2nz(f::Function, x::SparseVector{T}, xf::Vector{T}) where T
681-
R = typeof(f(zero(T)))
682-
r = f(x)
683-
isa(r, Vector) || error("$f(x) is not a dense vector.")
684-
eltype(r) == R || error("$f(x) results in eltype = $(eltype(r)), expect $R")
685-
r == f.(xf) || error("Incorrect results found in $f(x).")
686-
end
687-
688-
for f in [exp, exp2, exp10, log, log2, log10,
689-
cos, csc, cot, sec, cospi,
690-
cosd, cscd, cotd, secd,
691-
acos, acot, acosd, acotd,
692-
cosh, csch, coth, sech, acsch, asech]
693-
check_z2nz(f, rnd_x0, rnd_x0f)
680+
for op in (exp, exp2, exp10, log, log2, log10,
681+
cos, cosd, acos, cosh, cospi,
682+
csc, cscd, acot, csch, acsch,
683+
cot, cotd, acosd, coth,
684+
sec, secd, acotd, sech, asech)
685+
spvec = rnd_x0
686+
densevec = rnd_x0f
687+
spresvec = op.(spvec)
688+
@test spresvec == op.(densevec)
689+
resvaltype = typeof(op(zero(eltype(spvec))))
690+
resindtype = Base.SparseArrays.indtype(spvec)
691+
@test isa(spresvec, SparseVector{resvaltype,resindtype})
694692
end
695693

696694

0 commit comments

Comments
 (0)