From 040ba8d7a224262e494cd1783ff1d71386d98efd Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 4 Jan 2026 07:56:13 -0500 Subject: [PATCH] Switch from JuliaFormatter to Runic.jl for code formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update CI workflow to use fredrikekre/runic-action@v1 - Remove .JuliaFormatter.toml configuration - Format all source files with Runic.jl 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .JuliaFormatter.toml | 3 - .github/workflows/FormatCheck.yml | 42 ++-------- docs/make.jl | 2 +- src/SparseBandedMatrices.jl | 134 +++++++++++++++--------------- test/qa.jl | 2 +- test/runtests.jl | 4 +- 6 files changed, 78 insertions(+), 109 deletions(-) delete mode 100644 .JuliaFormatter.toml diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml deleted file mode 100644 index 03b0602..0000000 --- a/.JuliaFormatter.toml +++ /dev/null @@ -1,3 +0,0 @@ -style = "sciml" -annotate_untyped_fields_with_any = false -join_lines_based_on_source = false \ No newline at end of file diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 8d72cf1..6762c6f 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -3,45 +3,17 @@ name: format-check on: push: branches: - - main + - 'master' + - 'main' + - 'release-' + tags: '*' pull_request: - branches: - - main - -concurrency: - # Skip intermediate builds: always. - # Cancel intermediate builds: only if it is a pull request build. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} jobs: - build: + runic: runs-on: ubuntu-latest steps: - - uses: julia-actions/setup-julia@v2 + - uses: actions/checkout@v4 + - uses: fredrikekre/runic-action@v1 with: version: '1' - - uses: actions/checkout@v5 - - name: Install JuliaFormatter and SciMLStyle - run: | - using Pkg - Pkg.add(; name="JuliaFormatter") - Pkg.add(; name="SciMLStyle") - shell: julia --color=yes {0} - - name: Run formatter - run: | - using JuliaFormatter - using SciMLStyle - format("."; style=SciMLStyle(), verbose=true) - shell: julia --color=yes {0} - - name: Format check - run: | - out = Cmd(`git diff --name-only`) |> read |> String - if out == "" - exit(0) - else - @error "Some files have not been formatted !!!" - write(stdout, out) - exit(1) - end - shell: julia --color=yes {0} \ No newline at end of file diff --git a/docs/make.jl b/docs/make.jl index 0a3db8b..ee9aff3 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -23,4 +23,4 @@ makedocs(; deploydocs(; repo = "github.com/SciML/SparseBandedMatrices.jl", devbranch = "main", -) \ No newline at end of file +) diff --git a/src/SparseBandedMatrices.jl b/src/SparseBandedMatrices.jl index 680ae7f..4816110 100644 --- a/src/SparseBandedMatrices.jl +++ b/src/SparseBandedMatrices.jl @@ -53,32 +53,32 @@ diagonal indices range from 1 to N+M-1. The storage is optimized for fast matrix multiplication operations used in butterfly factorizations. """ struct SparseBandedMatrix{T} <: AbstractMatrix{T} - size :: Tuple{Int, Int} - indices :: Vector{Int} - diags :: Vector{Vector{T}} - function SparseBandedMatrix{T}(::UndefInitializer, N, M) where T + size::Tuple{Int, Int} + indices::Vector{Int} + diags::Vector{Vector{T}} + function SparseBandedMatrix{T}(::UndefInitializer, N, M) where {T} size = (N, M) indices = Int[] diags = Vector{T}[] - new(size, indices, diags) + return new(size, indices, diags) end - function SparseBandedMatrix{T}(ind_vals, diag_vals, N, M) where T + function SparseBandedMatrix{T}(ind_vals, diag_vals, N, M) where {T} size = (N, M) perm = sortperm(ind_vals) indices = ind_vals[perm] - for i in 1 : length(indices) - 1 + for i in 1:(length(indices) - 1) @assert indices[i] != indices[i + 1] end diags = diag_vals[perm] - new(size, indices, diags) + return new(size, indices, diags) end end -function Base.size(M :: SparseBandedMatrix) - M.size +function Base.size(M::SparseBandedMatrix) + return M.size end -function Base.getindex(M :: SparseBandedMatrix{T}, i :: Int, j :: Int, I :: Int...) where T +function Base.getindex(M::SparseBandedMatrix{T}, i::Int, j::Int, I::Int...) where {T} @boundscheck checkbounds(M, i, j, I...) rows, cols = size(M) wanted_ind = rows - i + j @@ -90,11 +90,11 @@ function Base.getindex(M :: SparseBandedMatrix{T}, i :: Int, j :: Int, I :: Int. return M.diags[ind][i] end end - zero(T) + return zero(T) end -function Base.setindex!(M :: SparseBandedMatrix{T}, val, i :: Int, j :: Int, I :: Int...) where T - @boundscheck checkbounds(M, i, j, I...) +function Base.setindex!(M::SparseBandedMatrix{T}, val, i::Int, j::Int, I::Int...) where {T} + @boundscheck checkbounds(M, i, j, I...) rows = size(M, 1) wanted_ind = rows - i + j ind = searchsortedfirst(M.indices, wanted_ind) @@ -107,8 +107,8 @@ function Base.setindex!(M :: SparseBandedMatrix{T}, val, i :: Int, j :: Int, I : else M.diags[ind][i] = val isa T ? val : convert(T, val)::T end - val - end + return val +end """ setdiagonal!(M::SparseBandedMatrix{T}, diagvals, lower::Bool) where T @@ -141,7 +141,7 @@ setdiagonal!(A, [1.0, 2.0], false) # Throws - `ErrorException`: If `length(diagvals) > rows` (diagonal is too large for the matrix) """ -function setdiagonal!(M :: SparseBandedMatrix{T}, diagvals, lower :: Bool) where T +function setdiagonal!(M::SparseBandedMatrix{T}, diagvals, lower::Bool) where {T} rows, cols = size(M) if length(diagvals) > rows error("size of diagonal is too big for the matrix") @@ -161,85 +161,85 @@ function setdiagonal!(M :: SparseBandedMatrix{T}, diagvals, lower :: Bool) where M.diags[ind][i] = diagvals[i] isa T ? diagvals[i] : convert(T, diagvals[i])::T end end - diagvals + return diagvals end # C = Cb + aAB -function LinearAlgebra.mul!(C :: Matrix{T}, A:: SparseBandedMatrix{T}, B :: Matrix{T}, a :: Number, b :: Number) where T +function LinearAlgebra.mul!(C::Matrix{T}, A::SparseBandedMatrix{T}, B::Matrix{T}, a::Number, b::Number) where {T} @assert size(A, 2) == size(B, 1) @assert size(A, 1) == size(C, 1) @assert size(B, 2) == size(C, 2) - C.*=b + C .*= b rows, cols = size(A) @inbounds for (ind, location) in enumerate(A.indices) @threads for i in 1:length(A.diags[ind]) # value: diag[i] - # index in array: + # index in array: # if ind < rows(A), then index = (rows - loc + i, i) # else index = (i, loc - cols + i) val = A.diags[ind][i] * a - if location < rows - index_i = rows - location + i - index_j = i + if location < rows + index_i = rows - location + i + index_j = i else - index_i = i - index_j = location - cols + i + index_i = i + index_j = location - cols + i end #A[index_i, index_j] * B[index_j, j] = C[index_i, j] - for j in 1 : size(B, 2) + for j in 1:size(B, 2) C[index_i, j] = fma(val, B[index_j, j], C[index_i, j]) end end end - C + return C end # C = Cb + aBA -function LinearAlgebra.mul!(C :: Matrix{T}, A:: Matrix{T}, B :: SparseBandedMatrix{T}, a :: Number, b :: Number) where T +function LinearAlgebra.mul!(C::Matrix{T}, A::Matrix{T}, B::SparseBandedMatrix{T}, a::Number, b::Number) where {T} @assert size(A, 2) == size(B, 1) @assert size(A, 1) == size(C, 1) @assert size(B, 2) == size(C, 2) - C.*=b + C .*= b rows, cols = size(B) @inbounds for (ind, location) in enumerate(B.indices) @threads for i in eachindex(B.diags[ind]) - val = B.diags[ind][i] * a - if location < rows - index_i = rows - location + i - index_j = i - else - index_i = i - index_j = location - cols + i - end - @simd for j in 1 : size(A, 1) + val = B.diags[ind][i] * a + if location < rows + index_i = rows - location + i + index_j = i + else + index_i = i + index_j = location - cols + i + end + @simd for j in 1:size(A, 1) C[j, index_j] = fma(val, A[j, index_i], C[j, index_j]) end end end - C + return C end -function LinearAlgebra.mul!(C :: SparseBandedMatrix{T}, A:: SparseBandedMatrix{T}, B :: SparseBandedMatrix{T}, a :: Number, b :: Number) where T +function LinearAlgebra.mul!(C::SparseBandedMatrix{T}, A::SparseBandedMatrix{T}, B::SparseBandedMatrix{T}, a::Number, b::Number) where {T} @assert size(A, 2) == size(B, 1) @assert size(A, 1) == size(C, 1) @assert size(B, 2) == size(C, 2) - C.*=b + C .*= b rows_a, cols_a = size(A) rows_b, cols_b = size(B) @inbounds for (ind_a, location_a) in enumerate(A.indices) @threads for i in eachindex(A.diags[ind_a]) val_a = A.diags[ind_a][i] * a - if location_a < rows_a - index_ia = rows_a - location_a + i - index_ja = i + if location_a < rows_a + index_ia = rows_a - location_a + i + index_ja = i else - index_ia = i - index_ja = location_a - cols_a + i + index_ia = i + index_ja = location_a - cols_a + i end min_loc = rows_b - index_ja + 1 max_loc = 2 * rows_b - index_ja @@ -248,42 +248,42 @@ function LinearAlgebra.mul!(C :: SparseBandedMatrix{T}, A:: SparseBandedMatrix{T # if ind < rows(A), then index = (rows - loc + i, i) #rows - loc + j = index_ja, j = index_ja - rows + loc # else index = (i, loc - cols + i) - # if location < rows(B), then + # if location < rows(B), then if location_b <= rows_b && location_b >= min_loc j = index_ja - rows_b + location_b index_jb = j val_b = B.diags[ind_b][j] - C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) + C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) elseif location_b > rows_b && location_b <= max_loc j = index_ja - index_jb = location_b - cols_b + j + index_jb = location_b - cols_b + j val_b = B.diags[ind_b][j] - C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) - end + C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) + end end end end - C + return C end -function LinearAlgebra.mul!(C :: Matrix{T}, A:: SparseBandedMatrix{T}, B :: SparseBandedMatrix{T}, a :: Number, b :: Number) where T +function LinearAlgebra.mul!(C::Matrix{T}, A::SparseBandedMatrix{T}, B::SparseBandedMatrix{T}, a::Number, b::Number) where {T} @assert size(A, 2) == size(B, 1) @assert size(A, 1) == size(C, 1) @assert size(B, 2) == size(C, 2) - C.*=b + C .*= b rows_a, cols_a = size(A) rows_b, cols_b = size(B) @inbounds for (ind_a, location_a) in enumerate(A.indices) @threads for i in eachindex(A.diags[ind_a]) val_a = A.diags[ind_a][i] * a - if location_a < rows_a - index_ia = rows_a - location_a + i - index_ja = i + if location_a < rows_a + index_ia = rows_a - location_a + i + index_ja = i else - index_ia = i - index_ja = location_a - cols_a + i + index_ia = i + index_ja = location_a - cols_a + i end min_loc = rows_b - index_ja + 1 max_loc = 2 * rows_b - index_ja @@ -292,22 +292,22 @@ function LinearAlgebra.mul!(C :: Matrix{T}, A:: SparseBandedMatrix{T}, B :: Spar # if ind < rows(A), then index = (rows - loc + i, i) #rows - loc + j = index_ja, j = index_ja - rows + loc # else index = (i, loc - cols + i) - # if location < rows(B), then + # if location < rows(B), then if location_b <= rows_b && location_b >= min_loc j = index_ja - rows_b + location_b index_jb = j val_b = B.diags[ind_b][j] - C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) + C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) elseif location_b > rows_b && location_b <= max_loc j = index_ja - index_jb = location_b - cols_b + j + index_jb = location_b - cols_b + j val_b = B.diags[ind_b][j] - C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) - end + C[index_ia, index_jb] = muladd(val_a, val_b, C[index_ia, index_jb]) + end end end end - C + return C end export SparseBandedMatrix, size, getindex, setindex!, setdiagonal!, mul! @@ -346,4 +346,4 @@ export SparseBandedMatrix, size, getindex, setindex!, setdiagonal!, mul! end end -end \ No newline at end of file +end diff --git a/test/qa.jl b/test/qa.jl index 9a31d46..0dd74bf 100644 --- a/test/qa.jl +++ b/test/qa.jl @@ -1,4 +1,4 @@ using SparseBandedMatrices, Aqua @testset "Aqua" begin Aqua.test_all(SparseBandedMatrices; ambiguities = (recursive = false,)) -end \ No newline at end of file +end diff --git a/test/runtests.jl b/test/runtests.jl index 1adeb88..decf943 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,7 +15,7 @@ using SafeTestsets, Test A[1, 3] = 5 @test A[1, 3] == 5.0 - @test size(A) == (5,5) + @test size(A) == (5, 5) end @safetestset "Multiplication" begin @@ -81,4 +81,4 @@ using SafeTestsets, Test @test isapprox(x_butterfly / y_butterfly, x_dense / y_dense) end -end \ No newline at end of file +end