diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index fc9e227..f67c4e9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -26,7 +26,7 @@ jobs: - macOS-latest - windows-latest arch: - - x64 + - aarch64 steps: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 diff --git a/Project.toml b/Project.toml index afa351c..bb641fd 100644 --- a/Project.toml +++ b/Project.toml @@ -10,16 +10,18 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [weakdeps] AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Metal = "dde4c033-4e86-420c-a63e-0dd931031962" [compat] -Adapt = "3, 4" AMDGPU = "0.3.7, 0.4, 0.5, 0.6, 0.7, 0.8" +Adapt = "3, 4" CUDA = "3.12, 4, 5" -julia = "1.9" # Minimum required Julia version (supporting extensions and weak dependencies) +Metal = "1" StaticArrays = "1" +julia = "1.9" # Minimum required Julia version (supporting extensions and weak dependencies) [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "AMDGPU", "CUDA"] +test = ["Test", "AMDGPU", "CUDA", "Metal"] diff --git a/src/CellArray.jl b/src/CellArray.jl index 0b64583..df76692 100644 --- a/src/CellArray.jl +++ b/src/CellArray.jl @@ -188,6 +188,44 @@ function define_ROCCellArray() end end +""" + @define_MtlCellArray + +Define the following type alias and constructors in the caller module: + +******************************************************************************** + MtlCellArray{T<:Cell,N,B,T_elem} <: AbstractArray{T,N} where Cell <: Union{Number, SArray, FieldArray} + +`N`-dimensional CellArray with cells of type `T`, blocklength `B`, and `T_array` being a `MtlArray` of element type `T_elem`: alias for `CellArray{T,N,B,MtlArray{T_elem,CellArrays._N}}`. + +-------------------------------------------------------------------------------- + + MtlCellArray{T,B}(undef, dims) + MtlCellArray{T}(undef, dims) + +Construct an uninitialized `N`-dimensional `CellArray` containing `Cells` of type `T` which are stored in an array of kind `MtlArray`. + +See also: [`CellArray`](@ref), [`CPUCellArray`](@ref), [`ROCCellArray`](@ref) +******************************************************************************** + +!!! note "Avoiding unneeded dependencies" + The type aliases and constructors for GPU `CellArray`s are provided via macros to avoid unneeded dependencies on the GPU packages in CellArrays. + +See also: [`@define_MtlCellArray`](@ref) +""" +macro define_MtlCellArray() esc(define_MtlCellArray()) end + +function define_MtlCellArray() + quote + const MtlCellArray{T,N,B,T_elem} = CellArrays.CellArray{T,N,B,Metal.MtlArray{T_elem,CellArrays._N}} + + MtlCellArray{T,B}(::UndefInitializer, dims::NTuple{N,Int}) where {T<:CellArrays.Cell,N,B} = (CellArrays.check_T(T); MtlCellArray{T,N,B,eltype(T)}(undef, dims)) + MtlCellArray{T,B}(::UndefInitializer, dims::Int...) where {T<:CellArrays.Cell,B} = MtlCellArray{T,B}(undef, dims) + MtlCellArray{T}(::UndefInitializer, dims::NTuple{N,Int}) where {T<:CellArrays.Cell,N} = MtlCellArray{T,0}(undef, dims) + MtlCellArray{T}(::UndefInitializer, dims::Int...) where {T<:CellArrays.Cell} = MtlCellArray{T}(undef, dims) + end +end + ## AbstractArray methods @@ -203,7 +241,6 @@ end CellArray{T,N,B}(T_arraykind{eltype(T),_N}, undef, dims) end - @inline function Base.fill!(A::CellArray{T,N,B,T_array}, x) where {T<:Number,N,B,T_array} cell = convert(T, x) A.data[:, 1, :] .= cell diff --git a/src/CellArrays.jl b/src/CellArrays.jl index 86bab21..bbd8292 100644 --- a/src/CellArrays.jl +++ b/src/CellArrays.jl @@ -31,5 +31,5 @@ using .Exceptions include("CellArray.jl") ## Exports (need to be after include of submodules if re-exports from them) -export CellArray, CPUCellArray, @define_CuCellArray, @define_ROCCellArray, cellsize, blocklength, field +export CellArray, CPUCellArray, @define_CuCellArray, @define_ROCCellArray, @define_MtlCellArray, cellsize, blocklength, field end diff --git a/test/test_CellArray.jl b/test/test_CellArray.jl index 5a3c5a8..878b135 100644 --- a/test/test_CellArray.jl +++ b/test/test_CellArray.jl @@ -1,22 +1,27 @@ using Test -using CUDA, AMDGPU, StaticArrays +using CUDA, AMDGPU, Metal, StaticArrays import CellArrays -import CellArrays: CPUCellArray, @define_CuCellArray, @define_ROCCellArray, cellsize, blocklength, _N +import CellArrays: CPUCellArray, @define_CuCellArray, @define_ROCCellArray, @define_MtlCellArray, cellsize, blocklength, _N import CellArrays: IncoherentArgumentError, ArgumentError @define_CuCellArray @define_ROCCellArray +@define_MtlCellArray -test_cuda = CUDA.functional() +test_cuda = CUDA.functional() test_amdgpu = AMDGPU.functional() +test_metal = @static Metal.functional() && Sys.isapple() array_types = ["CPU"] +FloatDefaultTypes = [Float64] ArrayConstructors = [Array] CellArrayConstructors = [CPUCellArray] allowscalar_functions = Function[(x->x)] + if test_cuda cuzeros = CUDA.zeros push!(array_types, "CUDA") + push!(FloatDefaultTypes, Float64) push!(ArrayConstructors, CuArray) push!(CellArrayConstructors, CuCellArray) push!(allowscalar_functions, CUDA.allowscalar) @@ -24,10 +29,19 @@ end if test_amdgpu roczeros = AMDGPU.zeros push!(array_types, "AMDGPU") + push!(FloatDefaultTypes, Float64) push!(ArrayConstructors, ROCArray) push!(CellArrayConstructors, ROCCellArray) push!(allowscalar_functions, AMDGPU.allowscalar) #TODO: to be implemented end +if test_metal + mtlzeros = Metal.zeros + push!(array_types, "Metal") + push!(FloatDefaultTypes, Float32) + push!(ArrayConstructors, MtlArray) + push!(CellArrayConstructors, MtlCellArray) + push!(allowscalar_functions, Metal.allowscalar) #TODO: to be implemented +end struct MyFieldArray{T} <: FieldArray{Tuple{2,2,2,2}, T, 4} xxxx::T @@ -53,64 +67,63 @@ mutable struct MyMutableFieldArray{T} <: FieldArray{Tuple{2}, T, 1} yxxx::T end - @testset "$(basename(@__FILE__))" begin - @testset "1. CellArray allocation ($array_type arrays)" for (array_type, Array, CellArray) in zip(array_types, ArrayConstructors, CellArrayConstructors) + @testset "1. CellArray allocation ($array_type arrays)" for (array_type, Array, CellArray, Float) in zip(array_types, ArrayConstructors, CellArrayConstructors, FloatDefaultTypes) @testset "Number cells" begin - dims = (2,3) - A = CellArray{Float64}(undef, dims) - B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims...) - C = CellArray{Float64,1}(undef, dims) - D = CellArray{Int32,4}(undef, dims) - @test typeof(A.data) <: Array - @test typeof(B.data) <: Array - @test typeof(C.data) <: Array - @test typeof(D.data) <: Array - @test eltype(A.data) == Float64 - @test eltype(B.data) == Int32 - @test eltype(C.data) == Float64 - @test eltype(D.data) == Int32 - @test eltype(A) == Float64 - @test eltype(B) == Int32 - @test eltype(C) == Float64 - @test eltype(D) == Int32 - @test typeof(A) == CellArrays.CellArray{Float64, length(dims), 0, Array{eltype(A.data),_N}} - @test typeof(B) == CellArrays.CellArray{Int32, length(dims), prod(dims), Array{eltype(B.data),_N}} - @test typeof(C) == CellArrays.CellArray{Float64, length(dims), 1, Array{eltype(C.data),_N}} - @test typeof(D) == CellArrays.CellArray{Int32, length(dims), 4, Array{eltype(D.data),_N}} - @test length(A.data) == prod(dims) - @test length(B.data) == prod(dims) - @test length(C.data) == prod(dims) - @test (length(D.data) > prod(dims) && length(D.data)%prod(dims) <= 4) - @test A.dims == dims - @test B.dims == dims - @test C.dims == dims - @test D.dims == dims - end; + dims = (2,3) + A = CellArray{Float}(undef, dims) + B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims...) + C = CellArray{Float,1}(undef, dims) + D = CellArray{Int32,4}(undef, dims) + @test typeof(A.data) <: Array + @test typeof(B.data) <: Array + @test typeof(C.data) <: Array + @test typeof(D.data) <: Array + @test eltype(A.data) == Float + @test eltype(B.data) == Int32 + @test eltype(C.data) == Float + @test eltype(D.data) == Int32 + @test eltype(A) == Float + @test eltype(B) == Int32 + @test eltype(C) == Float + @test eltype(D) == Int32 + @test typeof(A) == CellArrays.CellArray{Float, length(dims), 0, Array{eltype(A.data),_N}} + @test typeof(B) == CellArrays.CellArray{Int32, length(dims), prod(dims), Array{eltype(B.data),_N}} + @test typeof(C) == CellArrays.CellArray{Float, length(dims), 1, Array{eltype(C.data),_N}} + @test typeof(D) == CellArrays.CellArray{Int32, length(dims), 4, Array{eltype(D.data),_N}} + @test length(A.data) == prod(dims) + @test length(B.data) == prod(dims) + @test length(C.data) == prod(dims) + @test (length(D.data) > prod(dims) && length(D.data)%prod(dims) <= 4) + @test A.dims == dims + @test B.dims == dims + @test C.dims == dims + @test D.dims == dims + end @testset "SArray cells" begin - dims = (2,3) - celldims = (3,4) - T_Float64 = SMatrix{celldims..., Float64, prod(celldims)} - T_Int32 = SMatrix{celldims..., Int32, prod(celldims)} - A = CellArray{T_Float64}(undef, dims) + dims = (2,3) + celldims = (3,4) + T_Float = SMatrix{celldims..., Float, prod(celldims)} + T_Int32 = SMatrix{celldims..., Int32, prod(celldims)} + A = CellArray{T_Float}(undef, dims) B = CellArrays.CellArray{T_Int32,prod(dims)}(Array, undef, dims...) - C = CellArray{T_Float64,1}(undef, dims) + C = CellArray{T_Float,1}(undef, dims) D = CellArray{T_Int32,4}(undef, dims) @test typeof(A.data) <: Array @test typeof(B.data) <: Array @test typeof(C.data) <: Array @test typeof(D.data) <: Array - @test eltype(A.data) == Float64 + @test eltype(A.data) == Float @test eltype(B.data) == Int32 - @test eltype(C.data) == Float64 + @test eltype(C.data) == Float @test eltype(D.data) == Int32 - @test eltype(A) == T_Float64 + @test eltype(A) == T_Float @test eltype(B) == T_Int32 - @test eltype(C) == T_Float64 + @test eltype(C) == T_Float @test eltype(D) == T_Int32 - @test typeof(A) == CellArrays.CellArray{T_Float64, length(dims), 0, Array{eltype(A.data),_N}} + @test typeof(A) == CellArrays.CellArray{T_Float, length(dims), 0, Array{eltype(A.data),_N}} @test typeof(B) == CellArrays.CellArray{T_Int32, length(dims), prod(dims), Array{eltype(B.data),_N}} - @test typeof(C) == CellArrays.CellArray{T_Float64, length(dims), 1, Array{eltype(C.data),_N}} + @test typeof(C) == CellArrays.CellArray{T_Float, length(dims), 1, Array{eltype(C.data),_N}} @test typeof(D) == CellArrays.CellArray{T_Int32, length(dims), 4, Array{eltype(D.data),_N}} @test length(A.data) == prod(dims)*prod(celldims) @test length(B.data) == prod(dims)*prod(celldims) @@ -122,29 +135,29 @@ end @test D.dims == dims end; @testset "FieldArray cells" begin - dims = (2,3) - celldims = size(MyFieldArray) - T_Float64 = MyFieldArray{Float64} - T_Int32 = MyFieldArray{Int32} - A = CellArray{T_Float64}(undef, dims) + dims = (2,3) + celldims = size(MyFieldArray) + T_Float = MyFieldArray{Float} + T_Int32 = MyFieldArray{Int32} + A = CellArray{T_Float}(undef, dims) B = CellArrays.CellArray{T_Int32,prod(dims)}(Array, undef, dims...) - C = CellArray{T_Float64,1}(undef, dims) + C = CellArray{T_Float,1}(undef, dims) D = CellArray{T_Int32,4}(undef, dims) @test typeof(A.data) <: Array @test typeof(B.data) <: Array @test typeof(C.data) <: Array @test typeof(D.data) <: Array - @test eltype(A.data) == Float64 + @test eltype(A.data) == Float @test eltype(B.data) == Int32 - @test eltype(C.data) == Float64 + @test eltype(C.data) == Float @test eltype(D.data) == Int32 - @test eltype(A) == T_Float64 + @test eltype(A) == T_Float @test eltype(B) == T_Int32 - @test eltype(C) == T_Float64 + @test eltype(C) == T_Float @test eltype(D) == T_Int32 - @test typeof(A) == CellArrays.CellArray{T_Float64, length(dims), 0, Array{eltype(A.data),_N}} + @test typeof(A) == CellArrays.CellArray{T_Float, length(dims), 0, Array{eltype(A.data),_N}} @test typeof(B) == CellArrays.CellArray{T_Int32, length(dims), prod(dims), Array{eltype(B.data),_N}} - @test typeof(C) == CellArrays.CellArray{T_Float64, length(dims), 1, Array{eltype(C.data),_N}} + @test typeof(C) == CellArrays.CellArray{T_Float, length(dims), 1, Array{eltype(C.data),_N}} @test typeof(D) == CellArrays.CellArray{T_Int32, length(dims), 4, Array{eltype(D.data),_N}} @test length(A.data) == prod(dims)*prod(celldims) @test length(B.data) == prod(dims)*prod(celldims) @@ -156,20 +169,20 @@ end @test D.dims == dims end; end; - @testset "2. functions ($array_type arrays)" for (array_type, Array, CellArray, allowscalar) in zip(array_types, ArrayConstructors, CellArrayConstructors, allowscalar_functions) - dims = (2,3) - celldims = (3,4) # Needs to be compatible for matrix multiplication! - T_Float64 = SMatrix{celldims..., Float64, prod(celldims)} - T_Int32 = SMatrix{celldims..., Int32, prod(celldims)} - T2_Float64 = MyFieldArray{Float64} - T2_Int32 = MyFieldArray{Int32} - A = CellArray{Float64}(undef, dims) + @testset "2. functions ($array_type arrays)" for (array_type, Array, CellArray, allowscalar, Float) in zip(array_types, ArrayConstructors, CellArrayConstructors, allowscalar_functions, FloatDefaultTypes) + dims = (2,3) + celldims = (3,4) # Needs to be compatible for matrix multiplication! + T_Float = SMatrix{celldims..., Float, prod(celldims)} + T_Int32 = SMatrix{celldims..., Int32, prod(celldims)} + T2_Float = MyFieldArray{Float} + T2_Int32 = MyFieldArray{Int32} + A = CellArray{Float}(undef, dims) B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims) - C = CellArray{T_Float64}(undef, dims) + C = CellArray{T_Float}(undef, dims) D = CellArray{T_Int32,prod(dims)}(undef, dims) - E = CellArray{T2_Float64}(undef, dims) + E = CellArray{T2_Float}(undef, dims) F = CellArray{T2_Int32,prod(dims)}(undef, dims) - G = CellArray{T_Float64,1}(undef, dims) + G = CellArray{T_Float,1}(undef, dims) H = CellArray{T_Int32,4}(undef, dims) @testset "size" begin @test size(A) == dims @@ -203,12 +216,12 @@ end allowscalar(true) fill!(A, 9); @test all(Base.Array(A.data) .== 9.0) fill!(B, 9.0); @test all(Base.Array(B.data) .== 9) - fill!(C, (1:length(eltype(C)))); @test all(C .== (T_Float64(1:length(eltype(C))) for i=1:dims[1], j=1:dims[2])) - fill!(D, (1:length(eltype(D)))); @test all(D .== (T_Int32(1:length(eltype(D))) for i=1:dims[1], j=1:dims[2])) - fill!(E, (1:length(eltype(E)))); @test all(E .== (T2_Float64(1:length(eltype(E))) for i=1:dims[1], j=1:dims[2])) - fill!(F, (1:length(eltype(F)))); @test all(F .== (T2_Int32(1:length(eltype(F))) for i=1:dims[1], j=1:dims[2])) - fill!(G, (1:length(eltype(G)))); @test all(G .== (T_Float64(1:length(eltype(G))) for i=1:dims[1], j=1:dims[2])) - fill!(H, (1:length(eltype(H)))); @test all(H .== (T_Int32(1:length(eltype(H))) for i=1:dims[1], j=1:dims[2])) + fill!(C, (1:length(eltype(C)))); @test all(C .== (T_Float(1:length(eltype(C))) for i=1:dims[1], j=1:dims[2])) + fill!(D, (1:length(eltype(D)))); @test all(D .== (T_Int32(1:length(eltype(D))) for i=1:dims[1], j=1:dims[2])) + fill!(E, (1:length(eltype(E)))); @test all(E .== (T2_Float(1:length(eltype(E))) for i=1:dims[1], j=1:dims[2])) + fill!(F, (1:length(eltype(F)))); @test all(F .== (T2_Int32(1:length(eltype(F))) for i=1:dims[1], j=1:dims[2])) + fill!(G, (1:length(eltype(G)))); @test all(G .== (T_Float(1:length(eltype(G))) for i=1:dims[1], j=1:dims[2])) + fill!(H, (1:length(eltype(H)))); @test all(H .== (T_Int32(1:length(eltype(H))) for i=1:dims[1], j=1:dims[2])) allowscalar(false) end @testset "getindex / setindex! (array programming)" begin @@ -216,19 +229,19 @@ end A.data.=0; B.data.=0; C.data.=0; D.data.=0; E.data.=0; F.data.=0; G.data.=0; H.data.=0; A[2,2:3] .= 9 B[2,2:3] .= 9.0 - C[2,2:3] .= (T_Float64(1:length(T_Float64)), T_Float64(1:length(T_Float64))) + C[2,2:3] .= (T_Float(1:length(T_Float)), T_Float(1:length(T_Float))) D[2,2:3] .= (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32))) - E[2,2:3] .= (T2_Float64(1:length(T2_Float64)), T2_Float64(1:length(T2_Float64))) + E[2,2:3] .= (T2_Float(1:length(T2_Float)), T2_Float(1:length(T2_Float))) F[2,2:3] .= (T2_Int32(1:length(T2_Int32)), T2_Int32(1:length(T2_Int32))) - G[2,2:3] .= (T_Float64(1:length(T_Float64)), T_Float64(1:length(T_Float64))) + G[2,2:3] .= (T_Float(1:length(T_Float)), T_Float(1:length(T_Float))) H[2,2:3] .= (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32))) @test all(A[2,2:3] .== 9.0) @test all(B[2,2:3] .== 9) - @test all(C[2,2:3] .== (T_Float64(1:length(T_Float64)), T_Float64(1:length(T_Float64)))) + @test all(C[2,2:3] .== (T_Float(1:length(T_Float)), T_Float(1:length(T_Float)))) @test all(D[2,2:3] .== (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32)))) - @test all(E[2,2:3] .== (T2_Float64(1:length(T2_Float64)), T2_Float64(1:length(T2_Float64)))) + @test all(E[2,2:3] .== (T2_Float(1:length(T2_Float)), T2_Float(1:length(T2_Float)))) @test all(F[2,2:3] .== (T2_Int32(1:length(T2_Int32)), T2_Int32(1:length(T2_Int32)))) - @test all(G[2,2:3] .== (T_Float64(1:length(T_Float64)), T_Float64(1:length(T_Float64)))) + @test all(G[2,2:3] .== (T_Float(1:length(T_Float)), T_Float(1:length(T_Float)))) @test all(H[2,2:3] .== (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32)))) allowscalar(false) end; @@ -271,6 +284,21 @@ end J.data.=3; J_ref.data.=36; @roc gridsize=size(J) matsquare2D_AMDGPU!(J); AMDGPU.synchronize(); @test AMDGPU.@allowscalar all(J .== J_ref) C.data.=2; G.data.=3; @roc gridsize=size(C) add2D_AMDGPU!(C, G); AMDGPU.synchronize(); @test all(Base.Array(C.data) .== 5) end + if array_type == "Metal" + function add2D_Metal!(A, B) + ix, iy = thread_position_in_grid_2d() + A[ix,iy] = A[ix,iy] + B[ix,iy]; + return + end + function matsquare2D_Metal!(A) + ix, iy = thread_position_in_grid_2d() + A[ix,iy] = A[ix,iy] * A[ix,iy]; + return + end + A.data.=3; @metal threads=size(A) groups=1 matsquare2D_Metal!(A); Metal.synchronize(); @test all(Base.Array(A.data) .== 9) + J.data.=3; J_ref.data.=36; @metal threads=size(J) groups=1 matsquare2D_Metal!(J); Metal.synchronize(); @test Metal.@allowscalar all(J .== J_ref) + C.data.=2; G.data.=3; @metal threads=size(C) groups=1 add2D_Metal!(C, G); Metal.synchronize(); @test all(Base.Array(C.data) .== 5) + end end; @testset "cellsize" begin @test cellsize(A) == (1,) @@ -293,38 +321,40 @@ end @test blocklength(H) == 4 end; end; - @testset "3. Exceptions ($array_type arrays)" for (array_type, Array, CellArray) in zip(array_types, ArrayConstructors, CellArrayConstructors) - dims = (2,3) - celldims = (3,4) - T_Float64 = SMatrix{celldims..., Float64, prod(celldims)} - T_Int32 = SMatrix{celldims..., Int32, prod(celldims)} - T2_Float64 = MyFieldArray{Float64} - T2_Int32 = MyFieldArray{Int32} - A = CellArray{Float64}(undef, dims) + + @testset "3. Exceptions ($array_type arrays)" for (array_type, Array, CellArray, Float) in zip(array_types, ArrayConstructors, CellArrayConstructors, FloatDefaultTypes) + Float = array_type === "Metal" ? Float32 : Float64 + dims = (2,3) + celldims = (3,4) + T_Float = SMatrix{celldims..., Float, prod(celldims)} + T_Int32 = SMatrix{celldims..., Int32, prod(celldims)} + T2_Float = MyFieldArray{Float} + T2_Int32 = MyFieldArray{Int32} + A = CellArray{Float}(undef, dims) B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims) - C = CellArray{T_Float64}(undef, dims) + C = CellArray{T_Float}(undef, dims) D = CellArray{T_Int32,prod(dims)}(undef, dims) - E = CellArray{T2_Float64}(undef, dims) + E = CellArray{T2_Float}(undef, dims) F = CellArray{T2_Int32,prod(dims)}(undef, dims) - G = CellArray{T_Float64,1}(undef, dims) + G = CellArray{T_Float,1}(undef, dims) H = CellArray{T_Int32,4}(undef, dims) - @test_throws TypeError CellArray{Array}(undef, dims) # Error: TypeError (celltype T is restricted to `Cell` in the package) - @test_throws TypeError CellArray{MMatrix{celldims..., Float64, prod(celldims)}}(undef, dims) # ... - @test_throws ArgumentError CellArray{MyMutableFieldArray}(undef, dims) # Error: the celltype, `T`, must be a bitstype. - @test_throws IncoherentArgumentError CellArrays.CellArray{Float64,2,0}(similar(A.data, Float32), A.dims) # Error: eltype(data) must match eltype(T). - @test_throws IncoherentArgumentError CellArrays.CellArray{Int32,2,prod(dims)}(similar(B.data, Float64), B.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T_Float64,2,0}(similar(C.data, Float32), C.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T_Int32,2,prod(dims)}(similar(D.data, T_Int32), D.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T2_Float64,2,0}(similar(E.data, Float32), E.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T2_Int32,2,prod(dims)}(similar(F.data, T2_Int32), F.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T_Float64,2,1}(similar(G.data, Float32), G.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T_Int32,2,4}(similar(H.data, T_Int32), H.dims) # ... - @test_throws MethodError CellArrays.CellArray{Float64,2,0}(A.data[:], A.dims) # Error: ndims(data) must be 3. - @test_throws MethodError CellArrays.CellArray{T_Float64,2,0}(C.data[:], C.dims) # Error: ... - @test_throws MethodError CellArrays.CellArray{T2_Float64,2,0}(E.data[:], E.dims) # Error: ... - @test_throws IncoherentArgumentError CellArrays.CellArray{Float64,2,0}(similar(A.data, Float64, (1,2,1)), A.dims) # Error: size(data) must match (blocklen, prod(size(T), ceil(prod(dims)/blocklen)). - @test_throws IncoherentArgumentError CellArrays.CellArray{T_Float64,2,0}(similar(C.data, Float64, (1,2,1)), C.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{T2_Float64,2,0}(similar(E.data, Float64, (1,2,1)), E.dims) # ... - @test_throws IncoherentArgumentError CellArrays.CellArray{SMatrix{(4,5)..., Float64, prod((4,5))},2,0}(C.data, C.dims) # ... + @test_throws TypeError CellArray{Array}(undef, dims) # Error: TypeError (celltype T is restricted to `Cell` in the package) + @test_throws TypeError CellArray{MMatrix{celldims..., Float, prod(celldims)}}(undef, dims) # ... + @test_throws ArgumentError CellArray{MyMutableFieldArray}(undef, dims) # Error: the celltype, `T`, must be a bitstype. + @test_throws IncoherentArgumentError CellArrays.CellArray{Float,2,0}(similar(A.data, Float16), A.dims) # Error: eltype(data) must match eltype(T). + @test_throws IncoherentArgumentError CellArrays.CellArray{Int32,2,prod(dims)}(similar(B.data, Float), B.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T_Float,2,0}(similar(C.data, Float16), C.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T_Int32,2,prod(dims)}(similar(D.data, T_Int32), D.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T2_Float,2,0}(similar(E.data, Float16), E.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T2_Int32,2,prod(dims)}(similar(F.data, T2_Int32), F.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T_Float,2,1}(similar(G.data, Float16), G.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T_Int32,2,4}(similar(H.data, T_Int32), H.dims) # ... + @test_throws MethodError CellArrays.CellArray{Float,2,0}(A.data[:], A.dims) # Error: ndims(data) must be 3. + @test_throws MethodError CellArrays.CellArray{T_Float,2,0}(C.data[:], C.dims) # Error: ... + @test_throws MethodError CellArrays.CellArray{T2_Float,2,0}(E.data[:], E.dims) # Error: ... + @test_throws IncoherentArgumentError CellArrays.CellArray{Float,2,0}(similar(A.data, Float, (1,2,1)), A.dims) # Error: size(data) must match (blocklen, prod(size(T), ceil(prod(dims)/blocklen)). + @test_throws IncoherentArgumentError CellArrays.CellArray{T_Float,2,0}(similar(C.data, Float, (1,2,1)), C.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{T2_Float,2,0}(similar(E.data, Float, (1,2,1)), E.dims) # ... + @test_throws IncoherentArgumentError CellArrays.CellArray{SMatrix{(4,5)..., Float, prod((4,5))},2,0}(C.data, C.dims) # ... end; end;