All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data Structures | Namespaces
vector.h File Reference

Assorted generic vector functions. More...

Detailed Description

This file contains a set of template functions which can be applied to almost any vector or matrix type which allow element access through operator[]. Detailed requirements on the template parameters are given in the functions below.

For a general discussion of vectors and matrices in O2scl , see the Arrays, Vectors, Matrices and Tensors of the User's Guide.

For statistics operations not included here, see vec_stats.h in the directory src/other . Also related are the matrix output functions, o2scl::matrix_out(), which is defined in columnify.h because they utilize the class o2scl::columnify to format the output.

For functions which search for a value in an ordered (either increasing or decreasing) vector, see the class o2scl::search_vec .

Idea for Future:

Create a matrix transpose copy function?

Create matrix swap row and column functions

Definition in file vector.h.

#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <o2scl/misc.h>
#include <o2scl/uniform_grid.h>
#include <armadillo>
#include <Eigen/Dense>

Go to the source code of this file.

Data Structures

class  o2scl::matrix_row_gen< mat_t >
 Generic object which represents a row of a matrix. More...
 
class  o2scl::matrix_column_gen< mat_t >
 Generic object which represents a column of a matrix. More...
 
class  boost::numeric::ublas::vector< T, A >
 The default vector type from uBlas. More...
 
class  boost::numeric::ublas::matrix< T, F, A >
 The default matrix type from uBlas. More...
 

Namespaces

 o2scl
 The main O2scl namespace.
 
 boost
 Placeholder documentation of some related Boost objects.
 
 boost::numeric
 Documentation of Boost::numeric objects.
 
 boost::numeric::ublas
 Documentation of uBlas objects.
 

Functions

Copying vectors and matrices
template<class vec_t , class vec2_t >
void o2scl::vector_copy (vec_t &src, vec2_t &dest)
 Simple generic vector copy. More...
 
template<class vec_t , class vec2_t >
void o2scl::vector_copy (size_t N, vec_t &src, vec2_t &dest)
 Simple generic vector copy of the first N elements. More...
 
template<class mat_t , class mat2_t >
void o2scl::matrix_copy (mat_t &src, mat2_t &dest)
 Simple generic matrix copy. More...
 
template<class mat_t , class mat2_t >
void o2scl::matrix_copy (size_t M, size_t N, mat_t &src, mat2_t &dest)
 Simple generic matrix copy of the first $ (M,N) $ matrix elements. More...
 
Swapping parts of vectors and matrices
template<class vec_t , class vec2_t , class data_t >
void o2scl::vector_swap (size_t N, vec_t &v1, vec2_t &v2)
 Swap the first N elements of two vectors. More...
 
template<class vec_t , class vec2_t >
void o2scl::vector_swap_double (size_t N, vec_t &v1, vec2_t &v2)
 Generic swap of of the first N elements of two double-precision vectors. More...
 
template<class mat_t , class mat2_t , class data_t >
void o2scl::matrix_swap (size_t M, size_t N, mat_t &v1, mat2_t &v2)
 Generic swap of two matrices. More...
 
template<class mat_t , class mat2_t , class data_t >
void o2scl::matrix_swap_double (size_t M, size_t N, mat_t &m1, mat2_t &m2)
 Generic swap of two matrices. More...
 
template<class vec_t , class data_t >
void o2scl::vector_swap (vec_t &v, size_t i, size_t j)
 Generic swap two elements in a vector. More...
 
template<class vec_t >
void o2scl::vector_swap_double (vec_t &v, size_t i, size_t j)
 Generic swap two elements in a vector. More...
 
template<class mat_t , class data_t >
void o2scl::matrix_swap (mat_t &m, size_t i1, size_t j1, size_t i2, size_t j2)
 Generic swap two elements in a matrix. More...
 
template<class mat_t >
void o2scl::matrix_swap_double (mat_t &m, size_t i1, size_t j1, size_t i2, size_t j2)
 Generic swap two elements in a matrix. More...
 
template<class mat_t , class data_t >
void o2scl::matrix_swap_cols (size_t M, mat_t &m, size_t j1, size_t j2)
 Generic swap two columns in a matrix. More...
 
template<class mat_t >
void o2scl::matrix_swap_cols_double (size_t M, mat_t &m, size_t j1, size_t j2)
 Generic swap two elements in a matrix. More...
 
template<class mat_t , class data_t >
void o2scl::matrix_swap_rows (size_t N, mat_t &m, size_t i1, size_t i2)
 Generic swap two columns in a matrix. More...
 
template<class mat_t >
void o2scl::matrix_swap_rows_double (size_t N, mat_t &m, size_t i1, size_t i2)
 Generic swap two elements in a matrix. More...
 
Sorting vectors
template<class vec_t , class data_t >
void o2scl::sort_downheap (vec_t &data, size_t n, size_t k)
 Provide a downheap() function for vector_sort()
 
