IMP logo
Public Types | Public Member Functions | Friends | Related Functions
IMP::algebra::MultiArray< T, D > Class Template Reference

Detailed Description

template<typename T, int D>
class IMP::algebra::MultiArray< T, D >

Template class for managing multidimensional arrays. This class is based on boost multi_array. This classes is primarily aimed to implement generic 2D and 3D bitmaps. See GridD if you want a more general purpose spatial grid.

The class adds new functionality to the boost class: 1) Operators + - * and / to deal with other multiarrays and scalars 2) Computation of maximum, minimum, and statistical properties of the array. 3) Read/Write both in text and binary modes (taking into account the endianess).

+ Inheritance diagram for IMP::algebra::MultiArray< T, D >:

List of all members.

Public Types

typedef boost::multi_array< T, D > BMA
typedef
boost::multi_array_types::index 
index
typedef
boost::multi_array_types::size_type 
size_type
typedef MultiArray< T, D > This

Public Member Functions

 MultiArray ()
 Empty constructor.
bool almost_equal (const double a, const double b, const double epsilon)
void centered_start ()
double compute_avg () const
 Average of the values in the array.
compute_max () const
 Maximum of the values in the array.
template<typename T1 >
compute_max (T1 &max_idx) const
 Maximum of the values in the array.
compute_min () const
 Minimum of the values in the array.
template<typename T1 >
compute_min (T1 &min_idx) const
 Minimum of the values in the array.
void compute_stats (double &avg, double &stddev, T &minval, T &maxval) const
 Compute average, standard deviation, minimum and maximum values.
double compute_stddev () const
 Standard deviation of the values in the array.
void copy (This &v)
template<typename U >
void copy_with_casting (MultiArray< U, D > &v)
 Copy with casting. Use with care!
double cross_correlation_coefficient (const This &v, bool apply_threshold=false, double threshold=0.0, bool divide_by_stddev=true, bool force_recalc_stats=true, double avg=0.0, double stddev=0.0, double avg_v=0.0, double stddev_v=0.0)
 Computes the cross correlation coeffcient between two MultiArrays.
void fill_with_value (T val=0)
 Fill all the voxels of the array with a given value.
bool first_element () const
 Returns the first element.
int get_finish (const int dim) const
int get_size (const int dim) const
int get_start (const int dim) const
void init_zeros ()
 All the values of the array are set to zero.
template<typename T1 >
bool is_logical_element (T1 &v) const
 Returns true if the LOGICAL index belongs to those of the matrix.
template<typename T1 >
bool is_physical_element (T1 &v) const
 Returns true if the PHYSICAL index belongs to those of the matrix.
bool is_void () const
 Check if the array has some dimensionality or is just empty.
void normalize ()
This operator* (const This &v) const
 Multiplication operator.
This operator* (const T &v) const
 Multiplication operator for an array and a scalar.
void operator*= (const This &v) const
 Multiplication operator.
void operator*= (const T &v) const
 Multiplication operator for an array and a scalar.
This operator+ (const This &v) const
 Sum operator.
This operator+ (const T &v) const
 Sum operator for an array and a scalar.
void operator+= (const This &v) const
 Addition operator.
void operator+= (const T &v) const
 Addition operator for an array and a scalar.
This operator- (const This &v) const
 Minus operator.
This operator- (const T &v) const
 Minus operator for an array and a scalar.
void operator-= (const This &v) const
 Substraction operator.
void operator-= (const T &v) const
 Substraction operator for an array and a scalar.
This operator/ (const This &v) const
 Division operator.
This operator/ (const T &v) const
 Division operator for an array and a scalar.
void operator/= (const This &v) const
 Division operator.
void operator/= (const T &v) const
 Division operator for an array and a scalar.
void print_shape (std::ostream &out=std::cout) const
 Print shape of multidimensional array.
void read (const std::string &filename)
 Read from an ASCII file.
void read_binary (const std::string &filename, bool reversed=false)
 Read from a binary file.
void read_binary (std::ifstream &input, bool reversed=false)
 Read from a input stream in binary mode.
template<typename T1 >
bool same_shape (const MultiArray< T1, D > &b) const
 Compares the shape of two multidimensional arrays.
template<typename T1 >
bool same_size (const MultiArray< T1, D > &b) const
 Compares the size of two multidimensional arrays.
template<typename T1 >
bool same_start (const MultiArray< T1, D > &b) const
 Compares the origin of two multidimensional arrays.
void set_start (const int dim, const int value)
template<typename T1 >
void set_start (const T1 &v)
squared_difference (const This &v) const
sum_elements () const
 Computes the sum of all the array elements.
sum_squared_elements () const
void write (const std::string &filename) const
 Write to an ASCII file.
void write_binary (const std::string &filename, bool reversed=false)
 Write to a binary file.
void write_binary (std::ofstream &out, bool reversed=false)
 Write to a output stream in binary mode.

Friends

std::istream & operator>> (std::istream &input, This &v)

Related Functions

(Note that these are not member functions.)

