Classes | List of all members
o2scl::table< vec_t > Class Template Reference

Data table class. More...

#include <table.h>

Detailed Description

template<class vec_t = std::vector<double>>
class o2scl::table< vec_t >

Summary

A class to contain and manipulate several equally-sized columns of data. The purpose of this class is to provide a structure which allows one to refer to the columns using a name represented by a string. Thus for a table object named t with 3 columns (named "colx", "coly" and "colz") and three rows, one could do the following:

// Set the 1st row of column "colx" to 1.0
t.set("colx",0,1.0);
// Set the 2nd row of column "colz" to 2.0
t.set("colz",1,2.0);
// Set the 3rd row of column "coly" to 4.0
t.set("coly",2,4.0);
// This will print out 2.0
cout << t.get("colz",1) << endl;

Note that the rows are numbered starting with 0 instead of starting with 1. To output all the rows of entire column, one can use

for(size_t i=0;i<t.get_nlines();i++) {
cout << i << " " << t.get("colx",i) << endl;
}

To output all the columns of an entire row (in the following example it is the second row), labeled by their column name, one can use:

for(size_t i=0;i<t.get_ncolumns();i++) {
cout << t.get_column_name(i) << " ";
}
cout << endl;
for(size_t i=0;i<t.get_ncolumns();i++) {
cout << t.get(i,1) << " ";
}
cout << endl;

Methods are provided for interpolating columns, sorting columns, finding data points, and several other manipulations of the data.

Lookup, differentiation, integration, and interpolation
Lookup, differentiation, integration, and interpolation are automatically implemented using splines from the class interp_vec. A caching mechanism is implemented so that successive interpolations, derivative evaluations or integrations over the same two columns are fast.

Sorting
The columns are automatically sorted by name for speed, the results can be accessed from get_sorted_name(). Individual columns can be sorted (sort_column() ), or the entire table can be sorted by one column (sort_table() ).

Data representation
Each individual column is just a vector object. The columns can be referred to in one of two ways:

The columns are organized in a both a <map> and a <vector> structure so that finding a column by its index, using either of

std::string table::get_column_name(size_t index);
ubvector &table::operator[](size_t index);

takes only constant time, and finding a column by its name using either of

size_t lookup_column(std::string name) const;
const ubvector &get_column(std::string col) const;

is O(log(C)). Insertion of a column ( new_column() ) is O(log(C)), but deletion ( delete_column() ) is O(C). Adding a row of data can be either O(1) or O(C), but row insertion and deletion is slow, since the all of the rows must be shifted accordingly.

Because of the structure, this class is not suitable for the matrix manipulation.

Vector types
The type vec_t can be any vector type with operator[], size() and resize() methods. HDF5 I/O with vector types other than std::vector<double> requires a copy. See the the discussion in the sections Tensors and I/O and contiguous storage of the user's guide for more details.

Thread-safety
Generally, the member functions are only thread-safe if they are const .

I/O and command-line manipulation
When data from an object of type table is output to a file through the hdf_output() function in o2scl_hdf, the table can be manipulated on the command-line through the acol utility (see The 'acol' Command-line Utility).

There is an example for the usage of this class given in examples/ex_table.cpp.

Idea for Future:
  • Create a sort_column_names() or a function to arbitrarily rearrange the columns
  • The present structure, std::map<std::string,col,string_comp> atree and std::vector<aiter> alist; could be replaced with std::vector<col> list and std::map<std::string,int> tree where the map just stores the index of the the column in the list.
  • Rewrite check_synchro into a full is_valid()-like sanity check

Definition at line 49 of file table.h.

Classes

class  col
 Column structure for table [protected]. More...
 

Public Member Functions

Constructors, destructors
 table (size_t cmaxlines=0)
 Create a new table with space for nlines<=cmaxlines.
 
virtual ~table ()
 Table destructor.
 
 table (const table &t)
 Copy constructor.
 
tableoperator= (const table &t)
 Copy constructor.
 
Basic get and set methods
void set (std::string scol, size_t row, double val)
 Set row row of column named col to value val . $ {\cal O}(\log(C)) $. More...
 
void set (size_t icol, size_t row, double val)
 Set row row of column number icol to value val . $ {\cal O}(1) $.
 
template<class size_vec_t >
void set_row (size_t row, size_vec_t &v)
 Set an entire row of data. More...
 
double get (std::string scol, size_t row) const
 Get value from row row of column named col. $ {\cal O}(\log(C)) $.
 
double get (size_t icol, size_t row) const
 Get value from row row of column number icol. $ {\cal O}(1) $.
 
size_t get_ncolumns () const
 Return the number of columns.
 
Manipulate current and maximum number of rows
size_t get_nlines () const
 Return the number of lines.
 
