Skip to content

Commit 9a2a1c9

Browse files
committed
Rename count_ones and count_zeros to countones and countzeros.
1 parent 383b919 commit 9a2a1c9

14 files changed

+29
-22
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ Deprecated or removed
271271
* The `cholfact`/`cholfact!` methods that accepted an `uplo` symbol have been deprecated
272272
in favor of using `Hermitian` (or `Symmetric`) views ([#22187], [#22188]).
273273

274+
* `count_ones` and `count_zeros` have been renamed
275+
`countones` and `countzeros` ([#MEW]).
276+
274277
* `isposdef(A::AbstractMatrix, UL::Symbol)` and `isposdef!(A::AbstractMatrix, UL::Symbol)`
275278
have been deprecated in favor of `isposdef(Hermitian(A, UL))` and `isposdef!(Hermitian(A, UL))`
276279
respectively ([#22245]).

base/bitarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ function count(B::BitArray)
15031503
n = 0
15041504
Bc = B.chunks
15051505
@inbounds for i = 1:length(Bc)
1506-
n += count_ones(Bc[i])
1506+
n += countones(Bc[i])
15071507
end
15081508
return n
15091509
end

base/deprecated.jl

+4
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,10 @@ function countnz(x)
17251725
return count(t -> t != 0, x)
17261726
end
17271727

1728+
# deprecate count_ones and count_zeros to countones and countzeros
1729+
@deprecate count_ones countones
1730+
@deprecate count_zeros countzeros
1731+
17281732
# issue #22791
17291733
@deprecate select partialsort
17301734
@deprecate select! partialsort!

base/exports.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ export
299299
cot,
300300
cotd,
301301
coth,
302-
count_ones,
303-
count_zeros,
302+
countones,
303+
countzeros,
304304
csc,
305305
cscd,
306306
csch,

base/gmp.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export BigInt
77
import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
88
binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod,
99
ndigits, promote_rule, rem, show, isqrt, string, powermod,
10-
sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal,
10+
sum, trailing_zeros, trailing_ones, countones, base, tryparse_internal,
1111
bin, oct, dec, hex, isequal, invmod, prevpow2, nextpow2, ndigits0zpb,
1212
widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit,
1313
hastypemax
@@ -473,7 +473,7 @@ end
473473
trailing_zeros(x::BigInt) = MPZ.scan1(x, 0)
474474
trailing_ones(x::BigInt) = MPZ.scan0(x, 0)
475475

476-
count_ones(x::BigInt) = MPZ.popcount(x)
476+
countones(x::BigInt) = MPZ.popcount(x)
477477

478478
"""
479479
count_ones_abs(x::BigInt)

base/int.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,16 @@ bswap(x::Union{Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128}) =
319319
bswap_int(x)
320320

321321
"""
322-
count_ones(x::Integer) -> Integer
322+
countones(x::Integer) -> Integer
323323
324324
Number of ones in the binary representation of `x`.
325325
326326
```jldoctest
327-
julia> count_ones(7)
327+
julia> countones(7)
328328
3
329329
```
330330
"""
331-
count_ones(x::BitInteger) = Int(ctpop_int(x))
331+
countones(x::BitInteger) = Int(ctpop_int(x))
332332

333333
"""
334334
leading_zeros(x::Integer) -> Integer
@@ -355,16 +355,16 @@ julia> trailing_zeros(2)
355355
trailing_zeros(x::BitInteger) = Int(cttz_int(x))
356356

357357
"""
358-
count_zeros(x::Integer) -> Integer
358+
countzeros(x::Integer) -> Integer
359359
360360
Number of zeros in the binary representation of `x`.
361361
362362
```jldoctest
363-
julia> count_zeros(Int32(2 ^ 16 - 1))
363+
julia> countzeros(Int32(2 ^ 16 - 1))
364364
16
365365
```
366366
"""
367-
count_zeros(x::Integer) = count_ones(~x)
367+
countzeros(x::Integer) = countones(~x)
368368

369369
"""
370370
leading_ones(x::Integer) -> Integer

base/intfuncs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ julia> ispow2(5)
335335
false
336336
```
337337
"""
338-
ispow2(x::Integer) = x > 0 && count_ones(x) == 1
338+
ispow2(x::Integer) = x > 0 && countones(x) == 1
339339

340340
"""
341341
nextpow(a, x)

base/linalg/bitarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function dot(x::BitVector, y::BitVector)
77
xc = x.chunks
88
yc = y.chunks
99
@inbounds for i = 1:length(xc)
10-
s += count_ones(xc[i] & yc[i])
10+
s += countones(xc[i] & yc[i])
1111
end
1212
s
1313
end
@@ -33,7 +33,7 @@ end
3333
#for j = 1:nB
3434
#for k = 1:col_ch
3535
## TODO: improve
36-
#C[i, j] += count_ones(aux_chunksA[k] & aux_chunksB[j][k])
36+
#C[i, j] += countones(aux_chunksA[k] & aux_chunksB[j][k])
3737
#end
3838
#end
3939
#end

base/rational.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fma(x::Rational, y::Rational, z::Rational) = x*y+z
278278

279279
function ==(x::AbstractFloat, q::Rational)
280280
if isfinite(x)
281-
(count_ones(q.den) == 1) & (x*q.den == q.num)
281+
(countones(q.den) == 1) & (x*q.den == q.num)
282282
else
283283
x == q.num/q.den
284284
end

doc/src/stdlib/numbers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ Base.Rounding.set_zero_subnormals
105105
### Integers
106106

107107
```@docs
108-
Base.count_ones
109-
Base.count_zeros
108+
Base.countones
109+
Base.countzeros
110110
Base.leading_zeros
111111
Base.leading_ones
112112
Base.trailing_zeros

test/bigint.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ g = parse(BigInt,"-1")
224224

225225
@test trailing_ones(a) == 8
226226
@test trailing_zeros(b) == 2
227-
@test count_ones(a) == 14
227+
@test countones(a) == 14
228228

229229
# Large Fibonacci to exercise BigInt
230230
# from Bill Hart, https://groups.google.com/group/julia-dev/browse_frm/thread/798e2d1322daf633

test/int.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ end
6969
@test bswap(Int128(2)^(15*8)) == Int128(1)
7070
@test bswap(UInt128(2)^(15*8)) == UInt128(1)
7171

72-
@test count_zeros(10) == Sys.WORD_SIZE - 2
73-
@test count_zeros(UInt8(10)) == 6
72+
@test countzeros(10) == Sys.WORD_SIZE - 2
73+
@test countzeros(UInt8(10)) == 6
7474

7575
@test convert(Signed, UInt128(3)) === Int128(3)
7676
@test convert(Signed, false) === 0

test/intfuncs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ end
175175
@test leading_zeros(Int32(1)) == 31
176176
@test leading_zeros(UInt32(Int64(2) ^ 32 - 2)) == 0
177177

178-
@test count_zeros(Int64(1)) == 63
178+
@test countzeros(Int64(1)) == 63
179179

180180
@test factorial(3) == 6
181181
@test factorial(Int8(3)) === 6

test/perf/shootout/meteor_contest.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const masksAtCell = Array{Any}(width*height, height)
4848

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

5353
function findFreeCell(board::UInt64)
5454
for y in 0:height-1

0 commit comments

Comments
 (0)