Skip to content

Commit e13661e

Browse files
authored
Merge branch 'master' into master
2 parents c3074b8 + 394054c commit e13661e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2837
-693
lines changed

src/Core/Algorithms/BrainStimulator/Tests/GenerateROIStatisticsAlgorithmTests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace
7575
(*expected_result)(0, 1) = 0.2023192248404992; (*expected_result)(1, 1) = std::numeric_limits<double>::quiet_NaN(); (*expected_result)(2, 1) = 0.270036948169627; (*expected_result)(3, 1) = 0.2819928747450936; (*expected_result)(4, 1) = 0.2464919130115238; (*expected_result)(5, 1) = 0.348358459345021; (*expected_result)(6, 1) = 0.3382031144990396; (*expected_result)(7, 1) = 0.1699586184078796;
7676
(*expected_result)(0, 2) = 0.1868726045543786; (*expected_result)(1, 2) = 0.7546866819823609; (*expected_result)(2, 2) = 0.1189976815583766; (*expected_result)(3, 2) = 0.223811939491137; (*expected_result)(4, 2) = 0.2550951154592691; (*expected_result)(5, 2) = 0.1386244428286791; (*expected_result)(6, 2) = 0.2435249687249893; (*expected_result)(7, 2) = 0.1965952504312082;
7777
(*expected_result)(0, 3) = 0.7951999011370632; (*expected_result)(1, 3) = 0.7546866819823609; (*expected_result)(2, 3) = 0.6797026768536748; (*expected_result)(3, 3) = 0.9597439585160811; (*expected_result)(4, 3) = 0.8909032525357985; (*expected_result)(5, 3) = 0.9592914252054443; (*expected_result)(6, 3) = 0.9292636231872278; (*expected_result)(7, 3) = 0.6160446761466392;
78-
(*expected_result)(0, 4) = 9; (*expected_result)(1, 4) = 1; (*expected_result)(2, 4) = 5; (*expected_result)(3, 4) = 5; (*expected_result)(4, 4) = 5; (*expected_result)(5, 4) = 5; (*expected_result)(6, 4) = 5; (*expected_result)(7, 4) = 5;
78+
(*expected_result)(0, 4) = 9; (*expected_result)(1, 4) = 1; (*expected_result)(2, 4) = 5; (*expected_result)(3, 4) = 5; (*expected_result)(4, 4) = 5; (*expected_result)(5, 4) = 5; (*expected_result)(6, 4) = 5; (*expected_result)(7, 4) = 5;
7979

8080
return expected_result;
8181
}
@@ -153,7 +153,7 @@ TEST(GenerateROIStatisticsAlgorithm, ValidInput_TestCoordinateSpace)
153153
FieldHandle atlas = CreateAtlas();
154154
FieldHandle createcoordcubesshiftby10 = CreateCoordinatesCubesShiftedBy10();
155155
FieldHandle createmeshsolution = CreateGetMeshSolution();
156-
const std::string& atlasMeshLabelsStr = std::string("Region1;Region2;Region3;Region4;Region5;Region6;Region7;Region8");
156+
std::string atlasMeshLabelsStr("Region1;Region2;Region3;Region4;Region5;Region6;Region7;Region8");
157157
DenseMatrixHandle specROI(new DenseMatrix(5, 1));
158158
(*specROI)(0, 0) = 10.5;
159159
(*specROI)(1, 0) = 10.5;

src/Core/Algorithms/Math/SolveLinearSystemWithEigen.cc

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,46 @@
3434
#include <Core/Datatypes/MatrixTypeConversions.h>
3535
#include <Eigen/Sparse>
3636

37+
using namespace SCIRun;
3738
using namespace SCIRun::Core::Algorithms::Math;
3839
using namespace SCIRun::Core::Datatypes;
3940
using namespace SCIRun::Core::Algorithms;
4041
using namespace SCIRun::Core;
4142

