Skip to content

Commit 15134f3

Browse files
authored
Use top_set_bit (#324)
1 parent 6b50890 commit 15134f3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/linalg.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,16 @@ function estimate_mulsize(m::Integer, nnzA::Integer, n::Integer, nnzB::Integer,
275275
p >= 1 ? m*k : p > 0 ? Int(ceil(-expm1(log1p(-p) * n)*m*k)) : 0 # (1-(1-p)^n)*m*k
276276
end
277277

278+
if VERSION < v"1.10.0-DEV.299"
279+
top_set_bit(x::Base.BitInteger) = 8 * sizeof(x) - leading_zeros(x)
280+
else
281+
top_set_bit(x::Base.BitInteger) = Base.top_set_bit(x)
282+
end
278283
# determine if sort! shall be used or the whole column be scanned
279284
# based on empirical data on i7-3610QM CPU
280285
# measuring runtimes of the scanning and sorting loops of the algorithm.
281286
# The parameters 6 and 3 might be modified for different architectures.
282-
prefer_sort(nz::Integer, m::Integer) = m > 6 && 3 * ilog2(nz) * nz < m
283-
284-
# minimal number of bits required to represent integer; ilog2(n) >= log2(n)
285-
ilog2(n::Integer) = sizeof(n)<<3 - leading_zeros(n)
287+
prefer_sort(nz::Integer, m::Integer) = m > 6 && 3 * top_set_bit(nz) * nz < m
286288

287289
# Frobenius dot/inner product: trace(A'B)
288290
function dot(A::AbstractSparseMatrixCSC{T1,S1},B::AbstractSparseMatrixCSC{T2,S2}) where {T1,T2,S1,S2}

0 commit comments

Comments
 (0)