TensorOps { public static void checkShape(String which, List<int[]> expected , List<Tensor<?>> actual , boolean ignoreAxis0 ) { if( expected.size() != actual.size() ) throw new IllegalArgumentException( which+": Unexpected number of tensors. "+expected.size()+" vs "+actual.size()); for (int i = 0; i < expected.size(); i++) { int[] e = expected.get(i); int[] a = actual.get(i).getShape(); checkShape(which, i, e, a, ignoreAxis0); } }  static List<T> WT(T ...elements ); static int[] WI( int ... elements ); static int[] WI( int a , int[] elements ); static int[] WI( int[] elements , int a ); static int[] TH(int[] elements ); static List<int[]> WI( int a , List<int[]> list ); static T AD( T input ); static int sumTensorLength( List<int[]> shapes ); static int tensorLength( int... shape ); static void checkShape(String which, List<int[]> expected , List<Tensor<?>> actual , boolean ignoreAxis0 ); static void checkShape( Tensor_F64 a , Tensor_F64 b ); static void checkShape( Tensor_F32 a , Tensor_F32 b ); static void checkShape(String which, int tensor, int[] expected, int[] actual, boolean ignoreAxis0 ); static String toStringShapeA( int []shape ); static String toStringShape( int []shape ); static int outerLength(int[] shape , int startDimen ); static File pathToRoot(); static double elementSum( Tensor tensor ); static void fill( Tensor t , double value ); static void boundSpatial( int bounds[] , int rows , int cols );  }
@Test public void checkShape_list() { List<int[]> expected = new ArrayList<int[]>(); List<Tensor<?>> actual = new ArrayList(); expected.add(new int[]{2,1,3}); actual.add(new Tensor_F64(2,1,3)); TensorOps.checkShape("",expected,actual,false); List<Tensor<?>> actual2 = new ArrayList(); actual2.add(new Tensor_F64(2,2,1,3)); TensorOps.checkShape("",expected,actual2,true); expected.add(new int[]{5,1,4}); actual.add(new Tensor_F64(2,1,4)); try { TensorOps.checkShape("",expected,actual,false); fail("Should have thrown an exception"); } catch( IllegalArgumentException ignore){} expected.add(new int[]{5,1,4}); actual2.add(new Tensor_F64(2,2,1,4)); try { TensorOps.checkShape("",expected,actual,true); fail("Should have thrown an exception"); } catch( IllegalArgumentException ignore){} }
@Test public void checkShape_individual() { TensorOps.checkShape("",2,new int[]{2,1,3},new int[]{2,1,3},false); TensorOps.checkShape("",2,new int[]{2,1,3},new int[]{10,2,1,3},true); try { TensorOps.checkShape("",2,new int[]{2,2,3},new int[]{2,1,3},false); fail("Should have thrown an exception"); } catch( IllegalArgumentException ignore){} try { TensorOps.checkShape("",2,new int[]{2,2,3},new int[]{10,2,1,3},false); fail("Should have thrown an exception"); } catch( IllegalArgumentException ignore){} }