4243
namespace
4344
{
44-
template <class ColumnMatrixType>
45+
template <class ColumnMatrixType, template <typename> class SolverType>
4546
class SolveLinearSystemAlgorithmEigenCGImpl
4647
{
4748
public:
48-
SolveLinearSystemAlgorithmEigenCGImpl(const ColumnMatrixType& rhs, double tolerance, int maxIterations) :
49+
SolveLinearSystemAlgorithmEigenCGImpl(SharedPointer<ColumnMatrixType> rhs, double tolerance, int maxIterations) :
4950
tolerance_(tolerance), maxIterations_(maxIterations), rhs_(rhs) {}
5051

5152
using SolutionType = ColumnMatrixType;
5253

5354
template <class MatrixType>
5455
typename ColumnMatrixType::EigenBase solveWithEigen(const MatrixType& lhs)
5556
{
56-
Eigen::ConjugateGradient<typename MatrixType::EigenBase> cg;
57-
cg.compute(lhs);
57+
SolverType<typename MatrixType::EigenBase> solver;
58+
solver.compute(lhs);
5859

59-
if (cg.info() != Eigen::Success)
60+
if (solver.info() != Eigen::Success)
6061
BOOST_THROW_EXCEPTION(AlgorithmInputException()
61-
<< LinearAlgebraErrorMessage("Conjugate gradient initialization was unsuccessful")
62-
<< EigenComputationInfo(cg.info()));
63-
64-
cg.setTolerance(tolerance_);
65-
cg.setMaxIterations(maxIterations_);
66-
auto solution = cg.solve(rhs_).eval();
67-
tolerance_ = cg.error();
68-
maxIterations_ = cg.iterations();
62+
<< LinearAlgebraErrorMessage("Eigen solver initialization was unsuccessful")
63+
<< EigenComputationInfo(solver.info()));
64+
65+
solver.setTolerance(tolerance_);
66+
solver.setMaxIterations(maxIterations_);
67+
auto solution = solver.solve(*rhs_).eval();
68+
tolerance_ = solver.error();
69+
maxIterations_ = solver.iterations();
6970
return solution;
7071
}
7172

7273
double tolerance_;
7374
int maxIterations_;
7475
private:
75-
const ColumnMatrixType& rhs_;
76+
SharedPointer<ColumnMatrixType> rhs_;
7677
};
7778
}
7879

@@ -86,6 +87,14 @@ SolveLinearSystemAlgorithm::ComplexOutputs SolveLinearSystemAlgorithm::run(const
8687
return runImpl<ComplexInputs, ComplexOutputs>(input, params);
8788
}
8889

