From 3738dbc19a8d571210bfe825a4df15faaf82ad9c Mon Sep 17 00:00:00 2001 From: Adam Welc <adam.welc@oracle.com> Date: Wed, 29 Jan 2014 23:52:38 -0800 Subject: [PATCH] Further cleanup and fixes to cast operations and conversion builtins. --- .../r/nodes/builtin/base/AsCharacter.java | 26 +- .../r/nodes/builtin/base/AsComplex.java | 84 ++---- .../r/nodes/builtin/base/AsDouble.java | 26 +- .../r/nodes/builtin/base/AsInteger.java | 26 +- .../truffle/r/nodes/builtin/base/AsRaw.java | 131 +++------ .../truffle/r/nodes/builtin/base/Combine.java | 4 +- .../r/nodes/unary/CastComplexNode.java | 146 ++++++++-- .../truffle/r/nodes/unary/CastDoubleNode.java | 1 - .../r/nodes/unary/CastIntegerNode.java | 6 + .../truffle/r/nodes/unary/CastRawNode.java | 254 +++++++++++++++++- .../oracle/truffle/r/runtime/RRuntime.java | 85 +++--- .../r/runtime/data/RComplexVector.java | 6 + .../truffle/r/runtime/data/RRawVector.java | 6 + .../truffle/r/test/ExpectedTestOutput.test | 98 +++++++ .../oracle/truffle/r/test/all/AllTests.java | 106 +++++--- .../truffle/r/test/failing/FailingTests.java | 100 ++----- .../r/test/simple/TestSimpleBuiltins.java | 29 +- 17 files changed, 760 insertions(+), 374 deletions(-) diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java index 17707ee6d3..363281c3b6 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsCharacter.java @@ -37,19 +37,35 @@ public abstract class AsCharacter extends RBuiltinNode { @Child CastStringNode castStringNode; - private String castString(VirtualFrame frame, Object o) { + private void initCast() { if (castStringNode == null) { CompilerDirectives.transferToInterpreter(); castStringNode = adoptChild(CastStringNodeFactory.create(null, false, false, false)); } + } + + private String castString(VirtualFrame frame, int o) { + initCast(); + return (String) castStringNode.executeString(frame, o); + } + + private String castString(VirtualFrame frame, double o) { + initCast(); + return (String) castStringNode.executeString(frame, o); + } + + private String castString(VirtualFrame frame, byte o) { + initCast(); + return (String) castStringNode.executeString(frame, o); + } + + private String castString(VirtualFrame frame, Object o) { + initCast(); return (String) castStringNode.executeString(frame, o); } private RStringVector castStringVector(VirtualFrame frame, Object o) { - if (castStringNode == null) { - CompilerDirectives.transferToInterpreter(); - castStringNode = adoptChild(CastStringNodeFactory.create(null, false, false, false)); - } + initCast(); return (RStringVector) castStringNode.executeStringVector(frame, o); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsComplex.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsComplex.java index 0355db203a..34c956af3d 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsComplex.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsComplex.java @@ -29,40 +29,47 @@ import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.r.nodes.builtin.*; import com.oracle.truffle.r.nodes.unary.*; import com.oracle.truffle.r.runtime.data.*; +import com.oracle.truffle.r.runtime.data.model.*; import com.oracle.truffle.r.runtime.ops.na.*; @RBuiltin("as.complex") @SuppressWarnings("unused") public abstract class AsComplex extends RBuiltinNode { - private final NACheck check; - @Child CastComplexNode castComplexNode; public abstract RComplexVector executeRComplexVector(VirtualFrame frame, Object o) throws UnexpectedResultException; - private RComplex castComplex(VirtualFrame frame, Object o) { + private void initCast() { if (castComplexNode == null) { CompilerDirectives.transferToInterpreter(); - castComplexNode = adoptChild(CastComplexNodeFactory.create(null)); + castComplexNode = adoptChild(CastComplexNodeFactory.create(null, false, false)); } + } + + private RComplex castComplex(VirtualFrame frame, int o) { + initCast(); return (RComplex) castComplexNode.executeComplex(frame, o); } - private RComplexVector castComplexVector(VirtualFrame frame, Object o) { - if (castComplexNode == null) { - CompilerDirectives.transferToInterpreter(); - castComplexNode = adoptChild(CastComplexNodeFactory.create(null)); - } - return (RComplexVector) castComplexNode.executeComplexVector(frame, o); + private RComplex castComplex(VirtualFrame frame, double o) { + initCast(); + return (RComplex) castComplexNode.executeComplex(frame, o); } - protected AsComplex() { - this.check = NACheck.create(); + private RComplex castComplex(VirtualFrame frame, byte o) { + initCast(); + return (RComplex) castComplexNode.executeComplex(frame, o); } - protected AsComplex(AsComplex other) { - this.check = other.check; + private RComplex castComplex(VirtualFrame frame, Object o) { + initCast(); + return (RComplex) castComplexNode.executeComplex(frame, o); + } + + private RComplexVector castComplexVector(VirtualFrame frame, Object o) { + initCast(); + return (RComplexVector) castComplexNode.executeComplexVector(frame, o); } @Specialization @@ -71,21 +78,18 @@ public abstract class AsComplex extends RBuiltinNode { } @Specialization - public RComplex doInt(int value) { - check.enable(value); - return check.convertIntToComplex(value); + public RComplex doInt(VirtualFrame frame, int value) { + return castComplex(frame, value); } @Specialization - public RComplex doDouble(double value) { - check.enable(value); - return check.convertDoubleToComplex(value); + public RComplex doDouble(VirtualFrame frame, double value) { + return castComplex(frame, value); } @Specialization - public RComplex doLogical(byte value) { - check.enable(value); - return check.convertLogicalToComplex(value); + public RComplex doLogical(VirtualFrame frame, byte value) { + return castComplex(frame, value); } @Specialization @@ -100,41 +104,11 @@ public abstract class AsComplex extends RBuiltinNode { @Specialization public RComplexVector doComplexVector(VirtualFrame frame, RComplexVector vector) { - return vector; - } - - @Specialization - public RComplexVector doIntVector(VirtualFrame frame, RIntVector vector) { - return castComplexVector(frame, vector); - } - - @Specialization - public RComplexVector doDoubleVector(VirtualFrame frame, RDoubleVector vector) { - return castComplexVector(frame, vector); - } - - @Specialization - public RComplexVector doLogicalVector(VirtualFrame frame, RLogicalVector vector) { - return castComplexVector(frame, vector); + return RDataFactory.createComplexVector(vector.getDataCopy(), vector.isComplete()); } @Specialization - public RComplexVector doRawVector(VirtualFrame frame, RRawVector vector) { + public RComplexVector doIntVector(VirtualFrame frame, RAbstractVector vector) { return castComplexVector(frame, vector); } - - @Specialization - public RComplexVector doStringVector(VirtualFrame frame, RStringVector vector) { - return castComplexVector(frame, vector); - } - - @Specialization - public RComplexVector doIntSequence(VirtualFrame frame, RIntSequence sequence) { - return castComplexVector(frame, sequence); - } - - @Specialization - public RComplexVector doDoubleSequence(VirtualFrame frame, RDoubleSequence sequence) { - return castComplexVector(frame, sequence); - } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java index 299a679801..ab0214a955 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsDouble.java @@ -39,43 +39,35 @@ public abstract class AsDouble extends RBuiltinNode { @Child CastDoubleNode castDoubleNode; - private double castDouble(VirtualFrame frame, int o) { + private void initCast() { if (castDoubleNode == null) { CompilerDirectives.transferToInterpreter(); castDoubleNode = adoptChild(CastDoubleNodeFactory.create(null, false, false)); } + } + + private double castDouble(VirtualFrame frame, int o) { + initCast(); return (double) castDoubleNode.executeDouble(frame, o); } private double castDouble(VirtualFrame frame, double o) { - if (castDoubleNode == null) { - CompilerDirectives.transferToInterpreter(); - castDoubleNode = adoptChild(CastDoubleNodeFactory.create(null, false, false)); - } + initCast(); return (double) castDoubleNode.executeDouble(frame, o); } private double castDouble(VirtualFrame frame, byte o) { - if (castDoubleNode == null) { - CompilerDirectives.transferToInterpreter(); - castDoubleNode = adoptChild(CastDoubleNodeFactory.create(null, false, false)); - } + initCast(); return (double) castDoubleNode.executeDouble(frame, o); } private double castDouble(VirtualFrame frame, Object o) { - if (castDoubleNode == null) { - CompilerDirectives.transferToInterpreter(); - castDoubleNode = adoptChild(CastDoubleNodeFactory.create(null, false, false)); - } + initCast(); return (double) castDoubleNode.executeDouble(frame, o); } private RDoubleVector castDoubleVector(VirtualFrame frame, Object o) { - if (castDoubleNode == null) { - CompilerDirectives.transferToInterpreter(); - castDoubleNode = adoptChild(CastDoubleNodeFactory.create(null, false, false)); - } + initCast(); return (RDoubleVector) castDoubleNode.executeDoubleVector(frame, o); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java index 71303a640d..60a90f4120 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsInteger.java @@ -39,19 +39,35 @@ public abstract class AsInteger extends RBuiltinNode { @Child CastIntegerNode castIntNode; - private int castInt(VirtualFrame frame, Object o) { + private void initCast() { if (castIntNode == null) { CompilerDirectives.transferToInterpreter(); castIntNode = adoptChild(CastIntegerNodeFactory.create(null, false, false)); } + } + + private int castInt(VirtualFrame frame, int o) { + initCast(); + return (int) castIntNode.executeInt(frame, o); + } + + private int castInt(VirtualFrame frame, double o) { + initCast(); + return (int) castIntNode.executeInt(frame, o); + } + + private int castInt(VirtualFrame frame, byte o) { + initCast(); + return (int) castIntNode.executeInt(frame, o); + } + + private int castInt(VirtualFrame frame, Object o) { + initCast(); return (int) castIntNode.executeInt(frame, o); } private RIntVector castIntVector(VirtualFrame frame, Object o) { - if (castIntNode == null) { - CompilerDirectives.transferToInterpreter(); - castIntNode = adoptChild(CastIntegerNodeFactory.create(null, false, false)); - } + initCast(); return (RIntVector) castIntNode.executeIntVector(frame, o); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java index d3343e131d..e1aee4faeb 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/AsRaw.java @@ -36,144 +36,95 @@ import com.oracle.truffle.r.runtime.data.model.*; @SuppressWarnings("unused") public abstract class AsRaw extends RBuiltinNode { - @Child private AsRaw asRawRecursive; @Child private CastIntegerNode castInteger; - public abstract Object executeRaw(VirtualFrame frame, Object o); + @Child private CastRawNode castRawNode; - @Specialization - public RRawVector asRaw(RNull vector) { - return RDataFactory.createRawVector(0); + private void initCast() { + if (castRawNode == null) { + CompilerDirectives.transferToInterpreter(); + castRawNode = adoptChild(CastRawNodeFactory.create(null, false, false)); + } } - @Specialization - public RRaw asRaw(byte logical) { - if (RRuntime.isNA(logical)) { - // TODO: Output out-of-range warning. - return RDataFactory.createRaw((byte) 0); - } - return RDataFactory.createRaw(logical); + private RRaw castRaw(VirtualFrame frame, int o) { + initCast(); + return (RRaw) castRawNode.executeRaw(frame, o); } - @Specialization - public RRaw asRaw(int value) { - int result = (value & 0xFF); - if (result == value) { - return RDataFactory.createRaw((byte) result); - } - // TODO: Output out-of-range warning. - return RDataFactory.createRaw((byte) 0); + private RRaw castRaw(VirtualFrame frame, double o) { + initCast(); + return (RRaw) castRawNode.executeRaw(frame, o); } - @Specialization - public RRaw asRaw(double value) { - return asRaw((int) value); + private RRaw castRaw(VirtualFrame frame, byte o) { + initCast(); + return (RRaw) castRawNode.executeRaw(frame, o); } - @Specialization - public RRaw asRaw(RComplex value) { - // TODO: Output dropping of imaginary part warning if imaginary part not 0.0. - return asRaw(value.getRealPart()); + private RRaw castRaw(VirtualFrame frame, Object o) { + initCast(); + return (RRaw) castRawNode.executeRaw(frame, o); } - @Specialization - public RRaw asRaw(VirtualFrame frame, String value) { - // TODO: Output NA and out-of-range warning. - if (castInteger == null) { - CompilerDirectives.transferToInterpreter(); - castInteger = adoptChild(CastIntegerNodeFactory.create(null, false, false)); - } - return asRaw((int) castInteger.executeInt(frame, value)); + private RRawVector castRawVector(VirtualFrame frame, Object o) { + initCast(); + return (RRawVector) castRawNode.executeRawVector(frame, o); } + public abstract RRaw executeRaw(VirtualFrame frame, Object o); + @Specialization - public RRaw asRaw(RRaw value) { - return value; + public RRawVector asRaw(RNull vector) { + return RDataFactory.createRawVector(0); } @Specialization - public RRawVector asRaw(RIntVector vector) { - return performAbstractIntVector(vector); + public RRaw asRaw(VirtualFrame frame, byte logical) { + return castRaw(frame, logical); } @Specialization - public RRawVector asRaw(RIntSequence vector) { - return performAbstractIntVector(vector); + public RRaw asRaw(VirtualFrame frame, int value) { + return castRaw(frame, value); } @Specialization - public RRawVector asRaw(RDoubleSequence vector) { - return performAbstractDoubleVector(vector); + public RRaw asRaw(VirtualFrame frame, double value) { + return castRaw(frame, value); } @Specialization - public RRawVector asRaw(RDoubleVector vector) { - return performAbstractDoubleVector(vector); + public RRaw asRaw(VirtualFrame frame, RComplex value) { + return castRaw(frame, value); } @Specialization - public RRawVector asRaw(RStringVector vector) { - int length = vector.getLength(); - RRawVector result = RDataFactory.createRawVector(length); - for (int i = 0; i < length; i++) { - result.updateDataAt(i, RDataFactory.createRaw((byte) 0)); - } - return result; + public RRaw asRaw(VirtualFrame frame, String value) { + return castRaw(frame, value); } @Specialization - public RRawVector asRaw(RLogicalVector vector) { - int length = vector.getLength(); - RRawVector result = RDataFactory.createRawVector(length); - for (int i = 0; i < length; i++) { - result.updateDataAt(i, asRaw(vector.getDataAt(i))); - } - return result; + public RRaw asRaw(RRaw value) { + return value; } @Specialization - public RRawVector asRaw(RComplexVector vector) { - int length = vector.getLength(); - RRawVector result = RDataFactory.createRawVector(length); - for (int i = 0; i < length; i++) { - result.updateDataAt(i, asRaw(vector.getDataAt(i))); - } - return result; + public RRawVector asRaw(VirtualFrame frame, RAbstractVector vector) { + return castRawVector(frame, vector); } @Specialization public RRawVector asRaw(RRawVector value) { - return value; + return RDataFactory.createRawVector(value.getDataCopy()); } @Specialization public RRawVector asRaw(VirtualFrame frame, RList value) { - if (asRawRecursive == null) { - CompilerDirectives.transferToInterpreter(); - asRawRecursive = adoptChild(AsRawFactory.create(new RNode[1], getBuiltin())); - } int length = value.getLength(); RRawVector result = RDataFactory.createRawVector(length); for (int i = 0; i < length; ++i) { - result.updateDataAt(i, (RRaw) asRawRecursive.executeRaw(frame, value.getDataAt(i))); - } - return result; - } - - private RRawVector performAbstractIntVector(RAbstractIntVector vector) { - int length = vector.getLength(); - RRawVector result = RDataFactory.createRawVector(length); - for (int i = 0; i < length; i++) { - result.updateDataAt(i, asRaw(vector.getDataAt(i))); - } - return result; - } - - private RRawVector performAbstractDoubleVector(RAbstractDoubleVector vector) { - int length = vector.getLength(); - RRawVector result = RDataFactory.createRawVector(length); - for (int i = 0; i < length; i++) { - result.updateDataAt(i, asRaw(vector.getDataAt(i))); + result.updateDataAt(i, castRaw(frame, value.getDataAt(i))); } return result; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java index 52a1d5c0ff..10c93c4624 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java @@ -256,7 +256,7 @@ public abstract class Combine extends RBuiltinNode { private Object castComplex(VirtualFrame frame, Object operand) { if (castComplex == null) { CompilerDirectives.transferToInterpreter(); - castComplex = adoptChild(CastComplexNodeFactory.create(null)); + castComplex = adoptChild(CastComplexNodeFactory.create(null, true, false)); } return castComplex.executeCast(frame, operand); } @@ -296,7 +296,7 @@ public abstract class Combine extends RBuiltinNode { private Object castRaw(VirtualFrame frame, Object operand) { if (castRaw == null) { CompilerDirectives.transferToInterpreter(); - castRaw = adoptChild(CastRawNodeFactory.create(null)); + castRaw = adoptChild(CastRawNodeFactory.create(null, true, false)); } return castRaw.executeCast(frame, operand); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastComplexNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastComplexNode.java index 4d17675204..ea8f2c4f04 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastComplexNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastComplexNode.java @@ -26,18 +26,38 @@ import com.oracle.truffle.api.*; import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.r.nodes.unary.ConvertNode.*; +import com.oracle.truffle.r.runtime.*; import com.oracle.truffle.r.runtime.data.*; import com.oracle.truffle.r.runtime.data.model.*; import com.oracle.truffle.r.runtime.ops.na.*; +@NodeFields({@NodeField(name = "namesPreservation", type = boolean.class), @NodeField(name = "dimensionsPreservation", type = boolean.class)}) public abstract class CastComplexNode extends CastNode { private final NACheck naCheck = NACheck.create(); + public abstract Object executeComplex(VirtualFrame frame, int o); + + public abstract Object executeComplex(VirtualFrame frame, double o); + + public abstract Object executeComplex(VirtualFrame frame, byte o); + public abstract Object executeComplex(VirtualFrame frame, Object o); public abstract Object executeComplexVector(VirtualFrame frame, Object o); + protected abstract boolean isNamesPreservation(); + + protected abstract boolean isDimensionsPreservation(); + + protected boolean preserveNames() { + return isNamesPreservation(); + } + + protected boolean preserveDimensions() { + return isDimensionsPreservation(); + } + @Specialization public RNull doNull(@SuppressWarnings("unused") RNull operand) { return RNull.instance; @@ -74,21 +94,14 @@ public abstract class CastComplexNode extends CastNode { @Specialization(order = 6) public RComplex doCharacter(String operand) { naCheck.enable(operand); - return naCheck.convertStringToComplex(operand); - } - - @Specialization - public RComplexVector doIntVector(RIntVector operand) { - return performAbstractIntVector(operand); - } - - @Specialization - public RComplexVector doIntSequence(RIntSequence operand) { - return performAbstractIntVector(operand); + RComplex result = naCheck.convertStringToComplex(operand); + if (RRuntime.isNA(result)) { + RContext.getInstance().setEvalWarning(RError.NA_INTRODUCED_COERCION); + } + return result; } - @Specialization - public RComplexVector doLogicalVector(RLogicalVector operand) { + private double[] dataFromLogical(RLogicalVector operand) { naCheck.enable(operand); double[] ddata = new double[operand.getLength() << 1]; for (int i = 0; i < operand.getLength(); i++) { @@ -98,21 +111,80 @@ public abstract class CastComplexNode extends CastNode { ddata[index] = complexValue.getRealPart(); ddata[index + 1] = complexValue.getImaginaryPart(); } - return RDataFactory.createComplexVector(ddata, operand.isComplete(), operand.getNames()); + return ddata; } - @Specialization - public RComplexVector doStringVector(RStringVector operand) { + private double[] dataFromString(RStringVector operand) { naCheck.enable(operand); double[] ddata = new double[operand.getLength() << 1]; for (int i = 0; i < operand.getLength(); i++) { String value = operand.getDataAt(i); RComplex complexValue = naCheck.convertStringToComplex(value); + if (RRuntime.isNA(complexValue)) { + RContext.getInstance().setEvalWarning(RError.NA_INTRODUCED_COERCION); + } int index = i << 1; ddata[index] = complexValue.getRealPart(); ddata[index + 1] = complexValue.getImaginaryPart(); } - return RDataFactory.createComplexVector(ddata, operand.isComplete(), operand.getNames()); + return ddata; + } + + private static double[] dataFromRaw(RRawVector operand) { + double[] ddata = new double[operand.getLength() << 1]; + for (int i = 0; i < operand.getLength(); i++) { + byte value = operand.getDataAt(i).getValue(); + int index = i << 1; + ddata[index] = value; + ddata[index + 1] = 0; + } + return ddata; + } + + @Specialization + public RComplexVector doIntVector(RIntVector operand) { + return performAbstractIntVector(operand); + } + + @Specialization + public RComplexVector doIntSequence(RIntSequence operand) { + return performAbstractIntVector(operand); + } + + @Specialization(order = 101, guards = "preserveDimensions") + public RComplexVector doLogicalVectorDims(RLogicalVector operand) { + double[] ddata = dataFromLogical(operand); + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getDimensions()); + } + + @Specialization(order = 102, guards = "preserveNames") + public RComplexVector doLogicalVectorNames(RLogicalVector operand) { + double[] ddata = dataFromLogical(operand); + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getNames()); + } + + @Specialization(order = 103) + public RComplexVector doLogicalVector(RLogicalVector operand) { + double[] ddata = dataFromLogical(operand); + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA()); + } + + @Specialization(order = 104, guards = "preserveDimensions") + public RComplexVector doStringVectorDims(RStringVector operand) { + double[] ddata = dataFromString(operand); + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getDimensions()); + } + + @Specialization(order = 105, guards = "preserveNames") + public RComplexVector doStringVectorNames(RStringVector operand) { + double[] ddata = dataFromString(operand); + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getNames()); + } + + @Specialization(order = 106) + public RComplexVector doStringVector(RStringVector operand) { + double[] ddata = dataFromString(operand); + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA()); } @Specialization @@ -130,18 +202,24 @@ public abstract class CastComplexNode extends CastNode { return vector; } - @Specialization - public RComplexVector doRawVector(RRawVector operand) { - double[] ddata = new double[operand.getLength() << 1]; - for (int i = 0; i < operand.getLength(); i++) { - byte value = operand.getDataAt(i).getValue(); - int index = i << 1; - ddata[index] = value; - ddata[index + 1] = 0; - } + @Specialization(order = 107, guards = "preserveDimensions") + public RComplexVector doRawVectorDims(RRawVector operand) { + double[] ddata = dataFromRaw(operand); + return RDataFactory.createComplexVector(ddata, RDataFactory.COMPLETE_VECTOR, operand.getDimensions()); + } + + @Specialization(order = 108, guards = "preserveNames") + public RComplexVector doRawVectorNames(RRawVector operand) { + double[] ddata = dataFromRaw(operand); return RDataFactory.createComplexVector(ddata, RDataFactory.COMPLETE_VECTOR, operand.getNames()); } + @Specialization(order = 109) + public RComplexVector doRawVector(RRawVector operand) { + double[] ddata = dataFromRaw(operand); + return RDataFactory.createComplexVector(ddata, RDataFactory.COMPLETE_VECTOR); + } + @Generic public int doOther(Object operand) { CompilerDirectives.transferToInterpreter(); @@ -158,7 +236,13 @@ public abstract class CastComplexNode extends CastNode { ddata[index] = complexValue.getRealPart(); ddata[index + 1] = complexValue.getImaginaryPart(); } - return RDataFactory.createComplexVector(ddata, operand.isComplete(), operand.getNames()); + if (preserveDimensions()) { + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getDimensions()); + } else if (preserveNames()) { + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getNames()); + } else { + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA()); + } } private RComplexVector performAbstractDoubleVector(RAbstractDoubleVector operand) { @@ -171,7 +255,13 @@ public abstract class CastComplexNode extends CastNode { ddata[index] = complexValue.getRealPart(); ddata[index + 1] = complexValue.getImaginaryPart(); } - return RDataFactory.createComplexVector(ddata, operand.isComplete(), operand.getNames()); + if (preserveDimensions()) { + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getDimensions()); + } else if (preserveNames()) { + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA(), operand.getNames()); + } else { + return RDataFactory.createComplexVector(ddata, naCheck.neverSeenNA()); + } } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastDoubleNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastDoubleNode.java index 4e9e623a75..15897f20a1 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastDoubleNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastDoubleNode.java @@ -271,5 +271,4 @@ public abstract class CastDoubleNode extends CastNode { return RDataFactory.createDoubleVector(ddata, naCheck.neverSeenNA()); } } - } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java index d686e5d1dc..77500f191b 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastIntegerNode.java @@ -35,6 +35,12 @@ public abstract class CastIntegerNode extends CastNode { private final NACheck check = NACheck.create(); + public abstract Object executeInt(VirtualFrame frame, int o); + + public abstract Object executeInt(VirtualFrame frame, double o); + + public abstract Object executeInt(VirtualFrame frame, byte o); + public abstract Object executeInt(VirtualFrame frame, Object o); public abstract Object executeIntVector(VirtualFrame frame, Object o); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastRawNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastRawNode.java index fbec887241..07745a17b2 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastRawNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/CastRawNode.java @@ -24,12 +24,37 @@ package com.oracle.truffle.r.nodes.unary; import com.oracle.truffle.api.*; import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; import com.oracle.truffle.r.nodes.unary.ConvertNode.*; +import com.oracle.truffle.r.runtime.*; import com.oracle.truffle.r.runtime.data.*; import com.oracle.truffle.r.runtime.data.model.*; +@NodeFields({@NodeField(name = "namesPreservation", type = boolean.class), @NodeField(name = "dimensionsPreservation", type = boolean.class)}) public abstract class CastRawNode extends CastNode { + protected abstract boolean isNamesPreservation(); + + protected abstract boolean isDimensionsPreservation(); + + public abstract Object executeRaw(VirtualFrame frame, int o); + + public abstract Object executeRaw(VirtualFrame frame, double o); + + public abstract Object executeRaw(VirtualFrame frame, byte o); + + public abstract Object executeRaw(VirtualFrame frame, Object o); + + public abstract Object executeRawVector(VirtualFrame frame, Object o); + + protected boolean preserveNames() { + return isNamesPreservation(); + } + + protected boolean preserveDimensions() { + return isDimensionsPreservation(); + } + @Specialization public RNull doNull(@SuppressWarnings("unused") RNull operand) { return RNull.instance; @@ -37,7 +62,119 @@ public abstract class CastRawNode extends CastNode { @Specialization public RRaw doInt(int operand) { - return RDataFactory.createRaw((byte) operand); + int intResult = RRuntime.int2rawIntValue(operand); + if (intResult != operand) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + return RDataFactory.createRaw((byte) intResult); + } + + @Specialization + public RRaw doDouble(double operand) { + int intResult = RRuntime.double2rawIntValue(operand); + if (intResult != (int) operand) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + return RDataFactory.createRaw((byte) intResult); + } + + @Specialization + public RRaw doComplex(RComplex operand) { + int intResult = RRuntime.complex2rawIntValue(operand); + if (operand.getImaginaryPart() != 0) { + RContext.getInstance().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION); + } + if (intResult != (int) operand.getRealPart()) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + return RDataFactory.createRaw((byte) intResult); + } + + @Specialization + public RRaw doRaw(RRaw operand) { + return operand; + } + + @Specialization + public RRaw doLogical(byte operand) { + // need to convert to int so that NA-related warning is caught + int intVal = RRuntime.logical2int(operand); + return doInt(intVal); + } + + @Specialization + public RRaw doString(String operand) { + // need to cast to int to catch conversion warnings + int intVal = RRuntime.string2int(operand); + if (RRuntime.isNA(intVal)) { + RContext.getInstance().setEvalWarning(RError.NA_INTRODUCED_COERCION); + } + return doInt(intVal); + } + + private static byte[] dataFromComplex(RComplexVector operand) { + byte[] bdata = new byte[operand.getLength()]; + boolean imaginaryDiscardedWarning = false; + boolean outOfRangeWarning = false; + for (int i = 0; i < operand.getLength(); i++) { + RComplex complexVal = operand.getDataAt(i); + int intRawValue = RRuntime.complex2rawIntValue(complexVal); + if (complexVal.getImaginaryPart() != 0.0) { + imaginaryDiscardedWarning = true; + } + if ((int) complexVal.getRealPart() != intRawValue) { + outOfRangeWarning = true; + } + bdata[i] = (byte) intRawValue; + } + if (imaginaryDiscardedWarning) { + RContext.getInstance().setEvalWarning(RError.IMAGINARY_PARTS_DISCARDED_IN_COERCION); + } + if (outOfRangeWarning) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + return bdata; + } + + private static byte[] dataFromLogical(RLogicalVector operand) { + byte[] bdata = new byte[operand.getLength()]; + boolean warning = false; + for (int i = 0; i < operand.getLength(); i++) { + int intVal = RRuntime.logical2int(operand.getDataAt(i)); + int intRawValue = RRuntime.int2rawIntValue(intVal); + if (intVal != intRawValue) { + warning = true; + } + bdata[i] = (byte) intRawValue; + } + if (warning) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + return bdata; + } + + private static byte[] dataFromString(RStringVector operand) { + byte[] bdata = new byte[operand.getLength()]; + boolean naCoercionWarning = false; + boolean outOfRangeWarning = false; + for (int i = 0; i < operand.getLength(); i++) { + int intVal = RRuntime.string2int(operand.getDataAt(i)); + int intRawValue = RRuntime.int2rawIntValue(intVal); + if (RRuntime.isNA(intVal)) { + naCoercionWarning = true; + } + if (intVal != intRawValue) { + outOfRangeWarning = true; + } + bdata[i] = (byte) intRawValue; + } + if (naCoercionWarning) { + RContext.getInstance().setEvalWarning(RError.NA_INTRODUCED_COERCION); + } + if (outOfRangeWarning) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + return bdata; } @Specialization @@ -50,23 +187,68 @@ public abstract class CastRawNode extends CastNode { return performAbstractIntVector(value); } - private static RRawVector performAbstractIntVector(RAbstractIntVector value) { - int length = value.getLength(); - byte[] array = new byte[length]; - for (int i = 0; i < length; ++i) { - array[i] = (byte) value.getDataAt(i); - } - return RDataFactory.createRawVector(array, value.getNames()); + @Specialization(order = 101, guards = "preserveDimensions") + public RRawVector doLogicalVectorDims(RLogicalVector operand) { + byte[] bdata = dataFromLogical(operand); + return RDataFactory.createRawVector(bdata, operand.getDimensions()); + } + + @Specialization(order = 102, guards = "preserveNames") + public RRawVector doLogicalVectorNames(RLogicalVector operand) { + byte[] bdata = dataFromLogical(operand); + return RDataFactory.createRawVector(bdata, operand.getNames()); + } + + @Specialization(order = 103) + public RRawVector doLogicalVector(RLogicalVector operand) { + byte[] bdata = dataFromLogical(operand); + return RDataFactory.createRawVector(bdata); + } + + @Specialization(order = 104, guards = "preserveDimensions") + public RRawVector doStringVectorDims(RStringVector operand) { + byte[] bdata = dataFromString(operand); + return RDataFactory.createRawVector(bdata, operand.getDimensions()); + } + + @Specialization(order = 105, guards = "preserveNames") + public RRawVector doStringVectorNames(RStringVector operand) { + byte[] bdata = dataFromString(operand); + return RDataFactory.createRawVector(bdata, operand.getNames()); + } + + @Specialization(order = 106) + public RRawVector doStringVector(RStringVector operand) { + byte[] bdata = dataFromString(operand); + return RDataFactory.createRawVector(bdata); + } + + @Specialization(order = 107, guards = "preserveDimensions") + public RRawVector doRawVectorDims(RComplexVector operand) { + byte[] bdata = dataFromComplex(operand); + return RDataFactory.createRawVector(bdata, operand.getDimensions()); + } + + @Specialization(order = 108, guards = "preserveNames") + public RRawVector doComplexVectorNames(RComplexVector operand) { + byte[] bdata = dataFromComplex(operand); + return RDataFactory.createRawVector(bdata, operand.getNames()); + } + + @Specialization(order = 109) + public RRawVector doComplexVector(RComplexVector operand) { + byte[] bdata = dataFromComplex(operand); + return RDataFactory.createRawVector(bdata); } @Specialization - public RRaw doBoolean(byte operand) { - return RDataFactory.createRaw(operand); + public RRawVector doDoubleVector(RDoubleVector value) { + return performAbstractDoubleVector(value); } @Specialization - public RRaw doRaw(RRaw operand) { - return operand; + public RRawVector doDoubleSequence(RDoubleSequence value) { + return performAbstractDoubleVector(value); } @Specialization @@ -80,4 +262,52 @@ public abstract class CastRawNode extends CastNode { throw new ConversionFailedException(operand.getClass().getName()); } + private RRawVector performAbstractIntVector(RAbstractIntVector value) { + int length = value.getLength(); + byte[] array = new byte[length]; + boolean warning = false; + for (int i = 0; i < length; ++i) { + int intValue = value.getDataAt(i); + int intRawValue = RRuntime.int2rawIntValue(intValue); + if (intRawValue != intValue) { + warning = true; + } + array[i] = (byte) intRawValue; + } + if (warning) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + if (preserveDimensions()) { + return RDataFactory.createRawVector(array, value.getDimensions()); + } else if (preserveNames()) { + return RDataFactory.createRawVector(array, value.getNames()); + } else { + return RDataFactory.createRawVector(array); + } + } + + private RRawVector performAbstractDoubleVector(RAbstractDoubleVector value) { + int length = value.getLength(); + byte[] array = new byte[length]; + boolean warning = false; + for (int i = 0; i < length; ++i) { + double doubleValue = value.getDataAt(i); + int intRawValue = RRuntime.double2rawIntValue(doubleValue); + if (intRawValue != (int) doubleValue) { + warning = true; + } + array[i] = (byte) intRawValue; + } + if (warning) { + RContext.getInstance().setEvalWarning(RError.OUT_OF_RANGE); + } + if (preserveDimensions()) { + return RDataFactory.createRawVector(array, value.getDimensions()); + } else if (preserveNames()) { + return RDataFactory.createRawVector(array, value.getNames()); + } else { + return RDataFactory.createRawVector(array); + } + + } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java index 89cce30f97..431dc90021 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java @@ -131,7 +131,7 @@ public class RRuntime { } public static byte asLogical(boolean b) { - return b ? RRuntime.LOGICAL_TRUE : RRuntime.LOGICAL_FALSE; + return b ? LOGICAL_TRUE : LOGICAL_FALSE; } // conversions from logical @@ -141,7 +141,7 @@ public class RRuntime { } public static int logical2int(byte value) { - return isNA(value) ? RRuntime.INT_NA : logical2intNoCheck(value); + return isNA(value) ? INT_NA : logical2intNoCheck(value); } public static double logical2doubleNoCheck(byte value) { @@ -149,7 +149,7 @@ public class RRuntime { } public static double logical2double(byte value) { - return isNA(value) ? RRuntime.DOUBLE_NA : logical2doubleNoCheck(value); + return isNA(value) ? DOUBLE_NA : logical2doubleNoCheck(value); } public static RComplex logical2complexNoCheck(byte value) { @@ -161,7 +161,7 @@ public class RRuntime { } public static String logicalToStringNoCheck(byte operand) { - return operand == RRuntime.LOGICAL_TRUE ? "TRUE" : operand == RRuntime.LOGICAL_FALSE ? "FALSE" : STRING_NA; + return operand == LOGICAL_TRUE ? "TRUE" : operand == LOGICAL_FALSE ? "FALSE" : STRING_NA; } public static String logicalToString(byte operand) { @@ -171,7 +171,7 @@ public class RRuntime { // conversions from raw public static byte raw2logical(RRaw value) { - return value.getValue() == 0 ? RRuntime.LOGICAL_FALSE : RRuntime.LOGICAL_TRUE; + return value.getValue() == 0 ? LOGICAL_FALSE : LOGICAL_TRUE; } public static int raw2int(RRaw value) { @@ -204,11 +204,7 @@ public class RRuntime { } public static int string2int(String s) { - if (isNA(s)) { - return INT_NA; - } else { - return string2intNoCheck(s); - } + return isNA(s) ? INT_NA : string2intNoCheck(s); } public static double string2doubleNoCheck(String v) { @@ -263,32 +259,37 @@ public class RRuntime { @SlowPath public static RComplex string2complexNoCheck(String v) { - try { - int startIdx = 0; - char firstChar = v.charAt(0); - boolean negativeReal = firstChar == '-'; - if (firstChar == '+' || negativeReal) { - startIdx++; - } + double doubleValue = string2doubleNoCheck(v); + if (!RRuntime.isNA(doubleValue)) { + return RDataFactory.createComplex(doubleValue, 0.0); + } else { + try { + int startIdx = 0; + char firstChar = v.charAt(0); + boolean negativeReal = firstChar == '-'; + if (firstChar == '+' || negativeReal) { + startIdx++; + } - int plusIdx = v.indexOf("+", startIdx); - int minusIdx = v.indexOf("-", startIdx); - int iIdx = v.indexOf("i", startIdx); - int signIdx = getSignIdx(plusIdx, minusIdx); - boolean negativeImaginary = minusIdx > 0; + int plusIdx = v.indexOf("+", startIdx); + int minusIdx = v.indexOf("-", startIdx); + int iIdx = v.indexOf("i", startIdx); + int signIdx = getSignIdx(plusIdx, minusIdx); + boolean negativeImaginary = minusIdx > 0; - double realPart = Double.parseDouble(v.substring(startIdx, signIdx)); - double imaginaryPart = Double.parseDouble(v.substring(signIdx + 1, iIdx)); + double realPart = Double.parseDouble(v.substring(startIdx, signIdx)); + double imaginaryPart = Double.parseDouble(v.substring(signIdx + 1, iIdx)); - return RDataFactory.createComplex(realPart * (negativeReal ? -1 : 1), imaginaryPart * (negativeImaginary ? -1 : 1)); - } catch (NumberFormatException ex) { - return RRuntime.createComplexNA(); + return RDataFactory.createComplex(realPart * (negativeReal ? -1 : 1), imaginaryPart * (negativeImaginary ? -1 : 1)); + } catch (NumberFormatException ex) { + return createComplexNA(); + } } } @SlowPath public static RComplex string2complex(String v) { - return isNA(v) ? RRuntime.createComplexNA() : string2complexNoCheck(v); + return isNA(v) ? createComplexNA() : string2complexNoCheck(v); } // conversions from int @@ -327,6 +328,14 @@ public class RRuntime { return isNA(operand) ? STRING_NA : intToStringNoCheck(operand, appendL); } + public static int int2rawIntValue(int i) { + return isNA(i) ? 0 : i & 0xFF; + } + + public static RRaw int2raw(int i) { + return RDataFactory.createRaw((byte) int2rawIntValue(i)); + } + // conversions from double public static int double2intNoCheck(double d) { @@ -365,7 +374,7 @@ public class RRuntime { @SlowPath public static String doubleToStringNoCheck(double operand) { - if (RRuntime.doubleIsInt(operand)) { + if (doubleIsInt(operand)) { return String.valueOf((int) operand); } if (operand == Double.POSITIVE_INFINITY) { @@ -397,6 +406,14 @@ public class RRuntime { return isNA(operand) ? STRING_NA : doubleToStringNoCheck(operand); } + public static int double2rawIntValue(double operand) { + return isNA(operand) ? 0 : ((int) operand) & 0xFF; + } + + public static RRaw double2raw(double operand) { + return RDataFactory.createRaw((byte) double2rawIntValue(operand)); + } + // conversions from complex public static byte complex2logicalNoCheck(RComplex c) { @@ -433,6 +450,14 @@ public class RRuntime { return isNA(operand) ? STRING_NA : complexToStringNoCheck(operand); } + public static int complex2rawIntValue(RComplex c) { + return isNA(c) ? 0 : ((int) c.getRealPart() & 0xFF); + } + + public static RRaw complex2raw(RComplex c) { + return RDataFactory.createRaw((byte) complex2rawIntValue(c)); + } + private static int getSignIdx(int plusIdx, int minusIdx) throws NumberFormatException { if (plusIdx < 0) { if (minusIdx < 0) { @@ -510,7 +535,7 @@ public class RRuntime { @SlowPath public static String quoteString(String data) { - return data == RRuntime.STRING_NA ? RRuntime.STRING_NA : "\"" + data + "\""; + return data == STRING_NA ? STRING_NA : "\"" + data + "\""; } private static final class REmptyEnvironment extends REnvironment { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexVector.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexVector.java index 28679dad30..f48f636d97 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexVector.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RComplexVector.java @@ -74,6 +74,12 @@ public final class RComplexVector extends RVector implements RAbstractComplexVec return new RComplex(data[index], data[index + 1]); } + public double[] getDataCopy() { + double[] copy = new double[data.length]; + System.arraycopy(data, 0, copy, 0, data.length); + return copy; + } + public RComplexVector copyWithNewDimensions(int[] newDimensions) { return RDataFactory.createComplexVector(data, isComplete(), newDimensions); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawVector.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawVector.java index 1768deb636..0d11ee9e1a 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawVector.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RRawVector.java @@ -64,6 +64,12 @@ public final class RRawVector extends RVector implements RAbstractRawVector { return RDataFactory.createRaw(data[i]); } + public byte[] getDataCopy() { + byte[] copy = new byte[data.length]; + System.arraycopy(data, 0, copy, 0, data.length); + return copy; + } + public RRawVector copyWithNewDimensions(int[] newDimensions) { return RDataFactory.createRawVector(data, newDimensions); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 976fb2d57d..5cd0f73190 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -2299,10 +2299,28 @@ character(0) #{ as.complex("-1-5i") } [1] -1-5i +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ as.complex("0x42") } +[1] 66+0i + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex #{ as.complex("1+5i") } [1] 1+5i +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ as.complex("Inf") } +[1] Inf+0i + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ as.complex("NaN") } +[1] NaN+0i + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ as.complex("TRUE") } +[1] NA +Warning message: +NAs introduced by coercion + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex #{ as.complex(0) } [1] 0+0i @@ -2315,10 +2333,24 @@ character(0) #{ as.complex(TRUE) } [1] 1+0i +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ as.complex(c("1","hello")) } +[1] 1+0i NA +Warning message: +NAs introduced by coercion + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex #{ as.complex(c(0/0, 0/0)) } [1] NA NA +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ x<-c(a=1.1, b=2.2); dim(x)<-c(1,2); attr(x, "foo")<-"foo"; y<-as.complex(x); attributes(y) } +NULL + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsComplex +#{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, "foo")<-"foo"; y<-as.complex(x); attributes(y) } +NULL + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsDouble #{ as.double("1.27") } [1] 1.27 @@ -2501,6 +2533,10 @@ NULL #{ as.raw(1) } [1] 01 +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRaw +#{ as.raw(1.1) } +[1] 01 + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRaw #{ as.raw(1L) } [1] 01 @@ -2525,6 +2561,68 @@ raw(0) #{ as.raw(list(1,2,3)) } [1] 01 02 03 +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw("test") } +[1] 00 +Warning messages: +1: NAs introduced by coercion +2: out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(-1) } +[1] 00 +Warning message: +out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(-1L) } +[1] 00 +Warning message: +out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(1+1i) } +[1] 01 +Warning message: +imaginary parts discarded in coercion + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(NA) } +[1] 00 +Warning message: +out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(c(1+3i, -2-1i, NA)) } +[1] 01 00 00 +Warning messages: +1: imaginary parts discarded in coercion +2: out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(c(1, -2, 3)) } +[1] 01 00 03 +Warning message: +out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(c(1,1000,NA)) } +[1] 01 00 00 +Warning message: +out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(c(1L, -2L, 3L)) } +[1] 01 00 03 +Warning message: +out-of-range values treated as 0 in coercion to raw + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAsRawIgnore +#{ as.raw(c(1L, -2L, NA)) } +[1] 01 00 00 +Warning message: +out-of-range values treated as 0 in coercion to raw + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testAttributes #{ x <- 1 ; attributes(x) <- list(hi=3, hello=2) ; x } [1] 1 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java index 9b6cf461f9..9cf7d6e453 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/all/AllTests.java @@ -1339,22 +1339,17 @@ public class AllTests extends TestBase { } @Test - public void TestSimpleArithmetic_testScalarsComplexIgnore_ec41b305258209dcd1f01b4c73dfa38c() { + public void TestSimpleArithmetic_testScalarsComplex_ec41b305258209dcd1f01b4c73dfa38c() { assertEval("{ x <- 1+2i; y <- 3+4i; round(x*x*y/(x+y), digits=5) }"); } @Test - public void TestSimpleArithmetic_testScalarsComplexIgnore_3687279e543d6b321de708f1696d22d9() { - assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; round(y/x, digits=5) }"); - } - - @Test - public void TestSimpleArithmetic_testScalarsComplexIgnore_e04a6b232a786acb98dfb4218c363291() { + public void TestSimpleArithmetic_testScalarsComplex_e04a6b232a786acb98dfb4218c363291() { assertEval("{ round( (1+2i)^(3+4i), digits=5 ) }"); } @Test - public void TestSimpleArithmetic_testScalarsComplexIgnore_b962b71eb5d225af35b575db321f93dc() { + public void TestSimpleArithmetic_testScalarsComplex_b962b71eb5d225af35b575db321f93dc() { assertEval("{ round( ((1+1i)/(0+1i)) ^ (-3.54), digits=5) }"); } @@ -1368,6 +1363,11 @@ public class AllTests extends TestBase { assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; y*x }"); } + @Test + public void TestSimpleArithmetic_testScalarsComplexIgnore_3687279e543d6b321de708f1696d22d9() { + assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; round(y/x, digits=5) }"); + } + @Test public void TestSimpleArithmetic_testScalarsRange_dd5eca5b8772a13dc278f20c915b60db() { assertEval("{ f <- function(a, b) { a + b } ; f(c(1,2), c(3,4)) ; f(c(1,2), 3:4) }"); @@ -2238,21 +2238,11 @@ public class AllTests extends TestBase { assertEval("{ z <- c(1+1i,3+2i) ; z * c(1,2) }"); } - @Test - public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_26cbb52252ff028ab7bba252147de26c() { - assertEval("{ round(c(1+1i,2+3i)^c(1+1i,3+4i), digits = 5) }"); - } - @Test public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_9b81d167391e44e04a528a367013f806() { assertEval("{ z <- c(-1.5-1i,10) ; (z * z)[1] }"); } - @Test - public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_a88a08c3bbe4807e9507763726c626e5() { - assertEval("{ round( 3^c(1,2,3+1i), digits=5 ) }"); - } - @Test public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_0dae874162cc69c107cdd6f0c5ea334c() { assertEval("{ c(1+1i,3+2i) / 2 }"); @@ -2263,6 +2253,16 @@ public class AllTests extends TestBase { assertEval("{ c(1,2,3+1i)^3 }"); } + @Test + public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_26cbb52252ff028ab7bba252147de26c() { + assertEval("{ round(c(1+1i,2+3i)^c(1+1i,3+4i), digits = 5) }"); + } + + @Test + public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_a88a08c3bbe4807e9507763726c626e5() { + assertEval("{ round( 3^c(1,2,3+1i), digits=5 ) }"); + } + @Test public void TestSimpleArithmetic_testVectorsOperationsIgnore_bc2cc92da6012e61c40e913719b41e8a() { assertEval("{ c(1,3) / c(2,4) }"); @@ -4148,6 +4148,41 @@ public class AllTests extends TestBase { assertEval("{ as.complex(c(0/0, 0/0)) }"); } + @Test + public void TestSimpleBuiltins_testAsComplex_b6b94ce72b18de1ff03ebe7feeb17554() { + assertEval("{ x<-c(a=1.1, b=2.2); dim(x)<-c(1,2); attr(x, \"foo\")<-\"foo\"; y<-as.complex(x); attributes(y) }"); + } + + @Test + public void TestSimpleBuiltins_testAsComplex_8ffbf32e73519b2e78880c77bb680ced() { + assertEval("{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, \"foo\")<-\"foo\"; y<-as.complex(x); attributes(y) }"); + } + + @Test + public void TestSimpleBuiltins_testAsComplex_1c161837613fc8eb032e82d2847d699a() { + assertEval("{ as.complex(\"Inf\") }"); + } + + @Test + public void TestSimpleBuiltins_testAsComplex_09a336b246204913af2ac217bb9c8a39() { + assertEval("{ as.complex(\"NaN\") }"); + } + + @Test + public void TestSimpleBuiltins_testAsComplex_a8ce6a3e28ddb6e5b3050aa2adb56f87() { + assertEval("{ as.complex(\"0x42\") }"); + } + + @Test + public void TestSimpleBuiltins_testAsComplex_a956418be2f92dc147b9880ee38a0baa() { + assertEvalWarning("{ as.complex(c(\"1\",\"hello\")) }"); + } + + @Test + public void TestSimpleBuiltins_testAsComplex_0e40e701e12f7aaf40302968a93162c8() { + assertEvalWarning("{ as.complex(\"TRUE\") }"); + } + @Test public void TestSimpleBuiltins_testAsComplexIgnore_a234b535de865dc1374d86dc2a304cb0() { assertEval("{ as.complex(\"1e10+5i\") }"); @@ -4378,6 +4413,11 @@ public class AllTests extends TestBase { assertEval("{ as.raw(1L) }"); } + @Test + public void TestSimpleBuiltins_testAsRaw_810e96ba01dde0b9203a17a350b5ca70() { + assertEval("{ as.raw(1.1) }"); + } + @Test public void TestSimpleBuiltins_testAsRaw_535958221e3ffa3f60a58fb378e2204b() { assertEval("{ as.raw(c(1, 2, 3)) }"); @@ -4400,52 +4440,52 @@ public class AllTests extends TestBase { @Test public void TestSimpleBuiltins_testAsRawIgnore_234cefc5ff95e036f3fa00ff5e0f2088() { - assertEval("{ as.raw(1+1i) }"); + assertEvalWarning("{ as.raw(1+1i) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_6cd26c8e6df8ead2edcbb6df45860698() { - assertEval("{ as.raw(-1) }"); + assertEvalWarning("{ as.raw(-1) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_b2f6c512a8b92fcc2861d16b643c77e8() { - assertEval("{ as.raw(-1L) }"); + assertEvalWarning("{ as.raw(-1L) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_6e315b6de04235063bc8e0be93dc9780() { - assertEval("{ as.raw(NA) }"); + assertEvalWarning("{ as.raw(NA) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_3dced2b189d4bc08910497a4c84f8eaf() { - assertEval("{ as.raw(\"test\") }"); + assertEvalWarning("{ as.raw(\"test\") }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_75c975b8a03a598a4af0a0a332d02b71() { - assertEval("{ as.raw(c(1+3i, -2-1i, NA)) }"); + assertEvalWarning("{ as.raw(c(1+3i, -2-1i, NA)) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_747e8b9acbda8dd5dc02ce1274604e0c() { - assertEval("{ as.raw(c(1, -2, 3)) }"); + assertEvalWarning("{ as.raw(c(1, -2, 3)) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_ad6deee1d16519ee2ce790bb577709d2() { - assertEval("{ as.raw(c(1,1000,NA)) }"); + assertEvalWarning("{ as.raw(c(1,1000,NA)) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_d799cae365e5f001ed4de47c2cbbff01() { - assertEval("{ as.raw(c(1L, -2L, 3L)) }"); + assertEvalWarning("{ as.raw(c(1L, -2L, 3L)) }"); } @Test public void TestSimpleBuiltins_testAsRawIgnore_05185c7c12248d279730674e3b527d86() { - assertEval("{ as.raw(c(1L, -2L, NA)) }"); + assertEvalWarning("{ as.raw(c(1L, -2L, NA)) }"); } @Test @@ -15668,6 +15708,11 @@ public class AllTests extends TestBase { assertEval("{ x <- \"hi\"; y<-c(1,1) ; x[y] }"); } + @Test + public void TestSimpleVectors_testVectorIndex_735c444595fe843fd5efb95ee1f0a3bd() { + assertEval("{ l <- list(1,function(){3}) ; f <- function(i) { l[[i]] } ; f(c(2)) }"); + } + @Test public void TestSimpleVectors_testVectorIndexIgnore_1d6d1e8273a075727e7f7ee39bf9060e() { assertEval(" { f <- function(b,i) { b[i] } ; f(c(a=1,b=2,c=3), c(TRUE,NA)) }"); @@ -15883,11 +15928,6 @@ public class AllTests extends TestBase { assertEval("{ l <- list(1,list(2)) ; f <- function(i) { l[[i]] } ; f(c(2,1)) ; f(1) }"); } - @Test - public void TestSimpleVectors_testVectorIndexIgnore_735c444595fe843fd5efb95ee1f0a3bd() { - assertEval("{ l <- list(1,function(){3}) ; f <- function(i) { l[[i]] } ; f(c(2)) }"); - } - @Test public void TestSimpleVectors_testVectorIndexIgnore_1f99c587df8881ae8bb4134fbb911f66() { assertEval("{ f <- function(i) { l[[i]] } ; l <- list(1, as.list(1:3)) ; f(c(2,NA)) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java index 94f6214b56..ce36eee586 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/failing/FailingTests.java @@ -263,26 +263,6 @@ public class FailingTests extends TestBase { assertEval("{ f <- function(a,b) { a && b } ; f(c(TRUE, FALSE), logical()) ; f(TRUE, c(TRUE,TRUE,FALSE)) ; f(1,2) }"); } - @Ignore - public void TestSimpleArithmetic_testScalarsComplexIgnore_ec41b305258209dcd1f01b4c73dfa38c() { - assertEval("{ x <- 1+2i; y <- 3+4i; round(x*x*y/(x+y), digits=5) }"); - } - - @Ignore - public void TestSimpleArithmetic_testScalarsComplexIgnore_3687279e543d6b321de708f1696d22d9() { - assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; round(y/x, digits=5) }"); - } - - @Ignore - public void TestSimpleArithmetic_testScalarsComplexIgnore_e04a6b232a786acb98dfb4218c363291() { - assertEval("{ round( (1+2i)^(3+4i), digits=5 ) }"); - } - - @Ignore - public void TestSimpleArithmetic_testScalarsComplexIgnore_b962b71eb5d225af35b575db321f93dc() { - assertEval("{ round( ((1+1i)/(0+1i)) ^ (-3.54), digits=5) }"); - } - @Ignore public void TestSimpleArithmetic_testScalarsComplexIgnore_0dc33376658fd492af2c5beb032efdbf() { assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; y+x }"); @@ -293,6 +273,11 @@ public class FailingTests extends TestBase { assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; y*x }"); } + @Ignore + public void TestSimpleArithmetic_testScalarsComplexIgnore_3687279e543d6b321de708f1696d22d9() { + assertEval("{ x <- c(-1-2i,3+10i) ; y <- c(3+1i, -4+5i) ; round(y/x, digits=5) }"); + } + @Ignore public void TestSimpleArithmetic_testScalarsRealIgnore_706f889093f4841d307059b60cb81c13() { assertEval("{ 1000000000*100000000000 }"); @@ -388,21 +373,11 @@ public class FailingTests extends TestBase { assertEvalError("{ x <- 1:2 ; dim(x) <- 1:2 ; y <- 2:3 ; dim(y) <- c(1,1,2) ; x + y }"); } - @Ignore - public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_26cbb52252ff028ab7bba252147de26c() { - assertEval("{ round(c(1+1i,2+3i)^c(1+1i,3+4i), digits = 5) }"); - } - @Ignore public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_9b81d167391e44e04a528a367013f806() { assertEval("{ z <- c(-1.5-1i,10) ; (z * z)[1] }"); } - @Ignore - public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_a88a08c3bbe4807e9507763726c626e5() { - assertEval("{ round( 3^c(1,2,3+1i), digits=5 ) }"); - } - @Ignore public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_0dae874162cc69c107cdd6f0c5ea334c() { assertEval("{ c(1+1i,3+2i) / 2 }"); @@ -413,6 +388,16 @@ public class FailingTests extends TestBase { assertEval("{ c(1,2,3+1i)^3 }"); } + @Ignore + public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_26cbb52252ff028ab7bba252147de26c() { + assertEval("{ round(c(1+1i,2+3i)^c(1+1i,3+4i), digits = 5) }"); + } + + @Ignore + public void TestSimpleArithmetic_testVectorsOperationsComplexIgnore_a88a08c3bbe4807e9507763726c626e5() { + assertEval("{ round( 3^c(1,2,3+1i), digits=5 ) }"); + } + @Ignore public void TestSimpleArithmetic_testVectorsOperationsIgnore_bc2cc92da6012e61c40e913719b41e8a() { assertEval("{ c(1,3) / c(2,4) }"); @@ -1483,56 +1468,6 @@ public class FailingTests extends TestBase { assertEval("{ as.complex(\"+.1e+2-3i\") }"); } - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_234cefc5ff95e036f3fa00ff5e0f2088() { - assertEval("{ as.raw(1+1i) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_6cd26c8e6df8ead2edcbb6df45860698() { - assertEval("{ as.raw(-1) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_b2f6c512a8b92fcc2861d16b643c77e8() { - assertEval("{ as.raw(-1L) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_6e315b6de04235063bc8e0be93dc9780() { - assertEval("{ as.raw(NA) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_3dced2b189d4bc08910497a4c84f8eaf() { - assertEval("{ as.raw(\"test\") }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_75c975b8a03a598a4af0a0a332d02b71() { - assertEval("{ as.raw(c(1+3i, -2-1i, NA)) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_747e8b9acbda8dd5dc02ce1274604e0c() { - assertEval("{ as.raw(c(1, -2, 3)) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_ad6deee1d16519ee2ce790bb577709d2() { - assertEval("{ as.raw(c(1,1000,NA)) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_d799cae365e5f001ed4de47c2cbbff01() { - assertEval("{ as.raw(c(1L, -2L, 3L)) }"); - } - - @Ignore - public void TestSimpleBuiltins_testAsRawIgnore_05185c7c12248d279730674e3b527d86() { - assertEval("{ as.raw(c(1L, -2L, NA)) }"); - } - @Ignore public void TestSimpleBuiltins_testCall_7d3147e26292301cfabf8939c17af430() { assertEval("{ f <- function(a, b) { a + b } ; l <- call(\"f\", 2, 3) ; eval(l) }"); @@ -6578,11 +6513,6 @@ public class FailingTests extends TestBase { assertEval("{ l <- list(1,list(2)) ; f <- function(i) { l[[i]] } ; f(c(2,1)) ; f(1) }"); } - @Ignore - public void TestSimpleVectors_testVectorIndexIgnore_735c444595fe843fd5efb95ee1f0a3bd() { - assertEval("{ l <- list(1,function(){3}) ; f <- function(i) { l[[i]] } ; f(c(2)) }"); - } - @Ignore public void TestSimpleVectors_testVectorIndexIgnore_1f99c587df8881ae8bb4134fbb911f66() { assertEval("{ f <- function(i) { l[[i]] } ; l <- list(1, as.list(1:3)) ; f(c(2,NA)) }"); diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java index f0f3731158..b49278cdf2 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleBuiltins.java @@ -386,6 +386,13 @@ public class TestSimpleBuiltins extends TestBase { assertEval("{ as.complex(\"-1-5i\") }"); assertEval("{ as.complex(0/0) }"); assertEval("{ as.complex(c(0/0, 0/0)) }"); + assertEvalWarning("{ as.complex(c(\"1\",\"hello\")) }"); + assertEvalWarning("{ as.complex(\"TRUE\") }"); + assertEval("{ x<-c(a=1.1, b=2.2); dim(x)<-c(1,2); attr(x, \"foo\")<-\"foo\"; y<-as.complex(x); attributes(y) }"); + assertEval("{ x<-c(a=1L, b=2L); dim(x)<-c(1,2); attr(x, \"foo\")<-\"foo\"; y<-as.complex(x); attributes(y) }"); + assertEval("{ as.complex(\"Inf\") }"); + assertEval("{ as.complex(\"NaN\") }"); + assertEval("{ as.complex(\"0x42\") }"); } @Test @@ -402,6 +409,7 @@ public class TestSimpleBuiltins extends TestBase { assertEval("{ as.raw(NULL) }"); assertEval("{ as.raw(1) }"); assertEval("{ as.raw(1L) }"); + assertEval("{ as.raw(1.1) }"); assertEval("{ as.raw(c(1, 2, 3)) }"); assertEval("{ as.raw(c(1L, 2L, 3L)) }"); assertEval("{ as.raw(list(1,2,3)) }"); @@ -409,19 +417,18 @@ public class TestSimpleBuiltins extends TestBase { } @Test - @Ignore public void testAsRawIgnore() { // FIXME coercion warnings - assertEval("{ as.raw(1+1i) }"); - assertEval("{ as.raw(-1) }"); - assertEval("{ as.raw(-1L) }"); - assertEval("{ as.raw(NA) }"); - assertEval("{ as.raw(\"test\") }"); - assertEval("{ as.raw(c(1+3i, -2-1i, NA)) }"); - assertEval("{ as.raw(c(1, -2, 3)) }"); - assertEval("{ as.raw(c(1,1000,NA)) }"); - assertEval("{ as.raw(c(1L, -2L, 3L)) }"); - assertEval("{ as.raw(c(1L, -2L, NA)) }"); + assertEvalWarning("{ as.raw(1+1i) }"); + assertEvalWarning("{ as.raw(-1) }"); + assertEvalWarning("{ as.raw(-1L) }"); + assertEvalWarning("{ as.raw(NA) }"); + assertEvalWarning("{ as.raw(\"test\") }"); + assertEvalWarning("{ as.raw(c(1+3i, -2-1i, NA)) }"); + assertEvalWarning("{ as.raw(c(1, -2, 3)) }"); + assertEvalWarning("{ as.raw(c(1,1000,NA)) }"); + assertEvalWarning("{ as.raw(c(1L, -2L, 3L)) }"); + assertEvalWarning("{ as.raw(c(1L, -2L, NA)) }"); } @Test -- GitLab