Skip to content

Commit fe3c9c2

Browse files
authored
Update ProductSpace constructors with promote/convert (#112)
* Update ProductSpace constructors for more flexibility * Fix test productspace errortype * Fix missing Productspace constructor
1 parent 00cc31c commit fe3c9c2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/spaces/productspace.jl

+19-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,30 @@ ProductSpace{S}(spaces::Vararg{S}) where {S<:ElementarySpace} = ProductSpace{S}(
2222
function ProductSpace(spaces::Tuple{S,Vararg{S}}) where {S<:ElementarySpace}
2323
return ProductSpace{S,length(spaces)}(spaces)
2424
end
25-
function ProductSpace(space1::S, rspaces::Vararg{S}) where {S<:ElementarySpace}
25+
function ProductSpace(space1::ElementarySpace, rspaces::Vararg{ElementarySpace})
2626
return ProductSpace((space1, rspaces...))
2727
end
2828

2929
ProductSpace(P::ProductSpace) = P
3030

31+
# constructors with conversion behaviour
32+
function ProductSpace{S,N}(V::Vararg{ElementarySpace,N}) where {S<:ElementarySpace,N}
33+
return ProductSpace{S,N}(V)
34+
end
35+
function ProductSpace{S}(V::Vararg{ElementarySpace}) where {S<:ElementarySpace}
36+
return ProductSpace{S}(V)
37+
end
38+
39+
function ProductSpace{S,N}(V::Tuple{Vararg{ElementarySpace,N}}) where {S<:ElementarySpace,N}
40+
return ProductSpace{S}(convert.(S, V))
41+
end
42+
function ProductSpace{S}(V::Tuple{Vararg{ElementarySpace}}) where {S<:ElementarySpace}
43+
return ProductSpace{S}(convert.(S, V))
44+
end
45+
function ProductSpace(V::Tuple{ElementarySpace,Vararg{ElementarySpace}})
46+
return ProductSpace(promote(V...))
47+
end
48+
3149
# Corresponding methods
3250
#-----------------------
3351
"""

test/spaces.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ println("------------------------------------")
122122
# promote_except = ErrorException("promotion of types $(typeof(ℝ^d)) and " *
123123
# "$(typeof(ℂ^d)) failed to change any arguments")
124124
# @test_throws promote_except (⊕(ℝ^d, ℂ^d))
125-
@test_throws MethodError ((ℝ^d, ℂ^d))
125+
@test_throws ErrorException ((ℝ^d, ℂ^d))
126126
@test @constinferred((V, V)) ==^(2d)
127127
@test @constinferred((V, oneunit(V))) ==^(d + 1)
128128
@test @constinferred((V, V, V, V)) ==^(4d)

0 commit comments

Comments
 (0)