Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Conversation

@marcelluethi
Copy link
Owner

Add a value type parameter to Tensor and factory methods to create a tensor.

A Float32 Tensor is created using the following pattern

val t : Tensor1[A, Float32] = Tensor.of[Float32].ones(Shape(Axis[A]->3)

and a custom type can be created using

trait Y
object Y extends Value.As[Y, Float32]
val t : Tensor1[A, Y] = Tensor.of[Y].ones(Shape(Axis[A]->3)

Note that for arithmetic operations the Value type needs to correspond. The following gives a type error

Tensor0.of[Int32](3)+Tensor0.of[Float32](3f)

Instead an explicit type cast ist needed

Tensor0.of[Int32](3)+Tensor0.of[Float32](3f).asType[Int32]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants