Skip to content
Snippets Groups Projects
Commit 73d4e676 authored by Adam Welc's avatar Adam Welc
Browse files

Fixed a problem with vapply related to non-complete vectors.

parent c525f27f
Branches
No related tags found
No related merge requests found
......@@ -59,6 +59,7 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
import com.oracle.truffle.r.runtime.ops.na.NACheck;
/**
* The {@code vapply} builtin. The closure definition for {@code vapply} is
......@@ -79,6 +80,7 @@ public abstract class VApply extends RBuiltinNode {
private final ConditionProfile dimsProfile = ConditionProfile.createBinaryProfile();
private final BranchProfile errorProfile = BranchProfile.create();
private final RAttributeProfiles attrProfiles = RAttributeProfiles.create();
private final NACheck naCheck = NACheck.create();
@Child private LapplyInternalNode doApply = LapplyInternalNodeGen.create();
......@@ -156,22 +158,23 @@ public abstract class VApply extends RBuiltinNode {
RVector result = null;
boolean applyResultZeroLength = applyResult.length == 0;
naCheck.enable(true);
// TODO check funValueLen against length of result
if (funValueVec instanceof RAbstractIntVector) {
int[] data = applyResultZeroLength ? new int[0] : convertIntVector(applyResult, funValueVecLen);
result = RDataFactory.createIntVector(data, RDataFactory.COMPLETE_VECTOR);
result = RDataFactory.createIntVector(data, naCheck.neverSeenNA());
} else if (funValueVec instanceof RAbstractDoubleVector) {
double[] data = applyResultZeroLength ? new double[0] : convertDoubleVector(applyResult, funValueVecLen);
result = RDataFactory.createDoubleVector(data, RDataFactory.COMPLETE_VECTOR);
result = RDataFactory.createDoubleVector(data, naCheck.neverSeenNA());
} else if (funValueVec instanceof RAbstractLogicalVector) {
byte[] data = applyResultZeroLength ? new byte[0] : convertLogicalVector(applyResult, funValueVecLen);
result = RDataFactory.createLogicalVector(data, RDataFactory.COMPLETE_VECTOR);
result = RDataFactory.createLogicalVector(data, naCheck.neverSeenNA());
} else if (funValueVec instanceof RAbstractStringVector) {
String[] data = applyResultZeroLength ? new String[0] : convertStringVector(applyResult, funValueVecLen);
result = RDataFactory.createStringVector(data, RDataFactory.COMPLETE_VECTOR);
result = RDataFactory.createStringVector(data, naCheck.neverSeenNA());
} else if (funValueVec instanceof RAbstractComplexVector) {
double[] data = applyResultZeroLength ? new double[1] : convertComplexVector(applyResult, funValueVecLen);
result = RDataFactory.createComplexVector(data, RDataFactory.COMPLETE_VECTOR);
result = RDataFactory.createComplexVector(data, naCheck.neverSeenNA());
} else {
throw RInternalError.shouldNotReachHere();
}
......@@ -202,7 +205,9 @@ public abstract class VApply extends RBuiltinNode {
for (int i = 0; i < values.length; i++) {
RAbstractDoubleVector v = (RAbstractDoubleVector) RRuntime.asAbstractVector(castDouble(values[i], false));
for (int j = 0; j < v.getLength(); j++) {
newArray[ind++] = v.getDataAt(j);
double val = v.getDataAt(j);
naCheck.check(val);
newArray[ind++] = val;
}
}
return newArray;
......@@ -214,7 +219,9 @@ public abstract class VApply extends RBuiltinNode {
for (int i = 0; i < values.length; i++) {
RAbstractIntVector v = (RAbstractIntVector) RRuntime.asAbstractVector(castInteger(values[i], false));
for (int j = 0; j < v.getLength(); j++) {
newArray[ind++] = v.getDataAt(j);
int val = v.getDataAt(j);
naCheck.check(val);
newArray[ind++] = val;
}
}
return newArray;
......@@ -226,7 +233,9 @@ public abstract class VApply extends RBuiltinNode {
for (int i = 0; i < values.length; i++) {
RAbstractLogicalVector v = (RAbstractLogicalVector) RRuntime.asAbstractVector(castLogical(values[i], false));
for (int j = 0; j < v.getLength(); j++) {
newArray[ind++] = v.getDataAt(j);
byte val = v.getDataAt(j);
naCheck.check(val);
newArray[ind++] = val;
}
}
return newArray;
......@@ -238,7 +247,9 @@ public abstract class VApply extends RBuiltinNode {
for (int i = 0; i < values.length; i++) {
RAbstractStringVector v = (RAbstractStringVector) RRuntime.asAbstractVector(castString(values[i], false));
for (int j = 0; j < v.getLength(); j++) {
newArray[ind++] = v.getDataAt(j);
String val = v.getDataAt(j);
naCheck.check(val);
newArray[ind++] = val;
}
}
return newArray;
......@@ -251,6 +262,7 @@ public abstract class VApply extends RBuiltinNode {
RAbstractComplexVector v = (RAbstractComplexVector) RRuntime.asAbstractVector(castComplex(values[i], false));
for (int j = 0; j < v.getLength(); j++) {
RComplex val = v.getDataAt(j);
naCheck.check(val);
newArray[ind++] = val.getRealPart();
newArray[ind++] = val.getImaginaryPart();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment