BaseSpatialPadding2D extends BaseTensor implements SpatialPadding2D<T> { public <T extends Tensor<T>> void checkBackwardsShapeChannel( Tensor<T> padded , Tensor<T> original ) { if( padded.getDimension() != 2 ) throw new IllegalArgumentException("Padded image expected to be a 2D spatial image, i.e. 2 channels"); if( original.getDimension() != 4 ) throw new IllegalArgumentException("Original image expected to be a 4D spatial image, i.e. 4 channels"); if( padded.length(0) != original.length(2)+config.y0+config.y1 ) { throw new IllegalArgumentException( "Image heights do not match. "+padded.length(0)+" != "+original.length(2)+config.y0+config.y1); } if( padded.length(1) != original.length(3)+config.x0+config.x1) { throw new IllegalArgumentException( "Image widths do not match. "+padded.length(1)+" != "+original.length(3)+config.x0+config.x1); } } BaseSpatialPadding2D(ConfigPadding config); void setInput(T input); @Override int getPaddingRow0(); @Override int getPaddingCol0(); @Override int getPaddingRow1(); @Override int getPaddingCol1(); @Override int[] shapeGivenInput( int ...inputShape ); void checkBackwardsShapeChannel( Tensor<T> padded , Tensor<T> original ); void checkBackwardsShapeImage( Tensor<T> padded , Tensor<T> original );  }
@Test public void checkBackwardsShapeChannel() { Tensor_F64 padded = new Tensor_F64(4+6,5+4); Tensor_F64 original = new Tensor_F64(2,3,4,5); Helper alg = new Helper(config); alg.checkBackwardsShapeChannel(padded,original); checkFailBackwardsShapeChannel(alg,new Tensor_F64(4+5,5+4),original); checkFailBackwardsShapeChannel(alg,new Tensor_F64(4+6,5+3),original); checkFailBackwardsShapeChannel(alg,new Tensor_F64(4+6),original); checkFailBackwardsShapeChannel(alg,padded,new Tensor_F64(2,3,4)); }