예제 #1
0
 @Specialization(guards = {"x.isMatrix()", "y.isMatrix()"})
 protected RDoubleVector crossprod(
     RAbstractDoubleVector x,
     RAbstractDoubleVector y,
     @Cached("create()") GetDimAttributeNode getXDimsNode,
     @Cached("create()") GetDimAttributeNode getYDimsNode,
     @Cached("create()") SetDimNamesAttributeNode setDimNamesNode,
     @Cached("create()") GetDimNamesAttributeNode getADimNamesNode,
     @Cached("create()") GetDimNamesAttributeNode getBDimNamesNode) {
   int[] xDims = getXDimsNode.getDimensions(x);
   int[] yDims = getYDimsNode.getDimensions(y);
   int xRows = xDims[0];
   int xCols = xDims[1];
   int yRows = yDims[0];
   int yCols = yDims[1];
   return matMult.doubleMatrixMultiply(
       x,
       y,
       xCols,
       xRows,
       yRows,
       yCols,
       xRows,
       1,
       1,
       yRows,
       false,
       setDimNamesNode,
       getADimNamesNode,
       getBDimNamesNode);
 }
예제 #2
0
 @Specialization(guards = "x.isMatrix()")
 protected RDoubleVector crossprodDoubleMatrix(
     RAbstractDoubleVector x,
     @SuppressWarnings("unused") RNull y,
     @Cached("create()") GetDimAttributeNode getDimsNode,
     @Cached("create()") GetDimAttributeNode getResultDimsNode,
     @Cached("create()") SetDimNamesAttributeNode setDimNamesNode,
     @Cached("create()") GetDimNamesAttributeNode getADimNamesNode,
     @Cached("create()") GetDimNamesAttributeNode getBDimNamesNode) {
   int[] xDims = getDimsNode.getDimensions(x);
   int xRows = xDims[0];
   int xCols = xDims[1];
   return mirror(
       matMult.doubleMatrixMultiply(
           x,
           x,
           xCols,
           xRows,
           xRows,
           xCols,
           xRows,
           1,
           1,
           xRows,
           true,
           setDimNamesNode,
           getADimNamesNode,
           getBDimNamesNode),
       getResultDimsNode);
 }
예제 #3
0
  @Specialization(guards = {"!copyAllAttributes || target != source", "containsMetadata(source)"})
  protected RAbstractVector copySameLength(
      RAbstractVector target,
      RAbstractVector source, //
      @Cached("create()") CopyOfRegAttributesNode copyOfReg, //
      @Cached("createDim()") RemoveFixedAttributeNode removeDim, //
      @Cached("createDimNames()") RemoveFixedAttributeNode removeDimNames, //
      @Cached("create()") InitAttributesNode initAttributes, //
      @Cached("createNames()") SetFixedAttributeNode putNames, //
      @Cached("createDim()") SetFixedAttributeNode putDim, //
      @Cached("createDimNames()") SetFixedAttributeNode putDimNames, //
      @Cached("createBinaryProfile()") ConditionProfile noDimensions, //
      @Cached("createBinaryProfile()") ConditionProfile hasNamesSource, //
      @Cached("createBinaryProfile()") ConditionProfile hasDimNames,
      @Cached("create()") GetDimAttributeNode getDimsNode) {
    RVector<?> result = target.materialize();

    if (copyAllAttributes) {
      copyOfReg.execute(source, result);
    }

    int[] newDimensions = getDimsNode.getDimensions(source);
    if (noDimensions.profile(newDimensions == null)) {
      DynamicObject attributes = result.getAttributes();
      if (attributes != null) {
        removeDim.execute(attributes);
        removeDimNames.execute(attributes);
      }

      RStringVector vecNames = getNamesNode.getNames(source);
      if (hasNamesSource.profile(vecNames != null)) {
        putNames.execute(initAttributes.execute(result), vecNames);
        return result;
      }
      return result;
    }

    putDim.execute(
        initAttributes.execute(result),
        RDataFactory.createIntVector(newDimensions, RDataFactory.COMPLETE_VECTOR));

    RList newDimNames = getDimNamesNode.getDimNames(source);
    if (hasDimNames.profile(newDimNames != null)) {
      putDimNames.execute(result.getAttributes(), newDimNames);
      newDimNames.elementNamePrefix = RRuntime.DIMNAMES_LIST_ELEMENT_NAME_PREFIX;
      return result;
    }
    return result;
  }
예제 #4
0
 private static RDoubleVector mirror(RDoubleVector result, GetDimAttributeNode getResultDimsNode) {
   /*
    * Mirroring the result is not only good for performance, but it is also required to produce
    * the same result as GNUR.
    */
   int[] resultDims = getResultDimsNode.getDimensions(result);
   assert result.isMatrix() && resultDims[0] == resultDims[1];
   int size = resultDims[0];
   double[] data = result.getDataWithoutCopying();
   for (int row = 0; row < size; row++) {
     int destIndex = row * size + row + 1;
     int sourceIndex = (row + 1) * size + row;
     for (int col = row + 1; col < size; col++) {
       data[destIndex] = data[sourceIndex];
       destIndex++;
       sourceIndex += size;
     }
   }
   return result;
 }