Class table (o2scl)

O2scl : Class List

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

Data class.

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:

  • A numerical index from 0 to C-1 (where C is the number of columns). For example, data can be accessed through table::get() and table::set(size_t c, size_t r,double val), or the overloaded [] operator, table[c][r].

  • A name of the column which is a string. For example, data can be accessed with table::get(string cname,

    int r) and table::set(string cname, int r, double val).

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 Vector and matrix introduction 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 for more details on acol.

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

Todo

In class table:

  • 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 c std::vector<aiter> alist; could be replaced with c std::vector<col> list and c std::map<std::string,int> tree where the map just stores the index of the the column in the list.

Subclassed by o2scl::table_units< vec_t >

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.

Parsing mathematical functions specified as strings

std::map<std::string, double> constants

The list of constants.

inline void functions_columns(std::string list)

Create new columns or recompute from a list of functions.

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.

inline void function_column(std::string function, std::string scol)

Make a column from the function specified in function and add it to the table.

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.

template<class resize_vec_t>
inline 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.

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.

Todo

In table::function_vector(): FIXME: there may be a problem with the OpenMP code if an exception is thrown in the calculator class and there is not a unique error handler for each thread.

inline double row_function(std::string function, size_t row) const

Compute a value by applying a function to a row.

inline size_t function_find_row(std::string function) const

Find a row which maximizes a function.

inline vec_t &get_column_no_const(std::string scol)

Returns a non-const reference to the column named col. \( {\cal O}(\log(C)) \).

inline void reset_list()

Set the elements of alist with the appropriate iterators from atree. \( {\cal O}(C) \).

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.

inline void make_fp_varname(std::string &s)

Ensure a variable name does not match a function or contain non-alphanumeric characters.

inline void make_unique_name(std::string &colx, std::vector<std::string> &cnames)

Make sure a name is unique.

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<aiter> alist

The list of tree iterators.

Column manipulation methods

vec_t empty_col

An empty vector for get_column()

inline aiter get_iterator(std::string lname)

Return the iterator for a column.

inline col *get_col_struct(std::string lname)

Return the column structure for a column.

inline aiter begin()

Return the beginning of the column tree.

inline aiter end()

Return the end of the column tree.

Interpolation

bool intp_set

True if the interpolation object is up-to-date.

size_t itype

Current interpolation type.

interp_base<vec_t> *si

Interpolation object.

std::string intp_colx

The last x-column interpolated.

std::string intp_coly

The last y-column interpolated.

Constructors, destructors

inline table(size_t cmaxlines = 0)

Create a new table with space for nlines<=cmaxlines.

inline virtual ~table()

Table destructor.

inline table(const table &t)

Copy constructor.

inline table &operator=(const table &t)

Copy constructor.

inline friend void swap(table &t1, table &t2)

Swap method.

Basic get and set methods

inline void set(std::string scol, size_t row, double val)

Set row row of column named col to value val . \( {\cal O}(\log(C)) \).

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

inline 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>
inline void set_row(size_t row, size_vec_t &v)

Set an entire row of data.

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.

inline double get(std::string scol, size_t row) const

Get value from row row of column named col. \( {\cal O}(\log(C)) \).

inline double get(size_t icol, size_t row) const

Get value from row row of column number icol. \( {\cal O}(1) \).

inline size_t get_ncolumns() const

Return the number of columns.

Manipulate current and maximum number of rows

inline size_t get_nlines() const

Return the number of lines.

inline void set_nlines(size_t il)

Set the number of lines.

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.

inline size_t get_maxlines()

Return the maximum number of lines before a reallocation is required.

template<class resize_vec_t>
inline 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) \).

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.

template<class resize_vec_t>
inline void get_row(size_t irow, resize_vec_t &row) const

Returns a copy of row number irow. \( {\cal O}(C) \).

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.

inline void set_nlines_auto(size_t il)

Set the number of lines, increasing the size more agressively.

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.