void set_nlines (size_t il)
 Set the number of lines. More...
 
size_t get_maxlines ()
 Return the maximum number of lines before a reallocation is required.
 
template<class resize_vec_t >
void get_row (std::string scol, double val, resize_vec_t &row) const
 Returns a copy of the row with value val in column col. $ {\cal O}(R C) $. More...
 
template<class resize_vec_t >
void get_row (size_t irow, resize_vec_t &row) const
 Returns a copy of row number irow. $ {\cal O}(C) $. More...
 
void set_nlines_auto (size_t il)
 Set the number of lines, increasing the size more agressively. More...
 
void inc_maxlines (size_t llines)
 Manually increase the maximum number of lines.
 
void set_maxlines (size_t llines)
 Manually set the maximum number of lines. More...
 
Column manipulation
const vec_t & get_column (std::string scol) const
 Returns a reference to the column named col. $ {\cal O}(\log(C)) $. More...
 
const vec_t & operator[] (size_t icol) const
 Returns the column of index icol (const version). $ {\cal O}(1) $. More...
 
const vec_t & operator[] (std::string scol) const
 Returns the column named scol (const version). $ {\cal O}(\log(C)) $. More...
 
void new_column (std::string head)
 Add a new column owned by the table $ {\cal O}(\log(C)) $. More...
 
template<class vec2_t >
int new_column (std::string name, size_t sz, vec2_t &v)
 Add a new column by copying data from another vector. More...
 
std::string get_column_name (size_t icol) const
 Returns the name of column col $ {\cal O}(1) $. More...
 
virtual void swap_column_data (std::string scol, vec_t &v)
 Swap the data in column scol with that in vector v. More...
 
virtual void rename_column (std::string src, std::string dest)
 Rename column named src to dest $ {\cal O}(C) $.
 
virtual void delete_column (std::string scol)
 Delete column named scol $ {\cal O}(C) $. More...
 
std::string get_sorted_name (size_t icol) const
 Returns the name of column col in sorted order. $ {\cal O}(1) $.
 
void init_column (std::string scol, double val)
 Initialize all values of column named scol to val $ {\cal O}(R \log(C)) $. More...
 
bool is_column (std::string scol) const
 Return true if scol is a column in the current table. More...
 
size_t lookup_column (std::string lname) const
 Find the index for column named name $ {\cal O}(\log(C)) $. More...
 
virtual void copy_column (std::string src, std::string dest)
 Copy data from column named src to column named dest, creating a new column if necessary $ {\cal O}(R \log(C)) $.
 
template<class resize_vec_t >
void column_to_vector (std::string scol, resize_vec_t &v) const
 Copy a column to a generic vector object. More...
 
template<class vec2_t >
void copy_to_column (vec2_t &v, std::string scol)
 Copy to a column from a generic vector object. More...
 
template<class vec2_t >
void add_col_from_table (table< vec2_t > &source, std::string src_index, std::string src_col, std::string dest_index, std::string dest_col="")
 Insert a column from a separate table, interpolating it into a new column. More...
 
template<class vec2_t >
void insert_table (table< vec2_t > &source, std::string src_index, bool allow_extrap=true, std::string dest_index="")
 Insert columns from a source table into the new table by interpolation (or extrapolation) More...
 
Row maninpulation and data input
void new_row (size_t n)
 Insert a row before row n. More...
 
void copy_row (size_t src, size_t dest)
 Copy the data in row src to row dest. More...
 
void delete_row (std::string scol, double val)
 Delete the row with the entry closest to the value val in column scol $ {\cal O}(R C) $.
 
void delete_row (size_t irow)
 Delete the row of index irow $ {\cal O}(R C) $.
 
void delete_rows_func (std::string func)
 Delete all rows where func evaluates to a number greater than 0.5 $ {\cal O}(R C) $. More...
 
template<class vec2_t >
void copy_rows (std::string func, table< vec2_t > &dest)
 Copy all rows matching a particular condition to a new table. More...
 
void delete_rows_ends (size_t row_start, size_t row_end)
 Delete all rows between row_start and row_end $ {\cal O}(R C) $. More...
 
template<class vec_size_t >
void delete_rows_list (vec_size_t &row_list)
 Delete all rows in a specified list. More...
 
size_t delete_rows_tolerance (double tol_rel=1.0e-12, double tol_abs=1.0e-20, int verbose=0)
 Exaustively search for groups of rows which match within a specified tolerance and remove all but one of each group. More...
 
void delete_idadj_rows ()
 Delete all rows which are identical to adjacent rows. More...
 
void line_of_names (std::string newheads)
 Read a new set of names from newheads. More...
 
template<class vec2_t >
void line_of_data (size_t nv, const vec2_t &v)
 Read a line of data from the first nv entries in a vector and store as a new row in the table. More...
 
