Transforms { public static INDArray pool(INDArray toPool,int[] stride) { int nDims = toPool.shape().length; assert nDims == 3 : "NDArray must have 3 dimensions"; int nRows = toPool.shape()[nDims - 2]; int nCols = toPool.shape()[nDims - 1]; int yStride = stride[0],xStride = stride[1]; INDArray blocks = Nd4j.create(toPool.shape()); for(int iR = 0; iR < Math.ceil(nRows / yStride); iR++) { NDArrayIndex rows = NDArrayIndex.interval(iR * yStride,iR * yStride,true); for(int jC = 0; jC < Math.ceil(nCols / xStride); jC++) { NDArrayIndex cols = NDArrayIndex.interval(jC * xStride ,(jC * xStride) + 1,true); INDArray blockVal = toPool.get(rows,cols).sum(toPool.shape().length - 1).sum(toPool.shape().length - 1); blocks.put( new NDArrayIndex[]{rows,cols}, blockVal.permute(new int[]{1,2,0})) .repmat(new int[]{rows.length(),cols.length()}); } } return blocks; }  static INDArray maxPool(INDArray input,int[] ds,boolean ignoreBorder); static INDArray downSample(INDArray d1,int[] stride); static INDArray pool(INDArray toPool,int[] stride); static INDArray upSample(INDArray d, INDArray scale); static double cosineSim(INDArray d1, INDArray d2); static INDArray normalizeZeroMeanAndUnitVariance(INDArray toNormalize); static INDArray unitVec(INDArray toScale); static INDArray neg(INDArray ndArray); static IComplexNDArray neg(IComplexNDArray ndArray); static INDArray eq(INDArray ndArray); static IComplexNDArray eq(IComplexNDArray ndArray); static INDArray neq(INDArray ndArray); static IComplexNDArray neq(IComplexNDArray ndArray); static INDArray floor(INDArray ndArray); static INDArray sign(IComplexNDArray toSign); static INDArray sign(INDArray toSign); static IComplexNDArray floor(IComplexNDArray ndArray); static INDArray gt(INDArray ndArray); static IComplexNDArray gt(IComplexNDArray ndArray); static INDArray lt(INDArray ndArray); static IComplexNDArray lt(IComplexNDArray ndArray); static INDArray stabilize(INDArray ndArray,double k); static IComplexNDArray stabilize(IComplexNDArray ndArray,double k); static INDArray abs(INDArray ndArray); static IComplexNDArray abs(IComplexNDArray ndArray); static INDArray exp(INDArray ndArray); static IComplexNDArray exp(IComplexNDArray ndArray); static INDArray hardTanh(INDArray ndArray); static IComplexNDArray hardTanh(IComplexNDArray ndArray); static INDArray identity(INDArray ndArray); static IComplexNDArray identity(IComplexNDArray ndArray); static INDArray max(INDArray ndArray); static INDArray max(INDArray ndArray,double max); static IComplexNDArray max(IComplexNDArray ndArray,double max); static IComplexNDArray max(IComplexNDArray ndArray); static INDArray pow(INDArray ndArray,Number power); static IComplexNDArray pow(IComplexNDArray ndArray,IComplexNumber power); static INDArray round(INDArray ndArray); static IComplexNDArray round(IComplexNDArray ndArray); static INDArray sigmoid(INDArray ndArray); static IComplexNDArray sigmoid(IComplexNDArray ndArray); static INDArray sqrt(INDArray ndArray); static IComplexNDArray sqrt(IComplexNDArray ndArray); static INDArray tanh(INDArray ndArray); static IComplexNDArray tanh(IComplexNDArray ndArray); static INDArray log(INDArray ndArray); static IComplexNDArray log(IComplexNDArray ndArray); static INDArray eq(INDArray ndArray,boolean dup); static IComplexNDArray eq(IComplexNDArray ndArray,boolean dup); static INDArray neq(INDArray ndArray,boolean dup); static IComplexNDArray neq(IComplexNDArray ndArray,boolean dup); static INDArray floor(INDArray ndArray,boolean dup); static INDArray sign(IComplexNDArray toSign,boolean dup); static INDArray sign(INDArray toSign,boolean dup); static IComplexNDArray floor(IComplexNDArray ndArray,boolean dup); static INDArray gt(INDArray ndArray,boolean dup); static IComplexNDArray gt(IComplexNDArray ndArray,boolean dup); static INDArray lt(INDArray ndArray,boolean dup); static IComplexNDArray lt(IComplexNDArray ndArray,boolean dup); static INDArray stabilize(INDArray ndArray,double k,boolean dup); static IComplexNDArray stabilize(IComplexNDArray ndArray,double k,boolean dup); static INDArray abs(INDArray ndArray,boolean dup); static IComplexNDArray abs(IComplexNDArray ndArray,boolean dup); static INDArray exp(INDArray ndArray,boolean dup); static IComplexNDArray exp(IComplexNDArray ndArray,boolean dup); static INDArray hardTanh(INDArray ndArray,boolean dup); static IComplexNDArray hardTanh(IComplexNDArray ndArray,boolean dup); static INDArray identity(INDArray ndArray,boolean dup); static IComplexNDArray identity(IComplexNDArray ndArray,boolean dup); static INDArray max(INDArray ndArray,boolean dup); static INDArray max(INDArray ndArray,double max,boolean dup); static IComplexNDArray max(IComplexNDArray ndArray,double max,boolean dup); static IComplexNDArray max(IComplexNDArray ndArray,boolean dup); static INDArray pow(INDArray ndArray,Number power,boolean dup); static IComplexNDArray pow(IComplexNDArray ndArray,IComplexNumber power,boolean dup); static INDArray round(INDArray ndArray,boolean dup); static IComplexNDArray round(IComplexNDArray ndArray,boolean dup); static INDArray sigmoid(INDArray ndArray,boolean dup); static IComplexNDArray sigmoid(IComplexNDArray ndArray,boolean dup); static INDArray sqrt(INDArray ndArray,boolean dup); static IComplexNDArray sqrt(IComplexNDArray ndArray,boolean dup); static INDArray tanh(INDArray ndArray,boolean dup); static IComplexNDArray tanh(IComplexNDArray ndArray,boolean dup); static INDArray log(INDArray ndArray,boolean dup); static IComplexNDArray log(IComplexNDArray ndArray,boolean dup); static INDArray neg(INDArray ndArray,boolean dup); static IComplexNDArray neg(IComplexNDArray ndArray,boolean dup);  }
@Test public void testPooling() { INDArray twoByTwo = Nd4j.ones(new int[]{2,2,2}); INDArray pool = Transforms.pool(twoByTwo,new int[]{1,2}); }