inline void inc_maxlines(size_t llines)

Manually increase the maximum number of lines.

inline void set_maxlines(size_t llines)

Manually set the maximum number of lines.

Note

This function will call the error handler if the argument llines is smaller than the current number of lines in the table.

Column manipulation

inline const vec_t &get_column(std::string scol) const

Returns a reference to the column named col. \( {\cal O}(\log(C)) \).

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().

inline const vec_t &operator[](size_t icol) const

Returns the column of index icol (const version). \( {\cal O}(1) \).

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.

inline const vec_t &operator[](std::string scol) const

Returns the column named scol (const version). \( {\cal O}(\log(C)) \).

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.

inline void new_column(std::string head)

Add a new column owned by the \( {\cal O}(\log(C)) \).

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.

template<class vec2_t>
inline int new_column(std::string name, size_t sz, vec2_t &v)

Add a new column by copying data from another vector.

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.

inline std::string get_column_name(size_t icol) const

Returns the name of column col \( {\cal O}(1) \).

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

inline virtual void swap_column_data(std::string scol, vec_t &v)

Swap the data in column scol with that in vector v.

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.

inline virtual void rename_column(std::string src, std::string dest)

Rename column named src to dest \( {\cal O}(C) \).

inline virtual void delete_column(std::string scol)

Delete column named scol \( {\cal O}(C) \).

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

inline std::string get_sorted_name(size_t icol) const

Returns the name of column col in sorted order. \( {\cal O}(1) \).

inline void init_column(std::string scol, double val)

Initialize all values of column named scol to val \( {\cal O}(R \log(C)) \).

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.

inline bool is_column(std::string scol) const

Return true if scol is a column in the current .

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

inline size_t lookup_column(std::string lname) const

Find the index for column named name \( {\cal O}(\log(C)) \).

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

inline 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>
inline void column_to_vector(std::string scol, resize_vec_t &v) const

Copy a column to a generic vector object.

Note

It is assumed that the vector type is one that can be resized with resize().

template<class vec2_t>
inline void copy_to_column(vec2_t &v, std::string scol)

Copy to a column from a generic vector object.

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

template<class vec2_t>
inline 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.

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.

template<class vec2_t>
inline 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)

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.

template<class vec2_t>
inline void add_table(table<vec2_t> &source)

Add a second table to this one, adding all constants, columns and data from the source.

Row maninpulation and data input

inline void new_row(size_t n)

Insert a row before row n.

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.

inline void copy_row(size_t src, size_t dest)

Copy the data in row src to row dest.

inline 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) \).

inline void delete_row(size_t irow)

Delete the row of index irow \( {\cal O}(R C) \).

inline void delete_rows_func(std::string func)

Delete all rows where func evaluates to a number greater than 0.5 \( {\cal O}(R C) \).

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

template<class vec2_t>
inline void copy_row(table<vec2_t> &src, size_t ix)

Copy row ix from table src to the end of the current table.

template<class vec2_t>
inline void copy_rows(std::string func, table<vec2_t> &dest)

Copy all rows matching a particular condition to a new table.

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.

inline 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) \).

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.

template<class vec_size_t>
inline void delete_rows_list(vec_size_t &row_list)

Delete all rows in a specified list.

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.

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

For each column, the entries in the two rows do not match if either of their absolute values are greater the absolute tolerance and their relative deviation is greater than the relative tolerance.

This function returns the number of rows deleted.

inline void delete_idadj_rows()

Delete all rows which are identical to adjacent rows.

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

inline void line_of_names(std::string newheads)

Read a new set of names from newheads.

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

table t;
t.line_of_names("position velocity acceleration");
will create three new columns with the names “position”, “velocity”, and “acceleration”.

template<class vec2_t>
inline 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.

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.

template<class vec2_t>
inline void insert_row(size_t nv, const vec2_t &v, size_t row)

Insert nv entries from v as a new row in the table at row row.

Warning