template<class vec2_t >
void line_of_data (const vec2_t &v)
 Read a line of data and store in a new row of the table. More...
 
Lookup and search methods
size_t ordered_lookup (std::string scol, double val) const
 Look for a value in an ordered column $ {\cal O}(\log(C) \log(R)) $. More...
 
size_t lookup (std::string scol, double val) const
 Exhaustively search column col for the value val $ {\cal O}(R \log(C)) $.
 
double lookup_val (std::string scol, double val, std::string scol2) const
 Search column col for the value val and return value in col2.
 
size_t lookup (int icol, double val) const
 Exhaustively search column col for the value val $ {\cal O}(R \log(C)) $.
 
size_t mlookup (std::string scol, double val, std::vector< size_t > &results, double threshold=0.0) const
 Exhaustively search column col for many occurences of val $ {\cal O}(R \log(C)) $.
 
Interpolation, differentiation, integration, max, min
void set_interp_type (size_t interp_type)
 Set the base interpolation objects.
 
size_t get_interp_type () const
 Get the interpolation type.
 
double interp (std::string sx, double x0, std::string sy)
 Interpolate value x0 from column named sx into column named sy. More...
 
double interp_const (std::string sx, double x0, std::string sy) const
 Interpolate value x0 from column named sx into column named sy (const version) More...
 
double interp (size_t ix, double x0, size_t iy)
 Interpolate value x0 from column with index ix into column with index iy $ {\cal O}(\log(R)) $.
 
double interp_const (size_t ix, double x0, size_t iy) const
 Interpolate value x0 from column with index ix into column with index iy $ {\cal O}(\log(R)) $.
 
void deriv (std::string x, std::string y, std::string yp)
 Make a new column named yp which is the derivative $ y^{\prime}(x) $ formed from columns named x and y $ {\cal O}(R \log(C)) $. More...
 
double deriv (std::string sx, double x0, std::string sy)
 Compute the first derivative of the function defined by x-values stored in column named sx and y-values stored in column named sy at the value x0. More...
 
double deriv_const (std::string sx, double x0, std::string sy) const
 Compute the first derivative of the function defined by x-values stored in column named sx and y-values stored in column named sy at the value x0 (const version) More...
 
double deriv (size_t ix, double x0, size_t iy)
 Compute the first derivative of the function defined by x-values stored in column with index ix and y-values stored in column with index iy at the value x0. More...
 
double deriv_const (size_t ix, double x0, size_t iy) const
 Compute the first derivative of the function defined by x-values stored in column with index ix and y-values stored in column with index iy at the value x0 (const version) More...
 
void deriv2 (std::string x, std::string y, std::string yp)
 Create a new column named yp which is equal to the second derivative of the function defined by x-values stored in column named x and y-values stored in column named y, i.e. $ y^{\prime \prime}(x) $ - O(log(C)*R). More...
 
double deriv2 (std::string sx, double x0, std::string sy)
 Compute the second derivative of the function defined by x-values stored in column named sx and y-values stored in column named sy at the value x0. More...
 
double deriv2_const (std::string sx, double x0, std::string sy) const
 The Compute the second derivative of the function defined by x-values stored in column named sx and y-values stored in column named sy at the value x0 (const version) More...
 
double deriv2 (size_t ix, double x0, size_t iy)
 Compute the second derivative of the function defined by x-values stored in column with index ix and y-values stored in column with index iy at the value x0. More...
 
double deriv2_const (size_t ix, double x0, size_t iy) const
 Compute the second derivative of the function defined by x-values stored in column with index ix and y-values stored in column with index iy at the value x0 (const version) More...
 
double integ (std::string sx, double x1, double x2, std::string sy)
 Compute the integral of the function defined by x-values stored in column named sx and y-values stored in column named sy between the values x1 and x2. More...
 
double integ_const (std::string sx, double x1, double x2, std::string sy) const
 Compute the integral of the function defined by x-values stored in column named sx and y-values stored in column named sy between the values x1 and x2 (const version) More...
 
double integ (size_t ix, double x1, double x2, size_t iy)
 Compute the integral of the function defined by x-values stored in column with index ix and y-values stored in column with index iy between the values x1 and x2. More...
 
double integ_const (size_t ix, double x1, double x2, size_t iy) const
 Compute the integral of the function defined by x-values stored in column with index ix and y-values stored in column with index iy between the values x1 and x2 (const version) More...
 
void integ (std::string x, std::string y, std::string ynew)
 Create a new column named ynew which is equal to the integral of the function defined by x-values stored in column named x and y-values stored in column named y. More...
 
double max (std::string scol) const
 Return column maximum. Makes no assumptions about ordering, $ {\cal O}(R) $.
 