template<class T , int D>
MultiArray< T, D > operator* (const T &X, const MultiArray< T, D > &a1)
 Multiplication operator for a scalar and an array.
template<class T , int D>
MultiArray< T, D > operator+ (const T &X, const MultiArray< T, D > &a1)
 Sum operator for a scalar and an array.
template<class T , int D>
MultiArray< T, D > operator- (const T &X, const MultiArray< T, D > &a1)
 Minus operator for a scalar and an array.
template<class T , int D>
MultiArray< T, D > operator/ (const T &X, const MultiArray< T, D > &a1)
 Division operator for a scalar and an array.

Constructor & Destructor Documentation

template<typename T, int D>
IMP::algebra::MultiArray< T, D >::MultiArray ( )

Empty constructor.


Member Function Documentation

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::centered_start ( )

Sets the zero (0,0,0,...) of the logical coordinates at the center of the center of the matrix. Some examples:

m.centered_start(); // if m is a 5x4 matrix, the origin will be (-2,-2)
m.centered_start(); // if m is a 16x3 matrix, the origin will be (-8,-1)
template<typename T, int D>
double IMP::algebra::MultiArray< T, D >::compute_avg ( ) const

Average of the values in the array.

The returned value is always double, independently of the type of the array.

template<typename T, int D>
T IMP::algebra::MultiArray< T, D >::compute_max ( ) const

Maximum of the values in the array.

template<typename T, int D>
template<typename T1 >
T IMP::algebra::MultiArray< T, D >::compute_max ( T1 &  max_idx) const

Maximum of the values in the array.

Parameters:
[out]max_idxindex containing the maximum value
template<typename T, int D>
T IMP::algebra::MultiArray< T, D >::compute_min ( ) const

Minimum of the values in the array.

template<typename T, int D>
template<typename T1 >
T IMP::algebra::MultiArray< T, D >::compute_min ( T1 &  min_idx) const

Minimum of the values in the array.

Parameters:
[out]min_idxindex containing the minimum value
template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::compute_stats ( double &  avg,
double &  stddev,
T &  minval,
T &  maxval 
) const

Compute average, standard deviation, minimum and maximum values.

template<typename T, int D>
double IMP::algebra::MultiArray< T, D >::compute_stddev ( ) const

Standard deviation of the values in the array.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::copy ( This v)

Copies the contents of a MultiArray to this one (no resizing is done). For copying with resizing use operator=

Parameters:
[in]vMultiArray whose contents to copy
template<typename T, int D>
template<typename U >
void IMP::algebra::MultiArray< T, D >::copy_with_casting ( MultiArray< U, D > &  v)

Copy with casting. Use with care!

template<typename T, int D>
double IMP::algebra::MultiArray< T, D >::cross_correlation_coefficient ( const This v,
bool  apply_threshold = false,
double  threshold = 0.0,
bool  divide_by_stddev = true,
bool  force_recalc_stats = true,
double  avg = 0.0,
double  stddev = 0.0,
double  avg_v = 0.0,
double  stddev_v = 0.0 
)

Computes the cross correlation coeffcient between two MultiArrays.

Note:
Both MultiArrays are required to have the same size, but not the same origin
Parameters:
[in]varray to compute the cross_correlation with.
[in]apply_thresholdtrue if a threshold is applied to the elements of v .
[in]thresholdminimum value for an element v to consider it in the computation .
[in]divide_by_stddevtrue if the cross correlation term is divided by the standard deviation to get the cross correlation coefficient (0 <= ccc <= 1).
[in]force_recalc_statstrue if the statistics (mean, stddev) for the Multiarrays must be recalculated (default). If the statistics are known from previous computations, you can speed up the next computations setting this variable to false and directly providing the parameters.
[in]avgaverage of this Multiarray.
[in]stddevstandard deviation of this Multiarray.
[in]avg_vaverage of Multiarray v.
[in]stddev_vstandard deviation of Multiarray v.
template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::fill_with_value ( val = 0)

Fill all the voxels of the array with a given value.

template<typename T, int D>
bool IMP::algebra::MultiArray< T, D >::first_element ( ) const

Returns the first element.

template<typename T, int D>
int IMP::algebra::MultiArray< T, D >::get_finish ( const int  dim) const

Another way of asking for the final value (logical) for the index of the dimension

template<typename T, int D>
int IMP::algebra::MultiArray< T, D >::get_size ( const int  dim) const

Another way of asking for the size of a given dimension. You can always use x.shape()[i] too.

template<typename T, int D>
int IMP::algebra::MultiArray< T, D >::get_start ( const int  dim) const

Another way of asking for the initial value (logical) for the index of the dimension. You can always use index_bases()[dim]

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::init_zeros ( )

All the values of the array are set to zero.

template<typename T, int D>
template<typename T1 >
bool IMP::algebra::MultiArray< T, D >::is_logical_element ( T1 &  v) const

Returns true if the LOGICAL index belongs to those of the matrix.

Parameters:
[in]vAny class able to be accessed with []
template<typename T, int D>
template<typename T1 >
bool IMP::algebra::MultiArray< T, D >::is_physical_element ( T1 &  v) const

