diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticNode.java index 8bb619952a5ed7e80b42e573994ea8df3dbcd951..a12084e5fecd4492f632c8fa6caf8596d0c53ed7 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticNode.java @@ -68,12 +68,12 @@ public abstract class UnaryArithmeticNode extends UnaryNode { return RRuntime.DOUBLE_NA; } - @Specialization(guards = "!isComplexNA") + @Specialization(guards = "!isNA") protected RComplex doComplex(RComplex operand) { return arithmetic.op(operand.getRealPart(), operand.getImaginaryPart()); } - @Specialization(guards = "isComplexNA") + @Specialization(guards = "isNA") protected RComplex doComplexNA(@SuppressWarnings("unused") RComplex operand) { return RRuntime.createComplexNA(); } @@ -109,15 +109,14 @@ public abstract class UnaryArithmeticNode extends UnaryNode { @Specialization(guards = "!isComplete") protected RDoubleVector doDoubleVectorNA(RAbstractDoubleVector operands) { double[] res = new double[operands.getLength()]; - na.enable(operands); for (int i = 0; i < operands.getLength(); ++i) { - if (na.check(operands.getDataAt(i))) { + if (RRuntime.isNA(operands.getDataAt(i))) { res[i] = RRuntime.DOUBLE_NA; } else { res[i] = arithmetic.op(operands.getDataAt(i)); } } - RDoubleVector ret = RDataFactory.createDoubleVector(res, na.neverSeenNA()); + RDoubleVector ret = RDataFactory.createDoubleVector(res, false); copyAttributes(ret, operands); return ret; } @@ -138,9 +137,8 @@ public abstract class UnaryArithmeticNode extends UnaryNode { @Specialization(guards = "!isComplete") protected RComplexVector doComplexVectorNA(RAbstractComplexVector operands) { double[] res = new double[operands.getLength() * 2]; - na.enable(operands); for (int i = 0; i < operands.getLength(); ++i) { - if (na.check(operands.getDataAt(i))) { + if (RRuntime.isNA(operands.getDataAt(i))) { res[2 * i] = RRuntime.DOUBLE_NA; res[2 * i + 1] = 0.0; } else { @@ -149,7 +147,7 @@ public abstract class UnaryArithmeticNode extends UnaryNode { res[2 * i + 1] = r.getImaginaryPart(); } } - RComplexVector ret = RDataFactory.createComplexVector(res, na.neverSeenNA()); + RComplexVector ret = RDataFactory.createComplexVector(res, false); copyAttributes(ret, operands); return ret; } @@ -168,15 +166,14 @@ public abstract class UnaryArithmeticNode extends UnaryNode { @Specialization(guards = "!isComplete") protected RIntVector doIntVectorNA(RAbstractIntVector operands) { int[] res = new int[operands.getLength()]; - na.enable(operands); for (int i = 0; i < operands.getLength(); ++i) { - if (na.check(operands.getDataAt(i))) { + if (RRuntime.isNA(operands.getDataAt(i))) { res[i] = RRuntime.INT_NA; } else { res[i] = arithmetic.op(operands.getDataAt(i)); } } - RIntVector ret = RDataFactory.createIntVector(res, na.neverSeenNA()); + RIntVector ret = RDataFactory.createIntVector(res, false); copyAttributes(ret, operands); return ret; } @@ -193,20 +190,15 @@ public abstract class UnaryArithmeticNode extends UnaryNode { @Specialization protected Object doStringVector(@SuppressWarnings("unused") RAbstractStringVector operands) { - throw RError.error(this.getEncapsulatingSourceSection(), RError.Message.INVALID_ARG_TYPE_UNARY); + throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_ARG_TYPE_UNARY); } @Specialization protected Object doRawVector(@SuppressWarnings("unused") RAbstractRawVector operands) { - throw RError.error(this.getEncapsulatingSourceSection(), RError.Message.INVALID_ARG_TYPE_UNARY); - } - - protected static boolean isComplexNA(RComplex c) { - return c.isNA(); + throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_ARG_TYPE_UNARY); } protected static boolean isComplete(RAbstractVector cv) { return cv.isComplete(); } - } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNode.java index b2287d7bf6cfd9ecfba9d3d9f554cdcd77b814cf..d8df6b311d3a3d1441077f307795faf94a42f952 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryNode.java @@ -25,6 +25,7 @@ package com.oracle.truffle.r.nodes.unary; import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.r.nodes.*; import com.oracle.truffle.r.runtime.*; +import com.oracle.truffle.r.runtime.data.*; @NodeChildren({@NodeChild("operand")}) public abstract class UnaryNode extends RNode { @@ -47,4 +48,7 @@ public abstract class UnaryNode extends RNode { return Double.isNaN(operand); } + protected static boolean isNA(RComplex c) { + return c.isNA(); + } }