This function potentially requires reallocating and copying a portion of the entire table.

template<class vec2_t>
inline void line_of_data(const vec2_t &v)

Read a line of data and store in a new row of the table.

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.

Lookup and search methods

inline size_t ordered_lookup(std::string scol, double val) const

Look for a value in an ordered column \( {\cal O}(\log(C) \log(R)) \).

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.

inline size_t lookup(std::string scol, double val) const

Exhaustively search column col for the value val \( {\cal O}(R \log(C)) \).

inline double lookup_val(std::string scol, double val, std::string scol2) const

Search column col for the value val and return value in col2.

inline size_t lookup(int icol, double val) const

Exhaustively search column col for the value val \( {\cal O}(R \log(C)) \).

inline 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

inline void set_interp_type(size_t interp_type)

Set the base interpolation objects.

inline size_t get_interp_type() const

Get the interpolation type.

inline int set_interp_obj(std::string sx, std::string sy, interp_base<vec_t> *si2)

Set the interpolation object for strings sx and sy to the specified pointer.

inline void clear_interp_obj()

Clear the interpolation object.

inline double interp(std::string sx, double x0, std::string sy)

Interpolate value x0 from column named sx into column named sy.

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.

inline 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)

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.

inline 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)) \).

inline 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)) \).

inline 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)) \).

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

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

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.

inline 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)

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

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

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

inline 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)

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

inline 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).

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

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

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

inline 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)

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

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

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

inline 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)

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

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

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

inline 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)

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

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

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

inline 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)

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

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

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.

inline double max(std::string scol) const

Return column maximum. Makes no assumptions about ordering, \( {\cal O}(R) \).

inline double min(std::string scol) const

Return column minimum. Makes no assumptions about ordering, \( {\cal O}(R) \).

Subtable method

inline void subtable(std::string list, size_t top, size_t bottom, table<vec_t> &tnew) const

Make a subtable.

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.

Clear methods

inline void zero_table()

Zero the data entries but keep the column names and nlines fixed.

inline virtual void clear()

Clear everything.

inline virtual void clear_table()

Clear the table and the column names (but leave constants)

inline void clear_data()

Remove all of the data by setting the number of lines to zero.

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

inline void clear_constants()

CLear all constants.

Sorting methods

inline void sort_table(std::string scol)

Sort the entire table by the column scol.

Note

This function works by allocating space for an entirely new chunk of memory for the data in the table.

inline void sort_column(std::string scol)

Individually sort the column scol.

Summary method

inline virtual void summary(std::ostream *out = 0, size_t ncol = 79) const

Output a summary of the information stored.

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

Constant manipulation

inline virtual void add_constant(std::string name, double val)

Add a constant, or if the constant already exists, change its value.

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

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.

inline virtual bool is_constant(std::string name) const

Test if name is a constant.

inline virtual double get_constant(std::string name) const

Get a constant.

inline virtual size_t get_nconsts() const

Get the number of constants.

inline virtual void get_constant(size_t ix, std::string &name, double &val) const

Get a constant by index.

inline virtual void remove_constant(std::string name)

Remove a constant.

Miscellaneous methods

inline virtual void average_col_roll(std::string col_name, size_t window)

Compute the rolling average of column named col.

inline virtual void average_rows(size_t window, bool rolling = false)

Average nearby rows together over the entire table.

inline virtual int read_generic(std::istream &fin, int verbose = 0)

Clear the current table and read from a generic data file.

inline void is_valid() const

Check if the table object appears to be valid.

inline virtual const char *type()

Return the type, "table".

class col

Column structure for table [protected].

This struct is used internally by table to organize the columns and need not be instantiated by the casual end-user.

Public Functions

inline col()
inline col(const col &c)

Copy constructor.

inline col &operator=(const col &c)

Copy constructor for assignment operator.

Public Members

vec_t dat

Column of data.

int index

Column index.

Friends

inline friend void swap(col &t1, col &t2)

Swap method.