Scopira  20080306
scopira::basekit Namespace Reference

Classes

class  base_directio_slice
 
class  const_islice_vec_iterator_g
 
class  const_niterator
 
class  const_nslice
 
class  directio_slice
 
class  directio_traints
 
class  directio_traints< char >
 
class  directio_traints< double >
 
class  directio_traints< float >
 
class  directio_traints< int >
 
class  directio_traints< short >
 
class  islice_vec_g
 
class  islice_vec_iterator_g
 
class  narray
 
class  narray_delete_i
 
class  narray_o
 
class  nindex
 
class  nindex< 1 >
 
class  nindex< 2 >
 
class  nindex< 3 >
 
class  nindex< 4 >
 
class  niterator
 
class  nslice
 
class  stringvector_o
 
class  vecindex_sortable
 

Typedefs

typedef narray< bool, 1 > boolvec_t
 
typedef narray< char, 1 > charvec_t
 
typedef narray< short, 1 > shortvec_t
 
typedef narray< int, 1 > intvec_t
 
typedef narray< float, 1 > floatvec_t
 
typedef narray< double, 1 > doublevec_t
 
typedef narray< bool, 2 > boolmatrix_t
 
typedef narray< char, 2 > charmatrix_t
 
typedef narray< short, 2 > shortmatrix_t
 
typedef narray< int, 2 > intmatrix_t
 
typedef narray< float, 2 > floatmatrix_t
 
typedef narray< double, 2 > doublematrix_t
 
typedef narray< bool, 3 > boolcube_t
 
typedef narray< char, 3 > charcube_t
 
typedef narray< short, 3 > shortcube_t
 
typedef narray< int, 3 > intcube_t
 
typedef narray< float, 3 > floatcube_t
 
typedef narray< double, 3 > doublecube_t
 
typedef narray< bool, 4 > boolquad_t
 
typedef narray< char, 4 > charquad_t
 
typedef narray< short, 4 > shortquad_t
 
typedef narray< int, 4 > intquad_t
 
typedef narray< float, 4 > floatquad_t
 
typedef narray< double, 4 > doublequad_t
 
typedef narray_o< bool, 1 > boolvec_o
 
typedef narray_o< char, 1 > charvec_o
 
typedef narray_o< short, 1 > shortvec_o
 
typedef narray_o< int, 1 > intvec_o
 
typedef narray_o< float, 1 > floatvec_o
 
typedef narray_o< double, 1 > doublevec_o
 
typedef narray_o< bool, 2 > boolmatrix_o
 
typedef narray_o< char, 2 > charmatrix_o
 
typedef narray_o< short, 2 > shortmatrix_o
 
typedef narray_o< int, 2 > intmatrix_o
 
typedef narray_o< float, 2 > floatmatrix_o
 
typedef narray_o< double, 2 > doublematrix_o
 
typedef narray_o< bool, 3 > boolcube_o
 
typedef narray_o< char, 3 > charcube_o
 
typedef narray_o< short, 3 > shortcube_o
 
typedef narray_o< int, 3 > intcube_o
 
typedef narray_o< float, 3 > floatcube_o
 
typedef narray_o< double, 3 > doublecube_o
 
typedef narray_o< bool, 4 > boolquad_o
 
typedef narray_o< char, 4 > charquad_o
 
typedef narray_o< short, 4 > shortquad_o
 
typedef narray_o< int, 4 > intquad_o
 
typedef narray_o< float, 4 > floatquad_o
 
typedef narray_o< double, 4 > doublequad_o
 

Enumerations

enum  {
  white_c = 0xFFFFFF, red_c = 0xFF0000, green_c = 0xFF00, blue_c = 0xFF,
  yellow_c = 0xFFFF00, cyan_c = 0xFFFF, purple_c = 0xFF00FF, black_c = 0
}
 constant colours
 
enum  { x_axis_c = 0, y_axis_c = 1, z_axis_c = 2, t_axis_c = 3 }
 

Functions

int color_rgb (int r, int g, int b)
 converts a RGB triplet to a packed color
 
int color_argb (int a, int r, int g, int b)
 converts a ARGB triplet to packed color
 
int color_gray (int v)
 expand a single 0..255 to a packed color
 
int color_alpha (int packedcol)
 extracts alpha
 
int color_red (int packedcol)
 extracts red
 
int color_green (int packedcol)
 extracts gree
 
int color_blue (int packedcol)
 extracts blue
 
int set_alpha (int packedcol, int a)
 sets
 
int set_red (int packedcol, int r)
 sets
 
int set_green (int packedcol, int g)
 sets
 
int set_blue (int packedcol, int b)
 sets
 
int clamp_color (int c)
 clamps this number between 0 and 255
 
double color_to_double (int c)
 convert a colour to doulbe (0..1)... basically, c/255
 
int color_to_gray (int c)
 convert colour into a 0..255 (mean)
 
int color_scale (int factor, int packedcol)
 sclaes a color. factor is 1000 for no change (alpha aware)
 
int layer_color (int basecolor, int layercolor)
 layers a colour (alpha aware)
 
void fill_color_pick (nslice< int > target, int offset=0)
 set colors, suitable for picking
 
