From 6d04d30c94111ec1db32e18611ed9dc92bf5921d Mon Sep 17 00:00:00 2001 From: Robert Altena Date: Mon, 2 Sep 2019 15:06:20 +0900 Subject: [PATCH] INDArray.java javadoc (#215) * javadoc Signed-off-by: Robert Altena * javadoc Signed-off-by: Robert Altena --- .../nd4j/linalg/api/ndarray/BaseNDArray.java | 118 ------------------ .../api/ndarray/BaseSparseNDArrayCOO.java | 8 -- .../org/nd4j/linalg/api/ndarray/INDArray.java | 37 ++++-- .../linalg/jcublas/JcusparseNDArrayCSR.java | 8 -- .../cpu/nativecpu/SparseNDArrayCSR.java | 8 -- 5 files changed, 24 insertions(+), 155 deletions(-) diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java index 46dd786c6..0d0af0788 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseNDArray.java @@ -2836,156 +2836,78 @@ public abstract class BaseNDArray implements INDArray, Iterable { return putScalar(i, element.getDouble(0)); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray diviColumnVector(INDArray columnVector) { validateNumericalArray("diviColumnVector", false); return doColumnWise(columnVector, 'd'); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray divColumnVector(INDArray columnVector) { validateNumericalArray("divColumnVector", false); return dup().diviColumnVector(columnVector); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray diviRowVector(INDArray rowVector) { validateNumericalArray("diviRowVector", false); return doRowWise(rowVector, 'd'); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray divRowVector(INDArray rowVector) { validateNumericalArray("divRowVector", false); return dup().diviRowVector(rowVector); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray muliColumnVector(INDArray columnVector) { validateNumericalArray("muliColumnVector", false); return doColumnWise(columnVector, 'm'); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray mulColumnVector(INDArray columnVector) { validateNumericalArray("mulColumnVector", false); return dup().muliColumnVector(columnVector); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray muliRowVector(INDArray rowVector) { validateNumericalArray("muliRowVector", false); return doRowWise(rowVector, 'm'); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray mulRowVector(INDArray rowVector) { validateNumericalArray("mulRowVector", false); return dup().muliRowVector(rowVector); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray subiColumnVector(INDArray columnVector) { validateNumericalArray("subiColumnVector", false); return doColumnWise(columnVector, 's'); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray subColumnVector(INDArray columnVector) { validateNumericalArray("subColumnVector", false); return dup().subiColumnVector(columnVector); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray subiRowVector(INDArray rowVector) { validateNumericalArray("subiRowVector", false); return doRowWise(rowVector, 's'); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray subRowVector(INDArray rowVector) { validateNumericalArray("subRowVector", false); return dup().subiRowVector(rowVector); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray addiColumnVector(INDArray columnVector) { validateNumericalArray("addiColumnVector", false); @@ -2997,24 +2919,12 @@ public abstract class BaseNDArray implements INDArray, Iterable { return doColumnWise(columnVector, 'p'); } - /** - * In place addition of a column vector - * - * @param columnVector the column vector to add - * @return the result of the addition - */ @Override public INDArray addColumnVector(INDArray columnVector) { validateNumericalArray("addColumnVector", false); return dup().addiColumnVector(columnVector); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray addiRowVector(INDArray rowVector) { validateNumericalArray("addiRowVector", false); @@ -3027,47 +2937,22 @@ public abstract class BaseNDArray implements INDArray, Iterable { return doRowWise(rowVector, 'p'); } - /** - * In place addition of a column vector - * - * @param rowVector the row vector to add - * @return the result of the addition - */ @Override public INDArray addRowVector(INDArray rowVector) { validateNumericalArray("addRowVector", false); return dup().addiRowVector(rowVector); } - - /** - * Perform a copy matrix multiplication - * - * @param other the other matrix to perform matrix multiply with - * @return the result of the matrix multiplication - */ @Override public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { return mMulTranspose.exec(this, other, result); } - /** - * Perform a copy matrix multiplication - * - * @param other the other matrix to perform matrix multiply with - * @return the result of the matrix multiplication - */ @Override public INDArray mmul(INDArray other, MMulTranspose mMulTranspose) { return mMulTranspose.exec(this, other, null); } - /** - * Perform a copy matrix multiplication - * - * @param other the other matrix to perform matrix multiply with - * @return the result of the matrix multiplication - */ @Override public INDArray mmul(INDArray other) { Preconditions.checkState(this.dataType() == other.dataType(), "Matrix multiplication: arrays must have same dtype: %s vs. %s", this.dataType(), other.dataType()); @@ -3105,8 +2990,6 @@ public abstract class BaseNDArray implements INDArray, Iterable { if(!isVectorOrScalar()) { throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector! Shape: " + Shape.shapeToStringShort(this)); } - - return dup().data().asDouble(); } @@ -3115,7 +2998,6 @@ public abstract class BaseNDArray implements INDArray, Iterable { if(!isVectorOrScalar()) { throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector! Shape: " + Shape.shapeToStringShort(this)); } - return dup().data().asFloat(); } diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java index da5cd3f60..116a4b4f7 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/BaseSparseNDArrayCOO.java @@ -1123,14 +1123,6 @@ public class BaseSparseNDArrayCOO extends BaseSparseNDArray { return null; } - /** - * Perform an copy matrix multiplication - * - * @param other the other matrix to perform matrix multiply with - * @param result the result ndarray - * @param mMulTranspose the transpose status of each array - * @return the result of the matrix multiplication - */ @Override public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { return null; diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java index 49cabf6bb..b842797f9 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ndarray/INDArray.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/* ***************************************************************************** * Copyright (c) 2015-2018 Skymind, Inc. * * This program and the accompanying materials are made available under the @@ -16,9 +16,6 @@ package org.nd4j.linalg.api.ndarray; -import static org.nd4j.linalg.factory.Nd4j.compressDebug; -import static org.nd4j.linalg.factory.Nd4j.preventUnpack; - import com.google.flatbuffers.FlatBufferBuilder; import lombok.NonNull; import org.nd4j.linalg.api.blas.params.MMulTranspose; @@ -52,6 +49,7 @@ public interface INDArray extends Serializable, AutoCloseable { */ DataBuffer shapeInfoDataBuffer(); + // TODO: Unused untested method. /** * Sparse info * @return Sparse info. @@ -110,12 +108,13 @@ public interface INDArray extends Serializable, AutoCloseable { */ int elementWiseStride(); + // TODO: Unused untested method. /** * Get a double at the given linear offset unsafe, without checks. * @param offset the offset to get at * @return double value at offset */ - double getDoubleUnsafe(long offset); //TODO: consider deleting. + double getDoubleUnsafe(long offset); /** * Get string value at given index. @@ -124,13 +123,14 @@ public interface INDArray extends Serializable, AutoCloseable { */ String getString(long index); + // TODO: Unused untested method. /** * Insert a scalar at the given linear offset * @param offset the offset to insert at * @param value the value to insert * @return this */ - INDArray putScalarUnsafe(long offset, double value); //TODO: consider deleting. + INDArray putScalarUnsafe(long offset, double value); /** * Returns the number of possible vectors for a given dimension @@ -190,6 +190,7 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray assign(INDArray arr); + // TODO: Unused untested method. /** * Assign all elements from given ndarray that are matching given condition, * ndarray to this ndarray @@ -553,7 +554,7 @@ public interface INDArray extends Serializable, AutoCloseable { * * @param n the number to subtract by * @param result the result ndarray - * @return + * @return the result ndarray */ INDArray rsub(Number n, INDArray result); @@ -1041,7 +1042,6 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray divRowVector(INDArray rowVector); - /** * In place reverse divison of a column vector * @@ -1066,6 +1066,7 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray rdiviRowVector(INDArray rowVector); + //TODO: unused / untested method. /** * Reverse division of a column vector (copy) * @@ -1074,7 +1075,6 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray rdivRowVector(INDArray rowVector); - /** * In place multiplication of a column vector * @@ -1107,7 +1107,6 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray mulRowVector(INDArray rowVector); - /** * In place reverse subtraction of a column vector * @@ -1132,6 +1131,7 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray rsubiRowVector(INDArray rowVector); + //TODO: unused / untested method. /** * Reverse subtraction of a row vector (copy) * @@ -1180,7 +1180,6 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray addiColumnVector(INDArray columnVector); - /** * In place assignment of a column vector * @@ -1221,6 +1220,12 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray addRowVector(INDArray rowVector); + /** + * Perform a copy matrix multiplication + * + * @param other the other matrix to perform matrix multiply with + * @return the result of the matrix multiplication + */ INDArray mmul(INDArray other, MMulTranspose mMulTranspose); /** @@ -1231,8 +1236,6 @@ public interface INDArray extends Serializable, AutoCloseable { */ INDArray mmul(INDArray other); - - /** * Convert this ndarray to a 2d double matrix. * Note that THIS SHOULD NOT BE USED FOR SPEED. @@ -1283,6 +1286,14 @@ public interface INDArray extends Serializable, AutoCloseable { */ int[] toIntVector(); + /** + * Convert this ndarray to a 1d long matrix. + * Note that THIS SHOULD NOT BE USED FOR SPEED. + * This is mainly used for integrations with other libraries. + * Due to nd4j's off heap nature, moving data on heap is very expensive + * and should not be used if possible. + * @return a copy of this array as a 1d long array + */ long[] toLongVector(); /** diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java index c9266e9e7..2698c299f 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/JcusparseNDArrayCSR.java @@ -68,14 +68,6 @@ public class JcusparseNDArrayCSR extends BaseSparseNDArrayCSR { return null; } - /** - * Perform an copy matrix multiplication - * - * @param other the other matrix to perform matrix multiply with - * @param result the result ndarray - * @param mMulTranspose the transpose status of each array - * @return the result of the matrix multiplication - */ @Override public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { return null; diff --git a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java index 0135ef2c5..b35662b98 100644 --- a/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java +++ b/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/SparseNDArrayCSR.java @@ -79,14 +79,6 @@ public class SparseNDArrayCSR extends BaseSparseNDArrayCSR { return null; } - /** - * Perform an copy matrix multiplication - * - * @param other the other matrix to perform matrix multiply with - * @param result the result ndarray - * @param mMulTranspose the transpose status of each array - * @return the result of the matrix multiplication - */ @Override public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { return null;