Skip to content

Commit

Permalink
backports for Interlace bandwidth, ArraySpace show and ProductFun (#558)
Browse files Browse the repository at this point in the history
* backports for Interlace bandwidth, ArraySpace show and ProductFun

* Bump version to v0.8.53
  • Loading branch information
jishnub authored Aug 11, 2023
1 parent 7439f42 commit 9aa84c0
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunBase"
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
version = "0.8.52"
version = "0.8.53"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
2 changes: 1 addition & 1 deletion src/Multivariate/ProductFun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function coefficients(f::ProductFun, ox::Space, oy::Space)
# convert in x direction
#TODO: adaptively grow in x?
for k=1:length(f.coefficients)
B[:,k] = pad(coefficients(f.coefficients[k],ox), m)
copyto!(@view(B[:,k]), coefficients(f.coefficients[k],ox))
end

sp = space(f)
Expand Down
4 changes: 3 additions & 1 deletion src/Multivariate/TensorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ factor(d::AbstractProductSpace,k) = factors(d)[k]
# would be Tensorizer((Ones{Int}(∞), Fill(2,∞)))


struct Tensorizer{DMS<:Tuple}
struct Tensorizer{DMS<:Tuple{Vararg{AbstractVector{Int}}}}
blocks::DMS
end

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

show(io::IO, t::Tensorizer) = print(io, Tensorizer, "(", t.blocks, ")")

eltype(::Type{<:Tensorizer{<:Tuple{Vararg{Any,N}}}}) where {N} = NTuple{N,Int}
dimensions(a::Tensorizer) = map(sum,a.blocks)
length(a::Tensorizer) = reduce(*, dimensions(a)) # easier type-inference than mapreduce
Expand Down
8 changes: 4 additions & 4 deletions src/Operators/SubOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,18 @@ end


function mul_coefficients(A::SubOperator{<:Any,<:Any,NTuple{2,UnitRange{Int}}}, b)
if size(A,2) == length(b)
if size(A,2) == size(b,1)
AbstractMatrix(A)*b
else
AbstractMatrix(view(A,:,1:length(b)))*b
AbstractMatrix(view(A,:,axes(b,1)))*b
end
end
function mul_coefficients!(A::SubOperator{<:Any,<:Any,NTuple{2,UnitRange{Int}}}, b,
temp = similar(b, promote_type(eltype(A), eltype(b)), size(A,1)))
if size(A,2) == length(b)
if size(A,2) == size(b,1)
mul!(temp, AbstractMatrix(A), b)
else
mul!(temp, AbstractMatrix(view(A,:,1:length(b))), b)
mul!(temp, AbstractMatrix(view(A,:,axes(b,1))), b)
end
b .= temp
return b
Expand Down
2 changes: 1 addition & 1 deletion src/Operators/functionals/Evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ _eval(f, x) = f(x)
_eval(f, x::SpecialEvalPtType) = boundaryevalfn(x)(f)
function getindex(D::ConcreteEvaluation,k::Integer)
T = prectype(domainspace(D))
f = Fun(D.space, [zeros(T,k-1); one(T)])
f = D.space(k-1)
df = differentiate(f,D.order)
v = _eval(df, D.x)
strictconvert(eltype(D), v)
Expand Down
4 changes: 2 additions & 2 deletions src/Operators/general/InterlaceOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ end
# special case for example
l,u = max(bandwidth(ops[1],1),bandwidth(ops[2],1)-1),bandwidth(ops[2],2)+1
else
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
l,u = (dimension(rs)-1,dimension(ds)-1) # not banded
end

l,u
Expand Down Expand Up @@ -171,7 +171,7 @@ end
u = max(u, p*opbw[2]+1-k)
end
else
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
l,u = (dimension(rs)-1,dimension(ds)-1) # not banded
end
l,u
end
Expand Down
17 changes: 9 additions & 8 deletions src/Spaces/SubSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SubSpace(sp::SubSpace,kr) = SubSpace(sp.space,reindex(sp,sp.indexes,to_indexes(k
domain(DS::SubSpace) = domain(DS.space)
dimension(sp::SubSpace) = length(sp.indexes)

|(sp::Space,kr::AbstractRange) = SubSpace(sp,kr)
|(sp::Space, kr) = SubSpace(sp,kr)


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

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

function blocklengths(sp::SubSpace{DS,<:AbstractInfUnitRange{Int}}) where DS
N = first(sp.indexes)
B1=block(sp.space,N)
B1 = block(sp.space,N)

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

Expand Down
15 changes: 2 additions & 13 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ function show(io::IO, f::Fun)
print(io,")")
end

evalconst(f, ::AnyDomain) = f(0.0)
evalconst(f, d) = f(leftendpoint(d))
evalconst(f, d::Union{Point, UnionDomain{<:Any, <:Tuple{Point, Vararg{Point}}}}) = f(d)

function show(io::IO,f::Fun{<:Union{ConstantSpace, ArraySpace{<:ConstantSpace}}})
d = domain(f)
print(io, evalconst(f, domain(f)))
print(io, d isa AnyDomain ? " anywhere" : " on " * string(d))
end

## MultivariateFun

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

summarystr(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")
summary(io::IO, ss::ArraySpace) = print(io, summarystr(ss))
function show(io::IO,ss::ArraySpace;header::Bool=true)
header && print(io,summarystr(ss)*":\n")
show(io, ss.spaces)
function show(io::IO, ss::ArraySpace; header::Bool=true)
print(io, ArraySpace, "(", ss.spaces, ")")
end

function show(io::IO,s::TensorSpace)
Expand Down
11 changes: 11 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
@test contains(rpr, "PiecewiseSpace")
@test contains(rpr, repr(p))
end
@testset "ArraySpace" begin
spaces = [PointSpace(1:1), PointSpace(2:2)]
A = ApproxFunBase.ArraySpace(spaces)
@test startswith(repr(A), "$(ApproxFunBase.ArraySpace)")
@test contains(repr(A), repr(spaces))
end
end
@testset "Fun" begin
f = Fun(PointSpace(1:3), [1,2,3])
Expand Down Expand Up @@ -93,4 +99,9 @@
C = cache(B)
@test contains(repr(C), "Cached " * repr(B))
end
@testset "Tensorizer" begin
o = Ones(Int,ℵ₀)
t = ApproxFunBase.Tensorizer((o,o))
@test repr(t) == "ApproxFunBase.Tensorizer($((o,o)))"
end
end

2 comments on commit 9aa84c0

@jishnub
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/89429

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.53 -m "<description of version>" 9aa84c07309ae039801c1d2059bf2673c901a62b
git push origin v0.8.53

Please sign in to comment.