Exemple #1
0
 /** Prepare the input vector by replicating its elements. */
 private static RVector<?> handleEach(RAbstractVector x, int each) {
   RVector<?> r = x.createEmptySameType(x.getLength() * each, x.isComplete());
   for (int i = 0; i < x.getLength(); i++) {
     for (int j = i * each; j < (i + 1) * each; j++) {
       r.transferElementSameType(j, x, i);
     }
   }
   return r;
 }
  @Theory
  public void testCompleteness(UnaryArithmeticFactory factory, RAbstractVector originalOperand) {
    RAbstractVector operand = originalOperand.copy();
    Object result = executeArithmetic(factory, operand);

    boolean resultComplete = isPrimitive(result) ? true : ((RAbstractVector) result).isComplete();

    if (operand.getLength() == 0) {
      Assert.assertTrue(resultComplete);
    } else {
      boolean expectedComplete = operand.isComplete();
      Assert.assertEquals(expectedComplete, resultComplete);
    }
  }
Exemple #3
0
 /** Replicate the vector a given number of times. */
 private RVector<?> handleTimes(
     RAbstractVector x, RAbstractIntVector times, boolean copyIfSameSize) {
   if (oneTimeGiven.profile(times.getLength() == 1)) {
     // only one times value is given
     final int howManyTimes = times.getDataAt(0);
     if (howManyTimes < 0) {
       errorBranch.enter();
       throw invalidTimes();
     }
     if (replicateOnce.profile(howManyTimes == 1)) {
       return (RVector<?>) (copyIfSameSize ? x.copy() : x);
     } else {
       return x.copyResized(x.getLength() * howManyTimes, false);
     }
   } else {
     // times is a vector with several elements
     if (x.getLength() != times.getLength()) {
       errorBranch.enter();
       invalidTimes();
     }
     // iterate once over the times vector to determine result vector size
     int resultLength = 0;
     for (int i = 0; i < times.getLength(); i++) {
       int t = times.getDataAt(i);
       if (t < 0) {
         errorBranch.enter();
         throw invalidTimes();
       }
       resultLength += t;
     }
     // create and populate result vector
     RVector<?> r = x.createEmptySameType(resultLength, x.isComplete());
     int wp = 0; // write pointer
     for (int i = 0; i < x.getLength(); i++) {
       for (int j = 0; j < times.getDataAt(i); ++j, ++wp) {
         r.transferElementSameType(wp, x, i);
       }
     }
     return r;
   }
 }