Package r.data.RArray

Examples of r.data.RArray.Names


            int parentIndex = -1;
            if (isize > 1) {
                for (; i < isize - 1; i++) { // shallow copy
                    if (!(b instanceof RList)) { throw RError.getSelectMoreThanOne(ast); }
                    RList l = (RList) b;
                    Names names = l.names();
                    if (names == null) { throw RError.getNoSuchIndexAtLevel(ast, i + 1); }
                    RSymbol s = RSymbol.getSymbol(index.getString(i));
                    int indexv = names.map(s);
                    if (indexv == -1) { throw RError.getNoSuchIndexAtLevel(ast, i + 1); }
                    int bsize = l.size();
                    RAny[] content = new RAny[bsize];
                    // TODO: add optimization like in the case with integer index (above)
                    int k = 0;
View Full Code Here


                if (!(index instanceof RString)) { throw new SpecializationException(Failure.NOT_STRING_INDEX); }
                RString irstr = (RString) index;
                if (irstr.size() != 1) { throw new SpecializationException(Failure.NOT_ONE_ELEMENT); }
                if (!(vector instanceof RArray)) { throw new SpecializationException(Failure.NOT_ARRAY_BASE); }
                RArray vrarr = (RArray) vector;
                Names names = vrarr.names();
                if (names == null) { throw new SpecializationException(Failure.UNSPECIFIED); }
                RSymbol symbol = RSymbol.getSymbol(irstr.getString(0));
                int i = names.map(symbol);
                if (i == -1) { throw new SpecializationException(Failure.UNSPECIFIED); }
                return getWithName(vrarr, i, subset);
            } catch (SpecializationException e) {
                Failure f = (Failure) e.getResult();
                if (DEBUG_SEL) Utils.debug("selection - SimpleScalarStringSelection failed: " + f);
View Full Code Here

                    if (i == RLogical.TRUE) { return base; }
                    if (i == RLogical.FALSE) { return Utils.createEmptyArray(base); }
                }
            } else if (index instanceof RString) {
                RSymbol name = RSymbol.getSymbol(((RString) index).getString(0));
                Names bnames = base.names();
                if (bnames == null) { return Utils.getBoxedNA(base); }
                i = bnames.map(name);
                if (i != -1) {
                    return getWithName(base, i, subset);
                } else {
                    return Utils.getNamedNA(base);
                }
View Full Code Here

            Utils.check(subset);
        }

        public static RAny executeIntVector(RInt indexArg, RArray base, ASTNode ast) {

            Names names = base.names();
            RSymbol[] symbols = (names == null) ? null : names.sequence();
            RSymbol[] newSymbols = null;
            int nzeros = 0;
            boolean hasNegative = false;
            boolean hasPositive = false;
            boolean hasNA = false;
View Full Code Here

        }

        public static RAny executeLogicalVector(RLogical index, RArray base) {
            int isize = index.size();
            int bsize = base.size();
            Names names = base.names();
            if (isize == 0) { return Utils.createEmptyArray(base, names != null); }
            RSymbol[] symbols = (names == null) ? null : names.sequence();
            RSymbol[] newSymbols = null;

            if (isize >= bsize) {
                // no re-use of index, but index can be longer than base
                int nsize = 0;
View Full Code Here

        }

        public static RAny executeStringVector(RString index, RArray base) {
            int isize = index.size();
            if (isize == 0) { return Utils.createEmptyArray(base, base.names() != null); }
            Names baseNames = base.names();
            if (baseNames == null) { return Utils.createNAArray(base, isize); }
            RSymbol[] symbols = new RSymbol[isize];
            RArray res = Utils.createArray(base, isize, true);
            for (int i = 0; i < isize; i++) {
                RSymbol symbol = RSymbol.getSymbol(index.getString(i));
                int v = baseNames.map(symbol);
                if (v != -1) {
                    res.set(i, base.get(v));
                    symbols[i] = symbol;
                } else {
                    Utils.setNA(res, i);
View Full Code Here

            try {
                if (!(base instanceof RArray)) { throw new SpecializationException(Failure.NOT_ARRAY_BASE); }
                RArray abase = (RArray) base;
                if (!(index instanceof RString)) { throw new SpecializationException(Failure.NOT_STRING_INDEX); }
                RString sindex = (RString) index;
                Names baseNames = abase.names();
                if (baseNames != null) {
                    if (abase instanceof RString) {
                        return TracingView.ViewTrace.trace(new RStringSubset((RString) abase, sindex, baseNames));
                    }
                    if (abase instanceof RDouble) {
View Full Code Here

                // the upper levels of recursive indexes have to be treated differently from the lowest level (the error semantics is different)
                // also, we know that the upper levels must be lists
                for (; i < isize - 1; i++) {
                    if (!(b instanceof RList)) { throw RError.getSelectMoreThanOne(ast); }
                    RList l = (RList) b;
                    Names names = l.names();
                    if (names == null) { throw RError.getNoSuchIndexAtLevel(ast, i + 1); }
                    RSymbol s = RSymbol.getSymbol(index.getString(i));
                    int indexv = names.map(s);
                    if (indexv == -1) { throw RError.getNoSuchIndexAtLevel(ast, i + 1); }
                    b = l.getRAny(indexv);
                }
            }
            // selection at the last level
            if (!(b instanceof RArray)) { throw RError.getSubscriptBounds(ast); // NOTE: this makes more sense than the error message with integer index
            // (both are to mimic GNU-R)
            }
            RArray a = (RArray) b;
            Names names = a.names();
            int indexv = -1;
            if (names != null) {
                RSymbol s = RSymbol.getSymbol(index.getString(i));
                indexv = names.map(s);
            }
            boolean isList = a instanceof RList;
            if (indexv != -1) {
                if (isList) {
                    return ((RList) a).getRAny(indexv);
View Full Code Here

    public static class ScalarStringSelection {
        public static RArray genericUpdate(RArray base, String index, RAny value, boolean subset, ASTNode ast) {
            RArray typedBase;
            Object rawValue;
            int[] dimensions = base.dimensions();
            Names names = base.names();

            if (value instanceof RList) { // FIXME: this code gets copied around a few times, could it be refactored without a performance penalty?
                if (base instanceof RList) {
                    typedBase = base;
                } else {
                    typedBase = base.asList();
                    dimensions = null;
                }
                RAny v = subset ? ((RList) value).getRAny(0) : value;
                v.ref();
                rawValue = v;
            } else if (base instanceof RList) {
                typedBase = base;
                rawValue = value;
                value.ref();
            } else if (base instanceof RRaw) {
                if (value instanceof RRaw) {
                    typedBase = base;
                    rawValue = ((RRaw) value).get(0);
                } else {
                    throw RError.getSubassignTypeFix(ast, value.typeOf(), base.typeOf());
                }
            } else if (value instanceof RRaw) {
                throw RError.getSubassignTypeFix(ast, value.typeOf(), base.typeOf());
            } else if (base instanceof RString || value instanceof RString) {
                typedBase = base.asString();
                rawValue = value.asString().get(0);
            } else if (base instanceof RComplex || value instanceof RComplex) {
                typedBase = base.asComplex();
                rawValue = value.asComplex().get(0);
            } else if (base instanceof RDouble || value instanceof RDouble) {
                typedBase = base.asDouble();
                rawValue = value.asDouble().get(0);
            } else if (base instanceof RInt || value instanceof RInt) {
                typedBase = base.asInt();
                rawValue = value.asInt().get(0);
            } else {
                assert Utils.check(base instanceof RLogical || base instanceof RNull);
                assert Utils.check(value instanceof RLogical);
                typedBase = base.asLogical();
                rawValue = ((RLogical) value).get(0);
            }
            int bsize = base.size();
            int pos = -1;
            RSymbol symbol = RSymbol.getSymbol(index);
            if (names != null) {
                pos = names.map(symbol);
            }
            if (pos != -1) {
                // updating
                if (base == typedBase && !base.isShared()) {
                    base.set(pos, rawValue);
View Full Code Here

            }
            i++;
            for (; j < nsize; j++) { // shallow copy
                content[j] = base.getRAny(i++);
            }
            Names bnames = base.names();
            return RList.RListFactory.getFor(content, null, bnames == null ? null : removeName(bnames, index), base.attributesRef()); // drop dimensions
        }
View Full Code Here

TOP

Related Classes of r.data.RArray.Names

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.