vector.h File Reference

File for generic vector functions. More...

#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <o2scl/err_hnd.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_sort.h>

Go to the source code of this file.


Detailed Description

File for generic vector functions.

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

For overloaded operators involving vectors and matrices, see vec_arith.h . For statistics operations not included here, see vec_stats.h in the directory src/other . For functions and classes which are specific to C-style arrays, see array.h . Also related are the matrix output functions, matrix_out(), matrix_cx_out_paren(), and matrix_out_paren() which are defined in columnify.h because they utilize the class columnify to format the output.

For functions which search for a value in an ordered vector, see the class search_vec .

Definition in file vector.h.


Functions

template<class vec_t , class vec2_t >
void vector_copy (size_t N, vec_t &src, vec2_t &dest)
 Naive vector copy.
template<class mat_t , class mat2_t >
void matrix_copy (size_t M, size_t N, mat_t &src, mat2_t &dest)
 Naive matrix copy.
template<class vec_t , class vec2_t >
void vector_cx_copy_gsl (size_t N, vec_t &src, vec2_t &dest)
 GSL complex vector copy.
template<class mat_t , class mat2_t >
void matrix_cx_copy_gsl (size_t M, size_t N, mat_t &src, mat2_t &dest)
 GSL complex matrix copy.
template<class vec_t >
int vector_out (std::ostream &os, size_t n, vec_t &v, bool endline=false)
 Output a vector to a stream.
template<class data_t , class vec_t >
void sort_downheap (vec_t &data, const size_t N, size_t k)
 Provide a downheap() function for vector_sort().
template<class data_t , class vec_t >
int vector_sort (const size_t n, vec_t &data)
 Sort a vector.
template<class data_t , class vec_t >
int vector_rotate (const size_t n, vec_t &data, size_t k)
 "Rotate" a vector so that the kth element is now the beginning
template<class vec_t >
double vector_max (const size_t n, vec_t &data)
 Compute the maximum of the first n elements of a vector.
template<class vec_t >
double vector_min (const size_t n, vec_t &data)
 Compute the minimum of the first n elements of a vector.
template<class vec_t >
int vector_minmax (const size_t n, vec_t &data, double &min, double &max)
 Compute the minimum and maximum of the first n elements of a vector.
template<class vec_t >
size_t vector_max_index (const size_t n, vec_t &data, double &max)
 Compute the maximum of the first n elements of a vector.
template<class vec_t >
int vector_min_index (const size_t n, vec_t &data, double &min)
 Compute the minimum of the first n elements of a vector.
template<class vec_t >
int vector_minmax_index (const size_t n, vec_t &data, double &min, size_t &ix, double &max, size_t &ix2)
 Compute the minimum and maximum of the first n elements of a vector.
template<class vec_t >
double vector_sum (const size_t n, vec_t &data)
 Compute the sum of the first n elements of a vector.
template<class data_t , class vec_t >
int vector_reverse (const size_t n, vec_t &data)
 Reverse a vector.

Function Documentation

void matrix_copy ( size_t  M,
size_t  N,
mat_t &  src,
mat2_t &  dest 
) [inline]

Naive matrix copy.

Note:
This ordering is reversed from the GSL function gsl_matrix_memcpy . This is to be used with
      matrix_copy(N,source,destination);
instead of
      gsl_matrix_memcpy(destination,source);

Definition at line 91 of file vector.h.

void matrix_cx_copy_gsl ( size_t  M,
size_t  N,
mat_t &  src,
mat2_t &  dest 
) [inline]

GSL complex matrix copy.

Idea for future:
At present this works only with complex types based directly on the GSL complex format. This could be improved.

Definition at line 120 of file vector.h.

void vector_copy ( size_t  N,
vec_t &  src,
vec2_t &  dest 
) [inline]

Naive vector copy.

Note:
This ordering is reversed from the GSL function gsl_vector_memcpy . This is to be used with
      vector_copy(N,source,destination);
instead of
      gsl_vector_memcpy(destination,source);

Definition at line 73 of file vector.h.

void vector_cx_copy_gsl ( size_t  N,
vec_t &  src,
vec2_t &  dest 
) [inline]

GSL complex vector copy.

Idea for future:
At present this works only with complex types based directly on the GSL complex format. This could be improved.

Definition at line 106 of file vector.h.

int vector_out ( std::ostream &  os,
size_t  n,
vec_t &  v,
bool  endline = false 
) [inline]

Output a vector to a stream.

No trailing space is output after the last element, and an endline is output only if endline is set to true. If the parameter n is zero, this function silently does nothing.

Note that the O2scl vector classes also have their own operator<<() defined for them.

Definition at line 140 of file vector.h.

int vector_rotate ( const size_t  n,
vec_t &  data,
size_t  k 
) [inline]

"Rotate" a vector so that the kth element is now the beginning

This is a generic template function which will work for any types data_t and vec_t for which

  • data_t has an operator=
  • vec_t::operator[] returns a reference to an object of type data_t

Definition at line 229 of file vector.h.

int vector_sort ( const size_t  n,
vec_t &  data 
) [inline]

Sort a vector.

This is a generic sorting template function. It will work for any types data_t and vec_t for which

  • data_t has an operator=
  • data_t has a less than operator to compare elements
  • vec_t::operator[] returns a reference to an object of type data_t

In particular, it will work with ovector, uvector, ovector_int, uvector_int (and other related O2scl vector classes), the STL template class std::vector, and arrays and pointers of numeric, character, and string objects.

For example,

      std::string list[3]={"dog","cat","fox"};
      vector_sort<std::string, std::string[3]>(3,list);

Definition at line 193 of file vector.h.

double vector_sum ( const size_t  n,
vec_t &  data 
) [inline]

Compute the sum of the first n elements of a vector.

If n is zero, this will set avg to zero and return gsl_success.

Definition at line 363 of file vector.h.


Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page