Skip to content

Commit 40c2d89

Browse files
committed
Move findmin and findmax BitArray methods from LinearAlgebra to Base
There is no reason to have them in LinearAlgebra.
1 parent 4f8a7b9 commit 40c2d89

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

Diff for: base/bitarray.jl

+31
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,37 @@ function findprev(testf::Function, B::BitArray, start::Integer)
15101510
end
15111511
#findlast(testf::Function, B::BitArray) = findprev(testf, B, 1) ## defined in array.jl
15121512

1513+
1514+
function findmax(a::BitArray)
1515+
isempty(a) && throw(ArgumentError("BitArray must be non-empty"))
1516+
m, mi = false, 1
1517+
ti = 1
1518+
ac = a.chunks
1519+
for i = 1:length(ac)
1520+
@inbounds k = trailing_zeros(ac[i])
1521+
ti += k
1522+
k == 64 || return (true, ti)
1523+
end
1524+
return m, mi
1525+
end
1526+
1527+
function findmin(a::BitArray)
1528+
isempty(a) && throw(ArgumentError("BitArray must be non-empty"))
1529+
m, mi = true, 1
1530+
ti = 1
1531+
ac = a.chunks
1532+
for i = 1:length(ac)-1
1533+
@inbounds k = trailing_ones(ac[i])
1534+
ti += k
1535+
k == 64 || return (false, ti)
1536+
end
1537+
l = Base._mod64(length(a)-1) + 1
1538+
@inbounds k = trailing_ones(ac[end] & Base._msk_end(l))
1539+
ti += k
1540+
k == l || return (false, ti)
1541+
return m, mi
1542+
end
1543+
15131544
# findall helper functions
15141545
# Generic case (>2 dimensions)
15151546
function allindices!(I, B::BitArray)

Diff for: stdlib/LinearAlgebra/src/LinearAlgebra.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module LinearAlgebra
1010
import Base: \, /, *, ^, +, -, ==
1111
import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, asec, asech,
1212
asin, asinh, atan, atanh, axes, big, broadcast, ceil, conj, convert, copy, copyto!, cos,
13-
cosh, cot, coth, csc, csch, eltype, exp, findmax, findmin, fill!, floor, getindex, hcat,
13+
cosh, cot, coth, csc, csch, eltype, exp, fill!, floor, getindex, hcat,
1414
getproperty, imag, inv, isapprox, isone, iszero, IndexStyle, kron, length, log, map, ndims,
1515
oneunit, parent, power_by_squaring, print_matrix, promote_rule, real, round, sec, sech,
1616
setindex!, show, similar, sin, sincos, sinh, size, size_to_strides, sqrt, StridedReinterpretArray,

Diff for: stdlib/LinearAlgebra/src/bitarray.jl

-30
Original file line numberDiff line numberDiff line change
@@ -171,36 +171,6 @@ function istril(A::BitMatrix)
171171
return true
172172
end
173173

174-
function findmax(a::BitArray)
175-
isempty(a) && throw(ArgumentError("BitArray must be non-empty"))
176-
m, mi = false, 1
177-
ti = 1
178-
ac = a.chunks
179-
for i = 1:length(ac)
180-
@inbounds k = trailing_zeros(ac[i])
181-
ti += k
182-
k == 64 || return (true, ti)
183-
end
184-
return m, mi
185-
end
186-
187-
function findmin(a::BitArray)
188-
isempty(a) && throw(ArgumentError("BitArray must be non-empty"))
189-
m, mi = true, 1
190-
ti = 1
191-
ac = a.chunks
192-
for i = 1:length(ac)-1
193-
@inbounds k = trailing_ones(ac[i])
194-
ti += k
195-
k == 64 || return (false, ti)
196-
end
197-
l = Base._mod64(length(a)-1) + 1
198-
@inbounds k = trailing_ones(ac[end] & Base._msk_end(l))
199-
ti += k
200-
k == l || return (false, ti)
201-
return m, mi
202-
end
203-
204174
# fast 8x8 bit transpose from Henry S. Warrens's "Hacker's Delight"
205175
# http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt
206176
function transpose8x8(x::UInt64)

0 commit comments

Comments
 (0)