diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RRootNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RRootNode.java index a6902d271636f89b4a1599f3340f2c0143afa9d6..19d278f4b73bc23c762ba76e818c5af9ebadc844 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RRootNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RRootNode.java @@ -23,6 +23,7 @@ package com.oracle.truffle.r.nodes; import com.oracle.truffle.api.*; +import com.oracle.truffle.api.CompilerDirectives.SlowPath; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; @@ -43,6 +44,7 @@ public abstract class RRootNode extends RootNode { return parameterNames.length; } + @SlowPath public String getSourceCode() { return getSourceSection().getCode(); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java index a02010cb9e307e430683974645019126a82f5238..72446f6128f9b0890d8af5c907a9c61d731f50ef 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/RTruffleVisitor.java @@ -289,12 +289,13 @@ public final class RTruffleVisitor extends BasicVisitor<RNode> { FunctionCall rfCall = new FunctionCall(null, f.getName(), rfArgs); RCallNode replacementFunctionCall = (RCallNode) visit(rfCall); - // assign v, read a + // assign v, delete *tmp*, read a WriteVariableNode vAssign = WriteVariableNode.create(vSymbol, replacementFunctionCall, false, n.isSuper()); + Rm rmTmp = Rm.create(tmp); ReadVariableNode aRead = ReadVariableNode.create(a, false, false); // assemble - SequenceNode replacement = new SequenceNode(new RNode[]{aAssign, tmpAssign, vAssign, Invisible.create(aRead)}); + SequenceNode replacement = new SequenceNode(new RNode[]{aAssign, tmpAssign, vAssign, rmTmp, Invisible.create(aRead)}); replacement.assignSourceSection(n.getSource()); return replacement; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ConstantNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ConstantNode.java index 6e0dead36205792e8f950f976b0d80a49e55af9b..af39d753b6a7b7b5e76a711d4154076688445c84 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ConstantNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/ConstantNode.java @@ -28,6 +28,7 @@ import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.r.nodes.*; import com.oracle.truffle.r.runtime.*; import com.oracle.truffle.r.runtime.data.*; +import com.oracle.truffle.r.runtime.data.model.*; public abstract class ConstantNode extends RNode { @@ -54,6 +55,8 @@ public abstract class ConstantNode extends RNode { return new ConstantEmptyObjectArrayNode(); } else if (value instanceof RComplex) { return new ConstantComplexNode((RComplex) value); + } else if (value instanceof RAbstractVector) { + return new ConstantVectorNode((RAbstractVector) value); } throw new UnsupportedOperationException(value.getClass().getName()); } @@ -233,4 +236,23 @@ public abstract class ConstantNode extends RNode { return EMPTY_OBJECT_ARRAY; } } + + private static final class ConstantVectorNode extends ConstantNode { + + private final RAbstractVector vector; + + public ConstantVectorNode(RAbstractVector vector) { + this.vector = vector; + } + + @Override + public RAbstractVector executeRAbstractVector(VirtualFrame frame) { + return vector; + } + + @Override + public Object execute(VirtualFrame frame) { + return vector; + } + } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java index 3f688c908c67e3da106956cff88b0d3c852b06d5..aa7e45028521824f36d9d52d64b5b7d6424029a9 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/RPackages.java @@ -63,7 +63,7 @@ public abstract class RPackages implements RBuiltinLookup { return RContext.getInstance().putCachedFunction(methodName, new RFunction(builtin.getBuiltinNames()[0], callTarget, true)); } - private RBuiltinFactory lookupBuiltin(String name) { + public RBuiltinFactory lookupBuiltin(String name) { for (RPackage pack : packages) { RBuiltinFactory factory = pack.lookupByName(name); if (factory != null) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java index 49854aea7c6629d310315ec457c945ce1563e850..15daa0f3e4ad9a938f3489408cbebf66ec716729 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/BasePackage.java @@ -141,6 +141,7 @@ public class BasePackage extends RPackage { load(RepeatInternal.class); load(Return.class); load(Rev.class); + load(Rm.class); load(Rnorm.class); load(Round.class); load(Runif.class); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java index fb9d3c48785ab3a36fc22778879bbd5a8d910f47..4deb3dbbfac0b36d10452cf9b048350d37fbbd14 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java @@ -69,7 +69,7 @@ public abstract class PrettyPrinterNode extends RNode { private String prettyPrintAttributes(VirtualFrame frame, Object o) { if (attributePrettyPrinter == null) { - CompilerDirectives.transferToInterpreter(); + CompilerDirectives.transferToInterpreterAndInvalidate(); attributePrettyPrinter = adoptChild(PrettyPrinterNodeFactory.create(null, true, false)); } return attributePrettyPrinter.executeString(frame, o); @@ -77,7 +77,7 @@ public abstract class PrettyPrinterNode extends RNode { private String prettyPrintVectorElement(VirtualFrame frame, Object o) { if (vectorElementPrettyPrinter == null) { - CompilerDirectives.transferToInterpreter(); + CompilerDirectives.transferToInterpreterAndInvalidate(); vectorElementPrettyPrinter = adoptChild(PrettyPrinterNodeFactory.create(null, false, true)); } return vectorElementPrettyPrinter.executeString(frame, o); @@ -85,7 +85,7 @@ public abstract class PrettyPrinterNode extends RNode { private String prettyPrintRecursive(VirtualFrame frame, Object o) { if (recursivePrettyPrinter == null) { - CompilerDirectives.transferToInterpreter(); + CompilerDirectives.transferToInterpreterAndInvalidate(); recursivePrettyPrinter = adoptChild(PrettyPrinterNodeFactory.create(null, isPrintingAttributes(), isPrintingVectorElements())); } return recursivePrettyPrinter.executeString(frame, o); @@ -97,10 +97,9 @@ public abstract class PrettyPrinterNode extends RNode { return "NULL"; } - @SlowPath @Specialization(order = 1, guards = "!printingVectorElements") public String prettyPrintVector(byte operand) { - return "[1] " + RRuntime.logicalToString(operand); + return concat("[1] ", RRuntime.logicalToString(operand)); } @Specialization(order = 2, guards = "printingVectorElements") @@ -108,10 +107,9 @@ public abstract class PrettyPrinterNode extends RNode { return RRuntime.logicalToString(operand); } - @SlowPath @Specialization(order = 10, guards = "!printingVectorElements") public String prettyPrintVector(int operand) { - return "[1] " + RRuntime.intToString(operand, false); + return concat("[1] ", RRuntime.intToString(operand, false)); } @Specialization(order = 11, guards = "printingVectorElements") @@ -119,10 +117,9 @@ public abstract class PrettyPrinterNode extends RNode { return RRuntime.intToString(operand, false); } - @SlowPath @Specialization(order = 20, guards = "!printingVectorElements") public String prettyPrintVector(double operand) { - return "[1] " + doubleToStringPrintFormat(operand, calcRoundFactor(operand, 10000000)); + return concat("[1] ", doubleToStringPrintFormat(operand, calcRoundFactor(operand, 10000000))); } @Specialization(order = 21, guards = "printingVectorElements") @@ -130,13 +127,12 @@ public abstract class PrettyPrinterNode extends RNode { return doubleToStringPrintFormat(operand, calcRoundFactor(operand, 10000000)); } - @SlowPath @Specialization(order = 30, guards = "!printingVectorElements") public String prettyPrintVector(RComplex operand) { double factor = calcRoundFactor(operand.getRealPart(), 10000000); - return "[1] " + + return concat("[1] ", operand.toString(doubleToStringPrintFormat(operand.getRealPart(), factor), - doubleToStringPrintFormat(operand.getImaginaryPart(), calcRoundFactor(operand.getImaginaryPart(), 10000000))); + doubleToStringPrintFormat(operand.getImaginaryPart(), calcRoundFactor(operand.getImaginaryPart(), 10000000)))); } @Specialization(order = 31, guards = "printingVectorElements") @@ -145,10 +141,9 @@ public abstract class PrettyPrinterNode extends RNode { return operand.toString(doubleToStringPrintFormat(operand.getRealPart(), factor), doubleToStringPrintFormat(operand.getImaginaryPart(), calcRoundFactor(operand.getImaginaryPart(), 10000000))); } - @SlowPath @Specialization(order = 40, guards = "!printingVectorElements") public String prettyPrintVector(String operand) { - return "[1] " + RRuntime.quoteString(operand); + return concat("[1] ", RRuntime.quoteString(operand)); } @Specialization(order = 41, guards = "printingVectorElements") @@ -156,10 +151,9 @@ public abstract class PrettyPrinterNode extends RNode { return RRuntime.quoteString(operand); } - @SlowPath @Specialization(order = 50, guards = "!printingVectorElements") public String prettyPrintVector(RRaw operand) { - return "[1] " + operand.toString(); + return concat("[1] ", operand.toString()); } @Specialization(order = 51, guards = "printingVectorElements") @@ -172,7 +166,6 @@ public abstract class PrettyPrinterNode extends RNode { return ((RRootNode) ((DefaultCallTarget) operand.getTarget()).getRootNode()).getSourceCode(); } - @SlowPath private String printAttributes(VirtualFrame frame, RAbstractVector vector, Map<String, Object> attributes) { StringBuilder builder = new StringBuilder(); for (Map.Entry<String, Object> attr : attributes.entrySet()) { @@ -188,14 +181,13 @@ public abstract class PrettyPrinterNode extends RNode { builder.append("attr(,\"" + attr.getKey() + "\")\n"); builder.append(prettyPrintAttributes(frame, attr.getValue())); } - return builder.toString(); + return builderToString(builder); } - @SlowPath private String printVector(VirtualFrame frame, RAbstractVector vector, String[] values, boolean isStringVector, boolean isRawVector) { assert vector.getLength() == values.length; if (values.length == 0) { - return RRuntime.classToString(vector.getElementClass()) + "(0)"; + return concat(RRuntime.classToString(vector.getElementClass()), "(0)"); } else { boolean printNamesHeader = (!vector.hasDimensions() && vector.getNames() != null && vector.getNames() != RNull.instance); RStringVector names = printNamesHeader ? (RStringVector) vector.getNames() : null; @@ -231,7 +223,7 @@ public abstract class PrettyPrinterNode extends RNode { while (index < vector.getLength()) { if (!printNamesHeader) { int position = index + 1; - String positionString = Integer.toString(position); + String positionString = intString(position); for (int i = 0; i < maxPositionLength - positionString.length(); ++i) { builder.append(' '); } @@ -280,74 +272,183 @@ public abstract class PrettyPrinterNode extends RNode { builder.append('\n'); if (printNamesHeader) { headerBuilder.append('\n'); - headerBuilder.append(builder); + headerBuilder.append(builderToString(builder)); builder = new StringBuilder(); } } - String result = (!printNamesHeader ? builder.deleteCharAt(builder.length() - 1).toString() : headerBuilder.deleteCharAt(headerBuilder.length() - 1).toString()); + StringBuilder resultBuilder = printNamesHeader ? headerBuilder : builder; + resultBuilder.deleteCharAt(resultBuilder.length() - 1); Map<String, Object> attributes = vector.getAttributes(); if (attributes != null) { - result = result + printAttributes(frame, vector, attributes); + resultBuilder.append(printAttributes(frame, vector, attributes)); } - return result; + return builderToString(resultBuilder); } } - @SlowPath - protected static String padColHeader(int r, int dataColWidth) { + protected static String padColHeader(int r, int dataColWidth, RAbstractVector vector, boolean isList) { + RList dimNames = vector.getDimNames(); StringBuilder sb = new StringBuilder(); - String rs = Integer.toString(r); - int wdiff = dataColWidth - (rs.length() + 3); // 3: [,] - sb.append("[,").append(rs).append(']'); - if (wdiff > 0) { + int wdiff; + if (dimNames == null || dimNames.getDataAt(1) == RNull.instance) { + String rs = intString(r); + wdiff = dataColWidth - (rs.length() + 3); // 3: [,] + if (!isList && wdiff > 0) { + spaces(sb, wdiff); + } + sb.append("[,").append(rs).append(']'); + } else { + RStringVector dimNamesVector = (RStringVector) dimNames.getDataAt(1); + String dimId = dimNamesVector.getDataAt(r - 1); + wdiff = dataColWidth - dimId.length(); + if (!isList && wdiff > 0) { + spaces(sb, wdiff); + } + sb.append(dimId); + } + if (isList && wdiff > 0) { spaces(sb, wdiff); } - return sb.toString(); + return builderToString(sb); } - @SlowPath - protected static String rowHeader(int c) { - return new StringBuilder("[").append(c).append(",]").toString(); + protected static String rowHeader(int c, RAbstractVector vector) { + RList dimNames = vector.getDimNames(); + if (dimNames == null || dimNames.getDataAt(0) == RNull.instance) { + return concat("[", intString(c), ",]"); + } else { + RStringVector dimNamesVector = (RStringVector) dimNames.getDataAt(0); + return dimNamesVector.getDataAt(c - 1); + } } - @SlowPath protected static void spaces(StringBuilder sb, int s) { for (int i = 0; i < s; ++i) { sb.append(' '); } } - @SlowPath - protected String printVector2Dim(VirtualFrame frame, RAbstractVector vector, boolean isList) { - // FIXME support empty matrices + private static String getDimId(RAbstractVector vector, int dimLevel, int dimInd) { + String dimId; + RList dimNames = vector.getDimNames(); + if (dimNames == null || dimNames.getDataAt(dimLevel - 1) == RNull.instance) { + dimId = intString(dimInd + 1); + } else { + RStringVector dimNamesVector = (RStringVector) dimNames.getDataAt(dimLevel - 1); + dimId = dimNamesVector.getDataAt(dimInd); + } + return dimId; + } + + private String printDim(VirtualFrame frame, RAbstractVector vector, boolean isList, int currentDimLevel, int arrayBase, int accDimensions, String header) { + int[] dimensions = vector.getDimensions(); + if (currentDimLevel == 3) { + StringBuilder sb = new StringBuilder(); + int dimSize = dimensions[currentDimLevel - 1]; + int matrixSize = dimensions[0] * dimensions[1]; + for (int dimInd = 0; dimInd < dimSize; dimInd++) { + // CheckStyle: stop system..print check + sb.append(", , "); + // CheckStyle: resume system..print check + sb.append(getDimId(vector, currentDimLevel, dimInd)); + sb.append(", "); + sb.append(header); + sb.append("\n\n"); + sb.append(printVector2Dim(frame, vector, dimensions, arrayBase + (dimInd * matrixSize), isList)); + sb.append("\n"); + if ((arrayBase + (dimInd * matrixSize) + matrixSize) < vector.getLength()) { + sb.append("\n"); + } + } + return builderToString(sb); + } else { + StringBuilder sb = new StringBuilder(); + int dimSize = dimensions[currentDimLevel - 1]; + int newAccDimensions = accDimensions / dimSize; + for (int dimInd = 0; dimInd < dimSize; dimInd++) { + int newArrayBase = arrayBase + newAccDimensions * dimInd; + String dimId = getDimId(vector, currentDimLevel, dimInd); + sb.append(printDim(frame, vector, isList, currentDimLevel - 1, newArrayBase, newAccDimensions, concat(dimId, ", ", header))); + } + return builderToString(sb); + } + } + private String printVectorMultiDim(VirtualFrame frame, RAbstractVector vector, boolean isList) { int[] dimensions = vector.getDimensions(); + assert dimensions != null; + int numDimensions = dimensions.length; + assert numDimensions > 1; + if (numDimensions == 2) { + return printVector2Dim(frame, vector, dimensions, 0, isList); + } else if (numDimensions == 3) { + StringBuilder sb = new StringBuilder(); + int dimSize = dimensions[numDimensions - 1]; + int matrixSize = dimensions[0] * dimensions[1]; + for (int dimInd = 0; dimInd < dimSize; dimInd++) { + // CheckStyle: stop system..print check + sb.append(", , "); + // CheckStyle: resume system..print check + sb.append(getDimId(vector, numDimensions, dimInd)); + sb.append("\n\n"); + sb.append(printVector2Dim(frame, vector, dimensions, dimInd * matrixSize, isList)); + sb.append("\n"); + if (dimInd < (dimSize - 1)) { + sb.append("\n"); + } + } + return builderToString(sb); + } else { + StringBuilder sb = new StringBuilder(); + int dimSize = dimensions[numDimensions - 1]; + int accDimensions = vector.getLength() / dimSize; + for (int dimInd = 0; dimInd < dimSize; dimInd++) { + int arrayBase = accDimensions * dimInd; + String dimId = getDimId(vector, numDimensions, dimInd); + sb.append(printDim(frame, vector, isList, numDimensions - 1, arrayBase, accDimensions, dimId)); + } + return builderToString(sb); + } + } + + private String printVector2Dim(VirtualFrame frame, RAbstractVector vector, int[] dimensions, int offset, boolean isList) { int nrow = dimensions[0]; int ncol = dimensions[1]; // prepare data (relevant for column widths) String[] dataStrings = new String[nrow * ncol]; int[] dataColWidths = new int[ncol]; + RList dimNames = vector.getDimNames(); + RStringVector columnDimNames = null; + if (dimNames != null && dimNames.getDataAt(1) != RNull.instance) { + columnDimNames = (RStringVector) dimNames.getDataAt(1); + } for (int r = 0; r < nrow; ++r) { for (int c = 0; c < ncol; ++c) { int index = c * nrow + r; - String data = prettyPrintVectorElement(frame, vector.getDataAtAsObject(index)); + String data = prettyPrintVectorElement(frame, vector.getDataAtAsObject(index + offset)); dataStrings[index] = data; if (data.length() > dataColWidths[c]) { dataColWidths[c] = data.length(); } + if (columnDimNames != null) { + String columnName = columnDimNames.getDataAt(c); + if (columnName.length() > dataColWidths[c]) { + dataColWidths[c] = columnName.length(); + } + } } } - int rowHeaderWidth = rowHeader(nrow).length(); - String rowFormat = "%" + rowHeaderWidth + "s"; + int rowHeaderWidth = rowHeader(nrow, vector).length(); + String rowFormat = concat("%", intString(rowHeaderWidth), "s"); StringBuilder b = new StringBuilder(); // column header spaces(b, rowHeaderWidth + 1); for (int c = 1; c <= ncol; ++c) { - b.append(padColHeader(c, dataColWidths[c - 1])); + b.append(padColHeader(c, dataColWidths[c - 1], vector, isList)); if (c < ncol) { b.append(' '); } @@ -356,18 +457,16 @@ public abstract class PrettyPrinterNode extends RNode { // rows for (int r = 1; r <= nrow; ++r) { - b.append(String.format(rowFormat, rowHeader(r))).append(' '); + b.append(String.format(rowFormat, rowHeader(r, vector))).append(' '); for (int c = 1; c <= ncol; ++c) { String dataString = dataStrings[(c - 1) * nrow + (r - 1)]; if (isList) { // list elements are aligned to the left and vector's to the right b.append(dataString); - for (int i = 0; i < padColHeader(c, dataColWidths[c - 1]).length() - dataString.length(); i++) { - b.append(' '); - } + spaces(b, padColHeader(c, dataColWidths[c - 1], vector, isList).length() - dataString.length()); } else { - String cellFormat = "%" + padColHeader(c, dataColWidths[c - 1]).length() + "s"; - b.append(String.format(cellFormat, dataString)); + String cellFormat = concat("%", intString(padColHeader(c, dataColWidths[c - 1], vector, isList).length()), "s"); + b.append(stringFormat(cellFormat, dataString)); } if (c < ncol) { b.append(' '); @@ -378,7 +477,7 @@ public abstract class PrettyPrinterNode extends RNode { } } - return b.toString(); + return builderToString(b); } private static double calcRoundFactor(double input, long maxFactor) { @@ -408,7 +507,6 @@ public abstract class PrettyPrinterNode extends RNode { return factor; } - @SlowPath private static String doubleToStringPrintFormat(double input, double roundFactor) { double data = input; if (!Double.isNaN(data) && !Double.isInfinite(data)) { @@ -422,8 +520,6 @@ public abstract class PrettyPrinterNode extends RNode { return RRuntime.doubleToString(data); } - // FIXME support nesting levels >1 - @SlowPath private String prettyPrintList0(VirtualFrame frame, RList operand, Object listName) { int length = operand.getLength(); if (length == 0) { @@ -436,18 +532,18 @@ public abstract class PrettyPrinterNode extends RNode { } Object name = operand.getNameAt(i); if (listName != null) { - name = new StringBuilder(listName.toString()).append(name).toString(); + name = concat(objectString(listName), objectString(name)); } sb.append(name).append('\n'); Object value = operand.getDataAt(i); sb.append(printSingleListValue(frame, value, name)).append("\n\n"); } - String result = sb.deleteCharAt(sb.length() - 1).toString(); + sb.deleteCharAt(sb.length() - 1); Map<String, Object> attributes = operand.getAttributes(); if (attributes != null) { - result = result + printAttributes(frame, operand, attributes); + sb.append(printAttributes(frame, operand, attributes)); } - return result; + return builderToString(sb); } } @@ -477,34 +573,33 @@ public abstract class PrettyPrinterNode extends RNode { return prettyPrintRecursive(frame, operand.getDataAtAsObject(0)); } - @SlowPath @Specialization(order = 80, guards = "printingVectorElements") public String prettyPrintElements(RList operand) { - return "List," + operand.getLength(); + return concat("List,", intString(operand.getLength())); } @Specialization(order = 81, guards = "printingVectorElements") public String prettyPrintElements(RAbstractVector operand) { - return RRuntime.classToStringCap(operand.getElementClass()) + "," + operand.getLength(); + return concat(RRuntime.classToStringCap(operand.getElementClass()), ",", intString(operand.getLength())); } - @Specialization(order = 100, guards = {"isMatrix", "!printingVectorElements"}) + @Specialization(order = 100, guards = {"twoDimsOrMore", "!printingVectorElements"}) public String prettyPrintM(VirtualFrame frame, RList operand) { - return printVector2Dim(frame, operand, true); + return printVectorMultiDim(frame, operand, true); } - @Specialization(order = 101, guards = {"isMatrix", "!printingVectorElements"}) + @Specialization(order = 101, guards = {"twoDimsOrMore", "!printingVectorElements"}) public String prettyPrintM(VirtualFrame frame, RAbstractVector operand) { - return printVector2Dim(frame, operand, false); + return printVectorMultiDim(frame, operand, false); } @SlowPath - @Specialization(order = 200, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 200, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RList operand) { return prettyPrintList0(frame, operand, null); } - @Specialization(order = 300, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 300, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RAbstractDoubleVector operand) { int length = operand.getLength(); String[] values = new String[length]; @@ -515,7 +610,7 @@ public abstract class PrettyPrinterNode extends RNode { return printVector(frame, operand, values, false, false); } - @Specialization(order = 400, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 400, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RAbstractIntVector operand) { int length = operand.getLength(); String[] values = new String[length]; @@ -526,7 +621,7 @@ public abstract class PrettyPrinterNode extends RNode { return printVector(frame, operand, values, false, false); } - @Specialization(order = 500, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 500, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RAbstractStringVector operand) { int length = operand.getLength(); String[] values = new String[length]; @@ -537,7 +632,7 @@ public abstract class PrettyPrinterNode extends RNode { return printVector(frame, operand, values, true, false); } - @Specialization(order = 600, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 600, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RAbstractLogicalVector operand) { int length = operand.getLength(); String[] values = new String[length]; @@ -548,7 +643,7 @@ public abstract class PrettyPrinterNode extends RNode { return printVector(frame, operand, values, false, false); } - @Specialization(order = 700, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 700, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RAbstractRawVector operand) { int length = operand.getLength(); String[] values = new String[length]; @@ -559,7 +654,7 @@ public abstract class PrettyPrinterNode extends RNode { return printVector(frame, operand, values, false, true); } - @Specialization(order = 800, guards = {"!isMatrix", "!printingVectorElements"}) + @Specialization(order = 800, guards = {"!twoDimsOrMore", "!printingVectorElements"}) public String prettyPrint(VirtualFrame frame, RAbstractComplexVector operand) { int length = operand.getLength(); String[] values = new String[length]; @@ -570,36 +665,36 @@ public abstract class PrettyPrinterNode extends RNode { return printVector(frame, operand, values, false, false); } - protected static boolean isMatrix(RAbstractVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RAbstractDoubleVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractDoubleVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RAbstractIntVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractIntVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RAbstractStringVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractStringVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RAbstractLogicalVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractLogicalVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RAbstractRawVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractRawVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RAbstractComplexVector v) { - return v.isMatrix(); + protected static boolean twoDimsOrMore(RAbstractComplexVector v) { + return v.hasDimensions() && v.getDimensions().length > 1; } - protected static boolean isMatrix(RList l) { - return l.isMatrix(); + protected static boolean twoDimsOrMore(RList l) { + return l.hasDimensions() && l.getDimensions().length > 1; } protected static boolean isLengthOne(RAbstractIntVector v) { @@ -622,7 +717,6 @@ public abstract class PrettyPrinterNode extends RNode { return v.getLength() == 1; } - @SlowPath protected Object printSingleListValue(VirtualFrame frame, Object argumentsValue0, Object listElementName) { if (RTYPES.isByte(argumentsValue0)) { byte argumentsValue0Cast = RTYPES.asByte(argumentsValue0); @@ -696,7 +790,7 @@ public abstract class PrettyPrinterNode extends RNode { RInvisible argumentsValue0Cast = RTYPES.asRInvisible(argumentsValue0); return prettyPrint(frame, argumentsValue0Cast); } - throw new UnsupportedOperationException("Unsupported values" + argumentsValue0); + throw new UnsupportedOperationException(concat("Unsupported values ", objectString(argumentsValue0))); } @Specialization @@ -704,4 +798,32 @@ public abstract class PrettyPrinterNode extends RNode { return prettyPrintRecursive(frame, operand.get()); } + @SlowPath + private static String builderToString(StringBuilder sb) { + return sb.toString(); + } + + @SlowPath + private static String intString(int x) { + return Integer.toString(x); + } + + @SlowPath + private static String stringFormat(String format, String arg) { + return String.format(format, arg); + } + + @SlowPath + private static String objectString(Object o) { + return o.toString(); + } + + private static String concat(String... ss) { + StringBuilder sb = new StringBuilder(); + for (String s : ss) { + sb.append(s); + } + return builderToString(sb); + } + } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java new file mode 100644 index 0000000000000000000000000000000000000000..3e304ea2da15cdd5000b639606fe6ad32fcaab03 --- /dev/null +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/Rm.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.nodes.builtin.base; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.r.nodes.*; +import com.oracle.truffle.r.nodes.access.*; +import com.oracle.truffle.r.nodes.builtin.*; +import com.oracle.truffle.r.nodes.builtin.RBuiltin.*; +import com.oracle.truffle.r.runtime.*; +import com.oracle.truffle.r.runtime.data.*; + +@RBuiltin(value = {"rm", "remove"}, lastParameterKind = LastParameterKind.VAR_ARGS_SPECIALIZE) +public abstract class Rm extends RBuiltinNode { + + public static Rm create(String name) { + RNode[] args = getParameterValues0(); + args[0] = ConstantNode.create(name); + return RmFactory.create(args, RDefaultPackages.getInstance().lookupBuiltin("rm")); + } + + private static RNode[] getParameterValues0() { + return new RNode[]{ConstantNode.create(RMissing.instance), ConstantNode.create(RDataFactory.createStringVector(0)), ConstantNode.create(-1), ConstantNode.create(RMissing.instance), + ConstantNode.create(RRuntime.LOGICAL_FALSE)}; + } + + private static final Object[] PARAMETER_NAMES = new Object[]{"...", "list", "pos", "envir", "inherits"}; + + @Override + public Object[] getParameterNames() { + return PARAMETER_NAMES; + } + + @Override + public RNode[] getParameterValues() { + return getParameterValues0(); + } + + @Specialization + @SuppressWarnings("unused") + public Object rm(VirtualFrame frame, String name, RStringVector list, Object pos, RMissing envir, byte inherits) { + removeFromCurrentFrame(frame, name); + return RInvisible.INVISIBLE_NULL; + } + + @Specialization + @SuppressWarnings("unused") + public Object rm(VirtualFrame frame, Object[] names, RStringVector list, Object pos, RMissing envir, byte inherits) { + for (Object o : names) { + assert o instanceof String; + removeFromCurrentFrame(frame, (String) o); + } + return RInvisible.INVISIBLE_NULL; + } + + private void removeFromCurrentFrame(VirtualFrame frame, String x) { + // standard case for lookup in current frame + Frame frm = frame; + FrameSlot fs = frame.getFrameDescriptor().findFrameSlot(x); + while (fs == null && frm != null) { + frm = RArguments.get(frm).getEnclosingFrame(); + if (frm != null) { + fs = frm.getFrameDescriptor().findFrameSlot(x); + } + } + if (fs == null) { + RError.warning(this.getEncapsulatingSourceSection(), RError.UNKNOWN_OBJECT, x); + } else { + frm.getFrameDescriptor().removeFrameSlot(x); + } + } + +} diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDimNames.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDimNames.java index b0f9c9ad0a32c689286ad71af9183ed5ae1ef6ac..29a8b90b793396352fb7a2e7cbe76e1a0033e017 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDimNames.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/base/UpdateDimNames.java @@ -38,6 +38,7 @@ import com.oracle.truffle.r.runtime.data.model.*; public abstract class UpdateDimNames extends RBuiltinNode { @Child CastStringNode castStringNode; + @Child CastToVectorNode castVectorNode; private Object castString(VirtualFrame frame, Object o) { if (castStringNode == null) { @@ -47,6 +48,14 @@ public abstract class UpdateDimNames extends RBuiltinNode { return castStringNode.executeCast(frame, o); } + private RAbstractVector castVector(VirtualFrame frame, Object value) { + if (castVectorNode == null) { + CompilerDirectives.transferToInterpreter(); + castVectorNode = adoptChild(CastToVectorNodeFactory.create(null, false, false)); + } + return castVectorNode.executeRAbstractVector(frame, value).materialize(); + } + public abstract Object executeList(VirtualFrame frame, RAbstractVector vector, Object o); public RList convertToListOfStrings(VirtualFrame frame, RList list) { @@ -54,7 +63,7 @@ public abstract class UpdateDimNames extends RBuiltinNode { for (int i = 0; i < list.getLength(); i++) { Object element = list.getDataAt(i); if (element != RNull.instance) { - Object s = castString(frame, element); + Object s = castString(frame, castVector(frame, element)); list.updateDataAt(i, s, null); } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java index 20e151bd8db43466b4a48ad4e03d49e25c6031c4..1a77c323f95291779a567250583cfe1f956fa08a 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java @@ -184,6 +184,8 @@ public abstract class RError extends RuntimeException { public static final String IS_OF_WRONG_ARITY = "'%d' argument passed to '%s' which requires '%d'"; public static final String OBJECT_NOT_SUBSETTABLE = "object of type '%s' is not subsettable"; public static final String DIMS_DONT_MATCH_LENGTH = "dims [product %d] do not match the length of object [%d]"; + public static final String DIMNAMES_DONT_MATCH_DIMS = "length of 'dimnames' [%d] must match that of 'dims' [%d]"; + public static final String DIMNAMES_DONT_MATCH_EXTENT = "length of 'dimnames' [%d] not equal to array extent"; public static final String MUST_BE_ATOMIC = "'%s' must be atomic"; public static final String MUST_BE_NULL_OR_STRING = "'%s' must be NULL or a character vector"; public static final String MUST_BE_SCALAR = "'%s' must be of length 1"; @@ -231,6 +233,10 @@ public abstract class RError extends RuntimeException { RContext.getInstance().setEvalWarning("In " + source.getCode() + " : " + message); } + public static void warning(SourceSection source, String message, Object... args) { + RContext.getInstance().setEvalWarning("In " + source.getCode() + " : " + stringFormat(message, args)); + } + public abstract static class RNYIError extends RError { private static final long serialVersionUID = -7296314309177604737L; @@ -1754,6 +1760,14 @@ public abstract class RError extends RuntimeException { return getGenericError(ast, stringFormat(RError.DIMS_DONT_MATCH_LENGTH, dimsProduct, objectLength)); } + public static RError getDimNamesDontMatchDims(SourceSection ast, int dimNamesLength, int dimsLength) { + return getGenericError(ast, stringFormat(RError.DIMNAMES_DONT_MATCH_DIMS, dimNamesLength, dimsLength)); + } + + public static RError getDimNamesDontMatchExtent(SourceSection ast, int dimNamesVectorLength) { + return getGenericError(ast, stringFormat(RError.DIMNAMES_DONT_MATCH_EXTENT, dimNamesVectorLength)); + } + @SlowPath public static RError getArgOneOf(SourceSection ast, String argName, String[] allowed) { StringBuilder str = new StringBuilder(); 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 73f8ad06f4b7514b3ee5214aaaaa39b3ef9cce5c..be1dcd5cab63c7f7ff429278368cc6483ffe0743 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 @@ -110,6 +110,7 @@ public class RRuntime { return Double.isNaN(d); } + @SlowPath public static String classToString(Class<?> c) { if (c == RLogical.class) { return TYPE_LOGICAL; @@ -128,6 +129,7 @@ public class RRuntime { } } + @SlowPath public static String classToStringCap(Class<?> c) { if (c == RLogical.class) { return TYPE_LOGICAL_CAP; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RList.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RList.java index 02ce7f74473c427c457be8664283838b32ca0474..b4104e8fe79aa5abfb00accd0d1f5d31c6a0ac72 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RList.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RList.java @@ -28,6 +28,7 @@ import com.oracle.truffle.r.runtime.*; import com.oracle.truffle.r.runtime.data.model.*; import com.oracle.truffle.r.runtime.ops.na.*; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.CompilerDirectives.SlowPath; public final class RList extends RVector implements RAbstractVector { @@ -107,6 +108,7 @@ public final class RList extends RVector implements RAbstractVector { return RDataFactory.createList(data, newDimensions); } + @SlowPath public Object getNameAt(int index) { if (names != null && names != RNull.instance) { String name = ((RStringVector) names).getDataAt(index); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RVector.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RVector.java index fa021f070b68abbc17dd3cadde15011710a15369..6a3df393d40fdcad710bc20a313a5b59a7ea64f7 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RVector.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RVector.java @@ -144,6 +144,27 @@ public abstract class RVector extends RBounded implements RAbstractVector { if (dimensions == null) { throw RError.getDimnamesNonarray(sourceSection); } + int newDimNamesLength = newDimNames.getLength(); + if (newDimNamesLength > dimensions.length) { + throw RError.getDimNamesDontMatchDims(sourceSection, newDimNamesLength, dimensions.length); + } + for (int i = 0; i < newDimNamesLength; i++) { + Object dimObject = newDimNames.getDataAt(i); + if (dimObject != RNull.instance) { + RStringVector dimVector = (RStringVector) dimObject; + if (dimVector.getLength() != dimensions[i]) { + throw RError.getDimNamesDontMatchExtent(sourceSection, i + 1); + } + } + } + + if (newDimNamesLength < dimensions.length) { + // resize the array and fill the missing entries with NULL-s + newDimNames.resizeInternal(dimensions.length); + for (int i = newDimNamesLength; i < dimensions.length; i++) { + newDimNames.updateDataAt(i, RNull.instance, null); + } + } attributes.put(RRuntime.DIMNAMES_ATTR_KEY, newDimNames); newDimNames.elementNamePrefix = RRuntime.DIMNAMES_LIST_ELEMENT_NAME_PREFIX; } 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 2c350a6580deaa341dedc0f031fd640ac61ddb53..0b2a6d29ff446cff121114ce98bd086afa1a08b9 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 @@ -3995,6 +3995,77 @@ $foo Error in attr(x, "dimnames") <- list(101, 102, 103, 104) : 'dimnames' applied to non-array +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(NULL); attributes(x) } +$dim +[1] 2 1 2 + +$dimnames +$dimnames[[1]] +NULL + +$dimnames[[2]] +NULL + +$dimnames[[3]] +NULL + + + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a")); x } +Error in dimnames(x) <- list(c("a")) : + length of 'dimnames' [1] not equal to array extent + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a", "b"), "c", c("d", "e")); attributes(x) } +$dim +[1] 2 1 2 + +$dimnames +$dimnames[[1]] +[1] "a" "b" + +$dimnames[[2]] +[1] "c" + +$dimnames[[3]] +[1] "d" "e" + + + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a", "b"), "c", c("d", "e"), 7); attributes(x) } +Error in dimnames(x) <- list(c("a", "b"), "c", c("d", "e"), 7) : + length of 'dimnames' [4] must match that of 'dims' [3] + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a", "b"), 42, c("d", "e")); attributes(x) } +$dim +[1] 2 1 2 + +$dimnames +$dimnames[[1]] +[1] "a" "b" + +$dimnames[[2]] +[1] "42" + +$dimnames[[3]] +[1] "d" "e" + + + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a", "b"), 42, c("d", "e", "f")); attributes(x) } +Error in dimnames(x) <- list(c("a", "b"), 42, c("d", "e", "f")) : + length of 'dimnames' [3] not equal to array extent + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a", "b"), NULL, c("d")); x } +Error in dimnames(x) <- list(c("a", "b"), NULL, c("d")) : + length of 'dimnames' [3] not equal to array extent + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testDimensions #{ x<-1:4; dim(x)<-c(4); y<-101:104; dim(y)<-c(2,2); x > y } Error in x > y : non-conformable arrays @@ -5505,6 +5576,18 @@ numeric(0) #{ rev(c(1+1i, 2+2i)) } [1] 2+2i 1+1i +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testRm +#{ rm("ieps") } +Warning message: +In rm("ieps") : object 'ieps' not found + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testRm +#{ x <- 200 ; rm("x") ; x } +Error: object 'x' not found + +##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testRm +#{ x <- 200 ; rm("x") } + ##com.oracle.truffle.r.test.simple.TestSimpleBuiltins.testRound #{ round(-1.5) } [1] -2 @@ -39258,6 +39341,718 @@ NULL #{ x<-NULL; x[3L] } NULL +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-10001:10008; dim(x)<-c(2,2,2); x } +, , 1 + + [,1] [,2] +[1,] 10001 10003 +[2,] 10002 10004 + +, , 2 + + [,1] [,2] +[1,] 10005 10007 +[2,] 10006 10008 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-101:108; dim(x)<-c(2,2,2); dimnames(x)<-list(c(1, 2), c(3, 4), c(5, 6)); x } +, , 5 + + 3 4 +1 101 103 +2 102 104 + +, , 6 + + 3 4 +1 105 107 +2 106 108 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:16; dim(x)<-c(2,2,2,2); x } +, , 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2, 1 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + +, , 1, 2 + + [,1] [,2] +[1,] 9 11 +[2,] 10 12 + +, , 2, 2 + + [,1] [,2] +[1,] 13 15 +[2,] 14 16 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:16; dim(x)<-c(2,4,2); x } +, , 1 + + [,1] [,2] [,3] [,4] +[1,] 1 3 5 7 +[2,] 2 4 6 8 + +, , 2 + + [,1] [,2] [,3] [,4] +[1,] 9 11 13 15 +[2,] 10 12 14 16 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:256; dim(x)<-c(4,4,4,4); x } +, , 1, 1 + + [,1] [,2] [,3] [,4] +[1,] 1 5 9 13 +[2,] 2 6 10 14 +[3,] 3 7 11 15 +[4,] 4 8 12 16 + +, , 2, 1 + + [,1] [,2] [,3] [,4] +[1,] 17 21 25 29 +[2,] 18 22 26 30 +[3,] 19 23 27 31 +[4,] 20 24 28 32 + +, , 3, 1 + + [,1] [,2] [,3] [,4] +[1,] 33 37 41 45 +[2,] 34 38 42 46 +[3,] 35 39 43 47 +[4,] 36 40 44 48 + +, , 4, 1 + + [,1] [,2] [,3] [,4] +[1,] 49 53 57 61 +[2,] 50 54 58 62 +[3,] 51 55 59 63 +[4,] 52 56 60 64 + +, , 1, 2 + + [,1] [,2] [,3] [,4] +[1,] 65 69 73 77 +[2,] 66 70 74 78 +[3,] 67 71 75 79 +[4,] 68 72 76 80 + +, , 2, 2 + + [,1] [,2] [,3] [,4] +[1,] 81 85 89 93 +[2,] 82 86 90 94 +[3,] 83 87 91 95 +[4,] 84 88 92 96 + +, , 3, 2 + + [,1] [,2] [,3] [,4] +[1,] 97 101 105 109 +[2,] 98 102 106 110 +[3,] 99 103 107 111 +[4,] 100 104 108 112 + +, , 4, 2 + + [,1] [,2] [,3] [,4] +[1,] 113 117 121 125 +[2,] 114 118 122 126 +[3,] 115 119 123 127 +[4,] 116 120 124 128 + +, , 1, 3 + + [,1] [,2] [,3] [,4] +[1,] 129 133 137 141 +[2,] 130 134 138 142 +[3,] 131 135 139 143 +[4,] 132 136 140 144 + +, , 2, 3 + + [,1] [,2] [,3] [,4] +[1,] 145 149 153 157 +[2,] 146 150 154 158 +[3,] 147 151 155 159 +[4,] 148 152 156 160 + +, , 3, 3 + + [,1] [,2] [,3] [,4] +[1,] 161 165 169 173 +[2,] 162 166 170 174 +[3,] 163 167 171 175 +[4,] 164 168 172 176 + +, , 4, 3 + + [,1] [,2] [,3] [,4] +[1,] 177 181 185 189 +[2,] 178 182 186 190 +[3,] 179 183 187 191 +[4,] 180 184 188 192 + +, , 1, 4 + + [,1] [,2] [,3] [,4] +[1,] 193 197 201 205 +[2,] 194 198 202 206 +[3,] 195 199 203 207 +[4,] 196 200 204 208 + +, , 2, 4 + + [,1] [,2] [,3] [,4] +[1,] 209 213 217 221 +[2,] 210 214 218 222 +[3,] 211 215 219 223 +[4,] 212 216 220 224 + +, , 3, 4 + + [,1] [,2] [,3] [,4] +[1,] 225 229 233 237 +[2,] 226 230 234 238 +[3,] 227 231 235 239 +[4,] 228 232 236 240 + +, , 4, 4 + + [,1] [,2] [,3] [,4] +[1,] 241 245 249 253 +[2,] 242 246 250 254 +[3,] 243 247 251 255 +[4,] 244 248 252 256 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:32; dim(x)<-c(2,2,2,2,2); x } +, , 1, 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2, 1, 1 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + +, , 1, 2, 1 + + [,1] [,2] +[1,] 9 11 +[2,] 10 12 + +, , 2, 2, 1 + + [,1] [,2] +[1,] 13 15 +[2,] 14 16 + +, , 1, 1, 2 + + [,1] [,2] +[1,] 17 19 +[2,] 18 20 + +, , 2, 1, 2 + + [,1] [,2] +[1,] 21 23 +[2,] 22 24 + +, , 1, 2, 2 + + [,1] [,2] +[1,] 25 27 +[2,] 26 28 + +, , 2, 2, 2 + + [,1] [,2] +[1,] 29 31 +[2,] 30 32 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:32; dim(x)<-c(2,2,2,4); x } +, , 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2, 1 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + +, , 1, 2 + + [,1] [,2] +[1,] 9 11 +[2,] 10 12 + +, , 2, 2 + + [,1] [,2] +[1,] 13 15 +[2,] 14 16 + +, , 1, 3 + + [,1] [,2] +[1,] 17 19 +[2,] 18 20 + +, , 2, 3 + + [,1] [,2] +[1,] 21 23 +[2,] 22 24 + +, , 1, 4 + + [,1] [,2] +[1,] 25 27 +[2,] 26 28 + +, , 2, 4 + + [,1] [,2] +[1,] 29 31 +[2,] 30 32 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:32; dim(x)<-c(2,2,4,2); x } +, , 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2, 1 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + +, , 3, 1 + + [,1] [,2] +[1,] 9 11 +[2,] 10 12 + +, , 4, 1 + + [,1] [,2] +[1,] 13 15 +[2,] 14 16 + +, , 1, 2 + + [,1] [,2] +[1,] 17 19 +[2,] 18 20 + +, , 2, 2 + + [,1] [,2] +[1,] 21 23 +[2,] 22 24 + +, , 3, 2 + + [,1] [,2] +[1,] 25 27 +[2,] 26 28 + +, , 4, 2 + + [,1] [,2] +[1,] 29 31 +[2,] 30 32 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:32; dim(x)<-c(2,4,2,2); x } +, , 1, 1 + + [,1] [,2] [,3] [,4] +[1,] 1 3 5 7 +[2,] 2 4 6 8 + +, , 2, 1 + + [,1] [,2] [,3] [,4] +[1,] 9 11 13 15 +[2,] 10 12 14 16 + +, , 1, 2 + + [,1] [,2] [,3] [,4] +[1,] 17 19 21 23 +[2,] 18 20 22 24 + +, , 2, 2 + + [,1] [,2] [,3] [,4] +[1,] 25 27 29 31 +[2,] 26 28 30 32 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:32; dim(x)<-c(4,2,2,2); x } +, , 1, 1 + + [,1] [,2] +[1,] 1 5 +[2,] 2 6 +[3,] 3 7 +[4,] 4 8 + +, , 2, 1 + + [,1] [,2] +[1,] 9 13 +[2,] 10 14 +[3,] 11 15 +[4,] 12 16 + +, , 1, 2 + + [,1] [,2] +[1,] 17 21 +[2,] 18 22 +[3,] 19 23 +[4,] 20 24 + +, , 2, 2 + + [,1] [,2] +[1,] 25 29 +[2,] 26 30 +[3,] 27 31 +[4,] 28 32 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:4; dim(x)<-c(1,2,2); x } +, , 1 + + [,1] [,2] +[1,] 1 2 + +, , 2 + + [,1] [,2] +[1,] 3 4 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c("a", "b"), "c", c("d", "e")); x } +, , d + + c +a 1 +b 2 + +, , e + + c +a 3 +b 4 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:4; dim(x)<-c(2,1,2); x } +, , 1 + + [,1] +[1,] 1 +[2,] 2 + +, , 2 + + [,1] +[1,] 3 +[2,] 4 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:4; dim(x)<-c(2,2,1); x } +, , 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:4; dim(x)<-c(2,2,1,1); x } +, , 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:64; dim(x)<-c(2,2,2,2,2,2); x } +, , 1, 1, 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2, 1, 1, 1 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + +, , 1, 2, 1, 1 + + [,1] [,2] +[1,] 9 11 +[2,] 10 12 + +, , 2, 2, 1, 1 + + [,1] [,2] +[1,] 13 15 +[2,] 14 16 + +, , 1, 1, 2, 1 + + [,1] [,2] +[1,] 17 19 +[2,] 18 20 + +, , 2, 1, 2, 1 + + [,1] [,2] +[1,] 21 23 +[2,] 22 24 + +, , 1, 2, 2, 1 + + [,1] [,2] +[1,] 25 27 +[2,] 26 28 + +, , 2, 2, 2, 1 + + [,1] [,2] +[1,] 29 31 +[2,] 30 32 + +, , 1, 1, 1, 2 + + [,1] [,2] +[1,] 33 35 +[2,] 34 36 + +, , 2, 1, 1, 2 + + [,1] [,2] +[1,] 37 39 +[2,] 38 40 + +, , 1, 2, 1, 2 + + [,1] [,2] +[1,] 41 43 +[2,] 42 44 + +, , 2, 2, 1, 2 + + [,1] [,2] +[1,] 45 47 +[2,] 46 48 + +, , 1, 1, 2, 2 + + [,1] [,2] +[1,] 49 51 +[2,] 50 52 + +, , 2, 1, 2, 2 + + [,1] [,2] +[1,] 53 55 +[2,] 54 56 + +, , 1, 2, 2, 2 + + [,1] [,2] +[1,] 57 59 +[2,] 58 60 + +, , 2, 2, 2, 2 + + [,1] [,2] +[1,] 61 63 +[2,] 62 64 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:64; dim(x)<-c(2,2,2,4,2); x } +, , 1, 1, 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2, 1, 1 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + +, , 1, 2, 1 + + [,1] [,2] +[1,] 9 11 +[2,] 10 12 + +, , 2, 2, 1 + + [,1] [,2] +[1,] 13 15 +[2,] 14 16 + +, , 1, 3, 1 + + [,1] [,2] +[1,] 17 19 +[2,] 18 20 + +, , 2, 3, 1 + + [,1] [,2] +[1,] 21 23 +[2,] 22 24 + +, , 1, 4, 1 + + [,1] [,2] +[1,] 25 27 +[2,] 26 28 + +, , 2, 4, 1 + + [,1] [,2] +[1,] 29 31 +[2,] 30 32 + +, , 1, 1, 2 + + [,1] [,2] +[1,] 33 35 +[2,] 34 36 + +, , 2, 1, 2 + + [,1] [,2] +[1,] 37 39 +[2,] 38 40 + +, , 1, 2, 2 + + [,1] [,2] +[1,] 41 43 +[2,] 42 44 + +, , 2, 2, 2 + + [,1] [,2] +[1,] 45 47 +[2,] 46 48 + +, , 1, 3, 2 + + [,1] [,2] +[1,] 49 51 +[2,] 50 52 + +, , 2, 3, 2 + + [,1] [,2] +[1,] 53 55 +[2,] 54 56 + +, , 1, 4, 2 + + [,1] [,2] +[1,] 57 59 +[2,] 58 60 + +, , 2, 4, 2 + + [,1] [,2] +[1,] 61 63 +[2,] 62 64 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:64; dim(x)<-c(4,4,4); x } +, , 1 + + [,1] [,2] [,3] [,4] +[1,] 1 5 9 13 +[2,] 2 6 10 14 +[3,] 3 7 11 15 +[4,] 4 8 12 16 + +, , 2 + + [,1] [,2] [,3] [,4] +[1,] 17 21 25 29 +[2,] 18 22 26 30 +[3,] 19 23 27 31 +[4,] 20 24 28 32 + +, , 3 + + [,1] [,2] [,3] [,4] +[1,] 33 37 41 45 +[2,] 34 38 42 46 +[3,] 35 39 43 47 +[4,] 36 40 44 48 + +, , 4 + + [,1] [,2] [,3] [,4] +[1,] 49 53 57 61 +[2,] 50 54 58 62 +[3,] 51 55 59 63 +[4,] 52 56 60 64 + + ##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint #{ x<-1:8; dim(x)<-c(2, 4); toString(x) } [1] "1, 2, 3, 4, 5, 6, 7, 8" @@ -39268,12 +40063,132 @@ NULL [1,] 1 3 5 7 [2,] 2 4 6 8 +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), NULL, NULL); x } +, , 1 + + [,1] [,2] +101 1 3 +102 2 4 + +, , 2 + + [,1] [,2] +101 5 7 +102 6 8 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), NULL, c(105, 106)); x } +, , 105 + + [,1] [,2] +101 1 3 +102 2 4 + +, , 106 + + [,1] [,2] +101 5 7 +102 6 8 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(103, 104), NULL); x } +, , 1 + + 103 104 +101 1 3 +102 2 4 + +, , 2 + + 103 104 +101 5 7 +102 6 8 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(103, 104), c(105, 106)); x } +, , 105 + + 103 104 +101 1 3 +102 2 4 + +, , 106 + + 103 104 +101 5 7 +102 6 8 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(105, 106)); x } +, , 1 + + 105 106 +101 1 3 +102 2 4 + +, , 2 + + 105 106 +101 5 7 +102 6 8 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-1:8; dim(x)<-c(2,2,2); x } +, , 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + + ##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint #{ x<-c(1,2); y<-list(x, 1, 2, 3); dim(y)<-c(2, 2); y } [,1] [,2] [1,] Numeric,2 2 [2,] 1 3 +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-c(1:2, 100003:100004,10005:10008); dim(x)<-c(2,2,2); x } +, , 1 + + [,1] [,2] +[1,] 1 100003 +[2,] 2 100004 + +, , 2 + + [,1] [,2] +[1,] 10005 10007 +[2,] 10006 10008 + + +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-c(1:4,10005:10008); dim(x)<-c(2,2,2); x } +, , 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2 + + [,1] [,2] +[1,] 10005 10007 +[2,] 10006 10008 + + ##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint #{ x<-character(0); y<-list(x, 1+1i, 2+2i, 3+3i); dim(y)<-c(2, 2); y } [,1] [,2] @@ -39296,6 +40211,21 @@ NULL [1,] List,4 2 [2,] 1 3 +##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint +#{ x<-list(1,2,3,4,5,6,7,8); dim(x)<-c(2,2,2); x } +, , 1 + + [,1] [,2] +[1,] 1 3 +[2,] 2 4 + +, , 2 + + [,1] [,2] +[1,] 5 7 +[2,] 6 8 + + ##com.oracle.truffle.r.test.simple.TestSimpleVectors.testPrint #{ z<-list(1,2,3,4); dim(z)<-c(2,2); x<-list(z,2,3,42); dim(x)<-c(2, 2); y<-list(x, 1, 2, 3); dim(y)<-c(2, 2); y } [,1] [,2] 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 13a43624521b057c15fa5cc84adb214a5916fc12..0522d824cdbb0f36ab67e60fb932a4b23428c529 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 @@ -6033,6 +6033,21 @@ public class AllTests extends TestBase { assertEval("{ x<-c(1); y<-c(1); dim(x)<-1; dim(y)<-1; attr(x, \"dimnames\")<-(attr(y, \"dimnames\")<-list(\"b\")); attributes(x) }"); } + @Test + public void TestSimpleBuiltins_testDimensions_60ce105fa17b875756e65d14e8dff5c3() { + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(NULL); attributes(x) }"); + } + + @Test + public void TestSimpleBuiltins_testDimensions_a030ab7282df112d4d7c259076dd0aa6() { + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), \"c\", c(\"d\", \"e\")); attributes(x) }"); + } + + @Test + public void TestSimpleBuiltins_testDimensions_87dd54d946d76d249f6f1254077b043c() { + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), 42, c(\"d\", \"e\")); attributes(x) }"); + } + @Test public void TestSimpleBuiltins_testDimensions_fd5ee9595105a81c94947c2282870d1d() { assertEval("{ x<-42; y<-(dim(x)<-1); }"); @@ -6143,6 +6158,26 @@ public class AllTests extends TestBase { assertEvalError("{ x<-1:4; attr(x, \"dimnames\")<-list(101, 102, 103, 104) }"); } + @Test + public void TestSimpleBuiltins_testDimensions_98fb2f33b520aa77b2ea86a7ad78eb2f() { + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\")); x }"); + } + + @Test + public void TestSimpleBuiltins_testDimensions_989da2c864d4ceee6a1239a1a4506808() { + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), NULL, c(\"d\")); x }"); + } + + @Test + public void TestSimpleBuiltins_testDimensions_50637ed13319c74f192676b625670ec3() { + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), 42, c(\"d\", \"e\", \"f\")); attributes(x) }"); + } + + @Test + public void TestSimpleBuiltins_testDimensions_7eb667774ce4ad670bbea6ea28d551e1() { + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), \"c\", c(\"d\", \"e\"), 7); attributes(x) }"); + } + @Test public void TestSimpleBuiltins_testDimensions_b89fca3316a99a6fae82c3f731c89989() { assertEvalError("{ x<-1; dim(x)<-1; dimnames(x)<-1; dimnames(x) }"); @@ -8648,6 +8683,21 @@ public class AllTests extends TestBase { assertEval("{ rev(c(1+1i, 2+2i)) }"); } + @Test + public void TestSimpleBuiltins_testRm_ca7a9f28edcdd3c7bf66a0b3735a11dc() { + assertEval("{ x <- 200 ; rm(\"x\") }"); + } + + @Test + public void TestSimpleBuiltins_testRm_7c0682fb8c9a86ff5b94ead1d97dbab6() { + assertEvalError("{ x <- 200 ; rm(\"x\") ; x }"); + } + + @Test + public void TestSimpleBuiltins_testRm_638fe08c6d320c8475e37234929ca562() { + assertEvalWarning("{ rm(\"ieps\") }"); + } + @Test public void TestSimpleBuiltins_testRound_33dc93cb0d4989bdf0b386cebae13f9d() { assertEval("{ round(0.4) }"); @@ -13738,6 +13788,141 @@ public class AllTests extends TestBase { assertEval("{ x<-list(1, 2, 3, 4); dim(x)<-c(2, 2); toString(x) }"); } + @Test + public void TestSimpleVectors_testPrint_c227b9929334bb2fd8e85a7fc27a0a62() { + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_cbf1decbcd38dea9aaf593c96b7ddec9() { + assertEval("{ x<-list(1,2,3,4,5,6,7,8); dim(x)<-c(2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_652efb0e3d197644eaf862f8a8358274() { + assertEval("{ x<-1:16; dim(x)<-c(2,2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_33625f228f215e90dca785f18ae6d1db() { + assertEval("{ x<-1:32; dim(x)<-c(2,2,2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_17457869fdb86ec6e041e20ba496a7c2() { + assertEval("{ x<-1:64; dim(x)<-c(2,2,2,2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_c7ff2bd7fba8e216c7350673ace9901a() { + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), NULL, NULL); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_0b4cdccccc0a6a09fb8816311a87493b() { + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(103, 104), NULL); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_88d879760a1d4d6d70c163f6b101551b() { + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(103, 104), c(105, 106)); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_8e23d61b4a3ecc43d7a3b32a02a365e7() { + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(105, 106)); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_e5a4975280a8bb37b70d51826cfb83e2() { + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), NULL, c(105, 106)); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_01b5961257e84363c7f3e1e197091c4d() { + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), \"c\", c(\"d\", \"e\")); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_6c779ed900c8e2abe428d228b96e9319() { + assertEval("{ x<-101:108; dim(x)<-c(2,2,2); dimnames(x)<-list(c(1, 2), c(3, 4), c(5, 6)); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_48685b68f49fd142b40c17c34b686a03() { + assertEval("{ x<-10001:10008; dim(x)<-c(2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_efbf44179f1ba5857a1edbf332e10fb5() { + assertEval("{ x<-c(1:2, 100003:100004,10005:10008); dim(x)<-c(2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_30107f4e77c1473f22795431639c8c2c() { + assertEval("{ x<-c(1:4,10005:10008); dim(x)<-c(2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_1b6f7c0c459865d98873e1e045c36e0b() { + assertEval("{ x<-1:16; dim(x)<-c(2,4,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_c3b8c4e50d796d4d3a3e54bbd92c0b13() { + assertEval("{ x<-1:32; dim(x)<-c(4,2,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_6973675d621590a897682c6943e0e97f() { + assertEval("{ x<-1:32; dim(x)<-c(2,4,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_1ac72e8058e1e4e3cbcc3c819e1cea22() { + assertEval("{ x<-1:32; dim(x)<-c(2,2,4,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_e6805e12f0418d16fbbacf74b58a4667() { + assertEval("{ x<-1:32; dim(x)<-c(2,2,2,4); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_3e24af09eb7d8f00b2e3972fdde9b773() { + assertEval("{ x<-1:64; dim(x)<-c(4,4,4); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_f8456a1d3fda495af109147a4dd0cef2() { + assertEval("{ x<-1:256; dim(x)<-c(4,4,4,4); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_38265eb3763a6030a7d2c9f0a0b051dd() { + assertEval("{ x<-1:64; dim(x)<-c(2,2,2,4,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_3bed41bb0850feb512afc7fc8c6005a1() { + assertEval("{ x<-1:4; dim(x)<-c(2,2,1); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_cabfc5cdcbfb67d9ec4d395095ee8635() { + assertEval("{ x<-1:4; dim(x)<-c(2,2,1,1); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_d171a6dc0219f3a8476f11bc9ec328ec() { + assertEval("{ x<-1:4; dim(x)<-c(1,2,2); x }"); + } + + @Test + public void TestSimpleVectors_testPrint_f3603e1eb847493e36900b208b7c1631() { + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); x }"); + } + @Test public void TestSimpleVectors_testScalarDoubleAsVector_9acec1f4b64be4651d8f6034c161155e() { assertEval("{ x<-1; x[1L] }"); 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 b0b683097bf5038d2b66d38e6157322e50125059..ef40734f136f24772f6af664d1969277744717ef 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 @@ -825,6 +825,13 @@ public class TestSimpleBuiltins extends TestBase { // assigning an "invisible" list returned by "attr(y, dimnames)<-" as dimnames attribute for // x assertEval("{ x<-c(1); y<-c(1); dim(x)<-1; dim(y)<-1; attr(x, \"dimnames\")<-(attr(y, \"dimnames\")<-list(\"b\")); attributes(x) }"); + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(NULL); attributes(x) }"); + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\")); x }"); + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), NULL, c(\"d\")); x }"); + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), 42, c(\"d\", \"e\", \"f\")); attributes(x) }"); + assertEvalError("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), \"c\", c(\"d\", \"e\"), 7); attributes(x) }"); + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), \"c\", c(\"d\", \"e\")); attributes(x) }"); + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), 42, c(\"d\", \"e\")); attributes(x) }"); // there should be no output assertEval("{ x<-42; y<-(dim(x)<-1); }"); @@ -2306,4 +2313,11 @@ public class TestSimpleBuiltins extends TestBase { assertEval("{ f <- function() { invisible(23) } ; toString(f()) }"); } + @Test + public void testRm() { + assertEvalError("{ x <- 200 ; rm(\"x\") ; x }"); + assertEvalWarning("{ rm(\"ieps\") }"); + assertEval("{ x <- 200 ; rm(\"x\") }"); + } + } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleVectors.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleVectors.java index bebd786c2fd4abab6763871d1f215abb8e101f1f..1fa8a146719f423acd5d14f259dd09bf128affaf 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleVectors.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/simple/TestSimpleVectors.java @@ -1392,5 +1392,34 @@ public class TestSimpleVectors extends TestBase { assertEval("{ z<-list(1,2,3,4); dim(z)<-c(2,2); x<-list(z,2,3,42); dim(x)<-c(2, 2); y<-list(x, 1, 2, 3); dim(y)<-c(2, 2); y }"); assertEval("{ x<-1:8; dim(x)<-c(2, 4); toString(x) }"); assertEval("{ x<-list(1, 2, 3, 4); dim(x)<-c(2, 2); toString(x) }"); + + // multiple dimensions + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); x }"); + assertEval("{ x<-list(1,2,3,4,5,6,7,8); dim(x)<-c(2,2,2); x }"); + assertEval("{ x<-1:16; dim(x)<-c(2,2,2,2); x }"); + assertEval("{ x<-1:32; dim(x)<-c(2,2,2,2,2); x }"); + assertEval("{ x<-1:64; dim(x)<-c(2,2,2,2,2,2); x }"); + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), NULL, NULL); x }"); + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(103, 104), NULL); x }"); + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(103, 104), c(105, 106)); x }"); + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), c(105, 106)); x }"); + assertEval("{ x<-1:8; dim(x)<-c(2,2,2); dimnames(x)<-list(c(101, 102), NULL, c(105, 106)); x }"); + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); dimnames(x)<-list(c(\"a\", \"b\"), \"c\", c(\"d\", \"e\")); x }"); + assertEval("{ x<-101:108; dim(x)<-c(2,2,2); dimnames(x)<-list(c(1, 2), c(3, 4), c(5, 6)); x }"); + assertEval("{ x<-10001:10008; dim(x)<-c(2,2,2); x }"); + assertEval("{ x<-c(1:2, 100003:100004,10005:10008); dim(x)<-c(2,2,2); x }"); + assertEval("{ x<-c(1:4,10005:10008); dim(x)<-c(2,2,2); x }"); + assertEval("{ x<-1:16; dim(x)<-c(2,4,2); x }"); + assertEval("{ x<-1:32; dim(x)<-c(4,2,2,2); x }"); + assertEval("{ x<-1:32; dim(x)<-c(2,4,2,2); x }"); + assertEval("{ x<-1:32; dim(x)<-c(2,2,4,2); x }"); + assertEval("{ x<-1:32; dim(x)<-c(2,2,2,4); x }"); + assertEval("{ x<-1:64; dim(x)<-c(4,4,4); x }"); + assertEval("{ x<-1:256; dim(x)<-c(4,4,4,4); x }"); + assertEval("{ x<-1:64; dim(x)<-c(2,2,2,4,2); x }"); + assertEval("{ x<-1:4; dim(x)<-c(2,2,1); x }"); + assertEval("{ x<-1:4; dim(x)<-c(2,2,1,1); x }"); + assertEval("{ x<-1:4; dim(x)<-c(1,2,2); x }"); + assertEval("{ x<-1:4; dim(x)<-c(2,1,2); x }"); } } diff --git a/mx.fastr/imports b/mx.fastr/imports index 2b9b797ac71bd6994899c304f0e7d2d204ed0431..7cc3b1719326ec2ce2f3bcd001a53559deb33391 100644 --- a/mx.fastr/imports +++ b/mx.fastr/imports @@ -1 +1 @@ -graal,1e01e2644a5db946e371d81aaa6199aca267b06d,http://hg.openjdk.java.net/graal/graal +graal,c6b1802ae32b4479f9efff39c98c9322c9e00a12,http://hg.openjdk.java.net/graal/graal