コード例 #1
0
ファイル: Arrays.java プロジェクト: spurious/kawa-mirror
 /* Create a view of a simple-array that is an affine index transform.
  */
 public static Array shareArray(Array array, Array shape, Procedure proc) throws Throwable {
   GeneralArray result = allocateArray(shape);
   int rank = result.rank();
   Object[] args = new Object[rank];
   int[] dimensions = result.getDimensions();
   int[] lowBounds = result.getLowBounds();
   boolean empty = result.getSize() == 0;
   for (int i = rank; --i >= 0; ) args[i] = Integer.valueOf(result.getLowBound(i));
   int arank = array.rank();
   int[] offsets = new int[rank];
   int offset0;
   if (empty) offset0 = 0;
   else {
     int[] work = new int[arank];
     offset0 = effectiveIndex(array, proc, args, work);
     for (int i = rank; --i >= 0; ) {
       int size = dimensions[i];
       int lo = lowBounds == null ? 0 : lowBounds[i];
       if (size <= 1) offsets[i] = 0;
       else {
         Object low = args[i];
         args[i] = IntNum.make(lo + 1);
         offsets[i] = (effectiveIndex(array, proc, args, work) - offset0);
         args[i] = low;
       }
     }
   }
   AVector base =
       array instanceof GeneralArray ? ((GeneralArray) array).getBase() : (AVector) array;
   result.setBase(base);
   result.setStrides(offsets, offset0);
   return result;
 }
コード例 #2
0
ファイル: Arrays.java プロジェクト: spurious/kawa-mirror
 public static <E> Array<E> getTransformed(Array<E> base, Procedure transformer, Array shape) {
   GeneralArray ashape = allocateArray(shape);
   return new ProcTransformedArray(
       base, transformer, ashape.getDimensions(), ashape.getLowBounds());
 }
コード例 #3
0
ファイル: Arrays.java プロジェクト: spurious/kawa-mirror
 public static <E> Array<E> getBuiltArray(Array shape, Procedure procedure) {
   GeneralArray ashape = allocateArray(shape);
   return new BuiltArray(procedure, ashape.getDimensions(), ashape.getLowBounds());
 }