Beispiel #1
0
 @Specialization(guards = {"each > 1", "hasNames(x)"})
 protected RAbstractVector repEachNames(
     RAbstractVector x,
     RAbstractIntVector times,
     int lengthOut,
     int each,
     @Cached("create()") InitAttributesNode initAttributes,
     @Cached("createNames()") SetFixedAttributeNode putNames) {
   if (times.getLength() > 1) {
     errorBranch.enter();
     throw invalidTimes();
   }
   RAbstractVector input = handleEach(x, each);
   RStringVector names = (RStringVector) handleEach(getNames.getNames(x), each);
   RVector<?> r;
   if (lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut))) {
     names = (RStringVector) handleLengthOut(names, lengthOut, false);
     r = handleLengthOut(input, lengthOut, false);
   } else {
     names = (RStringVector) handleTimes(names, times, false);
     r = handleTimes(input, times, false);
   }
   putNames.execute(initAttributes.execute(r), names);
   return r;
 }
Beispiel #2
0
 @Specialization(guards = {"each <= 1", "hasNames(x)"})
 protected RAbstractVector repNoEachNames(
     RAbstractVector x,
     RAbstractIntVector times,
     int lengthOut,
     @SuppressWarnings("unused") int each,
     @Cached("create()") InitAttributesNode initAttributes,
     @Cached("createNames()") SetFixedAttributeNode putNames) {
   RStringVector names;
   RVector<?> r;
   if (lengthOutOrTimes.profile(!RRuntime.isNA(lengthOut))) {
     names = (RStringVector) handleLengthOut(getNames.getNames(x), lengthOut, true);
     r = handleLengthOut(x, lengthOut, true);
   } else {
     names = (RStringVector) handleTimes(getNames.getNames(x), times, true);
     r = handleTimes(x, times, true);
   }
   putNames.execute(initAttributes.execute(r), names);
   return r;
 }
  @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;
  }
 protected boolean containsMetadata(RAbstractVector vector) {
   return vector instanceof RVector && hasDimNode.execute(vector)
       || (copyAllAttributes && vector.getAttributes() != null)
       || getNamesNode.getNames(vector) != null
       || getDimNamesNode.getDimNames(vector) != null;
 }
Beispiel #5
0
 protected boolean hasNames(RAbstractVector x) {
   return getNames.getNames(x) != null;
 }