Skip to content

Commit 9aa84c0

Browse files
authored
backports for Interlace bandwidth, ArraySpace show and ProductFun (#558)
* backports for Interlace bandwidth, ArraySpace show and ProductFun * Bump version to v0.8.53
1 parent 7439f42 commit 9aa84c0

File tree

9 files changed

+34
-31
lines changed

9 files changed

+34
-31
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.8.52"
3+
version = "0.8.53"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Multivariate/ProductFun.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function coefficients(f::ProductFun, ox::Space, oy::Space)
255255
# convert in x direction
256256
#TODO: adaptively grow in x?
257257
for k=1:length(f.coefficients)
258-
B[:,k] = pad(coefficients(f.coefficients[k],ox), m)
258+
copyto!(@view(B[:,k]), coefficients(f.coefficients[k],ox))
259259
end
260260

261261
sp = space(f)

src/Multivariate/TensorSpace.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ factor(d::AbstractProductSpace,k) = factors(d)[k]
2424
# would be Tensorizer((Ones{Int}(∞), Fill(2,∞)))
2525

2626

27-
struct Tensorizer{DMS<:Tuple}
27+
struct Tensorizer{DMS<:Tuple{Vararg{AbstractVector{Int}}}}
2828
blocks::DMS
2929
end
3030

3131
const InfOnes = Ones{Int,1,Tuple{OneToInf{Int}}}
3232
const Tensorizer2D{AA, BB} = Tensorizer{Tuple{AA, BB}}
3333
const TrivialTensorizer{d} = Tensorizer{NTuple{d,InfOnes}}
3434

35+
show(io::IO, t::Tensorizer) = print(io, Tensorizer, "(", t.blocks, ")")
36+
3537
eltype(::Type{<:Tensorizer{<:Tuple{Vararg{Any,N}}}}) where {N} = NTuple{N,Int}
3638
dimensions(a::Tensorizer) = map(sum,a.blocks)
3739
length(a::Tensorizer) = reduce(*, dimensions(a)) # easier type-inference than mapreduce

src/Operators/SubOperator.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,18 +378,18 @@ end
378378

379379

380380
function mul_coefficients(A::SubOperator{<:Any,<:Any,NTuple{2,UnitRange{Int}}}, b)
381-
if size(A,2) == length(b)
381+
if size(A,2) == size(b,1)
382382
AbstractMatrix(A)*b
383383
else
384-
AbstractMatrix(view(A,:,1:length(b)))*b
384+
AbstractMatrix(view(A,:,axes(b,1)))*b
385385
end
386386
end
387387
function mul_coefficients!(A::SubOperator{<:Any,<:Any,NTuple{2,UnitRange{Int}}}, b,
388388
temp = similar(b, promote_type(eltype(A), eltype(b)), size(A,1)))
389-
if size(A,2) == length(b)
389+
if size(A,2) == size(b,1)
390390
mul!(temp, AbstractMatrix(A), b)
391391
else
392-
mul!(temp, AbstractMatrix(view(A,:,1:length(b))), b)
392+
mul!(temp, AbstractMatrix(view(A,:,axes(b,1))), b)
393393
end
394394
b .= temp
395395
return b

src/Operators/functionals/Evaluation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ _eval(f, x) = f(x)
8181
_eval(f, x::SpecialEvalPtType) = boundaryevalfn(x)(f)
8282
function getindex(D::ConcreteEvaluation,k::Integer)
8383
T = prectype(domainspace(D))
84-
f = Fun(D.space, [zeros(T,k-1); one(T)])
84+
f = D.space(k-1)
8585
df = differentiate(f,D.order)
8686
v = _eval(df, D.x)
8787
strictconvert(eltype(D), v)

src/Operators/general/InterlaceOperator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ end
134134
# special case for example
135135
l,u = max(bandwidth(ops[1],1),bandwidth(ops[2],1)-1),bandwidth(ops[2],2)+1
136136
else
137-
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
137+
l,u = (dimension(rs)-1,dimension(ds)-1) # not banded
138138
end
139139

140140
l,u
@@ -171,7 +171,7 @@ end
171171
u = max(u, p*opbw[2]+1-k)
172172
end
173173
else
174-
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
174+
l,u = (dimension(rs)-1,dimension(ds)-1) # not banded
175175
end
176176
l,u
177177
end

src/Spaces/SubSpace.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SubSpace(sp::SubSpace,kr) = SubSpace(sp.space,reindex(sp,sp.indexes,to_indexes(k
1313
domain(DS::SubSpace) = domain(DS.space)
1414
dimension(sp::SubSpace) = length(sp.indexes)
1515

16-
|(sp::Space,kr::AbstractRange) = SubSpace(sp,kr)
16+
|(sp::Space, kr) = SubSpace(sp,kr)
1717

1818

1919
function |(f::Fun,kr::AbstractInfUnitRange)
@@ -26,21 +26,22 @@ block(sp::SubSpace, k::Integer) = block(sp.space,reindex(sp,(sp.indexes,),(k,))[
2626
function blocklengths(sp::SubSpace{DS,UnitRange{Int}}) where DS
2727
N = first(sp.indexes)
2828
M = last(sp.indexes)
29-
B1=block(sp.space,N)
30-
B2=block(sp.space,M)
29+
B1 = block(sp.space,N)
30+
B2 = block(sp.space,M)
3131
# if the blocks are equal, we have only one bvlock
32-
B1 == B2 && return [zeros(Int,B1.n[1]-1);length(sp.indexes)]
32+
B1 == B2 && return [Zeros{Int}(B1.n[1]-1); length(sp.indexes)]
3333

34-
[zeros(Int,B1.n[1]-1);
35-
blockstop(sp.space,B1)-N+1;blocklengths(sp.space)[B1.n[1]+1:B2.n[1]-1];
34+
[Zeros{Int}(B1.n[1]-1);
35+
blockstop(sp.space,B1)-N+1;
36+
blocklengths(sp.space)[B1.n[1]+1:B2.n[1]-1];
3637
M-blockstart(sp.space,B2)+1]
3738
end
3839

3940
function blocklengths(sp::SubSpace{DS,<:AbstractInfUnitRange{Int}}) where DS
4041
N = first(sp.indexes)
41-
B1=block(sp.space,N)
42+
B1 = block(sp.space,N)
4243

43-
Vcat([zeros(Int,B1.n[1]-1); blockstop(sp.space,B1)-N+1],
44+
Vcat([Zeros{Int}(B1.n[1]-1); blockstop(sp.space,B1)-N+1],
4445
blocklengths(sp.space)[B1.n[1]+1:∞])
4546
end
4647

src/show.jl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ function show(io::IO, f::Fun)
1010
print(io,")")
1111
end
1212

13-
evalconst(f, ::AnyDomain) = f(0.0)
14-
evalconst(f, d) = f(leftendpoint(d))
15-
evalconst(f, d::Union{Point, UnionDomain{<:Any, <:Tuple{Point, Vararg{Point}}}}) = f(d)
16-
17-
function show(io::IO,f::Fun{<:Union{ConstantSpace, ArraySpace{<:ConstantSpace}}})
18-
d = domain(f)
19-
print(io, evalconst(f, domain(f)))
20-
print(io, d isa AnyDomain ? " anywhere" : " on " * string(d))
21-
end
22-
2313
## MultivariateFun
2414

2515
show(io::IO, ::MIME"text/plain", f::MultivariateFun) = show(io, f)
@@ -159,9 +149,8 @@ end
159149

160150
summarystr(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
161151
summary(io::IO, ss::ArraySpace) = print(io, summarystr(ss))
162-
function show(io::IO,ss::ArraySpace;header::Bool=true)
163-
header && print(io,summarystr(ss)*":\n")
164-
show(io, ss.spaces)
152+
function show(io::IO, ss::ArraySpace; header::Bool=true)
153+
print(io, ArraySpace, "(", ss.spaces, ")")
165154
end
166155

167156
function show(io::IO,s::TensorSpace)

test/show.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
@test contains(rpr, "PiecewiseSpace")
3636
@test contains(rpr, repr(p))
3737
end
38+
@testset "ArraySpace" begin
39+
spaces = [PointSpace(1:1), PointSpace(2:2)]
40+
A = ApproxFunBase.ArraySpace(spaces)
41+
@test startswith(repr(A), "$(ApproxFunBase.ArraySpace)")
42+
@test contains(repr(A), repr(spaces))
43+
end
3844
end
3945
@testset "Fun" begin
4046
f = Fun(PointSpace(1:3), [1,2,3])
@@ -93,4 +99,9 @@
9399
C = cache(B)
94100
@test contains(repr(C), "Cached " * repr(B))
95101
end
102+
@testset "Tensorizer" begin
103+
o = Ones(Int,ℵ₀)
104+
t = ApproxFunBase.Tensorizer((o,o))
105+
@test repr(t) == "ApproxFunBase.Tensorizer($((o,o)))"
106+
end
96107
end

0 commit comments

Comments
 (0)