RML  1.0
Robotics Mathematical Library
Loading...
Searching...
No Matches
rml_test_defines.h
Go to the documentation of this file.
1/*
2 * rml_test_defines.h
3 *
4 * Created on: Feb 16, 2018
5 * Author: Francesco Wanderlingh
6 */
7
8#ifndef INCLUDE_TEST_RML_TEST_DEFINES_H_
9#define INCLUDE_TEST_RML_TEST_DEFINES_H_
10
11#include <iostream>
12#include <sys/time.h>
13#include <vector>
14#include <rml/RML.h>
15
16#include "rml_internal/Futils.h"
17
18using std::vector;
19
21 double svd;
22 double mul;
23 double add;
24 double inv;
25 double tran;
26};
27
28struct PinvSpecs {
29 int nRows;
30 int nCols;
32
34 nRows(0), nCols(0) {
36 SVDdata.params.lambda = 0.0001;
37 }
38};
39
40double TimeDiff(timeval t1, timeval t2) {
41 double t;
42 t = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
43 t += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
44
45 return t;
46}
47
48void PrintResult(const std::string type, const int iter, const PinvSpecs specs, const double time){
49 std::cout << type << "\t" << specs.nRows << "x" << specs.nCols << " \t " << tc::white << time/1000 << " us"
50 << tc::none << "\t(avg. on " << iter << " iterations)" << std::endl;
51}
52
53void PseudoInverseTest(const int iterations, Eigen::MatrixXd& A, PinvSpecs &specs, Eigen::MatrixXd& Apinv, TimeResults &results) {
54
55 timeval t1, t2;
56 double d;
57
58 A.resize(specs.nRows, specs.nCols);
59 A.setRandom();
60
61 gettimeofday(&t1, NULL);
62 for (int i = 0; i < iterations; i++) {
63 Apinv = rml::RegularizedPseudoInverse(A, specs.SVDdata);
64 }
65 gettimeofday(&t2, NULL);
66 d = TimeDiff(t1, t2);
67 results.inv = d;
68 PrintResult("PseudoInverseTest", iterations, specs, d);
69}
70
71
72
73
74#endif /* INCLUDE_TEST_RML_TEST_DEFINES_H_ */
Eigen::Matrix< typename MatT::Scalar, MatT::ColsAtCompileTime, MatT::RowsAtCompileTime > RegularizedPseudoInverse(const MatT &mat, RegularizationData &regData)
Computes the SVD-based regularized matrix pseudoinversion (A = U*S*V')
Definition PseudoInverse.h:83
void PseudoInverseTest(const int iterations, Eigen::MatrixXd &A, PinvSpecs &specs, Eigen::MatrixXd &Apinv, TimeResults &results)
Definition rml_test_defines.h:53
double TimeDiff(timeval t1, timeval t2)
Definition rml_test_defines.h:40
void PrintResult(const std::string type, const int iter, const PinvSpecs specs, const double time)
Definition rml_test_defines.h:48
Definition rml_test_defines.h:28
int nRows
Definition rml_test_defines.h:29
int nCols
Definition rml_test_defines.h:30
rml::RegularizationData SVDdata
Definition rml_test_defines.h:31
PinvSpecs()
Definition rml_test_defines.h:33
Definition rml_test_defines.h:20
double svd
Definition rml_test_defines.h:21
double inv
Definition rml_test_defines.h:24
double mul
Definition rml_test_defines.h:22
double tran
Definition rml_test_defines.h:25
double add
Definition rml_test_defines.h:23
Regularization parameters and results container.
Definition PseudoInverse.h:50
RegularizationParameters params
Definition PseudoInverse.h:51
double lambda
The maximum value of the raised cosine.
Definition PseudoInverse.h:20
double threshold
The value above which the raised cosine becomes 0.
Definition PseudoInverse.h:19