/** * Computes the tensors per slice * given a tensor shape and array * @param arr the array to get the tensors per slice for * @param tensorShape the desired tensor shape * @return the tensors per slice of an ndarray */ public static long tensorsPerSlice(INDArray arr, int[] tensorShape) { return lengthPerSlice(arr) / ArrayUtil.prod(tensorShape); }
public static long sliceOffsetForTensor(int index, INDArray arr, long[] tensorShape) { long tensorLength = ArrayUtil.prodLong(tensorShape); long lengthPerSlice = NDArrayMath.lengthPerSlice(arr); long offset = index * tensorLength / lengthPerSlice; return offset; }
public static long[] getStrides(long[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape); return ArrayUtil.calcStrides(shape); }
/** * Returns a subset of an array from 0 to "to" * using the specified stride * * @param data the data to getFromOrigin a subset of * @param to the end point of the data * @param stride the stride to go through the array * @return the subset of the data specified */ public static double[] range(double[] data, int to, int stride) { return range(data, to, stride, 1); }
/** * Construct an ndarray of the specified shape * with an empty data array * * @param shape the shape of the ndarray * @param stride the stride of the ndarray * @param offset the desired offset */ public BaseComplexNDArray(int[] shape, int[] stride, long offset) { this(new float[ArrayUtil.prod(shape) * 2], shape, stride, offset); }
/** * 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[] calcStridesFortran(int[] shape) { return calcStridesFortran(shape, 1); }
/** * Pass in the shape to iterate over * @param shape the shape to iterate over */ public NdIndexIterator(char order, int... shape) { this(order, false, ArrayUtil.toLongArray(shape)); }
public static short[] toHalfs(long[] data) { short[] ret = new short[data.length]; for (int i = 0; i < ret.length; i++) { ret[i] = fromFloat((float) data[i]); } return ret; }
/** * This returns the permutation of n choose r. * * @param n the n to choose * @param r the number of elements to choose * @return the permutation of these numbers */ public static double permutation(double n, double r) { double nFac = MathUtils.factorial(n); double nMinusRFac = MathUtils.factorial((n - r)); return nFac / nMinusRFac; }//end permutation
public BaseTransformOp(INDArray x, INDArray y, INDArray z, long n) { super(x, y, z, n); if (y != null) LinAlgExceptions.assertSameLength(x, y, z); else LinAlgExceptions.assertSameLength(x, z); }
/** * 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 static long[] range(long from, long to) { if (from == to) return new long[0]; return range(from, to, 1); }
/** * calculates the offset for a tensor * @param index * @param arr * @param tensorShape * @return */ public static long sliceOffsetForTensor(int index, INDArray arr, int[] tensorShape) { long tensorLength = ArrayUtil.prodLong(tensorShape); long lengthPerSlice = NDArrayMath.lengthPerSlice(arr); long offset = index * tensorLength / lengthPerSlice; return offset; }
/** * * @param shape the shape of the linear index * @param ordering the ordering of the linear index */ public LinearIndexLookup(int[] shape, char ordering) { this(ArrayUtil.toLongArray(shape), ordering); }
/** * 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[] getComplexStrides(long[] shape, char order) { if (order == NDArrayFactory.FORTRAN) return ArrayUtil.calcStridesFortran(shape, 2); return ArrayUtil.calcStrides(shape, 2); }