Skip to content

Commit c18df44

Browse files
authored
Merge pull request #3 from JuliaApproximation/dl/3d
3D support
2 parents 4c6f85a + c65570d commit c18df44

File tree

8 files changed

+41
-23
lines changed

8 files changed

+41
-23
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ FastTransforms = "≥ 0.4.2"
4343
FillArrays = "≥ 0.5.0"
4444
InfiniteArrays = "0.1"
4545
IntervalSets = "≥ 0.3.1"
46-
LazyArrays = "0.8.0"
46+
LazyArrays = "0.8, 0.9"
4747
LowRankApprox = "0.2"
4848
SpecialFunctions = "≥ 0.7.0"
4949
StaticArrays = "≥ 0.8.3"

src/Domains/ProductDomain.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ function pushappendpts!(ret, xx, pts)
1919
push!(ret,Vec(xx...))
2020
else
2121
for x in pts[1]
22-
pushappendpts!(ret,(xx...,x),pts[2:end])
22+
pushappendpts!(ret,(xx...,x...),pts[2:end])
2323
end
2424
end
2525
ret
2626
end
2727

2828
function checkpoints(d::ProductDomain)
29-
pts=map(checkpoints,d.domains)
30-
ret=Vector{Vec{length(d.domains),float(mapreduce(eltype,promote_type,d.domains))}}(undef, 0)
29+
pts = checkpoints.(d.domains)
30+
ret=Vector{Vec{sum(dimension.(d.domains)),float(promote_type(eltype.(eltype.(d.domains))...))}}(undef, 0)
3131

3232
pushappendpts!(ret,(),pts)
3333
ret

src/LinearAlgebra/helper.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -716,18 +716,6 @@ conv(y::SVector{1}, x::AbstractVector) = y[1]*x
716716
conv(x::AbstractFill, y::SVector{1}) = x*y[1]
717717
conv(y::SVector{1}, x::AbstractFill) = y[1]*x
718718
conv(x::AbstractFill, y::AbstractFill) = DSP.conv(x, y)
719-
function conv(x::AbstractFill, y::AbstractVector)
720-
isinf(length(x)) || return DSP.conv(x,y)
721-
@assert length(y) == 1
722-
x*y[1]
723-
end
724-
function conv(y::AbstractVector, x::AbstractFill)
725-
isinf(length(x)) || return DSP.conv(y,x)
726-
@assert length(y) == 1
727-
y[1]*x
728-
end
729-
730-
731719

732720

733721
## BlockInterlacer

src/Multivariate/TensorSpace.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ TensorSpace(A::ProductDomain) = TensorSpace(tuple(map(Space,A.domains)...))
246246
(A::Space,B::TensorSpace) = TensorSpace(A,B.spaces...)
247247
(A::Space,B::Space) = TensorSpace(A,B)
248248

249-
domain(f::TensorSpace) = mapreduce(domain,×,f.spaces)
249+
domain(f::TensorSpace) = ×(domain.(f.spaces)...)
250250
Space(sp::ProductDomain) = TensorSpace(sp)
251251

252252
setdomain(sp::TensorSpace, d::ProductDomain) = TensorSpace(setdomain.(factors(sp), factors(d)))
@@ -368,9 +368,15 @@ function plan_transform(sp::TensorSpace, ::Type{T}, n::Integer) where {T}
368368
TransformPlan(sp,((plan_transform(sp.spaces[1],T,N),N),
369369
(plan_transform(sp.spaces[2],T,M),M)),
370370
Val{false})
371-
end
371+
end
372+
373+
function plan_transform!(sp::TensorSpace, ::Type{T}, n::Integer) where {T}
374+
P = plan_transform(sp, T, n)
375+
TransformPlan(sp, P.plan, Val{true})
376+
end
372377

373378
plan_transform(sp::TensorSpace, v::AbstractVector) = plan_transform(sp,eltype(v),length(v))
379+
plan_transform!(sp::TensorSpace, v::AbstractVector) = plan_transform!(sp,eltype(v),length(v))
374380

375381
function plan_itransform(sp::TensorSpace, v::AbstractVector{T}) where {T}
376382
N,M = size(totensor(sp, v)) # wasteful
@@ -380,13 +386,13 @@ function plan_itransform(sp::TensorSpace, v::AbstractVector{T}) where {T}
380386
end
381387

382388

