mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
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.
This commit is contained in:
@@ -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<index.vector.count(); i++) {
|
||||
int it=index.vector[i];
|
||||
if (it < 0 || it >= 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
|
||||
|
||||
Reference in New Issue
Block a user