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

Allow tensors of rank 0 to represent scalars #21

Open
snunezcr opened this issue Jun 25, 2020 · 2 comments
Open

Allow tensors of rank 0 to represent scalars #21

snunezcr opened this issue Jun 25, 2020 · 2 comments

Comments

@snunezcr
Copy link

It would be highly beneficial for tensor calculus applications, and higher generality, to include the case of a rank 0 tensor. This is of particular usefulness for scientific codes to avoid adding special cases.

@Qqwy
Copy link
Owner

Qqwy commented Jun 25, 2020

This is a great suggestion! I have been using the Haskell array-computation library 'Accelerate' for a couple of months for a project now, and they use rank 0 tensors in very much the same way.

However, adding this to the library as-is would be a major breaking change, since a lot of the functionality expects e.g. to return a bare inner value. That said, Tensor is now multiple years old and there are definitely other things about the API that could be improved for a hypothetical v 2.0.

What kind of behaviour would you like to see exactly for rank-0 tensors? What is your opinion on how 'simple' values should be converted to- and from rank-0 tensors?

@snunezcr
Copy link
Author

Thanks for writing back! After looking at your code, I understand why this is a major change.

Regarding behavior, the following behavior should be great:

  • another constructor new(scalar) that is very similar to the empty constructor
  • a module Scalar with similar delegation of functions to Tensor
  • a way to operate with Scalars without extracting their value until it is required within regular arithmetic operations

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

No branches or pull requests

2 participants