/* * tensor product */ public <N, V> void tPoduct(N arr1, V arr2) { try { Access<?> access1 = Access.rawAccess(arr1, null); Access<?> access2 = Access.rawAccess(arr2, null); for (int i = 0; i < access1.size()[0]; i++) { final float f = access1.elementFloat(i) * access2.elementFloat(i); access1.putFloat(i, f); } } catch (UnsupportedTypeException e) { e.printStackTrace(); } }
/* * dot product */ public <N, V> float dotPoduct(N arr1, V arr2) { float sum = 0; try { Access<?> access1 = Access.rawAccess(arr1, null); Access<?> access2 = Access.rawAccess(arr2, null); for (int i = 0; i < access1.size()[0]; i++) { final float f = access1.elementFloat(i) * access2.elementFloat(i); sum += f; } } catch (UnsupportedTypeException e) { e.printStackTrace(); } return sum; }
/** * @param out * @param ind * @param vcoords * @param ivals * @param accessin * @param mc */ public void minmaxFloat( final Access<?> accessin, final GridIndex ind, final int[][] vcoords, final float[] ivals, final BoundaryCondition<int[]> mc, final Access<?> out) { final int[] dims = ind.getDim(); final int sz = vcoords.length; ind.setIndexAndUpdate(0); int[] ct = dims.clone(); final int limit = accessin.size()[0]; for (int i = 0; i < limit; i++) { float sum = 0; final int[] coords = ind.getCoordinates(); // iteration over kernel for (int k = 0; k < sz; k++) { // adding coordinates for (int u = 0; u < ct.length; u++) { ct[u] = (coords[u] + vcoords[k][u]); } // checking for validity boolean valid = true; for (int a = 0; a < dims.length; a++) { valid = valid && (ct[a] >= 0) && (ct[a] < dims[a]); } int u; try { if (valid) { u = ind.indexOf(ct); } else { final int[] coords_aux = mc.getCoordsAt(coords); u = ind.indexOf(coords_aux); } // end else final float elem = accessin.elementFloat(u); sum += elem * ivals[k]; } catch (Exception e) { // if (debug) { System.out.println(e + ": " + ind + " "); Util.printIntArray(vcoords[k]); // } } // end catch } // end for out.putFloat(i, sum); ind.inc(); } // end for }
// TODO @SuppressWarnings("unchecked") @Override public N join() { PixelCube<E, BaseIndex> pc = new PixelCube<E, BaseIndex>(dim, dummy); pc.setIndexing(BASE_INDEXING); pc.one(); pc.setIterationPattern(IP_SINGLE + IP_DIR + IP_FWD); pc.setDir(new int[] {0, 1}); PixelDirForwardIterator<E> iter = (PixelDirForwardIterator<E>) pc.iterator(); PixelDirForwardIterator<E> iter2 = (PixelDirForwardIterator<E>) pc.iterator(); for (int i = 0; i < nKernels; i++) { System.out.println("iter: " + i); for (int u = 0; u < ndim; u++) { int[] dir = {0, u + 1}; // direction if (u == ndim - 1) dir = new int[] {1, 0}; iter.setDirection(dir); iter2.setDirection(dir); int p = 0; Access<?> kaccess; try { kaccess = Access.rawAccess(kernels[i], null); final int len = kaccess.size()[0]; System.out.println(dim[u] + ","); while (iter.hasNext()) { float elem = iter.next().floatValue(); elem *= kaccess.elementFloat(p); System.out.print(elem + ","); iter2.putFloat(elem); iter2.inc(); p++; p = p % len; } iter.reset(); iter2.reset(); System.out.println(); } catch (UnsupportedTypeException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } // end catch } // end for } // end for // System.out.println(pc); return (N) pc.getAccess().getArray(); } //