scijs/ndarray

Idempotent constructor

Opened this issue · 2 comments

Would be nice if ndarray could take any ndarray-ish object and automatically coerce it to an ndarray. For example, if you feed it any object with data,shape,stride,offset properties, it should convert it into an ndarray with the correct interface automatically.

Pros:

  • This would allow for a new pattern where libraries construct ndarrays immediately, thus protecting themselves from possible API breakages and ensuring stability
  • It would also simplify the problem of marshalling ndarrays, since a plain old JS object could be directly converted with this style.
  • It would not break backwards compatibility in any existing ndarray code.

Cons:

  • This is a minor version bump, and would break the promise of freezing the API

In lieu of this, is there a nice clean already-existing way to serialize/deserialize an ndarray? It looks possible to make one with something like typedarray-to-buffer, but I'd rather not if it already exists.