double min (std::string scol) const
 Return column minimum. Makes no assumptions about ordering, $ {\cal O}(R) $.
 
Subtable method
void subtable (std::string list, size_t top, size_t bottom, table< vec_t > &tnew) const
 Make a subtable. More...
 
Clear methods
void zero_table ()
 Zero the data entries but keep the column names and nlines fixed.
 
virtual void clear ()
 Clear everything.
 
virtual void clear_table ()
 Clear the table and the column names (but leave constants)
 
void clear_data ()
 Remove all of the data by setting the number of lines to zero. More...
 
void clear_constants ()
 CLear all constants.
 
Sorting methods
void sort_table (std::string scol)
 Sort the entire table by the column scol. More...
 
void sort_column (std::string scol)
 Individually sort the column scol.
 
Summary method
virtual void summary (std::ostream *out, size_t ncol=79) const
 Output a summary of the information stored. More...
 
Constant manipulation
virtual void add_constant (std::string name, double val)
 Add a constant, or if the constant already exists, change its value.
 
virtual int set_constant (std::string name, double val, bool err_on_notfound=true)
 Set a constant equal to a value, but don't add it if not already present. More...
 
virtual bool is_constant (std::string name) const
 Test if name is a constant.
 
virtual double get_constant (std::string name) const
 Get a constant.
 
virtual size_t get_nconsts () const
 Get the number of constants.
 
virtual void get_constant (size_t ix, std::string &name, double &val) const
 Get a constant by index.
 
virtual void remove_constant (std::string name)
 Remove a constant.
 
Miscellaneous methods
virtual int read_generic (std::istream &fin, int verbose=0)
 Clear the current table and read from a generic data file.
 
void check_synchro () const
 Check if the tree and list are properly synchronized.
 
void is_valid () const
 Check if the table object appears to be valid.
 
virtual const char * type ()
 Return the type, "table".
 

Protected Types

Iterator types
typedef std::map< std::string, col, std::greater< std::string > >::iterator aiter
 Map iterator type.
 
typedef std::map< std::string, col, std::greater< std::string > >::const_iterator aciter
 Const map iterator type.
 
typedef std::vector< aiter >::iterator aviter
 Vector iterator type.
 

Protected Attributes

Actual data
size_t maxlines
 The size of allocated memory.
 
size_t nlines
 The size of presently used memory.
 
std::map< std::string, col, std::greater< std::string > > atree
 The tree of columns.
 
std::vector< aiteralist
 The list of tree iterators.
 
Interpolation
bool intp_set
 True if the interpolation object is up-to-date.
 
size_t itype
 Current interpolation type.
 
interp_vec< vec_t > * si
 Interpolation object.
 
std::string intp_colx
 The last x-column interpolated.
 
std::string intp_coly
 The last y-column interpolated.
 

Parsing mathematical functions specified as strings

template<typename vecf_t >
class matrix_view_table
 
template<typename vecf_t >
class matrix_view_table_transpose
 
void o2scl_hdf::hdf_output (o2scl_hdf::hdf_file &hf, table<> &t, std::string name)
 
template<class vecf_t >
void o2scl_hdf::hdf_input (o2scl_hdf::hdf_file &hf, table< vecf_t > &t, std::string name)
 
void o2scl_hdf::hdf_output_data (o2scl_hdf::hdf_file &hf, table<> &t)
 
template<class vecf_t >
void o2scl_hdf::hdf_input_data (o2scl_hdf::hdf_file &hf, table< vecf_t > &t)
 
std::map< std::string, double > constants
 The list of constants.
 
void functions_columns (std::string list)
 Create new columns or recompute from a list of functions. More...
 
void function_column (std::string function, std::string scol)
 Make a column from the function specified in function and add it to the table. More...
 
template<class resize_vec_t >
int function_vector (std::string function, resize_vec_t &vec, bool throw_on_err=true)
 Compute a column from a function specified in a string. More...
 
double row_function (std::string function, size_t row) const
 Compute a value by applying a function to a row.
 
size_t function_find_row (std::string function) const
 Find a row which maximizes a function.
 
vec_t & get_column_no_const (std::string scol)
 Returns a non-const reference to the column named col. $ {\cal O}(\log(C)) $.
 
void reset_list ()
 Set the elements of alist with the appropriate iterators from atree. $ {\cal O}(C) $. More...
 
void make_fp_varname (std::string &s)
 Ensure a variable name does not match a function or contain non-alphanumeric characters.
 
void make_unique_name (std::string &colx, std::vector< std::string > &cnames)
 Make sure a name is unique.
 

Column manipulation methods

vec_t empty_col
 An empty vector for get_column()
 
aiter get_iterator (std::string lname)
 Return the iterator for a column.
 
