@Specialization( guards = { "!copyAllAttributes || target != source", "containsMetadata(source, attrSourceProfiles)" }) public RAbstractVector copySameLength( RAbstractVector target, RAbstractVector source, // @Cached("create()") CopyOfRegAttributesNode copyOfReg, // @Cached("createDim()") RemoveAttributeNode removeDim, // @Cached("createDimNames()") RemoveAttributeNode removeDimNames, // @Cached("create()") InitAttributesNode initAttributes, // @Cached("createNames()") PutAttributeNode putNames, // @Cached("createDim()") PutAttributeNode putDim, // @Cached("createBinaryProfile()") ConditionProfile noDimensions, // @Cached("createBinaryProfile()") ConditionProfile hasNamesSource, // @Cached("createBinaryProfile()") ConditionProfile hasDimNames) { RVector result = target.materialize(); if (copyAllAttributes) { copyOfReg.execute(source, result); } int[] newDimensions = source.getDimensions(); if (noDimensions.profile(newDimensions == null)) { RAttributes attributes = result.getAttributes(); if (attributes != null) { removeDim.execute(attributes); removeDimNames.execute(attributes); result.setInternalDimNames(null); } result.setInternalDimensions(null); RStringVector vecNames = source.getNames(attrSourceProfiles); if (hasNamesSource.profile(vecNames != null)) { putNames.execute(initAttributes.execute(result), vecNames); result.setInternalNames(vecNames); return result; } return result; } putDim.execute( initAttributes.execute(result), RDataFactory.createIntVector(newDimensions, RDataFactory.COMPLETE_VECTOR)); result.setInternalDimensions(newDimensions); RList newDimNames = source.getDimNames(attrSourceProfiles); if (hasDimNames.profile(newDimNames != null)) { result.getAttributes().put(RRuntime.DIMNAMES_ATTR_KEY, newDimNames); newDimNames.elementNamePrefix = RRuntime.DIMNAMES_LIST_ELEMENT_NAME_PREFIX; result.setInternalDimNames(newDimNames); return result; } return result; }
public static class WriteSuperFrameVariableConditionalNode extends WriteSuperFrameVariableNodeHelper { @Child private WriteSuperFrameVariableNode writeNode; @Child private WriteSuperFrameVariableNodeHelper nextNode; @Child private RNode rhs; private final ValueProfile enclosingFrameProfile = ValueProfile.createClassProfile(); private final ConditionProfile hasValueProfile = ConditionProfile.createBinaryProfile(); private final ConditionProfile nullSuperFrameProfile = ConditionProfile.createBinaryProfile(); WriteSuperFrameVariableConditionalNode( WriteSuperFrameVariableNode writeNode, WriteSuperFrameVariableNodeHelper nextNode, RNode rhs) { this.writeNode = writeNode; this.nextNode = nextNode; this.rhs = rhs; } @Override public Object getName() { return writeNode.getName(); } @Override public RNode getRhs() { return rhs; } @Override public void execute(VirtualFrame frame, Object value, MaterializedFrame enclosingFrame) { MaterializedFrame profiledEnclosingFrame = enclosingFrameProfile.profile(enclosingFrame); if (hasValueProfile.profile(writeNode.getFrameSlotNode().hasValue(profiledEnclosingFrame))) { writeNode.execute(frame, value, profiledEnclosingFrame); } else { MaterializedFrame superFrame = RArguments.getEnclosingFrame(profiledEnclosingFrame); if (nullSuperFrameProfile.profile(superFrame == null)) { // Might be the case if "{ x <<- 42 }": This is in globalEnv! superFrame = REnvironment.globalEnv().getFrame(); } nextNode.execute(frame, value, superFrame); } } @Override public void execute(VirtualFrame frame, Object value) { assert RArguments.getEnclosingFrame(frame) != null; execute(frame, value, RArguments.getEnclosingFrame(frame)); } }
@Override public void execute(VirtualFrame frame, Object value, MaterializedFrame enclosingFrame) { MaterializedFrame profiledEnclosingFrame = enclosingFrameProfile.profile(enclosingFrame); if (hasValueProfile.profile(writeNode.getFrameSlotNode().hasValue(profiledEnclosingFrame))) { writeNode.execute(frame, value, profiledEnclosingFrame); } else { MaterializedFrame superFrame = RArguments.getEnclosingFrame(profiledEnclosingFrame); if (nullSuperFrameProfile.profile(superFrame == null)) { // Might be the case if "{ x <<- 42 }": This is in globalEnv! superFrame = REnvironment.globalEnv().getFrame(); } nextNode.execute(frame, value, superFrame); } }
@Specialization protected Object getDimNames(RAbstractContainer container) { controlVisibility(); RList names; if (container instanceof RDataFrame) { dataframeProfile.enter(); names = ((RDataFrame) container).getVector().getDimNames(); } else if (container instanceof RFactor) { factorProfile.enter(); names = ((RFactor) container).getVector().getDimNames(); } else { otherProfile.enter(); names = container.getDimNames(attrProfiles); } return nullProfile.profile(names == null) ? RNull.instance : names; }
@RBuiltin( name = "dimnames", kind = PRIMITIVE, parameterNames = {"x"}, dispatch = INTERNAL_GENERIC) public abstract class DimNames extends RBuiltinNode { private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); private final ConditionProfile nullProfile = ConditionProfile.createBinaryProfile(); private final BranchProfile dataframeProfile = BranchProfile.create(); private final BranchProfile factorProfile = BranchProfile.create(); private final BranchProfile otherProfile = BranchProfile.create(); @Specialization protected RNull getDimNames(@SuppressWarnings("unused") RNull operand) { controlVisibility(); return RNull.instance; } @Specialization protected Object getDimNames(RAbstractContainer container) { controlVisibility(); RList names; if (container instanceof RDataFrame) { dataframeProfile.enter(); names = ((RDataFrame) container).getVector().getDimNames(); } else if (container instanceof RFactor) { factorProfile.enter(); names = ((RFactor) container).getVector().getDimNames(); } else { otherProfile.enter(); names = container.getDimNames(attrProfiles); } return nullProfile.profile(names == null) ? RNull.instance : names; } }