elixir-tensor icon indicating copy to clipboard operation
elixir-tensor copied to clipboard

Allow tensors of rank 0 to represent scalars

Open snunezcr opened this issue 5 years ago • 2 comments

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.

snunezcr avatar Jun 25 '20 15:06 snunezcr

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?

Qqwy avatar Jun 25 '20 16:06 Qqwy

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

snunezcr avatar Jun 25 '20 17:06 snunezcr