void fill_color_gradient (nslice< int > target, int startpcol, int endpcol)
 set a gradient (alpha aware)
 
void make_gray_palette (const nslice< int > &pal)
 makes a palette
 
void make_red_palette (const nslice< int > &pal)
 makes a palette
 
void make_green_palette (const nslice< int > &pal)
 makes a palette
 
void make_blue_palette (const nslice< int > &pal)
 makes a palette
 
void make_pick_palette (const nslice< int > &pal)
 makes a palette
 
void make_heat_palette (const nslice< int > &pal)
 makes a palette
 
void make_rainbow_palette (const nslice< int > &pal)
 makes a palette
 
void make_bluered_palette (const nslice< int > &pal)
 makes a palette
 
void make_bone_palette (const nslice< int > &pal)
 makes a palette
 
void make_copper_palette (const nslice< int > &pal)
 makes a palette
 
void make_spectra_palette (const nslice< int > &pal)
 makes a palette
 
void make_opus_palette (const nslice< int > &pal)
 makes a palette
 
bool save_directio_file_impl (const std::string &filename, short numdimen, const size_t *dimen, size_t elemsize, const char *id, const void *data)
 
bool load_directio_file_impl (const std::string &filename, short numdimen, size_t *dimen, size_t elemsize, const char *id, void *&outary)
 
bool bind_direct_file_impl (scopira::tool::fileflow *f, scopira::tool::byte_t *&baseary, size_t len, narray_delete_i *&func, bool readonly)
 
bool create_directio_file_impl (const std::string &filename, short numdimen, size_t *dimen, size_t elemsize, const char *id)
 
bool bind_directio_file_impl (const std::string &filename, short numdimen, size_t *dimen, size_t elemsize, const char *id, bool readonly, void *&outary, narray_delete_i *&outfunc)
 
void sync_directio_file (narray_delete_i *d)
 
bool query_directio_file (const std::string &filename, std::string &elementtype, std::vector< size_t > &dimen)
 
template<class T , int DIM>
bool load_directio_file (const std::string &filename, scopira::basekit::narray< T, DIM > &out)
 
template<class T , int DIM>
bool save_directio_file (const std::string &filename, const scopira::basekit::narray< T, DIM > &in)
 
template<class T , int DIM>
bool bind_direct_file (scopira::tool::fileflow *f, scopira::basekit::nindex< DIM > sz, scopira::basekit::narray< T, DIM > &out, bool readonly=false, scopira::tool::fileflow::offset_t skipb=0)
 
template<class T , int DIM>
bool create_directio_file (const std::string &filename, nindex< DIM > sz)
 
template<class T , int DIM>
bool bind_directio_file (const std::string &filename, narray< T, DIM > &out, bool readonly=false)
 
template<class T , int DIM>
void sync_directio_file (const narray< T, DIM > &out)
 
template<class T >
sqr (T v)
 
template<class T >
bool is_equal (T v1, T v2)
 
template<class T >
bool is_zero (T v)
 
bool is_nan (double v)
 
bool is_nan (float v)
 
int is_inf (double v)
 see man isinf for the meanin of the return More...
 
int is_inf (float v)
 
template<class T >
sign (T v)
 
int factorial (int n, int m=0)
 
int binomial (int n, int i)
 
template<class T , class SCA >
void mul_matrix (T &dest, SCA d)
 
template<class T , class T2 , class T3 >
void mul_matrix (T &dest, const T2 &m1, const T3 &m2, bool t1=false, bool t2=false)
 
template<class T >
bool invert_matrix (T &dest, const T &src)
 
template<class D , class S >
void transpose_matrix (D &dest, const S &src)
 
template<class SRC , class DEST >
void resample_nn (DEST &dest, const SRC &src)
 
template<class SRC , class DEST >
void resample_linear (DEST &dest, const SRC &src)
 
template<class T >
bool lu_decomposition (narray< T, 2 > &dest, const narray< T, 2 > &src, narray< int > &idx, bool &odd)
 
template<class T >
void lu_backsubstitution (narray< T > &dest, const narray< T, 2 > &inv_a, const narray< int > &index)
 
template<class T >
bool svd (narray< T, 2 > &Mu, narray< T > &Vw, narray< T, 2 > &Mv)
 
template<class T >
void svd_backsubstitution (narray< T, 2 > &Mu, narray< T > &Vw, narray< T, 2 > &Mv, narray< T > &b, narray< T > &x)
 
template<class DT >
DT pythagorean (DT a, DT b)
 
template<class T >
void elim_hessian (narray< T, 2 > &matrix)
 
template<class T >
void eigen_hessenberg (narray< T, 2 > &matrix, narray< T > &eigen_real, narray< T > &eigen_imaginary)
 
template<class T >
void gauss_jordan (narray< T, 2 > &matrix, narray< T, 2 > &rhs)
 
template<class T >
void sort_covariance (narray< T, 2 > &matrix, narray< int > &fitted, int mfit)
 
template<class T >
svd_sign (T v1, T v2)
 internal function for svd
 
template<int DIM>
bool is_flat_stride (const nindex< DIM > &stride, const nindex< DIM > &size)
 
template<class E >
void print_element (scopira::tool::oflow_i &o, E el)
 element printing helper
 
