Commit a95142bf5d952d57faf175b6f4096cc9d3cceb2f

Authored by Brendan Klare
1 parent 7056f9dd

Linspace helper function

openbr/core/common.cpp
... ... @@ -63,3 +63,15 @@ QList<int> Common::RandSample(int n, const QSet<int> &values, bool unique)
63 63 }
64 64 return samples;
65 65 }
  66 +
  67 +QList<float> linspace(float start, float stop, int n) {
  68 + float delta = (stop - start) / (n - 1);
  69 + float curValue = start;
  70 + QList<float> spaced;
  71 + spaced.reserve(n);
  72 + spaced.append(start);
  73 + for (int i = 1; i < (n - 1); i++) {
  74 + spaced.append(curValue += delta);
  75 + }
  76 + spaced.append(stop);
  77 +}
... ...
openbr/core/common.h
... ... @@ -253,6 +253,11 @@ QList&lt;int&gt; RandSample(int n, const QList&lt;T&gt; &amp;weights, bool unique = false)
253 253 }
254 254  
255 255 /*!
  256 + * \brief See Matlab function linspace() for documentation.
  257 + */
  258 +QList<float> linspace(float start, float stop, int n);
  259 +
  260 +/*!
256 261 * \brief See Matlab function unique() for documentation.
257 262 */
258 263 template <typename T>
... ...