From 3559395c83c1c16a936b87a462ee9491b4c65962 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 14 Mar 2020 16:12:52 +0000 Subject: [PATCH] Fix [ expr ] when expr is a vector .. whilst its possible to assign to a selection of elements in a vector e.g. v[c(3,5,7)] <- 99 to assign 99 to el 3,5 and 7 I forgot to update the code to /return/ a vector e.g.; a <- v[c(3,5,7)] was not handled at all. This commit fixes that. It means we can select from a vector element-wise -or- via a logical expression. --- src/Core/DataFilter.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Core/DataFilter.cpp b/src/Core/DataFilter.cpp index 1a2f37f7f..28462c295 100644 --- a/src/Core/DataFilter.cpp +++ b/src/Core/DataFilter.cpp @@ -3827,12 +3827,29 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem // INDEXING INTO VECTORS case Leaf::Index : { - int index = eval(df,leaf->fparms[0],x, it, m, p, c, s, d).number; + Result index = eval(df,leaf->fparms[0],x, it, m, p, c, s, d); Result value = eval(df,leaf->lvalue.l,x, it, m, p, c, s, d); // lhs might also be a symbol - if (index < 0 || index >= value.vector.count()) return Result(0); // out of bounds + // are we returning the value or a vector of values? + if (index.vector.count()) { - return Result(value.vector[index]); + Result returning(0); + + // a range + for(int i=0; i= value.vector.count()) continue; // ignore out of bounds + returning.vector << value.vector[it]; + returning.number += value.vector[it]; + } + + return returning; + + } else { + // a single value + if (index.number < 0 || index.number >= value.vector.count()) return Result(0); + return Result(value.vector[index.number]); + } } // SELECTING FROM VECTORS