Skip to content

Remove ipiv allocation from GenericLUFactorization #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 26, 2025

Conversation

ChrisRackauckas
Copy link
Member

No description provided.


y = _ldiv!(cache.u, @get_cacheval(cache, $(Meta.quot(defaultalg_symbol(alg)))),
cache.b)
return SciMLBase.build_linear_solution(alg, y, nothing, cache; retcode = ReturnCode.Success)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return SciMLBase.build_linear_solution(alg, y, nothing, cache; retcode = ReturnCode.Success)
return SciMLBase.build_linear_solution(
alg, y, nothing, cache; retcode = ReturnCode.Success)


cache.isfresh = false
end
y = ldiv!(cache.u, LinearSolve.@get_cacheval(cache, :GenericLUFactorization)[1], cache.b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
y = ldiv!(cache.u, LinearSolve.@get_cacheval(cache, :GenericLUFactorization)[1], cache.b)
y = ldiv!(
cache.u, LinearSolve.@get_cacheval(cache, :GenericLUFactorization)[1], cache.b)

Comment on lines +4 to +6
function generic_lufact!(A::AbstractMatrix{T}, pivot::Union{RowMaximum,NoPivot,RowNonZero} = LinearAlgebra.lupivottype(T),
ipiv = Vector{LinearAlgebra.BlasInt}(undef, min(size(A)...));
check::Bool = true, allowsingular::Bool = false) where {T}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function generic_lufact!(A::AbstractMatrix{T}, pivot::Union{RowMaximum,NoPivot,RowNonZero} = LinearAlgebra.lupivottype(T),
ipiv = Vector{LinearAlgebra.BlasInt}(undef, min(size(A)...));
check::Bool = true, allowsingular::Bool = false) where {T}
function generic_lufact!(A::AbstractMatrix{T},
pivot::Union{RowMaximum, NoPivot, RowNonZero} = LinearAlgebra.lupivottype(T),
ipiv = Vector{LinearAlgebra.BlasInt}(undef, min(size(A)...));
check::Bool = true, allowsingular::Bool = false) where {T}

check && LinearAlgebra.LAPACK.chkfinite(A)
# Extract values
m, n = size(A)
minmn = min(m,n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
minmn = min(m,n)
minmn = min(m, n)


# Initialize variables
info = 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

info = 0

@inbounds begin
for k = 1:minmn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
for k = 1:minmn
for k in 1:minmn

Comment on lines +21 to +22
for i = k+1:m
absi = abs(A[i,k])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
for i = k+1:m
absi = abs(A[i,k])
for i in (k + 1):m
absi = abs(A[i, k])

Comment on lines +102 to +105
for i = 1:n
tmp = A[k,i]
A[k,i] = A[kp,i]
A[kp,i] = tmp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
for i = 1:n
tmp = A[k,i]
A[k,i] = A[kp,i]
A[kp,i] = tmp
for i in 1:n
tmp = A[k, i]
A[k, i] = A[kp, i]
A[kp, i] = tmp

Comment on lines +109 to +111
Akkinv = inv(A[k,k])
for i = k+1:m
A[i,k] *= Akkinv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Akkinv = inv(A[k,k])
for i = k+1:m
A[i,k] *= Akkinv
Akkinv = inv(A[k, k])
for i in (k + 1):m
A[i, k] *= Akkinv

Comment on lines +117 to +119
for j = k+1:n
for i = k+1:m
A[i,j] -= A[i,k]*A[k,j]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
for j = k+1:n
for i = k+1:m
A[i,j] -= A[i,k]*A[k,j]
for j in (k + 1):n
for i in (k + 1):m
A[i, j] -= A[i, k] * A[k, j]

info = -info
end
check && LinearAlgebra._check_lu_success(info, allowsingular)
return LinearAlgebra.LU{T,typeof(A),typeof(ipiv)}(A, ipiv, convert(LinearAlgebra.BlasInt, info))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return LinearAlgebra.LU{T,typeof(A),typeof(ipiv)}(A, ipiv, convert(LinearAlgebra.BlasInt, info))
return LinearAlgebra.LU{T, typeof(A), typeof(ipiv)}(
A, ipiv, convert(LinearAlgebra.BlasInt, info))

Comment on lines +132 to +134
else
generic_lufact!(args...; kwargs...) = LinearAlgebra.generic_lufact!(args...; kwargs...)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
else
generic_lufact!(args...; kwargs...) = LinearAlgebra.generic_lufact!(args...; kwargs...)
end
else
generic_lufact!(args...; kwargs...) = LinearAlgebra.generic_lufact!(args...; kwargs...)
end

@ChrisRackauckas ChrisRackauckas merged commit e101fd3 into main May 26, 2025
23 of 29 checks passed
@ChrisRackauckas ChrisRackauckas deleted the generic_lufact_alloc branch May 26, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant