Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate count_ones and count_zeros to countones and countzeros #23531

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ Deprecated or removed
* The `cholfact`/`cholfact!` methods that accepted an `uplo` symbol have been deprecated
in favor of using `Hermitian` (or `Symmetric`) views ([#22187], [#22188]).

* `count_ones` and `count_zeros` have been renamed
`countones` and `countzeros` ([#23531]).

* `isposdef(A::AbstractMatrix, UL::Symbol)` and `isposdef!(A::AbstractMatrix, UL::Symbol)`
have been deprecated in favor of `isposdef(Hermitian(A, UL))` and `isposdef!(Hermitian(A, UL))`
respectively ([#22245]).
Expand Down
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ function count(B::BitArray)
n = 0
Bc = B.chunks
@inbounds for i = 1:length(Bc)
n += count_ones(Bc[i])
n += countones(Bc[i])
end
return n
end
Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,10 @@ function countnz(x)
return count(t -> t != 0, x)
end

# deprecate count_ones and count_zeros to countones and countzeros
@deprecate count_ones countones
@deprecate count_zeros countzeros

# issue #22791
@deprecate select partialsort
@deprecate select! partialsort!
Expand Down
4 changes: 2 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ export
cot,
cotd,
coth,
count_ones,
count_zeros,
countones,
countzeros,
csc,
cscd,
csch,
Expand Down
4 changes: 2 additions & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export BigInt
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod,
ndigits, promote_rule, rem, show, isqrt, string, powermod,
sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal,
sum, trailing_zeros, trailing_ones, countones, base, tryparse_internal,
bin, oct, dec, hex, isequal, invmod, prevpow2, nextpow2, ndigits0zpb,
widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit,
hastypemax
Expand Down Expand Up @@ -473,7 +473,7 @@ end
trailing_zeros(x::BigInt) = MPZ.scan1(x, 0)
trailing_ones(x::BigInt) = MPZ.scan0(x, 0)

count_ones(x::BigInt) = MPZ.popcount(x)
countones(x::BigInt) = MPZ.popcount(x)

"""
count_ones_abs(x::BigInt)
Expand Down
12 changes: 6 additions & 6 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,16 @@ bswap(x::Union{Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128}) =
bswap_int(x)

"""
count_ones(x::Integer) -> Integer
countones(x::Integer) -> Integer

Number of ones in the binary representation of `x`.

```jldoctest
julia> count_ones(7)
julia> countones(7)
3
```
"""
count_ones(x::BitInteger) = Int(ctpop_int(x))
countones(x::BitInteger) = Int(ctpop_int(x))

"""
leading_zeros(x::Integer) -> Integer
Expand All @@ -355,16 +355,16 @@ julia> trailing_zeros(2)
trailing_zeros(x::BitInteger) = Int(cttz_int(x))

"""
count_zeros(x::Integer) -> Integer
countzeros(x::Integer) -> Integer

Number of zeros in the binary representation of `x`.

```jldoctest
julia> count_zeros(Int32(2 ^ 16 - 1))
julia> countzeros(Int32(2 ^ 16 - 1))
16
```
"""
count_zeros(x::Integer) = count_ones(~x)
countzeros(x::Integer) = countones(~x)

"""
leading_ones(x::Integer) -> Integer
Expand Down
2 changes: 1 addition & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ julia> ispow2(5)
false
```
"""
ispow2(x::Integer) = x > 0 && count_ones(x) == 1
ispow2(x::Integer) = x > 0 && countones(x) == 1

"""
nextpow(a, x)
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function dot(x::BitVector, y::BitVector)
xc = x.chunks
yc = y.chunks
@inbounds for i = 1:length(xc)
s += count_ones(xc[i] & yc[i])
s += countones(xc[i] & yc[i])
end
s
end
Expand All @@ -33,7 +33,7 @@ end
#for j = 1:nB
#for k = 1:col_ch
## TODO: improve
#C[i, j] += count_ones(aux_chunksA[k] & aux_chunksB[j][k])
#C[i, j] += countones(aux_chunksA[k] & aux_chunksB[j][k])
#end
#end
#end
Expand Down
2 changes: 1 addition & 1 deletion base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fma(x::Rational, y::Rational, z::Rational) = x*y+z

function ==(x::AbstractFloat, q::Rational)
if isfinite(x)
(count_ones(q.den) == 1) & (x*q.den == q.num)
(countones(q.den) == 1) & (x*q.den == q.num)
else
x == q.num/q.den
end
Expand Down
4 changes: 2 additions & 2 deletions doc/src/stdlib/numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Base.Rounding.set_zero_subnormals
### Integers

```@docs
Base.count_ones
Base.count_zeros
Base.countones
Base.countzeros
Base.leading_zeros
Base.leading_ones
Base.trailing_zeros
Expand Down
2 changes: 1 addition & 1 deletion test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ g = parse(BigInt,"-1")

@test trailing_ones(a) == 8
@test trailing_zeros(b) == 2
@test count_ones(a) == 14
@test countones(a) == 14

# Large Fibonacci to exercise BigInt
# from Bill Hart, https://groups.google.com/group/julia-dev/browse_frm/thread/798e2d1322daf633
Expand Down
4 changes: 2 additions & 2 deletions test/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ end
@test bswap(Int128(2)^(15*8)) == Int128(1)
@test bswap(UInt128(2)^(15*8)) == UInt128(1)

@test count_zeros(10) == Sys.WORD_SIZE - 2
@test count_zeros(UInt8(10)) == 6
@test countzeros(10) == Sys.WORD_SIZE - 2
@test countzeros(UInt8(10)) == 6

@test convert(Signed, UInt128(3)) === Int128(3)
@test convert(Signed, false) === 0
Expand Down
2 changes: 1 addition & 1 deletion test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ end
@test leading_zeros(Int32(1)) == 31
@test leading_zeros(UInt32(Int64(2) ^ 32 - 2)) == 0

@test count_zeros(Int64(1)) == 63
@test countzeros(Int64(1)) == 63

@test factorial(3) == 6
@test factorial(Int8(3)) === 6
Expand Down
2 changes: 1 addition & 1 deletion test/perf/shootout/meteor_contest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const masksAtCell = Array{Any}(width*height, height)

valid(x, y) = (0 <= x < width) && (0 <= y < height)
legal(mask::UInt64, board::UInt64) = (mask & board) == 0
zerocount(mask::UInt64) = 50 - count_ones(mask)
zerocount(mask::UInt64) = 50 - countones(mask)

function findFreeCell(board::UInt64)
for y in 0:height-1
Expand Down