Errors:axpy and testErrors
parent
5b6af9e4bd
commit
274265a401
13
.cproject
13
.cproject
|
@ -469,6 +469,7 @@
|
|||
</target>
|
||||
<target name="testBayesTree.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>testBayesTree.run</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
|
@ -476,7 +477,6 @@
|
|||
</target>
|
||||
<target name="testSymbolicBayesNet.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>testSymbolicBayesNet.run</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
|
@ -484,6 +484,7 @@
|
|||
</target>
|
||||
<target name="testSymbolicFactorGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>testSymbolicFactorGraph.run</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
|
@ -675,6 +676,7 @@
|
|||
</target>
|
||||
<target name="testGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>testGraph.run</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
|
@ -730,7 +732,6 @@
|
|||
</target>
|
||||
<target name="testSimulated2D.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>testSimulated2D.run</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
|
@ -776,6 +777,14 @@
|
|||
<useDefaultCommand>true</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="testErrors.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments/>
|
||||
<buildTarget>testErrors.run</buildTarget>
|
||||
<stopOnError>true</stopOnError>
|
||||
<useDefaultCommand>false</useDefaultCommand>
|
||||
<runAllBuilders>true</runAllBuilders>
|
||||
</target>
|
||||
<target name="install" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||
<buildCommand>make</buildCommand>
|
||||
<buildArguments>-j2</buildArguments>
|
||||
|
|
|
@ -38,9 +38,11 @@ bool Errors::equals(const Errors& expected, double tol) const {
|
|||
|
||||
/* ************************************************************************* */
|
||||
Errors Errors::operator-(const Errors& b) const {
|
||||
#ifndef NDEBUG
|
||||
size_t m = size();
|
||||
if (b.size()!=m)
|
||||
throw(std::invalid_argument("Errors::operator-: incompatible sizes"));
|
||||
#endif
|
||||
Errors result;
|
||||
Errors::const_iterator it = b.begin();
|
||||
BOOST_FOREACH(const Vector& ai, *this)
|
||||
|
@ -50,9 +52,11 @@ Errors Errors::operator-(const Errors& b) const {
|
|||
|
||||
/* ************************************************************************* */
|
||||
double dot(const Errors& a, const Errors& b) {
|
||||
#ifndef NDEBUG
|
||||
size_t m = a.size();
|
||||
if (b.size()!=m)
|
||||
throw(std::invalid_argument("Errors::dot: incompatible sizes"));
|
||||
#endif
|
||||
double result = 0.0;
|
||||
Errors::const_iterator it = b.begin();
|
||||
BOOST_FOREACH(const Vector& ai, a)
|
||||
|
@ -60,6 +64,13 @@ double dot(const Errors& a, const Errors& b) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void axpy(double alpha, const Errors& x, Errors& y) {
|
||||
Errors::const_iterator it = x.begin();
|
||||
BOOST_FOREACH(Vector& yi, y)
|
||||
axpy(alpha,*(it++),yi);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void print(const Errors& a, const string& s) {
|
||||
a.print(s);
|
||||
|
|
|
@ -36,6 +36,11 @@ namespace gtsam {
|
|||
*/
|
||||
double dot(const Errors& a, const Errors& b);
|
||||
|
||||
/**
|
||||
* BLAS level 2 style
|
||||
*/
|
||||
void axpy(double alpha, const Errors& x, Errors& y);
|
||||
|
||||
/** print with optional string */
|
||||
void print(const Errors& a, const std::string& s = "Error");
|
||||
|
||||
|
|
|
@ -93,8 +93,10 @@ testBinaryBayesNet_LDADD = libgtsam.la
|
|||
|
||||
# Gaussian inference
|
||||
headers += GaussianFactorSet.h SharedGaussian.h SharedDiagonal.h VectorConfig.h
|
||||
sources += NoiseModel.cpp Errors.cpp VectorMap.cpp VectorBTree.cpp GaussianFactor.cpp GaussianFactorGraph.cpp GaussianConditional.cpp GaussianBayesNet.cpp
|
||||
check_PROGRAMS += testVectorMap testVectorBTree testGaussianFactor testGaussianFactorGraph testGaussianConditional testGaussianBayesNet testNoiseModel
|
||||
sources += NoiseModel.cpp Errors.cpp VectorMap.cpp VectorBTree.cpp GaussianFactor.cpp
|
||||
sources += GaussianFactorGraph.cpp GaussianConditional.cpp GaussianBayesNet.cpp
|
||||
check_PROGRAMS += testVectorMap testVectorBTree testGaussianFactor testGaussianFactorGraph
|
||||
check_PROGRAMS += testGaussianConditional testGaussianBayesNet testNoiseModel testErrors
|
||||
testVectorMap_SOURCES = testVectorMap.cpp
|
||||
testVectorMap_LDADD = libgtsam.la
|
||||
testVectorBTree_SOURCES = testVectorBTree.cpp
|
||||
|
@ -109,6 +111,8 @@ testGaussianBayesNet_SOURCES = testGaussianBayesNet.cpp
|
|||
testGaussianBayesNet_LDADD = libgtsam.la
|
||||
testNoiseModel_SOURCES = testNoiseModel.cpp
|
||||
testNoiseModel_LDADD = libgtsam.la
|
||||
testErrors_SOURCES = testErrors.cpp
|
||||
testErrors_LDADD = libgtsam.la
|
||||
|
||||
# Iterative Methods
|
||||
headers += iterative-inl.h SubgraphPreconditioner-inl.h
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* testErrors.cpp
|
||||
*
|
||||
* Created on: Feb 20, 2010
|
||||
* @Author: Frank Dellaert
|
||||
*/
|
||||
|
||||
#include <boost/assign/std/list.hpp> // for +=
|
||||
using namespace boost::assign;
|
||||
|
||||
#include <CppUnitLite/TestHarness.h>
|
||||
#include "Errors.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace gtsam;
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( Errors, arithmetic )
|
||||
{
|
||||
Errors e;
|
||||
e += Vector_(2,1.0,2.0), Vector_(3,3.0,4.0,5.0);
|
||||
DOUBLES_EQUAL(1+4+9+16+25,dot(e,e),1e-9);
|
||||
|
||||
axpy(2.0,e,e);
|
||||
Errors expected;
|
||||
expected += Vector_(2,3.0,6.0), Vector_(3,9.0,12.0,15.0);
|
||||
CHECK(assert_equal(expected,e));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
int main() {
|
||||
TestResult tr;
|
||||
return TestRegistry::runAllTests(tr);
|
||||
}
|
||||
/* ************************************************************************* */
|
Loading…
Reference in New Issue