90+
template <typename T>
91+
using CG = Eigen::ConjugateGradient<T>;
92+
// Not available yet, need to upgrade Eigen
93+
// template <typename T>
94+
// using LSCG = Eigen::LeastSquaresConjugateGradient<T>;
95+
template <typename T>
96+
using BiCG = Eigen::BiCGSTAB<T>;
97+
8998
template <typename In, typename Out>
9099
Out SolveLinearSystemAlgorithm::runImpl(const In& input, const Parameters& params) const
91100
{
@@ -101,9 +110,32 @@ Out SolveLinearSystemAlgorithm::runImpl(const In& input, const Parameters& param
101110
int maxIterations = std::get<1>(params);
102111
ENSURE_POSITIVE_INT(maxIterations, "Max iterations out of range!");
103112

104-
using SolutionType = DenseMatrixGeneric<typename std::tuple_element<0, In>::type::element_type::value_type>;
105-
using SolverType = SolveLinearSystemAlgorithmEigenCGImpl<SolutionType>;
106-
SolverType impl(*b, tolerance, maxIterations);
113+
auto method = std::get<2>(params);
114+
115+
using SolutionType = DenseColumnMatrixGeneric<typename std::tuple_element<0, In>::type::element_type::value_type>;
116+
using AlgoTypeCG = SolveLinearSystemAlgorithmEigenCGImpl<SolutionType, CG>;
117+
using AlgoTypeBiCG = SolveLinearSystemAlgorithmEigenCGImpl<SolutionType, BiCG>;
118+
119+
if ("cg" == method)
120+
return solve<AlgoTypeCG, In, Out>(input, params);
121+
else if ("bicg" == method)
122+
return solve<AlgoTypeBiCG, In, Out>(input, params);
123+
else
124+
{
125+
BOOST_THROW_EXCEPTION(AlgorithmProcessingException() << ErrorMessage("Need to upgrade Eigen for LSCG."));
126+
}
127+
}
128+
129+
template <typename SolverType, typename In, typename Out>
130+
Out SolveLinearSystemAlgorithm::solve(const In& input, const Parameters& params) const
131+
{
132+
auto A = std::get<0>(input);
133+
auto b = std::get<1>(input);
134+
double tolerance = std::get<0>(params);
135+
int maxIterations = std::get<1>(params);
136+
137+
SolverType impl(b, tolerance, maxIterations);
138+
107139
typename SolverType::SolutionType x;
108140
if (matrixIs::dense(A))
109141
{
@@ -120,8 +152,7 @@ Out SolveLinearSystemAlgorithm::runImpl(const In& input, const Parameters& param
120152

121153
if (x.size() != 0)
122154
{
123-
/// @todo: move ctor
124-
auto solution(boost::make_shared<SolutionType>(x));
155+
auto solution(boost::make_shared<typename SolverType::SolutionType>(x));
125156
return Out(solution, impl.tolerance_, impl.maxIterations_);
126157
}
127158
else

src/Core/Algorithms/Math/SolveLinearSystemWithEigen.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ namespace Math {
4545
public:
4646
typedef std::tuple<SCIRun::Core::Datatypes::MatrixHandle, SCIRun::Core::Datatypes::DenseColumnMatrixHandle> Inputs;
4747
typedef std::tuple<SCIRun::Core::Datatypes::ComplexMatrixHandle, SCIRun::Core::Datatypes::ComplexDenseColumnMatrixHandle> ComplexInputs;
48-
typedef std::tuple<double, int> Parameters;
49-
typedef std::tuple<SCIRun::Core::Datatypes::DenseMatrixHandle, double, int> Outputs;
50-
typedef std::tuple<SCIRun::Core::Datatypes::ComplexDenseMatrixHandle, double, int> ComplexOutputs;
48+
typedef std::tuple<double, int, std::string> Parameters;
49+
typedef std::tuple<SCIRun::Core::Datatypes::DenseColumnMatrixHandle, double, int> Outputs;
50+
typedef std::tuple<SCIRun::Core::Datatypes::ComplexDenseColumnMatrixHandle, double, int> ComplexOutputs;
5151

5252
Outputs run(const Inputs& input, const Parameters& params) const;
5353
ComplexOutputs run(const ComplexInputs& input, const Parameters& params) const;
@@ -56,6 +56,8 @@ namespace Math {
5656
private:
5757
template <typename In, typename Out>
5858
Out runImpl(const In& input, const Parameters& params) const;
59+
template <typename SolverType, typename In, typename Out>
60+
Out solve(const In& input, const Parameters& params) const;
5961
};
6062

6163
typedef boost::error_info<struct tag_eigen_computation, Eigen::ComputationInfo> EigenComputationInfo;

src/Core/Algorithms/Math/Tests/SolveLinearSystemWithEigenTests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ TEST(EigenSparseSolverTest, DISABLED_CanSolveBigSystem)
344344
ScopedTimer t("using algorithm object");
345345
SolveLinearSystemAlgorithm algo;
346346

347-
x = algo.run(std::make_tuple(A, bCol), std::make_tuple(1e-20, 4000));
347+
x = algo.run(std::make_tuple(A, bCol), std::make_tuple(1e-20, 4000, "cg"));
348348
MatrixHandle solution = std::get<0>(x);
349349

350350
ASSERT_TRUE(solution.get() != nullptr);

src/Dataflow/Engine/Controller/ProvenanceManager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ namespace Engine {
4444
class ProvenanceManager : boost::noncopyable
4545
{
4646
public:
47-
typedef ProvenanceItem<Memento> Item;
48-
typedef typename Item::Handle ItemHandle;
49-
typedef std::stack<ItemHandle> Stack;
50-
typedef typename Stack::container_type List;
51-
typedef Engine::NetworkIOInterface<Memento> IOType;
47+
using Item = ProvenanceItem<Memento>;
48+
using ItemHandle = typename Item::Handle;
49+
using Stack = std::stack<ItemHandle>;
50+
using List = typename Stack::container_type;
51+
using IOType = Engine::NetworkIOInterface<Memento>;
5252

5353
explicit ProvenanceManager(IOType* networkIO);
5454
void setInitialState(const Memento& initialState);

src/Dataflow/Engine/Scheduler/GraphNetworkAnalyzer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ bool ExecuteSingleModule::operator()(SCIRun::Dataflow::Networks::ModuleHandle mo
154154
THROW_INVALID_ARGUMENT("Module not found in component map");
155155

156156
auto rootId = module_->get_id();
157+
if (rootId.name_ == "Subnet")
158+
return false;
157159
auto rootIdIter = components_.find(rootId);
158160
if (rootIdIter == components_.end())
159161
THROW_INVALID_ARGUMENT("Current module not found in component map");

0 commit comments

Comments
 (0)