template<class vec_t , class data_t >
void o2scl::vector_sort (size_t n, vec_t &data)
 Sort a vector (in increasing order) More...
 
template<class vec_t , class vec_size_t >
void o2scl::sort_index_downheap (size_t N, const vec_t &data, vec_size_t &order, size_t k)
 Provide a downheap() function for vector_sort_index()
 
template<class vec_t , class vec_size_t >
void o2scl::vector_sort_index (size_t n, const vec_t &data, vec_size_t &order)
 Create a permutation which sorts a vector (in increasing order) More...
 
template<class vec_t >
void o2scl::vector_sort_double (size_t n, vec_t &data)
 Sort a vector of doubles (in increasing order) More...
 
Smallest or largest subset functions
template<class vec_t , class data_t >
void o2scl::vector_smallest (size_t n, vec_t &data, size_t k, vec_t &smallest)
 Find the k smallest entries of a vector. More...
 
template<class vec_t , class data_t >
void o2scl::vector_largest (size_t n, vec_t &data, size_t k, vec_t &largest)
 Find the k largest entries of a vector. More...
 
Vector minimum and maximum functions
template<class vec_t , class data_t >
data_t o2scl::vector_max_value (size_t n, const vec_t &data)
 Compute the maximum of the first n elements of a vector.
 
template<class vec_t , class data_t >
size_t o2scl::vector_max_index (size_t n, const vec_t &data)
 Compute the index which holds the maximum of the first n elements of a vector.
 
template<class vec_t , class data_t >
void o2scl::vector_max (size_t n, const vec_t &data, size_t &index, data_t &val)
 Compute the maximum of the first n elements of a vector.
 
template<class vec_t , class data_t >
data_t o2scl::vector_min_value (size_t n, const vec_t &data)
 Compute the minimum of the first n elements of a vector.
 
template<class vec_t , class data_t >
size_t o2scl::vector_min_index (size_t n, const vec_t &data)
 Compute the index which holds the minimum of the first n elements of a vector.
 
template<class vec_t , class data_t >
void o2scl::vector_min (size_t n, const vec_t &data, size_t &index, data_t &val)
 Compute the minimum of the first n elements of a vector.
 
template<class vec_t , class data_t >
void o2scl::vector_minmax_value (size_t n, vec_t &data, data_t &min, data_t &max)
 Compute the minimum and maximum of the first n elements of a vector.
 
template<class vec_t , class data_t >
void o2scl::vector_minmax_index (size_t n, vec_t &data, size_t &ix_min, size_t &ix_max)
 Compute the minimum and maximum of the first n elements of a vector.
 
template<class vec_t , class data_t >
void o2scl::vector_minmax (size_t n, vec_t &data, size_t &ix_min, data_t &min, size_t &ix_max, data_t &max)
 Compute the minimum and maximum of the first n elements of a vector.
 
Minima and maxima of vectors through quadratic fit
template<class vec_t , class data_t >
data_t o2scl::vector_max_quad (size_t n, const vec_t &data)
 Maximum of vector by quadratic fit.
 
template<class vec_t , class data_t >
data_t o2scl::vector_max_quad (size_t n, const vec_t &x, const vec_t &y)
 Maximum of vector by quadratic fit.
 
template<class vec_t , class data_t >
data_t o2scl::vector_max_quad_loc (size_t n, const vec_t &x, const vec_t &y)
 Location of vector maximum by quadratic fit.
 
template<class vec_t , class data_t >
data_t o2scl::vector_min_quad (size_t n, const vec_t &data)
 Minimum of vector by quadratic fit.
 
template<class vec_t , class data_t >
data_t o2scl::vector_min_quad (size_t n, const vec_t &x, const vec_t &y)
 Minimum of vector by quadratic fit.
 
template<class vec_t , class data_t >
data_t o2scl::vector_min_quad_loc (size_t n, const vec_t &x, const vec_t &y)
 Location of vector minimum by quadratic fit.
 
Matrix minimum and maximum functions
template<class mat_t , class data_t >
data_t o2scl::matrix_max (size_t m, const size_t n, const mat_t &data)
 Compute the maximum of the lower-left part of a matrix.
 
template<class mat_t , class data_t >
data_t o2scl::matrix_max (const mat_t &data)
 Compute the maximum of a matrix.
 
template<class mat_t , class data_t >
void o2scl::matrix_max_index (size_t n, const size_t m, const mat_t &data, size_t &i_max, size_t &j_max, data_t &max)
 Compute the maximum of a matrix and return the indices of the maximum element.
 
template<class mat_t , class data_t >
data_t o2scl::matrix_min (size_t n, const size_t m, const mat_t &data)
 Compute the minimum of a matrix.
 
