INDArray.java javadoc (#215)

* javadoc

Signed-off-by: Robert Altena <Rob@Ra-ai.com>

* javadoc

Signed-off-by: Robert Altena <Rob@Ra-ai.com>
master
Robert Altena 2019-09-02 15:06:20 +09:00 committed by Alex Black
parent a35926c6e9
commit 6d04d30c94
5 changed files with 24 additions and 155 deletions

View File

@ -2836,156 +2836,78 @@ public abstract class BaseNDArray implements INDArray, Iterable {
return putScalar(i, element.getDouble(0)); 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 @Override
public INDArray diviColumnVector(INDArray columnVector) { public INDArray diviColumnVector(INDArray columnVector) {
validateNumericalArray("diviColumnVector", false); validateNumericalArray("diviColumnVector", false);
return doColumnWise(columnVector, 'd'); 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 @Override
public INDArray divColumnVector(INDArray columnVector) { public INDArray divColumnVector(INDArray columnVector) {
validateNumericalArray("divColumnVector", false); validateNumericalArray("divColumnVector", false);
return dup().diviColumnVector(columnVector); 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 @Override
public INDArray diviRowVector(INDArray rowVector) { public INDArray diviRowVector(INDArray rowVector) {
validateNumericalArray("diviRowVector", false); validateNumericalArray("diviRowVector", false);
return doRowWise(rowVector, 'd'); 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 @Override
public INDArray divRowVector(INDArray rowVector) { public INDArray divRowVector(INDArray rowVector) {
validateNumericalArray("divRowVector", false); validateNumericalArray("divRowVector", false);
return dup().diviRowVector(rowVector); 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 @Override
public INDArray muliColumnVector(INDArray columnVector) { public INDArray muliColumnVector(INDArray columnVector) {
validateNumericalArray("muliColumnVector", false); validateNumericalArray("muliColumnVector", false);
return doColumnWise(columnVector, 'm'); 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 @Override
public INDArray mulColumnVector(INDArray columnVector) { public INDArray mulColumnVector(INDArray columnVector) {
validateNumericalArray("mulColumnVector", false); validateNumericalArray("mulColumnVector", false);
return dup().muliColumnVector(columnVector); 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 @Override
public INDArray muliRowVector(INDArray rowVector) { public INDArray muliRowVector(INDArray rowVector) {
validateNumericalArray("muliRowVector", false); validateNumericalArray("muliRowVector", false);
return doRowWise(rowVector, 'm'); 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 @Override
public INDArray mulRowVector(INDArray rowVector) { public INDArray mulRowVector(INDArray rowVector) {
validateNumericalArray("mulRowVector", false); validateNumericalArray("mulRowVector", false);
return dup().muliRowVector(rowVector); 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 @Override
public INDArray subiColumnVector(INDArray columnVector) { public INDArray subiColumnVector(INDArray columnVector) {
validateNumericalArray("subiColumnVector", false); validateNumericalArray("subiColumnVector", false);
return doColumnWise(columnVector, 's'); 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 @Override
public INDArray subColumnVector(INDArray columnVector) { public INDArray subColumnVector(INDArray columnVector) {
validateNumericalArray("subColumnVector", false); validateNumericalArray("subColumnVector", false);
return dup().subiColumnVector(columnVector); 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 @Override
public INDArray subiRowVector(INDArray rowVector) { public INDArray subiRowVector(INDArray rowVector) {
validateNumericalArray("subiRowVector", false); validateNumericalArray("subiRowVector", false);
return doRowWise(rowVector, 's'); 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 @Override
public INDArray subRowVector(INDArray rowVector) { public INDArray subRowVector(INDArray rowVector) {
validateNumericalArray("subRowVector", false); validateNumericalArray("subRowVector", false);
return dup().subiRowVector(rowVector); 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 @Override
public INDArray addiColumnVector(INDArray columnVector) { public INDArray addiColumnVector(INDArray columnVector) {
validateNumericalArray("addiColumnVector", false); validateNumericalArray("addiColumnVector", false);
@ -2997,24 +2919,12 @@ public abstract class BaseNDArray implements INDArray, Iterable {
return doColumnWise(columnVector, 'p'); 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 @Override
public INDArray addColumnVector(INDArray columnVector) { public INDArray addColumnVector(INDArray columnVector) {
validateNumericalArray("addColumnVector", false); validateNumericalArray("addColumnVector", false);
return dup().addiColumnVector(columnVector); 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 @Override
public INDArray addiRowVector(INDArray rowVector) { public INDArray addiRowVector(INDArray rowVector) {
validateNumericalArray("addiRowVector", false); validateNumericalArray("addiRowVector", false);
@ -3027,47 +2937,22 @@ public abstract class BaseNDArray implements INDArray, Iterable {
return doRowWise(rowVector, 'p'); 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 @Override
public INDArray addRowVector(INDArray rowVector) { public INDArray addRowVector(INDArray rowVector) {
validateNumericalArray("addRowVector", false); validateNumericalArray("addRowVector", false);
return dup().addiRowVector(rowVector); 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 @Override
public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) {
return mMulTranspose.exec(this, other, result); 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 @Override
public INDArray mmul(INDArray other, MMulTranspose mMulTranspose) { public INDArray mmul(INDArray other, MMulTranspose mMulTranspose) {
return mMulTranspose.exec(this, other, null); 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 @Override
public INDArray mmul(INDArray other) { 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()); 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()) { if(!isVectorOrScalar()) {
throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector! Shape: " + Shape.shapeToStringShort(this)); throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector! Shape: " + Shape.shapeToStringShort(this));
} }
return dup().data().asDouble(); return dup().data().asDouble();
} }
@ -3115,7 +2998,6 @@ public abstract class BaseNDArray implements INDArray, Iterable {
if(!isVectorOrScalar()) { if(!isVectorOrScalar()) {
throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector! Shape: " + Shape.shapeToStringShort(this)); throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector! Shape: " + Shape.shapeToStringShort(this));
} }
return dup().data().asFloat(); return dup().data().asFloat();
} }

View File

@ -1123,14 +1123,6 @@ public class BaseSparseNDArrayCOO extends BaseSparseNDArray {
return null; 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 @Override
public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) {
return null; return null;

View File

@ -1,4 +1,4 @@
/******************************************************************************* /* *****************************************************************************
* Copyright (c) 2015-2018 Skymind, Inc. * Copyright (c) 2015-2018 Skymind, Inc.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
@ -16,9 +16,6 @@
package org.nd4j.linalg.api.ndarray; 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 com.google.flatbuffers.FlatBufferBuilder;
import lombok.NonNull; import lombok.NonNull;
import org.nd4j.linalg.api.blas.params.MMulTranspose; import org.nd4j.linalg.api.blas.params.MMulTranspose;
@ -52,6 +49,7 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
DataBuffer shapeInfoDataBuffer(); DataBuffer shapeInfoDataBuffer();
// TODO: Unused untested method.
/** /**
* Sparse info * Sparse info
* @return Sparse info. * @return Sparse info.
@ -110,12 +108,13 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
int elementWiseStride(); int elementWiseStride();
// TODO: Unused untested method.
/** /**
* Get a double at the given linear offset unsafe, without checks. * Get a double at the given linear offset unsafe, without checks.
* @param offset the offset to get at * @param offset the offset to get at
* @return double value at offset * @return double value at offset
*/ */
double getDoubleUnsafe(long offset); //TODO: consider deleting. double getDoubleUnsafe(long offset);
/** /**
* Get string value at given index. * Get string value at given index.
@ -124,13 +123,14 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
String getString(long index); String getString(long index);
// TODO: Unused untested method.
/** /**
* Insert a scalar at the given linear offset * Insert a scalar at the given linear offset
* @param offset the offset to insert at * @param offset the offset to insert at
* @param value the value to insert * @param value the value to insert
* @return this * @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 * Returns the number of possible vectors for a given dimension
@ -190,6 +190,7 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray assign(INDArray arr); INDArray assign(INDArray arr);
// TODO: Unused untested method.
/** /**
* Assign all elements from given ndarray that are matching given condition, * Assign all elements from given ndarray that are matching given condition,
* ndarray to this ndarray * ndarray to this ndarray
@ -553,7 +554,7 @@ public interface INDArray extends Serializable, AutoCloseable {
* *
* @param n the number to subtract by * @param n the number to subtract by
* @param result the result ndarray * @param result the result ndarray
* @return * @return the result ndarray
*/ */
INDArray rsub(Number n, INDArray result); INDArray rsub(Number n, INDArray result);
@ -1041,7 +1042,6 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray divRowVector(INDArray rowVector); INDArray divRowVector(INDArray rowVector);
/** /**
* In place reverse divison of a column vector * In place reverse divison of a column vector
* *
@ -1066,6 +1066,7 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray rdiviRowVector(INDArray rowVector); INDArray rdiviRowVector(INDArray rowVector);
//TODO: unused / untested method.
/** /**
* Reverse division of a column vector (copy) * Reverse division of a column vector (copy)
* *
@ -1074,7 +1075,6 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray rdivRowVector(INDArray rowVector); INDArray rdivRowVector(INDArray rowVector);
/** /**
* In place multiplication of a column vector * In place multiplication of a column vector
* *
@ -1107,7 +1107,6 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray mulRowVector(INDArray rowVector); INDArray mulRowVector(INDArray rowVector);
/** /**
* In place reverse subtraction of a column vector * In place reverse subtraction of a column vector
* *
@ -1132,6 +1131,7 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray rsubiRowVector(INDArray rowVector); INDArray rsubiRowVector(INDArray rowVector);
//TODO: unused / untested method.
/** /**
* Reverse subtraction of a row vector (copy) * Reverse subtraction of a row vector (copy)
* *
@ -1180,7 +1180,6 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray addiColumnVector(INDArray columnVector); INDArray addiColumnVector(INDArray columnVector);
/** /**
* In place assignment of a column vector * In place assignment of a column vector
* *
@ -1221,6 +1220,12 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray addRowVector(INDArray rowVector); 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); INDArray mmul(INDArray other, MMulTranspose mMulTranspose);
/** /**
@ -1231,8 +1236,6 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
INDArray mmul(INDArray other); INDArray mmul(INDArray other);
/** /**
* Convert this ndarray to a 2d double matrix. * Convert this ndarray to a 2d double matrix.
* Note that THIS SHOULD NOT BE USED FOR SPEED. * Note that THIS SHOULD NOT BE USED FOR SPEED.
@ -1283,6 +1286,14 @@ public interface INDArray extends Serializable, AutoCloseable {
*/ */
int[] toIntVector(); 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(); long[] toLongVector();
/** /**

View File

@ -68,14 +68,6 @@ public class JcusparseNDArrayCSR extends BaseSparseNDArrayCSR {
return null; 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 @Override
public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) {
return null; return null;

View File

@ -79,14 +79,6 @@ public class SparseNDArrayCSR extends BaseSparseNDArrayCSR {
return null; 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 @Override
public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) { public INDArray mmul(INDArray other, INDArray result, MMulTranspose mMulTranspose) {
return null; return null;