colget_col_struct (std::string lname)
 Return the column structure for a column.
 
aiter begin ()
 Return the beginning of the column tree.
 
aiter end ()
 Return the end of the column tree.
 

Member Function Documentation

◆ add_col_from_table()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::add_col_from_table ( table< vec2_t > &  source,
std::string  src_index,
std::string  src_col,
std::string  dest_index,
std::string  dest_col = "" 
)
inline

Given a pair of columns ( src_index, src_col ) in a separate table (source), this creates a new column in the present table named src_col which interpolates loc_index into src_index. The interpolation objects from the source table will be used. If there is already a column in the present table named src_col, then this will fail.

Definition at line 1047 of file table.h.

◆ clear_data()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::clear_data ( )
inline

This leaves the column names intact and does not remove the constants.

Definition at line 2311 of file table.h.

◆ column_to_vector()

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
void o2scl::table< vec_t >::column_to_vector ( std::string  scol,
resize_vec_t &  v 
) const
inline
Note
It is assumed that the vector type is one that can be resized with resize().

Definition at line 1015 of file table.h.

◆ copy_row()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::copy_row ( size_t  src,
size_t  dest 
)
inline

Definition at line 1178 of file table.h.

◆ copy_rows()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::copy_rows ( std::string  func,
table< vec2_t > &  dest 
)
inline

This function begins by ensuring that all columns in the current table are present in dest, creating new columns in dest if necessary. It then copies all rows where func evaluates to a number greater than 0.5 to table dest by adding rows at the end of the table.

Definition at line 1269 of file table.h.

◆ copy_to_column()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::copy_to_column ( vec2_t &  v,
std::string  scol 
)
inline

The type vec2_t can be any type with an operator[] method.

Definition at line 1029 of file table.h.

◆ delete_column()

template<class vec_t = std::vector<double>>
virtual void o2scl::table< vec_t >::delete_column ( std::string  scol)
inlinevirtual

This is slow because the iterators in alist are mangled and we have to call reset_list() to get them back.

Definition at line 877 of file table.h.

◆ delete_idadj_rows()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::delete_idadj_rows ( )
inline

This function does silently does nothing if there are less than 2 rows in the table.

Definition at line 1431 of file table.h.

◆ delete_rows_ends()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::delete_rows_ends ( size_t  row_start,
size_t  row_end 
)
inline

If row_start is less or equal to row_end, then all rows beginnning with row_start and ending with row_end are deleted (inclusive). If row_start is greater than row_end, then rows from the start of the table until row_end are deleted, as well as all rows from row_start through the end of the table.

If either row_start or row_end are beyond the end of the table (greater than or equal to the value given by get_nlines() ), an exception is thrown.

Definition at line 1310 of file table.h.

◆ delete_rows_func()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::delete_rows_func ( std::string  func)
inline

If no rows match the delete condition, this function silently performs no changes to the table.

Definition at line 1234 of file table.h.

◆ delete_rows_list()

template<class vec_t = std::vector<double>>
template<class vec_size_t >
void o2scl::table< vec_t >::delete_rows_list ( vec_size_t &  row_list)
inline

Given a list of rows in row_list, this function deletes all of the specified rows. If a row beyond the end of the table is in the list, the error handler is called.

Note
This function will proceed normally if a row is specified more than once in row_list.

Definition at line 1343 of file table.h.

◆ delete_rows_tolerance()

template<class vec_t = std::vector<double>>
size_t o2scl::table< vec_t >::delete_rows_tolerance ( double  tol_rel = 1.0e-12,
double  tol_abs = 1.0e-20,
int  verbose = 0 
)
inline

This function returns the number of rows deleted.

Definition at line 1384 of file table.h.