383-
function *(T::TransformPlan{<:Any,<:TensorSpace,true},v::AbstractVector)
389+
function *(T::TransformPlan{TT,<:TensorSpace,true},v::AbstractVector) where TT # need where TT
384390
N,M = T.plan[1][2],T.plan[2][2]
385391
V=reshape(v,N,M)
386392
fromtensor(T.space,T*V)
387393
end
388394

389-
*(T::ITransformPlan{<:Any,<:TensorSpace,true},v::AbstractVector) =
395+
*(T::ITransformPlan{TT,<:TensorSpace,true},v::AbstractVector) where TT =
390396
vec(T*totensor(T.space,v))
391397

392398

src/Operators/Operator.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ macro wrapperstructure(Wrap)
461461
$ret
462462

463463
$func(D::$Wrap,k::Integer) = $func(D.op,k)
464+
$func(A::$Wrap,i::ApproxFunBase.Infinity) = $func(D.op,k)
464465
end
465466
end
466467

src/Space.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ isambiguous(sp::Space) = isambiguous(rangetype(sp))
9898

9999
#TODO: should it default to canonicalspace?
100100
points(d::Space,n) = points(domain(d),n)
101+
points(d::Space) = points(d, dimension(d))
101102

102103

103104

src/constructors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ end
3838

3939
# default_Fun is the default constructor, based on evaluation and transforms
4040
# last argument is whether to splat or not
41-
default_Fun(::Type{T},f,d::Space{ReComp},pts::AbstractVector,::Type{Val{true}}) where {T,ReComp} =
41+
default_Fun(::Type{T},f,d::Space{ReComp},pts::AbstractArray,::Type{Val{true}}) where {T,ReComp} =
4242
Fun(d,transform(d,T[f(x...) for x in pts]))
4343

44-
default_Fun(::Type{T},f,d::Space{ReComp},pts::AbstractVector,::Type{Val{false}}) where {T,ReComp} =
44+
default_Fun(::Type{T},f,d::Space{ReComp},pts::AbstractArray,::Type{Val{false}}) where {T,ReComp} =
4545
Fun(d,transform(d,broadcast!(f, similar(pts, T), pts)))
4646

4747

test/SpacesTest.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using ApproxFunBase, Test
2-
import ApproxFunBase: PointSpace, HeavisideSpace, PiecewiseSegment
2+
import ApproxFunBase: PointSpace, HeavisideSpace, PiecewiseSegment, dimension, Vec, checkpoints
33

44
@testset "Spaces" begin
55
@testset "PointSpace" begin
@@ -34,6 +34,10 @@ import ApproxFunBase: PointSpace, HeavisideSpace, PiecewiseSegment
3434

3535
S = HeavisideSpace([-1.0,0.0,1.0])
3636
@test Derivative(S) === Derivative(S,1)
37+
38+
a = HeavisideSpace(0:0.25:1)
39+
@test dimension(a) == 4
40+
@test @inferred(points(a)) == 0.125:0.25:0.875
3741
end
3842

3943
@testset "DiracDelta integration and differentiation" begin
@@ -57,4 +61,22 @@ import ApproxFunBase: PointSpace, HeavisideSpace, PiecewiseSegment
5761
@test h(2) == 0.3+1im
5862
@test h(3) == 3.3+1im
5963
end
64+
65+
@testset "Multivariate" begin
66+
a = HeavisideSpace(0:0.25:1)
67+
@test @inferred(dimension(a^2)) == dimension(a)^2
68+
@test @inferred(domain(a^2)) == domain(a)^2
69+
@test @inferred(points(a^2)) == vec(Vec.(points(a), points(a)'))
70+
@test @inferred(checkpoints(a^2)) == vec(Vec.(checkpoints(a)', checkpoints(a)))
71+
72+
aa2 = TensorSpace(a , a^2)
73+
@test dimension(aa2) == dimension(a)^3
74+
@test @inferred(domain(aa2)) == domain(a)^3
75+
@test @inferred(points(aa2)) == vec(Vec.(points(a), points(a)', reshape(points(a), 1,1,4)))
76+
@test @inferred(checkpoints(aa2)) == vec(Vec.(reshape(checkpoints(a), 1,1,length(checkpoints(a))), checkpoints(a)', checkpoints(a)))
77+
78+
@test dimension(a^3) == dimension(a)^3
79+
@test @inferred(domain(a^3)) == domain(a)^3
80+
@test_broken @inferred(points(a^3)) == vec(Vec.(points(a), points(a)', reshape(points(a), 1,1,4)))
81+
end
6082
end

0 commit comments

Comments
 (0)