protected DataBuffer shapeOf() { if (shape == null) shape = Shape.shapeOf(shapeInfoDataBuffer()); return shape; }
/** * Returns true if the given shape is of length 1 * or provided the shape length is 2: * element 0 is 1 * @param shapeInfo the shape info to check * @return true if the above conditions hold,false otherwise */ public static boolean isRowVectorShape(IntBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); IntBuffer shape = Shape.shapeOf(shapeInfo); return (rank == 2 && shape.get(0) == 1) || rank == 1; }
protected DataBuffer shapeOf() { // if (shape == null) // shape = Shape.shapeOf(shapeInfoDataBuffer()); // return shape; return Shape.shapeOf(shapeInfoDataBuffer()); }
/** * Gets the rank given the shape info buffer * @param buffer the buffer to get the rank for * @return the rank for the shape buffer */ public static int length(IntBuffer buffer) { int ret = 1; IntBuffer shape = Shape.shapeOf(buffer); int rank = Shape.rank(buffer); for (int i = 0; i < rank; i++) ret *= shape.get(i); return ret; }
/** * Returns whether the given shape is a vector * * @param shapeInfo the shapeinfo to test * @return whether the given shape is a vector */ public static boolean isVector(IntBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); if (rank > 2 || rank < 1) return false; else { int len = Shape.length(shapeInfo); IntBuffer shape = Shape.shapeOf(shapeInfo); return shape.get(0) == len || shape.get(1) == len; } }
/** * Returns true if the given shape is of length 1 * or provided the shape length is 2: * element 0 is 1 * @param shapeInfo the shape info to check * @return true if the above conditions hold,false otherwise */ public static boolean isRowVectorShape(DataBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); DataBuffer shape = Shape.shapeOf(shapeInfo); return (rank == 2 && shape.getInt(0) == 1) || rank == 1; }
public static String shapeToString(LongBuffer buffer) { val shapeBuff = shapeOf(buffer); int rank = Shape.rank(buffer); val strideBuff = stride(buffer); StringBuilder sb = new StringBuilder(); sb.append("Rank: " + rank + ","); sb.append("Offset: " + Shape.offset(buffer) + "\n"); sb.append(" Order: " + Shape.order(buffer)); sb.append(" Shape: ["); for (int i = 0; i < rank; i++) { sb.append(shapeBuff.get(i)); if (i < rank - 1) sb.append(","); } sb.append("], "); sb.append(" stride: ["); for (int i = 0; i < rank; i++) { sb.append(strideBuff.get(i)); if (i < rank - 1) sb.append(","); } sb.append("]"); return sb.toString(); }
/** * Prints the shape * for this shape information * @param buffer the shape information to print * @return the shape information to string */ public static String shapeToString(IntBuffer buffer) { val shapeBuff = shapeOf(buffer); int rank = Shape.rank(buffer); val strideBuff = stride(buffer); StringBuilder sb = new StringBuilder(); sb.append("Rank: " + rank + ","); sb.append("Offset: " + Shape.offset(buffer) + "\n"); sb.append(" Order: " + Shape.order(buffer)); sb.append(" Shape: ["); for (int i = 0; i < rank; i++) { sb.append(shapeBuff.get(i)); if (i < rank - 1) sb.append(","); } sb.append("], "); sb.append(" stride: ["); for (int i = 0; i < rank; i++) { sb.append(strideBuff.get(i)); if (i < rank - 1) sb.append(","); } sb.append("]"); return sb.toString(); }
/** * Gets the rank given the shape info buffer * @param buffer the buffer to get the rank for * @return the rank for the shape buffer */ public static int length(DataBuffer buffer) { int ret = 1; val rr = buffer.asLong(); DataBuffer shape = Shape.shapeOf(buffer); int rank = Shape.rank(buffer); for (int i = 0; i < rank; i++) ret *= shape.getLong(i); return ret; }
/** * Returns whether the given shape is a vector * * @param shapeInfo the shapeinfo to test * @return whether the given shape is a vector */ public static boolean isVector(DataBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); if (rank > 2 || rank < 1) return false; else { int len = Shape.length(shapeInfo); DataBuffer shape = Shape.shapeOf(shapeInfo); return shape.getInt(0) == len || shape.getInt(1) == len; } }
val shapeOf = Shape.shapeOf(shape); val stridesOf = Shape.stridesOf(shape);
@Override public void checkDimensions(INDArray other) { assert Shape.contentEquals(other.shape(), Shape.shapeOf(shapeInformation)) : " Other array should have been shape: " + Shape.toString(Shape.shapeOf(shapeInformation)) + " but was " + Arrays.toString(other.shape()); assert Shape.contentEquals(other.stride(), Shape.stride(shapeInformation)) : " Other array should have been stride: " + Shape.toString(Shape.stride(shapeInformation)) + " but was " + Arrays.toString(other.stride()); assert Shape.offset(javaShapeInformation) == other.offset() : "Offset of this array is " + Shape.offset(javaShapeInformation) + " but other was " + other.offset(); }
DataBuffer shape = Shape.shapeOf(shapeInfo); INDArrayIndex[] ret = new INDArrayIndex[intendedIndexes.length]; for (int i = 0; i < intendedIndexes.length; i++) { DataBuffer shape = Shape.shapeOf(shapeInfo); if (intendedIndexes.length >= rank || Shape.isVector(shapeInfo) && intendedIndexes.length == 1) { if (Shape.isRowVectorShape(shapeInfo) && intendedIndexes.length == 1) {
/** * * @param data * @param shapeInfo * @return */ public static INDArray createArrayFromShapeBuffer(DataBuffer data, DataBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); long offset = Shape.offset(shapeInfo); INDArray result = Nd4j.create(data, toIntArray(rank, Shape.shapeOf(shapeInfo)), toIntArray(rank, Shape.stride(shapeInfo)), offset, Shape.order(shapeInfo)); if (data instanceof CompressedDataBuffer) result.markAsCompressed(true); return result; }
val newShape = doPermuteSwap(Shape.shapeOf(shapeInfo), rearrange); val newStride = doPermuteSwap(Shape.stride(shapeInfo), rearrange); char newOrder = Shape.getOrder(newShape, newStride, elementStride());
/** * * @param data * @param shapeInfo * @return */ public static INDArray createArrayFromShapeBuffer(DataBuffer data, Pair<DataBuffer, long[]> shapeInfo) { int rank = Shape.rank(shapeInfo.getFirst()); long offset = Shape.offset(shapeInfo.getFirst()); INDArray result = Nd4j.create(data, toIntArray(rank, Shape.shapeOf(shapeInfo.getFirst())), toIntArray(rank, Shape.stride(shapeInfo.getFirst())), offset, Shape.order(shapeInfo.getFirst())); if (data instanceof CompressedDataBuffer) result.markAsCompressed(true); return result; }
/** * Returns true if the given shape is of length 1 * or provided the shape length is 2: * element 0 is 1 * @param shapeInfo the shape info to check * @return true if the above conditions hold,false otherwise */ public static boolean isRowVectorShape(IntBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); IntBuffer shape = Shape.shapeOf(shapeInfo); return (rank == 2 && shape.get(0) == 1) || rank == 1; }
protected DataBuffer shapeOf() { // if (shape == null) // shape = Shape.shapeOf(shapeInfoDataBuffer()); // return shape; return Shape.shapeOf(shapeInfoDataBuffer()); }
/** * Returns true if the given shape is of length 1 * or provided the shape length is 2: * element 0 is 1 * @param shapeInfo the shape info to check * @return true if the above conditions hold,false otherwise */ public static boolean isRowVectorShape(DataBuffer shapeInfo) { int rank = Shape.rank(shapeInfo); DataBuffer shape = Shape.shapeOf(shapeInfo); return (rank == 2 && shape.getInt(0) == 1) || rank == 1; }
@Override public void checkDimensions(INDArray other) { assert Shape.contentEquals(other.shape(), Shape.shapeOf(shapeInformation)) : " Other array should have been shape: " + Shape.toString(Shape.shapeOf(shapeInformation)) + " but was " + Arrays.toString(other.shape()); assert Shape.contentEquals(other.stride(), Shape.stride(shapeInformation)) : " Other array should have been stride: " + Shape.toString(Shape.stride(shapeInformation)) + " but was " + Arrays.toString(other.stride()); assert Shape.offset(javaShapeInformation) == other.offset() : "Offset of this array is " + Shape.offset(javaShapeInformation) + " but other was " + other.offset(); }