From fe876ea4be083bf6a809db28fd21e64a32305547 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Thu, 31 Aug 2017 11:54:07 -0700 Subject: [PATCH] Rename count_ones and count_zeros to countones and countzeros. --- NEWS.md | 3 +++ base/bitarray.jl | 2 +- base/deprecated.jl | 4 ++++ base/exports.jl | 4 ++-- base/gmp.jl | 4 ++-- base/int.jl | 12 ++++++------ base/intfuncs.jl | 2 +- base/linalg/bitarray.jl | 4 ++-- base/rational.jl | 2 +- doc/src/stdlib/numbers.md | 4 ++-- test/bigint.jl | 2 +- test/int.jl | 4 ++-- test/intfuncs.jl | 2 +- test/perf/shootout/meteor_contest.jl | 2 +- 14 files changed, 29 insertions(+), 22 deletions(-) diff --git a/NEWS.md b/NEWS.md index 19dd81a117fed..eb8a8fc29968d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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]). diff --git a/base/bitarray.jl b/base/bitarray.jl index 71c2702a34d59..c08be24962b58 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -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 diff --git a/base/deprecated.jl b/base/deprecated.jl index d20e243f921ba..3bbdd8fb36c10 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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! diff --git a/base/exports.jl b/base/exports.jl index 75607641a48f8..c472da1dcebf9 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -299,8 +299,8 @@ export cot, cotd, coth, - count_ones, - count_zeros, + countones, + countzeros, csc, cscd, csch, diff --git a/base/gmp.jl b/base/gmp.jl index 9abfc34d44610..29a60d5022e13 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -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 @@ -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) diff --git a/base/int.jl b/base/int.jl index df3f4823f9512..84645a1113692 100644 --- a/base/int.jl +++ b/base/int.jl @@ -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 @@ -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 diff --git a/base/intfuncs.jl b/base/intfuncs.jl index e34986037b5fa..80cecd3fd82dd 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -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) diff --git a/base/linalg/bitarray.jl b/base/linalg/bitarray.jl index b7dacb300a3f8..98204829084d9 100644 --- a/base/linalg/bitarray.jl +++ b/base/linalg/bitarray.jl @@ -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 @@ -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 diff --git a/base/rational.jl b/base/rational.jl index 87c0c2cb0cdd9..e4200773df0c7 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -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 diff --git a/doc/src/stdlib/numbers.md b/doc/src/stdlib/numbers.md index 977bd50049ac8..f1cbf9ba29cce 100644 --- a/doc/src/stdlib/numbers.md +++ b/doc/src/stdlib/numbers.md @@ -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 diff --git a/test/bigint.jl b/test/bigint.jl index 71a2fd16e8cec..66d620212168f 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -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 diff --git a/test/int.jl b/test/int.jl index 3cf1cbbd65f30..7b52b8fe2c088 100644 --- a/test/int.jl +++ b/test/int.jl @@ -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 diff --git a/test/intfuncs.jl b/test/intfuncs.jl index 0ecf36d203a97..c1022f4b08437 100644 --- a/test/intfuncs.jl +++ b/test/intfuncs.jl @@ -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 diff --git a/test/perf/shootout/meteor_contest.jl b/test/perf/shootout/meteor_contest.jl index 08ca2b9b2ae19..8e8a25265121f 100644 --- a/test/perf/shootout/meteor_contest.jl +++ b/test/perf/shootout/meteor_contest.jl @@ -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