14 #ifndef __INCLUDED_SCOPIRA_BASEKIT_VECTORMATH_H__ 15 #define __INCLUDED_SCOPIRA_BASEKIT_VECTORMATH_H__ 19 #include <scopira/basekit/narray.h> 36 void add_scalar(T &v,
typename T::data_type val);
46 void sub_scalar(T &v,
typename T::data_type val);
56 void mul_scalar(T &v,
typename T::data_type val);
66 void div_scalar(T &v,
typename T::data_type val);
92 template <
class V,
class T>
93 size_t min(
const V &v, T& out);
102 template <
class V,
class T>
103 size_t max(
const V &v, T& out);
111 template <
class V,
class T>
112 void sum(
const V &v, T& out);
120 template <
class V,
class T>
121 void mean(
const V &v, T& out);
129 template <
class V,
class T>
138 template <
class V,
class T>
140 { variance<V,T>(v, out); out =
static_cast<T
>(::sqrt(out)); }
148 template <
class LH,
class RH>
157 template <
class LH,
class RH>
166 template <
class LH,
class RH>
175 template <
class LH,
class RH>
187 template <
class LH,
class RH>
188 void abs_vector(LH &target,
const RH& source);
219 template <
class DATAT,
class REFT>
227 typedef typename T::iterator iter;
228 iter ii=v.begin(), endii = v.end();
230 for (; ii != endii; ++ii)
237 typedef typename T::iterator iter;
238 iter ii=v.begin(), endii = v.end();
240 for (; ii != endii; ++ii)
247 typedef typename T::iterator iter;
248 iter ii=v.begin(), endii = v.end();
250 for (; ii != endii; ++ii)
257 typedef typename T::iterator iter;
258 iter ii=v.begin(), endii = v.end();
260 for (; ii != endii; ++ii)
267 typedef typename T::iterator iter;
268 iter ii=v.begin(), endii = v.end();
270 for (; ii != endii; ++ii)
274 template <
class V,
class T>
277 typedef typename V::const_iterator iter;
287 for (++ii, ++cur; ii!=endii; ++ii, ++cur)
296 template <
class V,
class T>
299 typedef typename V::const_iterator iter;
309 for (++ii, ++cur; ii!=endii; ++ii, ++cur)
318 template <
class V,
class T>
321 typedef typename V::const_iterator iter;
328 for (; ii!=endii; ++ii)
333 template <
class V,
class T>
341 out = out / v.size();
344 template <
class V,
class T>
347 typedef typename V::const_iterator iter;
362 for (ii=v.begin(); ii != endii; ++ii) {
367 out = sum / (mx - 1);
370 template <
class LH,
class RH>
373 typename LH::iterator tar, endtar;
374 typename RH::const_iterator src, endsrc;
376 tar = target.begin();
377 endtar = target.end();
379 endsrc = delta.end();
380 while (tar != endtar) {
381 assert(src != endsrc);
388 template <
class LH,
class RH>
391 typename LH::iterator tar, endtar;
392 typename RH::const_iterator src, endsrc;
394 tar = target.begin();
395 endtar = target.end();
397 endsrc = delta.end();
398 while (tar != endtar) {
399 assert(src != endsrc);
406 template <
class LH,
class RH>
409 typename LH::iterator tar, endtar;
410 typename RH::const_iterator src, endsrc;
412 tar = target.begin();
413 endtar = target.end();
415 endsrc = delta.end();
416 while (tar != endtar) {
417 assert(src != endsrc);
424 template <
class LH,
class RH>
427 typename LH::iterator tar, endtar;
428 typename RH::const_iterator src, endsrc;
430 tar = target.begin();
431 endtar = target.end();
433 endsrc = delta.end();
434 while (tar != endtar) {
435 assert(src != endsrc);
442 template <
class LH,
class RH>
445 typename LH::iterator tar, endtar;
446 typename RH::const_iterator src, endsrc;
448 tar = target.begin();
449 endtar = target.end();
450 src = source.begin();
451 endsrc = source.end();
452 while (tar != endtar) {
453 assert(src != endsrc);
454 *tar = (*src < 0.0) ? (*src * -1) : *src;
463 typedef typename V::const_iterator iter;
464 iter ii = vv.begin(), endii = vv.end();
466 for (; ii != endii; ++ii)
493 sX = sXX = sY = sYY = sXY = 0;
496 assert(x.size() == y.size());
498 for (
long i=0; i<n; i++)
507 top = sXY - (sX*sY/n);
508 btm = (sXX-sX*sX/n) * (sYY-sY*sY/n);
510 if (top==0 || btm==0)
513 rho = top / sqrt(btm);
520 int i, j, k, n, l=0, ir, temp_index, temp;
521 int stack_index = -1;
533 for (j=l+1; j<=ir; j++) {
534 temp_index = index[j];
535 array_val = array[temp_index];
536 for (i=j-1; i>=1; i--) {
537 if (array[index[i]] <= array_val)
539 index[i+1] = index[i];
541 index[i+1] = temp_index;
545 ir = stack[stack_index--];
546 l = stack[stack_index--];
549 temp = index[k]; index[k] = index[l+1]; index[l+1] = temp;
550 if (array[index[l+1]] > array[index[ir]]) {
551 temp = index[l+1]; index[l+1] = index[ir]; index[ir] = temp;
553 if (array[index[l]] > array[index[ir]]) {
554 temp = index[l]; index[l] = index[ir]; index[ir] = temp;
556 if (array[index[l+1]] > array[index[l]]) {
557 temp = index[l+1]; index[l+1] = index[l]; index[l] = temp;
561 temp_index = index[l+1];
562 array_val = array[temp_index];
565 while (array[index[i]] < array_val)
568 while (array[index[j]] > array_val)
572 temp = index[i]; index[i] = index[j]; index[j] = temp;
574 index[l+1] = index[j];
575 index[j] = temp_index;
577 if (stack_index >= 50) {
582 stack[stack_index] = ir;
583 stack[stack_index-1] = i;
586 stack[stack_index] = j-1;
587 stack[stack_index-1] = l;
604 template <
class DATAT,
class REFT>
608 typedef DATAT data_type;
609 typedef REFT ref_type;
612 const ref_type &dm_ref;
615 int compare_element(
int lidx,
int ridx)
const {
616 typedef typename ref_type::data_type t;
619 l = dm_ref[dm_data[lidx]];
620 r = dm_ref[dm_data[ridx]];
628 void swap_element(
int lidx,
int ridx) {
629 typedef typename data_type::data_type t;
633 dm_data[lidx] = dm_data[ridx];
Definition: vectormath.h:220
void construct_index(narray< T > &array, narray< int > &index)
Definition: vectormath.h:518
Definition: archiveflow.h:20
void print_vector(scopira::tool::oflow_i &o, const V &vv)
Definition: vectormath.h:461
void div_scalar(T &v, typename T::data_type val)
Definition: vectormath.h:255
void abs_vector(LH &target, const RH &source)
Definition: vectormath.h:443
size_t size(void) const
gets the size (1D)
Definition: narray.h:859
void add_scalar(T &v, typename T::data_type val)
Definition: vectormath.h:225
void sum(const V &v, T &out)
Definition: vectormath.h:319
void pearson_scalar(T &x, T &y, double &rho)
Definition: vectormath.h:484
void mul_vector(LH &target, const RH &delta)
Definition: vectormath.h:407
void invdiv_scalar(T &v, typename T::data_type val)
Definition: vectormath.h:265
void sub_vector(LH &target, const RH &delta)
Definition: vectormath.h:389
size_t min(const V &v, T &out)
Definition: vectormath.h:275
void sub_scalar(T &v, typename T::data_type val)
Definition: vectormath.h:235
void div_vector(LH &target, const RH &delta)
Definition: vectormath.h:425
void stddev(const V &v, T &out)
Definition: vectormath.h:139
void variance(const V &v, T &out)
Definition: vectormath.h:345
size_t max(const V &v, T &out)
Definition: vectormath.h:297
void mean(const V &v, T &out)
Definition: vectormath.h:334
void mul_scalar(T &v, typename T::data_type val)
Definition: vectormath.h:245
void resize(size_t len)
Definition: narray.h:877
void add_vector(LH &target, const RH &delta)
Definition: vectormath.h:371