/** * Add elements of two arrays together, allocating the result array. * The result type and the operation type are taken from the type of a. * * @param a add values from here * @param b add values from here * @return result = a + b * @throws IllegalArgumentException a and b are not conformable * @throws UnsupportedOperationException dont support this data type yet */ public static Array add(Array a, Array b) throws IllegalArgumentException { Array result = Array.factory(a.getElementType(), a.getShape()); if (a.getElementType() == double.class) { addDouble(result, a, b); } else throw new UnsupportedOperationException(); return result; }
/** * Add elements of two arrays together, allocating the result array. * The result type and the operation type are taken from the type of a. * * @param a add values from here * @param b add values from here * @return result = a + b * @throws IllegalArgumentException a and b are not conformable * @throws UnsupportedOperationException dont support this data type yet */ public static Array add(Array a, Array b) throws IllegalArgumentException { Array result = Array.factory(a.getElementType(), a.getShape()); if (a.getElementType() == double.class) { addDouble(result, a, b); } else throw new UnsupportedOperationException(); return result; }
/** * Add elements of two arrays together, allocating the result array. * The result type and the operation type are taken from the type of a. * * @param a add values from here * @param b add values from here * @return result = a + b * @throws IllegalArgumentException a and b are not conformable * @throws UnsupportedOperationException dont support this data type yet */ public static Array add(Array a, Array b) throws IllegalArgumentException { Array result = Array.factory(a.getDataType(), a.getShape()); if (a.getElementType() == double.class) { addDouble(result, a, b); } else throw new UnsupportedOperationException(); return result; }
@Test public void testAdd() { int dim0 = 2; int dim1 = 3; int [] shape = {dim0, dim1}; ArrayDouble A = new ArrayDouble(shape); ArrayDouble B = new ArrayDouble(shape); try { MAMath.setDouble(A, 1.0); MAMath.setDouble(B, 22.0F); MAMath.addDouble(A, A, A); Array result = MAMath.add( A, B); IndexIterator iterR = result.getIndexIterator(); while (iterR.hasNext()) { double vala = iterR.getDoubleNext(); assert( vala == 24.0); } } catch (Exception e) { fail("testAdd Exception" + e); } }