From 40142329a243cce1042c7c022aca5ddb1bb9a1ac Mon Sep 17 00:00:00 2001 From: mtfishman <7855256+mtfishman@users.noreply.github.com> Date: Thu, 9 Oct 2025 01:16:38 +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 +- .../SerializedArraysAdaptExt.jl | 2 +- .../SerializedArraysLinearAlgebraExt.jl | 58 +-- src/SerializedArrays.jl | 356 +++++++++--------- test/runtests.jl | 80 ++-- test/test_adaptext.jl | 20 +- test/test_aqua.jl | 2 +- test/test_basics.jl | 284 +++++++------- test/test_linearalgebraext.jl | 68 ++-- 13 files changed, 465 insertions(+), 463 deletions(-) diff --git a/Project.toml b/Project.toml index c9b47fd..0e563ba 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SerializedArrays" uuid = "621c0da3-e96e-4f80-bd06-5ae31cdfcb39" +version = "0.2.2" authors = ["ITensor developers and contributors"] -version = "0.2.1" [deps] ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" diff --git a/docs/make.jl b/docs/make.jl index ebc9157..7f45741 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -2,23 +2,23 @@ using SerializedArrays: SerializedArrays using Documenter: Documenter, DocMeta, deploydocs, makedocs DocMeta.setdocmeta!( - SerializedArrays, :DocTestSetup, :(using SerializedArrays); recursive=true + SerializedArrays, :DocTestSetup, :(using SerializedArrays); recursive = true ) include("make_index.jl") makedocs(; - modules=[SerializedArrays], - authors="ITensor developers and contributors", - sitename="SerializedArrays.jl", - format=Documenter.HTML(; - canonical="https://itensor.github.io/SerializedArrays.jl", - edit_link="main", - assets=["assets/favicon.ico", "assets/extras.css"], - ), - pages=["Home" => "index.md", "Reference" => "reference.md"], + modules = [SerializedArrays], + authors = "ITensor developers and contributors", + sitename = "SerializedArrays.jl", + format = Documenter.HTML(; + canonical = "https://itensor.github.io/SerializedArrays.jl", + edit_link = "main", + assets = ["assets/favicon.ico", "assets/extras.css"], + ), + pages = ["Home" => "index.md", "Reference" => "reference.md"], ) deploydocs(; - repo="github.com/ITensor/SerializedArrays.jl", devbranch="main", push_preview=true + repo = "github.com/ITensor/SerializedArrays.jl", devbranch = "main", push_preview = true ) diff --git a/docs/make_index.jl b/docs/make_index.jl index 6abdc08..5ea45f0 100644 --- a/docs/make_index.jl +++ b/docs/make_index.jl @@ -2,20 +2,20 @@ using Literate: Literate using SerializedArrays: SerializedArrays 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(SerializedArrays), "examples", "README.jl"), - joinpath(pkgdir(SerializedArrays), "docs", "src"); - flavor=Literate.DocumenterFlavor(), - name="index", - postprocess=ccq_logo, + joinpath(pkgdir(SerializedArrays), "examples", "README.jl"), + joinpath(pkgdir(SerializedArrays), "docs", "src"); + flavor = Literate.DocumenterFlavor(), + name = "index", + postprocess = ccq_logo, ) diff --git a/docs/make_readme.jl b/docs/make_readme.jl index e835175..07e4110 100644 --- a/docs/make_readme.jl +++ b/docs/make_readme.jl @@ -2,20 +2,20 @@ using Literate: Literate using SerializedArrays: SerializedArrays 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(SerializedArrays), "examples", "README.jl"), - joinpath(pkgdir(SerializedArrays)); - flavor=Literate.CommonMarkFlavor(), - name="README", - postprocess=ccq_logo, + joinpath(pkgdir(SerializedArrays), "examples", "README.jl"), + joinpath(pkgdir(SerializedArrays)); + flavor = Literate.CommonMarkFlavor(), + name = "README", + postprocess = ccq_logo, ) diff --git a/examples/README.jl b/examples/README.jl index 4e5cf6a..9653f16 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -1,5 +1,5 @@ # # SerializedArrays.jl -# +# # [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/SerializedArrays.jl/stable/) # [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/SerializedArrays.jl/dev/) # [![Build Status](https://github.com/ITensor/SerializedArrays.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/SerializedArrays.jl/actions/workflows/Tests.yml?query=branch%3Amain) diff --git a/ext/SerializedArraysAdaptExt/SerializedArraysAdaptExt.jl b/ext/SerializedArraysAdaptExt/SerializedArraysAdaptExt.jl index 8dbc07b..8e853a3 100644 --- a/ext/SerializedArraysAdaptExt/SerializedArraysAdaptExt.jl +++ b/ext/SerializedArraysAdaptExt/SerializedArraysAdaptExt.jl @@ -4,7 +4,7 @@ using Adapt: Adapt using SerializedArrays: SerializedArray function Adapt.adapt_storage(arrayt::Type{<:SerializedArray}, a::AbstractArray) - return convert(arrayt, a) + return convert(arrayt, a) end end diff --git a/ext/SerializedArraysLinearAlgebraExt/SerializedArraysLinearAlgebraExt.jl b/ext/SerializedArraysLinearAlgebraExt/SerializedArraysLinearAlgebraExt.jl index 7eb44fd..af3e19d 100644 --- a/ext/SerializedArraysLinearAlgebraExt/SerializedArraysLinearAlgebraExt.jl +++ b/ext/SerializedArraysLinearAlgebraExt/SerializedArraysLinearAlgebraExt.jl @@ -4,48 +4,48 @@ using LinearAlgebra: LinearAlgebra, mul! using SerializedArrays: AbstractSerializedMatrix, memory function mul_serialized!( - a_dest::AbstractMatrix, a1::AbstractMatrix, a2::AbstractMatrix, α::Number, β::Number -) - mul!(a_dest, memory(a1), memory(a2), α, β) - return a_dest + a_dest::AbstractMatrix, a1::AbstractMatrix, a2::AbstractMatrix, α::Number, β::Number + ) + mul!(a_dest, memory(a1), memory(a2), α, β) + return a_dest end function LinearAlgebra.mul!( - a_dest::AbstractMatrix, - a1::AbstractSerializedMatrix, - a2::AbstractSerializedMatrix, - α::Number, - β::Number, -) - return mul_serialized!(a_dest, a1, a2, α, β) + a_dest::AbstractMatrix, + a1::AbstractSerializedMatrix, + a2::AbstractSerializedMatrix, + α::Number, + β::Number, + ) + return mul_serialized!(a_dest, a1, a2, α, β) end function LinearAlgebra.mul!( - a_dest::AbstractMatrix, - a1::AbstractMatrix, - a2::AbstractSerializedMatrix, - α::Number, - β::Number, -) - return mul_serialized!(a_dest, a1, a2, α, β) + a_dest::AbstractMatrix, + a1::AbstractMatrix, + a2::AbstractSerializedMatrix, + α::Number, + β::Number, + ) + return mul_serialized!(a_dest, a1, a2, α, β) end function LinearAlgebra.mul!( - a_dest::AbstractMatrix, - a1::AbstractSerializedMatrix, - a2::AbstractMatrix, - α::Number, - β::Number, -) - return mul_serialized!(a_dest, a1, a2, α, β) + a_dest::AbstractMatrix, + a1::AbstractSerializedMatrix, + a2::AbstractMatrix, + α::Number, + β::Number, + ) + return mul_serialized!(a_dest, a1, a2, α, β) end for f in [:eigen, :qr, :svd] - @eval begin - function LinearAlgebra.$f(a::AbstractSerializedMatrix; kwargs...) - return LinearAlgebra.$f(copy(a)) + @eval begin + function LinearAlgebra.$f(a::AbstractSerializedMatrix; kwargs...) + return LinearAlgebra.$f(copy(a)) + end end - end end end diff --git a/src/SerializedArrays.jl b/src/SerializedArrays.jl index 342504d..1f8b351 100644 --- a/src/SerializedArrays.jl +++ b/src/SerializedArrays.jl @@ -5,7 +5,7 @@ export SerializedArray, disk, memory using Base.PermutedDimsArrays: genperm using ConstructionBase: constructorof using DiskArrays: - DiskArrays, AbstractDiskArray, PermutedDiskArray, Unchunked, readblock!, writeblock! + DiskArrays, AbstractDiskArray, PermutedDiskArray, Unchunked, readblock!, writeblock! using Serialization: deserialize, serialize adapt_serialized(to, x) = adapt_structure_serialized(to, x) @@ -23,104 +23,104 @@ memory(x) = adapt_serialized(MemoryAdaptor(), x) # AbstractSerializedArray # -abstract type AbstractSerializedArray{T,N} <: AbstractDiskArray{T,N} end -const AbstractSerializedMatrix{T} = AbstractSerializedArray{T,2} -const AbstractSerializedVector{T} = AbstractSerializedArray{T,1} +abstract type AbstractSerializedArray{T, N} <: AbstractDiskArray{T, N} end +const AbstractSerializedMatrix{T} = AbstractSerializedArray{T, 2} +const AbstractSerializedVector{T} = AbstractSerializedArray{T, 1} disk(a::AbstractSerializedArray) = a function Base.copy(a::AbstractSerializedArray) - return copy(memory(a)) + return copy(memory(a)) end function _copyto_write!(dst, src) - writeblock!(dst, src, axes(src)...) - return dst + writeblock!(dst, src, axes(src)...) + return dst end function _copyto_read!(dst, src) - readblock!(src, dst, axes(src)...) - return dst + readblock!(src, dst, axes(src)...) + return dst end function Base.copyto!(dst::AbstractSerializedArray, src::AbstractArray) - return _copyto_write!(dst, src) + return _copyto_write!(dst, src) end function Base.copyto!(dst::AbstractArray, src::AbstractSerializedArray) - return _copyto_read!(dst, src) + return _copyto_read!(dst, src) end # Fix ambiguity error. function Base.copyto!(dst::AbstractSerializedArray, src::AbstractSerializedArray) - return copyto!(dst, memory(src)) + return copyto!(dst, memory(src)) end # Fix ambiguity error. function Base.copyto!(dst::AbstractDiskArray, src::AbstractSerializedArray) - return copyto!(dst, memory(src)) + return copyto!(dst, memory(src)) end # Fix ambiguity error. function Base.copyto!(dst::AbstractSerializedArray, src::AbstractDiskArray) - return _copyto_write!(dst, src) + return _copyto_write!(dst, src) end # Fix ambiguity error. function Base.copyto!(dst::PermutedDimsArray, src::AbstractSerializedArray) - return _copyto_read!(dst, src) + return _copyto_read!(dst, src) end equals_serialized(a1, a2) = memory(a1) == memory(a2) function Base.:(==)(a1::AbstractSerializedArray, a2::AbstractSerializedArray) - return equals_serialized(a1, a2) + return equals_serialized(a1, a2) end function Base.:(==)(a1::AbstractArray, a2::AbstractSerializedArray) - return equals_serialized(a1, a2) + return equals_serialized(a1, a2) end function Base.:(==)(a1::AbstractSerializedArray, a2::AbstractArray) - return equals_serialized(a1, a2) + return equals_serialized(a1, a2) end # # SerializedArray # -struct SerializedArray{T,N,A<:AbstractArray{T,N},Axes} <: AbstractSerializedArray{T,N} - file::String - axes::Axes +struct SerializedArray{T, N, A <: AbstractArray{T, N}, Axes} <: AbstractSerializedArray{T, N} + file::String + axes::Axes end file(a::SerializedArray) = getfield(a, :file) Base.axes(a::SerializedArray) = getfield(a, :axes) -arraytype(a::SerializedArray{<:Any,<:Any,A}) where {A} = A +arraytype(a::SerializedArray{<:Any, <:Any, A}) where {A} = A disk(a::AbstractArray) = SerializedArray(a) function SerializedArray(file::String, a::AbstractArray) - serialize(file, a) - ax = axes(a) - return SerializedArray{eltype(a),ndims(a),typeof(a),typeof(ax)}(file, ax) + serialize(file, a) + ax = axes(a) + return SerializedArray{eltype(a), ndims(a), typeof(a), typeof(ax)}(file, ax) end function SerializedArray(a::AbstractArray) - return SerializedArray(tempname(), a) + return SerializedArray(tempname(), a) end function Base.convert(arrayt::Type{<:SerializedArray}, a::AbstractArray) - return arrayt(a) + return arrayt(a) end function Base.similar(a::SerializedArray, elt::Type, dims::Tuple{Vararg{Int}}) - return constructorof(arraytype(a)){elt}(undef, dims...) + return constructorof(arraytype(a)){elt}(undef, dims...) end function _memory(a::SerializedArray) - return deserialize(file(a))::arraytype(a) + return deserialize(file(a))::arraytype(a) end function adapt_storage_serialized(::DeepMemoryAdaptor, a::SerializedArray) - return _memory(a) + return _memory(a) end function adapt_storage_serialized(::MemoryAdaptor, a::SerializedArray) - return _memory(a) + return _memory(a) end function Base.copy(a::SerializedArray) - return memory(a) + return memory(a) end Base.size(a::SerializedArray) = length.(axes(a)) @@ -131,103 +131,103 @@ to_axis(d::Integer) = Base.OneTo(d) # DiskArrays interface DiskArrays.haschunks(::SerializedArray) = Unchunked() function DiskArrays.readblock!( - a::SerializedArray{<:Any,N}, aout, i::Vararg{AbstractUnitRange,N} -) where {N} - if i == axes(a) - aout .= deepmemory(a) + a::SerializedArray{<:Any, N}, aout, i::Vararg{AbstractUnitRange, N} + ) where {N} + if i == axes(a) + aout .= deepmemory(a) + return a + end + aout .= @view memory(a)[i...] return a - end - aout .= @view memory(a)[i...] - return a end function DiskArrays.writeblock!( - a::SerializedArray{<:Any,N}, ain, i::Vararg{AbstractUnitRange,N} -) where {N} - if i == axes(a) - serialize(file(a), ain) + a::SerializedArray{<:Any, N}, ain, i::Vararg{AbstractUnitRange, N} + ) where {N} + if i == axes(a) + serialize(file(a), ain) + return a + end + a′ = memory(a) + a′[i...] = ain + serialize(file(a), a′) return a - end - a′ = memory(a) - a′[i...] = ain - serialize(file(a), a′) - return a end function DiskArrays.create_outputarray(::Nothing, a::SerializedArray, output_size::Tuple) - return similar(a, output_size) + return similar(a, output_size) end # # PermutedSerializedArray # -struct PermutedSerializedArray{T,N,perm,iperm,P<:AbstractArray{T,N}} <: - AbstractSerializedArray{T,N} - parent::P +struct PermutedSerializedArray{T, N, perm, iperm, P <: AbstractArray{T, N}} <: + AbstractSerializedArray{T, N} + parent::P end Base.parent(a::PermutedSerializedArray) = getfield(a, :parent) file(a::PermutedSerializedArray) = file(parent(a)) # TODO: Use `TypeParameterAccessors.jl`. -perm(a::PermutedDimsArray{<:Any,<:Any,p}) where {p} = p -perm(a::PermutedDiskArray{<:Any,<:Any,p}) where {p} = p -perm(a::PermutedSerializedArray{<:Any,<:Any,p}) where {p} = p +perm(a::PermutedDimsArray{<:Any, <:Any, p}) where {p} = p +perm(a::PermutedDiskArray{<:Any, <:Any, p}) where {p} = p +perm(a::PermutedSerializedArray{<:Any, <:Any, p}) where {p} = p # TODO: Use `TypeParameterAccessors.jl`. -iperm(a::PermutedDimsArray{<:Any,<:Any,<:Any,ip}) where {ip} = ip -iperm(a::PermutedDiskArray{<:Any,<:Any,ip}) where {ip} = ip -iperm(a::PermutedSerializedArray{<:Any,<:Any,<:Any,ip}) where {ip} = ip +iperm(a::PermutedDimsArray{<:Any, <:Any, <:Any, ip}) where {ip} = ip +iperm(a::PermutedDiskArray{<:Any, <:Any, ip}) where {ip} = ip +iperm(a::PermutedSerializedArray{<:Any, <:Any, <:Any, ip}) where {ip} = ip Base.axes(a::PermutedSerializedArray) = genperm(axes(parent(a)), perm(a)) Base.size(a::PermutedSerializedArray) = map(length, axes(a)) function PermutedSerializedArray(a::AbstractArray, p) - # This returns a `PermutedDiskArray` as of: - # https://github.com/JuliaIO/DiskArrays.jl/pull/249 - a′ = PermutedDimsArray(a, p) - return PermutedSerializedArray{eltype(a),ndims(a),perm(a′),iperm(a′),typeof(a)}(a) + # This returns a `PermutedDiskArray` as of: + # https://github.com/JuliaIO/DiskArrays.jl/pull/249 + a′ = PermutedDimsArray(a, p) + return PermutedSerializedArray{eltype(a), ndims(a), perm(a′), iperm(a′), typeof(a)}(a) end function Base.permutedims(a::AbstractSerializedArray, perm) - return PermutedSerializedArray(a, perm) + return PermutedSerializedArray(a, perm) end function Base.similar(a::PermutedSerializedArray, elt::Type, dims::Tuple{Vararg{Int}}) - return similar(parent(a), elt, dims) + return similar(parent(a), elt, dims) end function adapt_structure_serialized(to, a::PermutedSerializedArray) - return PermutedDimsArray(adapt_serialized(to, parent(a)), perm(a)) + return PermutedDimsArray(adapt_serialized(to, parent(a)), perm(a)) end # Special case to eagerly instantiate permutations. function adapt_structure_serialized(to::MemoryAdaptor, a::PermutedSerializedArray) - return copy(deepmemory(a)) + return copy(deepmemory(a)) end haschunks(a::PermutedSerializedArray) = Unchunked() function DiskArrays.readblock!(a::PermutedSerializedArray, aout, i::OrdinalRange...) - ip = iperm(a) - # Permute the indices - inew = genperm(i, ip) - # Permute the dest block and read from the true parent - readblock!(parent(a), PermutedDimsArray(aout, ip), inew...) - return nothing + ip = iperm(a) + # Permute the indices + inew = genperm(i, ip) + # Permute the dest block and read from the true parent + readblock!(parent(a), PermutedDimsArray(aout, ip), inew...) + return nothing end function DiskArrays.writeblock!(a::PermutedSerializedArray, v, i::OrdinalRange...) - ip = iperm(a) - inew = genperm(i, ip) - # Permute the dest block and write from the true parent - writeblock!(parent(a), PermutedDimsArray(v, ip), inew...) - return nothing + ip = iperm(a) + inew = genperm(i, ip) + # Permute the dest block and write from the true parent + writeblock!(parent(a), PermutedDimsArray(v, ip), inew...) + return nothing end # # ReshapedSerializedArray # -struct ReshapedSerializedArray{T,N,P<:AbstractArray{T},Axes} <: AbstractSerializedArray{T,N} - parent::P - axes::Axes +struct ReshapedSerializedArray{T, N, P <: AbstractArray{T}, Axes} <: AbstractSerializedArray{T, N} + parent::P + axes::Axes end Base.parent(a::ReshapedSerializedArray) = getfield(a, :parent) Base.axes(a::ReshapedSerializedArray) = getfield(a, :axes) @@ -235,82 +235,82 @@ Base.axes(a::ReshapedSerializedArray) = getfield(a, :axes) file(a::ReshapedSerializedArray) = file(parent(a)) function ReshapedSerializedArray( - a::AbstractSerializedArray, - ax::Tuple{AbstractUnitRange{<:Integer},Vararg{AbstractUnitRange{<:Integer}}}, -) - return ReshapedSerializedArray{eltype(a),length(ax),typeof(a),typeof(ax)}(a, ax) + a::AbstractSerializedArray, + ax::Tuple{AbstractUnitRange{<:Integer}, Vararg{AbstractUnitRange{<:Integer}}}, + ) + return ReshapedSerializedArray{eltype(a), length(ax), typeof(a), typeof(ax)}(a, ax) end function ReshapedSerializedArray( - a::AbstractSerializedArray, - shape::Tuple{ - Union{Integer,AbstractUnitRange{<:Integer}}, - Vararg{Union{Integer,AbstractUnitRange{<:Integer}}}, - }, -) - return ReshapedSerializedArray(a, to_axis.(shape)) + a::AbstractSerializedArray, + shape::Tuple{ + Union{Integer, AbstractUnitRange{<:Integer}}, + Vararg{Union{Integer, AbstractUnitRange{<:Integer}}}, + }, + ) + return ReshapedSerializedArray(a, to_axis.(shape)) end Base.size(a::ReshapedSerializedArray) = length.(axes(a)) function Base.similar(a::ReshapedSerializedArray, elt::Type, dims::Tuple{Vararg{Int}}) - return similar(parent(a), elt, dims) + return similar(parent(a), elt, dims) end function adapt_structure_serialized(to, a::ReshapedSerializedArray) - return reshape(adapt_serialized(to, parent(a)), axes(a)) + return reshape(adapt_serialized(to, parent(a)), axes(a)) end function Base.copy(a::ReshapedSerializedArray) - # `memory` instantiates `PermutedSerializedArray`, which is - # friendlier for GPU. Consider special cases of strded arrays - # and handle with stride manipulations. - a′ = memory(a) - return a′ isa Base.ReshapedArray ? copy(a′) : a′ + # `memory` instantiates `PermutedSerializedArray`, which is + # friendlier for GPU. Consider special cases of strded arrays + # and handle with stride manipulations. + a′ = memory(a) + return a′ isa Base.ReshapedArray ? copy(a′) : a′ end -function Base.reshape(a::AbstractSerializedArray, dims::Tuple{Int,Vararg{Int}}) - return ReshapedSerializedArray(a, dims) +function Base.reshape(a::AbstractSerializedArray, dims::Tuple{Int, Vararg{Int}}) + return ReshapedSerializedArray(a, dims) end DiskArrays.haschunks(a::ReshapedSerializedArray) = Unchunked() function DiskArrays.readblock!( - a::ReshapedSerializedArray{<:Any,N}, aout, i::Vararg{AbstractUnitRange,N} -) where {N} - if i == axes(a) - aout .= memory(a) - return a - end - aout .= @view memory(a)[i...] - return nothing + a::ReshapedSerializedArray{<:Any, N}, aout, i::Vararg{AbstractUnitRange, N} + ) where {N} + if i == axes(a) + aout .= memory(a) + return a + end + aout .= @view memory(a)[i...] + return nothing end function DiskArrays.writeblock!( - a::ReshapedSerializedArray{<:Any,N}, ain, i::Vararg{AbstractUnitRange,N} -) where {N} - if i == axes(a) - serialize(file(a), ain) - return a - end - a′ = memory(a) - a′[i...] = ain - serialize(file(a), a′) - return nothing + a::ReshapedSerializedArray{<:Any, N}, ain, i::Vararg{AbstractUnitRange, N} + ) where {N} + if i == axes(a) + serialize(file(a), ain) + return a + end + a′ = memory(a) + a′[i...] = ain + serialize(file(a), a′) + return nothing end # # SubSerializedArray # -struct SubSerializedArray{T,N,P,I,L} <: AbstractSerializedArray{T,N} - sub_parent::SubArray{T,N,P,I,L} +struct SubSerializedArray{T, N, P, I, L} <: AbstractSerializedArray{T, N} + sub_parent::SubArray{T, N, P, I, L} end file(a::SubSerializedArray) = file(parent(a)) # Base methods function Base.view(a::SerializedArray, i...) - return SubSerializedArray(SubArray(a, Base.to_indices(a, i))) + return SubSerializedArray(SubArray(a, Base.to_indices(a, i))) end function Base.view(a::SerializedArray, i::CartesianIndices) - return SubSerializedArray(SubArray(a, Base.to_indices(a, i))) + return SubSerializedArray(SubArray(a, Base.to_indices(a, i))) end Base.view(a::SubSerializedArray, i...) = SubSerializedArray(view(a.sub_parent, i...)) Base.view(a::SubSerializedArray, i::CartesianIndices) = view(a, i.indices...) @@ -320,36 +320,36 @@ Base.parent(a::SubSerializedArray) = parent(a.sub_parent) Base.parentindices(a::SubSerializedArray) = parentindices(a.sub_parent) function adapt_structure_serialized(to, a::SubSerializedArray) - return view(adapt_serialized(to, parent(a)), parentindices(a)...) + return view(adapt_serialized(to, parent(a)), parentindices(a)...) end DiskArrays.haschunks(a::SubSerializedArray) = Unchunked() function DiskArrays.readblock!(a::SubSerializedArray, aout, i::OrdinalRange...) - if i == axes(a) - aout .= deepmemory(a) - end - aout[i...] = memory(view(a, i...)) - return nothing + if i == axes(a) + aout .= deepmemory(a) + end + aout[i...] = memory(view(a, i...)) + return nothing end function DiskArrays.writeblock!(a::SubSerializedArray, ain, i::OrdinalRange...) - if i == axes(a) - serialize(file(a), ain) - return a - end - a_parent = deepmemory(parent(a)) - pinds = parentindices(view(a.sub_parent, i...)) - a_parent[pinds...] = ain - serialize(file(a), a_parent) - return nothing + if i == axes(a) + serialize(file(a), ain) + return a + end + a_parent = deepmemory(parent(a)) + pinds = parentindices(view(a.sub_parent, i...)) + a_parent[pinds...] = ain + serialize(file(a), a_parent) + return nothing end # # TransposeSerializedArray # -struct TransposeSerializedArray{T,P<:AbstractSerializedArray{T}} <: - AbstractSerializedMatrix{T} - parent::P +struct TransposeSerializedArray{T, P <: AbstractSerializedArray{T}} <: + AbstractSerializedMatrix{T} + parent::P end Base.parent(a::TransposeSerializedArray) = getfield(a, :parent) @@ -359,35 +359,35 @@ Base.axes(a::TransposeSerializedArray) = reverse(axes(parent(a))) Base.size(a::TransposeSerializedArray) = length.(axes(a)) function Base.transpose(a::AbstractSerializedArray) - return TransposeSerializedArray(a) + return TransposeSerializedArray(a) end Base.transpose(a::TransposeSerializedArray) = parent(a) function Base.similar(a::TransposeSerializedArray, elt::Type, dims::Tuple{Vararg{Int}}) - return similar(parent(a), elt, dims) + return similar(parent(a), elt, dims) end function adapt_structure_serialized(to, a::TransposeSerializedArray) - return transpose(adapt_serialized(to, parent(a))) + return transpose(adapt_serialized(to, parent(a))) end haschunks(a::TransposeSerializedArray) = Unchunked() function DiskArrays.readblock!(a::TransposeSerializedArray, aout, i::OrdinalRange...) - readblock!(parent(a), transpose(aout), reverse(i)...) - return nothing + readblock!(parent(a), transpose(aout), reverse(i)...) + return nothing end function DiskArrays.writeblock!(a::TransposeSerializedArray, ain, i::OrdinalRange...) - writeblock!(parent(a), transpose(aout), reverse(i)...) - return nothing + writeblock!(parent(a), transpose(aout), reverse(i)...) + return nothing end # # AdjointSerializedArray # -struct AdjointSerializedArray{T,P<:AbstractSerializedArray{T}} <: - AbstractSerializedMatrix{T} - parent::P +struct AdjointSerializedArray{T, P <: AbstractSerializedArray{T}} <: + AbstractSerializedMatrix{T} + parent::P end Base.parent(a::AdjointSerializedArray) = getfield(a, :parent) @@ -397,28 +397,28 @@ Base.axes(a::AdjointSerializedArray) = reverse(axes(parent(a))) Base.size(a::AdjointSerializedArray) = length.(axes(a)) function Base.adjoint(a::AbstractSerializedArray) - return AdjointSerializedArray(a) + return AdjointSerializedArray(a) end Base.adjoint(a::AdjointSerializedArray) = parent(a) Base.adjoint(a::TransposeSerializedArray{<:Real}) = parent(a) Base.transpose(a::AdjointSerializedArray{<:Real}) = parent(a) function Base.similar(a::AdjointSerializedArray, elt::Type, dims::Tuple{Vararg{Int}}) - return similar(parent(a), elt, dims) + return similar(parent(a), elt, dims) end function adapt_structure_serialized(to, a::AdjointSerializedArray) - return adjoint(adapt_serialized(to, parent(a))) + return adjoint(adapt_serialized(to, parent(a))) end haschunks(a::AdjointSerializedArray) = Unchunked() function DiskArrays.readblock!(a::AdjointSerializedArray, aout, i::OrdinalRange...) - readblock!(parent(a), adjoint(aout), reverse(i)...) - return nothing + readblock!(parent(a), adjoint(aout), reverse(i)...) + return nothing end function DiskArrays.writeblock!(a::AdjointSerializedArray, ain, i::OrdinalRange...) - writeblock!(parent(a), adjoint(aout), reverse(i)...) - return nothing + writeblock!(parent(a), adjoint(aout), reverse(i)...) + return nothing end # @@ -426,50 +426,50 @@ end # using Base.Broadcast: - BroadcastStyle, Broadcasted, DefaultArrayStyle, combine_styles, flatten + BroadcastStyle, Broadcasted, DefaultArrayStyle, combine_styles, flatten struct SerializedArrayStyle{N} <: Base.Broadcast.AbstractArrayStyle{N} end function Base.BroadcastStyle(arrayt::Type{<:AbstractSerializedArray}) - SerializedArrayStyle{ndims(arrayt)}() + return SerializedArrayStyle{ndims(arrayt)}() end function Base.BroadcastStyle( - ::SerializedArrayStyle{N}, ::SerializedArrayStyle{M} -) where {N,M} - SerializedArrayStyle{max(N, M)}() + ::SerializedArrayStyle{N}, ::SerializedArrayStyle{M} + ) where {N, M} + return SerializedArrayStyle{max(N, M)}() end -function Base.BroadcastStyle(::SerializedArrayStyle{N}, ::DefaultArrayStyle{M}) where {N,M} - return SerializedArrayStyle{max(N, M)}() +function Base.BroadcastStyle(::SerializedArrayStyle{N}, ::DefaultArrayStyle{M}) where {N, M} + return SerializedArrayStyle{max(N, M)}() end -function Base.BroadcastStyle(::DefaultArrayStyle{M}, ::SerializedArrayStyle{N}) where {N,M} - return SerializedArrayStyle{max(N, M)}() +function Base.BroadcastStyle(::DefaultArrayStyle{M}, ::SerializedArrayStyle{N}) where {N, M} + return SerializedArrayStyle{max(N, M)}() end -struct BroadcastSerializedArray{T,N,BC<:Broadcasted{<:SerializedArrayStyle{N}}} <: - AbstractSerializedArray{T,N} - broadcasted::BC +struct BroadcastSerializedArray{T, N, BC <: Broadcasted{<:SerializedArrayStyle{N}}} <: + AbstractSerializedArray{T, N} + broadcasted::BC end function BroadcastSerializedArray( - broadcasted::B -) where {B<:Broadcasted{<:SerializedArrayStyle{N}}} where {N} - ElType = Base.Broadcast.combine_eltypes(broadcasted.f, broadcasted.args) - return BroadcastSerializedArray{ElType,N,B}(broadcasted) + broadcasted::B + ) where {B <: Broadcasted{<:SerializedArrayStyle{N}}} where {N} + ElType = Base.Broadcast.combine_eltypes(broadcasted.f, broadcasted.args) + return BroadcastSerializedArray{ElType, N, B}(broadcasted) end Base.size(a::BroadcastSerializedArray) = size(a.broadcasted) Base.broadcastable(a::BroadcastSerializedArray) = a.broadcasted function adapt_structure_serialized(to, a::BroadcastSerializedArray) - return Base.Broadcast.broadcasted( - a.broadcasted.f, map(adapt_serialized(to), a.broadcasted.args)... - ) + return Base.Broadcast.broadcasted( + a.broadcasted.f, map(adapt_serialized(to), a.broadcasted.args)... + ) end # Special case to eagerly instantiate broadcasts. function adapt_storage_serialized(::MemoryAdaptor, a::BroadcastSerializedArray) - return copy(a) + return copy(a) end function Base.copy(broadcasted::Broadcasted{SerializedArrayStyle{N}}) where {N} - return BroadcastSerializedArray(flatten(broadcasted)) + return BroadcastSerializedArray(flatten(broadcasted)) end end diff --git a/test/runtests.jl b/test/runtests.jl index 98b2d2b..0008050 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,60 +6,62 @@ 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) - groupdir = joinpath(@__DIR__, testgroup) - for file in filter(istestfile, readdir(groupdir)) - filename = joinpath(groupdir, file) - @eval @safetestset $file begin - include($filename) + # tests in groups based on folder structure + for testgroup in filter(isdir, readdir(@__DIR__)) + if GROUP == "ALL" || GROUP == uppercase(testgroup) + groupdir = joinpath(@__DIR__, testgroup) + for file in filter(istestfile, readdir(groupdir)) + filename = joinpath(groupdir, file) + @eval @safetestset $file begin + include($filename) + 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_adaptext.jl b/test/test_adaptext.jl index 5f461ae..1e270bf 100644 --- a/test/test_adaptext.jl +++ b/test/test_adaptext.jl @@ -8,15 +8,15 @@ using TestExtras: @constinferred elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) arrayts = (Array, JLArray) @testset "SerializedArraysAdaptExt (eltype=$elt, arraytype=$arrayt)" for elt in elts, - arrayt in arrayts + arrayt in arrayts - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = PermutedDimsArray(x, (2, 1)) - a = adapt(SerializedArray, x) - @test a isa SerializedArray{elt,2,arrayt{elt,2}} - b = adapt(SerializedArray, y) - @test b isa - PermutedDimsArray{elt,2,(2, 1),(2, 1),<:SerializedArray{elt,2,<:arrayt{elt,2}}} - @test parent(b) == a + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = PermutedDimsArray(x, (2, 1)) + a = adapt(SerializedArray, x) + @test a isa SerializedArray{elt, 2, arrayt{elt, 2}} + b = adapt(SerializedArray, y) + @test b isa + PermutedDimsArray{elt, 2, (2, 1), (2, 1), <:SerializedArray{elt, 2, <:arrayt{elt, 2}}} + @test parent(b) == a end diff --git a/test/test_aqua.jl b/test/test_aqua.jl index 6c9485c..76d7c59 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(SerializedArrays) + Aqua.test_all(SerializedArrays) end diff --git a/test/test_basics.jl b/test/test_basics.jl index 7c667be..6efbb99 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -1,14 +1,14 @@ using GPUArraysCore: @allowscalar using JLArrays: JLArray using SerializedArrays: - AdjointSerializedArray, - PermutedSerializedArray, - ReshapedSerializedArray, - SerializedArray, - SubSerializedArray, - TransposeSerializedArray, - disk, - memory + AdjointSerializedArray, + PermutedSerializedArray, + ReshapedSerializedArray, + SerializedArray, + SubSerializedArray, + TransposeSerializedArray, + disk, + memory using StableRNGs: StableRNG using Test: @test, @testset using TestExtras: @constinferred @@ -16,138 +16,138 @@ using TestExtras: @constinferred elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) arrayts = (Array, JLArray) @testset "SerializedArrays (eltype=$elt, arraytype=$arrayt)" for elt in elts, - arrayt in arrayts - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - @test @constinferred(copy(a)) == x - @test typeof(copy(a)) == typeof(x) - @test memory(a) == x - @test memory(a) isa arrayt{elt,2} - @test memory(x) === x - @test disk(a) === a - @test disk(x) == a - @test disk(x) isa SerializedArray{elt,2,<:arrayt{elt,2}} - - x = arrayt(zeros(elt, 4, 4)) - a = SerializedArray(x) - @allowscalar begin - a[1, 1] = 2 - @test @constinferred(a[1, 1]) == 2 - end - - x = arrayt(zeros(elt, 4, 4)) - a = SerializedArray(x) - b = 2a - @test @constinferred(copy(b)) == 2x - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - b = SerializedArray(y) - c = @constinferred(a * b) - @test c == x * y - @test c isa arrayt{elt,2} - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - b = similar(a) - @test b isa arrayt{elt,2} - @test size(b) == size(a) == size(x) - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = permutedims(SerializedArray(x), (2, 1)) - @test a isa PermutedSerializedArray{elt,2} - @test similar(a) isa arrayt{elt,2} - @test copy(a) == permutedims(x, (2, 1)) - @test copy(2a) == 2permutedims(x, (2, 1)) - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = transpose(SerializedArray(x)) - @test a isa TransposeSerializedArray{elt} - @test similar(a) isa arrayt{elt,2} - @test copy(a) == transpose(x) - @test copy(2a) == 2transpose(x) - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = adjoint(SerializedArray(x)) - @test a isa AdjointSerializedArray{elt} - @test similar(a) isa arrayt{elt,2} - @test copy(a) == adjoint(x) - @test copy(2a) == 2adjoint(x) - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - @test transpose(transpose(a)) === a - @test adjoint(adjoint(a)) === a - if isreal(a) - @test adjoint(transpose(a)) === a - @test transpose(adjoint(a)) === a - end - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = reshape(SerializedArray(x), 16) - @test a isa ReshapedSerializedArray{elt,1} - @test similar(a) isa arrayt{elt,1} - @test copy(a) == reshape(x, 16) - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = reshape(permutedims(SerializedArray(x), (2, 1)), 16) - @test a isa ReshapedSerializedArray{elt,1,<:PermutedSerializedArray{elt,2}} - @test similar(a) isa arrayt{elt,1} - @test copy(a) == reshape(permutedims(x, (2, 1)), 16) - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - @test a == a - @test x == a - @test a == x - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - b = SerializedArray(y) - copyto!(b, a) - @test b == a - @test b == x - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - b = SerializedArray(y) - copyto!(b, x) - @test b == a - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - copyto!(y, a) - b = SerializedArray(y) - @test b == a - - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = @view x[2:3, 2:3] - a = SerializedArray(x) - b = @view a[2:3, 2:3] - @test b isa SubSerializedArray{elt,2} - c = 2b - @test 2y == copy(c) - @allowscalar begin - b[1, 1] = 2 - @test @constinferred(b[1, 1]) == 2 - end + arrayt in arrayts + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + @test @constinferred(copy(a)) == x + @test typeof(copy(a)) == typeof(x) + @test memory(a) == x + @test memory(a) isa arrayt{elt, 2} + @test memory(x) === x + @test disk(a) === a + @test disk(x) == a + @test disk(x) isa SerializedArray{elt, 2, <:arrayt{elt, 2}} + + x = arrayt(zeros(elt, 4, 4)) + a = SerializedArray(x) + @allowscalar begin + a[1, 1] = 2 + @test @constinferred(a[1, 1]) == 2 + end + + x = arrayt(zeros(elt, 4, 4)) + a = SerializedArray(x) + b = 2a + @test @constinferred(copy(b)) == 2x + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + b = SerializedArray(y) + c = @constinferred(a * b) + @test c == x * y + @test c isa arrayt{elt, 2} + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + b = similar(a) + @test b isa arrayt{elt, 2} + @test size(b) == size(a) == size(x) + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = permutedims(SerializedArray(x), (2, 1)) + @test a isa PermutedSerializedArray{elt, 2} + @test similar(a) isa arrayt{elt, 2} + @test copy(a) == permutedims(x, (2, 1)) + @test copy(2a) == 2permutedims(x, (2, 1)) + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = transpose(SerializedArray(x)) + @test a isa TransposeSerializedArray{elt} + @test similar(a) isa arrayt{elt, 2} + @test copy(a) == transpose(x) + @test copy(2a) == 2transpose(x) + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = adjoint(SerializedArray(x)) + @test a isa AdjointSerializedArray{elt} + @test similar(a) isa arrayt{elt, 2} + @test copy(a) == adjoint(x) + @test copy(2a) == 2adjoint(x) + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + @test transpose(transpose(a)) === a + @test adjoint(adjoint(a)) === a + if isreal(a) + @test adjoint(transpose(a)) === a + @test transpose(adjoint(a)) === a + end + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = reshape(SerializedArray(x), 16) + @test a isa ReshapedSerializedArray{elt, 1} + @test similar(a) isa arrayt{elt, 1} + @test copy(a) == reshape(x, 16) + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = reshape(permutedims(SerializedArray(x), (2, 1)), 16) + @test a isa ReshapedSerializedArray{elt, 1, <:PermutedSerializedArray{elt, 2}} + @test similar(a) isa arrayt{elt, 1} + @test copy(a) == reshape(permutedims(x, (2, 1)), 16) + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + @test a == a + @test x == a + @test a == x + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + b = SerializedArray(y) + copyto!(b, a) + @test b == a + @test b == x + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + b = SerializedArray(y) + copyto!(b, x) + @test b == a + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + copyto!(y, a) + b = SerializedArray(y) + @test b == a + + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = @view x[2:3, 2:3] + a = SerializedArray(x) + b = @view a[2:3, 2:3] + @test b isa SubSerializedArray{elt, 2} + c = 2b + @test 2y == copy(c) + @allowscalar begin + b[1, 1] = 2 + @test @constinferred(b[1, 1]) == 2 + end end diff --git a/test/test_linearalgebraext.jl b/test/test_linearalgebraext.jl index a703a29..ec7c028 100644 --- a/test/test_linearalgebraext.jl +++ b/test/test_linearalgebraext.jl @@ -8,43 +8,43 @@ using TestExtras: @constinferred elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) arrayts = (Array, JLArray) @testset "SerializedArraysLinearAlgebraExt (eltype=$elt, arraytype=$arrayt)" for elt in - elts, - arrayt in arrayts + elts, + arrayt in arrayts - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - y = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - b = SerializedArray(y) - c = @constinferred(a * b) - @test c == x * y - @test c isa arrayt{elt,2} + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + y = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + b = SerializedArray(y) + c = @constinferred(a * b) + @test c == x * y + @test c isa arrayt{elt, 2} - c = @constinferred(x * b) - @test c == x * y - @test c isa arrayt{elt,2} + c = @constinferred(x * b) + @test c == x * y + @test c isa arrayt{elt, 2} - c = @constinferred(a * y) - @test c == x * y - @test c isa arrayt{elt,2} + c = @constinferred(a * y) + @test c == x * y + @test c isa arrayt{elt, 2} - a = permutedims(SerializedArray(x), (2, 1)) - b = permutedims(SerializedArray(y), (2, 1)) - c = @constinferred(a * b) - @test c == permutedims(x, (2, 1)) * permutedims(y, (2, 1)) - @test c isa arrayt{elt,2} + a = permutedims(SerializedArray(x), (2, 1)) + b = permutedims(SerializedArray(y), (2, 1)) + c = @constinferred(a * b) + @test c == permutedims(x, (2, 1)) * permutedims(y, (2, 1)) + @test c isa arrayt{elt, 2} - rng = StableRNG(123) - x = arrayt(randn(rng, elt, 4, 4)) - a = SerializedArray(x) - # `LinearAlgebra.eigen(::JLArray)` is broken with - # a scalar indexing issue. - if arrayt ≠ JLArray - @test eigen(a) == eigen(x) - end - Q, R = qr(a) - Qₓ, Rₓ = qr(x) - @test Q == Qₓ - @test R == Rₓ - @test svd(a) == svd(x) + rng = StableRNG(123) + x = arrayt(randn(rng, elt, 4, 4)) + a = SerializedArray(x) + # `LinearAlgebra.eigen(::JLArray)` is broken with + # a scalar indexing issue. + if arrayt ≠ JLArray + @test eigen(a) == eigen(x) + end + Q, R = qr(a) + Qₓ, Rₓ = qr(x) + @test Q == Qₓ + @test R == Rₓ + @test svd(a) == svd(x) end