Skip to content

Commit e4bfbeb

Browse files
authored
optimize sort for tuples of spaces (#322)
* optimize sort for tuples of spaces * Add tests
1 parent fbd993e commit e4bfbeb

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/Spaces/SumSpace.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,9 @@ function spacescompatible(A::Tuple,B::Tuple)
172172
return false
173173
end
174174
#assumes domain doesn't impact sorting
175-
asort=sort(collect(A));bsort=sort(collect(B))
176-
for k=1:length(asort)
177-
if !spacescompatible(asort[k],bsort[k])
178-
return false
179-
end
180-
end
181-
182-
return true
175+
asort=sort(SVector(A))
176+
bsort=sort(SVector(B))
177+
all(((x,y),) -> spacescompatible(x,y), zip(asort, bsort))
183178
end
184179

185180

src/show.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,17 @@ end
157157

158158
function show(io::IO,ss::PiecewiseSpace)
159159
s = components(ss)
160+
if length(s) == 1
161+
print(io, "PiecewiseSpace(")
162+
end
160163
show(io,s[1])
161164
for sp in s[2:end]
162165
print(io,"")
163166
show(io,sp)
164167
end
168+
if length(s) == 1
169+
print(io, ")")
170+
end
165171
end
166172

167173
summarystr(ss::ArraySpace) = string(Base.dims2string(length.(axes(ss))), " ArraySpace")

test/SpacesTest.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ using LinearAlgebra
263263
@testset "spacescompatible for TensorSpace" begin
264264
a = PointSpace(1:4)^2
265265
@test ApproxFunBase.spacescompatible(a, a)
266+
@test ApproxFunBase.spacescompatible((a, a))
267+
@test ApproxFunBase.spacescompatible((a, a), (a, a))
266268
b = PointSpace(1:4) PointSpace(1:3)
267269
@test !ApproxFunBase.spacescompatible(a, b)
268270
@test a == a

test/show.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
@test length(v) == 2
2929
@test all(==(repr(S1)), v)
3030
end
31+
@testset "PiecewiseSpace" begin
32+
p = PointSpace(1:4)
33+
ps = PiecewiseSpace(p)
34+
rpr = repr(ps)
35+
@test contains(rpr, "PiecewiseSpace")
36+
@test contains(rpr, repr(p))
37+
end
3138
end
3239
@testset "Fun" begin
3340
f = Fun(PointSpace(1:3), [1,2,3])

0 commit comments

Comments
 (0)