Package org.renjin.sexp

Examples of org.renjin.sexp.Vector


 
   public static Margins fromExp(SEXP exp) {
     if(!(exp instanceof Vector)) {
       throw new IllegalArgumentException("vector required");
     }
     Vector vector = (Vector)exp;
     if(exp.length() != 4) {
       throw new IllegalArgumentException("vector of length 4 required");
     }
     return new Margins(
         vector.getElementAsDouble(0),
         vector.getElementAsDouble(1),
         vector.getElementAsDouble(2),
         vector.getElementAsDouble(3));
   }
View Full Code Here


  @Test
  public void simplificationPreservesAttributes() {

   
    Vector x = new DoubleSequence(AttributeMap.builder().setDim(200,40).build(), 1, 1, 8000);
    TransposingMatrix xt = new TransposingMatrix(x, AttributeMap.builder().setDim(40,200).build());
   
    SimpleVectorPipeliner pipeliner = new SimpleVectorPipeliner();
   
    Vector xts = pipeliner.simplify(xt);
   
    assertThat(xts.getAttribute(Symbols.DIM), equalTo(c_i(40,200)));
  }
View Full Code Here

  @Override
  public final Object convertToJava(SEXP value) {
    if(!(value instanceof AtomicVector)) {
      throw new EvalException("Cannot convert '%s' to boolean", value.getTypeName());
    }
    Vector vector = (Vector)value;
    if(vector == Null.INSTANCE || vector.isElementNA(0)) {
      return null;
    }
    return getFirstElement((Vector)value);
  }
View Full Code Here

public class CombinedDoubleVectorTest {

  @Test
  public void test() {
    Vector vectors[] = new Vector[] {
      new DoubleSequence(1, 1, 100),
      new DoubleSequence(98, 2, 100),
      new DoubleArrayVector(5, 4, 3, 2)
    };
View Full Code Here

 
  public static int ncols(SEXP s)
  {
      SEXP t;
      if (s instanceof Vector) {
        Vector dim = (Vector) s.getAttribute(Symbols.DIM);
        if(dim.length() >= 2) {
          return dim.getElementAsInt(1);
        } else {
          return 1;
        }
      } else if (s.inherits("data.frame")) {
          return s.length();
View Full Code Here

 
  public NumericVariable(String name, SEXP vector) {
    this.name = name;
    this.vector = (Vector)vector;
  
    Vector dim = vector.getAttributes().getDim();
    if(dim.length() < 2) {
      numColumns = 1;
    } else if(dim.length() == 2) {
      numColumns = dim.getElementAsInt(1);
    } else {
      throw new UnsupportedOperationException("variable " + name + " has " + dim.length() +
          " dimensions, don't know what to do");
    }
  }
View Full Code Here

        Vector[] operands = node.flattenVectors();
        JittedComputation computer = DeferredJitCache.INSTANCE.compile(node);

        long start = System.nanoTime();

        Vector result = DoubleArrayVector.unsafe(computer.compute(operands));

        long time = System.nanoTime() - start;
        if(VectorPipeliner.DEBUG) {
          System.out.println("compute: " + (time/1e6) + "ms");
        }
View Full Code Here

    if(VectorPipeliner.DEBUG) {
      System.err.println("simplify");
      graph.dumpGraph();
    }

    Vector vector = materialize(root);
    if(vector instanceof MemoizedDoubleVector) {
      return vector;
    } else if(vector instanceof DeferredComputation && vector instanceof DoubleVector) {
      return DoubleArrayVector.unsafe(((DoubleVector) vector).toDoubleArray(), vector.getAttributes());
    } else {
      return vector;
    }
  }
View Full Code Here

    private Vector vector;
   
    public MatrixAdapter(Vector vector) {
      this.vector = vector;
     
      Vector dim = vector.getAttributes().getDim();
      if(dim == Null.INSTANCE) {
        throw new IllegalArgumentException("the vector has no 'dim' attribute");
      }
      if(dim.length() != 2) {
        throw new IllegalArgumentException("the vector has is not a matrix; it has " + dim.length() + " dimension(s).");
      }
      nrows = dim.getElementAsInt(0);
      ncols = dim.getElementAsInt(1);
    }
View Full Code Here

    }
    return n;
  }
 
  private static int numCases(AtomicVector vector) {
    Vector dim = vector.getAttributes().getDim();
    if(dim.length() == 2) {
      return dim.getElementAsInt(1);
    } else {
     
      // even if there is no dim attribute, or
      // there are more than 2 dimensions, we treat the input
      // as a plain vector
View Full Code Here

TOP

Related Classes of org.renjin.sexp.Vector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.