tensorics / tensorics-core

The core library of Tensorics - a Java Library for Manipulating Multi-Dimensional Data with Pleasure
http://tensorics.org
Apache License 2.0
10 stars 2 forks source link

Introduce Scalar #19

Closed kaifox closed 7 years ago

kaifox commented 7 years ago

Hi all,

I was hesistating for a long time (since the beginning ;-) if we should introduce a type Scalar into the library. Actually the doubts with this are related to the fact that even in mathematics, the term scalar is used sometimes for (in the langueage of tensorics) the values of a tensor and the a tensor of zero dimension. The term is fuzzy (and we have some leftovers in the code: sometimes S (scalar) is used as a type parameter, sometimes V (value), sometimes E (element).

Long story short: I think it payed off to wait a bit here and learn from others ;-) ... If we look at reactive streams, each of them implements a dedicated object for 'zero or one' (Mono in java nine, Single in RxJava2).... So it seems to make sense.... However, seeing a bit more our use case... one main feature of a scalar object in tensorics is the fact that it still would have a context ... so a big difference wrt processing Scalars (if we would call zero-dimensional tensors like this) compared to bare values would be that they transport the context ... This would come in very handy as soon as scalars are values of reactive streams .(aka onlline-analysis at CERN).. (e.g. one can merge them into tensors etc....)

However, to make this stuff simpler, it seems to be natural to guarantee one more thing compared to Mono/Single, namely that it contains always one element. (This avoids a lot of checking of size()... (like avoiding null checks in java) ... I might be wrong ... still not sure...

In any case for a first iteration, I would propose:

Scalar extends Tensor

with the following features:

So it is basically only a wrapper around a single value, still implementing the tensor interface and having a potentially non-empty context. Therefore it needs no conversion and can be used everywhere a tensor could ...

kaifox commented 7 years ago

Pull request available. Please have a look.

25

kaifox commented 7 years ago

pull request merged into master and released as v0.0.42