From 1fe420b1de8752a673ad1cb81b9fe93f53f712e2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Nov 2024 04:41:44 -0600 Subject: [PATCH] :robot: Format .jl files (#313) Co-authored-by: amontoison --- src/sparsity_pattern.jl | 86 ++++++++++++++++++++----------------- test/sparse_hessian.jl | 8 ++-- test/sparse_hessian_nls.jl | 8 ++-- test/sparse_jacobian.jl | 10 ++--- test/sparse_jacobian_nls.jl | 10 ++--- 5 files changed, 65 insertions(+), 57 deletions(-) diff --git a/src/sparsity_pattern.jl b/src/sparsity_pattern.jl index f55c007e..daf5d6e9 100644 --- a/src/sparsity_pattern.jl +++ b/src/sparsity_pattern.jl @@ -74,57 +74,65 @@ Supported backends include `SparseADJacobian`, `SparseADHessian`, and `SparseRev * `S`: A sparse matrix of type `SparseMatrixCSC{Bool,Int}` indicating the sparsity pattern of the requested derivative. """ function get_sparsity_pattern(model::ADModel, derivative::Symbol) - get_sparsity_pattern(model, Val(derivative)) + get_sparsity_pattern(model, Val(derivative)) end function get_sparsity_pattern(model::ADModel, ::Val{:jacobian}) - backend = model.adbackend.jacobian_backend - validate_sparse_backend(backend, SparseADJacobian, "Jacobian") - m = model.meta.ncon - n = model.meta.nvar - colptr = backend.colptr - rowval = backend.rowval - nnzJ = length(rowval) - nzval = ones(Bool, nnzJ) - SparseMatrixCSC(m, n, colptr, rowval, nzval) + backend = model.adbackend.jacobian_backend + validate_sparse_backend(backend, SparseADJacobian, "Jacobian") + m = model.meta.ncon + n = model.meta.nvar + colptr = backend.colptr + rowval = backend.rowval + nnzJ = length(rowval) + nzval = ones(Bool, nnzJ) + SparseMatrixCSC(m, n, colptr, rowval, nzval) end function get_sparsity_pattern(model::ADModel, ::Val{:hessian}) - backend = model.adbackend.hessian_backend - validate_sparse_backend(backend, Union{SparseADHessian, SparseReverseADHessian}, "Hessian") - n = model.meta.nvar - colptr = backend.colptr - rowval = backend.rowval - nnzH = length(rowval) - nzval = ones(Bool, nnzH) - SparseMatrixCSC(n, n, colptr, rowval, nzval) + backend = model.adbackend.hessian_backend + validate_sparse_backend(backend, Union{SparseADHessian, SparseReverseADHessian}, "Hessian") + n = model.meta.nvar + colptr = backend.colptr + rowval = backend.rowval + nnzH = length(rowval) + nzval = ones(Bool, nnzH) + SparseMatrixCSC(n, n, colptr, rowval, nzval) end function get_sparsity_pattern(model::AbstractADNLSModel, ::Val{:jacobian_residual}) - backend = model.adbackend.jacobian_residual_backend - validate_sparse_backend(backend, SparseADJacobian, "Jacobian of the residual") - m = model.nls_meta.nequ - n = model.meta.nvar - colptr = backend.colptr - rowval = backend.rowval - nnzJ = length(rowval) - nzval = ones(Bool, nnzJ) - SparseMatrixCSC(m, n, colptr, rowval, nzval) + backend = model.adbackend.jacobian_residual_backend + validate_sparse_backend(backend, SparseADJacobian, "Jacobian of the residual") + m = model.nls_meta.nequ + n = model.meta.nvar + colptr = backend.colptr + rowval = backend.rowval + nnzJ = length(rowval) + nzval = ones(Bool, nnzJ) + SparseMatrixCSC(m, n, colptr, rowval, nzval) end function get_sparsity_pattern(model::AbstractADNLSModel, ::Val{:hessian_residual}) - backend = model.adbackend.hessian_residual_backend - validate_sparse_backend(backend, Union{SparseADHessian, SparseReverseADHessian}, "Hessian of the residual") - n = model.meta.nvar - colptr = backend.colptr - rowval = backend.rowval - nnzH = length(rowval) - nzval = ones(Bool, nnzH) - SparseMatrixCSC(n, n, colptr, rowval, nzval) + backend = model.adbackend.hessian_residual_backend + validate_sparse_backend( + backend, + Union{SparseADHessian, SparseReverseADHessian}, + "Hessian of the residual", + ) + n = model.meta.nvar + colptr = backend.colptr + rowval = backend.rowval + nnzH = length(rowval) + nzval = ones(Bool, nnzH) + SparseMatrixCSC(n, n, colptr, rowval, nzval) end -function validate_sparse_backend(backend::B, expected_type, derivative_name::String) where {B <: ADBackend} - if !(backend isa expected_type) - error("The current backend $B doesn't compute a sparse $derivative_name.") - end +function validate_sparse_backend( + backend::B, + expected_type, + derivative_name::String, +) where {B <: ADBackend} + if !(backend isa expected_type) + error("The current backend $B doesn't compute a sparse $derivative_name.") + end end diff --git a/test/sparse_hessian.jl b/test/sparse_hessian.jl index 9ccd56a2..250299f0 100644 --- a/test/sparse_hessian.jl +++ b/test/sparse_hessian.jl @@ -65,10 +65,10 @@ dt = (Float32, Float64) if (backend == ADNLPModels.SparseADHessian) || (backend == ADNLPModels.SparseReverseADHessian) H_sp = get_sparsity_pattern(nlp, :hessian) - @test H_sp == SparseMatrixCSC{Bool, Int}( - [ 1 0 ; - 1 1 ] - ) + @test H_sp == SparseMatrixCSC{Bool, Int}([ + 1 0 + 1 1 + ]) end nlp = ADNLPModel!( diff --git a/test/sparse_hessian_nls.jl b/test/sparse_hessian_nls.jl index ac552a5c..f0ee5cee 100644 --- a/test/sparse_hessian_nls.jl +++ b/test/sparse_hessian_nls.jl @@ -52,10 +52,10 @@ dt = (Float32, Float64) if (backend == ADNLPModels.SparseADHessian) || (backend == ADNLPModels.SparseReverseADHessian) H_sp = get_sparsity_pattern(nls, :hessian_residual) - @test H_sp == SparseMatrixCSC{Bool, Int}( - [ 1 0 ; - 0 0 ] - ) + @test H_sp == SparseMatrixCSC{Bool, Int}([ + 1 0 + 0 0 + ]) end nls = ADNLPModels.ADNLSModel!(F!, x0, 3, matrix_free = true; kw...) diff --git a/test/sparse_jacobian.jl b/test/sparse_jacobian.jl index 1b089406..da0a8e5f 100644 --- a/test/sparse_jacobian.jl +++ b/test/sparse_jacobian.jl @@ -53,11 +53,11 @@ dt = (Float32, Float64) if backend == ADNLPModels.SparseADJacobian J_sp = get_sparsity_pattern(nlp, :jacobian) - @test J_sp == SparseMatrixCSC{Bool, Int}( - [ 1 0 ; - 1 1 ; - 0 1 ] - ) + @test J_sp == SparseMatrixCSC{Bool, Int}([ + 1 0 + 1 1 + 0 1 + ]) end nlp = ADNLPModel!(x -> sum(x), x0, c!, zeros(T, ncon), zeros(T, ncon), matrix_free = true; kw...) diff --git a/test/sparse_jacobian_nls.jl b/test/sparse_jacobian_nls.jl index 9035d6b4..4405e7f7 100644 --- a/test/sparse_jacobian_nls.jl +++ b/test/sparse_jacobian_nls.jl @@ -45,11 +45,11 @@ dt = (Float32, Float64) if backend == ADNLPModels.SparseADJacobian J_sp = get_sparsity_pattern(nls, :jacobian_residual) - @test J_sp == SparseMatrixCSC{Bool, Int}( - [ 1 0 ; - 1 1 ; - 0 1 ] - ) + @test J_sp == SparseMatrixCSC{Bool, Int}([ + 1 0 + 1 1 + 0 1 + ]) end nls = ADNLPModels.ADNLSModel!(F!, x0, 3, matrix_free = true; kw...)