From 777e5c15c2985759006d38651280e3dbd1c2fae3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 09:05:27 +0000 Subject: [PATCH 1/2] Move shared object name out of the parameter list The name used to be fixed parameter 0 of every shared client, and the shared instance adaptor keyed its lookup tables on it, so it could not change after construction. The adaptor now owns the name: ParamAliasAdaptor gains name(), setName() (create-or-join, formerly done in setFixedParameterValues) and rename(), which re-keys both lookup tables while leaving the shared client and its parameters untouched. The name parameter and kName are removed from all shared clients, so remaining parameter indices shift down by one. Clients that print their name inherit the new NamedObject mixin, which the adaptor keeps up to date across renames. Host wrappers need to pass the name through setName() and read it with name() instead of using parameter 0. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01J2M1cHdyiJWcPaKy2FRnMe --- .../clients/common/FluidBaseClient.hpp | 14 ++ include/flucoma/clients/nrt/CorpusClient.hpp | 10 +- include/flucoma/clients/nrt/DataClient.hpp | 1 - include/flucoma/clients/nrt/DataSetClient.hpp | 6 +- .../nrt/FluidSharedInstanceAdaptor.hpp | 109 +++++++++--- include/flucoma/clients/nrt/KDTreeClient.hpp | 3 +- include/flucoma/clients/nrt/KMeansClient.hpp | 3 +- .../clients/nrt/KNNClassifierClient.hpp | 3 +- .../clients/nrt/KNNRegressorClient.hpp | 3 +- .../flucoma/clients/nrt/LabelSetClient.hpp | 6 +- .../clients/nrt/MLPClassifierClient.hpp | 2 - .../clients/nrt/MLPRegressorClient.hpp | 2 - .../flucoma/clients/nrt/NormalizeClient.hpp | 4 +- include/flucoma/clients/nrt/PCAClient.hpp | 3 +- include/flucoma/clients/nrt/ProviderTest.hpp | 9 +- .../flucoma/clients/nrt/RobustScaleClient.hpp | 3 +- include/flucoma/clients/nrt/SKMeansClient.hpp | 3 +- .../flucoma/clients/nrt/StandardizeClient.hpp | 4 +- include/flucoma/clients/nrt/UMAPClient.hpp | 2 - tests/CMakeLists.txt | 2 + .../common/TestSharedInstanceAdaptor.cpp | 164 ++++++++++++++++++ 21 files changed, 291 insertions(+), 65 deletions(-) create mode 100644 tests/clients/common/TestSharedInstanceAdaptor.cpp diff --git a/include/flucoma/clients/common/FluidBaseClient.hpp b/include/flucoma/clients/common/FluidBaseClient.hpp index ea7ac98f7..3aeeb3f9d 100644 --- a/include/flucoma/clients/common/FluidBaseClient.hpp +++ b/include/flucoma/clients/common/FluidBaseClient.hpp @@ -20,6 +20,8 @@ under the European Union’s Horizon 2020 research and innovation programme #include "TupleUtilities.hpp" #include "../../data/FluidIndex.hpp" #include "../../data/FluidMeta.hpp" +#include +#include #include namespace fluid { @@ -29,6 +31,18 @@ namespace client { struct ModelObject {}; +// Mixin for shared clients that want to know the name they are registered +// under (e.g. for printing). The name is not a parameter: it is owned by +// NRTSharedInstanceAdaptor, which keeps this copy up to date. +struct NamedObject +{ + void setName(std::string_view name) { mName = name; } + const std::string& name() const { return mName; } + +private: + std::string mName; +}; + enum ProcessState { kNoProcess, kProcessing, kDone, kDoneStillProcessing }; struct ControlChannel { diff --git a/include/flucoma/clients/nrt/CorpusClient.hpp b/include/flucoma/clients/nrt/CorpusClient.hpp index dd700f32d..fbd4c474c 100644 --- a/include/flucoma/clients/nrt/CorpusClient.hpp +++ b/include/flucoma/clients/nrt/CorpusClient.hpp @@ -30,12 +30,14 @@ namespace fluid { namespace client { namespace corpus { -enum { kName }; constexpr auto CorpusParams = - defineParameters(StringParam>("name", "Corpus name")); + defineParameters(); -class CorpusClient : public FluidBaseClient, public OfflineIn, public OfflineOut +class CorpusClient : public FluidBaseClient, + public OfflineIn, + public OfflineOut, + public NamedObject { using string = std::string; using Buffer = typename BufferT::type; @@ -72,8 +74,6 @@ class CorpusClient : public FluidBaseClient, public OfflineIn, public OfflineOut return {}; } - std::string name() const { return get(); } - MessageResult addPoint(string label, Buffer buffer, size_t offset, int length) { diff --git a/include/flucoma/clients/nrt/DataClient.hpp b/include/flucoma/clients/nrt/DataClient.hpp index 292afd409..537fa6a2f 100644 --- a/include/flucoma/clients/nrt/DataClient.hpp +++ b/include/flucoma/clients/nrt/DataClient.hpp @@ -37,7 +37,6 @@ class DataClient return OK(); } - MessageResult write(string fileName) { auto file = JSONFile(fileName, "w"); diff --git a/include/flucoma/clients/nrt/DataSetClient.hpp b/include/flucoma/clients/nrt/DataSetClient.hpp index 70a96f1c5..1d7c4741a 100644 --- a/include/flucoma/clients/nrt/DataSetClient.hpp +++ b/include/flucoma/clients/nrt/DataSetClient.hpp @@ -22,10 +22,9 @@ namespace fluid { namespace client { namespace dataset { -enum { kName }; constexpr auto DataSetParams = - defineParameters(StringParam>("name", "Name of the DataSet")); + defineParameters(); template double distance(FluidTensorView point1, FluidTensorView point2) @@ -53,6 +52,7 @@ auto sortedDistances(FluidTensorView x, FluidTensorView Y, class DataSetClient : public FluidBaseClient, OfflineIn, OfflineOut, + public NamedObject, public DataClient> { public: @@ -306,7 +306,7 @@ class DataSetClient : public FluidBaseClient, MessageResult print() { - return "DataSet " + std::string(get()) + ": " + mAlgorithm.print(); + return "DataSet " + name() + ": " + mAlgorithm.print(); } const DataSet& getDataSet() const { return mAlgorithm; } diff --git a/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp b/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp index 8c575b41b..d925b6c5c 100644 --- a/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp +++ b/include/flucoma/clients/nrt/FluidSharedInstanceAdaptor.hpp @@ -25,6 +25,9 @@ under the European Union’s Horizon 2020 research and innovation programme namespace fluid { namespace client { +template +class NRTSharedInstanceAdaptor; + template class ParamAliasAdaptor; @@ -45,6 +48,7 @@ class ParamAliasAdaptor> ParamSetType params{ClientWrapper::getParameterDescriptors(), FluidDefaultAllocator()}; ListenersArray listeners; + rt::string name; // key in the lookup tables; shared by all aliases std::shared_ptr getShared() { return shared_from_this(); }; }; @@ -70,8 +74,10 @@ class ParamAliasAdaptor> mParams.use_count() == 1) // is this the last remaining user of this // Corpus, except the hash table? { - auto name = mParams->params.template get<0>(); - mParamsTable.erase(name); // then remove it from the universe + auto entry = mParamsTable.find(mParams->name); + // then remove it from the universe (only if the entry is really ours) + if (entry != mParamsTable.end() && entry->second.lock() == mParams) + mParamsTable.erase(entry); } } @@ -128,35 +134,68 @@ class ParamAliasAdaptor> return {Result::Status::kWarning, name, " not found"}; } - template - auto setPrimaryParameterValues(bool reportage,Func&& f, Args&&...args) + /// The name this object's shared data is registered under + const rt::string& name() const { return mParams->name; } + + /// Give this object its name at creation time: if the name is already in + /// use, start sharing that entry, otherwise register a new one. + Result setName(rt::string name) { - return mParams->params.setPrimaryParameterValues(reportage, std::forward(f),std::forward(args)...); + if (!name.size()) + return {Result::Status::kWarning, + "Shared object given no name – won't be shared!"}; + + if (!mParamsTable.count(name)) // key not already in table + { + mParams->name = name; + mParamsTable.emplace(name, mParams); + } + + return refer(name); } - - template