template<>
void print_element< long > (scopira::tool::oflow_i &o, long el)
 element printing helper (specialization) More...
 
template<>
void print_element< unsigned long > (scopira::tool::oflow_i &o, unsigned long el)
 element printing helper (specialization) More...
 
template<>
void print_element< int > (scopira::tool::oflow_i &o, int el)
 element printing helper (specialization) More...
 
template<>
void print_element< unsigned int > (scopira::tool::oflow_i &o, unsigned int el)
 element printing helper (specialization) More...
 
template<>
void print_element< short > (scopira::tool::oflow_i &o, short el)
 element printing helper (specialization) More...
 
template<>
void print_element< char > (scopira::tool::oflow_i &o, char el)
 element printing helper (specialization) More...
 
template<>
void print_element< double > (scopira::tool::oflow_i &o, double el)
 element printing helper (specialization) More...
 
template<>
void print_element< float > (scopira::tool::oflow_i &o, float el)
 element printing helper (specialization) More...
 
template<class C >
scopira::tool::oflow_iprint_vector_slice (scopira::tool::oflow_i &o, const const_nslice< C, 1 > &V)
 internal
 
template<class C >
scopira::tool::oflow_iprint_matrix_slice (scopira::tool::oflow_i &o, const const_nslice< C, 2 > &M)
 internal
 
template<class C >
std::ostream & print_vector_slice (std::ostream &o, const const_nslice< C, 1 > &V)
 internal
 
template<class C >
std::ostream & print_matrix_slice (std::ostream &o, const const_nslice< C, 2 > &M)
 internal
 
template<class T >
void add_scalar (T &v, typename T::data_type val)
 
template<class T >
void sub_scalar (T &v, typename T::data_type val)
 
template<class T >
void mul_scalar (T &v, typename T::data_type val)
 
template<class T >
void div_scalar (T &v, typename T::data_type val)
 
template<class T >
void invdiv_scalar (T &v, typename T::data_type val)
 
template<class V , class T >
size_t min (const V &v, T &out)
 
template<class V , class T >
size_t max (const V &v, T &out)
 
template<class V , class T >
void sum (const V &v, T &out)
 
template<class V , class T >
void mean (const V &v, T &out)
 
template<class V , class T >
void variance (const V &v, T &out)
 
template<class V , class T >
void stddev (const V &v, T &out)
 
template<class LH , class RH >
void add_vector (LH &target, const RH &delta)
 
template<class LH , class RH >
void sub_vector (LH &target, const RH &delta)
 
template<class LH , class RH >
void mul_vector (LH &target, const RH &delta)
 
template<class LH , class RH >
void div_vector (LH &target, const RH &delta)
 
template<class LH , class RH >
void abs_vector (LH &target, const RH &source)
 
template<class V >
void print_vector (scopira::tool::oflow_i &o, const V &vv)
 
template<class T >
void pearson_scalar (T &x, T &y, double &rho)
 
template<class T >
void construct_index (narray< T > &array, narray< int > &index)
 

Variables

const double tol_c = 0.0000001
 
const double tinynum_c = 1.0e-20
 
const double smallnum_c = 1.0e-5
 
narray_delete_inull_narray_delete
 
narray_delete_inormal_narray_delete
 

Detailed Description

basekit provides basic math, array and direct I/O facilities.

Author
Aleksander Demko

Typedef Documentation

◆ boolcube_o

Simply typedef narray_o<bool,3> boolcube_o;

Author
Aleksander Demko

◆ boolcube_t

Simply typedef narray<bool,3> boolcube_t;

Author
Aleksander Demko

◆ boolmatrix_o

Simply typedef narray_o<bool,2> boolmatrix_o;

Author
Aleksander Demko

◆ boolmatrix_t

Simply typedef narray<bool,2> boolmatrix_t;

Author
Aleksander Demko

◆ boolquad_o

Simply typedef narray_o<bool,4> boolquad_o;

Author
Aleksander Demko

◆ boolquad_t

Simply typedef narray<bool,4> boolquad_t;

Author
Aleksander Demko

◆ boolvec_o

Simply typedef narray_o<bool,1> boolvec_o;

Author
Aleksander Demko

◆ boolvec_t

Simply typedef narray<bool,1> boolvec_t;

Author
Aleksander Demko

◆ charcube_o

Simply typedef narray_o<char,3> charcube_o;

Author
Aleksander Demko

◆ charcube_t

Simply typedef narray<char,3> charcube_t;

Author
Aleksander Demko

◆ charmatrix_o

Simply typedef narray_o<char,2> charmatrix_o;

Author
Aleksander Demko

◆ charmatrix_t

Simply typedef narray<char,2> charmatrix_t;

Author
Aleksander Demko

◆ charquad_o

Simply typedef narray_o<char,4> charquad_o;

Author
Aleksander Demko

◆ charquad_t

Simply typedef narray<char,4> charquad_t;

Author
Aleksander Demko

◆ charvec_o

Simply typedef narray_o<char,1> charvec_o;

Author
Aleksander Demko

◆ charvec_t

Simply typedef narray<char,1> charvec_t;

Author
Aleksander Demko

