mmx::array Namespace Reference
Module for generic functions on vectors. Generic implementations for vectors are gathered in the namespace array
. These are generic functions, that can be used to build new linear classes. The type R
must provide the following definitions or methods:.
More...
Functions
- template<class OS , class R > OS & print (OS &os, const R &v)
- Output function for general vectors:
[v1, v2, ...]
.
- template<class OS , class R > OS & print (OS &os, const R &v, unsigned sz)
- Output function for general vectors:
[v1, v2, ...]
.
- template<class IS , class R > IS & read (IS &is, R &V)
- template<class V1 , class V2 > bool equal_n (const V1 &v1, const V2 &v2, int n)
- template<class V1 , class V2 > bool equal (const V1 &v1, const V2 &v2)
- template<class V , class C > void init_n (V &a, const C &v, int n)
- template<class V , class C > void set_cst (V &a, const C &v)
- Set all the entries of
a
to the values v
.
- template<class V , class W > void set (V &a, const W &b)
- template<class V > void reverse_n (V &v, int a, int n)
- Reverse the entries of
v
, from the index a
to n-1
.
- template<class V > void reverse (V &v, int n)
- template<class V , class I > void reverse (V &v, I d)
- Reverse the entries of
v
, from the index 0
to d-1
.
- template<class V , class W > void neg_range (V &r, const W &w, int a, int b)
- template<class V , class W > void neg_range (V &r, int a, int b)
- template<class VI > void neg_i (VI a, VI eda)
- template<class VI > void neg_i (VI a, VI eda, VI b)
- template<class V > void neg (V &v)
- template<class V > void neg (V &a, const V &b)
- template<class V , class W > void copy_range (V &v, const W &w, int a, int b)
- template<class V , class W > void add_n (V &a, const W &b, int n)
- template<class VI , class WI > void add_i (VI a, VI ea, WI b)
- template<class V , class W > void add (V &a, const W &b)
- Addition of two vectors.
- template<class V , class W , class X > void add_n (V &a, const W &b, const X &c, int n)
- template<class V , class W , class X > void add_g (V &r, const W &a, const X &b)
- template<class V , class W , class X > void add (V &r, const W &a, const X &b)
- template<class V > void add (V &r, const V &a, const V &b)
- template<class V , class W > void sub_n (V &a, const W &b, int n)
- template<class V , class W > void sub (V &a, const W &b)
- Substraction of two vectors.
- template<class V , class W , class X > void sub_n (V &a, const W &b, const X &c, int n)
- template<class V , class W , class X > void sub_g (V &r, const W &a, const X &b)
- template<class V , class W , class X > void sub (V &r, const W &a, const X &b)
- template<class V > void sub (V &r, const V &a, const V &b)
- template<class V , class W > void mul_ext_n (V &a, const W &c, int n)
- template<class V , class W , class S > void mul_ext_n (V &a, const W &b, const S &c, int n)
- template<class VI , class W > void mul_ext_i (VI bga, VI eda, const W &c)
- template<class VI , class VII , class W > void mul_ext_i (VI bga, VI eda, VII bgb, const W &c)
- template<class V , class W > void mul_ext (V &a, const V &b, const W &c)
- Scalar multiplication.
- template<class V , class W > void mul_ext (V &a, const W &c)
- template<class V , class SC > void div_ext_n (V &a, const SC &sc, int n)
- template<class V1 , class V2 , class SC > void div_ext_n (V1 &a, const V2 &b, const SC &sc, int n)
- template<class VI , class SC > void div_ext_i (VI bga, VI eda, const SC &sc)
- template<class VI , class SC > void div_ext_i (VI a, VI eda, VI b, const SC &sc)
- template<class V , class SC > void div_ext (V &a, const V &b, const SC &sc)
- Scalar division.
- template<class V , class W > void div_ext (V &a, const W &c)
- Scalar division.
- template<class V , class W > void div (V &a, const W &c)
- Inplace scalar division.
- template<class R , class S , class C > void apply_mult (R &result, const S &a, const C &m)
- template<class C , class R > C norm (const R &v)
- The $L_{2}$ norm for vectors.
- template<class C , class R > C norm (const R &v, int p)
- Norm $L_{p}$ of a vector.
- template<class R , class S > R::value_type innerprod_n (const S &v, const R &w, unsigned n)
- Innerproduct of two vectors.
- template<class R , class S > R::value_type innerprod (const S &v, const R &w)
- template<class R > R::value_type max_abs (const R &v)
- template<class U , class R > void lcm_denominator (U &r, const R &v)
- template<typename V > void reverse (V &v)
- template<class Ia , class Ib > void assign_i (Ia a, Ia eda, Ib b)
- template<class Ra , class Rb > void assign (Ra &a, const Rb &b)
- template<class R , class C > void vaddsc (R &r, const C &x)
Detailed Description
Module for generic functions on vectors. Generic implementations for vectors are gathered in the namespace array
. These are generic functions, that can be used to build new linear classes. The type R
must provide the following definitions or methods:.
typename index_t;
typename value_type;
typename iterator;
typename const_iterator;
index_t this->size();
value_type this->operator[](index_t);
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
Function Documentation
void mmx::array::add |
( |
V & |
r, |
|
|
const V & |
a, |
|
|
const V & |
b | |
|
) |
| | [inline] |
Specialisation of the function add
when W=V
. Inplace addition is used when r=a
or r=b
.
Definition at line 208 of file array.hpp.
References add(), and add_g().
00209 {
00210 if(&r==&a) { add(r,b); return; };
00211 if(&r==&b) { add(r,a); return; };
00212 add_g(r,a,b);
00213 }
void mmx::array::add |
( |
V & |
r, |
|
|
const W & |
a, |
|
|
const X & |
b | |
|
) |
| | [inline] |
Addition of two vectors. r
should be allocated to the correct size and with 0 entries.
Definition at line 200 of file array.hpp.
References add_g().
00201 {
00202 add_g(r,a,b);
00203 }
void mmx::array::add |
( |
V & |
a, |
|
|
const W & |
b | |
|
) |
| | [inline] |
Addition of two vectors.
Definition at line 154 of file array.hpp.
References add_i(), add_n(), and copy_range().
Referenced by mmx::add(), add(), box_rep< C >::min_grad(), msimplify(), mmx::mul(), and seq2b().
00155 {
00156 int asz, bsz;
00157 asz = a.size(), bsz = b.size();
00158 if ( asz < bsz )
00159 {
00160 a.resize(bsz);
00161 add_i(a.begin(),a.end(),b.begin());
00162 copy_range(a,b,asz,bsz);
00163 }
00164 else
00165 {
00166
00167 add_n(a,b,bsz);
00168
00169 }
00170 }
void mmx::array::add_g |
( |
V & |
r, |
|
|
const W & |
a, |
|
|
const X & |
b | |
|
) |
| | [inline] |
Addition of two vectors. r
should be allocated to the correct size and with 0 entries.
Definition at line 179 of file array.hpp.
References add_n(), and copy_range().
Referenced by add().
00180 {
00181 int asz, bsz, rsz;
00182 asz = a.size(), bsz = b.size(), rsz = r.size();
00183 if ( asz > bsz )
00184 {
00185 if ( asz > rsz ) r.resize(asz);
00186 add_n(r,a,b,bsz);
00187 copy_range(r,a,bsz,asz);
00188 }
00189 else
00190 {
00191 if ( bsz > rsz ) r.resize(bsz);
00192 add_n(r,a,b,asz);
00193 copy_range(r,b,asz,bsz);
00194 };
00195 }
void mmx::array::add_i |
( |
VI |
a, |
|
|
VI |
ea, |
|
|
WI |
b | |
|
) |
| | [inline] |
Definition at line 150 of file array.hpp.
Referenced by add().
00150 { for ( ; a != ea; *a += *b, ++a, ++b ){} };
void mmx::array::add_n |
( |
V & |
a, |
|
|
const W & |
b, |
|
|
const X & |
c, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 173 of file array.hpp.
00173 { for ( int i = 0; i < n; a[i] = b[i]+c[i], i ++ ){} };
void mmx::array::add_n |
( |
V & |
a, |
|
|
const W & |
b, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 148 of file array.hpp.
Referenced by add(), and add_g().
00148 {for ( int i = 0; i < n; a[i] += b[i], i ++ ){} }
void mmx::array::apply_mult |
( |
R & |
result, |
|
|
const S & |
a, |
|
|
const C & |
m | |
|
) |
| | [inline] |
Definition at line 342 of file array.hpp.
00343 {
00344 typedef typename S::const_iterator const_iterator;
00345 typedef typename R::iterator iterator;
00346 result.resize(a.size());
00347 const_iterator b=a.begin(); iterator i=result.begin();
00348 for(; b!=a.end(); ++i, ++b) *i = (*b) * m;
00349 }
void mmx::array::assign |
( |
Ra & |
a, |
|
|
const Rb & |
b | |
|
) |
| | [inline] |
void mmx::array::assign_i |
( |
Ia |
a, |
|
|
Ia |
eda, |
|
|
Ib |
b | |
|
) |
| | [inline] |
void mmx::array::copy_range |
( |
V & |
v, |
|
|
const W & |
w, |
|
|
int |
a, |
|
|
int |
b | |
|
) |
| | [inline] |
void mmx::array::div |
( |
V & |
a, |
|
|
const W & |
c | |
|
) |
| | [inline] |
void mmx::array::div_ext |
( |
V & |
a, |
|
|
const W & |
c | |
|
) |
| | [inline] |
void mmx::array::div_ext |
( |
V & |
a, |
|
|
const V & |
b, |
|
|
const SC & |
sc | |
|
) |
| | [inline] |
void mmx::array::div_ext_i |
( |
VI |
a, |
|
|
VI |
eda, |
|
|
VI |
b, |
|
|
const SC & |
sc | |
|
) |
| | [inline] |
Definition at line 315 of file array.hpp.
00316 { for ( ; a < eda; *a = *b / sc, a++, b ++ ){} };
void mmx::array::div_ext_i |
( |
VI |
bga, |
|
|
VI |
eda, |
|
|
const SC & |
sc | |
|
) |
| | [inline] |
Definition at line 312 of file array.hpp.
Referenced by div_ext().
00313 { for ( ; bga < eda; *bga /= sc, bga++){} }
void mmx::array::div_ext_n |
( |
V1 & |
a, |
|
|
const V2 & |
b, |
|
|
const SC & |
sc, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 309 of file array.hpp.
00310 { for ( int i = 0; i < n; a[i] = b[i]/sc, i ++ ){} };
void mmx::array::div_ext_n |
( |
V & |
a, |
|
|
const SC & |
sc, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 306 of file array.hpp.
00307 { for ( int i = 0; i < n; a[i] /= sc, i++){} }
bool mmx::array::equal |
( |
const V1 & |
v1, |
|
|
const V2 & |
v2 | |
|
) |
| | [inline] |
bool mmx::array::equal_n |
( |
const V1 & |
v1, |
|
|
const V2 & |
v2, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 79 of file array.hpp.
Referenced by equal().
00080 {
00081 int i=0;
00082 while(i < n && v1[i] == v2[i]) i++;
00083 return i == n;
00084 };
void mmx::array::init_n |
( |
V & |
a, |
|
|
const C & |
v, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 94 of file array.hpp.
Referenced by set_cst().
00094 {
00095 for ( int i = 0; i < n; a[i] = v, i ++ ) {} };
R::value_type mmx::array::innerprod |
( |
const S & |
v, |
|
|
const R & |
w | |
|
) |
| | [inline] |
Definition at line 379 of file array.hpp.
00380 {
00381 typename R::value_type r =0;
00382 for(unsigned int i=0; i <v.size(); i++){r += (v[i]*w[i]);}
00383 return r;
00384 }
R::value_type mmx::array::innerprod_n |
( |
const S & |
v, |
|
|
const R & |
w, |
|
|
unsigned |
n | |
|
) |
| | [inline] |
Innerproduct of two vectors.
Definition at line 371 of file array.hpp.
00372 {
00373 typename R::value_type r = 0;
00374 for ( unsigned i = 0; i < n; r += v[i]*w[i], i++ ) {}
00375 return r;
00376 };
void mmx::array::lcm_denominator |
( |
U & |
r, |
|
|
const R & |
v | |
|
) |
| | [inline] |
R::value_type mmx::array::max_abs |
( |
const R & |
v |
) |
[inline] |
Definition at line 387 of file array.hpp.
Referenced by binary_sleeve_subdivision< K >::init_pol().
00388 {
00389 typename R::value_type r=0;
00390 for(unsigned i=0; i <(unsigned)v.size(); i++)
00391 {
00392 if(r>v[i]) r=v[i];
00393 else if(r>-v[i]) r=-v[i];
00394 }
00395 return r;
00396 }
void mmx::array::mul_ext |
( |
V & |
a, |
|
|
const W & |
c | |
|
) |
| | [inline] |
void mmx::array::mul_ext |
( |
V & |
a, |
|
|
const V & |
b, |
|
|
const W & |
c | |
|
) |
| | [inline] |
void mmx::array::mul_ext_i |
( |
VI |
bga, |
|
|
VI |
eda, |
|
|
VII |
bgb, |
|
|
const W & |
c | |
|
) |
| | [inline] |
Definition at line 286 of file array.hpp.
00287 { for ( VI a = bga; a != eda; *a = *bgb * c, ++bgb, ++a ){} };
void mmx::array::mul_ext_i |
( |
VI |
bga, |
|
|
VI |
eda, |
|
|
const W & |
c | |
|
) |
| | [inline] |
Definition at line 283 of file array.hpp.
Referenced by mul_ext().
00284 { for ( VI i = bga; i != eda; *i *= c, ++i ){} };
void mmx::array::mul_ext_n |
( |
V & |
a, |
|
|
const W & |
b, |
|
|
const S & |
c, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 280 of file array.hpp.
00281 { for ( int i = 0; i < n; a[i] = b[i]*c, i++ ){} };
void mmx::array::mul_ext_n |
( |
V & |
a, |
|
|
const W & |
c, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 277 of file array.hpp.
00278 { for ( int i = 0; i < n; a[i] = a[i]*c, i ++ ){} };
void mmx::array::neg |
( |
V & |
a, |
|
|
const V & |
b | |
|
) |
| | [inline] |
Definition at line 139 of file array.hpp.
References neg_i().
00140 {
00141 a.resize( b.size() );
00142 neg_i( a.begin(), a.end(), b.begin() );
00143 };
void mmx::array::neg |
( |
V & |
v |
) |
[inline] |
void mmx::array::neg_i |
( |
VI |
a, |
|
|
VI |
eda, |
|
|
VI |
b | |
|
) |
| | [inline] |
Definition at line 135 of file array.hpp.
00135 { for ( ; a != eda; *a = -(*b), a++, b++ ){} };
void mmx::array::neg_i |
( |
VI |
a, |
|
|
VI |
eda | |
|
) |
| | [inline] |
Definition at line 133 of file array.hpp.
Referenced by neg().
00133 { for ( ; a != eda; *a = -(*a), a++ ){} };
void mmx::array::neg_range |
( |
V & |
r, |
|
|
int |
a, |
|
|
int |
b | |
|
) |
| | [inline] |
Definition at line 129 of file array.hpp.
00130 { for ( int i = a; i < b; r[i] = -r[i], i++ ){} };
void mmx::array::neg_range |
( |
V & |
r, |
|
|
const W & |
w, |
|
|
int |
a, |
|
|
int |
b | |
|
) |
| | [inline] |
Definition at line 125 of file array.hpp.
Referenced by sub(), and sub_g().
00125 {
00126 for ( int i = a; i < b; r[i] = -w[i], i++ ) {}
00127 }
C mmx::array::norm |
( |
const R & |
v, |
|
|
int |
p | |
|
) |
| | [inline] |
Norm $L_{p}$ of a vector.
Definition at line 362 of file array.hpp.
References C, and mmx::pow().
00363 {
00364 C r=0;
00365 for(typename R::const_iterator it=v.begin(); it !=v.end(); ++it) r+=pow(*it,p);
00366 return pow(r,1/p);
00367 }
C mmx::array::norm |
( |
const R & |
v |
) |
[inline] |
The $L_{2}$ norm for vectors.
Definition at line 353 of file array.hpp.
References C, and mmx::sqrt().
00354 {
00355 C r=0;
00356 for(typename R::const_iterator it=v.begin(); it !=v.end(); ++it) r+=(*it)*(*it);
00357 return sqrt(r);
00358 }
OS& mmx::array::print |
( |
OS & |
os, |
|
|
const R & |
v, |
|
|
unsigned |
sz | |
|
) |
| | [inline] |
Output function for general vectors: [v1, v2, ...]
.
Definition at line 52 of file array.hpp.
00052 {
00053 os <<"[";
00054 unsigned i=0;
00055 if (sz){
00056 os<<v[i]; ++i;
00057 for(; i <sz; ++i) os <<","<<v[i];
00058 }
00059 os <<"]";
00060 return os;
00061 }
OS& mmx::array::print |
( |
OS & |
os, |
|
|
const R & |
v | |
|
) |
| | [inline] |
Output function for general vectors: [v1, v2, ...]
.
Definition at line 39 of file array.hpp.
00039 {
00040 os <<"[";
00041 typename R::const_iterator i=v.begin();
00042 if (v.size()){
00043 os<<*i; ++i;
00044 for(; i != v.end(); ++i) {os <<", "; os<<*i;}
00045 }
00046 os <<"]";
00047 return os;
00048 }
IS& mmx::array::read |
( |
IS & |
is, |
|
|
R & |
V | |
|
) |
| | [inline] |
Input operator for standard vectors. The input format is of the form s c0 c1 ...
where s
is the number of elements.
Definition at line 68 of file array.hpp.
00068 {
00069 typedef typename R::size_type size_type;
00070 size_type s;
00071 is >> s;
00072 V.rep().resize(s);
00073 for(size_type i=0; i< s; ++i) is >> V[i];
00074 return(is);
00075 }
void mmx::array::reverse |
( |
V & |
v |
) |
[inline] |
Definition at line 410 of file array.hpp.
References V.
00411 {
00412 unsigned sz = v.size();
00413 V temp(v);
00414 for (unsigned i = 0; i < sz; ++i)
00415 v[i] = temp[sz-1-i];
00416 }
void mmx::array::reverse |
( |
V & |
v, |
|
|
I |
d | |
|
) |
| | [inline] |
void mmx::array::reverse |
( |
V & |
v, |
|
|
int |
n | |
|
) |
| | [inline] |
void mmx::array::reverse_n |
( |
V & |
v, |
|
|
int |
a, |
|
|
int |
n | |
|
) |
| | [inline] |
Reverse the entries of v
, from the index a
to n-1
.
Definition at line 108 of file array.hpp.
References mmx::sparse::swap().
Referenced by reverse().
00109 {
00110 int k = n - a;
00111 for ( int i = 0; i < k/2; std::swap(v[a+i],v[k-1-i]), i ++ ) {}
00112 };
void mmx::array::set |
( |
V & |
a, |
|
|
const W & |
b | |
|
) |
| | [inline] |
Definition at line 103 of file array.hpp.
References V.
00103 {for ( int i = 0; i < (int)a.size(); a[i] = b[i], i ++ ) {} };
void mmx::array::set_cst |
( |
V & |
a, |
|
|
const C & |
v | |
|
) |
| | [inline] |
void mmx::array::sub |
( |
V & |
r, |
|
|
const V & |
a, |
|
|
const V & |
b | |
|
) |
| | [inline] |
Specialisation of the sub
function when W=V
. Inplace substraction is used when r=a
or r=b
.
Definition at line 269 of file array.hpp.
References sub(), and sub_g().
00270 {
00271 if(&r==&a) { sub(r,b); return; };
00272
00273 sub_g(r,a,b);
00274 }
void mmx::array::sub |
( |
V & |
r, |
|
|
const W & |
a, |
|
|
const X & |
b | |
|
) |
| | [inline] |
Substraction of two vectors. r
should be allocated to the correct size and with 0 entries.
Definition at line 261 of file array.hpp.
References sub_g().
00262 {
00263 sub_g(r,a,b);
00264 }
void mmx::array::sub |
( |
V & |
a, |
|
|
const W & |
b | |
|
) |
| | [inline] |
Substraction of two vectors.
Definition at line 221 of file array.hpp.
References neg_range(), and sub_n().
Referenced by mmx::div(), and sub().
00222 {
00223 int asz, bsz;
00224 asz = a.size(), bsz = b.size();
00225 if ( asz < bsz )
00226 {
00227 a.resize(bsz);
00228 sub_n(a,b,asz);
00229 neg_range(a,b,asz,bsz);
00230 }
00231 else
00232 sub_n(a,b,bsz);
00233 }
void mmx::array::sub_g |
( |
V & |
r, |
|
|
const W & |
a, |
|
|
const X & |
b | |
|
) |
| | [inline] |
Definition at line 240 of file array.hpp.
References copy_range(), neg_range(), and sub_n().
Referenced by sub().
00241 {
00242 int asz, bsz, rsz;
00243 asz = a.size(), bsz = b.size(), rsz = r.size();
00244
00245 if ( asz > bsz )
00246 {
00247 if ( asz > rsz ) r.resize(asz);
00248 sub_n(r,a,b,bsz);
00249 copy_range(r,a,bsz,asz);
00250 }
00251 else
00252 {
00253 if ( bsz > rsz ) r.resize(bsz);
00254 sub_n(r,a,b,asz);
00255 neg_range(r,b,asz,bsz);
00256 };
00257 }
void mmx::array::sub_n |
( |
V & |
a, |
|
|
const W & |
b, |
|
|
const X & |
c, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 236 of file array.hpp.
00236 { for ( int i = 0; i < n; a[i] = b[i]-c[i], i ++ ){} };
void mmx::array::sub_n |
( |
V & |
a, |
|
|
const W & |
b, |
|
|
int |
n | |
|
) |
| | [inline] |
Definition at line 216 of file array.hpp.
Referenced by sub(), and sub_g().
00216 { for ( int i = 0; i < n; a[i] -= b[i], i ++ ){} };
void mmx::array::vaddsc |
( |
R & |
r, |
|
|
const C & |
x | |
|
) |
| | [inline] |
Definition at line 432 of file array.hpp.
00433 { for ( typename R::iterator i = r.begin(); i != r.end(); *i += x, i ++ ){} };