TensorOps_F64 { public static double elementSum( Tensor_F64 tensor ) { int index = tensor.startIndex; int end = index + tensor.length(); double sum = 0; while( index < end ) { sum += tensor.d[index++]; } return sum; }  static void elementMult(Tensor_F64 tensor , double value  ); static void elementMult(Tensor_F64 input , double value , Tensor_F64 output ); static void elementMult(Tensor_F64 A , Tensor_F64 B , Tensor_F64 output ); static void elementAdd(Tensor_F64 A , Tensor_F64 B , Tensor_F64 output ); static double elementSum( Tensor_F64 tensor ); static void insertSubChannel( Tensor_F64 src , int srcStartIndex , int srcStride ,
										 Tensor_F64 dst , int dstStartIndex , int dstStride ,
										 int rows , int columns ); static void insertSpatial(Tensor_F64 src , int []srcCoor,
									 Tensor_F64 dst , int []dstCoor ); static void fillSpatialBorder(Tensor_F64 tensor , int[] coor ,
										 int borderY0 , int borderX0 , int borderY1 , int borderX1 ,
										 double value ); static void printSpatial( Tensor_F64 tensor , int batch , int channel ); static void fill( Tensor_F64 tensor , double value );  }
@Test public void elementSum() { List<int[]> shapes = new ArrayList<>(); shapes.add(new int[]{5}); shapes.add(new int[]{2,3,4}); for( boolean subtensor : new boolean[]{false,true}) { for( int[] shape : shapes ) { Tensor_F64 tensor = TensorFactory_F64.random(rand, subtensor, shape); double expected = 0; for (int i = 0; i < tensor.length(); i++) { expected += tensor.getAtIndex(i); } double found = TensorOps_F64.elementSum(tensor); assertEquals(expected,found,DeepBoofConstants.TEST_TOL_F64); } } }