-
Notifications
You must be signed in to change notification settings - Fork 17
NdArray Initializer API #4
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a bunch more documentation, I'm a bit confused by the type hierarchy, and it probably needs building out for the rest of the types before we make a release with it in.
ndarray/src/main/java/org/tensorflow/ndarray/hydrator/DoubleNdArrayHydrator.java
Show resolved
Hide resolved
ndarray/src/main/java/org/tensorflow/ndarray/hydrator/DoubleNdArrayHydrator.java
Show resolved
Hide resolved
ndarray/src/main/java/org/tensorflow/ndarray/hydrator/DoubleNdArrayHydrator.java
Show resolved
Hide resolved
Elements at(long... coordinates); | ||
|
||
/** | ||
* Set a n-dimensional array of doubles as the next element in the hydrated array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe this should be "next elements" rather than "next element", but also it's not entirely clear to me what happens if I pass in a rectangular ndarray into a larger ndarray where the values are set. Are they read off in row-major order and placed into the next elements in row-major order of the target array? Or is it doing broadcasting/shape matching of some kind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the contract more strict when it comes to per-element initialization: an initialization pass must always be done with elements of the same rank. So basically you target a dimension and then provide the elements for it.
this.coordinates = Helpers.validateCoordinates(array, coordinates, 0); | ||
} | ||
|
||
protected long[] coordinates; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lifecycle of these coordinates have changed in the last version
This draft shows how we could hydrate a just-allocated array using a new API that focuses on a stateful builder approach rather than the positional endpoints
setXXX(value, coords)
exposed by the NdArray itself.Not only it simplifies the task of initializing an array with explicit values but also it allows us to allocate an empty sparse array and then let the user initialize its data (right now, the user have to allocate and initialize the data of the indices and values subarrays first before being able to allocate a sparse array).
Example of usage: