cloudy
trunk
|
#include <container_classes.h>
Public Types | |
typedef random_access_iterator_tag | iterator_category |
typedef T | value_type |
typedef T & | reference |
typedef const T & | const_reference |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef pntr< T, lgBC > | iterator |
typedef const_pntr< T, lgBC > | const_iterator |
typedef n_pointer< T, d-1, ALLOC, lgBC > | indexed_type |
typedef const_n_pointer< T, d-1, ALLOC, lgBC > | const_indexed_type |
Private Member Functions | |
void | p_clear0 () |
void | p_clear1 () |
void | p_setupArray (size_type n1[], size_type n2[], const tree_vec *g, size_type l) |
iterator | p_iterator (size_type i1, size_type i2) const |
iterator | p_iterator_bc (size_type i1, size_type i2) const |
iterator | p_iterator (size_type i1, size_type i2, size_type i3) const |
iterator | p_iterator_bc (size_type i1, size_type i2, size_type i3) const |
iterator | p_iterator (size_type i1, size_type i2, size_type i3, size_type i4) const |
iterator | p_iterator_bc (size_type i1, size_type i2, size_type i3, size_type i4) const |
iterator | p_iterator (size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const |
iterator | p_iterator_bc (size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const |
iterator | p_iterator (size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6) const |
iterator | p_iterator_bc (size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6) const |
Private Attributes | |
multi_geom< d, ALLOC > | p_g |
T ** | p_psl [d-1] |
valarray< T > | p_dsl |
T * | p_ptr |
T ** | p_ptr2 |
T *** | p_ptr3 |
T **** | p_ptr4 |
T ***** | p_ptr5 |
T ****** | p_ptr6 |
Static Private Attributes | |
static const size_type | npos = static_cast<size_type>(-1) |
multi_arr: generic class for allocating multidimensional arrays. A typical example of its use could be:
multi_arr<double,3> arr; // define a placeholder for the array // the first argument is the type of data it holds // the second argument is the number of dimensions // (between 2 and 6) arr.alloc(3,4,2); // this will allocate a 3x4x2 block of doubles // memory will be allocated as a valarray, so each // element will be initialized to T() -- this means // that even POD types like double with be zeroed multi_arr<double,3> arr(3,4,2); // shorthand for the above
The following is an alternative way of allocating the array. It is very similar to the pre-multi_arr way of allocating arrays. In ARPA_TYPE arrays this will help you save memory since only the data elements that are really needed will be allocated. In C_TYPE allocation, the smallest rectangular block will be allocated that can hold all the data. This will use more memory in return for somewhat improved CPU speed. Tests carried out in 2007 showed that the speed advantage of C_TYPE arrays was only 1 to 2 percent. Hence the memory savings were deemed more important and ARPA_TYPE arrays were made the default. However, C_TYPE arrays are guaranteed to be compatible with C code, so these should be used if they are meant to be passed on to C library routines. The example below allocates a triangular matrix.
arr.reserve(3); for( int i=0, i < 3; ++i ) { arr.reserve( i, i+1 ); // note that size does not need to be constant! for( int j=0, j < i+1; ++j ) arr.reserve( i, j, j+1 ); } arr.alloc();
these are plausible ways to use the multi_arr class:
arr.invalidate(); // this will set float or double arrays to all SNaN // it will set any other type array to all 0xff bytes. arr.zero(); // this will set the array to all zero arr[0][0][0] = 1.; arr[0][0][1] = 2.; double x = arr[0][0][0]*arr[0][0][1]; arr.state_do(io,lgRead); // this will write/read the array to/from a state file // depending on the boolean flag lgRead; io should point to a // file that is already opened for binary writing/reading // the file will remain open after access. this allows you to // use state_do() for several arrays in a row multi_arr<double,2,C_TYPE> a(10,10); // allocate C_TYPE array C_library_routine( a.data(), ... ); // and call C library routine with it arr.clear(); // this will deallocate the array // the destructor will also automatically deallocate
the multi_arr class comes with iterators that allow you to speed up memory access even further. using iterators as shown below will generally speed up the code significantly since it avoids calculating the array index over and over inside the body of the loop. especially in tight loops over arrays with high dimension this can become a significant overhead! a const_iterator is also supplied for read-only access, but no reverse_iterators. you can define and initialize an iterator as follows
multi_arr<double,3>::iterator p = arr.begin(n,k);
the notation multi_arr<double,3>::iterator is rather cumbersome, so it may be convenient to define something like:
typedef multi_arr<double,3>::iterator md3i; typedef multi_arr<double,3>::const_iterator md3ci;
all the possible combinations for bool, long, realnum and double multi_arr's are predefined below.
this is a plausible way to use an iterator:
for( int k=0; i < 4; k++ ) { for( md3i p = arr.begin(n,k); p != arr.end(n,k); ++p ) *p = 3.; }
however, since many compilers have a hard time figuring out that arr.end() has no side effects, it is better to do the following:
for( int k=0; i < 4; k++ ) { md3i end = arr.end(n,k); for( md3i p = arr.begin(n,k); p != end; ++p ) *p = 3.; }
NB NB – the memory layout may change in future editions, so user code should not make any assumptions about the layout. the only exception is that the user may safely assume that for the default memory layout the last index runs over contiguous memory. this allows for efficient iterator access. the example above was OK since arr[n][k][0] and arr[n][k][1] are guaranteed to be adjacent. however the next example is not OK:
!! WRONG !!, arr[n][k-1][1] and arr[n][k][0] may NOT be adjacent
md3i p = arr.begin(n,0); for( int k=0; i < 4; k++ ) for( int i=0; i < 2; i++ ) *p++ = 3.; // ERROR, this may segfault. // bounds checking will catch this (see below for enabling this)
you can also use iterators for array-like access via []:
double sum = 0.; for( int k=0; i < 4; k++ ) { md3ci p = arr.begin(n,k); for( int i=0; i < 2; i++ ) sum += p[i]; }
last, but not least, the multi_arr class supports array bounds checking, both for direct access through the indexing method, as well as iterator access. To enable bounds checking, simply define the preprocessor macro BOUNDS_CHECK during compilation. the resulting code will be MUCH slower, so this should only be used as a debugging tool.
Definition at line 938 of file container_classes.h.
typedef const_n_pointer<T,d-1,ALLOC,lgBC> multi_arr< T, d, ALLOC, lgBC >::const_indexed_type |
Definition at line 1396 of file container_classes.h.
typedef const_pntr<T,lgBC> multi_arr< T, d, ALLOC, lgBC >::const_iterator |
Definition at line 961 of file container_classes.h.
typedef const T* multi_arr< T, d, ALLOC, lgBC >::const_pointer |
Definition at line 957 of file container_classes.h.
typedef const T& multi_arr< T, d, ALLOC, lgBC >::const_reference |
Definition at line 955 of file container_classes.h.
typedef ptrdiff_t multi_arr< T, d, ALLOC, lgBC >::difference_type |
Definition at line 959 of file container_classes.h.
typedef n_pointer<T,d-1,ALLOC,lgBC> multi_arr< T, d, ALLOC, lgBC >::indexed_type |
Definition at line 1391 of file container_classes.h.
typedef pntr<T,lgBC> multi_arr< T, d, ALLOC, lgBC >::iterator |
Definition at line 960 of file container_classes.h.
typedef random_access_iterator_tag multi_arr< T, d, ALLOC, lgBC >::iterator_category |
Definition at line 952 of file container_classes.h.
typedef T* multi_arr< T, d, ALLOC, lgBC >::pointer |
Definition at line 956 of file container_classes.h.
typedef T& multi_arr< T, d, ALLOC, lgBC >::reference |
Definition at line 954 of file container_classes.h.
typedef size_t multi_arr< T, d, ALLOC, lgBC >::size_type |
Definition at line 958 of file container_classes.h.
typedef T multi_arr< T, d, ALLOC, lgBC >::value_type |
Definition at line 953 of file container_classes.h.
|
inline |
Definition at line 986 of file container_classes.h.
|
inline |
Definition at line 990 of file container_classes.h.
|
inline |
Definition at line 995 of file container_classes.h.
|
inline |
Definition at line 1001 of file container_classes.h.
|
inline |
Definition at line 1007 of file container_classes.h.
|
inline |
Definition at line 1013 of file container_classes.h.
|
inline |
Definition at line 1019 of file container_classes.h.
|
inline |
Definition at line 1025 of file container_classes.h.
|
inline |
Definition at line 1030 of file container_classes.h.
|
inline |
Definition at line 1113 of file container_classes.h.
Referenced by t_ionbal::alloc(), StoutCollArray::alloc(), multi_arr< StoutColls, 2 >::alloc(), GridRetrieveXSPECData(), GroupMap::GroupMap(), HeCollidSetup(), diatomics::init(), InitGrid(), InterpolateGridCoStar(), InterpolateModel(), iso_allocate(), iso_level(), iso_multiplet_opacities_one(), lgCompileAtmosphere(), multi_arr< StoutColls, 2 >::multi_arr(), Atom_LevelN::operator()(), multi_arr< StoutColls, 2 >::operator=(), t_gaunt::p_read_table(), ParseCrashDo(), ParseMonitorResults(), diatomics::Read_Mol_Diss_cross_sections(), ReadCollisionRateTable(), diatomics::SolveExcitedElectronicLevels(), and t_mean::t_mean().
|
inline |
Definition at line 1164 of file container_classes.h.
|
inline |
Definition at line 1174 of file container_classes.h.
|
inline |
Definition at line 1179 of file container_classes.h.
|
inline |
Definition at line 1184 of file container_classes.h.
|
inline |
Definition at line 1189 of file container_classes.h.
|
inline |
Definition at line 1194 of file container_classes.h.
|
inline |
Definition at line 1199 of file container_classes.h.
|
inline |
Definition at line 1402 of file container_classes.h.
|
inline |
Definition at line 1409 of file container_classes.h.
|
inline |
Definition at line 1416 of file container_classes.h.
|
inline |
Definition at line 1423 of file container_classes.h.
|
inline |
Definition at line 1430 of file container_classes.h.
|
inline |
Definition at line 1437 of file container_classes.h.
|
inline |
Definition at line 1444 of file container_classes.h.
|
inline |
Definition at line 1451 of file container_classes.h.
|
inline |
Definition at line 1458 of file container_classes.h.
|
inline |
Definition at line 1465 of file container_classes.h.
|
inline |
Definition at line 1707 of file container_classes.h.
|
inline |
Definition at line 1711 of file container_classes.h.
|
inline |
Definition at line 1715 of file container_classes.h.
|
inline |
Definition at line 1719 of file container_classes.h.
|
inline |
Definition at line 1723 of file container_classes.h.
|
inline |
Definition at line 1727 of file container_classes.h.
|
inline |
Definition at line 1731 of file container_classes.h.
|
inline |
Definition at line 1735 of file container_classes.h.
|
inline |
Definition at line 1739 of file container_classes.h.
|
inline |
Definition at line 1743 of file container_classes.h.
|
inline |
Definition at line 1514 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::front(), diatomics::H2_Cooling(), diatomics::H2_LevelPops(), diatomics::H2_PunchDo(), diatomics::H2_X_coll_rate_evaluate(), and diatomics::SolveExcitedElectronicLevels().
|
inline |
Definition at line 1518 of file container_classes.h.
|
inline |
Definition at line 1522 of file container_classes.h.
|
inline |
Definition at line 1526 of file container_classes.h.
|
inline |
Definition at line 1530 of file container_classes.h.
|
inline |
Definition at line 1534 of file container_classes.h.
|
inline |
Definition at line 1538 of file container_classes.h.
|
inline |
Definition at line 1542 of file container_classes.h.
|
inline |
Definition at line 1546 of file container_classes.h.
|
inline |
Definition at line 1550 of file container_classes.h.
|
inline |
Definition at line 1752 of file container_classes.h.
|
inline |
Definition at line 1034 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and ParseCrashDo().
|
inline |
Definition at line 1779 of file container_classes.h.
Referenced by diatomics::init(), iso_allocate(), mie_write_opc(), diatomics::SolveExcitedElectronicLevels(), and t_mean::t_mean().
|
inline |
Definition at line 1764 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::dump_state(), multi_arr< StoutColls, 2 >::invalidate(), iso_level(), multi_arr< StoutColls, 2 >::restore_state(), and multi_arr< StoutColls, 2 >::zero().
|
inline |
Definition at line 1771 of file container_classes.h.
|
inline |
Definition at line 1067 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::state_do().
|
inline |
Definition at line 1756 of file container_classes.h.
Referenced by GridRetrieveXSPECData().
|
inline |
Definition at line 1555 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::back(), diatomics::H2_LevelPops(), and diatomics::SolveExcitedElectronicLevels().
|
inline |
Definition at line 1566 of file container_classes.h.
|
inline |
Definition at line 1577 of file container_classes.h.
|
inline |
Definition at line 1588 of file container_classes.h.
|
inline |
Definition at line 1599 of file container_classes.h.
|
inline |
Definition at line 1610 of file container_classes.h.
|
inline |
Definition at line 1621 of file container_classes.h.
|
inline |
Definition at line 1632 of file container_classes.h.
|
inline |
Definition at line 1643 of file container_classes.h.
|
inline |
Definition at line 1654 of file container_classes.h.
|
inline |
Definition at line 1666 of file container_classes.h.
|
inline |
Definition at line 1670 of file container_classes.h.
|
inline |
Definition at line 1674 of file container_classes.h.
|
inline |
Definition at line 1678 of file container_classes.h.
|
inline |
Definition at line 1682 of file container_classes.h.
|
inline |
Definition at line 1686 of file container_classes.h.
|
inline |
Definition at line 1690 of file container_classes.h.
|
inline |
Definition at line 1694 of file container_classes.h.
|
inline |
Definition at line 1698 of file container_classes.h.
|
inline |
Definition at line 1702 of file container_classes.h.
|
inline |
Definition at line 1054 of file container_classes.h.
Referenced by iso_allocate(), and t_gaunt::p_read_table().
|
inline |
Definition at line 1383 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::operator[]().
|
inline |
Definition at line 1387 of file container_classes.h.
|
inline |
Definition at line 1039 of file container_classes.h.
|
inline |
Definition at line 1392 of file container_classes.h.
|
inline |
Definition at line 1397 of file container_classes.h.
|
inlineprivate |
Definition at line 966 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::clear(), and multi_arr< StoutColls, 2 >::~multi_arr().
|
inlineprivate |
Definition at line 973 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::clear(), and multi_arr< StoutColls, 2 >::multi_arr().
|
inlineprivate |
Definition at line 1231 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::begin(), multi_arr< StoutColls, 2 >::end(), and multi_arr< StoutColls, 2 >::ptr().
|
inlineprivate |
Definition at line 1261 of file container_classes.h.
|
inlineprivate |
Definition at line 1291 of file container_classes.h.
|
inlineprivate |
Definition at line 1321 of file container_classes.h.
|
inlineprivate |
Definition at line 1351 of file container_classes.h.
|
inlineprivate |
Definition at line 1245 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::p_iterator().
|
inlineprivate |
Definition at line 1275 of file container_classes.h.
|
inlineprivate |
Definition at line 1305 of file container_classes.h.
|
inlineprivate |
Definition at line 1335 of file container_classes.h.
|
inlineprivate |
Definition at line 1365 of file container_classes.h.
|
inlineprivate |
Definition at line 1210 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and multi_arr< StoutColls, 2 >::p_setupArray().
|
inline |
Definition at line 1473 of file container_classes.h.
Referenced by ParseCrashDo().
|
inline |
Definition at line 1477 of file container_classes.h.
|
inline |
Definition at line 1481 of file container_classes.h.
|
inline |
Definition at line 1485 of file container_classes.h.
|
inline |
Definition at line 1489 of file container_classes.h.
|
inline |
Definition at line 1493 of file container_classes.h.
|
inline |
Definition at line 1497 of file container_classes.h.
|
inline |
Definition at line 1501 of file container_classes.h.
|
inline |
Definition at line 1505 of file container_classes.h.
|
inline |
Definition at line 1509 of file container_classes.h.
|
inline |
Definition at line 1077 of file container_classes.h.
Referenced by t_ionbal::alloc(), GridRetrieveXSPECData(), GroupMap::GroupMap(), HeCollidSetup(), diatomics::init(), iso_allocate(), iso_multiplet_opacities_one(), ParseCrashDo(), ParseMonitorResults(), diatomics::Read_Mol_Diss_cross_sections(), ReadCollisionRateTable(), and t_mean::t_mean().
|
inline |
Definition at line 1083 of file container_classes.h.
|
inline |
Definition at line 1089 of file container_classes.h.
|
inline |
Definition at line 1095 of file container_classes.h.
|
inline |
Definition at line 1101 of file container_classes.h.
|
inline |
Definition at line 1107 of file container_classes.h.
|
inline |
Definition at line 1072 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::state_do().
|
inline |
Definition at line 1748 of file container_classes.h.
Referenced by InterpolateModel(), InterpolateModelCoStar(), multi_arr< StoutColls, 2 >::invalidate(), t_gaunt::p_read_table(), ReadCollisionRateTable(), multi_arr< StoutColls, 2 >::reserve(), and multi_arr< StoutColls, 2 >::zero().
|
inline |
Definition at line 1059 of file container_classes.h.
|
inline |
Definition at line 1784 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::invalidate(), Atom_LevelN::operator()(), multi_arr< StoutColls, 2 >::operator=(), multi_arr< StoutColls, 2 >::reserve(), and multi_arr< StoutColls, 2 >::zero().
|
inline |
Definition at line 1788 of file container_classes.h.
|
inline |
Definition at line 1048 of file container_classes.h.
Referenced by diatomics::H2_Colden(), diatomics::H2_LevelPops(), diatomics::H2_Reset(), diatomics::H2_X_coll_rate_evaluate(), diatomics::H2_zero_pops_too_low(), diatomics::init(), iso_level(), iso_multiplet_opacities_one(), diatomics::Mol_Photo_Diss_Rates(), mole_eval_balance(), Atom_LevelN::operator()(), ReadCollisionRateTable(), diatomics::SolveExcitedElectronicLevels(), diatomics::SolveSomeGroundElectronicLevels(), and t_mean::zero().
|
staticprivate |
Definition at line 964 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::end(), and multi_arr< StoutColls, 2 >::p_iterator_bc().
|
private |
|
private |
Definition at line 941 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), multi_arr< StoutColls, 2 >::at(), multi_arr< StoutColls, 2 >::capacity(), multi_arr< StoutColls, 2 >::clone(), multi_arr< StoutColls, 2 >::data(), multi_arr< StoutColls, 2 >::dump_state(), multi_arr< StoutColls, 2 >::empty(), multi_arr< StoutColls, 2 >::end(), multi_arr< StoutColls, 2 >::invalidate(), multi_arr< StoutColls, 2 >::n_ptr(), multi_arr< StoutColls, 2 >::operator=(), multi_arr< StoutColls, 2 >::p_clear0(), multi_arr< StoutColls, 2 >::p_iterator_bc(), multi_arr< StoutColls, 2 >::reserve(), multi_arr< StoutColls, 2 >::restore_state(), multi_arr< StoutColls, 2 >::size(), and multi_arr< StoutColls, 2 >::zero().
|
private |
Definition at line 942 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), multi_arr< StoutColls, 2 >::empty(), multi_arr< StoutColls, 2 >::p_clear0(), multi_arr< StoutColls, 2 >::p_clear1(), and multi_arr< StoutColls, 2 >::p_setupArray().
|
private |
Definition at line 944 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), multi_arr< StoutColls, 2 >::n_ptr(), and multi_arr< StoutColls, 2 >::p_clear1().
|
private |
Definition at line 945 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and multi_arr< StoutColls, 2 >::p_clear1().
|
private |
Definition at line 946 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and multi_arr< StoutColls, 2 >::p_clear1().
|
private |
Definition at line 947 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and multi_arr< StoutColls, 2 >::p_clear1().
|
private |
Definition at line 948 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and multi_arr< StoutColls, 2 >::p_clear1().
|
private |
Definition at line 949 of file container_classes.h.
Referenced by multi_arr< StoutColls, 2 >::alloc(), and multi_arr< StoutColls, 2 >::p_clear1().