From 7c1411eaee7c158e60c13574e226eac080adf8f8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sat, 12 Apr 2025 00:43:52 +0000 Subject: [PATCH 1/2] Format .jl files --- Project.toml | 2 +- src/indexing.jl | 83 +++++++++++++++++++++++++++--------------------- src/wrappers.jl | 5 +-- test/runtests.jl | 6 ++-- 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/Project.toml b/Project.toml index d61d384..78d6a6f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SparseArraysBase" uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208" authors = ["ITensor developers and contributors"] -version = "0.5.5" +version = "0.5.6" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/src/indexing.jl b/src/indexing.jl index 06a6392..8890dec 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -12,8 +12,9 @@ Obtain `getindex(A, I...)` with the guarantee that there is a stored entry at th Similar to `Base.getindex`, new definitions should be in line with `IndexStyle(A)`. """ -@inline getstoredindex(A::AbstractArray, I...) = - @interface interface(A) getstoredindex(A, I...) +@inline getstoredindex(A::AbstractArray, I...) = @interface interface(A) getstoredindex( + A, I... +) """ getunstoredindex(A::AbstractArray, I...) -> eltype(A) @@ -25,8 +26,9 @@ instantiated object. Similar to `Base.getindex`, new definitions should be in line with `IndexStyle(A)`. """ -@inline getunstoredindex(A::AbstractArray, I...) = - @interface interface(A) getunstoredindex(A, I...) +@inline getunstoredindex(A::AbstractArray, I...) = @interface interface(A) getunstoredindex( + A, I... +) """ isstored(A::AbstractArray, I...) -> Bool @@ -46,8 +48,9 @@ Similar to `Base.getindex`, new definitions should be in line with `IndexStyle(A Similar to `Base.setindex!`, new definitions should be in line with `IndexStyle(A)`. """ -@inline setstoredindex!(A::AbstractArray, v, I...) = - @interface interface(A) setstoredindex!(A, v, I...) +@inline setstoredindex!(A::AbstractArray, v, I...) = @interface interface(A) setstoredindex!( + A, v, I... +) """ setunstoredindex!(A::AbstractArray, v, I...) -> A @@ -56,8 +59,9 @@ Similar to `Base.setindex!`, new definitions should be in line with `IndexStyle( Similar to `Base.setindex!`, new definitions should be in line with `IndexStyle(A)`. """ -@inline setunstoredindex!(A::AbstractArray, v, I...) = - @interface interface(A) setunstoredindex!(A, v, I...) +@inline setunstoredindex!(A::AbstractArray, v, I...) = @interface interface(A) setunstoredindex!( + A, v, I... +) # Indices interface # ----------------- @@ -150,14 +154,16 @@ for f in (:isstored, :getunstoredindex, :getstoredindex) end # errors - $_f(::IndexStyle, A::AbstractArray, I...) = - error("`$f` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported") - - $error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = - throw(Base.CanonicalIndexError("$($f)", typeof(A))) - $error_if_canonical( - ::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N} - ) where {N} = throw(Base.CanonicalIndexError("$($f)", typeof(A))) + $_f(::IndexStyle, A::AbstractArray, I...) = error( + "`$f` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported" + ) + + $error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = throw( + Base.CanonicalIndexError("$($f)", typeof(A)) + ) + $error_if_canonical(::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}) where {N} = throw( + Base.CanonicalIndexError("$($f)", typeof(A)) + ) $error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing end end @@ -193,14 +199,16 @@ for f! in (:setunstoredindex!, :setstoredindex!) end # errors - $_f!(::IndexStyle, A::AbstractArray, I...) = - error("`$f!` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported") - - $error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = - throw(Base.CanonicalIndexError("$($(string(f!)))", typeof(A))) - $error_if_canonical( - ::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N} - ) where {N} = throw(Base.CanonicalIndexError("$($f!)", typeof(A))) + $_f!(::IndexStyle, A::AbstractArray, I...) = error( + "`$f!` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported" + ) + + $error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = throw( + Base.CanonicalIndexError("$($(string(f!)))", typeof(A)) + ) + $error_if_canonical(::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}) where {N} = throw( + Base.CanonicalIndexError("$($f!)", typeof(A)) + ) $error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing end end @@ -227,14 +235,16 @@ end @inline return setindex!(A, v, I...) end -@interface ::AbstractArrayInterface setunstoredindex!(A::AbstractArray, v, I::Int...) = - error("setunstoredindex! for $(typeof(A)) is not supported") +@interface ::AbstractArrayInterface setunstoredindex!(A::AbstractArray, v, I::Int...) = error( + "setunstoredindex! for $(typeof(A)) is not supported" +) -@interface ::AbstractArrayInterface eachstoredindex(A::AbstractArray, B::AbstractArray...) = - eachstoredindex(IndexStyle(A, B...), A, B...) -@interface ::AbstractArrayInterface eachstoredindex( - style::IndexStyle, A::AbstractArray, B::AbstractArray... -) = eachindex(style, A, B...) +@interface ::AbstractArrayInterface eachstoredindex(A::AbstractArray, B::AbstractArray...) = eachstoredindex( + IndexStyle(A, B...), A, B... +) +@interface ::AbstractArrayInterface eachstoredindex(style::IndexStyle, A::AbstractArray, B::AbstractArray...) = eachindex( + style, A, B... +) @interface ::AbstractArrayInterface storedvalues(A::AbstractArray) = values(A) @interface ::AbstractArrayInterface storedpairs(A::AbstractArray) = pairs(A) @@ -299,9 +309,9 @@ end end # required: -@interface ::AbstractSparseArrayInterface eachstoredindex( - style::IndexStyle, A::AbstractArray -) = throw(MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)})) +@interface ::AbstractSparseArrayInterface eachstoredindex(style::IndexStyle, A::AbstractArray) = throw( + MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)}) +) # derived but may be specialized: @interface ::AbstractSparseArrayInterface function eachstoredindex( @@ -379,8 +389,9 @@ for f! in (:setstoredindex!, :setunstoredindex!) end end -@interface ::AbstractSparseArrayInterface storedlength(A::AbstractArray) = - length(storedvalues(A)) +@interface ::AbstractSparseArrayInterface storedlength(A::AbstractArray) = length( + storedvalues(A) +) @interface ::AbstractSparseArrayInterface function storedpairs(A::AbstractArray) return Iterators.map(I -> (I => A[I]), eachstoredindex(A)) end diff --git a/src/wrappers.jl b/src/wrappers.jl index bd9e481..33ef3c1 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -201,8 +201,9 @@ else return view(CartesianIndices(x), LinearAlgebra.diagind(x)) end end -@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) = - _diagind(D, IndexCartesian()) +@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) = _diagind( + D, IndexCartesian() +) @interface ::AbstractArrayInterface function isstored(D::Diagonal, i::Int, j::Int) return i == j && checkbounds(Bool, D, i, j) diff --git a/test/runtests.jl b/test/runtests.jl index 1c52c3e..b4ae80f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,11 +14,13 @@ const GROUP = uppercase( ) "match files of the form `test_*.jl`, but exclude `*setup*.jl`" -istestfile(fn) = +function istestfile(fn) endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") +end "match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`" -isexamplefile(fn) = +function isexamplefile(fn) endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") +end @time begin # tests in groups based on folder structure From 261c787d0b8fe63c65d5be540d24b8837f856719 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Sat, 12 Apr 2025 08:56:16 -0400 Subject: [PATCH 2/2] Apply suggestions from code review --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index b4ae80f..98b2d2b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,11 +15,11 @@ const GROUP = uppercase( "match files of the form `test_*.jl`, but exclude `*setup*.jl`" function istestfile(fn) - endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") + return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") end "match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`" function isexamplefile(fn) - endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") + return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") end @time begin