[sdpb] 133/233: Small fixes/simplifications
Tobias Hansen
thansen at moszumanska.debian.org
Thu Mar 9 04:06:29 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 2b52503e86cbf2bab3b6949cb38cb71a084c9d44
Author: David Simmons-Duffin <dsd at minerva.sns.ias.edu>
Date: Sat Jan 10 16:04:13 2015 -0500
Small fixes/simplifications
---
src/Matrix.cpp | 6 +++---
src/Matrix.h | 2 +-
src/SDPSolver.cpp | 10 ++++------
src/Vector.h | 24 +++++++-----------------
4 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/src/Matrix.cpp b/src/Matrix.cpp
index 62cc036..ee3c21b 100644
--- a/src/Matrix.cpp
+++ b/src/Matrix.cpp
@@ -19,9 +19,9 @@
// For a list of MLAPACK routines with documentation, see
// http://mplapack.sourceforge.net/mlapack_routines.html
//
-// We have chosen not to parallelize the operations here that are used
-// within BlockDiagonalMatrices, since there parallelism can be
-// achieved by parallelizing loops over blocks.
+// We have chosen not to parallelize operations that are used in
+// BlockDiagonalMatrix, since there parallelism can be achieved by
+// parallelizing loops over blocks.
ostream& operator<<(ostream& os, const Matrix& a) {
os << "{";
diff --git a/src/Matrix.h b/src/Matrix.h
index d53a21d..0b3c915 100644
--- a/src/Matrix.h
+++ b/src/Matrix.h
@@ -49,7 +49,7 @@ class Matrix {
// M := 0
void setZero() {
- fillVector(elements, 0);
+ std::fill(elements.begin(), elements.end(), 0);
}
// M += c*I, where I is the identity and c is a constant
diff --git a/src/SDPSolver.cpp b/src/SDPSolver.cpp
index 3acbd1d..6b925d9 100644
--- a/src/SDPSolver.cpp
+++ b/src/SDPSolver.cpp
@@ -984,15 +984,13 @@ SDPSolverTerminateReason SDPSolver::run(const path checkpointFile) {
printIteration(iteration, mu, primalStepLength, dualStepLength, betaCorrector);
- // Update the primal point (x, X) += primalStepLength (dx, dX)
- scaleVector(dx, primalStepLength);
- addVector(x, dx);
+ // Update the primal point (x, X) += primalStepLength*(dx, dX)
+ addScaledVector(x, primalStepLength, dx);
dX *= primalStepLength;
X += dX;
- // Update the dual point (y, Y) += dualStepLength (dy, dY)
- scaleVector(dy, dualStepLength);
- addVector(y, dy);
+ // Update the dual point (y, Y) += dualStepLength*(dy, dY)
+ addScaledVector(y, dualStepLength, dy);
dY *= dualStepLength;
Y += dY;
}
diff --git a/src/Vector.h b/src/Vector.h
index ff5e662..1442381 100644
--- a/src/Vector.h
+++ b/src/Vector.h
@@ -19,6 +19,7 @@
using std::ostream;
using std::vector;
+// a Vector is just an STL vector of Real's
typedef vector<Real> Vector;
// print any vector<T>, including Vector
@@ -43,23 +44,12 @@ 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) {
+// v := v + a*u
+inline void addScaledVector(Vector &v, const Real &a, const Vector &u) {
assert(v.size() == u.size());
for (unsigned int i = 0; i < v.size(); i++)
- v[i] += u[i];
+ v[i] += a * u[i];
}
// The smash product... just kidding. The dot product u.v.
@@ -70,9 +60,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.
+// 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
+// allocation.
inline Vector multiplyVectors(const Vector &u, const Vector &v) {
Vector w(u.size());
for (unsigned int i = 0; i < w.size(); i++)
--
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