[sdpb] 128/233: More commenting
Tobias Hansen
thansen at moszumanska.debian.org
Thu Mar 9 04:06:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository sdpb.
commit 1f6ed6b3f1e3dc5be98d7b23a9dc6c6e47b2dfaa
Author: David Simmons-Duffin <dsd at minerva.sns.ias.edu>
Date: Sat Jan 10 03:35:36 2015 -0500
More commenting
---
src/Polynomial.h | 17 +++++++++++++----
src/SDPSolver.cpp | 4 ++--
src/Vector.h | 8 ++++++++
src/parse.cpp | 10 ++++++++++
4 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/src/Polynomial.h b/src/Polynomial.h
index 8f2cf09..baf3e6e 100644
--- a/src/Polynomial.h
+++ b/src/Polynomial.h
@@ -13,26 +13,35 @@
#include "util.h"
#include "Vector.h"
+// A univariate polynomial
+//
+// p(x) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n
+//
class Polynomial {
public:
+ // Coefficients {a_0, a_1, ..., a_n} in increasing order of degree
Vector coefficients;
+ // The zero polynomial
Polynomial(): coefficients(1, 0) {}
+ // Degree of p(x)
int degree() const {
return coefficients.size() - 1;
};
+ // Evaluate p(x) for some x using horner's method
Real operator()(const Real &x) const {
int deg = degree();
- Real y = coefficients[deg];
+ Real result = coefficients[deg];
for (int i = deg - 1; i >= 0; i--) {
- y *= x;
- y += coefficients[i];
+ result *= x;
+ result += coefficients[i];
}
- return y;
+ return result;
}
+ // Print p(x), for debugging purposes
friend ostream& operator<<(ostream& os, const Polynomial& p) {
for (int i = p.degree(); i >= 0; i--) {
os << p.coefficients[i];
diff --git a/src/SDPSolver.cpp b/src/SDPSolver.cpp
index 5a8542a..3acbd1d 100644
--- a/src/SDPSolver.cpp
+++ b/src/SDPSolver.cpp
@@ -956,12 +956,12 @@ SDPSolverTerminateReason SDPSolver::run(const path checkpointFile) {
if (mu > parameters.maxComplementarity)
return MaxComplementarityExceeded;
- // Mehrotra predictor solution for (dx, dX, dy, dY)
+ // Compute the predictor solution for (dx, dX, dy, dY)
Real betaPredictor =
predictorCenteringParameter(parameters, isPrimalFeasible && isDualFeasible);
computeSearchDirection(betaPredictor, mu, false);
- // Mehrotra corrector solution for (dx, dX, dy, dY)
+ // Compute the corrector solution for (dx, dX, dy, dY)
Real betaCorrector =
correctorCenteringParameter(parameters, X, dX, Y, dY, mu,
isPrimalFeasible && isDualFeasible);
diff --git a/src/Vector.h b/src/Vector.h
index c3ed2fe..e6c39b6 100644
--- a/src/Vector.h
+++ b/src/Vector.h
@@ -23,19 +23,23 @@ inline bool compareAbs(const Real &a, const Real &b) {
return abs(a) < abs(b);
}
+// The maximal absolute value of the components of v
inline Real maxAbsVector(const Vector &v) {
return abs(*std::max_element(v.begin(), v.end(), compareAbs));
}
+// v := (a, a, ..., a)
inline void fillVector(Vector &v, const Real &a) {
std::fill(v.begin(), v.end(), a);
}
+// v := a*v, where a is a constant
inline void scaleVector(Vector &v, const Real &a) {
for (unsigned int i = 0; i < v.size(); i++)
v[i] *= a;
}
+// v := v + u
inline void addVector(Vector &v, const Vector &u) {
assert(v.size() == u.size());
@@ -43,6 +47,7 @@ inline void addVector(Vector &v, const Vector &u) {
v[i] += u[i];
}
+// The smash product... just kidding. The dot product u.v.
inline Real dotProduct(const Vector &u, const Vector v) {
Real result = 0;
for (unsigned int i = 0; i < u.size(); i++)
@@ -50,6 +55,9 @@ inline Real dotProduct(const Vector &u, const Vector v) {
return result;
}
+// Return the component-wise product w = (v[0] u[0], ..., v[n] u[n])
+// This routine is used only once, so we needn't worry about memory
+// efficiency.
inline Vector multiplyVectors(const Vector &u, const Vector &v) {
Vector w(u.size());
for (unsigned int i = 0; i < w.size(); i++)
diff --git a/src/parse.cpp b/src/parse.cpp
index c6df5b6..3222046 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -6,6 +6,14 @@
//=======================================================================
+// Currently, SDPB uses tinyxml2 to parse an input file into an XML
+// tree, which is stored entirely in memory. This tree is then
+// transformed into the appropriate data structures using the parse
+// functions below. In the future, this could be made more memory
+// efficient by avoiding building the XML tree in memory.
+
+// See the manual for a description of the correct XML input format.
+
#include <vector>
#include "types.h"
#include "parse.h"
@@ -18,6 +26,8 @@ using tinyxml2::XMLDocument;
using tinyxml2::XMLElement;
using boost::filesystem::path;
+// parse a bunch of adjacent elements with tag `name' into a vector<T>
+// using the function `parse' for each element.
template <class T>
vector<T> parseMany(const char *name, T(*parse)(XMLElement *),
XMLElement *elt) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sdpb.git
More information about the debian-science-commits
mailing list