From dfc8230820711e230bc30c3fd32727be5b433f20 Mon Sep 17 00:00:00 2001 From: Michael Haupt <michael.haupt@oracle.com> Date: Tue, 11 Nov 2014 14:15:47 +0100 Subject: [PATCH] support col internal --- .../truffle/r/nodes/builtin/base/Col.java | 56 +++++++++++++++++++ .../com/oracle/truffle/r/runtime/RError.java | 4 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Col.java diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Col.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Col.java new file mode 100644 index 0000000000..06bf211157 --- /dev/null +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Col.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, 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 static com.oracle.truffle.r.runtime.RBuiltinKind.*; + +import java.util.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.r.nodes.builtin.*; +import com.oracle.truffle.r.runtime.*; +import com.oracle.truffle.r.runtime.data.*; + +@RBuiltin(name = "col", kind = INTERNAL, parameterNames = {"dims"}) +public abstract class Col extends RBuiltinNode { + + @Specialization + protected RIntVector col(@SuppressWarnings("unused") RNull x) { + controlVisibility(); + throw RError.error(getEncapsulatingSourceSection(), RError.Message.MATRIX_LIKE_REQUIRED, "col"); + } + + @Specialization + protected RIntVector col(RIntVector x) { + controlVisibility(); + int nrows = x.getDataAt(0); + int ncols = x.getDataAt(1); + int[] result = new int[nrows * ncols]; + for (int i = 0; i < ncols; ++i) { + int colstart = i * nrows; + Arrays.fill(result, colstart, colstart + nrows, i + 1); + } + return RDataFactory.createIntVector(result, RDataFactory.COMPLETE_VECTOR, new int[]{nrows, ncols}); + } + +} 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 c5ad5fba8b..81d268d5a2 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 @@ -557,7 +557,9 @@ public final class RError extends RuntimeException { DEFAULT_METHOD_NOT_IMPLEMENTED_FOR_TYPE("default method not implemented for type '%s'"), ADDING_INVALID_CLASS("adding class \"%s\" to an invalid object"), IS_NA_TO_NON_VECTOR("is.na() applied to non-(list or vector) of type '%s'"), - NOT_MEANINGFUL_FOR_FACTORS("%s not meaningful for factors"); + NOT_MEANINGFUL_FOR_FACTORS("%s not meaningful for factors"), + INPUTS_DIFFERENT_LENGTHS("inputs of different lengths"), + MATRIX_LIKE_REQUIRED("a matrix-like object is required as argument to '%s'"); public final String message; private final boolean hasArgs; -- GitLab