public static long[] getStrides(long[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape); return ArrayUtil.calcStrides(shape); }
/** * Computes the standard packed array strides for a given shape. * * @param shape the shape of a matrix: * @return the strides for a matrix of n dimensions */ public static int[] calcStrides(int[] shape) { return calcStrides(shape, 1); }
/** * Get the strides for the given order and shape * * @param shape the shape of the ndarray * @param order the order to getScalar the strides for * @return the strides for the given shape and order */ public static int[] getComplexStrides(int[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape, 2); return ArrayUtil.calcStrides(shape, 2); }
public static long[] calcStrides(long[] shape) { return calcStrides(shape, 1); }
public static long[] getComplexStrides(long[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape, 2); return ArrayUtil.calcStrides(shape, 2); }
/** * Computes the standard packed array strides for a given shape. * * @param shape the shape of a matrix: * @return the strides for a matrix of n dimensions */ public static int[] calcStrides(int[] shape) { return calcStrides(shape, 1); }
/** * Get the strides for the given order and shape * * @param shape the shape of the ndarray * @param order the order to getScalar the strides for * @return the strides for the given shape and order */ public static int[] getStrides(int[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape); return ArrayUtil.calcStrides(shape); }
public BaseComplexNDArray(float[] data, int[] shape, long offset, char ordering) { this(data, shape, ordering == NDArrayFactory.C ? calcStrides(shape, 2) : calcStridesFortran(shape, 2), offset, ordering); }
public static boolean hasDefaultStridesForShape(INDArray input){ if(!strideDescendingCAscendingF(input)){ return false; } char order = input.ordering(); long[] defaultStrides; if(order == 'f'){ defaultStrides = ArrayUtil.calcStridesFortran(input.shape()); } else { defaultStrides = ArrayUtil.calcStrides(input.shape()); } return Arrays.equals(input.stride(), defaultStrides); } }
/** Are the elements in the buffer contiguous for this NDArray? */ public static boolean isContiguousInBuffer(INDArray in) { long length = in.length(); long dLength = in.data().length(); if (length == dLength) return true; //full buffer, always contiguous char order = in.ordering(); long[] shape = in.shape(); long[] stridesIfContiguous; if (order == 'f') { stridesIfContiguous = ArrayUtil.calcStridesFortran(shape); } else if (order == 'c') { stridesIfContiguous = ArrayUtil.calcStrides(shape); } else if (order == 'a') { stridesIfContiguous = new long[] {1, 1}; } else { throw new RuntimeException("Invalid order: not c or f (is: " + order + ")"); } return Arrays.equals(in.stride(), stridesIfContiguous); }
/** Can we do the op (X = Op(X)) directly on the arrays without breaking X up into 1d tensors first? * In general, this is possible if the elements of X are contiguous in the buffer, OR if every element * of X is at position offset+i*elementWiseStride in the buffer * */ public static boolean canDoOpDirectly(INDArray x) { if (x.elementWiseStride() < 1) return false; if (x.isVector()) return true; //For a single NDArray all we require is that the elements are contiguous in the buffer or every nth element //Full buffer -> implies all elements are contiguous (and match) long l1 = x.lengthLong(); long dl1 = x.data().length(); if (l1 == dl1) return true; //Strides are same as a zero offset NDArray -> all elements are contiguous (even if not offset 0) long[] shape1 = x.shape(); long[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1)); boolean stridesSameAsInit = Arrays.equals(x.stride(), stridesAsInit); return stridesSameAsInit; }
/** Can we do the transform op (X = Op(X,Y)) directly on the arrays without breaking them up into 1d tensors first? */ public static boolean canDoOpDirectly(INDArray x, INDArray y) { if (x.isVector()) return true; if (x.ordering() != y.ordering()) return false; //other than vectors, elements in f vs. c NDArrays will never line up if (x.elementWiseStride() < 1 || y.elementWiseStride() < 1) return false; //Full buffer + matching strides -> implies all elements are contiguous (and match) //Need strides to match, otherwise elements in buffer won't line up (i.e., c vs. f order arrays) long l1 = x.lengthLong(); long dl1 = x.data().length(); long l2 = y.lengthLong(); long dl2 = y.data().length(); long[] strides1 = x.stride(); long[] strides2 = y.stride(); boolean equalStrides = Arrays.equals(strides1, strides2); if (l1 == dl1 && l2 == dl2 && equalStrides) return true; //Strides match + are same as a zero offset NDArray -> all elements are contiguous (and match) if (equalStrides) { long[] shape1 = x.shape(); long[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1)); boolean stridesSameAsInit = Arrays.equals(strides1, stridesAsInit); return stridesSameAsInit; } return false; }
long[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1)); boolean stridesSameAsInit = Arrays.equals(strides1, stridesAsInit);
/** * Get the strides for the given order and shape * * @param shape the shape of the ndarray * @param order the order to getScalar the strides for * @return the strides for the given shape and order */ public static int[] getStrides(int[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape); return ArrayUtil.calcStrides(shape); }
/** * Get the strides for the given order and shape * * @param shape the shape of the ndarray * @param order the order to getScalar the strides for * @return the strides for the given shape and order */ public static int[] getComplexStrides(int[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape, 2); return ArrayUtil.calcStrides(shape, 2); }
public BaseComplexNDArray(float[] data, int[] shape, long offset, char ordering) { this(data, shape, ordering == NDArrayFactory.C ? calcStrides(shape, 2) : calcStridesFortran(shape, 2), offset, ordering); }
/** Are the elements in the buffer contiguous for this NDArray? */ public static boolean isContiguousInBuffer(INDArray in) { int length = in.length(); long dLength = in.data().length(); if (length == dLength) return true; //full buffer, always contiguous char order = in.ordering(); int[] shape = in.shape(); int[] stridesIfContiguous; if (order == 'f') { stridesIfContiguous = ArrayUtil.calcStridesFortran(shape); } else if (order == 'c') { stridesIfContiguous = ArrayUtil.calcStrides(shape); } else if (order == 'a') { stridesIfContiguous = new int[] {1, 1}; } else { throw new RuntimeException("Invalid order: not c or f (is: " + order + ")"); } return Arrays.equals(in.stride(), stridesIfContiguous); }
/** Can we do the op (X = Op(X)) directly on the arrays without breaking X up into 1d tensors first? * In general, this is possible if the elements of X are contiguous in the buffer, OR if every element * of X is at position offset+i*elementWiseStride in the buffer * */ public static boolean canDoOpDirectly(INDArray x) { if (x.elementWiseStride() < 1) return false; if (x.isVector()) return true; //For a single NDArray all we require is that the elements are contiguous in the buffer or every nth element //Full buffer -> implies all elements are contiguous (and match) long l1 = x.lengthLong(); long dl1 = x.data().length(); if (l1 == dl1) return true; //Strides are same as a zero offset NDArray -> all elements are contiguous (even if not offset 0) int[] shape1 = x.shape(); int[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1)); boolean stridesSameAsInit = Arrays.equals(x.stride(), stridesAsInit); return stridesSameAsInit; }
/** Can we do the transform op (X = Op(X,Y)) directly on the arrays without breaking them up into 1d tensors first? */ public static boolean canDoOpDirectly(INDArray x, INDArray y) { if (x.isVector()) return true; if (x.ordering() != y.ordering()) return false; //other than vectors, elements in f vs. c NDArrays will never line up if (x.elementWiseStride() < 1 || y.elementWiseStride() < 1) return false; //Full buffer + matching strides -> implies all elements are contiguous (and match) //Need strides to match, otherwise elements in buffer won't line up (i.e., c vs. f order arrays) long l1 = x.lengthLong(); long dl1 = x.data().length(); long l2 = y.lengthLong(); long dl2 = y.data().length(); int[] strides1 = x.stride(); int[] strides2 = y.stride(); boolean equalStrides = Arrays.equals(strides1, strides2); if (l1 == dl1 && l2 == dl2 && equalStrides) return true; //Strides match + are same as a zero offset NDArray -> all elements are contiguous (and match) if (equalStrides) { int[] shape1 = x.shape(); int[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1)); boolean stridesSameAsInit = Arrays.equals(strides1, stridesAsInit); return stridesSameAsInit; } return false; }
int[] stridesAsInit = (x.ordering() == 'c' ? ArrayUtil.calcStrides(shape1) : ArrayUtil.calcStridesFortran(shape1)); boolean stridesSameAsInit = Arrays.equals(strides1, stridesAsInit);