Skip to content

Commit 1e70879

Browse files
authored
Reduced allocations in pfaffian(::AbstractMatrix{<:Complex}) (#138)
* Reduced allocations in pfaffian(::AbstractMatrix{<:Complex}) * Added logabspfaffian(::AbstractMatrix{<:Complex}) I realised that the algorithm used to compute `pfaffian(::AbstractMatrix{<:Complex})` can be used to compute the `logabspfaffian` with little modifications and decided to add that too for completeness sake * Revert "Added logabspfaffian(::AbstractMatrix{<:Complex})" This reverts commit 0b49126. * Added argmaxabs() for compatibility with julia 1.6
1 parent b42ba83 commit 1e70879

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/pfaffian.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ else
88
exactdiv(a::Integer, b::Integer) = div(a, b)
99
end
1010

11+
if VERSION v"1.7"
12+
argmaxabs(a) = argmax(Iterators.map(abs, a))
13+
else
14+
argmaxabs(a) = argmax(abs.(a))
15+
end
16+
1117
# in-place O(n³) algorithm to compute the exact Pfaffian of
1218
# a skew-symmetric matrix over integers (or potentially any ring supporting exact division).
1319
#
@@ -98,7 +104,7 @@ function _pfaffian!(A::AbstractMatrix{<:Complex})
98104
tauk = @view tau[k:end]
99105

100106
# Pivot if neccessary
101-
@views kp = k + argmax(abs.(A[k+1:end, k]))
107+
@views kp = k + argmaxabs(A[k+1:end, k])
102108
if kp != k + 1
103109
@inbounds @simd for l in k:n
104110
A[k+1,l], A[kp,l] = A[kp,l], A[k+1,l]

0 commit comments

Comments
 (0)