◆ deriv() [1/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv ( size_t  ix,
double  x0,
size_t  iy 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1868 of file table.h.

◆ deriv() [2/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv ( std::string  sx,
double  x0,
std::string  sy 
)
inline

This function is O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1805 of file table.h.

◆ deriv() [3/3]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::deriv ( std::string  x,
std::string  y,
std::string  yp 
)
inline

If the column yp is not already in the table it is automatically created.

Definition at line 1770 of file table.h.

◆ deriv2() [1/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2 ( size_t  ix,
double  x0,
size_t  iy 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1989 of file table.h.

◆ deriv2() [2/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2 ( std::string  sx,
double  x0,
std::string  sy 
)
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1926 of file table.h.

◆ deriv2() [3/3]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::deriv2 ( std::string  x,
std::string  y,
std::string  yp 
)
inline

If the column yp is not already in the table it is automatically created.

Definition at line 1892 of file table.h.

◆ deriv2_const() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2_const ( size_t  ix,
double  x0,
size_t  iy 
) const
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 2000 of file table.h.

◆ deriv2_const() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv2_const ( std::string  sx,
double  x0,
std::string  sy 
) const
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1963 of file table.h.

◆ deriv_const() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv_const ( size_t  ix,
double  x0,
size_t  iy 
) const
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 1879 of file table.h.

◆ deriv_const() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::deriv_const ( std::string  sx,
double  x0,
std::string  sy 
) const
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 1842 of file table.h.

◆ function_column()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::function_column ( std::string  function,
std::string  scol 
)
inline

If a column named scol already exists, the data already present is overwritten with the result. Otherwise, a new column is created and filled with the result.

Definition at line 2789 of file table.h.

◆ function_vector()

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
int o2scl::table< vec_t >::function_vector ( std::string  function,
resize_vec_t &  vec,
bool  throw_on_err = true 
)
inline

The type resize_vec_t must have resize() and size() methods. If vec does not have enough space to hold the number of entries given by get_nlines(), it is resized.

Definition at line 2823 of file table.h.

◆ functions_columns()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::functions_columns ( std::string  list)
inline

The list should be a space-delimited list of entries of the form name=function where name is the column name and function the function specifing the values for the column. If a column named name is already present, it is overwritten. Otherwise, a new column is created.

Definition at line 2725 of file table.h.

◆ get_column()

template<class vec_t = std::vector<double>>
const vec_t& o2scl::table< vec_t >::get_column ( std::string  scol) const
inline

Note also that the vector object returned by this function may be larger than the number of rows in the table, as the table resizes these vectors automatically to make room for more data. To get the number of valid data entries in the object, use get_nlines() instead of get_column().size().

Definition at line 672 of file table.h.

◆ get_column_name()

template<class vec_t = std::vector<double>>
std::string o2scl::table< vec_t >::get_column_name ( size_t  icol) const
inline

This will throw if icol is larger than or equal to the number of columns.

Definition at line 819 of file table.h.

◆ get_row() [1/2]

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
void o2scl::table< vec_t >::get_row ( size_t  irow,
resize_vec_t &  row 
) const
inline

This function returns a copy of row with index irow, where irow ranges from 0 to get_nlines()-1, inclusive.

If the object row previously contains any data, it will be lost.

The type resize_vec_t must be a type which has size() and resize() methods.

Definition at line 534 of file table.h.

◆ get_row() [2/2]

template<class vec_t = std::vector<double>>
template<class resize_vec_t >
void o2scl::table< vec_t >::get_row ( std::string  scol,
double  val,
resize_vec_t &  row 
) const
inline

This function searches the entire table for the row which has the entry in column col which is closest to the value val, and copies that row to the vector row.

If the object row previously contains any data, it will be lost.

The type resize_vec_t must be a type which has size() and resize() methods.

Definition at line 508 of file table.h.

◆ init_column()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::init_column ( std::string  scol,
double  val 
)
inline

Note that this does not initialize elements beyond nlines so that if the number of rows is increased afterwards, the new rows will have uninitialized values.

Definition at line 931 of file table.h.

◆ insert_table()

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::insert_table ( table< vec2_t > &  source,
std::string  src_index,
bool  allow_extrap = true,
std::string  dest_index = "" 
)
inline

This takes all of the columns in source, and adds them into the current table using interpolation, using the columns src_index and dest_index as the independent variable. The column named src_index is the column of the independent variable in source and the column named dest_index is the column of the independent variable in the current table. If dest_index is empty (the default) then the names in the two tables are taken to be the same.

If necessary, columns are created in the current table for the dependent variable columns in source. Columns in the current table which do not correspond to dependent variable columns in source are left unchanged.

If allow_extrap is false, then extrapolation is not allowed, and rows in the current table which have values of the independent variable which are outside the source table are unmodified.

If a column for a dependent variable in source has the same name as dest_index, then it is ignored and not inserted into the current table.

If the column named src_index cannot be found in source or the column names dest_index cannot be found in the current table, then the error handler is called.

If the allow_extrap is false and either the minimum or maximum values of the column named src_index in the source table are not finite, then the error handler is called.

Definition at line 1099 of file table.h.

◆ integ() [1/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ ( size_t  ix,
double  x1,
double  x2,
size_t  iy 
)
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 2077 of file table.h.

◆ integ() [2/3]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ ( std::string  sx,
double  x1,
double  x2,
std::string  sy 
)
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 2011 of file table.h.

◆ integ() [3/3]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::integ ( std::string  x,
std::string  y,
std::string  ynew 
)
inline

This function is O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

If the column ynew is not already in the table it is automatically created.

Definition at line 2106 of file table.h.

◆ integ_const() [1/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ_const ( size_t  ix,
double  x1,
double  x2,
size_t  iy 
) const
inline

O(log(R)) but can be as bad as O(R) if the relevant columns are not well ordered.

Definition at line 2090 of file table.h.

◆ integ_const() [2/2]

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::integ_const ( std::string  sx,
double  x1,
double  x2,
std::string  sy 
) const
inline

O(log(C)*log(R)) but can be as bad as O(log(C)*R) if the relevant columns are not well ordered.

Definition at line 2050 of file table.h.

◆ interp()

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::interp ( std::string  sx,
double  x0,
std::string  sy 
)
inline

This function is $ {\cal O}(\log(R) \log(C)) $ but can be as bad as $ {\cal O}(C \log(R) $ if the relevant columns are not well ordered.

Definition at line 1694 of file table.h.

◆ interp_const()

template<class vec_t = std::vector<double>>
double o2scl::table< vec_t >::interp_const ( std::string  sx,
double  x0,
std::string  sy 
) const
inline

This function is $ {\cal O}(\log(R) \log(C)) $ but can be as bad as $ {\cal O}(C \log(R) $ if the relevant columns are not well ordered.

Definition at line 1729 of file table.h.

◆ is_column()

template<class vec_t = std::vector<double>>
bool o2scl::table< vec_t >::is_column ( std::string  scol) const
inline

This function does not call the error handler if the column is not found, but just silently returns false.

Definition at line 962 of file table.h.

◆ line_of_data() [1/2]

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::line_of_data ( const vec2_t &  v)
inline

The type vec2_t can be any type with an operator[] method. Note that this function does not verify that the vector size is equal to the number of columns, so some of the columns may be uninitialized in the new row which is created.

Definition at line 1524 of file table.h.

◆ line_of_data() [2/2]

template<class vec_t = std::vector<double>>
template<class vec2_t >
void o2scl::table< vec_t >::line_of_data ( size_t  nv,
const vec2_t &  v 
)
inline

The type vec2_t can be any type with an operator[] method. Note that this function does not verify that nv is equal to the number of columns, so some of the columns may be uninitialized in the new row which is created.

Similar to std::vector's push_back() method, this function now internally increases the maximum table size geometrically to help avoid excessive memory rearrangements.

Definition at line 1492 of file table.h.

◆ line_of_names()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::line_of_names ( std::string  newheads)
inline

This function reads a set of white-space delimited column names from the string newheads, and creates a new column for each name which is specified.

For example

t.line_of_names("position velocity acceleration");

will create three new columns with the names "position", "velocity", and "acceleration".

Definition at line 1462 of file table.h.

◆ lookup_column()

template<class vec_t = std::vector<double>>
size_t o2scl::table< vec_t >::lookup_column ( std::string  lname) const
inline

If the column is not present, this function calls the error handler.

Definition at line 974 of file table.h.

◆ new_column() [1/2]

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::new_column ( std::string  head)
inline
Note
This function does not set all the column entries to zero in the case that a new column is added to a table which already contains data.

Definition at line 751 of file table.h.

◆ new_column() [2/2]

template<class vec_t = std::vector<double>>
template<class vec2_t >
int o2scl::table< vec_t >::new_column ( std::string  name,
size_t  sz,
vec2_t &  v 
)
inline

This function copies sz elements of vector v into the table in a new column named name. If sz is larger than the current number of lines (as given, e.g. in get_nlines() ), then only the first part of the vector v is copied, up to the current number of lines.

This function calls the error handler if sz is zero.

The type vec2_t can be any type with an operator[] method.

Definition at line 791 of file table.h.

◆ new_row()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::new_row ( size_t  n)
inline

Acceptable values for n are between 0 and get_nlines() inclusive, with the maximum value denoting the addition of a row after the last row presently in the table.

Definition at line 1155 of file table.h.

◆ operator[]() [1/2]

template<class vec_t = std::vector<double>>
const vec_t& o2scl::table< vec_t >::operator[] ( size_t  icol) const
inline

Note that several of the methods require reallocation of memory and refereces previously returned by this function will be incorrect.

Note also that the vector object returned by this function may be larger than the number of rows in the table, as the table resizes these vectors automatically to make room for more data. To get the number of valid data entries in the object, use get_nlines() instead of operator[].size().

Unlike set(), this function will not automatically result in an increase in the size of the table if the user attempts to set an element beyond the current column range.

This function will throw an exception if icol is out of range unless O2SCL_NO_RANGE_CHECK is defined.

Definition at line 703 of file table.h.

◆ operator[]() [2/2]

template<class vec_t = std::vector<double>>
const vec_t& o2scl::table< vec_t >::operator[] ( std::string  scol) const
inline

Note that several of the methods require reallocation of memory and refereces previously returned by this function will be incorrect.

Note also that the vector object returned by this function may be larger than the number of rows in the table, as the table resizes these vectors automatically to make room for more data. To get the number of valid data entries in the object, use get_nlines() instead of operator[].size().

This function will throw an exception if icol is out of range unless O2SCL_NO_RANGE_CHECK is defined.

Definition at line 733 of file table.h.

◆ ordered_lookup()

template<class vec_t = std::vector<double>>
size_t o2scl::table< vec_t >::ordered_lookup ( std::string  scol,
double  val 
) const
inline

This uses the function search_vec::ordered_lookup(), which offers caching and assumes the vector is monotonic. If you don't have monotonic data, you can still use the table::lookup() function, which is more general.

Definition at line 1542 of file table.h.

◆ reset_list()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::reset_list ( )
inlineprotected

Generally, the end-user shouldn't need this method. It is only used in delete_column() to rearrange the list when a column is deleted from the tree.

Definition at line 2954 of file table.h.

◆ set()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set ( std::string  scol,
size_t  row,
double  val 
)
inline

This function calls the error handler if the row is beyond the end of the table or if the specified column is not found.

Definition at line 317 of file table.h.

◆ set_constant()

template<class vec_t = std::vector<double>>
virtual int o2scl::table< vec_t >::set_constant ( std::string  name,
double  val,
bool  err_on_notfound = true 
)
inlinevirtual

If err_on_notfound is true (the default), then this function throws an exception if a constant with name name is not found. If err_on_notfound is false, then if a constant with name name is not found this function just silently returns o2scl::exc_enotfound.

Definition at line 2473 of file table.h.

◆ set_maxlines()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set_maxlines ( size_t  llines)
inline
Note
This function will call the error handler if the argument llines is smaller than the current number of lines in the table.

Definition at line 621 of file table.h.

◆ set_nlines()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set_nlines ( size_t  il)
inline

This function is stingy about increasing the table memory space and will only increase it enough to fit il lines. Using it in succession to slowly increase the number of lines in the table is likely to be inefficient compared to set_nlines_auto() in this case.

Definition at line 470 of file table.h.

◆ set_nlines_auto()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::set_nlines_auto ( size_t  il)
inline

This function is like set_nlines(), but doubles the maximum column size if an increase in the maximum size is required instead of simply making enough room for the current number of lines. This function is used internally by set() to ensure that the cost of setting lines in sequence is linear and not quadratic.

Definition at line 562 of file table.h.

◆ set_row()

template<class vec_t = std::vector<double>>
template<class size_vec_t >
void o2scl::table< vec_t >::set_row ( size_t  row,
size_vec_t &  v 
)
inline

This function goes through v copying data until it runs out of columns in the table or it runs out of entries in v, whichever comes first.

The type size_vec_t must be a type which has a size() method.

Definition at line 393 of file table.h.

◆ sort_table()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::sort_table ( std::string  scol)
inline
Note
This function works by allocating space for an entirely new chunk of memory for the data in the table.

Definition at line 2336 of file table.h.

◆ subtable()

template<class vec_t = std::vector<double>>
void o2scl::table< vec_t >::subtable ( std::string  list,
size_t  top,
size_t  bottom,
table< vec_t > &  tnew 
) const
inline

Uses the columns specified in list from the row top to the row of index bottom to generate a new table which is a copy of part of the original.

Definition at line 2207 of file table.h.

◆ summary()

template<class vec_t = std::vector<double>>
virtual void o2scl::table< vec_t >::summary ( std::ostream *  out,
size_t  ncol = 79 
) const
inlinevirtual

Outputs the number of constants, the number of columns, a list of the column names, and the number of lines of data.

Definition at line 2398 of file table.h.

◆ swap_column_data()

template<class vec_t = std::vector<double>>
virtual void o2scl::table< vec_t >::swap_column_data ( std::string  scol,
vec_t &  v 
)
inlinevirtual

This requires that the column v must have the correct size, that returned by get_maxlines().

This function is useful, in part, because if objects of type vec_t have std::move defined, then the swap doesn't require a full copy.

Definition at line 838 of file table.h.


The documentation for this class was generated from the following file:
o2scl::table::lookup_column
size_t lookup_column(std::string lname) const
Find the index for column named name .
Definition: table.h:974
o2scl::table::table
table(size_t cmaxlines=0)
Create a new table with space for nlines<=cmaxlines.
Definition: table.h:199
o2scl::table::get_column
const vec_t & get_column(std::string scol) const
Returns a reference to the column named col. .
Definition: table.h:672
o2scl::table::operator[]
const vec_t & operator[](size_t icol) const
Returns the column of index icol (const version). .
Definition: table.h:703
o2scl::table::get_column_name
std::string get_column_name(size_t icol) const
Returns the name of column col .
Definition: table.h:819

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).