Skip to content

Automatic JuliaFormatter.jl run #55

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 2 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.5.5"
version = "0.5.6"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
83 changes: 47 additions & 36 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

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)
Expand All @@ -25,8 +26,9 @@

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
Expand All @@ -46,8 +48,9 @@

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
Expand All @@ -56,8 +59,9 @@

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
# -----------------
Expand Down Expand Up @@ -150,14 +154,16 @@
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(

Check warning on line 157 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L157

Added line #L157 was not covered by tests
"`$f` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported"
)

$error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = throw(

Check warning on line 161 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L161

Added line #L161 was not covered by tests
Base.CanonicalIndexError("$($f)", typeof(A))
)
$error_if_canonical(::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}) where {N} = throw(

Check warning on line 164 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L164

Added line #L164 was not covered by tests
Base.CanonicalIndexError("$($f)", typeof(A))
)
$error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing
end
end
Expand Down Expand Up @@ -193,14 +199,16 @@
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(

Check warning on line 202 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L202

Added line #L202 was not covered by tests
"`$f!` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported"
)

$error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = throw(

Check warning on line 206 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L206

Added line #L206 was not covered by tests
Base.CanonicalIndexError("$($(string(f!)))", typeof(A))
)
$error_if_canonical(::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}) where {N} = throw(

Check warning on line 209 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L209

Added line #L209 was not covered by tests
Base.CanonicalIndexError("$($f!)", typeof(A))
)
$error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing
end
end
Expand All @@ -227,14 +235,16 @@
@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)
Expand Down Expand Up @@ -299,9 +309,9 @@
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(

Check warning on line 312 in src/indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/indexing.jl#L312

Added line #L312 was not covered by tests
MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)})
)

# derived but may be specialized:
@interface ::AbstractSparseArrayInterface function eachstoredindex(
Expand Down Expand Up @@ -379,8 +389,9 @@
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
Expand Down
5 changes: 3 additions & 2 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ const GROUP = uppercase(
)

"match files of the form `test_*.jl`, but exclude `*setup*.jl`"
istestfile(fn) =
endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup")
function istestfile(fn)
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`"
isexamplefile(fn) =
endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
function isexamplefile(fn)
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
end

@time begin
# tests in groups based on folder structure
Expand Down
Loading