Java Code Examples for org.nd4j.linalg.api.shape.Shape#isVector()

The following examples show how to use org.nd4j.linalg.api.shape.Shape#isVector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Indices.java    From nd4j with Apache License 2.0 6 votes vote down vote up
/**
 * Prunes indices of greater length than the shape
 * and fills in missing indices if there are any
 *
 * @param originalShape the original shape to adjust to
 * @param indexes       the indexes to adjust
 * @return the  adjusted indices
 */
public static INDArrayIndex[] adjustIndices(int[] originalShape, INDArrayIndex... indexes) {
    if (Shape.isVector(originalShape) && indexes.length == 1)
        return indexes;

    if (indexes.length < originalShape.length)
        indexes = fillIn(originalShape, indexes);
    if (indexes.length > originalShape.length) {
        INDArrayIndex[] ret = new INDArrayIndex[originalShape.length];
        System.arraycopy(indexes, 0, ret, 0, originalShape.length);
        return ret;
    }

    if (indexes.length == originalShape.length)
        return indexes;
    for (int i = 0; i < indexes.length; i++) {
        if (indexes[i].end() >= originalShape[i] || indexes[i] instanceof NDArrayIndexAll)
            indexes[i] = NDArrayIndex.interval(0, originalShape[i] - 1);
    }

    return indexes;
}
 
Example 2
Source File: Indices.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * Prunes indices of greater length than the shape
 * and fills in missing indices if there are any
 *
 * @param originalShape the original shape to adjust to
 * @param indexes       the indexes to adjust
 * @return the  adjusted indices
 */
public static INDArrayIndex[] adjustIndices(int[] originalShape, INDArrayIndex... indexes) {
    if (Shape.isVector(originalShape) && indexes.length == 1)
        return indexes;

    if (indexes.length < originalShape.length)
        indexes = fillIn(originalShape, indexes);
    if (indexes.length > originalShape.length) {
        INDArrayIndex[] ret = new INDArrayIndex[originalShape.length];
        System.arraycopy(indexes, 0, ret, 0, originalShape.length);
        return ret;
    }

    if (indexes.length == originalShape.length)
        return indexes;
    for (int i = 0; i < indexes.length; i++) {
        if (indexes[i].end() >= originalShape[i] || indexes[i] instanceof NDArrayIndexAll)
            indexes[i] = NDArrayIndex.interval(0, originalShape[i] - 1);
    }

    return indexes;
}
 
Example 3
Source File: LinAlgExceptions.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static void assertSameShape(INDArray n, INDArray n2) {
    if (!Shape.isVector(n.shape()) && ! Shape.isVector(n2.shape()))
        if (!Shape.shapeEquals(n.shape(), n2.shape()))
            throw new IllegalStateException("Mis matched shapes: " + Arrays.toString(n.shape()) + ", " + Arrays.toString(n2.shape()));
}