array.h File Reference


Detailed Description

Various array classes.

This file contains the alloction classes

For output of matrices rather than vectors, see matrix_out() and related functions documented in columnify.h.

Note that the classes

Todo:
Ensure that array_row works, either here or in src/ode/ode_it_solve_ts.cpp
Todo:
Document vector_sort, etc.

Definition in file array.h.

#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.

Data Structures

class  array_alloc
 A simple class to provide an allocate() function for arrays. More...
class  array_2d_alloc
 A simple class to provide an allocate() function for 2-dimensional arrays. More...
class  pointer_alloc
 A simple class to provide an allocate() function for pointers. More...
class  pointer_2d_alloc
 A simple class to provide an allocate() function for pointers. More...
class  array_reverse
 A simple class which reverses the order of an array. More...
class  array_const_reverse
 A simple class which reverses the order of an array. More...
class  array_subvector
 A simple subvector class for an array (without error checking). More...
class  array_const_subvector
 A simple subvector class for a const array (without error checking). More...
class  array_subvector_reverse
 Reverse a subvector of an array. More...
class  array_const_subvector_reverse
 Reverse a subvector of a const array. More...
class  array_row
 Extract a row of a C-style 2d-array. More...

Functions

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 data_t, class vec_t>
int vector_max (const size_t n, vec_t &data, data_t &max, size_t &ix)
 Compute the maximum of the first n elements of a vector.
template<class data_t, class vec_t>
int vector_min (const size_t n, vec_t &data, data_t &min, size_t &ix)
 Compute the minimum of the first n elements of a vector.
template<class data_t, class vec_t>
int vector_sum (const size_t n, vec_t &data, data_t &sum)
 Compute the sum of the first n elements of a vector.
template<class data_t, class vec_t>
int vector_avg (const size_t n, vec_t &data, data_t &avg)
 Compute the mean of the first n elements of a vector.
template<class data_t, class vec_t>
int vector_variance (const size_t n, vec_t &data, data_t &mean, data_t &var)
 Compute the variance of the first n elements of a vector given the mean mean.
template<class data_t, class vec_t>
int vector_reverse (const size_t n, vec_t &data)
 Reverse a vector.
template<class data_t, class vec_t>
int vector_stdev (const size_t n, vec_t &data, data_t &var)
 Compute the standard deviation of the first n elements of a vector.


Function Documentation

int vector_avg ( const size_t  n,
vec_t &  data,
data_t &  avg 
) [inline]

Compute the mean 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 563 of file array.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.

Definition at line 401 of file array.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

Definition at line 490 of file array.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

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 454 of file array.h.

int vector_sum ( const size_t  n,
vec_t &  data,
data_t &  sum 
) [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 547 of file array.h.

int vector_variance ( const size_t  n,
vec_t &  data,
data_t &  mean,
data_t &  var 
) [inline]

Compute the variance of the first n elements of a vector given the mean mean.

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

Definition at line 580 of file array.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