-
Notifications
You must be signed in to change notification settings - Fork 7
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 Indexing, Slicing, Joining, Mutating Ops #35
Conversation
Apparently the complement-property testing was broken, which is useful to test if the tensor dtypes in tensor operations are narrowed just enough, but not too much. With this change the generator can generate all the DTypes (which is useful for complement-property testing) or filter them if you want to do just property testing
Quick update!
|
Oh wow the examples in the docs are being compiled, that's awesome! will work on fixing them later today |
- Add documentation - Add tests - Improve some implementations to handle more scenarios
Looks great, thank you!
I think more deeply nested seqs are quite rare, so I agree this is fine. If we want to support this in a more generic way at some point, perhaps https://maximekjaer.github.io/tf-dotty/ is worth a look.
Good point. I actually had the same thought a while ago. We need to ensure that the tuple only contains ints, though. One idea is to either have something like
Yeah apologies, I need to include that in the contributor docs. You can also run |
I was hoping to have mdoc like output rendering in Scaladoc as well, but that's not supported yet. But having compilation errors checked is already helpful. |
Awesome, thanks for reviewing and merging it!
Good idea, will do! After building some more complex models, I realized the pain for named tensors/shape checking, so will take a look at that repo, and also some other resources I've found. Here is a compiled list of them:
Would love to see that discussion. After some exploration, chatgpt prompts, and bouncing this with some friends, here are two solutions that are usable to guarantee a Tuple only has Ints (a bit more work needs to be done to get it to work with generic types, such as a union type like
@ def createTensor[T <: Tuple](tup: T)(using Tuple.Union[T] <:< Int) = tup.toList
defined function createTensor
@ createTensor((1,2,3))
res97: List[Int] = List(1, 2, 3)
@ createTensor((1,2,"3"))
-- [E172] Type Error: cmd98.sc:1:33 --------------------------------------------
1 |val res99 = createTensor((1,2,"3"))
| ^
| Cannot prove that Tuple.Union[(Int, Int, String)] <:< Int.
Compilation Failed
@ type IntTuple[T <: Tuple] = T match
case Int *: t => IntTuple[t]
case EmptyTuple => DummyImplicit
defined type IntTuple
@ def createTensor[T <: Tuple](tup: T)(using IntTuple[T]) = tup.toList
defined function createTensor
@ createTensor(1,2,3)
res101: List[Int] = List(1, 2, 3)
@ createTensor(1,2,"3")
-- Error: cmd102.sc:1:25 -------------------------------------------------------
1 |val res102 = createTensor(1,2,"3")
| ^
| Match type reduction failed since selector String *: EmptyTuple.type
| matches none of the cases
|
| case Int *: t => ammonite.$sess.cmd99.IntTuple[t]
| case EmptyTuple => DummyImplicit
Compilation Failed |
Interesting. I did not know the I found the discussion. After some ideas, I found a working solution, similar to yours above: type HomogeneousTuple[T <: Tuple, U] = T match
case EmptyTuple => EmptyTuple
case _ *: t => U *: IntTuple[t]
type IntTuple[T <: Tuple] = HomogeneousTuple[T, Int]
def f[T <: Tuple](x: T)(using T =:= IntTuple[T]) = x
f(1,2,3) // Tuple3[Int, Int, Int] = (1,2,3)
f(1,"a") // Cannot prove that (Int, String) =:= IntTuple[(Int, String)] And then people improved upon it: type ContainsOnly[U] = [T] =>> T <:< HomogeneousTuple[T, U]
def f[T: ContainsOnly[Int]](x: T) = x Someone proposed a very consice version via type ContainsOnly[U] = [T <: Tuple] =>> T <:< Tuple.Map[T, [X] =>> Int] |
Implement more Indexing, Slicing, Joining, Mutating Ops from https://pytorch.org/docs/stable/torch.html#indexing-slicing-joining-mutating-ops
TODO
Int | Seq(Int)
for some operationsFor later work on a separate PR:
indexReduce
andscatterReduce
- perhaps as an Enum?scatter
ops