@@ -22,22 +22,30 @@ function lu(A::AbstractMatrix, pivot = Val(true), thread = Val(true); kwargs...)
22
22
return lu! (copy (A), normalize_pivot (pivot), thread; kwargs... )
23
23
end
24
24
25
+ const CUSTOMIZABLE_PIVOT = VERSION >= v " 1.8.0-DEV.1507"
26
+
25
27
struct NotIPIV <: AbstractVector{BlasInt}
26
28
len:: Int
27
29
end
28
30
Base. size (A:: NotIPIV ) = (A. len,)
29
31
Base. getindex (:: NotIPIV , i:: Int ) = i
30
32
Base. view (:: NotIPIV , r:: AbstractUnitRange ) = NotIPIV (length (r))
31
- init_pivot (:: Val{false} , minmn) = NotIPIV (minmn)
33
+ function init_pivot (:: Val{false} , minmn)
34
+ @static if CUSTOMIZABLE_PIVOT
35
+ NotIPIV (minmn)
36
+ else
37
+ init_pivot (Val (true ), minmn)
38
+ end
39
+ end
32
40
init_pivot (:: Val{true} , minmn) = Vector {BlasInt} (undef, minmn)
33
41
34
- if isdefined (LinearAlgebra, :_ipiv_cols! )
42
+ if CUSTOMIZABLE_PIVOT && isdefined (LinearAlgebra, :_ipiv_cols! )
35
43
function LinearAlgebra. _ipiv_cols! (:: LU{<:Any, <:Any, NotIPIV} , :: OrdinalRange ,
36
44
B:: StridedVecOrMat )
37
45
return B
38
46
end
39
47
end
40
- if isdefined (LinearAlgebra, :_ipiv_rows! )
48
+ if CUSTOMIZABLE_PIVOT && isdefined (LinearAlgebra, :_ipiv_rows! )
41
49
function LinearAlgebra. _ipiv_rows! (:: LU{<:Any, <:Any, NotIPIV} , :: OrdinalRange ,
42
50
B:: StridedVecOrMat )
43
51
return B
47
55
function lu! (A, pivot = Val (true ), thread = Val (true ); check = true , kwargs... )
48
56
m, n = size (A)
49
57
minmn = min (m, n)
58
+ npivot = normalize_pivot (pivot)
50
59
# we want the type on both branches to match. When pivot = Val(false), we construct
51
- # a `NotIPIV`, which `LinearAlgebra.generic_lufact!` does not.
60
+ # a `NotIPIV`, which `LinearAlgebra.generic_lufact!` does not.
52
61
F = if pivot === Val (true ) && minmn < 10 # avx introduces small performance degradation
53
62
LinearAlgebra. generic_lufact! (A, to_stdlib_pivot (pivot); check = check)
54
63
else
55
- lu! (A, init_pivot (pivot , minmn), normalize_pivot (pivot) , thread; check = check,
64
+ lu! (A, init_pivot (npivot , minmn), npivot , thread; check = check,
56
65
kwargs... )
57
66
end
58
67
return F
@@ -80,6 +89,9 @@ function lu!(A::AbstractMatrix{T}, ipiv::AbstractVector{<:Integer},
80
89
info = zero (BlasInt)
81
90
m, n = size (A)
82
91
mnmin = min (m, n)
92
+ if pivot === Val (false ) && ! CUSTOMIZABLE_PIVOT
93
+ copyto! (ipiv, 1 : mnmin)
94
+ end
83
95
if recurse (A) && mnmin > threshold
84
96
if T <: Union{Float32, Float64}
85
97
GC. @preserve ipiv A begin info = recurse! (view (PtrArray (A), axes (A)... ), pivot,
116
128
# [AL AR]
117
129
AL = @view A[:, 1 : m]
118
130
AR = @view A[:, (m + 1 ): n]
119
- apply_permutation! (ipiv, AR, Val {Thread} ())
131
+ Pivot && apply_permutation! (ipiv, AR, Val {Thread} ())
120
132
ldiv! (_unit_lower_triangular (AL), AR, Val {Thread} ())
121
133
end
122
134
info
0 commit comments