Skip to content

Commit 190d74d

Browse files
authored
Empty array space (#425)
1 parent 72ea1f6 commit 190d74d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Spaces/ArraySpace.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const VectorSpace{S,DD,RR,A<:AbstractVector{S}} = ArraySpace{S,1,DD,RR,A}
1818
const MatrixSpace{S,DD,RR,A<:AbstractMatrix{S}} = ArraySpace{S,2,DD,RR,A}
1919

2020
#TODO: Think through domain/domaindominsion
21+
ArraySpace(sp::AbstractArray{SS,N}) where {D,R,SS<:Space{D,R},N} =
22+
ArraySpace{SS,N,D,R,typeof(sp)}(sp)
2123
ArraySpace(sp::AbstractArray{SS,N}, f = first(sp)) where {SS<:Space,N} =
2224
ArraySpace{SS,N,domaintype(f),mapreduce(rangetype,promote_type,sp),typeof(sp)}(sp)
2325
ArraySpace(S::Space,::Val{n}) where {n} = ArraySpace(@SArray fill(S,n...))
@@ -57,7 +59,7 @@ iterate(f::Fun{<:ArraySpace}) = iterate(components(f))
5759

5860

5961
Base.reshape(AS::ArraySpace,k...) = ArraySpace(reshape(AS.spaces,k...))
60-
dimension(AS::ArraySpace) = mapreduce(dimension,+,AS.spaces)
62+
dimension(AS::ArraySpace) = mapreduce(dimension,+,AS.spaces,init=0)
6163

6264
# TODO: union domain
6365
domain(AS::ArraySpace) = domain(AS.spaces[1])

test/SpacesTest.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,10 @@ using LinearAlgebra
345345
a = @inferred space(rand(2,2))
346346
b = @inferred space(@SArray rand(2,2))
347347
@test a == b
348+
349+
# empty array space
350+
A = ApproxFunBase.ArraySpace(empty!([PointSpace(1:3)]))
351+
@test length(A) == 0
352+
@test ApproxFunBase.dimension(A) == 0
348353
end
349354
end

0 commit comments

Comments
 (0)