New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lens for typed tensor #523
Conversation
Hi, looks interesting. I don’t understand what TensorData is good for. Can you explain this differently, please? |
The problem with roots is that the typed tensor doesn't specify a structure. Both tensor expressions are
These two definition are often used. It is also used in detr. |
I see now. In that case, why don't we make it so that a
What do you think? |
The idea is great, because it can support tensor's permutations. https://github.com/jasigal/hasktorch-naperian/blob/master/src/Torch/Naperian.hs#L74-L76 I don't understand how to use '[]' and '(,)' with heterogeneous lists. When there is
|
I suppose we'd need some sized list for that. Tensor device dtype '[ Sized [] 4, Sized [] 64, Sized [] 16, Sized [] 16]
Tensor device dtype '[ Sized [] 4, RGB, Sized [] 16, Sized [] 16] and so on, where newtype Sized (f :: * -> *) (n :: Nat) a = Sized (f a) So |
or, perhaps, a data family that makes the data type construction inductive: data family List (n :: Natural) a
data instance List 'Z a = Empty
data instance List ('S n) a = a ::: !(List n a) |
Thx! |
Yes, let's try your thing. |
Seems lenses be a generalization of Sasha's namedtensors http://nlp.seas.harvard.edu/NamedTensor? One difference is there names refer to dimensions and here they refer to values (I think, I still have difficulty reading generics code). One potential footgun is if users access tensor values both by indexing and lenses. If they were to insert a field or otherwise change the field ordering, that could break code in weird / silent ways. Can you include an example that shows the RGB usage? I'm a little unclear where/when the tensor gets initialized and how the ADT data gets bound to tensor values. |
Yes. The lens is like namedtensors with fields.
I think the footgun depends on the definition of shapes.
Here is an example of converting from RGB to YCoCg. An example with lens.
An example without lens.
For now, this PR does not include the initialization of the tensor, but we can get the initializer by making the tensor an instance of monoid with zeros-function. |
I've realized sized-vector is not a instance of Generics. |
This PR feature is reimplemented as follows. |
This PR provides embed tensor having fields and its lens.
For example, when we defines RGB data as follows,
the type of the embed tensor is
TensorData device dtype shape RGB
,and internal data of the embed tensor becomes
Tensor device dtype (shape ++ [3])
.Then the lens (e.g. field @"r" or field @"g" ) provides both setter and getter for each RGB field.