Skip to content

Commit

Permalink
make_vector => std::vector braced initalizers
Browse files Browse the repository at this point in the history
cc: #66
  • Loading branch information
jlblancoc committed Aug 21, 2017
1 parent 394172c commit 98aaaed
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 63 deletions.
1 change: 1 addition & 0 deletions doc/doxygen-pages/changeLog_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- \ref mrpt_base_grp
- Removed functions (replaced by C++11/14 standard library):
- mrpt::math::erf, mrpt::math::erfc, std::isfinite, mrpt::math::std::isnan
- `mrpt::math::make_vector<>` => `std::vector<>{...}` braced initializator
- Added: mrpt::make_aligned_shared<> template
- \ref mrpt_slam_grp
- rbpf-slam: Add support for simplemap continuation.
Expand Down
27 changes: 14 additions & 13 deletions libs/base/include/mrpt/math/CMonteCarlo.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,20 @@ class CMonteCarlo
}
NUM res = accumulate(errorData.begin(), errorData.end(), NUM(0)) /
errorData.size();
// if (showInWindow) {
// CStatisticalAnalyzer st(errorData);
// mrpt::gui::CDisplayWindowPlots wnd("Error results from Monte Carlo
// simulation");
// std::vector<NUM> errorX,errorY;
// st.getDistribution(errorX,errorY,0.1);
// wnd.plot(errorX,errorY,"b-","Plot1");
// NUM maxVal=*std::max_element(errorY.begin(),errorY.end());
// std::vector<NUM>
// dx(2,res),dy(mrpt::utils::make_vector<2,NUM>(0,maxVal));
// wnd.plot(dx,dy,"r-","Plot2");
// while (wnd.isOpen());
//}
#if 0
if (showInWindow)
{
CStatisticalAnalyzer st(errorData);
mrpt::gui::CDisplayWindowPlots wnd("Error results from Monte Carlo simulation");
std::vector<NUM> errorX,errorY;
st.getDistribution(errorX,errorY,0.1);
wnd.plot(errorX,errorY,"b-","Plot1");
NUM maxVal=*std::max_element(errorY.begin(),errorY.end());
const std::vector<NUM> dx{res, res}, dy{.0, maxVal};
wnd.plot(dx,dy,"r-","Plot2");
while (wnd.isOpen()) {};
}
#endif
return res;
}
};
Expand Down
28 changes: 0 additions & 28 deletions libs/base/include/mrpt/math/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,34 +229,6 @@ std::vector<T>& loadVector(std::vector<T>& v, At (&theArray)[N])
return v;
}

/** A versatile template to build vectors on-the-fly in a style close to
* MATLAB's v=[a b c d ...]
* The first argument of the template is the vector length, and the second the
* type of the numbers.
* Some examples:
*
* \code
* std::vector<double> = make_vector<4,double>(1.0,3.0,4.0,5.0);
* std::vector<float> = make_vector<2,float>(-8.12, 3e4);
* \endcode
*/
template <size_t N, typename T>
std::vector<T> make_vector(const T val1, ...)
{
MRPT_COMPILE_TIME_ASSERT(N > 0)
std::vector<T> ret;
ret.reserve(N);

ret.push_back(val1);

va_list args;
va_start(args, val1);
for (size_t i = 1; i < N; i++) ret.push_back(va_arg(args, T));

va_end(args);
return ret;
}

/** @} */ // end of grouping container_ops_grp

