-
Notifications
You must be signed in to change notification settings - Fork 17
NdArray Initializer API #4
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.tensorflow.ndarray.hydrator; | ||
|
karllessard marked this conversation as resolved.
|
||
|
|
||
| import org.tensorflow.ndarray.DoubleNdArray; | ||
| import org.tensorflow.ndarray.NdArray; | ||
| import org.tensorflow.ndarray.Shape; | ||
|
|
||
| public interface DoubleNdArrayHydrator extends NdArrayHydrator<Double> { | ||
|
|
||
| interface Scalars extends NdArrayHydrator.Scalars<Double> { | ||
|
|
||
| @Override | ||
| Scalars at(long... coordinates); | ||
|
|
||
| Scalars put(double scalar); | ||
| } | ||
|
|
||
| interface Vectors extends NdArrayHydrator.Vectors<Double> { | ||
|
|
||
| @Override | ||
| Vectors at(long... coordinates); | ||
|
|
||
| Vectors put(double... vector); | ||
| } | ||
|
|
||
| @Override | ||
| Scalars byScalars(long... coordinates); | ||
|
|
||
| @Override | ||
| Vectors byVectors(long... coordinates); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package org.tensorflow.ndarray.hydrator; | ||
|
karllessard marked this conversation as resolved.
|
||
|
|
||
| import org.tensorflow.ndarray.NdArray; | ||
| import org.tensorflow.ndarray.Shape; | ||
| import org.tensorflow.ndarray.buffer.ByteDataBuffer; | ||
|
|
||
| public interface NdArrayHydrator<T> { | ||
|
|
||
| interface Scalars<T> { | ||
|
|
||
| <U extends Scalars<T>> U at(long... coordinates); | ||
|
|
||
| <U extends Scalars<T>> U putObject(T scalar); | ||
| } | ||
|
|
||
| interface Vectors<T> { | ||
|
|
||
| <U extends Vectors<T>> U at(long... coordinates); | ||
|
|
||
| <U extends Vectors<T>> U putObjects(T... vector); | ||
| } | ||
|
|
||
| interface Elements<T> { | ||
|
|
||
| <U extends Elements<T>> U at(long... coordinates); | ||
|
|
||
| <U extends Elements<T>> U put(NdArray<T> vector); | ||
| } | ||
|
|
||
| <U extends Scalars<T>> U byScalars(long... coordinates); | ||
|
|
||
| <U extends Vectors<T>> U byVectors(long... coordinates); | ||
|
|
||
| <U extends Elements<T>> U byElements(long... coordinates); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |
| @SuppressWarnings("unchecked") | ||
| public abstract class AbstractDenseNdArray<T, U extends NdArray<T>> extends AbstractNdArray<T, U> { | ||
|
|
||
| abstract public DataBuffer<T> buffer(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copyright 2022 should probably be added to this file, e.g. "Copyright 2019, 2022, The TensorFlow Authors. All Rights Reserved.". Also javadoc for the new public method? And why does it need to be public now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I access directly the array buffer in the initializer as I know that at this point it is safe to do it. Now, I could also pass a reference to that buffer at the initializer construction I suppose, if we prefer to keep it hidden from malicious usage. Though in some cases I missed the fact that I cannot access the buffer of a dense array... so I'm a bit undecided on this, your thoughts?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would default to keeping it more private unless there is a strong reason not to. It provides us more flexibility in the future, and making things public is easier than making them private again. |
||
|
|
||
| @Override | ||
| public NdArraySequence<U> elements(int dimensionIdx) { | ||
| if (dimensionIdx >= shape().numDimensions()) { | ||
|
|
@@ -136,8 +138,6 @@ protected AbstractDenseNdArray(DimensionalSpace dimensions) { | |
| super(dimensions); | ||
| } | ||
|
|
||
| abstract protected DataBuffer<T> buffer(); | ||
|
|
||
| abstract U instantiate(DataBuffer<T> buffer, DimensionalSpace dimensions); | ||
|
|
||
| long positionOf(long[] coords, boolean isValue) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.