From 917bbab17322f37ffcdc593aa35eff5cf1b78d0d Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Thu, 19 Mar 2020 11:31:20 +0000 Subject: [PATCH] Datafilter - bool() .. bool(expr) - returns 0 or 1 for the expression passed. This allows a logical expression to be used in a formula (which is useful when fitting models). e.g a*(x>1) is invalid, whilst a*bool(x>1) is not. --- src/Core/DataFilter.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Core/DataFilter.cpp b/src/Core/DataFilter.cpp index 1d6ca2fad..c80104093 100644 --- a/src/Core/DataFilter.cpp +++ b/src/Core/DataFilter.cpp @@ -181,6 +181,11 @@ static struct { // diagnostics goodness of fit measures [ success, RMSE, CV ] where a non-zero value // for success means true, if it is false, RMSE and CV will be set to -1 + { "bool", 1 }, // bool(e) - will turn the passed parameter into a boolean with value 0 or 1 + // this is useful for embedding logical expresissions into formulas. Since the + // grammar does not support (a*x>1), instead we can use a*bool(x>1). All non + // zero expressions will evaluate to 1. + // add new ones above this line { "", -1 } }; @@ -2416,6 +2421,13 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem } } + // bool(expr) + if (leaf->function == "bool") { + Result r=eval(df, leaf->fparms[0],x, it, m, p, c, s, d); + if (r.number != 0) return Result(1); + else return Result(0); + } + // c (concat into a vector) if (leaf->function == "c") {