Skip to content

Commit a74f732

Browse files
authored
spacescompatible for tensorspace (#300)
* spacescompatible for tensorspace * fix ntuple signature in maxspace * fix ntuple signature in spacescompatible * Add test * Add incompatible test * fix equality
1 parent d6a43ce commit a74f732

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
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.7.43"
3+
version = "0.7.44"
44

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

src/Multivariate/TensorSpace.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,17 @@ TensorSpace(sp::Tuple) =
303303

304304
dimension(sp::TensorSpace) = mapreduce(dimension,*,sp.spaces)
305305

306-
for OP in (:spacescompatible,:(==))
307-
@eval $OP(A::TensorSpace{SV,D,R},B::TensorSpace{SV,D,R}) where {SV,D,R} =
308-
all(Bool[$OP(A.spaces[k],B.spaces[k]) for k=1:length(A.spaces)])
306+
==(A::TensorSpace{<:NTuple{N,Space}}, B::TensorSpace{<:NTuple{N,Space}}) where {N} =
307+
all(((a,b),) -> a == b, zip(factors(A), factors(B)))
308+
309+
conversion_rule(a::TensorSpace{<:NTuple{2,Space}}, b::TensorSpace{<:NTuple{2,Space}}) =
310+
conversion_type(a.spaces[1],b.spaces[1]) conversion_type(a.spaces[2],b.spaces[2])
311+
312+
maxspace(a::TensorSpace{<:NTuple{2,Space}}, b::TensorSpace{<:NTuple{2,Space}}) =
313+
maxspace(a.spaces[1],b.spaces[1]) maxspace(a.spaces[2],b.spaces[2])
314+
315+
function spacescompatible(A::TensorSpace{<:NTuple{N,Space}}, B::TensorSpace{<:NTuple{N,Space}}) where {N}
316+
all(((a,b),) -> spacescompatible(a,b), zip(factors(A), factors(B)))
309317
end
310318

311319
canonicalspace(T::TensorSpace) = TensorSpace(map(canonicalspace,T.spaces))
@@ -544,7 +552,7 @@ end
544552

545553
fromtensor(S::Space,M::AbstractMatrix) = fromtensor(tensorizer(S),M)
546554
totensor(S::Space,M::AbstractVector) = totensor(tensorizer(S),M)
547-
totensor(SS::TensorSpace{<:NTuple{d}},M::AbstractVector) where {d} =
555+
totensor(SS::TensorSpace{<:NTuple{d}},M::AbstractVector) where {d} =
548556
if d>2; totensoriterator(tensorizer(SS),M) else totensor(tensorizer(SS),M) end
549557

550558
function fromtensor(it::Tensorizer,M::AbstractMatrix)
@@ -570,7 +578,7 @@ function totensor(it::Tensorizer,M::AbstractVector)
570578
ds = dimensions(it)
571579

572580
#ret=zeros(eltype(M),[sum(it.blocks[i][1:min(B.n[1],length(it.blocks[i]))]) for i=1:length(it.blocks)]...)
573-
581+
574582
ret=zeros(eltype(M),sum(it.blocks[1][1:min(B.n[1],length(it.blocks[1]))]),
575583
sum(it.blocks[2][1:min(B.n[1],length(it.blocks[2]))]))
576584

src/PDE/KroneckerOperator.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,6 @@ convert(::Type{BandedBlockBandedMatrix}, S::SubOperator{T,KroneckerOperator{SS,V
384384

385385

386386
## Conversion
387-
388-
389-
390-
391-
conversion_rule(a::TensorSpace,b::TensorSpace) = conversion_type(a.spaces[1],b.spaces[1])conversion_type(a.spaces[2],b.spaces[2])
392-
maxspace(a::TensorSpace,b::TensorSpace) = maxspace(a.spaces[1],b.spaces[1])maxspace(a.spaces[2],b.spaces[2])
393-
394387
# TODO: we explicetly state type to avoid type inference bug in 0.4
395388

396389
ConcreteConversion(a::BivariateSpace,b::BivariateSpace) =

test/SpacesTest.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ using LinearAlgebra
259259
@test domain(@inferred TensorSpace(p)) == d
260260
@test components(domain(@inferred TensorSpace(p, p))) == (d, d)
261261
@test components(domain(@inferred TensorSpace(p, p, p))) == (d, d, d)
262+
263+
@testset "spacescompatible for TensorSpace" begin
264+
a = PointSpace(1:4)^2
265+
@test ApproxFunBase.spacescompatible(a, a)
266+
b = PointSpace(1:4) PointSpace(1:3)
267+
@test !ApproxFunBase.spacescompatible(a, b)
268+
end
262269
end
263270

264271
@testset "ConstantSpace" begin

0 commit comments

Comments
 (0)