From a89396c5d4d8069ddf6f0475605ba241dae95f4c Mon Sep 17 00:00:00 2001 From: Pierre Alexandre Tremblay Date: Fri, 20 Jun 2025 16:03:06 +0200 Subject: [PATCH] dataset and kdtree - k nearest is checked for min number of k --- include/flucoma/clients/nrt/DataSetClient.hpp | 2 +- include/flucoma/clients/nrt/KDTreeClient.hpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/flucoma/clients/nrt/DataSetClient.hpp b/include/flucoma/clients/nrt/DataSetClient.hpp index e80a10d7..0b044cb8 100644 --- a/include/flucoma/clients/nrt/DataSetClient.hpp +++ b/include/flucoma/clients/nrt/DataSetClient.hpp @@ -350,7 +350,7 @@ namespace dataset { constexpr auto DataSetReadParams = defineParameters( InputDataSetClientRef::makeParam("dataSet", "DataSet Name"), - LongParam("numNeighbours", "Number of Nearest Neighbours", 1), + LongParam("numNeighbours", "Number of Nearest Neighbours", 1, Min(1)), InputDataSetClientRef::makeParam("lookupDataSet", "Lookup DataSet Name"), InputBufferParam("inputPointBuffer", "Input Point Buffer"), BufferParam("predictionBuffer", "Prediction Buffer")); diff --git a/include/flucoma/clients/nrt/KDTreeClient.hpp b/include/flucoma/clients/nrt/KDTreeClient.hpp index bee49eae..0853988e 100644 --- a/include/flucoma/clients/nrt/KDTreeClient.hpp +++ b/include/flucoma/clients/nrt/KDTreeClient.hpp @@ -21,7 +21,7 @@ namespace kdtree { constexpr auto KDTreeParams = defineParameters( StringParam>("name", "Name"), - LongParam("numNeighbours", "Number of Nearest Neighbours", 1), + LongParam("numNeighbours", "Number of Nearest Neighbours", 1, Min(0)), FloatParam("radius", "Maximum distance", 0, Min(0))); class KDTreeClient : public FluidBaseClient, @@ -79,6 +79,8 @@ class KDTreeClient : public FluidBaseClient, Optional nNeighbours) const { index k = nNeighbours ? nNeighbours.value() : get(); + + if (k < 0) return Error(SmallK); auto reply = computeKnearest(data, k); if (!reply.ok()) return reply; @@ -98,6 +100,9 @@ class KDTreeClient : public FluidBaseClient, Optional nNeighbours) const { index k = nNeighbours ? nNeighbours.value() : get(); + + if (k < 0) return Error(SmallK); + auto reply = computeKnearest(data, k); if (!reply.ok()) return reply; @@ -149,7 +154,7 @@ using KDTreeRef = SharedClientRef; constexpr auto KDTreeQueryParams = defineParameters( KDTreeRef::makeParam("tree", "KDTree"), - LongParam("numNeighbours", "Number of Nearest Neighbours", 1), + LongParam("numNeighbours", "Number of Nearest Neighbours", 1, Min(0)), FloatParam("radius", "Maximum distance", 0, Min(0)), InputDataSetClientRef::makeParam("lookupDataSet", "Lookup DataSet Name"), InputBufferParam("inputPointBuffer", "Input Point Buffer"),