TensorOps_F32 { public static void fillSpatialBorder(Tensor_F32 tensor , int[] coor , int borderY0 , int borderX0 , int borderY1 , int borderX1 , float value ) { int channelAxis = coor.length-3; for (int i = channelAxis; i < coor.length; i++) { coor[i] = 0; } int numChannels = tensor.length(channelAxis); int height = tensor.length(channelAxis+1); int width = tensor.length(channelAxis+2); if( borderY0+borderY1 > height ) { throw new IllegalArgumentException("Y border is larger than image height"); } if( borderX0+borderX1 > width ) { throw new IllegalArgumentException("X border is larger than image width"); } for (int channel = 0; channel < numChannels; channel++) { coor[channelAxis] = channel; coor[channelAxis+1] = 0; coor[channelAxis+2] = 0; int indexTop = tensor.idx(coor); Arrays.fill(tensor.d,indexTop,indexTop+borderY0*width,value); coor[channelAxis+1] = height-borderY1; int indexBottom = tensor.idx(coor); Arrays.fill(tensor.d,indexBottom,indexBottom+borderY1*width,value); for (int y = borderY0; y < height - borderY1; y++) { coor[channelAxis+1] = y; int left = tensor.idx(coor); int right = left + width-borderX1; for (int i = 0; i < borderX0; i++) { tensor.d[left+i] = value; } for (int i = 0; i < borderX1; i++) { tensor.d[right+i] = value; } } } }  static void elementMult(Tensor_F32 tensor , float value  ); static void elementMult(Tensor_F32 input , float value , Tensor_F32 output ); static void elementMult(Tensor_F32 A , Tensor_F32 B , Tensor_F32 output ); static void elementAdd(Tensor_F32 A , Tensor_F32 B , Tensor_F32 output ); static float elementSum( Tensor_F32 tensor ); static void insertSubChannel( Tensor_F32 src , int srcStartIndex , int srcStride ,
										 Tensor_F32 dst , int dstStartIndex , int dstStride ,
										 int rows , int columns ); static void insertSpatial(Tensor_F32 src , int []srcCoor,
									 Tensor_F32 dst , int []dstCoor ); static void fillSpatialBorder(Tensor_F32 tensor , int[] coor ,
										 int borderY0 , int borderX0 , int borderY1 , int borderX1 ,
										 float value ); static void printSpatial( Tensor_F32 tensor , int batch , int channel ); static void fill( Tensor_F32 tensor , float value );  }
@Test public void fillSpatialBorder() { for( boolean subtensor : new boolean[]{false,true}) { int C = 3; int H = 13; int W = 18; float value = 2.3f; int borderX0 = 2, borderY0 = 1; int borderX1 = 3, borderY1 = 4; int[] coor = new int[]{2,0,0,0}; Tensor_F32 T = TensorFactory_F32.random(rand, subtensor,5, C, H, W); TensorOps_F32.fillSpatialBorder(T,coor,borderY0,borderX0,borderY1,borderX1,value); checkBorder(T,2,borderY0,borderX0,borderY1,borderX1, value); coor = new int[]{2,10,2,12}; T = TensorFactory_F32.random(rand, subtensor,5, C, H, W); TensorOps_F32.fillSpatialBorder(T,coor,borderY0,borderX0,borderY1,borderX1,value); checkBorder(T,2,borderY0,borderX0,borderY1,borderX1, value); } }