/** \defgroup mrpt_math_io Custom I/O for math containers
Expand Down
4 changes: 2 additions & 2 deletions libs/base/src/math/matrix_ops2_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TEST(Matrices, multiply_A_skew3)
{
const double dat_A[] = {1, 2, 3, 4, 5, 6};
const CMatrixDouble A(2, 3, dat_A);
const std::vector<double> v = make_vector<3>(1.0, 2.0, 3.0);
const std::vector<double> v{ 1.0, 2.0, 3.0 };
const CMatrixDouble S = CMatrixDouble(mrpt::math::skew_symmetric3(v));

CMatrixDouble R;
Expand All @@ -170,7 +170,7 @@ TEST(Matrices, multiply_skew3_A)
{
const double dat_A[] = {1, 2, 3, 4, 5, 6};
const CMatrixDouble A(3, 2, dat_A);
const std::vector<double> v = make_vector<3>(1.0, 2.0, 3.0);
const std::vector<double> v{ 1.0, 2.0, 3.0 };
const CMatrixDouble S = CMatrixDouble(mrpt::math::skew_symmetric3(v));

CMatrixDouble R;
Expand Down
14 changes: 4 additions & 10 deletions libs/nav/src/holonomic/CHolonomicFullEval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <mrpt/utils/CStream.h>
#include <mrpt/utils/round.h>
#include <mrpt/math/geometry.h>
#include <mrpt/math/utils.h> // make_vector()
#include <mrpt/math/ops_containers.h>
#include <mrpt/utils/stl_serialization.h>
#include <cmath>
Expand Down Expand Up @@ -654,19 +653,14 @@ CHolonomicFullEval::TOptions::TOptions()
TARGET_SLOW_APPROACHING_DISTANCE(0.60),
OBSTACLE_SLOW_DOWN_DISTANCE(0.15),
HYSTERESIS_SECTOR_COUNT(5),
factorWeights{ 0.1, 0.5, 0.5, 0.01, 1 },
factorNormalizeOrNot{0, 0, 0, 0, 1},
PHASE_FACTORS{ {1,2}, {4}, {0,2} },
PHASE_THRESHOLDS{ 0.5, 0.6, 0.7 },
LOG_SCORE_MATRIX(false),
clearance_threshold_ratio(0.05),
gap_width_ratio_threshold(0.25)
{
factorWeights = mrpt::math::make_vector<5, double>(0.1, 0.5, 0.5, 0.01, 1);
factorNormalizeOrNot = mrpt::math::make_vector<5, int>(0, 0, 0, 0, 1);

PHASE_FACTORS.resize(3);
PHASE_FACTORS[0] = mrpt::math::make_vector<2, int>(1, 2);
PHASE_FACTORS[1] = mrpt::math::make_vector<1, int>(4);
PHASE_FACTORS[2] = mrpt::math::make_vector<1, int>(0, 2);

PHASE_THRESHOLDS = mrpt::math::make_vector<3, double>(0.5, 0.6, 0.7);
}

void CHolonomicFullEval::TOptions::loadFromConfigFile(
Expand Down
8 changes: 2 additions & 6 deletions libs/nav/src/holonomic/CHolonomicND.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,9 @@ CHolonomicND::TOptions::TOptions()
RISK_EVALUATION_SECTORS_PERCENT(0.10),
RISK_EVALUATION_DISTANCE(0.4),
MAX_SECTOR_DIST_FOR_D2_PERCENT(0.25),
TARGET_SLOW_APPROACHING_DISTANCE(0.60)
TARGET_SLOW_APPROACHING_DISTANCE(0.60),
factorWeights{1.0, 0.5, 2.0, 0.4}
{
factorWeights.resize(4);
factorWeights[0] = 1.0;
factorWeights[1] = 0.5;
factorWeights[2] = 2.0;
factorWeights[3] = 0.4;
}

void CHolonomicND::TOptions::loadFromConfigFile(
Expand Down
6 changes: 2 additions & 4 deletions samples/stl_containers_serialize/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <mrpt/poses/CPose2D.h>
#include <mrpt/poses/CPose3DPDFGaussian.h>
#include <mrpt/math/lightweight_geom_data.h>
#include <mrpt/math/utils.h> // make_vector

using namespace mrpt;
using namespace mrpt::utils;
Expand Down Expand Up @@ -87,13 +86,12 @@ void Test_STL_containers_serialize()
"read OK"
<< endl;

std::vector<double> v2, v1;
v1 = make_vector<5, double>(1.0, 2.0, 3.0, 4.0, 5.0);

const std::vector<double> v1{ 1.0, 2.0, 3.0, 4.0, 5.0};
{
CFileOutputStream f("v1.bin");
f << v1;
}
std::vector<double> v2;
{
CFileInputStream f("v1.bin");
f >> v2;
Expand Down

0 comments on commit 98aaaed

Please sign in to comment.