From 0da386c8facf40518141f867a89c53d5bc6ced70 Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Fri, 26 Jan 2024 15:22:12 +0100 Subject: [PATCH] Model: mark more methods const, dont use is in python code with litterals, the torchscript compiler is fine with this, cpython is not --- eisgenerator/model.h | 4 ++-- model.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eisgenerator/model.h b/eisgenerator/model.h index f4f4541..75072ea 100644 --- a/eisgenerator/model.h +++ b/eisgenerator/model.h @@ -161,7 +161,7 @@ public: * * @return The uid. */ - size_t getUuid(); + size_t getUuid() const; /** * @brief Returns a vector of pointers to the circuit elements in this model. @@ -267,7 +267,7 @@ public: * * @return The function name in the code for this model. */ - std::string getCompiledFunctionName(); + std::string getCompiledFunctionName() const; /** * @brief Gets the function name in the code returned by getTorchScript and getCode for this model. diff --git a/model.cpp b/model.cpp index 21e0892..4fdbc68 100644 --- a/model.cpp +++ b/model.cpp @@ -565,7 +565,7 @@ std::vector<size_t> Model::getRecommendedParamIndices(eis::Range omegaRange, dou return indices; } -size_t Model::getUuid() +size_t Model::getUuid() const { return std::hash<std::string>{}(getModelStr()); } @@ -658,14 +658,14 @@ std::string Model::getTorchScript() std::stringstream out; out<<"def "<<getCompiledFunctionName()<<"(parameters: torch.Tensor, omegas: torch.Tensor) -> torch.Tensor:\n"; - out<<" assert parameters.size(0) is "<<parameters.size()<<"\n\n"; + out<<" assert parameters.size(0) == "<<parameters.size()<<"\n\n"; for(size_t i = 0; i < parameters.size(); ++i) out<<" "<<parameters[i]<<" = parameters["<<i<<"]\n"; out<<"\n return "<<formular<<"+0*omegas\n"; return out.str(); } -std::string Model::getCompiledFunctionName() +std::string Model::getCompiledFunctionName() const { return "model_"+std::to_string(getUuid()); } -- GitLab