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); } }
@Override public void preProcess(DataSet toPreProcess) { INDArray input = toPreProcess.getFeatures(); if (input.rank() == 2) return; //No op: should usually never happen in a properly configured data pipeline //Assume input is standard rank 4 activations - i.e., CNN image data //First: we require input to be in c order. But c order (as declared in array order) isn't enough; also need strides to be correct if (input.ordering() != 'c' || !Shape.strideDescendingCAscendingF(input)) input = input.dup('c'); val inShape = input.shape(); //[miniBatch,depthOut,outH,outW] val outShape = new long[] {inShape[0], inShape[1] * inShape[2] * inShape[3]}; INDArray reshaped = input.reshape('c', outShape); toPreProcess.setFeatures(reshaped); } }
if (data.ordering() != 'f' || data.isView() || !Shape.strideDescendingCAscendingF(data)) { data = data.dup('f'); if (mask.ordering() != 'f' || mask.isView() || !Shape.strideDescendingCAscendingF(mask)) { mask = mask.dup('f');
private static INDArray toCOrder(INDArray arr) { if (arr.isView() || arr.ordering() != 'c' || !Shape.strideDescendingCAscendingF(arr)) { arr = arr.dup('c'); } return arr; }
@Override public INDArray backprop(INDArray epsilons, int miniBatchSize) { //Epsilons from layer above should be 2d, with shape [miniBatchSize, depthOut*outH*outW] if (epsilons.ordering() != 'c' || !Shape.strideDescendingCAscendingF(epsilons)) epsilons = epsilons.dup('c'); if (epsilons.rank() == 4) return epsilons; //Should never happen if (epsilons.columns() != inputWidth * inputHeight * numChannels) throw new IllegalArgumentException("Invalid input: expect output columns must be equal to rows " + inputHeight + " x columns " + inputWidth + " x depth " + numChannels + " but was instead " + Arrays.toString(epsilons.shape())); return epsilons.reshape('c', epsilons.size(0), numChannels, inputHeight, inputWidth); }
@Override public INDArray preProcess(INDArray input, int miniBatchSize) { if (input.ordering() != 'c' || !Shape.strideDescendingCAscendingF(input)) input = input.dup('c'); this.shape = input.shape(); if (input.shape().length == 4) return input; if (input.columns() != inputWidth * inputHeight * numChannels) throw new IllegalArgumentException("Invalid input: expect output columns must be equal to rows " + inputHeight + " x columns " + inputWidth + " x channels " + numChannels + " but was instead " + Arrays.toString(input.shape())); return input.reshape('c', input.size(0), numChannels, inputHeight, inputWidth); }
@Override // return 2 dimensions public INDArray preProcess(INDArray input, int miniBatchSize) { if (input.rank() == 2) return input; //Should usually never happen //Assume input is standard rank 4 activations out of CNN layer //First: we require input to be in c order. But c order (as declared in array order) isn't enough; also need strides to be correct if (input.ordering() != 'c' || !Shape.strideDescendingCAscendingF(input)) input = input.dup('c'); int[] inShape = input.shape(); //[miniBatch,depthOut,outH,outW] int[] outShape = new int[] {inShape[0], inShape[1] * inShape[2] * inShape[3]}; return input.reshape('c', outShape); }
@Override // return 4 dimensions public INDArray backprop(INDArray epsilons, int miniBatchSize) { if (epsilons.ordering() != 'c' || !Shape.strideDescendingCAscendingF(epsilons)) epsilons = epsilons.dup('c'); if (shape == null || ArrayUtil.prod(shape) != epsilons.length()) { if (epsilons.rank() == 2) return epsilons; //should never happen return epsilons.reshape('c', epsilons.size(0), numChannels, inputHeight, inputWidth); } return epsilons.reshape('c', shape); }
@Override public void preProcess(DataSet toPreProcess) { INDArray input = toPreProcess.getFeatures(); if (input.rank() == 2) return; //No op: should usually never happen in a properly configured data pipeline //Assume input is standard rank 4 activations - i.e., CNN image data //First: we require input to be in c order. But c order (as declared in array order) isn't enough; also need strides to be correct if (input.ordering() != 'c' || !Shape.strideDescendingCAscendingF(input)) input = input.dup('c'); int[] inShape = input.shape(); //[miniBatch,depthOut,outH,outW] int[] outShape = new int[] {inShape[0], inShape[1] * inShape[2] * inShape[3]}; INDArray reshaped = input.reshape('c', outShape); toPreProcess.setFeatures(reshaped); } }
if (data.ordering() != 'f' || data.isView() || !Shape.strideDescendingCAscendingF(data)) { data = data.dup('f'); if (mask.ordering() != 'f' || mask.isView() || !Shape.strideDescendingCAscendingF(mask)) { mask = mask.dup('f');
val outW = outSize[1]; if (!Shape.strideDescendingCAscendingF(delta)) {
cOrderStrides = true; if (!cOrderStrides && Shape.strideDescendingCAscendingF(epsilon)) { cOrderStrides = true; } else if (!Arrays.equals(new int[] {outH * outW, inDepth * outH * outW, outW, 1}, epsilon.stride())) {