◆ doublecube_o

Simply typedef narray_o<double,3> doublecube_o;

Author
Aleksander Demko

◆ doublecube_t

Simply typedef narray<double,3> doublecube_t;

Author
Aleksander Demko

◆ doublematrix_o

Simply typedef narray_o<double,2> doublematrix_o;

Author
Aleksander Demko

◆ doublematrix_t

Simply typedef narray<double,2> doublematrix_t;

Author
Aleksander Demko

◆ doublequad_o

Simply typedef narray_o<double,4> doublequad_o;

Author
Aleksander Demko

◆ doublequad_t

Simply typedef narray<double,4> doublequad_t;

Author
Aleksander Demko

◆ doublevec_o

Simply typedef narray_o<double,1> doublevec_o;

Author
Aleksander Demko

◆ doublevec_t

Simply typedef narray<double,1> doublevec_t;

Author
Aleksander Demko

◆ floatcube_o

Simply typedef narray_o<float,3> floatcube_o;

Author
Aleksander Demko

◆ floatcube_t

Simply typedef narray<float,3> floatcube_t;

Author
Aleksander Demko

◆ floatmatrix_o

Simply typedef narray_o<float,2> floatmatrix_o;

Author
Aleksander Demko

◆ floatmatrix_t

Simply typedef narray<float,2> floatmatrix_t;

Author
Aleksander Demko

◆ floatquad_o

Simply typedef narray_o<float,4> floatquad_o;

Author
Aleksander Demko

◆ floatquad_t

Simply typedef narray<float,4> floatquad_t;

Author
Aleksander Demko

◆ floatvec_o

Simply typedef narray_o<float,1> floatvec_o;

Author
Aleksander Demko

◆ floatvec_t

Simply typedef narray<float,1> floatvec_t;

Author
Aleksander Demko

◆ intcube_o

Simply typedef narray_o<int,3> intcube_o;

Author
Aleksander Demko

◆ intcube_t

Simply typedef narray<int,3> intcube_t;

Author
Aleksander Demko

◆ intmatrix_o

Simply typedef narray_o<int,2> intmatrix_o;

Author
Aleksander Demko

◆ intmatrix_t

Simply typedef narray<int,2> intmatrix_t;

Author
Aleksander Demko

◆ intquad_o

Simply typedef narray_o<int,4> intquad_o;

Author
Aleksander Demko

◆ intquad_t

Simply typedef narray<int,4> intquad_t;

Author
Aleksander Demko

◆ intvec_o

Simply typedef narray_o<int,1> intvec_o;

Author
Aleksander Demko

◆ intvec_t

Simply typedef narray<int,1> intvec_t;

Author
Aleksander Demko

◆ shortcube_o

Simply typedef narray_o<short,3> shortcube_o;

Author
Aleksander Demko

◆ shortcube_t

Simply typedef narray<short,3> shortcube_t;

Author
Aleksander Demko

◆ shortmatrix_o

Simply typedef narray_o<short,2> shortmatrix_o;

Author
Aleksander Demko

◆ shortmatrix_t

Simply typedef narray<short,2> shortmatrix_t;

Author
Aleksander Demko

◆ shortquad_o

Simply typedef narray_o<short,4> shortquad_o;

Author
Aleksander Demko

◆ shortquad_t

Simply typedef narray<short,4> shortquad_t;

Author
Aleksander Demko

◆ shortvec_o

Simply typedef narray_o<short,1> shortvec_o;

Author
Aleksander Demko

◆ shortvec_t

Simply typedef narray<short,1> shortvec_t;

Author
Aleksander Demko

Function Documentation

◆ abs_vector()

template<class LH , class RH >
void scopira::basekit::abs_vector ( LH &  target,
const RH &  source 
)

Calculates the absolute value of each element in source, and writes it to target.

target and source may be the same instance.

Parameters
targettarget iterator-supporting container
sourceiterator-supporting source vector
Author
Brion Dolenko

Referenced by stddev().

◆ add_scalar()

template<class T >
void scopira::basekit::add_scalar ( T &  v,
typename T::data_type  val 
)

Adds val to every element in v. v can be any class that uses iterators.

Parameters
vthe vector to operator one
valthe value to add to each element in v
Author
Aleksander Demko

◆ add_vector()

template<class LH , class RH >
void scopira::basekit::add_vector ( LH &  target,
const RH &  delta 
)

Adds each element in target to each element in delta

Parameters
targettarget iterator-supporting container
deltaiterator-supporting delta vector
Author
Aleksander Demko

Referenced by stddev().

◆ bind_direct_file()

template<class T , int DIM>
bool scopira::basekit::bind_direct_file ( scopira::tool::fileflow f,
scopira::basekit::nindex< DIM >  sz,
scopira::basekit::narray< T, DIM > &  out,
bool  readonly = false,
scopira::tool::fileflow::offset_t  skipb = 0 
)

Binds the current file and offset to the output narray, at the given dimensions. f must be reference counted (and will be further reference counted.

Returns true on success.

Author
Aleksander Demko

References scopira::basekit::nindex< DIM >::product(), scopira::basekit::narray< T, DIM >::resize(), and scopira::basekit::narray< T, DIM >::resize_direct().

◆ bind_directio_file()

template<class T , int DIM>
bool scopira::basekit::bind_directio_file ( const std::string &  filename,
narray< T, DIM > &  out,
bool  readonly = false 
)

Binds an on disk DIO file to a narray.

This function uses the operating system's memory mapping facilities to map the "virtual array" to the disk file. As the elements in the array are accessed, the elements are loaded from disk. As they are written, the OS will queue disk writes.

The file must exist. If you need to create a new file, use scopira::basekit::create_directio_file.

See also
Scopira DIO (DirectIO) Array File Format
Parameters
filenamethe filename
outthe narray which will contain the loaded array. This variable must be initially empty.
readonlyif true, this file will be loaded in readonly mode.
Returns
true on success
Author
Aleksander Demko

References scopira::tool::fixed_array< size_t, DIM >::c_array(), scopira::basekit::narray< T, DIM >::get_direct(), and scopira::basekit::narray< T, DIM >::resize_direct().

◆ binomial()

int scopira::basekit::binomial ( int  n,
int  i 
)

Compute the binomial coefficient (n/(n-i, i)).

Parameters
nvalue n (total things)
ivalue i (choosen i at a time)
Returns
binomial coefficient (n/(n-i, i))
Author
Mark Alexiuk

Referenced by sign().

◆ construct_index()

template<class T >
void scopira::basekit::construct_index ( narray< T > &  array,
narray< int > &  index 
)

Constructs an index for a vector

Parameters
arraythe vector to be sorted
indexthe index array
Author
Shantha Ramachandran

References scopira::basekit::narray< T, DIM >::resize(), and scopira::basekit::narray< T, DIM >::size().

Referenced by stddev().

◆ create_directio_file()

template<class T , int DIM>
bool scopira::basekit::create_directio_file ( const std::string &  filename,
nindex< DIM >  sz 
)
inline

Creates a DIO file of the given type and dimensionality on disk. The element contents of the array on disk is undefined.

This function is used to create DIO files for scopira::basekit::bind_directio_file, as scopira::basekit::bind_directio_file can only bind to/open existing files.

See also
Scopira DIO (DirectIO) Array File Format
Parameters
filenamethe filename
szthe dimensions of the array to create
Returns
true on success
Author
Aleksander Demko

References scopira::tool::fixed_array< size_t, DIM >::c_array().

◆ div_scalar()

template<class T >
void scopira::basekit::div_scalar ( T &  v,
typename T::data_type  val 
)

Divides val to every element in v. v can be any class that uses iterators.

Parameters
vthe vector to operator one
valthe value to add to each element in v
Author
Aleksander Demko

◆ div_vector()

template<class LH , class RH >
void scopira::basekit::div_vector ( LH &  target,
const RH &  delta 
)

Divides each element in target to each element in delta

Parameters
targettarget iterator-supporting container
deltaiterator-supporting delta vector
Author
Aleksander Demko

Referenced by stddev().

◆ eigen_hessenberg()

template<class T >
void scopira::basekit::eigen_hessenberg ( narray< T, 2 > &  matrix,
narray< T > &  eigen_real,
narray< T > &  eigen_imaginary 
)

Calculates the eigenvalues of a Hessenberg matrix

Parameters
matrixthe Hessenberg matrix
eigen_realthe real parts of the eigenvalues
eigen_imaginarythe imaginary parts of the eigenvalues
Author
Shantha Ramachandran

References scopira::basekit::narray< T, DIM >::height().

◆ elim_hessian()

template<class T >
void scopira::basekit::elim_hessian ( narray< T, 2 > &  matrix)

Reduces a general matrix to Hessenberg form

Parameters
matrixthe matrix to be reduced
Author
Shantha Ramachandran

References scopira::basekit::narray< T, DIM >::height().

◆ factorial()

int scopira::basekit::factorial ( int  n,
int  m = 0 
)

Compute the factorial of n. If m != 0, compute factorial of (n-m).

Parameters
nnatural number n
mdifference integer m, m < n.
Returns
n! if (m==0), (n-m)! otherwise.
Author
Mark Alexiuk

Referenced by sign().

◆ gauss_jordan()

template<class T >
void scopira::basekit::gauss_jordan ( narray< T, 2 > &  matrix,
narray< T, 2 > &  rhs 
)

Gauss-Jordan matrix inversion and linear equations solution The input matrix 'matrix' is replaced by its inverse, and the input matrix 'rhs' is replaced by the set of solution vectors

Parameters
matrixthe matrix to be inverted
rhsthe right hand side matrix of the linear equation
Author
Shantha Ramachandran

References scopira::basekit::narray< T, DIM >::height(), max(), scopira::basekit::narray< T, DIM >::resize(), and scopira::basekit::narray< T, DIM >::width().

◆ invdiv_scalar()

template<class T >
void scopira::basekit::invdiv_scalar ( T &  v,
typename T::data_type  val 
)

Inverse divides val to every element in v. v can be any class that uses iterators. To summarize, each element in v will be replaced by val/v

Parameters
vthe vector to operator one
valthe value to add to each element in v
Author
Aleksander Demko

◆ invert_matrix()

template<class T >
bool scopira::basekit::invert_matrix ( T &  dest,
const T &  src 
)

Inverts the matrix.

Parameters
srcthe source matrix
destthe output matrix
Returns
true if the result was non-singular (OK)
Author
Aleksander Demko

References scopira::basekit::narray< T, DIM >::clear(), scopira::basekit::narray< T, DIM >::resize(), scopira::basekit::narray< T, DIM >::set(), and scopira::basekit::narray< T, DIM >::width().

◆ is_equal()

template<class T >
bool scopira::basekit::is_equal ( v1,
v2 
)
inline

Are v1 and v2 "equal" (within tolerance)

Author
Aleksander Demko

References tol_c.

Referenced by resample_linear().

◆ is_flat_stride()

template<int DIM>
bool scopira::basekit::is_flat_stride ( const nindex< DIM > &  stride,
const nindex< DIM > &  size 
)

Returns true if the given stride set is considered "flat". This allow for performance optimizations in nslice.

Author
Aleksander Demko

References scopira::tool::fixed_array< size_t, DIM >::size().

Referenced by scopira::basekit::const_nslice< T, DIM >::c_array(), scopira::basekit::nslice< T, DIM >::is_flat_stride(), and scopira::basekit::const_nslice< T, DIM >::is_flat_stride().

◆ is_inf() [1/2]

int scopira::basekit::is_inf ( double  v)
inline

see man isinf for the meanin of the return

Is v infinity.

Author
Aleksander Demko

Referenced by is_nan().

◆ is_inf() [2/2]

int scopira::basekit::is_inf ( float  v)
inline

Is v infinity.

Author
Aleksander Demko

◆ is_nan() [1/2]

bool scopira::basekit::is_nan ( double  v)
inline

Is v NaN (not a number)

Author
Aleksander Demko

Referenced by is_zero().

◆ is_nan() [2/2]

bool scopira::basekit::is_nan ( float  v)
inline

Is v NaN (not a number)

Author
Aleksander Demko

References is_inf().

◆ is_zero()

template<class T >
bool scopira::basekit::is_zero ( v)
inline

Is v zero (within tolerance)

Author
Aleksander Demko

References is_nan(), and tol_c.

Referenced by resample_linear().

◆ load_directio_file()

template<class T , int DIM>
bool scopira::basekit::load_directio_file ( const std::string &  filename,
scopira::basekit::narray< T, DIM > &  out 
)

Reads an array from disk in DIO format.

See also
Scopira DIO (DirectIO) Array File Format
Parameters
filenamethe filename
outthe narray which will contain the loaded array. This variable must be initially empty.
Returns
true on success
Author
Aleksander Demko

References scopira::tool::fixed_array< size_t, DIM >::c_array(), normal_narray_delete, and scopira::basekit::narray< T, DIM >::resize_direct().

◆ lu_backsubstitution()

template<class T >
void scopira::basekit::lu_backsubstitution ( narray< T > &  dest,
const narray< T, 2 > &  inv_a,
const narray< int > &  index 
)

Linear equation solution, backsubstitution Solves the set of n linear equations a�x = b.

Parameters
descthe solution vector x
inv_ais the input matrix, which is the LU decomposition of a
indexis the permutation vector returned by the LU decomposition.
bis the input right-hand side vector.
Author
Marina Mandelzweig

References scopira::basekit::narray< T, DIM >::copy(), scopira::basekit::narray< T, DIM >::get(), scopira::basekit::narray< T, DIM >::set(), sum(), and scopira::basekit::narray< T, DIM >::width().

◆ lu_decomposition()

template<class T >
bool scopira::basekit::lu_decomposition ( narray< T, 2 > &  dest,
const narray< T, 2 > &  src,
narray< int > &  idx,
bool &  odd 
)

Calaculates the LU decomposition of a rowwise permutation of the input matrix src

Parameters
destthe output LU decomposition matrix
srcthe source matrix
idxis an output vector that records the row permutation effected by the partial pivoting
oddindicated whether the number of row interchanges was even or odd, respectively.
Author
Marina Mandelzweig

References scopira::basekit::narray< T, DIM >::clear(), scopira::basekit::narray< T, DIM >::copy(), scopira::basekit::narray< T, DIM >::get(), max(), scopira::basekit::narray< T, DIM >::resize(), scopira::basekit::narray< T, DIM >::set(), sum(), tinynum_c, and scopira::basekit::narray< T, DIM >::width().

◆ max()

template<class V , class T >
size_t scopira::basekit::max ( const V &  v,
T &  out 
)

Finds the maximum.

Parameters
vany container that has iteration facilities
outthe output scalar
Returns
the index of the max
Author
Aleksander Demko

Referenced by gauss_jordan(), and lu_decomposition().

◆ mean()

template<class V , class T >
void scopira::basekit::mean ( const V &  v,
T &  out 
)

Calculates the mean

Parameters
vany container that has iteration facilities
outthe output scalar
Author
Aleksander Demko

References sum().

Referenced by variance().

◆ min()

template<class V , class T >
size_t scopira::basekit::min ( const V &  v,
T &  out 
)

Finds the minimum.

Parameters
vany container that has iteration facilities
outthe output scalar
Returns
the index of the min
Author
Aleksander Demko

◆ mul_matrix() [1/2]

template<class T , class SCA >
void scopira::basekit::mul_matrix ( T &  dest,
SCA  d 
)

Multiple each element in the given matrix-like lass by the given scalar

Parameters
destthe matrix like class to operate on
dthe value to multiple
Author
Aleksander Demko

◆ mul_matrix() [2/2]

template<class T , class T2 , class T3 >
void scopira::basekit::mul_matrix ( T &  dest,
const T2 &  m1,
const T3 &  m2,
bool  t1 = false,
bool  t2 = false 
)

Matrix-matrix copy, with inline transposing.

Parameters
destthe result/destination matrix. will be resized.
m1the first matrix
m2the second matrix
t1transpose the 1st matrix
t2transpose the 2nd matrix
Author
Aleksander Demko

References sum().

◆ mul_scalar()

template<class T >
void scopira::basekit::mul_scalar ( T &  v,
typename T::data_type  val 
)

Multiples val to every element in v. v can be any class that uses iterators.

Parameters
vthe vector to operator one
valthe value to add to each element in v
Author
Aleksander Demko

◆ mul_vector()

template<class LH , class RH >
void scopira::basekit::mul_vector ( LH &  target,
const RH &  delta 
)

Multiplies each element in target to each element in delta

Parameters
targettarget iterator-supporting container
deltaiterator-supporting delta vector
Author
Aleksander Demko

Referenced by stddev().

◆ pearson_scalar()

template<class T >
void scopira::basekit::pearson_scalar ( T &  x,
T &  y,
double &  rho 
)

Calculates pearson.

Author
Mark Alexiuk
Rodrigo Vivanco
Conrad Wiebe

Pearson coefficient of correlation.

Parameters
xfirst sample to compare
ysecond sample to compare
rhopearson correlation
Author
Mark Alexiuk
Rodrigo Vivanco
Conrad Wiebe

Referenced by stddev().

◆ print_element< char >()

template<>
void scopira::basekit::print_element< char > ( scopira::tool::oflow_i o,
char  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_element< double >()

template<>
void scopira::basekit::print_element< double > ( scopira::tool::oflow_i o,
double  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_element< float >()

template<>
void scopira::basekit::print_element< float > ( scopira::tool::oflow_i o,
float  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

References print_vector_slice().

◆ print_element< int >()

template<>
void scopira::basekit::print_element< int > ( scopira::tool::oflow_i o,
int  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_element< long >()

template<>
void scopira::basekit::print_element< long > ( scopira::tool::oflow_i o,
long  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_element< short >()

template<>
void scopira::basekit::print_element< short > ( scopira::tool::oflow_i o,
short  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_element< unsigned int >()

template<>
void scopira::basekit::print_element< unsigned int > ( scopira::tool::oflow_i o,
unsigned int  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_element< unsigned long >()

template<>
void scopira::basekit::print_element< unsigned long > ( scopira::tool::oflow_i o,
unsigned long  el 
)
inline

element printing helper (specialization)

internal print drivers. you may need to define more if you have your own types

◆ print_vector()

template<class V >
void scopira::basekit::print_vector ( scopira::tool::oflow_i o,
const V &  vv 
)

Prints all the elements in the given iterator supporting container

Parameters
othe output stream
vvthe container that supports iteration
Author
Aleksander Demko

Referenced by stddev().

◆ pythagorean()

template<class DT >
DT scopira::basekit::pythagorean ( DT  a,
DT  b 
)

Computes Pythagorean Theorem: (a^2 + b^2)^0.5 without destructive underflow or overflow

◆ query_directio_file()

bool scopira::basekit::query_directio_file ( const std::string &  filename,
std::string &  elementtype,
std::vector< size_t > &  dimen 
)

The queries the DIO file for its dimensionality and element type information. It doesn't do any data loading.

See also
Scopira DIO (DirectIO) Array File Format
Parameters
filenamethe filename
elementtypethe element type (int32, float64, etc)
dimenthe dimensions of the on disk file
Returns
true on successful query
Author
Aleksander Demko

◆ resample_linear()

template<class SRC , class DEST >
void scopira::basekit::resample_linear ( DEST &  dest,
const SRC &  src 
)

Resamples the src matrix to the destination matrix, using (not so fast) linear interpolation.

Author
Aleksander Demko

References is_equal(), and is_zero().

◆ resample_nn()

template<class SRC , class DEST >
void scopira::basekit::resample_nn ( DEST &  dest,
const SRC &  src 
)

Resamples the src matrix to the destination matrix, using (fast) nearest neighbor.

Author
Aleksander Demko

◆ save_directio_file()

template<class T , int DIM>
bool scopira::basekit::save_directio_file ( const std::string &  filename,
const scopira::basekit::narray< T, DIM > &  in 
)

Writes an array to disk in DIO format.

See also
Scopira DIO (DirectIO) Array File Format
Parameters
filenamethe filename
outthe narray which will contain the loaded array. This variable must be initially empty.
Returns
true on success
Author
Aleksander Demko

References scopira::basekit::narray< T, DIM >::c_array(), and scopira::basekit::narray< T, DIM >::dimen().

◆ sign()

template<class T >
T scopira::basekit::sign ( v)
inline

Returns the "sign" of v.

Parameters
vthe number to test
Returns
1 if v is positive, -1 if v is negative, 0 otherwise
Author
Aleksander Demko

References binomial(), and factorial().

◆ sort_covariance()

template<class T >
void scopira::basekit::sort_covariance ( narray< T, 2 > &  matrix,
narray< int > &  fitted,
int  mfit 
)

Rearrange covariance matrix

Parameters
matrixthe covariance matrix
fittedfitting coefficients
mfit(mfit?)
Author
Shantha Ramachandran

References scopira::basekit::narray< T, DIM >::height().

◆ sqr()

template<class T >
T scopira::basekit::sqr ( v)
inline

Computes the sqrt of v

Author
Aleksander Demko

◆ stddev()

template<class V , class T >
void scopira::basekit::stddev ( const V &  v,
T &  out 
)

Calculates standard deviation

Parameters
vany container that has iteration facilities
outthe output scalar
Author
Aleksander Demko

References abs_vector(), add_vector(), construct_index(), div_vector(), mul_vector(), pearson_scalar(), print_vector(), and sub_vector().

◆ sub_scalar()

template<class T >
void scopira::basekit::sub_scalar ( T &  v,
typename T::data_type  val 
)

Subtracts val to every element in v. v can be any class that uses iterators.

Parameters
vthe vector to operator one
valthe value to add to each element in v
Author
Aleksander Demko

◆ sub_vector()

template<class LH , class RH >
void scopira::basekit::sub_vector ( LH &  target,
const RH &  delta 
)

Subtracts each element in target to each element in delta

Parameters
targettarget iterator-supporting container
deltaiterator-supporting delta vector
Author
Aleksander Demko

Referenced by stddev().

◆ sum()

template<class V , class T >
void scopira::basekit::sum ( const V &  v,
T &  out 
)

Calculates the sum

Parameters
vany container that has iteration facilities
outthe output scalar
Author
Aleksander Demko

Referenced by lu_backsubstitution(), lu_decomposition(), mean(), mul_matrix(), and variance().

◆ svd()

template<class T >
bool scopira::basekit::svd ( narray< T, 2 > &  Mu,
narray< T > &  Vw,
narray< T, 2 > &  Mv 
)

construct the singular value decomposition of the matrix u svd results are:Mv,Vw,Mu(src matrix modified) return false if was not able to perform svd.

Parameters
MuM x M orthogonal matrix - u (src matrix modified)
VwN diagonal vector of singular values
MvN x M orthogonal matrix

References scopira::basekit::narray< T, DIM >::clear(), scopira::basekit::narray< T, DIM >::height(), scopira::basekit::narray< T, DIM >::resize(), svd_sign(), and scopira::basekit::narray< T, DIM >::width().

◆ svd_backsubstitution()

template<class T >
void scopira::basekit::svd_backsubstitution ( narray< T, 2 > &  Mu,
narray< T > &  Vw,
narray< T, 2 > &  Mv,
narray< T > &  b,
narray< T > &  x 
)

Solves linear equation for x using backsubstitution and the results of SVD Solves Dx = b where D has been decomposed int Mu,Vw and Mv. Solution is in x

Parameters
Muorthoganal matrix from SVD
Vwvector of singular values from SVD
Mvorthoganal matrix from SVD
bright hand side data vector
xthe solution

References scopira::basekit::narray< T, DIM >::height(), scopira::basekit::narray< T, DIM >::resize(), and scopira::basekit::narray< T, DIM >::width().

◆ transpose_matrix()

template<class D , class S >
void scopira::basekit::transpose_matrix ( D &  dest,
const S &  src 
)

Transposes a matrix.

Parameters
srcthe source matrix
destthe output matrix (cannot be the same as src)
Author
Aleksander Demko

◆ variance()

template<class V , class T >
void scopira::basekit::variance ( const V &  v,
T &  out 
)

Calculates variance

Parameters
vany container that has iteration facilities
outthe output scalar
Author
Aleksander Demko

References mean(), and sum().

Variable Documentation

◆ normal_narray_delete

narray_delete_i* scopira::basekit::normal_narray_delete

This special narray delete tells that narray to assume the array and "delete" it as per usual.

Author
Aleksander Demko

Referenced by load_directio_file(), and scopira::basekit::narray< scopira::tool::uuid >::resize_direct().

◆ null_narray_delete

narray_delete_i* scopira::basekit::null_narray_delete

A narray delete that does nothing.

Author
Aleksander Demko

Referenced by scopira::basekit::narray< scopira::tool::uuid >::resize().

◆ smallnum_c

const double scopira::basekit::smallnum_c = 1.0e-5

An arbitrary small number constant.

Author
Aleksander Demko

◆ tinynum_c

const double scopira::basekit::tinynum_c = 1.0e-20

An arbitrary tiny number constant.

Author
Aleksander Demko

Referenced by lu_decomposition().

◆ tol_c

const double scopira::basekit::tol_c = 0.0000001

The tolerance constant, as used in various functions.

Author
Aleksander Demko

Referenced by is_equal(), and is_zero().