Exemple #1
0
  /**
   * Computes the standard packed array strides for a given shape.
   *
   * @param shape the shape of a matrix:
   * @param startValue the startValue for the strides
   * @return the strides for a matrix of n dimensions
   */
  public static int[] calcStrides(int[] shape, int startValue) {
    if (Shape.isColumnVectorShape(shape)) {
      int[] ret = new int[2];
      Arrays.fill(ret, startValue);
      return ret;
    }

    if (Shape.isRowVectorShape(shape)) {
      int[] ret = new int[2];
      ret[0] = 1;
      ret[1] = shape[0];
      return ret;
    }

    int dimensions = shape.length;
    int[] stride = new int[dimensions];

    int st = startValue;
    for (int j = dimensions - 1; j >= 0; j--) {
      stride[j] = st;
      st *= shape[j];
    }

    if (dimensions > 2 && shape[0] == 1) {
      stride = ArrayUtil.reverseCopy(stride);
    }

    return stride;
  }
Exemple #2
0
  /**
   * Computes the standard packed array strides for a given shape.
   *
   * @param shape the shape of a matrix:
   * @param startNum the start number for the strides
   * @return the strides for a matrix of n dimensions
   */
  public static int[] calcStridesFortran(int[] shape, int startNum) {
    if (Shape.isColumnVectorShape(shape)) {
      int[] ret = new int[2];
      Arrays.fill(ret, startNum);
      return ret;
    }

    int dimensions = shape.length;
    int[] stride = new int[dimensions];
    int st = startNum;
    for (int j = 0; j < stride.length; j++) {
      stride[j] = st;
      st *= shape[j];
    }

    if (dimensions > 2 && shape[0] == 1) {
      stride = ArrayUtil.reverseCopy(stride);
    }

    return stride;
  }