template<class mat_t , class data_t >
void o2scl::matrix_min_index (size_t n, const size_t m, const mat_t &data, size_t &i_min, size_t &j_min, data_t &min)
 Compute the minimum of a matrix and return the indices of the minimum element.
 
template<class mat_t , class data_t >
void o2scl::matrix_minmax (size_t n, const size_t m, const mat_t &data, data_t &min, data_t &max)
 Compute the minimum and maximum of a matrix.
 
template<class mat_t , class data_t >
void o2scl::matrix_minmax_index (size_t n, const size_t m, const mat_t &data, size_t &i_min, size_t &j_min, data_t &min, size_t &i_max, size_t &j_max, data_t &max)
 Compute the minimum and maximum of a matrix and return their locations.
 
Searching vectors and matrices
template<class vec_t >
size_t o2scl::vector_lookup (size_t n, const vec_t &x, double x0)
 Lookup element x0 in vector x of length n. More...
 
template<class mat_t >
void o2scl::matrix_lookup (size_t m, size_t n, const mat_t &A, double x0, size_t &i, size_t &j)
 Lookup an element in a matrix. More...
 
template<class vec_t , class data_t >
size_t o2scl::vector_bsearch_inc (const data_t x0, const vec_t &x, size_t lo, size_t hi)
 Binary search a part of an increasing vector for x0. More...
 
template<class vec_t , class data_t >
size_t o2scl::vector_bsearch_dec (const data_t x0, const vec_t &x, size_t lo, size_t hi)
 Binary search a part of an decreasing vector for x0. More...
 
template<class vec_t , class data_t >
size_t o2scl::vector_bsearch (const data_t x0, const vec_t &x, size_t lo, size_t hi)
 Binary search a part of a monotonic vector for x0. More...
 
Miscellaneous mathematical functions
template<class vec_t , class data_t >
data_t o2scl::vector_sum (size_t n, vec_t &data)
 Compute the sum of the first n elements of a vector. More...
 
template<class vec_t , class data_t >
data_t o2scl::vector_sum (vec_t &data)
 Compute the sum of all the elements of a vector. More...
 
template<class vec_t , class data_t >
data_t o2scl::vector_norm (size_t n, const vec_t &x)
 Compute the norm of a vector of floating-point (single or double precision) numbers. More...
 
Other vector and matrix functions
template<class vec_t , class data_t >
void o2scl::vector_rotate (size_t n, vec_t &data, size_t k)
 "Rotate" a vector so that the kth element is now the beginning More...
 
template<class vec_t , class data_t >
void o2scl::vector_reverse (size_t n, vec_t &data)
 Reverse a vector. More...
 
template<class vec_t , class data_t >
void o2scl::vector_reverse (vec_t &data)
 Reverse a vector. More...
 
template<class mat_t , class mat_row_t >
mat_row_t o2scl::matrix_row (mat_t &M, size_t row)
 Construct a row of a matrix. More...
 
template<class mat_t , class mat_column_t >
mat_column_t o2scl::matrix_column (mat_t &M, size_t column)
 Construct a column of a matrix. More...
 
template<class vec_t >
void o2scl::vector_out (std::ostream &os, size_t n, const vec_t &v, bool endline=false)
 Output a vector to a stream. More...
 
template<class vec_t >
void o2scl::vector_out (std::ostream &os, const vec_t &v, bool endline=false)
 Output a vector to a stream. More...
 
template<class vec_t , class data_t >
void o2scl::vector_grid (uniform_grid< data_t > g, vec_t &v)
 Fill a vector with a specified grid.
 
template<class mat_t >
void o2scl::matrix_set_identity (size_t M, size_t N, mat_t &m)
 Set a matrix to unity on the diagonal and zero otherwise.
 
Armadillo specializations
double o2scl::matrix_max (const arma::mat &data)
 Armadillo version of matrix_max()
 
template<>
arma::subview_row< double > o2scl::matrix_row< arma::mat, arma::subview_row< double > > (arma::mat &M, size_t row)
 Armadillo version of matrix_row()
 
template<>
arma::subview_col< double > o2scl::matrix_column< arma::mat, arma::subview_col< double > > (arma::mat &M, size_t column)
 Armadillo version of matrix_column()
 
Eigen specializations
double o2scl::matrix_max (const Eigen::MatrixXd &data)
 Eigen version of matrix_max()
 
template<>
Eigen::MatrixXd::RowXpr o2scl::matrix_row< Eigen::MatrixXd, Eigen::MatrixXd::RowXpr > (Eigen::MatrixXd &M, size_t row)
 Eigen version of matrix_row()
 
template<>
Eigen::MatrixXd::ColXpr o2scl::matrix_column< Eigen::MatrixXd, Eigen::MatrixXd::ColXpr > (Eigen::MatrixXd &M, size_t column)
 Eigen version of matrix_column()
 

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..