Skip to content
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

Typechecked generic tensor? #137

Closed
tholok97 opened this issue Jan 5, 2024 · 1 comment
Closed

Typechecked generic tensor? #137

tholok97 opened this issue Jan 5, 2024 · 1 comment

Comments

@tholok97
Copy link

tholok97 commented Jan 5, 2024

Ref this quote from https://github.com/gorgonia/tensor?tab=readme-ov-file#generic-features:

One could argue that this sidesteps the compiler's type checking system, deferring it to runtime (which a number of people consider dangerous). However, tools are being developed to type check these things, and until Go does support typechecked generics, unfortunately this will be the way it has to be.
Currently, the tensor package supports limited type of genericity - limited to a tensor of any primitive type.

Go does have typechecked generics as of 1.18. I'm sure you've thought more about this than I have, so I'm very curious to hear your thoughts on templating the Tensor interface by T, so you'd write Tensor[float32] for example. It would allow writing functions operating only on float tensors like so: func dostuff[T Float](t Tensor[T]) Tensor[T]. Another consequence would be Apply taking a function of func (v T) T, rather than func (v interface{}) interface{}).

@tholok97
Copy link
Author

Closing this issue after a chat with @chewxy on the Gophers Slack. It is being worked on in the branch https://github.com/gorgonia/tensor/tree/v0.10.0-generics-working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant