Skip to content

Commit ada5d50

Browse files
committed
allow phase to be an integer in addRegion() and run()
1 parent f12b93c commit ada5d50

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

TestOutputDir/TestOutput.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.
-1.22 KB
Binary file not shown.

src/htm/engine/Network.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ class Link;
229229
const std::string &nodeType,
230230
const std::string &nodeParams,
231231
const std::set<UInt32> &phases);
232+
// An overload to use with a single phase as an integer (avoid warning of scaler initializer)
233+
std::shared_ptr<Region> addRegion(const std::string &name,
234+
const std::string &nodeType,
235+
const std::string &nodeParams,
236+
UInt32 phase) {
237+
std::set<UInt32> phases;
238+
phases.insert(phase);
239+
return addRegion(name, nodeType, nodeParams, phases);
240+
}
232241
// An overload to use without phases (region placed in phase 0)
233242
std::shared_ptr<Region> addRegion(const std::string &name,
234243
const std::string &nodeType,

src/test/unit/engine/NetworkTest.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,15 @@ TEST(NetworkTest, Callback) {
516516

517517
TEST(NetworkTest, Scenario1) {
518518
// This is intended to demonstrate execution order as A B C D C D C D E
519+
// Here we create three phases, phase 1 containing A and B,
520+
// phase 2 containing phases C and D, and phase 3 containing E.
519521
Network n;
520522

521-
std::shared_ptr<Region> regionA = n.addRegion("A", "TestNode", "{dim: [1]}", {1});
522-
std::shared_ptr<Region> regionB = n.addRegion("B", "TestNode", "{dim: [1]}", {1});
523-
std::shared_ptr<Region> regionC = n.addRegion("C", "TestNode", "{dim: [1]}", {2});
524-
std::shared_ptr<Region> regionD = n.addRegion("D", "TestNode", "{dim: [1]}", {2});
525-
std::shared_ptr<Region> regionE = n.addRegion("E", "TestNode", "{dim: [1]}", {3});
523+
std::shared_ptr<Region> regionA = n.addRegion("A", "TestNode", "{dim: [1]}", 1);
524+
std::shared_ptr<Region> regionB = n.addRegion("B", "TestNode", "{dim: [1]}", 1);
525+
std::shared_ptr<Region> regionC = n.addRegion("C", "TestNode", "{dim: [1]}", 2);
526+
std::shared_ptr<Region> regionD = n.addRegion("D", "TestNode", "{dim: [1]}", 2);
527+
std::shared_ptr<Region> regionE = n.addRegion("E", "TestNode", "{dim: [1]}", 3);
526528

527529
regionA->setParameterUInt64("computeCallback", (UInt64)recordCompute);
528530
regionB->setParameterUInt64("computeCallback", (UInt64)recordCompute);
@@ -531,9 +533,9 @@ TEST(NetworkTest, Scenario1) {
531533
regionE->setParameterUInt64("computeCallback", (UInt64)recordCompute);
532534

533535
computeHistory.clear();
534-
n.run(1, {1}); // execute A, B once
535-
n.run(3, {2}); // execute C, D three times
536-
n.run(1, {3}); // execute E once
536+
n.run(1, 1); // execute A, B once
537+
n.run(3, 2); // execute C, D three times
538+
n.run(1, 3); // execute E once
537539

538540
ASSERT_EQ(9u, computeHistory.size());
539541
EXPECT_STREQ("A", computeHistory.at(0).c_str());
@@ -545,6 +547,10 @@ TEST(NetworkTest, Scenario1) {
545547
EXPECT_STREQ("C", computeHistory.at(6).c_str());
546548
EXPECT_STREQ("D", computeHistory.at(7).c_str());
547549
EXPECT_STREQ("E", computeHistory.at(8).c_str());
550+
551+
552+
n.run(1, {1, 2}); // execute just phase 1 and 2
553+
n.run(1); // execute all phases
548554
}
549555

550556
/**
@@ -695,10 +701,10 @@ TEST(NetworkTest, Scenario2) {
695701
std::shared_ptr<Region> input = n.getRegion("INPUT");
696702
const Array &input_data = input->getOutputData("begin");
697703
EXPECT_EQ(input_data.asVector<UInt32>(), initialdata);
698-
n.run(1, {0}); // execute the internal INPUT region.
699-
n.run(1, {1}); // execute A, B once
700-
n.run(3, {2}); // execute C, D three times
701-
n.run(1, {3}); // execute E once
704+
n.run(1, 0); // execute the internal INPUT region.
705+
n.run(1, 1); // execute A, B once
706+
n.run(3, 2); // execute C, D three times
707+
n.run(1, 3); // execute E once
702708

703709
// We should end with the first element incremented the same number of times
704710
// that LinkRegion was executed. This shows that the message went through

0 commit comments

Comments
 (0)