6 #ifndef realroot_SOLVE_SBDSLV_LOOPS_VCTOPS_H
7 #define realroot_SOLVE_SBDSLV_LOOPS_VCTOPS_H
18 template<
typename real_t>
inline
19 void scsub(
const real_t& sc, real_t * data,
int sz,
int st = 1)
20 {
for (
int p = 0; p !=sz*st; p += st ) data[p] -= sc; };
22 template<
typename real_t>
inline
23 void scsub(
const real_t& sc, real_t * data,
const real_t * src,
int sz,
int sta = 1,
int stb = 1 )
24 {
int pd,p;
for ( pd = p = 0; p !=sz*sta; p += sta, pd += stb ) data[pd] = src[p]-sc; };
26 template<
typename real_t>
inline
27 void accscmul( real_t * dst,
const real_t& sc, real_t
const * _src_,
int sz,
int stdst = 1,
int stsrc = 1 )
29 real_t
const * src = _src_;
30 while ( src != _src_ + sz*stsrc ) { *dst += *src*sc; src += stsrc; dst += stdst; };
34 template<
typename real_t>
inline
35 void scmul(
const real_t& sc, real_t * data,
int sz,
int st = 1)
36 {
for (
int p = 0; p != sz*st; p += st ) data[p] *= sc; };
38 template<
typename real_t>
inline
39 void scdiv(
const real_t& sc, real_t * data,
int sz,
int st = 1)
40 {
for (
int p = 0; p != sz*st; p += st ) data[p] /= sc; };
43 template<
typename real_t>
inline
44 real_t
dotprod(
const real_t * a,
const real_t *
b,
int sz,
int sta = 1,
int stb = 1)
47 for (
int p = 0; p != sz*sta; p += sta, b += stb ) acc += a[p]*(*b);
51 template<
typename real_t>
inline
52 void padd( real_t * a,
const real_t *
b,
unsigned sz,
int sta = 1,
int stb = 1 )
53 {
for (
int p = 0; p != sz*sta; p += sta, b += stb ) a[p] += *b; };
55 template<
typename real_t>
inline
56 void psub( real_t * a,
const real_t *
b,
unsigned sz,
int sta = 1,
int stb = 1 )
57 {
for (
int p = 0; p != sz*sta; p += sta, b += stb ) a[p] -= *b; };
59 template<
typename real_t>
inline
60 void pmul( real_t * a,
const real_t *
b,
unsigned sz,
int sta = 1,
int stb = 1 )
61 {
for (
int p = 0; p != sz*sta; p += sta, b += stb ) a[p] *= *b; };
63 template<
typename real_t>
inline
64 void pdiv( real_t * a,
const real_t *
b,
unsigned sz,
int sta = 1,
int stb = 1 )
65 {
int p;
for ( p = 0; p != sz*sta; a[p] /= *
b, p += sta, b += stb ) ; };
67 template<
typename real0,
typename real_t>
71 for ( p = 0, i = 0; i < sz/2; i ++, p += 2*st )
73 if ( src[p] < src[p+st] )
75 if ( src[p] < min ) min = src[p];
76 if ( src[p+st] > max ) max = src[p+st];
80 if ( src[p] > max ) max = src[p];
81 if ( src[p+st] < min ) min = src[p+st];
86 template<
typename real0,
typename real_t>
87 void minmax( real0&
min, real0&
max, real_t * src,
int sz,
int st=1 )
94 template<
typename real_t>
95 real_t
min( real_t
const * src,
int sz,
int st = 1 )
98 for (
int p = st; p != sz*st; p += st )
if ( r > src[p] ) r = src[p];
102 template<
typename real_t>
103 real_t
max( real_t
const * src,
int sz,
int st = 1 )
106 for (
int p = st; p != sz*st; p += st )
if ( r < src[p] ) r = src[p];
112 void urand( T * data,
unsigned sz,
const T& a,
const T&
b,
int st = 1 )
114 for (
int p = 0; p != sz*st; p += st )
116 double t = ((double)rand()/(double)RAND_MAX);
117 data[p] = T(((1.0-t)*a + t*b));
121 template<
typename real_t>
122 real_t
mean( real_t
const *
const data,
int sz,
int st )
125 for (
int p = 0; p != sz*st; mv += data[p], p += st ) ;
129 template<
typename real_t>
130 std::ostream&
print( real_t
const *
const data,
unsigned sz,
int st = 1, std::ostream& out = std::cout )
134 for (
unsigned i = 0; i < sz-1; i++, p += st )
139 out << data[p] <<
" ]";
143 template<
typename real_t>
inline
144 unsigned sgncnt ( real_t
const *
b ,
unsigned sz,
int st = 1 )
146 real_t
const * last = b + (sz-1)*st;
148 for ( c = 0; b != last; b += st )
149 c += *b > 0 != *(b+st) > 0;
153 template<
typename real_t>
inline
154 bool sgnchg( real_t
const *
const b,
unsigned sz,
int st = 1 )
161 for (
unsigned i = 1; i < sz; i++, p+= st )
162 if ( (b[p]>0) != pprv )
return true;
166 template<
typename real_t>
inline
167 real_t
distance2( real_t
const *
const a, real_t
const *
const b,
unsigned sz,
int sta,
int stb )
171 for ( s = pb = pa = 0; pa != sz*sta; pa += sta, pb += stb ) s += (a[pa]-b[pb])*(a[pa]-b[pb]);
175 template<
typename real_t>
inline
176 real_t
delta_max( real_t * a, real_t *
b,
unsigned sz,
int st = 1 )
179 real_t tmp = a[0]-b[0];
180 for (
unsigned i = 1; i < sz; i++ , p += st )
181 if ( a[p]-b[p] > tmp ) tmp = a[p]-b[p];
185 template<
typename real_t>
inline
190 real_t tmp = a[0]-b[0];
191 for (
unsigned i = 1; i < sz; i++ , p += st )
192 if ( a[p]-b[p] > tmp ) { mx = i; tmp = a[p]-b[p]; };
196 template<
typename real_t>
inline
197 real_t
sum( real_t
const *
const src,
unsigned sz,
int st = 1 )
199 real_t acc = (real_t)0.0;
200 for (
int i = 0; i != sz*st; acc += src[i], i += st )
205 template<
typename real_t>
inline
206 unsigned set_conversion( real_t * src,
unsigned sz,
const real_t& epsilon = (real_t)0 )
208 std::sort(src,src+sz);
210 for (
unsigned i = 1; i < sz; i++ )
211 if ( src[i]-src[c] > epsilon ) src[++
c] = src[i];
215 template<
typename real_t>
inline
216 void scale( real_t * src,
unsigned sz,
const real_t& sc = (real_t)(1.0),
int st= 1 )
217 { real_t mn,mx;
minmax(mn,mx,src,sz,st);
scmul(sc/(mx-mn),src,sz,st); };
219 template<
typename U,
typename Y,
typename Z >
220 void convolution(U*dst,Y
const*a,Z
const*
b,
unsigned sza,
unsigned szb,
int sta=1,
int stb=1,
int stout=1)
222 assert((dst!=a)&&(dst!=b));
224 for ( p = 0; p != (sza+szb-1)*stout; dst[p] = (U)0, p += stout ) ;
225 for ( p = ia =0; ia != sza*sta; ia += sta, p += stout )
226 for ( ib = 0, q = p; ib != szb*stb; dst[q] += a[ia]*b[ib], ib += stb, q += stout ) ;
229 template<
typename U,
typename Y,
typename Z >
233 for ( p = 0; p != (2*sza-1); dst[p] = 0, p += stout ) ;
234 for ( p = ia = 0; ia != sza*sta; dst[2*p] += a[ia]*a[ia], ia += sta, p += stout )
235 for ( ib = 0, q = p; ib != ia; dst[q] += 2*a[ia]*a[ib], ib += sta, q += stout ) ;
Definition: system_epsilon.hpp:19
unsigned set_conversion(real_t *src, unsigned sz, const real_t &epsilon=(real_t) 0)
Definition: loops_vctops.hpp:206
int delta_max_index(real_t *a, real_t *b, unsigned sz, int st=1)
Definition: loops_vctops.hpp:186
const C & b
Definition: Interval_glue.hpp:25
void scdiv(const real_t &sc, real_t *data, int sz, int st=1)
Definition: loops_vctops.hpp:39
void accscmul(real_t *dst, const real_t &sc, real_t const *_src_, int sz, int stdst=1, int stsrc=1)
Definition: loops_vctops.hpp:27
unsigned sgncnt(real_t const *b, unsigned sz, int st=1)
Definition: loops_vctops.hpp:144
void scale(real_t *src, unsigned sz, const real_t &sc=(real_t)(1.0), int st=1)
Definition: loops_vctops.hpp:216
real_t mean(real_t const *const data, int sz, int st)
Definition: loops_vctops.hpp:122
std::ostream & print(real_t const *const data, unsigned sz, int st=1, std::ostream &out=std::cout)
Definition: loops_vctops.hpp:130
real_t distance2(real_t const *const a, real_t const *const b, unsigned sz, int sta, int stb)
Definition: loops_vctops.hpp:167
void scmul(const real_t &sc, real_t *data, int sz, int st=1)
Definition: loops_vctops.hpp:35
real_t min(real_t const *src, int sz, int st=1)
Definition: loops_vctops.hpp:95
void pdiv(real_t *a, const real_t *b, unsigned sz, int sta=1, int stb=1)
Definition: loops_vctops.hpp:64
real_t delta_max(real_t *a, real_t *b, unsigned sz, int st=1)
Definition: loops_vctops.hpp:176
real_t sum(real_t const *const src, unsigned sz, int st=1)
Definition: loops_vctops.hpp:197
void convolution(U *dst, Y const *a, Z const *b, unsigned sza, unsigned szb, int sta=1, int stb=1, int stout=1)
Definition: loops_vctops.hpp:220
void self_convolution(U *dst, Y const *a, unsigned sza, int sta=1, int stout=1)
Definition: loops_vctops.hpp:230
void minmax(real0 &min, real0 &max, real_t *src, int sz, int st=1)
Definition: loops_vctops.hpp:87
bool sgnchg(real_t const *const b, unsigned sz, int st=1)
Definition: loops_vctops.hpp:154
void abs(Interval< C, r > &x, const Interval< C, r > &a)
Definition: Interval_fcts.hpp:185
real_t dotprod(const real_t *a, const real_t *b, int sz, int sta=1, int stb=1)
Definition: loops_vctops.hpp:44
void minmaxu(real0 &min, real0 &max, real_t *src, int sz, int st=1)
Definition: loops_vctops.hpp:68
void urand(T *data, unsigned sz, const T &a, const T &b, int st=1)
Definition: loops_vctops.hpp:112
void scsub(const real_t &sc, real_t *data, int sz, int st=1)
Definition: loops_vctops.hpp:19
void pmul(real_t *a, const real_t *b, unsigned sz, int sta=1, int stb=1)
Definition: loops_vctops.hpp:60
real_t max(real_t const *src, int sz, int st=1)
Definition: loops_vctops.hpp:103
const C & c
Definition: Interval_glue.hpp:45
void psub(real_t *a, const real_t *b, unsigned sz, int sta=1, int stb=1)
Definition: loops_vctops.hpp:56
void padd(real_t *a, const real_t *b, unsigned sz, int sta=1, int stb=1)
Definition: loops_vctops.hpp:52
#define assert(expr, msg)
Definition: shared_object.hpp:57