I would like to subclass the tf.Tensor
class. The idea is that the objects of subclasses should behave like Tensors (i.e. I can use them to make any kind of tf operations) but they should also possess others attributes which provide them specific behaviors inside my framework.
Up to now, I worked in Graph mode and I simply do something like this:
class EnrichedTensor(tf.Tensor):
def __init__(self, tensor, other_stuff):
super(EnrichedTensor, self).__init__((
op=tensor.op,
value_index=tensor.value_index,
dtype=tensor.dtype)
self.other_stuff = other_stuff
Now, I would like to do the same to work only in eager mode, but I really don't know (and I didn't find anything) about EagerTensor
instantiation. Obviously, the op
attribute does not make sense anymore.
I tried to work on the creation of the object through the __new__
method but I found problems in subclassing my EnrichedTensor
and following the creation path.
So, I was wondering if is there any way to do this cleanly and in a "sound" way.