Skip to content

Commit 70cd5d2

Browse files
authored
Bandwidths tuple in view (#368)
1 parent 7157ab6 commit 70cd5d2

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
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.7.67"
3+
version = "0.7.68"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -41,6 +41,7 @@ FFTW = "0.3, 1"
4141
FillArrays = "0.11, 0.12, 0.13"
4242
InfiniteArrays = "0.11, 0.12"
4343
InfiniteLinearAlgebra = "0.5, 0.6"
44+
Infinities = "0.1"
4445
IntervalSets = "0.5, 0.6, 0.7"
4546
LazyArrays = "0.20, 0.21, 0.22"
4647
LowRankApprox = "0.2, 0.3, 0.4, 0.5"
@@ -50,7 +51,8 @@ julia = "1.6"
5051

5152
[extras]
5253
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
54+
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
5355
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
5456

5557
[targets]
56-
test = ["Aqua", "Random"]
58+
test = ["Aqua", "Random", "Infinities"]

src/Operators/SubOperator.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ function view(A::Operator,kr::InfRanges,jr::InfRanges)
8787
if isbanded(A) && st==step(jr) # Otherwise, its not a banded operator
8888
kr1=first(kr)
8989
jr1=first(jr)
90-
l,u=(bandwidth(A,1)+jr1-kr1)÷st,(bandwidth(A,2)+kr1-jr1)÷st
90+
shft = kr1-jr1
91+
# working on the whole bandwidths tuple instead of
92+
# the individual bandwidths helps with type-inference,
93+
# e.g. if the bandwidth is inferred as
94+
# Union{NTuple{2,InfiniteCardinal{0}}, NTuple{2,Int}}
95+
bw = map(x -> x ÷ st, map(+, bandwidths(A), (-shft,shft)))
9196
else
92-
l,u=ℵ₀,ℵ₀
97+
bw=(ℵ₀,ℵ₀)
9398
end
94-
SubOperator(A,(kr,jr),size(A),(l,u))
99+
SubOperator(A,(kr,jr),size(A),bw)
95100
end
96101

97102
view(V::SubOperator, kr::AbstractRange, jr::AbstractRange) =
@@ -102,8 +107,13 @@ function view(A::Operator, kr::AbstractRange, jr::AbstractRange)
102107
if isbanded(A) && st == step(jr)
103108
kr1=first(kr)
104109
jr1=first(jr)
105-
l,u=(bandwidth(A,1)+jr1-kr1)÷st,(bandwidth(A,2)+kr1-jr1)÷st
106-
SubOperator(A,(kr,jr),(length(kr),length(jr)),(l,u))
110+
shft = kr1-jr1
111+
# working on the whole bandwidths tuple instead of
112+
# the individual bandwidths helps with type-inference,
113+
# e.g. if the bandwidth is inferred as
114+
# Union{NTuple{2,InfiniteCardinal{0}}, NTuple{2,Int}}
115+
bw = map(x -> x ÷ st, map(+, bandwidths(A), (-shft,shft)))
116+
SubOperator(A,(kr,jr),(length(kr),length(jr)),bw)
107117
else
108118
SubOperator(A,(kr,jr))
109119
end
@@ -113,8 +123,12 @@ end
113123
function view(A::Operator,kr::UnitRange,jr::UnitRange)
114124
if isbanded(A)
115125
shft=first(kr)-first(jr)
116-
l,u=bandwidth(A,1)-shft,bandwidth(A,2)+shft
117-
SubOperator(A,(kr,jr),(length(kr),length(jr)),(l,u))
126+
# working on the whole bandwidths tuple instead of
127+
# the individual bandwidths helps with type-inference,
128+
# e.g. if the bandwidth is inferred as
129+
# Union{NTuple{2,InfiniteCardinal{0}}, NTuple{2,Int}}
130+
bw = map(+, bandwidths(A), (-shft,shft))
131+
SubOperator(A,(kr,jr),(length(kr),length(jr)),bw)
118132
else
119133
SubOperator(A,(kr,jr))
120134
end

test/runtests.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
using ApproxFunBase, LinearAlgebra, Random, Test
1+
using ApproxFunBase
22
using ApproxFunBase:
33
using Aqua
4-
using SpecialFunctions
54
using BandedMatrices
5+
using DomainSets
66
using FillArrays
7+
using InfiniteArrays
8+
using Infinities
9+
using LinearAlgebra
10+
using Random
11+
using SpecialFunctions
12+
using Test
713

814
@testset "Project quality" begin
915
Aqua.test_all(ApproxFunBase, ambiguities=false)
@@ -474,6 +480,17 @@ end
474480
A = @inferred ApproxFunBase.SymToeplitzOperator(Int[])
475481
B = A[1:5, 1:5]
476482
@test all(iszero, B)
483+
484+
@testset "kronecker type stability" begin
485+
T = ApproxFunBase.ToeplitzOperator(Float64[1,2], Float64[1,2])
486+
TT = T T
487+
TypeExp = Union{ApproxFunBase.SubOperator{Float64, KroneckerOperator{ToeplitzOperator{Float64}, ToeplitzOperator{Float64}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, Float64}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, Tuple{Int64, Int64}, Tuple{Infinities.InfiniteCardinal{0}, Infinities.InfiniteCardinal{0}}}, ApproxFunBase.SubOperator{Float64, KroneckerOperator{ToeplitzOperator{Float64}, ToeplitzOperator{Float64}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, Float64}, Tuple{UnitRange{Int64}, UnitRange{Int64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}}}
488+
@inferred TypeExp view(T, 1:1, 1:1)
489+
TypeExp2 = Union{ApproxFunBase.SubOperator{Float64, KroneckerOperator{ToeplitzOperator{Float64}, ToeplitzOperator{Float64}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, Float64}, Tuple{StepRange{Int64, Int64}, StepRange{Int64, Int64}}, Tuple{Int64, Int64}, Tuple{Infinities.InfiniteCardinal{0}, Infinities.InfiniteCardinal{0}}}, ApproxFunBase.SubOperator{Float64, KroneckerOperator{ToeplitzOperator{Float64}, ToeplitzOperator{Float64}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, FillArrays.Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, Float64}, Tuple{StepRange{Int64, Int64}, StepRange{Int64, Int64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}}}
490+
@inferred TypeExp2 view(T, 1:1:1, 1:1:1)
491+
TypeExp3 = Union{ApproxFunBase.SubOperator{Float64, KroneckerOperator{ToeplitzOperator{Float64}, ToeplitzOperator{Float64}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, Float64}, Tuple{InfiniteArrays.InfUnitRange{Int64}, InfiniteArrays.InfUnitRange{Int64}}, Tuple{Infinities.Infinity, Infinities.Infinity}, Tuple{Infinities.InfiniteCardinal{0}, Infinities.InfiniteCardinal{0}}}, ApproxFunBase.SubOperator{Float64, KroneckerOperator{ToeplitzOperator{Float64}, ToeplitzOperator{Float64}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, TensorSpace{Tuple{SequenceSpace, SequenceSpace}, DomainSets.VcatDomain{2, Int64, (1, 1), Tuple{ApproxFunBase.PositiveIntegers, ApproxFunBase.PositiveIntegers}}, Union{}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, ApproxFunBase.CachedIterator{Tuple{Int64, Int64}, ApproxFunBase.Tensorizer{Tuple{Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}, Ones{Int64, 1, Tuple{InfiniteArrays.OneToInf{Int64}}}}}}, Float64}, Tuple{InfiniteArrays.InfUnitRange{Int64}, InfiniteArrays.InfUnitRange{Int64}}, Tuple{Infinities.Infinity, Infinities.Infinity}, Tuple{Int64, Int64}}}
492+
@inferred TypeExp3 view(T, 1:∞, 1:∞)
493+
end
477494
end
478495

479496
@testset "Tensorizer" begin

0 commit comments

Comments
 (0)