Open adler-j opened 8 years ago
This is definitely useful. "Coerce" is more of a computer science notion AFAIK, this makes sense if changing only data type within the same "family", or changing implementation. In math one would rather speak of an embedding.
From the discussion in #49 i found another case:
FnBase
spaces (possibly only of the same kind) as a single space:
ProductSpace(Rn(3), Rn(2)) <--> Rn(5)
this would solve many of the problems in #49 aswell.Suggested programming of this:
operator
, call it coercion
or embedding
if we prefer that. (@ozanoktem ?)coerce
/embed
"entry point" function, so users can call>>> embed(Rn(10), CudaRn(10))
FnBaseEmbedding(Rn(10), CudaRn(10))
>>> embed(uniform_discr(FunctionSpace(Interval(0, 3.1415)), 10),
uniform_discr(FunctionSpace(Interval(0, 1)), 10))
USpaceEmbedding(uniform_discr(FunctionSpace(Interval(0, 3.1415)), 10),
uniform_discr(FunctionSpace(Interval(0, 1)), 10))
etc...
Followup, it seems coerce
is already taken, embed
it is then!
There are many cases in mathematics where a user "inteprets an X as an Y", often very subtly or unstated. Nonetheless, this needs to be made explicit at times. Some examples in odl include
FnBase
details,Rn(10)
asCudaRn(10)
Rn(10)
as `Rn(10, dtype='float32')ProductSpace(X, 1)
as inX
, or the inverse of thisuniform_discr(FunctionSpace(Interval(0, 1)), 10)
asuniform_discr(FunctionSpace(Interval(0, 3.1415)), 10)
Discretization
according to the aboveTo solve this we should implement some kind of
CoerceOperator
, example below for most simpleFnBase
case