Returns true if the PHYSICAL index belongs to those of the matrix.

Parameters:
[in]vAny class able to be accessed with []
template<typename T, int D>
bool IMP::algebra::MultiArray< T, D >::is_void ( ) const

Check if the array has some dimensionality or is just empty.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::normalize ( )

Normalize the values of the MultiArray to mean value 0 and standard deviation 1.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator* ( const This v) const

Multiplication operator.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator* ( const T &  v) const

Multiplication operator for an array and a scalar.

Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator*= ( const This v) const

Multiplication operator.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator*= ( const T &  v) const

Multiplication operator for an array and a scalar.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator+ ( const This v) const

Sum operator.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator+ ( const T &  v) const

Sum operator for an array and a scalar.

Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator+= ( const This v) const

Addition operator.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator+= ( const T &  v) const

Addition operator for an array and a scalar.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator- ( const This v) const

Minus operator.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator- ( const T &  v) const

Minus operator for an array and a scalar.

Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator-= ( const This v) const

Substraction operator.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator-= ( const T &  v) const

Substraction operator for an array and a scalar.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator/ ( const This v) const

Division operator.

template<typename T, int D>
This IMP::algebra::MultiArray< T, D >::operator/ ( const T &  v) const

Division operator for an array and a scalar.

Reimplemented in IMP::algebra::Matrix2D< T >, and IMP::algebra::Matrix3D< T >.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator/= ( const This v) const

Division operator.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::operator/= ( const T &  v) const

Division operator for an array and a scalar.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::print_shape ( std::ostream &  out = std::cout) const

Print shape of multidimensional array.

This function shows the size, starting and finishing indexes of the given array. No end of line is printed neither at the beginning nor the end.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::read ( const std::string &  filename)

Read from an ASCII file.

The array must be previously resized to the correct size.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::read_binary ( const std::string &  filename,
bool  reversed = false 
)

Read from a binary file.

The array must be previously resized to the correct size.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::read_binary ( std::ifstream &  input,
bool  reversed = false 
)

Read from a input stream in binary mode.

The array must be previously resized to the correct size.

template<typename T, int D>
template<typename T1 >
bool IMP::algebra::MultiArray< T, D >::same_shape ( const MultiArray< T1, D > &  b) const

Compares the shape of two multidimensional arrays.

Returns:
true if both arrays have the same size and origin
template<typename T, int D>
template<typename T1 >
bool IMP::algebra::MultiArray< T, D >::same_size ( const MultiArray< T1, D > &  b) const

Compares the size of two multidimensional arrays.

Returns:
true if both arrays have the same size
template<typename T, int D>
template<typename T1 >
bool IMP::algebra::MultiArray< T, D >::same_start ( const MultiArray< T1, D > &  b) const

Compares the origin of two multidimensional arrays.

Returns:
true if both arrays have the same origin
template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::set_start ( const int  dim,
const int  value 
)

Another way setting the initial value (logical) for the index of the dimension. You can always use reindex()

template<typename T, int D>
template<typename T1 >
void IMP::algebra::MultiArray< T, D >::set_start ( const T1 &  v)

Another way setting the initial value (logical) for the index of the dimension.

Parameters:
[in]vAny class able to be accessed with []
template<typename T, int D>
T IMP::algebra::MultiArray< T, D >::squared_difference ( const This v) const

Computes the sum of the squared elements of the difference MultiArray obtained from substracting v.

Note:
Both MultiArrays are required to have the same shape (size and origin)
template<typename T, int D>
T IMP::algebra::MultiArray< T, D >::sum_elements ( ) const

Computes the sum of all the array elements.

template<typename T, int D>
T IMP::algebra::MultiArray< T, D >::sum_squared_elements ( ) const

Computes the sum of all the squared elements of the array. (Frobenius norm)

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::write ( const std::string &  filename) const

Write to an ASCII file.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::write_binary ( const std::string &  filename,
bool  reversed = false 
)

Write to a binary file.

template<typename T, int D>
void IMP::algebra::MultiArray< T, D >::write_binary ( std::ofstream &  out,
bool  reversed = false 
)

Write to a output stream in binary mode.


Friends And Related Function Documentation

template<class T , int D>
MultiArray< T, D > operator* ( const T &  X,
const MultiArray< T, D > &  a1 
)
related

Multiplication operator for a scalar and an array.

template<class T , int D>
MultiArray< T, D > operator+ ( const T &  X,
const MultiArray< T, D > &  a1 
)
related

Sum operator for a scalar and an array.

template<class T , int D>
MultiArray< T, D > operator- ( const T &  X,
const MultiArray< T, D > &  a1 
)
related

Minus operator for a scalar and an array.

template<class T , int D>
MultiArray< T, D > operator/ ( const T &  X,
const MultiArray< T, D > &  a1 
)
related

Division operator for a scalar and an array.


The documentation for this class was generated from the following file:

Generated on Tue May 22 2012 23:33:25 for IMP by doxygen 1.8.1