Skip to content

Commit 7ef0317

Browse files
authored
constprop through Val in ArraySpace (#295)
* constprop through Val in ArraySpace * fix space
1 parent 777a1fc commit 7ef0317

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/ApproxFunBase.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using Base, BlockArrays, BandedMatrices, BlockBandedMatrices, DomainSets,
77
# Arpack
88

99
import StaticArrays, Calculus
10+
using StaticArrays: SVector, @SArray, SArray
1011

1112
import DomainSets: Domain, indomain, UnionDomain, ProductDomain, Point, ∂,
1213
elements, DifferenceDomain, Interval, ChebyshevInterval, boundary,
@@ -88,8 +89,6 @@ const BlockRange1 = BlockRange{1,Tuple{UnitRange{Int}}}
8889

8990
import Base: view
9091

91-
import StaticArrays: StaticArray, SVector
92-
9392
import DomainSets: dimension
9493

9594
import IntervalSets: (..), endpoints

src/Space.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,9 @@ for OP in (:maxspace,:(union))
638638
end
639639

640640
space(x::Number) = ConstantSpace(typeof(x))
641-
space(f::AbstractArray{T}) where T<:Number = ArraySpace(ConstantSpace{T}(), size(f)...)
641+
_maybestaticsize(A) = size(A)
642+
_maybestaticsize(A::SArray) = Val(size(A))
643+
space(f::AbstractArray{T}) where T<:Number = ArraySpace(ConstantSpace(T), _maybestaticsize(f))
642644

643645
setdomain(A::ConstantSpace{DD,R}, d) where {DD,R} = ConstantSpace{typeof(d),R}(d)
644646

src/Spaces/ArraySpace.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const MatrixSpace{S,DD,RR,A<:AbstractMatrix{S}} = ArraySpace{S,2,DD,RR,A}
2020
#TODO: Think through domain/domaindominsion
2121
ArraySpace(sp::AbstractArray{SS,N}, f = first(sp)) where {SS<:Space,N} =
2222
ArraySpace{SS,N,domaintype(f),mapreduce(rangetype,promote_type,sp),typeof(sp)}(sp)
23+
ArraySpace(S::Space,::Val{n}) where {n} = ArraySpace(@SArray fill(S,n...))
2324
ArraySpace(S::Space,n::NTuple{N,Int}) where {N} = ArraySpace(fill(S,n))
2425
ArraySpace(S::Space,n::Integer) = ArraySpace(S,(n,))
2526
ArraySpace(S::Space,n,m) = ArraySpace(fill(S,(n,m)))

test/SpacesTest.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,17 @@ using LinearAlgebra
298298
@test (@inferred union(b, b)) == b
299299
end
300300
end
301+
302+
@testset "ArraySpace" begin
303+
a = ApproxFunBase.ArraySpace(PointSpace(1:4), 2)
304+
b = @inferred ApproxFunBase.ArraySpace(PointSpace(1:4), Val(2))
305+
@test a == b
306+
a = ApproxFunBase.ArraySpace(PointSpace(1:4), 2, 2)
307+
b = @inferred ApproxFunBase.ArraySpace(PointSpace(1:4), Val((2,2)))
308+
@test a == b
309+
310+
a = @inferred space(rand(2,2))
311+
b = @inferred space(@SArray rand(2,2))
312+
@test a == b
313+
end
301314
end

0 commit comments

Comments
 (0)