Skip to content
Snippets Groups Projects
Commit 1035b32c authored by Lukas Stadler's avatar Lukas Stadler
Browse files

check for NA dimensions in matrix

parent a97a4e9e
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@ import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.SetDimAttributeNode;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RError.Message;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RVector;
......@@ -68,8 +69,8 @@ public abstract class Matrix extends RBuiltinNode.Arg7 {
static {
Casts casts = new Casts(Matrix.class);
casts.arg("data").asVector().mustBe(instanceOf(RAbstractVector.class));
casts.arg("nrow").asIntegerVector().findFirst(RError.Message.NON_NUMERIC_MATRIX_EXTENT);
casts.arg("ncol").asIntegerVector().findFirst(RError.Message.NON_NUMERIC_MATRIX_EXTENT);
casts.arg("nrow").asIntegerVector().findFirst(Message.NON_NUMERIC_MATRIX_EXTENT).mustNotBeNA(Message.INVALID_LARGE_NA_VALUE, "nrow");
casts.arg("ncol").asIntegerVector().findFirst(Message.NON_NUMERIC_MATRIX_EXTENT).mustNotBeNA(Message.INVALID_LARGE_NA_VALUE, "ncol");
casts.arg("byrow").asLogicalVector().findFirst().map(toBoolean());
casts.arg("dimnames").allowNull().mustBe(instanceOf(RAbstractListVector.class));
casts.arg("missingNr").asLogicalVector().findFirst().map(toBoolean());
......
......@@ -32,6 +32,7 @@ import com.oracle.truffle.r.nodes.builtin.base.MatrixNodeGen;
import com.oracle.truffle.r.nodes.unary.CastIntegerNode;
import com.oracle.truffle.r.nodes.unary.FirstIntNode;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.data.REmpty;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RNull;
......@@ -64,6 +65,9 @@ public abstract class MatrixFastPath extends RFastPathNode {
int row = rowMissing ? 1 : firstRow.executeInt(castRow.doCast(nrow));
int col = colMissing ? 1 : firstCol.executeInt(castCol.doCast(ncol));
Object dim = dimMissingProfile.profile(dimnames == RMissing.instance) ? RNull.instance : dimnames;
if (row == RRuntime.INT_NA || col == RRuntime.INT_NA) {
return null;
}
return matrix.execute(classProfile.profile(data), row, col, false, dim, rowMissing, colMissing);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment