From ce183eae3a0c1170703eeccfa95ea89133c86ef4 Mon Sep 17 00:00:00 2001 From: mtfishman <7855256+mtfishman@users.noreply.github.com> Date: Thu, 9 Oct 2025 01:41:06 +0000 Subject: [PATCH] Format .jl files (Runic) --- Project.toml | 2 +- docs/make.jl | 22 +-- docs/make_index.jl | 16 +- docs/make_readme.jl | 16 +- examples/README.jl | 2 +- src/NestedPermutedDimsArrays.jl | 286 ++++++++++++++++---------------- test/runtests.jl | 76 ++++----- test/test_aqua.jl | 2 +- test/test_basics.jl | 34 ++-- 9 files changed, 229 insertions(+), 227 deletions(-) diff --git a/Project.toml b/Project.toml index 6a183b3..703bf28 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NestedPermutedDimsArrays" uuid = "2c2a8ec4-3cfc-4276-aa3e-1307b4294e58" +version = "0.1.4" authors = ["ITensor developers and contributors"] -version = "0.1.3" [compat] julia = "1.10" diff --git a/docs/make.jl b/docs/make.jl index c0c8916..bdd0cb9 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -2,23 +2,23 @@ using NestedPermutedDimsArrays: NestedPermutedDimsArrays using Documenter: Documenter, DocMeta, deploydocs, makedocs DocMeta.setdocmeta!( - NestedPermutedDimsArrays, :DocTestSetup, :(using NestedPermutedDimsArrays); recursive=true + NestedPermutedDimsArrays, :DocTestSetup, :(using NestedPermutedDimsArrays); recursive = true ) include("make_index.jl") makedocs(; - modules=[NestedPermutedDimsArrays], - authors="ITensor developers and contributors", - sitename="NestedPermutedDimsArrays.jl", - format=Documenter.HTML(; - canonical="https://itensor.github.io/NestedPermutedDimsArrays.jl", - edit_link="main", - assets=["assets/favicon.ico", "assets/extras.css"], - ), - pages=["Home" => "index.md", "Reference" => "reference.md"], + modules = [NestedPermutedDimsArrays], + authors = "ITensor developers and contributors", + sitename = "NestedPermutedDimsArrays.jl", + format = Documenter.HTML(; + canonical = "https://itensor.github.io/NestedPermutedDimsArrays.jl", + edit_link = "main", + assets = ["assets/favicon.ico", "assets/extras.css"], + ), + pages = ["Home" => "index.md", "Reference" => "reference.md"], ) deploydocs(; - repo="github.com/ITensor/NestedPermutedDimsArrays.jl", devbranch="main", push_preview=true + repo = "github.com/ITensor/NestedPermutedDimsArrays.jl", devbranch = "main", push_preview = true ) diff --git a/docs/make_index.jl b/docs/make_index.jl index 887ed31..b1f7824 100644 --- a/docs/make_index.jl +++ b/docs/make_index.jl @@ -2,20 +2,20 @@ using Literate: Literate using NestedPermutedDimsArrays: NestedPermutedDimsArrays function ccq_logo(content) - include_ccq_logo = """ + include_ccq_logo = """ ```@raw html Flatiron Center for Computational Quantum Physics logo. Flatiron Center for Computational Quantum Physics logo. ``` """ - content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) - return content + content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) + return content end Literate.markdown( - joinpath(pkgdir(NestedPermutedDimsArrays), "examples", "README.jl"), - joinpath(pkgdir(NestedPermutedDimsArrays), "docs", "src"); - flavor=Literate.DocumenterFlavor(), - name="index", - postprocess=ccq_logo, + joinpath(pkgdir(NestedPermutedDimsArrays), "examples", "README.jl"), + joinpath(pkgdir(NestedPermutedDimsArrays), "docs", "src"); + flavor = Literate.DocumenterFlavor(), + name = "index", + postprocess = ccq_logo, ) diff --git a/docs/make_readme.jl b/docs/make_readme.jl index 6563b5c..17968fc 100644 --- a/docs/make_readme.jl +++ b/docs/make_readme.jl @@ -2,20 +2,20 @@ using Literate: Literate using NestedPermutedDimsArrays: NestedPermutedDimsArrays function ccq_logo(content) - include_ccq_logo = """ + include_ccq_logo = """ Flatiron Center for Computational Quantum Physics logo. """ - content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) - return content + content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) + return content end Literate.markdown( - joinpath(pkgdir(NestedPermutedDimsArrays), "examples", "README.jl"), - joinpath(pkgdir(NestedPermutedDimsArrays)); - flavor=Literate.CommonMarkFlavor(), - name="README", - postprocess=ccq_logo, + joinpath(pkgdir(NestedPermutedDimsArrays), "examples", "README.jl"), + joinpath(pkgdir(NestedPermutedDimsArrays)); + flavor = Literate.CommonMarkFlavor(), + name = "README", + postprocess = ccq_logo, ) diff --git a/examples/README.jl b/examples/README.jl index 471d2dc..848607d 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -1,5 +1,5 @@ # # NestedPermutedDimsArrays.jl -# +# # [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/NestedPermutedDimsArrays.jl/stable/) # [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/NestedPermutedDimsArrays.jl/dev/) # [![Build Status](https://github.com/ITensor/NestedPermutedDimsArrays.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/NestedPermutedDimsArrays.jl/actions/workflows/Tests.yml?query=branch%3Amain) diff --git a/src/NestedPermutedDimsArrays.jl b/src/NestedPermutedDimsArrays.jl index ea031dc..223ce53 100644 --- a/src/NestedPermutedDimsArrays.jl +++ b/src/NestedPermutedDimsArrays.jl @@ -46,75 +46,75 @@ import Base: permutedims, permutedims! export NestedPermutedDimsArray # Some day we will want storage-order-aware iteration, so put perm in the parameters -struct NestedPermutedDimsArray{T,N,perm,iperm,AA<:AbstractArray} <: AbstractArray{T,N} - parent::AA +struct NestedPermutedDimsArray{T, N, perm, iperm, AA <: AbstractArray} <: AbstractArray{T, N} + parent::AA - function NestedPermutedDimsArray{T,N,perm,iperm,AA}( - data::AA - ) where {T,N,perm,iperm,AA<:AbstractArray} - (isa(perm, NTuple{N,Int}) && isa(iperm, NTuple{N,Int})) || - error("perm and iperm must both be NTuple{$N,Int}") - isperm(perm) || - throw(ArgumentError(string(perm, " is not a valid permutation of dimensions 1:", N))) - all(d -> iperm[perm[d]] == d, 1:N) || - throw(ArgumentError(string(perm, " and ", iperm, " must be inverses"))) - return new(data) - end + function NestedPermutedDimsArray{T, N, perm, iperm, AA}( + data::AA + ) where {T, N, perm, iperm, AA <: AbstractArray} + (isa(perm, NTuple{N, Int}) && isa(iperm, NTuple{N, Int})) || + error("perm and iperm must both be NTuple{$N,Int}") + isperm(perm) || + throw(ArgumentError(string(perm, " is not a valid permutation of dimensions 1:", N))) + all(d -> iperm[perm[d]] == d, 1:N) || + throw(ArgumentError(string(perm, " and ", iperm, " must be inverses"))) + return new(data) + end end ## TODO: Fix this docstring. ## """ ## NestedPermutedDimsArray(A, perm) -> B -## +## ## Given an AbstractArray `A`, create a view `B` such that the ## dimensions appear to be permuted. Similar to `permutedims`, except ## that no copying occurs (`B` shares storage with `A`). -## +## ## See also [`permutedims`](@ref), [`invperm`](@ref). -## +## ## # Examples ## ```jldoctest ## julia> A = rand(3,5,4); -## +## ## julia> B = NestedPermutedDimsArray(A, (3,1,2)); -## +## ## julia> size(B) ## (4, 3, 5) -## +## ## julia> B[3,1,2] == A[1,2,3] ## true ## ``` ## """ Base.@constprop :aggressive function NestedPermutedDimsArray( - data::AbstractArray{T,N}, perm -) where {T,N} - length(perm) == N || - throw(ArgumentError(string(perm, " is not a valid permutation of dimensions 1:", N))) - iperm = invperm(perm) - return NestedPermutedDimsArray{ - PermutedDimsArray{eltype(T),N,(perm...,),(iperm...,),T}, - N, - (perm...,), - (iperm...,), - typeof(data), - }( - data - ) + data::AbstractArray{T, N}, perm + ) where {T, N} + length(perm) == N || + throw(ArgumentError(string(perm, " is not a valid permutation of dimensions 1:", N))) + iperm = invperm(perm) + return NestedPermutedDimsArray{ + PermutedDimsArray{eltype(T), N, (perm...,), (iperm...,), T}, + N, + (perm...,), + (iperm...,), + typeof(data), + }( + data + ) end Base.parent(A::NestedPermutedDimsArray) = A.parent -function Base.size(A::NestedPermutedDimsArray{T,N,perm}) where {T,N,perm} - return genperm(size(parent(A)), perm) +function Base.size(A::NestedPermutedDimsArray{T, N, perm}) where {T, N, perm} + return genperm(size(parent(A)), perm) end -function Base.axes(A::NestedPermutedDimsArray{T,N,perm}) where {T,N,perm} - return genperm(axes(parent(A)), perm) +function Base.axes(A::NestedPermutedDimsArray{T, N, perm}) where {T, N, perm} + return genperm(axes(parent(A)), perm) end Base.has_offset_axes(A::NestedPermutedDimsArray) = Base.has_offset_axes(A.parent) function Base.similar(A::NestedPermutedDimsArray, T::Type, dims::Base.Dims) - return similar(parent(A), T, dims) + return similar(parent(A), T, dims) end function Base.cconvert(::Type{Ptr{T}}, A::NestedPermutedDimsArray{T}) where {T} - return Base.cconvert(Ptr{T}, parent(A)) + return Base.cconvert(Ptr{T}, parent(A)) end # It's OK to return a pointer to the first element, and indeed quite @@ -123,155 +123,155 @@ end # storage order, a linear offset is ambiguous---is it a memory offset # or a linear index? function Base.pointer(A::NestedPermutedDimsArray, i::Integer) - throw( - ArgumentError("pointer(A, i) is deliberately unsupported for NestedPermutedDimsArray") - ) + throw( + ArgumentError("pointer(A, i) is deliberately unsupported for NestedPermutedDimsArray") + ) end -function Base.strides(A::NestedPermutedDimsArray{T,N,perm}) where {T,N,perm} - s = strides(parent(A)) - return ntuple(d -> s[perm[d]], Val(N)) +function Base.strides(A::NestedPermutedDimsArray{T, N, perm}) where {T, N, perm} + s = strides(parent(A)) + return ntuple(d -> s[perm[d]], Val(N)) end -function Base.elsize(::Type{<:NestedPermutedDimsArray{<:Any,<:Any,<:Any,<:Any,P}}) where {P} - return Base.elsize(P) +function Base.elsize(::Type{<:NestedPermutedDimsArray{<:Any, <:Any, <:Any, <:Any, P}}) where {P} + return Base.elsize(P) end @inline function Base.getindex( - A::NestedPermutedDimsArray{T,N,perm,iperm}, I::Vararg{Int,N} -) where {T,N,perm,iperm} - @boundscheck checkbounds(A, I...) - @inbounds val = PermutedDimsArray(getindex(A.parent, genperm(I, iperm)...), perm) - return val + A::NestedPermutedDimsArray{T, N, perm, iperm}, I::Vararg{Int, N} + ) where {T, N, perm, iperm} + @boundscheck checkbounds(A, I...) + @inbounds val = PermutedDimsArray(getindex(A.parent, genperm(I, iperm)...), perm) + return val end @inline function Base.setindex!( - A::NestedPermutedDimsArray{T,N,perm,iperm}, val, I::Vararg{Int,N} -) where {T,N,perm,iperm} - @boundscheck checkbounds(A, I...) - @inbounds setindex!(A.parent, PermutedDimsArray(val, iperm), genperm(I, iperm)...) - return val + A::NestedPermutedDimsArray{T, N, perm, iperm}, val, I::Vararg{Int, N} + ) where {T, N, perm, iperm} + @boundscheck checkbounds(A, I...) + @inbounds setindex!(A.parent, PermutedDimsArray(val, iperm), genperm(I, iperm)...) + return val end function Base.isassigned( - A::NestedPermutedDimsArray{T,N,perm,iperm}, I::Vararg{Int,N} -) where {T,N,perm,iperm} - @boundscheck checkbounds(Bool, A, I...) || return false - @inbounds x = isassigned(A.parent, genperm(I, iperm)...) - return x + A::NestedPermutedDimsArray{T, N, perm, iperm}, I::Vararg{Int, N} + ) where {T, N, perm, iperm} + @boundscheck checkbounds(Bool, A, I...) || return false + @inbounds x = isassigned(A.parent, genperm(I, iperm)...) + return x end -@inline genperm(I::NTuple{N,Any}, perm::Dims{N}) where {N} = ntuple(d -> I[perm[d]], Val(N)) +@inline genperm(I::NTuple{N, Any}, perm::Dims{N}) where {N} = ntuple(d -> I[perm[d]], Val(N)) @inline genperm(I, perm::AbstractVector{Int}) = genperm(I, (perm...,)) function Base.copyto!( - dest::NestedPermutedDimsArray{T,N}, src::AbstractArray{T,N} -) where {T,N} - checkbounds(dest, axes(src)...) - return _copy!(dest, src) + dest::NestedPermutedDimsArray{T, N}, src::AbstractArray{T, N} + ) where {T, N} + checkbounds(dest, axes(src)...) + return _copy!(dest, src) end Base.copyto!(dest::NestedPermutedDimsArray, src::AbstractArray) = _copy!(dest, src) -function _copy!(P::NestedPermutedDimsArray{T,N,perm}, src) where {T,N,perm} - # If dest/src are "close to dense," then it pays to be cache-friendly. - # Determine the first permuted dimension - d = 0 # d+1 will hold the first permuted dimension of src - while d < ndims(src) && perm[d + 1] == d + 1 - d += 1 - end - if d == ndims(src) - copyto!(parent(P), src) # it's not permuted - else - R1 = CartesianIndices(axes(src)[1:d]) - d1 = findfirst(isequal(d + 1), perm)::Int # first permuted dim of dest - R2 = CartesianIndices(axes(src)[(d + 2):(d1 - 1)]) - R3 = CartesianIndices(axes(src)[(d1 + 1):end]) - _permutedims!(P, src, R1, R2, R3, d + 1, d1) - end - return P +function _copy!(P::NestedPermutedDimsArray{T, N, perm}, src) where {T, N, perm} + # If dest/src are "close to dense," then it pays to be cache-friendly. + # Determine the first permuted dimension + d = 0 # d+1 will hold the first permuted dimension of src + while d < ndims(src) && perm[d + 1] == d + 1 + d += 1 + end + if d == ndims(src) + copyto!(parent(P), src) # it's not permuted + else + R1 = CartesianIndices(axes(src)[1:d]) + d1 = findfirst(isequal(d + 1), perm)::Int # first permuted dim of dest + R2 = CartesianIndices(axes(src)[(d + 2):(d1 - 1)]) + R3 = CartesianIndices(axes(src)[(d1 + 1):end]) + _permutedims!(P, src, R1, R2, R3, d + 1, d1) + end + return P end @noinline function _permutedims!( - P::NestedPermutedDimsArray, src, R1::CartesianIndices{0}, R2, R3, ds, dp -) - ip, is = axes(src, dp), axes(src, ds) - for jo in first(ip):8:last(ip), io in first(is):8:last(is) - for I3 in R3, I2 in R2 - for j in jo:min(jo + 7, last(ip)) - for i in io:min(io + 7, last(is)) - @inbounds P[i, I2, j, I3] = src[i, I2, j, I3] + P::NestedPermutedDimsArray, src, R1::CartesianIndices{0}, R2, R3, ds, dp + ) + ip, is = axes(src, dp), axes(src, ds) + for jo in first(ip):8:last(ip), io in first(is):8:last(is) + for I3 in R3, I2 in R2 + for j in jo:min(jo + 7, last(ip)) + for i in io:min(io + 7, last(is)) + @inbounds P[i, I2, j, I3] = src[i, I2, j, I3] + end + end end - end end - end - return P + return P end @noinline function _permutedims!(P::NestedPermutedDimsArray, src, R1, R2, R3, ds, dp) - ip, is = axes(src, dp), axes(src, ds) - for jo in first(ip):8:last(ip), io in first(is):8:last(is) - for I3 in R3, I2 in R2 - for j in jo:min(jo + 7, last(ip)) - for i in io:min(io + 7, last(is)) - for I1 in R1 - @inbounds P[I1, i, I2, j, I3] = src[I1, i, I2, j, I3] - end + ip, is = axes(src, dp), axes(src, ds) + for jo in first(ip):8:last(ip), io in first(is):8:last(is) + for I3 in R3, I2 in R2 + for j in jo:min(jo + 7, last(ip)) + for i in io:min(io + 7, last(is)) + for I1 in R1 + @inbounds P[I1, i, I2, j, I3] = src[I1, i, I2, j, I3] + end + end + end end - end end - end - return P + return P end const CommutativeOps = Union{ - typeof(+), - typeof(Base.add_sum), - typeof(min), - typeof(max), - typeof(Base._extrema_rf), - typeof(|), - typeof(&), + typeof(+), + typeof(Base.add_sum), + typeof(min), + typeof(max), + typeof(Base._extrema_rf), + typeof(|), + typeof(&), } function Base._mapreduce_dim( - f, op::CommutativeOps, init::Base._InitialValue, A::NestedPermutedDimsArray, dims::Colon -) - return Base._mapreduce_dim(f, op, init, parent(A), dims) + f, op::CommutativeOps, init::Base._InitialValue, A::NestedPermutedDimsArray, dims::Colon + ) + return Base._mapreduce_dim(f, op, init, parent(A), dims) end function Base._mapreduce_dim( - f::typeof(identity), - op::Union{typeof(Base.mul_prod),typeof(*)}, - init::Base._InitialValue, - A::NestedPermutedDimsArray{<:Union{Real,Complex}}, - dims::Colon, -) - return Base._mapreduce_dim(f, op, init, parent(A), dims) + f::typeof(identity), + op::Union{typeof(Base.mul_prod), typeof(*)}, + init::Base._InitialValue, + A::NestedPermutedDimsArray{<:Union{Real, Complex}}, + dims::Colon, + ) + return Base._mapreduce_dim(f, op, init, parent(A), dims) end function Base.mapreducedim!( - f, op::CommutativeOps, B::AbstractArray{T,N}, A::NestedPermutedDimsArray{S,N,perm,iperm} -) where {T,S,N,perm,iperm} - C = NestedPermutedDimsArray{T,N,iperm,perm,typeof(B)}(B) # make the inverse permutation for the output - Base.mapreducedim!(f, op, C, parent(A)) - return B + f, op::CommutativeOps, B::AbstractArray{T, N}, A::NestedPermutedDimsArray{S, N, perm, iperm} + ) where {T, S, N, perm, iperm} + C = NestedPermutedDimsArray{T, N, iperm, perm, typeof(B)}(B) # make the inverse permutation for the output + Base.mapreducedim!(f, op, C, parent(A)) + return B end function Base.mapreducedim!( - f::typeof(identity), - op::Union{typeof(Base.mul_prod),typeof(*)}, - B::AbstractArray{T,N}, - A::NestedPermutedDimsArray{<:Union{Real,Complex},N,perm,iperm}, -) where {T,N,perm,iperm} - C = NestedPermutedDimsArray{T,N,iperm,perm,typeof(B)}(B) # make the inverse permutation for the output - Base.mapreducedim!(f, op, C, parent(A)) - return B + f::typeof(identity), + op::Union{typeof(Base.mul_prod), typeof(*)}, + B::AbstractArray{T, N}, + A::NestedPermutedDimsArray{<:Union{Real, Complex}, N, perm, iperm}, + ) where {T, N, perm, iperm} + C = NestedPermutedDimsArray{T, N, iperm, perm, typeof(B)}(B) # make the inverse permutation for the output + Base.mapreducedim!(f, op, C, parent(A)) + return B end function Base.showarg( - io::IO, A::NestedPermutedDimsArray{T,N,perm}, toplevel -) where {T,N,perm} - print(io, "NestedPermutedDimsArray(") - Base.showarg(io, parent(A), false) - print(io, ", ", perm, ')') - toplevel && print(io, " with eltype ", eltype(A)) - return nothing + io::IO, A::NestedPermutedDimsArray{T, N, perm}, toplevel + ) where {T, N, perm} + print(io, "NestedPermutedDimsArray(") + Base.showarg(io, parent(A), false) + print(io, ", ", perm, ')') + toplevel && print(io, " with eltype ", eltype(A)) + return nothing end end diff --git a/test/runtests.jl b/test/runtests.jl index e2c9599..39c332d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,58 +6,60 @@ using Suppressor: Suppressor const pat = r"(?:--group=)(\w+)" arg_id = findfirst(contains(pat), ARGS) const GROUP = uppercase( - if isnothing(arg_id) - get(ENV, "GROUP", "ALL") - else - only(match(pat, ARGS[arg_id]).captures) - end, + if isnothing(arg_id) + get(ENV, "GROUP", "ALL") + else + only(match(pat, ARGS[arg_id]).captures) + end, ) "match files of the form `test_*.jl`, but exclude `*setup*.jl`" function istestfile(fn) - return 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) - return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") + return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") end @time begin - # tests in groups based on folder structure - for testgroup in filter(isdir, readdir(@__DIR__)) - if GROUP == "ALL" || GROUP == uppercase(testgroup) - for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) - @eval @safetestset $file begin - include($file) + # tests in groups based on folder structure + for testgroup in filter(isdir, readdir(@__DIR__)) + if GROUP == "ALL" || GROUP == uppercase(testgroup) + for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join = true)) + @eval @safetestset $file begin + include($file) + end + end end - end end - end - # single files in top folder - for file in filter(istestfile, readdir(@__DIR__)) - (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion - @eval @safetestset $file begin - include($file) + # single files in top folder + for file in filter(istestfile, readdir(@__DIR__)) + (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion + @eval @safetestset $file begin + include($file) + end end - end - # test examples - examplepath = joinpath(@__DIR__, "..", "examples") - for (root, _, files) in walkdir(examplepath) - contains(chopprefix(root, @__DIR__), "setup") && continue - for file in filter(isexamplefile, files) - filename = joinpath(root, file) - @eval begin - @safetestset $file begin - $(Expr( - :macrocall, - GlobalRef(Suppressor, Symbol("@suppress")), - LineNumberNode(@__LINE__, @__FILE__), - :(include($filename)), - )) + # test examples + examplepath = joinpath(@__DIR__, "..", "examples") + for (root, _, files) in walkdir(examplepath) + contains(chopprefix(root, @__DIR__), "setup") && continue + for file in filter(isexamplefile, files) + filename = joinpath(root, file) + @eval begin + @safetestset $file begin + $( + Expr( + :macrocall, + GlobalRef(Suppressor, Symbol("@suppress")), + LineNumberNode(@__LINE__, @__FILE__), + :(include($filename)), + ) + ) + end + end end - end end - end end diff --git a/test/test_aqua.jl b/test/test_aqua.jl index 96d6507..31c0741 100644 --- a/test/test_aqua.jl +++ b/test/test_aqua.jl @@ -3,5 +3,5 @@ using Aqua: Aqua using Test: @testset @testset "Code quality (Aqua.jl)" begin - Aqua.test_all(NestedPermutedDimsArrays) + Aqua.test_all(NestedPermutedDimsArrays) end diff --git a/test/test_basics.jl b/test/test_basics.jl index c3254f7..959d354 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -2,21 +2,21 @@ using NestedPermutedDimsArrays: NestedPermutedDimsArray using Test: @test, @testset @testset "NestedPermutedDimsArrays" for elt in ( - Float32, Float64, Complex{Float32}, Complex{Float64} -) - a = map(_ -> randn(elt, 2, 3, 4), CartesianIndices((2, 3, 4))) - perm = (3, 1, 2) - p = NestedPermutedDimsArray(a, perm) - T = PermutedDimsArray{elt,3,perm,invperm(perm),eltype(a)} - @test typeof(p) === NestedPermutedDimsArray{T,3,perm,invperm(perm),typeof(a)} - @test size(p) == (4, 2, 3) - @test eltype(p) === T - for I in eachindex(p) - @test size(p[I]) == (4, 2, 3) - @test p[I] == permutedims(a[CartesianIndex(map(i -> Tuple(I)[i], invperm(perm)))], perm) - end - x = randn(elt, 4, 2, 3) - p[3, 1, 2] = x - @test p[3, 1, 2] == x - @test a[1, 2, 3] == permutedims(x, invperm(perm)) + Float32, Float64, Complex{Float32}, Complex{Float64}, + ) + a = map(_ -> randn(elt, 2, 3, 4), CartesianIndices((2, 3, 4))) + perm = (3, 1, 2) + p = NestedPermutedDimsArray(a, perm) + T = PermutedDimsArray{elt, 3, perm, invperm(perm), eltype(a)} + @test typeof(p) === NestedPermutedDimsArray{T, 3, perm, invperm(perm), typeof(a)} + @test size(p) == (4, 2, 3) + @test eltype(p) === T + for I in eachindex(p) + @test size(p[I]) == (4, 2, 3) + @test p[I] == permutedims(a[CartesianIndex(map(i -> Tuple(I)[i], invperm(perm)))], perm) + end + x = randn(elt, 4, 2, 3) + p[3, 1, 2] = x + @test p[3, 1, 2] == x + @test a[1, 2, 3] == permutedims(x, invperm(perm)) end