odlgroup / odl

Operator Discretization Library https://odlgroup.github.io/odl/
Mozilla Public License 2.0
354 stars 104 forks source link

Coercion operator(s) #59

Open adler-j opened 8 years ago

adler-j commented 8 years ago

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

To solve this we should implement some kind of CoerceOperator, example below for most simple FnBase case

class CoerceOperator(odl.Operator):
    def __init__(self, dom, ran):
        super().__init__(dom, ran, True)

    def _call(self, x):
        return self.ran.element(x.asarray())

    def _apply(self, x, out):
        out[:] = x
kohr-h commented 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.

adler-j commented 8 years ago

From the discussion in #49 i found another case:

adler-j commented 8 years ago

Suggested programming of this:

>>> 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...

adler-j commented 8 years ago

Followup, it seems coerce is already taken, embed it is then!