示例#1
0
  /**
   * @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
  }
示例#2
0
  /*
   *  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();
    }
  }