diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index 0cd3114..fa4545c 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -1,25 +1,11 @@ name: TagBot + on: issue_comment: types: - created workflow_dispatch: - inputs: - lookback: - default: "3" -permissions: - actions: read - checks: read - contents: write - deployments: read - issues: read - discussions: read - packages: read - pages: read - pull-requests: read - repository-projects: read - security-events: read - statuses: read + jobs: TagBot: if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' @@ -28,4 +14,5 @@ jobs: - uses: JuliaRegistries/TagBot@v1 with: token: ${{ secrets.GITHUB_TOKEN }} + registry: ITensor/ITensorRegistry ssh: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3fc4743..d3c8686 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ ci: - skip: [runic] + skip: [itensor-formatter] repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -11,7 +11,7 @@ repos: - id: end-of-file-fixer exclude_types: [markdown] # incompatible with Literate.jl -- repo: https://github.com/fredrikekre/runic-pre-commit - rev: v2.0.1 +- repo: https://github.com/ITensor/ITensorFormatter.jl + rev: v0.2.9 hooks: - - id: runic + - id: itensor-formatter diff --git a/Project.toml b/Project.toml index 1d898af..5dfa1c4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "SparseArraysBase" uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208" -version = "0.9.3" +version = "0.9.4" authors = ["ITensor developers and contributors"] [workspace] diff --git a/README.md b/README.md index 2932aaf..5b66de5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/SparseArraysBase.jl/dev/) [![Build Status](https://github.com/ITensor/SparseArraysBase.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/SparseArraysBase.jl/actions/workflows/Tests.yml?query=branch%3Amain) [![Coverage](https://codecov.io/gh/ITensor/SparseArraysBase.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/SparseArraysBase.jl) -[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) +[![Code Style](https://img.shields.io/badge/code_style-ITensor-purple)](https://github.com/ITensor/ITensorFormatter.jl) [![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) ## Support diff --git a/docs/make.jl b/docs/make.jl index af887ba..8c8c51b 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -2,7 +2,7 @@ using Documenter: Documenter, DocMeta, deploydocs, makedocs using SparseArraysBase: SparseArraysBase DocMeta.setdocmeta!( - SparseArraysBase, :DocTestSetup, :(using SparseArraysBase); recursive = true, + SparseArraysBase, :DocTestSetup, :(using SparseArraysBase); recursive = true ) include("make_index.jl") @@ -14,11 +14,11 @@ makedocs(; format = Documenter.HTML(; canonical = "https://itensor.github.io/SparseArraysBase.jl", edit_link = "main", - assets = ["assets/favicon.ico", "assets/extras.css"], + assets = ["assets/favicon.ico", "assets/extras.css"] ), - pages = ["Home" => "index.md", "Reference" => "reference.md"], + pages = ["Home" => "index.md", "Reference" => "reference.md"] ) deploydocs(; - repo = "github.com/ITensor/SparseArraysBase.jl", devbranch = "main", push_preview = true, + repo = "github.com/ITensor/SparseArraysBase.jl", devbranch = "main", push_preview = true ) diff --git a/docs/make_index.jl b/docs/make_index.jl index 8039481..37e8b7e 100644 --- a/docs/make_index.jl +++ b/docs/make_index.jl @@ -17,5 +17,5 @@ Literate.markdown( joinpath(pkgdir(SparseArraysBase), "docs", "src"); flavor = Literate.DocumenterFlavor(), name = "index", - postprocess = ccq_logo, + postprocess = ccq_logo ) diff --git a/docs/make_readme.jl b/docs/make_readme.jl index 7537f73..f26b7b1 100644 --- a/docs/make_readme.jl +++ b/docs/make_readme.jl @@ -17,5 +17,5 @@ Literate.markdown( joinpath(pkgdir(SparseArraysBase)); flavor = Literate.CommonMarkFlavor(), name = "README", - postprocess = ccq_logo, + postprocess = ccq_logo ) diff --git a/examples/README.jl b/examples/README.jl index 4572484..7ae4198 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -4,7 +4,7 @@ # [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/SparseArraysBase.jl/dev/) # [![Build Status](https://github.com/ITensor/SparseArraysBase.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/SparseArraysBase.jl/actions/workflows/Tests.yml?query=branch%3Amain) # [![Coverage](https://codecov.io/gh/ITensor/SparseArraysBase.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/SparseArraysBase.jl) -# [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) +# [![Code Style](https://img.shields.io/badge/code_style-ITensor-purple)](https://github.com/ITensor/ITensorFormatter.jl) # [![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) # ## Support diff --git a/ext/SparseArraysBaseNamedDimsArraysExt/SparseArraysBaseNamedDimsArraysExt.jl b/ext/SparseArraysBaseNamedDimsArraysExt/SparseArraysBaseNamedDimsArraysExt.jl index c29bad0..8630347 100644 --- a/ext/SparseArraysBaseNamedDimsArraysExt/SparseArraysBaseNamedDimsArraysExt.jl +++ b/ext/SparseArraysBaseNamedDimsArraysExt/SparseArraysBaseNamedDimsArraysExt.jl @@ -11,7 +11,7 @@ function SparseArraysBase.dense(a::AbstractNamedDimsArray) end function SparseArraysBase.oneelement( - value, index::NTuple{N, Int}, ax::NTuple{N, AbstractNamedUnitRange}, + value, index::NTuple{N, Int}, ax::NTuple{N, AbstractNamedUnitRange} ) where {N} return nameddims(oneelement(value, index, denamed.(ax)), name.(ax)) end diff --git a/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl b/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl index 05f9c7a..94e32df 100644 --- a/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl +++ b/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl @@ -9,7 +9,7 @@ struct SparseArrayFusion <: FusionStyle end TensorAlgebra.FusionStyle(::Type{<:AnyAbstractSparseArray}) = SparseArrayFusion() function TensorAlgebra.matricize( - style::SparseArrayFusion, a::AbstractArray, length_codomain::Val, + style::SparseArrayFusion, a::AbstractArray, length_codomain::Val ) m = matricize(ReshapeFusion(), a, length_codomain) return convert(SparseMatrixCSC, m) @@ -18,7 +18,7 @@ function TensorAlgebra.unmatricize( style::SparseArrayFusion, m::AbstractMatrix, axes_codomain::Tuple{Vararg{AbstractUnitRange}}, - axes_domain::Tuple{Vararg{AbstractUnitRange}}, + axes_domain::Tuple{Vararg{AbstractUnitRange}} ) a = unmatricize(ReshapeFusion(), m, axes_codomain, axes_domain) # TODO: Use `similar_type(m)` instead of hardcoding to `SparseArrayDOK`? diff --git a/src/abstractsparsearray.jl b/src/abstractsparsearray.jl index 1444b53..3452ba2 100644 --- a/src/abstractsparsearray.jl +++ b/src/abstractsparsearray.jl @@ -52,14 +52,13 @@ function Base.similar(a::AnyAbstractSparseArray, T::Type, ax::Tuple{Vararg{Int}} return similar_sparsearray(a, T, ax) end function Base.similar( - a::AnyAbstractSparseArray, T::Type, ax::Tuple{Integer, Vararg{Integer}}, + a::AnyAbstractSparseArray, T::Type, ax::Tuple{Integer, Vararg{Integer}} ) return similar_sparsearray(a, T, ax) end function Base.similar( - a::AnyAbstractSparseArray, - T::Type, - ax::Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}, + a::AnyAbstractSparseArray, T::Type, + ax::Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}} ) return similar_sparsearray(a, T, ax) end @@ -98,7 +97,7 @@ function Base.permutedims!(dst, a::AnyAbstractSparseArray, perm) end function LinearAlgebra.mul!( dst::AbstractMatrix, a1::AnyAbstractSparseArray, a2::AnyAbstractSparseArray, - α::Number, β::Number, + α::Number, β::Number ) return style(a1, a2)(mul!)(dst, a1, a2, α, β) end @@ -146,7 +145,7 @@ function Base.print_array(io::IO, a::AnyAbstractSparseArray) return @invoke Base.print_array(io::typeof(io), a′::AbstractArray{<:Any, ndims(a)}) end function Base.replace_in_print_matrix( - a::AnyAbstractSparseVecOrMat, i::Integer, j::Integer, s::AbstractString, + a::AnyAbstractSparseVecOrMat, i::Integer, j::Integer, s::AbstractString ) return isstored(a, i, j) ? s : Base.replace_with_centered_mark(s) end @@ -252,17 +251,19 @@ end @doc """ sparserand!([rng], A::AbstractArray; density::Real=0.5, randfun::Function=rand) -> A -Overwrite part of an array with random entries, where the probability of overwriting is independently given by `density`. +Overwrite part of an array with random entries, where the probability of overwriting is +independently given by `density`. The optional `rng` argument specifies a random number generator, see also `Random`. -The optional `randfun` argument can be used to control the type of random elements, and should support -the signature `randfun(rng, T, N)` to generate `N` entries of type `T`. +The optional `randfun` argument can be used to control the type of random elements, and +should support the signature `randfun(rng, T, N)` to generate `N` entries of type `T`. See also [`sparserand`](@ref). """ sparserand! sparserand!(A::AbstractArray; kwargs...) = sparserand!(default_rng(), A; kwargs...) function sparserand!( - rng::AbstractRNG, A::AbstractArray; density::Real = 0.5, randfun::Function = Random.rand, + rng::AbstractRNG, A::AbstractArray; density::Real = 0.5, + randfun::Function = Random.rand ) ArrayLayouts.zero!(A) rand_inds = Random.randsubseq(rng, eachindex(A), density) @@ -275,30 +276,26 @@ end using ArrayLayouts: ArrayLayouts, MemoryLayout using LinearAlgebra: LinearAlgebra, Adjoint function ArrayLayouts.MemoryLayout( - ::Type{Transpose{T, P}}, + ::Type{Transpose{T, P}} ) where {T, P <: AbstractSparseMatrix} return MemoryLayout(P) end function ArrayLayouts.MemoryLayout( - ::Type{Adjoint{T, P}}, + ::Type{Adjoint{T, P}} ) where {T, P <: AbstractSparseMatrix} return MemoryLayout(P) end function LinearAlgebra.mul!( dest::AbstractMatrix, - A::Adjoint{<:Any, <:AbstractSparseMatrix}, - B::AbstractSparseMatrix, - α::Number, - β::Number, + A::Adjoint{<:Any, <:AbstractSparseMatrix}, B::AbstractSparseMatrix, + α::Number, β::Number ) return ArrayLayouts.mul!(dest, A, B, α, β) end function LinearAlgebra.mul!( dest::AbstractMatrix, - A::AbstractSparseMatrix, - B::Adjoint{<:Any, <:AbstractSparseMatrix}, - α::Number, - β::Number, + A::AbstractSparseMatrix, B::Adjoint{<:Any, <:AbstractSparseMatrix}, + α::Number, β::Number ) return ArrayLayouts.mul!(dest, A, B, α, β) end @@ -306,8 +303,7 @@ function LinearAlgebra.mul!( dest::AbstractMatrix, A::Adjoint{<:Any, <:AbstractSparseMatrix}, B::Adjoint{<:Any, <:AbstractSparseMatrix}, - α::Number, - β::Number, + α::Number, β::Number ) return ArrayLayouts.mul!(dest, A, B, α, β) end diff --git a/src/abstractsparsearraystyle.jl b/src/abstractsparsearraystyle.jl index 18cc7cc..3892687 100644 --- a/src/abstractsparsearraystyle.jl +++ b/src/abstractsparsearraystyle.jl @@ -59,13 +59,13 @@ abstract type AbstractSparseArrayImplementationStyle <: AbstractArrayImplementat function FunctionImplementations.ImplementationStyle( style1::AbstractSparseArrayImplementationStyle, - style2::AbstractSparseArrayImplementationStyle, + style2::AbstractSparseArrayImplementationStyle ) return SparseArrayImplementationStyle() end function FunctionImplementations.ImplementationStyle( style1::AbstractSparseArrayImplementationStyle, - style2::AbstractArrayImplementationStyle, + style2::AbstractArrayImplementationStyle ) return style1 end @@ -74,7 +74,7 @@ end using FunctionImplementations: DefaultArrayImplementationStyle function FunctionImplementations.ImplementationStyle( style1::AbstractSparseArrayImplementationStyle, - style2::DefaultArrayImplementationStyle, + style2::DefaultArrayImplementationStyle ) return style1 end @@ -122,30 +122,23 @@ end using LinearAlgebra: mul! function mul!!( - a_dest::AbstractMatrix, - a1::AbstractMatrix, - a2::AbstractMatrix, - α::Number = true, - β::Number = false, + a_dest::AbstractMatrix, a1::AbstractMatrix, a2::AbstractMatrix, + α::Number = true, β::Number = false ) mul!(a_dest, a1, a2, α, β) return a_dest end function mul!!( - a_dest::Number, a1::Number, a2::Number, α::Number = true, β::Number = false, + a_dest::Number, a1::Number, a2::Number, α::Number = true, β::Number = false ) return a1 * a2 * α + a_dest * β end # a1 * a2 * α + a_dest * β function _mul!_sparse( - a_dest::AbstractArray, - a1::AbstractArray, - a2::AbstractArray, - α::Number = true, - β::Number = false; - (mul!!) = (mul!!), + a_dest::AbstractArray, a1::AbstractArray, a2::AbstractArray, + α::Number = true, β::Number = false; (mul!!) = (mul!!) ) a_dest .*= β β′ = one(Bool) @@ -165,7 +158,9 @@ function _mul!_sparse( end function ArrayLayouts.materialize!( - m::MatMulMatAdd{<:AbstractSparseLayout, <:AbstractSparseLayout, <:AbstractSparseLayout}, + m::MatMulMatAdd{ + <:AbstractSparseLayout, <:AbstractSparseLayout, <:AbstractSparseLayout, + } ) _mul!_sparse(m.C, m.A, m.B, m.α, m.β) return m.C diff --git a/src/indexing.jl b/src/indexing.jl index 069eb50..9ead7f0 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -145,34 +145,33 @@ for f in (:isstored, :getunstoredindex, :getstoredindex) # cartesian indexing @inline function $_f( - ::IndexCartesian, - A::AbstractArray, - I::Vararg{Int, M}, + ::IndexCartesian, A::AbstractArray, I::Vararg{Int, M} ) where {M} @boundscheck checkbounds(A, I...) return @inbounds $f(A, Base._to_subscript_indices(A, I...)...) end @inline function $_f( - ::IndexCartesian, A::AbstractArray{<:Any, N}, I::Vararg{Int, N}, + ::IndexCartesian, A::AbstractArray{<:Any, N}, I::Vararg{Int, N} ) where {N} return $f(A, I...) 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)), - ) + function $_f(::IndexStyle, A::AbstractArray, I...) + return error( + "`$($f)` for $("$(typeof(A))") with types $("$(typeof(I))") " * + "is not supported" + ) + end + + function $error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) + return throw(Base.CanonicalIndexError("$($f)", typeof(A))) + end + function $error_if_canonical( + ::IndexCartesian, A::AbstractArray{<:Any, N}, ::Vararg{Int, N} + ) where {N} + return throw(Base.CanonicalIndexError("$($f)", typeof(A))) + end $error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing end end @@ -192,10 +191,7 @@ for f! in (:setstoredindex!, :setunstoredindex!) @inline $_f!(::IndexLinear, A::AbstractVector, v, i::Int) = $f!(A, v, i) @inline $_f!(::IndexLinear, A::AbstractArray, v, i::Int) = $f!(A, v, i) @inline function $_f!( - ::IndexLinear, - A::AbstractArray, - v, - I::Vararg{Int, M}, + ::IndexLinear, A::AbstractArray, v, I::Vararg{Int, M} ) where {M} @boundscheck checkbounds(A, I...) return @inbounds $f!(A, v, Base._to_linear_index(A, I...)) @@ -203,35 +199,34 @@ for f! in (:setstoredindex!, :setunstoredindex!) # cartesian indexing @inline function $_f!( - ::IndexCartesian, - A::AbstractArray, - v, - I::Vararg{Int, M}, + ::IndexCartesian, A::AbstractArray, v, I::Vararg{Int, M} ) where {M} @boundscheck checkbounds(A, I...) return @inbounds $f!(A, v, Base._to_subscript_indices(A, I...)...) end @inline function $_f!( - ::IndexCartesian, A::AbstractArray{<:Any, N}, v, I::Vararg{Int, N}, + ::IndexCartesian, A::AbstractArray{<:Any, N}, v, I::Vararg{Int, N} ) where {N} return $f!(A, v, I...) 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)), - ) + function $_f!(::IndexStyle, A::AbstractArray, I...) + return error( + "`$f!` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported" + ) + end + + function $error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) + return throw( + Base.CanonicalIndexError("$($(string(f!)))", typeof(A)) + ) + end + function $error_if_canonical( + ::IndexCartesian, A::AbstractArray{<:Any, N}, ::Vararg{Int, N} + ) where {N} + return throw(Base.CanonicalIndexError("$($f!)", typeof(A))) + end $error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing end end @@ -266,9 +261,7 @@ function (::Implementation{typeof(eachstoredindex)})(A::AbstractArray, B::Abstra return eachstoredindex(IndexStyle(A, B...), A, B...) end function (::Implementation{typeof(eachstoredindex)})( - style::IndexStyle, - A::AbstractArray, - B::AbstractArray..., + style::IndexStyle, A::AbstractArray, B::AbstractArray... ) return eachindex(style, A, B...) end @@ -282,9 +275,7 @@ end # canonical errors are moved to `isstored`, `getstoredindex` and `getunstoredindex` # so no errors at this level by defining both IndexLinear and IndexCartesian const getindex_sparse = sparse_style(getindex) -function getindex_sparse( - A::AbstractArray{<:Any, N}, I::Vararg{Int, N}, - ) where {N} +function getindex_sparse(A::AbstractArray{<:Any, N}, I::Vararg{Int, N}) where {N} @_propagate_inbounds_meta @boundscheck checkbounds(A, I...) # generally isstored requires bounds checking return @inbounds isstored(A, I...) ? getstoredindex(A, I...) : getunstoredindex(A, I...) @@ -302,7 +293,7 @@ function getindex_sparse(A::AbstractVector, I::Int) end # TODO: Make this more general, use `Base.to_index`. function getindex_sparse( - a::AbstractArray{<:Any, N}, I::CartesianIndex{N}, + a::AbstractArray{<:Any, N}, I::CartesianIndex{N} ) where {N} return getindex_sparse(a, Tuple(I)...) end @@ -313,7 +304,7 @@ end const setindex!_sparse = sparse_style(setindex!) function setindex!_sparse( - A::AbstractArray{<:Any, N}, v, I::Vararg{Int, N}, + A::AbstractArray{<:Any, N}, v, I::Vararg{Int, N} ) where {N} @_propagate_inbounds_meta @boundscheck checkbounds(A, I...) @@ -324,7 +315,7 @@ function setindex!_sparse( end end function setindex!_sparse( - A::AbstractArray, v, I::Int, + A::AbstractArray, v, I::Int ) @_propagate_inbounds_meta @boundscheck checkbounds(A, I) @@ -336,7 +327,7 @@ function setindex!_sparse( end # disambiguate vectors function setindex!_sparse( - A::AbstractVector, v, I::Int, + A::AbstractVector, v, I::Int ) @_propagate_inbounds_meta @boundscheck checkbounds(A, I) @@ -348,7 +339,7 @@ function setindex!_sparse( end # TODO: Make this more general, use `Base.to_index`. function setindex!_sparse( - a::AbstractArray{<:Any, N}, value, I::CartesianIndex{N}, + a::AbstractArray{<:Any, N}, value, I::CartesianIndex{N} ) where {N} return setindex!(a, value, Tuple(I)...) end @@ -364,9 +355,7 @@ end # required: one implementation for canonical index style const eachstoredindex_sparse = sparse_style(eachstoredindex) -function eachstoredindex_sparse( - style::IndexStyle, A::AbstractArray, - ) +function eachstoredindex_sparse(style::IndexStyle, A::AbstractArray) error_if_canonical_eachstoredindex(style, A) inds = eachstoredindex(A) if style === IndexCartesian() @@ -382,7 +371,7 @@ end # derived but may be specialized: function eachstoredindex_sparse( - style::IndexStyle, A::AbstractArray, B::AbstractArray..., + style::IndexStyle, A::AbstractArray, B::AbstractArray... ) return union(map(Base.Fix1(eachstoredindex, style), (A, B...))...) end @@ -414,31 +403,26 @@ function isstored_sparse(A::AbstractArray, I::Int...) end const getunstoredindex_sparse = sparse_style(getunstoredindex) -function getunstoredindex_sparse( - A::AbstractArray, I::Int..., - ) +function getunstoredindex_sparse(A::AbstractArray, I::Int...) @_propagate_inbounds_meta style = IndexStyle(A) - # canonical linear indexing if style == IndexLinear() && length(I) == 1 @boundscheck checkbounds(A, I...) return zero(eltype(A)) end - # canonical cartesian indexing if style == IndexCartesian() && length(I) == ndims(A) @boundscheck checkbounds(A, I...) return zero(eltype(A)) end - # non-canonical indexing return _getunstoredindex(style, A, Base.to_indices(A, I)...) end const getstoredindex_sparse = sparse_style(getstoredindex) function getstoredindex_sparse( - A::AbstractArray, I::Int..., + A::AbstractArray, I::Int... ) @_propagate_inbounds_meta style = IndexStyle(A) @@ -476,12 +460,12 @@ eg: ArrayLayouts.@layoutgetindex ArrayType TODO: decide if we need the interface approach at all here =# for (Tr, Tc) in Iterators.product( - Iterators.repeated((:Colon, :AbstractUnitRange, :AbstractVector, :Integer), 2)..., + Iterators.repeated((:Colon, :AbstractUnitRange, :AbstractVector, :Integer), 2)... ) Tr === Tc === :Integer && continue @eval begin function getindex_sparse( - A::AbstractMatrix, kr::$Tr, jr::$Tc, + A::AbstractMatrix, kr::$Tr, jr::$Tc ) Base.@inline # needed to make boundschecks work return ArrayLayouts.layout_getindex(A, kr, jr) diff --git a/src/map.jl b/src/map.jl index 80dced7..b18bcd0 100644 --- a/src/map.jl +++ b/src/map.jl @@ -70,7 +70,7 @@ end # ------ const map_sparse = sparse_style(map) function map_sparse( - f, A::AbstractArray, Bs::AbstractArray..., + f, A::AbstractArray, Bs::AbstractArray... ) f_pres = ZeroPreserving(f, A, Bs...) return map_sparse(f_pres, A, Bs...) @@ -91,7 +91,7 @@ end const map!_sparse = sparse_style(map!) function map!_sparse( - f, C::AbstractArray, A::AbstractArray, Bs::AbstractArray..., + f, C::AbstractArray, A::AbstractArray, Bs::AbstractArray... ) f_pres = ZeroPreserving(f, A, Bs...) return map!_sparse(f_pres, C, A, Bs...) @@ -99,7 +99,7 @@ end # This isn't an overload of `Base.map!` since that leads to ambiguity errors. function map!_sparse( - f::ZeroPreserving, C::AbstractArray, A::AbstractArray, Bs::AbstractArray..., + f::ZeroPreserving, C::AbstractArray, A::AbstractArray, Bs::AbstractArray... ) checkshape(C, A, Bs...) unaliased = map(Base.Fix1(Base.unalias, C), (A, Bs...)) @@ -126,7 +126,7 @@ end # ----------------- const copyto!_sparse = sparse_style(copyto!) function copyto!_sparse( - dest::AbstractArray, src::AbstractArray, + dest::AbstractArray, src::AbstractArray ) map!_sparse(identity, dest, src) return dest @@ -134,7 +134,7 @@ end const permutedims!_sparse = sparse_style(permutedims!) function permutedims!_sparse( - a_dest::AbstractArray, a_src::AbstractArray, perm, + a_dest::AbstractArray, a_src::AbstractArray, perm ) return map!(identity, a_dest, PermutedDimsArray(a_src, perm)) end @@ -144,7 +144,7 @@ function map_stored! end const map_stored!_sparse = sparse_style(map_stored!) function map_stored!_sparse( - f, a_dest::AbstractArray, as::AbstractArray..., + f, a_dest::AbstractArray, as::AbstractArray... ) map!_sparse(WeakPreserving(f), a_dest, as...) return a_dest @@ -155,7 +155,7 @@ function map_all! end const map_all!_sparse = sparse_style(map_all!) function map_all!_sparse( - f, a_dest::AbstractArray, as::AbstractArray..., + f, a_dest::AbstractArray, as::AbstractArray... ) map!_sparse(NonPreserving(f), a_dest, as...) return a_dest diff --git a/src/oneelementarray.jl b/src/oneelementarray.jl index 3799406..2d99548 100644 --- a/src/oneelementarray.jl +++ b/src/oneelementarray.jl @@ -10,7 +10,7 @@ struct OneElementArray{T, N, I, Unstored <: AbstractArray{T, N}} <: index::I unstored::Unstored global @inline function _OneElementArray( - value::T, index::I, unstored::Unstored, + value::T, index::I, unstored::Unstored ) where {T, N, I, Unstored <: AbstractArray{T, N}} @assert N == length(index) return new{T, N, I, Unstored}(value, index, unstored) @@ -21,72 +21,72 @@ const OneElementVector{T} = OneElementArray{T, 1} const OneElementMatrix{T} = OneElementArray{T, 2} function OneElementArray{T, N}( - value, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + value, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {T, N} return _OneElementArray(convert(T, value), index, Zeros{T}(axes)) end function OneElementArray{<:Any, N}( - value::T, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + value::T, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {T, N} return OneElementArray{T, N}(value, index, axes) end function OneElementArray( - value::T, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + value::T, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {T, N} return OneElementArray{T, N}(value, index, axes) end function OneElementArray{T, N}( - index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {T, N} return OneElementArray{T, N}(one(T), index, axes) end function OneElementArray{<:Any, N}( - index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {N} return OneElementArray{Bool, N}(index, axes) end function OneElementArray{T}( - index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {T, N} return OneElementArray{T, N}(index, axes) end function OneElementArray( index::NTuple{N, Int}, - axes::NTuple{N, AbstractUnitRange}, + axes::NTuple{N, AbstractUnitRange} ) where {N} return OneElementArray{Bool, N}(index, axes) end function OneElementArray{T, N}( - value, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N}, + value, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N} ) where {T, N} return OneElementArray{T, N}(value, last.(ax_ind), first.(ax_ind)) end function OneElementArray{<:Any, N}( - value::T, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N}, + value::T, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N} ) where {T, N} return OneElementArray{T, N}(value, ax_ind...) end function OneElementArray{T}( - value, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N}, + value, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N} ) where {T, N} return OneElementArray{T, N}(value, ax_ind...) end function OneElementArray( - value::T, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N}, + value::T, ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N} ) where {T, N} return OneElementArray{T, N}(value, ax_ind...) end function OneElementArray{T, N}( - ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N}, + ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N} ) where {T, N} return OneElementArray{T, N}(last.(ax_ind), first.(ax_ind)) end function OneElementArray{<:Any, N}( - ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N}, + ax_ind::Vararg{Pair{<:AbstractUnitRange, Int}, N} ) where {N} return OneElementArray{Bool, N}(ax_ind...) end @@ -152,22 +152,22 @@ function OneElementArray() end function OneElementArray{T, N}( - value, index::NTuple{N, Int}, size::NTuple{N, Integer}, + value, index::NTuple{N, Int}, size::NTuple{N, Integer} ) where {T, N} return OneElementArray{T, N}(value, index, Base.oneto.(size)) end function OneElementArray{<:Any, N}( - value::T, index::NTuple{N, Int}, size::NTuple{N, Integer}, + value::T, index::NTuple{N, Int}, size::NTuple{N, Integer} ) where {T, N} return OneElementArray{T, N}(value, index, size) end function OneElementArray{T}( - value, index::NTuple{N, Int}, size::NTuple{N, Integer}, + value, index::NTuple{N, Int}, size::NTuple{N, Integer} ) where {T, N} return OneElementArray{T, N}(value, index, size) end function OneElementArray( - value::T, index::NTuple{N, Int}, size::NTuple{N, Integer}, + value::T, index::NTuple{N, Int}, size::NTuple{N, Integer} ) where {T, N} return OneElementArray{T, N}(value, index, Base.oneto.(size)) end @@ -177,7 +177,7 @@ function OneElementArray{T, N}(index::NTuple{N, Int}, size::NTuple{N, Integer}) end function OneElementArray{<:Any, N}( index::NTuple{N, Int}, - size::NTuple{N, Integer}, + size::NTuple{N, Integer} ) where {N} return OneElementArray{Bool, N}(index, size) end @@ -217,12 +217,12 @@ end # Interface to overload for constructing arrays like `OneElementArray`, # that may not be `OneElementArray` (i.e. wrapped versions). function oneelement( - value, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + value, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {N} return OneElementArray(value, index, axes) end function oneelement( - eltype::Type, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange}, + eltype::Type, index::NTuple{N, Int}, axes::NTuple{N, AbstractUnitRange} ) where {N} return oneelement(one(eltype), index, axes) end diff --git a/src/sparsearraydok.jl b/src/sparsearraydok.jl index 7aa84b1..0050691 100644 --- a/src/sparsearraydok.jl +++ b/src/sparsearraydok.jl @@ -16,7 +16,7 @@ struct SparseArrayDOK{T, N, Unstored <: AbstractArray{T, N}} <: AbstractSparseAr storage::DOKStorage{T, N} unstored::Unstored global @inline function _SparseArrayDOK( - storage::DOKStorage{T, N}, unstored::Unstored, + storage::DOKStorage{T, N}, unstored::Unstored ) where {T, N, Unstored <: AbstractArray{T, N}} return new{T, N, Unstored}(storage, unstored) end @@ -87,7 +87,7 @@ end return unstored(a)[I...] end @inline function setstoredindex!( - a::SparseArrayDOK{<:Any, N}, value, I::Vararg{Int, N}, + a::SparseArrayDOK{<:Any, N}, value, I::Vararg{Int, N} ) where {N} # `isstored` includes a boundscheck as well @boundscheck isstored(a, I...) || @@ -97,7 +97,7 @@ end return a end @inline function setunstoredindex!( - a::SparseArrayDOK{<:Any, N}, value, I::Vararg{Int, N}, + a::SparseArrayDOK{<:Any, N}, value, I::Vararg{Int, N} ) where {N} @boundscheck checkbounds(a, I...) insert!(storage(a), CartesianIndex(I), value) diff --git a/src/sparsearrays.jl b/src/sparsearrays.jl index 8f87bb3..e8f7b7c 100644 --- a/src/sparsearrays.jl +++ b/src/sparsearrays.jl @@ -21,12 +21,12 @@ function SparseArrayDOK(a::Base.ReshapedArray{<:Any, <:Any, <:AbstractSparseMatr return SparseArrayDOK{eltype(a), ndims(a)}(a) end function SparseArrayDOK{T}( - a::Base.ReshapedArray{<:Any, <:Any, <:AbstractSparseMatrixCSC}, + a::Base.ReshapedArray{<:Any, <:Any, <:AbstractSparseMatrixCSC} ) where {T} return SparseArrayDOK{T, ndims(a)}(a) end function SparseArrayDOK{T, N}( - a::Base.ReshapedArray{<:Any, N, <:AbstractSparseMatrixCSC}, + a::Base.ReshapedArray{<:Any, N, <:AbstractSparseMatrixCSC} ) where {T, N} a′ = SparseArrayDOK{T, N}(undef, size(a)) for I in eachstoredindex(a) diff --git a/src/sparsearraystyle.jl b/src/sparsearraystyle.jl index 8a4ac2f..f998f2a 100644 --- a/src/sparsearraystyle.jl +++ b/src/sparsearraystyle.jl @@ -66,7 +66,7 @@ end const mapreduce_sparse = sparse_style(mapreduce) function mapreduce_sparse( - f, op, as::AbstractArray...; init = reduce_init(f, op, as...), kwargs..., + f, op, as::AbstractArray...; init = reduce_init(f, op, as...), kwargs... ) # TODO: Generalize this. @assert isone(length(as)) @@ -86,7 +86,7 @@ using MapBroadcast: Mapped # TODO: Look into `SparseArrays.capturescalars`: # https://github.com/JuliaSparse/SparseArrays.jl/blob/1beb0e4a4618b0399907b0000c43d9f66d34accc/src/higherorderfns.jl#L1092-L1102 function Base.copyto!( - a_dest::AbstractArray, bc::Base.Broadcast.Broadcasted{<:SparseArrayStyle}, + a_dest::AbstractArray, bc::Base.Broadcast.Broadcasted{<:SparseArrayStyle} ) m = Mapped(bc) map!(m.f, a_dest, m.args...) @@ -94,7 +94,7 @@ function Base.copyto!( end function Base.similar( - bc::Base.Broadcast.Broadcasted{<:SparseArrayStyle}, elt::Type, ax, + bc::Base.Broadcast.Broadcasted{<:SparseArrayStyle}, elt::Type, ax ) return similar(SparseArrayDOK{elt}, ax) end @@ -102,8 +102,8 @@ end using ArrayLayouts: ArrayLayouts const mul!_sparse = sparse_style(mul!) function mul!_sparse( - a_dest::AbstractVecOrMat, a1::AbstractVecOrMat, a2::AbstractVecOrMat, α::Number, - β::Number, + a_dest::AbstractVecOrMat, a1::AbstractVecOrMat, a2::AbstractVecOrMat, + α::Number, β::Number ) return ArrayLayouts.mul!(a_dest, a1, a2, α, β) end diff --git a/src/wrappers.jl b/src/wrappers.jl index 2c0ed61..7deee7c 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -54,14 +54,12 @@ end perm(::PermutedDimsArray{<:Any, <:Any, p}) where {p} = p iperm(::PermutedDimsArray{<:Any, <:Any, <:Any, ip}) where {ip} = ip function index_to_parentindex( - a::PermutedDimsArray{<:Any, N}, - I::CartesianIndex{N}, + a::PermutedDimsArray{<:Any, N}, I::CartesianIndex{N} ) where {N} return CartesianIndex(genperm(I, iperm(a))) end function parentindex_to_index( - a::PermutedDimsArray{<:Any, N}, - I::CartesianIndex{N}, + a::PermutedDimsArray{<:Any, N}, I::CartesianIndex{N} ) where {N} return CartesianIndex(genperm(I, perm(a))) end @@ -106,7 +104,7 @@ function parentindex_to_index(a::SubArray, I::CartesianIndex) return CartesianIndex( map(nonscalardims) do d return findfirst(==(I[d]), parentindices(a)[d]) - end, + end ) end ## TODO: Use this and something similar for `Dictionary` to make a faster @@ -162,34 +160,34 @@ for type in (:Adjoint, :PermutedDimsArray, :ReshapedArray, :SubArray, :Transpose return map(Base.Fix1(parentindex_to_index, a), eachstoredparentindex(a)) end function eachstoredindex_sparse( - style::IndexStyle, a::$type, + style::IndexStyle, a::$type ) # TODO: Make lazy with `Iterators.map`. return map(Base.Fix1(parentindex_to_index, a), eachstoredparentindex(style, a)) end function getstoredindex_sparse(a::$type, I::Int...) return parentvalue_to_value( - a, getstoredindex(parent(a), index_to_parentindex(a, I...)...), + a, getstoredindex(parent(a), index_to_parentindex(a, I...)...) ) end function getunstoredindex_sparse(a::$type, I::Int...) return parentvalue_to_value( - a, getunstoredindex(parent(a), index_to_parentindex(a, I...)...), + a, getunstoredindex(parent(a), index_to_parentindex(a, I...)...) ) end function setstoredindex!_sparse( - a::$type, value, I::Int..., + a::$type, value, I::Int... ) setstoredindex!( - parent(a), value_to_parentvalue(a, value), index_to_parentindex(a, I...)..., + parent(a), value_to_parentvalue(a, value), index_to_parentindex(a, I...)... ) return a end function setunstoredindex!_sparse( - a::$type, value, I::Int..., + a::$type, value, I::Int... ) setunstoredindex!( - parent(a), value_to_parentvalue(a, value), index_to_parentindex(a, I...)..., + parent(a), value_to_parentvalue(a, value), index_to_parentindex(a, I...)... ) return a end diff --git a/test/runtests.jl b/test/runtests.jl index fe78bec..16689fa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,7 +10,7 @@ const GROUP = uppercase( get(ENV, "GROUP", "ALL") else only(match(pat, ARGS[arg_id]).captures) - end, + end ) """ @@ -62,7 +62,7 @@ end :macrocall, GlobalRef(Suppressor, Symbol("@suppress")), LineNumberNode(@__LINE__, @__FILE__), - :(include($filename)), + :(include($filename)) ) ) end diff --git a/test/test_dense.jl b/test/test_dense.jl index 920eb24..bed2dea 100644 --- a/test/test_dense.jl +++ b/test/test_dense.jl @@ -34,7 +34,7 @@ arrayts = (Array, JLArray) @testset "Custom sparse array" begin s = TestDenseUtils.MySparseArrayDOK( dev(elt[2, 4]), - Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4), + Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4) ) d = dense(s) @test d isa arrayt{elt, 2} diff --git a/test/test_sparse_style.jl b/test/test_sparse_style.jl index 1e3fbab..0b71162 100644 --- a/test/test_sparse_style.jl +++ b/test/test_sparse_style.jl @@ -19,35 +19,35 @@ end @test sparse_style ≡ SparseArrayImplementationStyle() @test ImplementationStyle( SparseArrayImplementationStyle(), - SparseArrayImplementationStyle(), + SparseArrayImplementationStyle() ) ≡ SparseArrayImplementationStyle() @test ImplementationStyle( TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle(), - SparseArrayImplementationStyle(), + SparseArrayImplementationStyle() ) ≡ SparseArrayImplementationStyle() @test ImplementationStyle( SparseArrayImplementationStyle(), - TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle(), + TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle() ) ≡ SparseArrayImplementationStyle() @test style(TestSparseImplementationStyleUtils.MySparseArray{Float64, 2}((2, 2))) ≡ TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle() @test style( sparsezeros(2, 2), - TestSparseImplementationStyleUtils.MySparseArray{Float64, 2}((2, 2)), + TestSparseImplementationStyleUtils.MySparseArray{Float64, 2}((2, 2)) ) ≡ SparseArrayImplementationStyle() # Regression tests for ambiguity caused by combining AbstractSparseArrayStyle with # DefaultArrayStyle. @test ImplementationStyle( TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle(), - DefaultArrayImplementationStyle(), + DefaultArrayImplementationStyle() ) ≡ TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle() @test style( TestSparseImplementationStyleUtils.MySparseArray{Float64, 2}((2, 2)), - randn(2, 2), + randn(2, 2) ) ≡ TestSparseImplementationStyleUtils.MySparseArrayImplementationStyle() end