From 7347c535d650e3164b148c967351c66391fcb245 Mon Sep 17 00:00:00 2001 From: Zbysek Zapadlik Date: Thu, 27 Aug 2020 09:21:41 +0200 Subject: [PATCH 1/5] networkApi test getSpec --- py/tests/networkapi/getParameters_test.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/py/tests/networkapi/getParameters_test.py b/py/tests/networkapi/getParameters_test.py index f877a791a8..f383d87609 100644 --- a/py/tests/networkapi/getParameters_test.py +++ b/py/tests/networkapi/getParameters_test.py @@ -34,7 +34,7 @@ class NetworkAPI_getParameters_Test(unittest.TestCase): """ Unit tests for Network class. """ - def testGetSpec(self): + def testGetSpecJSON(self): """ A test of the Network.getSpecJSON( ) function. """ @@ -127,6 +127,19 @@ def testGetSpec(self): net = Network() json_str = net.getSpecJSON("RDSEEncoderRegion") self.assertEqual(json_str, expected) + + def testGetSpec(self): + """ + Test of region.getSpec() function. Testing if pybind pointers are correctly handled + """ + net = Network() + dateRegion = net.addRegion('dateEncoder', 'DateEncoderRegion', + str(dict(timeOfDay_width=30, + timeOfDay_radius=1, + weekend_width=21))) + + print(dateRegion.getSpec())# twice times to check if no double free arises + print(dateRegion.getSpec()) def testGetParameters(self): From 9d001770bdb7573057ac5cd47cf74064a9153633 Mon Sep 17 00:00:00 2001 From: Zbysek Zapadlik Date: Thu, 27 Aug 2020 09:23:47 +0200 Subject: [PATCH 2/5] without prints --- py/tests/networkapi/getParameters_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/tests/networkapi/getParameters_test.py b/py/tests/networkapi/getParameters_test.py index f383d87609..fc1c4416c1 100644 --- a/py/tests/networkapi/getParameters_test.py +++ b/py/tests/networkapi/getParameters_test.py @@ -138,8 +138,8 @@ def testGetSpec(self): timeOfDay_radius=1, weekend_width=21))) - print(dateRegion.getSpec())# twice times to check if no double free arises - print(dateRegion.getSpec()) + dateRegion.getSpec()# twice times to check if no double free arises + dateRegion.getSpec() def testGetParameters(self): From cc626b403431df2aed79cd23aadb986c28bbd8bd Mon Sep 17 00:00:00 2001 From: Zbysek Zapadlik Date: Wed, 2 Sep 2020 12:15:35 +0200 Subject: [PATCH 3/5] returning copy of shared ptr; making spec class shared_ptr holder type --- bindings/py/cpp_src/bindings/engine/py_Engine.cpp | 2 +- src/htm/engine/Region.hpp | 2 +- src/htm/engine/RegionImplFactory.cpp | 2 +- src/htm/engine/RegionImplFactory.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/py/cpp_src/bindings/engine/py_Engine.cpp b/bindings/py/cpp_src/bindings/engine/py_Engine.cpp index a60d4af163..fbdf107bc6 100644 --- a/bindings/py/cpp_src/bindings/engine/py_Engine.cpp +++ b/bindings/py/cpp_src/bindings/engine/py_Engine.cpp @@ -221,7 +221,7 @@ namespace htm_ext /////////////////// // Spec /////////////////// - py::class_ py_Spec(m, "Spec"); + py::class_> py_Spec(m, "Spec"); diff --git a/src/htm/engine/Region.hpp b/src/htm/engine/Region.hpp index cfa75f9eac..e5c7380f21 100644 --- a/src/htm/engine/Region.hpp +++ b/src/htm/engine/Region.hpp @@ -106,7 +106,7 @@ class Region : public Serializable { * * @returns The spec that describes this region */ - const std::shared_ptr &getSpec() const { return spec_; } + const std::shared_ptr getSpec() const { return spec_; } /** diff --git a/src/htm/engine/RegionImplFactory.cpp b/src/htm/engine/RegionImplFactory.cpp index 9da9f5d845..1cd9535a8c 100644 --- a/src/htm/engine/RegionImplFactory.cpp +++ b/src/htm/engine/RegionImplFactory.cpp @@ -207,7 +207,7 @@ RegionImpl *RegionImplFactory::deserializeRegionImpl(const std::string nodeType, -std::shared_ptr& RegionImplFactory::getSpec(const std::string nodeType) { +std::shared_ptr RegionImplFactory::getSpec(const std::string nodeType) { auto it = regionSpecMap.find(nodeType); if (it == regionSpecMap.end()) { NTA_THROW << "getSpec() -- unknown node type: '" << nodeType diff --git a/src/htm/engine/RegionImplFactory.hpp b/src/htm/engine/RegionImplFactory.hpp index 66fc0d4539..87167a98b9 100644 --- a/src/htm/engine/RegionImplFactory.hpp +++ b/src/htm/engine/RegionImplFactory.hpp @@ -60,7 +60,7 @@ class RegionImplFactory { // Returns node spec for a specific node type as a shared pointer. - std::shared_ptr& getSpec(const std::string nodeType); + std::shared_ptr getSpec(const std::string nodeType); // RegionImplFactory caches nodespecs and the dynamic library reference // This frees up the cached information. From 6e3d52787adadef6b3ef9aabf33441ff97f1d0be Mon Sep 17 00:00:00 2001 From: Zbysek Zapadlik Date: Wed, 2 Sep 2020 14:22:43 +0200 Subject: [PATCH 4/5] To string method & apostrophe instead of quotation marks --- bindings/py/cpp_src/bindings/engine/py_Engine.cpp | 1 + py/htm/advanced/regions/GridCellLocationRegion.py | 2 +- py/htm/advanced/regions/RawValues.py | 4 ++-- src/htm/regions/SPRegion.cpp | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bindings/py/cpp_src/bindings/engine/py_Engine.cpp b/bindings/py/cpp_src/bindings/engine/py_Engine.cpp index fbdf107bc6..2ae10dcfad 100644 --- a/bindings/py/cpp_src/bindings/engine/py_Engine.cpp +++ b/bindings/py/cpp_src/bindings/engine/py_Engine.cpp @@ -223,6 +223,7 @@ namespace htm_ext /////////////////// py::class_> py_Spec(m, "Spec"); + py_Spec.def("toString", &Spec::toString); diff --git a/py/htm/advanced/regions/GridCellLocationRegion.py b/py/htm/advanced/regions/GridCellLocationRegion.py index e05b603602..ce36338023 100644 --- a/py/htm/advanced/regions/GridCellLocationRegion.py +++ b/py/htm/advanced/regions/GridCellLocationRegion.py @@ -40,7 +40,7 @@ class GridCellLocationRegion(PyRegion): gaussian activity bumps that move as the population receives motor input. When two bumps are near each other, the intermediate cells have higher firing rates than they would with a single bump. The cells with firing rates above a - certain threshold are considered "active". When the network receives a motor + certain threshold are considered 'active'. When the network receives a motor command, it shifts its bumps. The cells are distributed uniformly through the rhombus, packed in the optimal diff --git a/py/htm/advanced/regions/RawValues.py b/py/htm/advanced/regions/RawValues.py index 9b55815a5e..582a7e6203 100644 --- a/py/htm/advanced/regions/RawValues.py +++ b/py/htm/advanced/regions/RawValues.py @@ -26,9 +26,9 @@ class RawValues(PyRegion): """ - RawDate is a simple region used to send raw scalar values into networks. + RawValues is a simple region used to send raw scalar values into networks. - It accepts data using the command "addDataToQueue" or through the function + It accepts data using the command 'addDataToQueue' or through the function addDataToQueue() which can be called directly from Python. Data is queued up in a FIFO and each call to compute pops the top element. diff --git a/src/htm/regions/SPRegion.cpp b/src/htm/regions/SPRegion.cpp index 1bb8f3328d..654aab4506 100644 --- a/src/htm/regions/SPRegion.cpp +++ b/src/htm/regions/SPRegion.cpp @@ -190,7 +190,7 @@ Spec *SPRegion::createSpec() { "SPRegion. This implements the Spatial Pooler algorithm as a plugin " "for the Network framework. The Spatial Pooler manages relationships " "between the columns of a region and the inputs bits. The primary " - "public interface to this function is the \"compute\" method, which " + "public interface to this function is the 'compute' method, which " "takes in an input vector and returns a list of activeColumns columns."; From a2b8ab13f48eab71aa06326d86d2af46e51bd45a Mon Sep 17 00:00:00 2001 From: Zbysek Zapadlik Date: Wed, 2 Sep 2020 14:52:11 +0200 Subject: [PATCH 5/5] Apostrophe instead of quotation marks --- src/htm/regions/SPRegion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/htm/regions/SPRegion.cpp b/src/htm/regions/SPRegion.cpp index 654aab4506..d973c7b6eb 100644 --- a/src/htm/regions/SPRegion.cpp +++ b/src/htm/regions/SPRegion.cpp @@ -372,7 +372,7 @@ Spec *SPRegion::createSpec() { ParameterSpec("(float)\n" "The default connected threshold.Any synapse whose " "permanence value is " - "above the connected threshold is a \"connected synapse\", " + "above the connected threshold is a 'connected synapse', " "meaning it can " "contribute to the cell's firing. Default ``0.1``.", NTA_BasicType_Real32, // type @@ -404,7 +404,7 @@ Spec *SPRegion::createSpec() { "when " "either its previously learned inputs are no longer ever active, or " "when " - "the vast majority of them have been \"hijacked\" by other " + "the vast majority of them have been 'hijacked' by other " "columns.Default " "``0.001``.", NTA_BasicType_Real32, // type