CVM Class Library  8.1
This C++ class library encapsulates concepts of vector and different matrices including square, band, symmetric and hermitian ones in Euclidean space of real and complex numbers.
 All Classes Files Functions Variables Typedefs Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
basic_array< TR, TC > Class Template Reference

Abstract array of numbers with increment between them. Root object for all library classes. More...

#include <cvm.h>

Inheritance diagram for basic_array< TR, TC >:
Inheritance graph
[legend]
Collaboration diagram for basic_array< TR, TC >:
Collaboration graph
[legend]

Public Types

typedef TC value_type
 STL-specific value type definition.
typedef value_typepointer
 STL-specific value pointer definition.
typedef value_typeiterator
 STL-specific iterator definition.
typedef const value_typeconst_iterator
 STL-specific const iterator definition.
typedef const value_typeconst_pointer
 STL-specific const pointer definition.
typedef value_typereference
 STL-specific reference definition.
typedef const value_typeconst_reference
 STL-specific const reference definition.
typedef size_t size_type
 STL-specific size type definition.
typedef ptrdiff_t difference_type
 STL-specific difference type definition.
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator
 STL-specific const reverse iterator definition.
typedef std::reverse_iterator
< iterator
reverse_iterator
 STL-specific reverse iterator definition.

Public Member Functions

 basic_array ()
 Default constructor.
 basic_array (tint nSize, bool bZeroMemory=true)
 Constructor.
 basic_array (TC *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_array (const TC *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_array (const TC *begin, const TC *end)
 Constructor.
 basic_array (const basic_array &a)
 Copy constructor.
 basic_array (basic_array &&a) noexcept
 Move constructor.
basic_arrayoperator= (const basic_array &a) throw (cvmexception)
 Assignment operator.
basic_arrayoperator= (basic_array &&a) throw (cvmexception)
 Move assignment operator.
virtual ~basic_array ()
 Destructor.
tint size () const
 Size (length) of array.
TC * get ()
 Pointer to data.
const TC * get () const
 Const pointer to data.
 operator TC * ()
 Type cast to pointer to data.
 operator const TC * () const
 Type cast to constant pointer to data.
TC & operator() (tint n) throw (cvmexception)
 Reference to element (l-value)
TC operator() (tint n) const throw (cvmexception)
 Value of element (not l-value)
TC & operator[] (tint n) throw (cvmexception)
 Reference to element (l-value)
TC operator[] (tint n) const throw (cvmexception)
 Value of element (not l-value)
basic_arrayassign (const TC *p)
 Assignment from external array.
basic_arrayset (TC x)
 Sets all elements to one value.
basic_arrayresize (tint nNewSize) throw (cvmexception)
 Changes size of array.
tint incr () const
 Increment between elements.
tint indofmax () const
 Index of element with maximum module.
tint indofmin () const
 Index of element with minimum module.
virtual TR norm () const
 Euclidean norm.
virtual TR norminf () const
 Infinity norm.
virtual TR norm1 () const
 1-norm
virtual TR norm2 () const
 2-norm
iterator begin ()
 (STL) iterator to begin
const_iterator begin () const
 (STL) const iterator to begin
iterator end ()
 (STL) iterator to end
const_iterator end () const
 (STL) const iterator to end
reverse_iterator rbegin ()
 (STL) iterator to begin reversed
const_reverse_iterator rbegin () const
 (STL) const iterator to begin reversed
reverse_iterator rend ()
 (STL) iterator to end reversed
const_reverse_iterator rend () const
 (STL) const iterator to end reversed
size_type max_size () const
 (STL) maximum possible size of array
size_type capacity () const
 (STL) current capacity of array, equal to size()
bool empty () const
 (STL) is array empty
reference front ()
 (STL) reference to first element
const_reference front () const
 (STL) const reference to first element
reference back ()
 (STL) reference to last element
const_reference back () const
 (STL) const reference to last element
void assign (size_type n, const TC &val) throw (cvmexception)
 (STL) assigns given value to n-th element (0-based)
void assign (const_iterator begin, const_iterator end) throw (cvmexception)
 (STL) assigns begin-end iteartor range to array
void clear ()
 (STL) clears array, dealocates memory and sets size() to zero
void swap (basic_array &v) throw (cvmexception)
 (STL) swaps array values, throws cvmexception if sizes are different
reference at (size_type n) throw (cvmexception)
 (STL) returns reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries
const_reference at (size_type n) const throw (cvmexception)
 (STL) returns const reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries
void push_back (const TC &x) throw (cvmexception)
 (STL) pushes new value to the end of array
void pop_back () throw (cvmexception)
 (STL) removes last element from array
iterator insert (iterator position, const TC &x) throw (cvmexception)
 (STL) inserts element to given position in array
iterator erase (iterator position) throw (cvmexception)
 (STL) removes element from given position in array

Protected Attributes

tint msz
 Number of elements of type TC allocated.
tint mincr
 Increment (distance) between elements (default is 1, i.e. elements follow each other)
std::shared_ptr< TC > mp
 native data pointer
TC * mpf
 Foreign data pointer.

Friends

std::istream & operator>> (std::istream &is, basic_array &aIn)
 Inserts elements from input stream to array.
std::ostream & operator<< (std::ostream &os, const basic_array &aOut)
 Inserts elements of array to output stream.

Detailed Description

template<typename TR, typename TC>
class basic_array< TR, TC >

Abstract array of numbers with increment between them. Root object for all library classes.

This abstract class encapsulates BLAS/LAPACK aware array of numbers. It implements increment bewteen elements (default increment is 1, i.e. elements follow each other). TR type stands for treal and TC stands for tcomplex for complex number classes and treal otherwise.

This class contains array-specific member functions inherited in other classes. It can be used as a standalone class too. It also provides STL-compatible functions and type definitions, so itself and derived classes can be used in the same way as std::vector<T>.

Definition at line 1818 of file cvm.h.

Member Typedef Documentation

template<typename TR, typename TC>
typedef TC basic_array< TR, TC >::value_type

STL-specific value type definition.

Definition at line 1832 of file cvm.h.

template<typename TR, typename TC>
typedef value_type* basic_array< TR, TC >::pointer

STL-specific value pointer definition.

Definition at line 1833 of file cvm.h.

template<typename TR, typename TC>
typedef value_type* basic_array< TR, TC >::iterator

STL-specific iterator definition.

Definition at line 1834 of file cvm.h.

template<typename TR, typename TC>
typedef const value_type* basic_array< TR, TC >::const_iterator

STL-specific const iterator definition.

Definition at line 1835 of file cvm.h.

template<typename TR, typename TC>
typedef const value_type* basic_array< TR, TC >::const_pointer

STL-specific const pointer definition.

Definition at line 1836 of file cvm.h.

template<typename TR, typename TC>
typedef value_type& basic_array< TR, TC >::reference

STL-specific reference definition.

Definition at line 1837 of file cvm.h.

template<typename TR, typename TC>
typedef const value_type& basic_array< TR, TC >::const_reference

STL-specific const reference definition.

Definition at line 1838 of file cvm.h.

template<typename TR, typename TC>
typedef size_t basic_array< TR, TC >::size_type

STL-specific size type definition.

Definition at line 1839 of file cvm.h.

template<typename TR, typename TC>
typedef ptrdiff_t basic_array< TR, TC >::difference_type

STL-specific difference type definition.

Definition at line 1840 of file cvm.h.

template<typename TR, typename TC>
typedef std::reverse_iterator<const_iterator> basic_array< TR, TC >::const_reverse_iterator

STL-specific const reverse iterator definition.

Definition at line 1841 of file cvm.h.

template<typename TR, typename TC>
typedef std::reverse_iterator<iterator> basic_array< TR, TC >::reverse_iterator

STL-specific reverse iterator definition.

Definition at line 1842 of file cvm.h.

Constructor & Destructor Documentation

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( )
inline

Default constructor.

Creates zero length array. Allocates no memory.

Example:
using namespace cvm;
std::cout << a.size() << std::endl;
a.resize(10);
std::cout << a.size() << std::endl;
prints
0
10

Definition at line 1863 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( tint  nSize,
bool  bZeroMemory = true 
)
inlineexplicit

Constructor.

Creates array of nSize elements of type TC. Assigns zero to all elements if bZeroMemory is true. Constructor throws cvmexception in case of non-positive size passed or memory allocation failure.

Example:
using namespace cvm;
iarray a(5);
std::cout << a.size() << " " << a[1] << std::endl;
prints
5 0
Parameters
[in]nSizeNumber of array elements.
[in]bZeroMemoryTrue (default) if all elements should be set to zero.

Definition at line 1896 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( TC *  pd,
tint  nSize,
tint  nIncr = 1 
)
inline

Constructor.

Creates array of nSize elements of type TC. This is non-const version, it shares memory (shallow copy) with array pointed to by pd parameter. Constructor throws cvmexception in case of non-positive size passed.

See Also
http://cvmlib.com/faq.htm
Example:
using namespace cvm;
int a[] = {1, 2, 3, 4};
iarray v (a, 3);
std::cout << v;
a[0] = 77;
std::cout << v;
prints
1 2 3
77 2 3
Parameters
[in]pdNon-const pointer to external array.
[in]nSizeNumber of array elements.
[in]nIncrIncrement (distance) between elements (default is 1, i.e. elements follow each other).

Definition at line 1936 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( const TC *  pd,
tint  nSize,
tint  nIncr = 1 
)
inline

Constructor.

Creates array of nSize elements of type TC. This is const version, it allocates memory and copies elemets (deep copy) from external array pointed to by pd parameter. Constructor throws cvmexception in case of non-positive size passed or memory allocation failure.

See Also
http://cvmlib.com/faq.htm
Example:
using namespace cvm;
const int a[] = {1, 2, 3, 4};
iarray v (a, 3);
std::cout << v;
prints
1 2 3
Parameters
[in]pdConst pointer to external array.
[in]nSizeNumber of array elements.
[in]nIncrIncrement (distance) between elements (default is 1, i.e. elements follow each other).

Definition at line 1973 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( const TC *  begin,
const TC *  end 
)
inline

Constructor.

STL-style constructor accepting pointers to begin and end iterator. Creates array of end-begin elements of type TC. Allocates memory and copies elemets (deep copy) from external array pointed to by begin parameter. Constructor throws cvmexception in case of wrong range passed or memory allocation failure.

Example:
using namespace cvm;
const int a[] = {1, 2, 3, 4};
const iarray v (a+1, a+3);
std::cout << v << std::endl;
prints
2 3
Parameters
[in]beginConst pointer to external array (begin iterator).
[in]endConst pointer to last element of external array (end iterator). Element pointed to by end is not copied.

Definition at line 2010 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( const basic_array< TR, TC > &  a)
inline

Copy constructor.

Creates deep copy of other array

Example:
using namespace cvm;
iarray a(5);
a.set(3);
iarray b(a);
std::cout << b;
prints
3 3 3 3 3
Parameters
[in]aConst reference to array.

Definition at line 2042 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::basic_array ( basic_array< TR, TC > &&  a)
inline

Move constructor.

Implements move semantics introduced in new C++ standard. Moves data ownership from other array to newly created object. It's usually executed implicitly in cases like this:

rvector a(b + c);

or this

rvector a = b + c;

Here temporary result of calling b.operator+(c) will not be destroyed but rather moved to newly created object a.

Parameters
[in]arvalue reference to other array.

Definition at line 2072 of file cvm.h.

template<typename TR, typename TC>
virtual basic_array< TR, TC >::~basic_array ( )
inlinevirtual

Destructor.

Virtual destructor to be inherited by other classes of the library.

Definition at line 2139 of file cvm.h.

Member Function Documentation

template<typename TR, typename TC>
basic_array& basic_array< TR, TC >::operator= ( const basic_array< TR, TC > &  a) throw (cvmexception)
inline

Assignment operator.

Assigns array to array. Throws cvmexception if sizes are different.

Example:
using namespace cvm;
iarray a(5), b(5);
a.set(3);
b = a;
std::cout << b;
prints
3 3 3 3 3
Parameters
[in]aReference to array to be assigned.
See Also
assign()
Returns
Reference to changed calling array.

Definition at line 2106 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
basic_array& basic_array< TR, TC >::operator= ( basic_array< TR, TC > &&  a) throw (cvmexception)
inline

Move assignment operator.

Implements move semantics introduced in new C++ standard. Moves data ownership from other array to calling object. It's usually executed implicitly in cases like this:

a = b + c;

Here temporary result of calling b.operator+(c) will not be destroyed but rather moved to calling object a.

Parameters
[in]arvalue reference to other array.

Definition at line 2126 of file cvm.h.

template<typename TR, typename TC>
tint basic_array< TR, TC >::size ( ) const
inline

Size (length) of array.

Number of elements in array.

Example:
using namespace cvm;
rvector v(3);
cmatrix m(10,20);
cout << v.size() << " " << m.size() << endl;
prints
3 200
Returns
tint Number of elements.

Definition at line 2164 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
TC* basic_array< TR, TC >::get ( )
inline

Pointer to data.

Returns pointer to internal data array.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
void cprint (const std::complex<double>* p, int size)
{
for (int i = 0; i < size; ++i)
std::cout << p[i] << " ";
std::cout << std::endl;
}
...
iarray a(10);
scmatrix m(3);
a[2] = 1;
m(3,1) = std::complex<double>(1., 2.);
std::cout << a.get()[1] << std::endl;
cprint(m, 3);
prints
1
(0.00e+00,0.00e+00) (0.00e+00,0.00e+00) (1.00e+00,2.00e+00)
See Also
basic_array::operator TC*()
Returns
TC* Pointer to internal data array.

Definition at line 2200 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
const TC* basic_array< TR, TC >::get ( ) const
inline

Const pointer to data.

Returns pointer to internal data array.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
void cprint (const std::complex<double>* p, int size)
{
for (int i = 0; i < size; ++i)
std::cout << p[i] << " ";
std::cout << std::endl;
}
...
iarray a(10);
scmatrix m(3);
a[2] = 1;
m(3,1) = std::complex<double>(1., 2.);
std::cout << a.get()[1] << std::endl;
cprint(m, 3);
prints
1
(0.00e+00,0.00e+00) (0.00e+00,0.00e+00) (1.00e+00,2.00e+00)
See Also
basic_array::operator const TC*() const
Returns
const TC*

Definition at line 2242 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::operator TC * ( )
inline

Type cast to pointer to data.

Returns pointer to internal data array.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
void cprint (const std::complex<double>* p, int size)
{
for (int i = 0; i < size; ++i)
std::cout << p[i] << " ";
std::cout << std::endl;
}
...
iarray a(10);
scmatrix m(3);
a[2] = 1;
m(3,1) = std::complex<double>(1., 2.);
std::cout << a.get()[1] << std::endl;
cprint(m, 3);
prints
1
(0.00e+00,0.00e+00) (0.00e+00,0.00e+00) (1.00e+00,2.00e+00)
See Also
get()
Returns
TC* Pointer to internal data array.

Definition at line 2285 of file cvm.h.

template<typename TR, typename TC>
basic_array< TR, TC >::operator const TC * ( ) const
inline

Type cast to constant pointer to data.

Returns constant pointer to internal data array.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
void cprint (const std::complex<double>* p, int size)
{
for (int i = 0; i < size; ++i)
std::cout << p[i] << " ";
std::cout << std::endl;
}
...
iarray a(10);
scmatrix m(3);
a[2] = 1;
m(3,1) = std::complex<double>(1., 2.);
std::cout << a.get()[1] << std::endl;
cprint(m, 3);
prints
1
(0.00e+00,0.00e+00) (0.00e+00,0.00e+00) (1.00e+00,2.00e+00)
See Also
get() const
Returns
const TC*

Definition at line 2322 of file cvm.h.

template<typename TR, typename TC>
TC& basic_array< TR, TC >::operator() ( tint  n) throw (cvmexception)
inline

Reference to element (l-value)

Returns reference to array's element by its index (CVM0 based).

Example:
using namespace cvm;
try {
rvector v (10);
v[1] = 1.;
v(2) = 2.;
std::cout << v;
double a[] = {1., 2., 3., 4.};
const rvector vc (a, 4);
std::cout << vc(1) << " " << vc[2] << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
1 2 0 0 0 0 0 0 0 0
1 2
Parameters
[in]nIndex of element to return reference to.
Returns
TC&

Reimplemented in basic_scmatrix< TR, TC >, basic_cmatrix< TR, TC >, basic_srmatrix< TR >, and basic_rmatrix< TR >.

Definition at line 2356 of file cvm.h.

template<typename TR, typename TC>
TC basic_array< TR, TC >::operator() ( tint  n) const throw (cvmexception)
inline

Value of element (not l-value)

Returns value of array's element by its index (CVM0 based).

Example:
using namespace cvm;
try {
rvector v (10);
v[1] = 1.;
v(2) = 2.;
std::cout << v;
double a[] = {1., 2., 3., 4.};
const rvector vc (a, 4);
std::cout << vc(1) << " " << vc[2] << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
1 2 0 0 0 0 0 0 0 0
1 2
Parameters
[in]nIndex of element to return value for.
Returns
TC

Reimplemented in basic_schmatrix< TR, TC >, basic_srsmatrix< TR >, basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, basic_scmatrix< TR, TC >, basic_cmatrix< TR, TC >, basic_srmatrix< TR >, and basic_rmatrix< TR >.

Definition at line 2390 of file cvm.h.

template<typename TR, typename TC>
TC& basic_array< TR, TC >::operator[] ( tint  n) throw (cvmexception)
inline

Reference to element (l-value)

Returns reference to array's element by its index (CVM0 based).

Example:
using namespace cvm;
try {
rvector v (10);
v[1] = 1.;
v(2) = 2.;
std::cout << v;
double a[] = {1., 2., 3., 4.};
const rvector vc (a, 4);
std::cout << vc(1) << " " << vc[2] << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
1 2 0 0 0 0 0 0 0 0
1 2
Parameters
[in]nIndex of element to return reference to.
Returns
TC&

Reimplemented in basic_scmatrix< TR, TC >, basic_cmatrix< TR, TC >, basic_srmatrix< TR >, and basic_rmatrix< TR >.

Definition at line 2424 of file cvm.h.

template<typename TR, typename TC>
TC basic_array< TR, TC >::operator[] ( tint  n) const throw (cvmexception)
inline

Value of element (not l-value)

Returns value of array's element by its index (CVM0 based).

Example:
using namespace cvm;
try {
rvector v (10);
v[1] = 1.;
v(2) = 2.;
std::cout << v;
double a[] = {1., 2., 3., 4.};
const rvector vc (a, 4);
std::cout << vc(1) << " " << vc[2] << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
1 2 0 0 0 0 0 0 0 0
1 2
Parameters
[in]nIndex of element to return value for.
Returns
TC&

Reimplemented in basic_schmatrix< TR, TC >, basic_srsmatrix< TR >, basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, basic_scmatrix< TR, TC >, basic_cmatrix< TR, TC >, basic_srmatrix< TR >, and basic_rmatrix< TR >.

Definition at line 2458 of file cvm.h.

template<typename TR, typename TC>
basic_array& basic_array< TR, TC >::assign ( const TC *  p)
inline

Assignment from external array.

Assigns size() elements of external array to array.

Example:
using namespace cvm;
const int a[] = {1, 2, 3, 4, 5, 6, 7};
iarray v (5);
v.assign(a);
std::cout << v;
prints
1 2 3 4 5
Parameters
[in]pConst pointer to external array to be assigned.
See Also
operator=()
Returns
Reference to changed calling array.

Reimplemented in basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, basic_scmatrix< TR, TC >, basic_cmatrix< TR, TC >, basic_srmatrix< TR >, and basic_rmatrix< TR >.

Definition at line 2484 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
basic_array& basic_array< TR, TC >::set ( TC  x)
inline

Sets all elements to one value.

Sets all elements of array to be equal to given value.

Example:
using namespace cvm;
iarray a(5);
a.set(3);
std::cout << a;
prints
3 3 3 3 3
Parameters
[in]xValue to set to.
Returns
Reference to changed calling array.

Reimplemented in basic_srsmatrix< TR >, basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, basic_scmatrix< TR, TC >, basic_cmatrix< TR, TC >, basic_srmatrix< TR >, basic_rmatrix< TR >, basic_cvector< TR, TC >, and basic_rvector< TR >.

Definition at line 2509 of file cvm.h.

template<typename TR, typename TC>
basic_array& basic_array< TR, TC >::resize ( tint  nNewSize) throw (cvmexception)
inline

Changes size of array.

In case of size increase fills new elements with zeros.

Example:
using namespace cvm;
try {
const int a[] = {1, 2, 3, 4};
iarray v (a, 3);
std::cout << v;
v.resize(2);
std::cout << v;
v.resize(4);
std::cout << v;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 2 3
1 2
1 2 0 0
Parameters
[in]nNewSizeNew size.
Returns
Reference to changed calling array.

Reimplemented in basic_schmatrix< TR, TC >, basic_srsmatrix< TR >, basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, basic_scmatrix< TR, TC >, basic_srmatrix< TR >, basic_cvector< TR, TC >, and basic_rvector< TR >.

Definition at line 2545 of file cvm.h.

template<typename TR, typename TC>
tint basic_array< TR, TC >::incr ( ) const
inline

Increment between elements.

Returns increment (usually 1).

Example:
using namespace cvm;
double a[] = {1., 2., 3., 4., 5., 6.};
rvector v1 (a, 3, 2);
rvector v2(10);
std::cout << v1 << v1.incr () << std::endl;
std::cout << v2.incr () << std::endl;
prints
1 3 5
2
1
Returns
tint Increment value

Definition at line 2575 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
tint basic_array< TR, TC >::indofmax ( ) const
inline

Index of element with maximum module.

Index of element with maximum module. CVM0 based. Doesn't make much sense for matrices.

Example:
using namespace cvm;
double a[] = {3., 2., -5., -4., 5., -6.};
const rvector v (a, 4);
const rmatrix m (a, 2, 3);
std::cout << v << v.indofmax () << std::endl << std::endl;
std::cout << m << m.indofmax () << std::endl;
prints
3 2 -5 -4
3
3 -5 5
2 -4 -6
6
Returns
tint Increment value

Definition at line 2605 of file cvm.h.

template<typename TR, typename TC>
tint basic_array< TR, TC >::indofmin ( ) const
inline

Index of element with minimum module.

Index of element with minimum module. CVM0 based. Doesn't make much sense for matrices.

Example:
using namespace cvm;
double a[] = {3., 2., -5., 0., 0., -6.};
const rvector v (a, 4);
const rmatrix m (a, 2, 3);
std::cout << v << v.indofmin () << std::endl << std::endl;
std::cout << m << m.indofmin () << std::endl;
prints
3 2 -5 0
4
3 -5 0
2 0 -6
4
Returns
tint Increment value

Definition at line 2635 of file cvm.h.

template<typename TR, typename TC>
virtual TR basic_array< TR, TC >::norm ( ) const
inlinevirtual

Euclidean norm.

Euclidean norm of calling array that for vectors is defined as

\[ {\|x\|}_E=\left(\sum_{i=1}^{n} |x_i|^2\right)^{1/2} \]

and for matrices as

\[ {\|A\|}_E=\left(\sum_{i=1}^{m}\sum_{j=1}^{n} |a_{ij}|^2\right)^{1/2}, \]

Example:
using namespace cvm;
std::cout.setf (ios::scientific | ios::showpos);
std::cout.precision (12);
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norm () << std::endl << std::endl;
std::cout << m << m.norm () << std::endl;
prints
+1.000000000000e+000 +2.000000000000e+000 +3.000000000000e+000
+3.741657386774e+000
+1.000000000000e+000 +3.000000000000e+000 +5.000000000000e+000
+2.000000000000e+000 -4.000000000000e+000 -6.000000000000e+000
+9.539392014169e+000
Returns
treal Norm value

Reimplemented in basic_scbmatrix< TR, TC >, and basic_srbmatrix< TR >.

Definition at line 2674 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
virtual TR basic_array< TR, TC >::norminf ( ) const
inlinevirtual

Infinity norm.

Infinity norm of calling array that for vectors is defined as

\[ {\|x\|}_\infty=\max_{i=1,\dots,n} |x_i| \]

and for matrices as

\[ {\|A\|}_\infty=\max_{i=1,\dots,m} \sum_{j=1}^{n} |a_{ij}|, \]

Example:
using namespace cvm;
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norminf () << std::endl;
std::cout << m << m.norminf () << std::endl;
prints
1 2 3
3
1 3 5
2 -4 -6
12
Returns
treal Norm value

Reimplemented in basic_schmatrix< TR, TC >, basic_srsmatrix< TR >, basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, Matrix< TR, TC >, and Matrix< TR, TR >.

Definition at line 2711 of file cvm.h.

template<typename TR, typename TC>
virtual TR basic_array< TR, TC >::norm1 ( ) const
inlinevirtual

1-norm

1-norm of calling array that for vectors is defined as

\[ {\|x\|}_1=\sum_{i=1}^{n} |x_i| \]

and for matrices as

\[ {\|A\|}_{1}=\max_{j=1,\dots,n} \sum_{i=1}^{m} |a_{ij}|, \]

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (12);
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norm1 () << std::endl << std::endl;
std::cout << m << m.norm1 () << std::endl;
prints
+1.000000000000e+000 +2.000000000000e+000 +3.000000000000e+000
+6.000000000000e+000
+1.000000000000e+000 +3.000000000000e+000 +5.000000000000e+000
+2.000000000000e+000 -4.000000000000e+000 -6.000000000000e+000
+1.100000000000e+001
Returns
treal Norm value

Reimplemented in basic_scbmatrix< TR, TC >, basic_srbmatrix< TR >, Matrix< TR, TC >, and Matrix< TR, TR >.

Definition at line 2752 of file cvm.h.

template<typename TR, typename TC>
virtual TR basic_array< TR, TC >::norm2 ( ) const
inlinevirtual

2-norm

2-norm of calling array that for vectors is defined as

\[ {\|x\|}_2={\|x\|}_E=\left(\sum_{i=1}^{n} |x_i|^2\right)^{1/2} \]

and for matrices as

\[ {\|A\|}_2=\max_i\sigma_i = \left(\max_{|x|=1}\, (Ax\cdot Ax)\right)^{1/2}, \]

where $\sigma_i$ is $i$-th singular value of $m\times n$ matrix $A,\ i=1,\dots,\min(m,n)$.

Example:
using namespace cvm;
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (12);
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norm2 () << std::endl << std::endl;
std::cout << m << m.norm2 () << std::endl;
prints
+1.000000000000e+000 +2.000000000000e+000 +3.000000000000e+000
+3.741657386774e+000
+1.000000000000e+000 +3.000000000000e+000 +5.000000000000e+000
+2.000000000000e+000 -4.000000000000e+000 -6.000000000000e+000
+9.319612060784e+000
Returns
treal Norm value

Reimplemented in basic_cmatrix< TR, TC >, and basic_rmatrix< TR >.

Definition at line 2801 of file cvm.h.

template<typename TR, typename TC>
iterator basic_array< TR, TC >::begin ( )
inline

(STL) iterator to begin

Definition at line 2837 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
const_iterator basic_array< TR, TC >::begin ( ) const
inline

(STL) const iterator to begin

Definition at line 2839 of file cvm.h.

template<typename TR, typename TC>
iterator basic_array< TR, TC >::end ( )
inline

(STL) iterator to end

Definition at line 2841 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
const_iterator basic_array< TR, TC >::end ( ) const
inline

(STL) const iterator to end

Definition at line 2843 of file cvm.h.

template<typename TR, typename TC>
reverse_iterator basic_array< TR, TC >::rbegin ( )
inline

(STL) iterator to begin reversed

Definition at line 2846 of file cvm.h.

template<typename TR, typename TC>
const_reverse_iterator basic_array< TR, TC >::rbegin ( ) const
inline

(STL) const iterator to begin reversed

Definition at line 2848 of file cvm.h.

template<typename TR, typename TC>
reverse_iterator basic_array< TR, TC >::rend ( )
inline

(STL) iterator to end reversed

Definition at line 2850 of file cvm.h.

template<typename TR, typename TC>
const_reverse_iterator basic_array< TR, TC >::rend ( ) const
inline

(STL) const iterator to end reversed

Definition at line 2852 of file cvm.h.

template<typename TR, typename TC>
size_type basic_array< TR, TC >::max_size ( ) const
inline

(STL) maximum possible size of array

Definition at line 2855 of file cvm.h.

template<typename TR, typename TC>
size_type basic_array< TR, TC >::capacity ( ) const
inline

(STL) current capacity of array, equal to size()

Definition at line 2857 of file cvm.h.

template<typename TR, typename TC>
bool basic_array< TR, TC >::empty ( ) const
inline

(STL) is array empty

Definition at line 2859 of file cvm.h.

template<typename TR, typename TC>
reference basic_array< TR, TC >::front ( )
inline

(STL) reference to first element

Definition at line 2862 of file cvm.h.

template<typename TR, typename TC>
const_reference basic_array< TR, TC >::front ( ) const
inline

(STL) const reference to first element

Definition at line 2864 of file cvm.h.

template<typename TR, typename TC>
reference basic_array< TR, TC >::back ( )
inline

(STL) reference to last element

Definition at line 2866 of file cvm.h.

template<typename TR, typename TC>
const_reference basic_array< TR, TC >::back ( ) const
inline

(STL) const reference to last element

Definition at line 2868 of file cvm.h.

template<typename TR, typename TC>
void basic_array< TR, TC >::assign ( size_type  n,
const TC &  val 
) throw (cvmexception)
inline

(STL) assigns given value to n-th element (0-based)

Definition at line 2878 of file cvm.h.

template<typename TR, typename TC>
void basic_array< TR, TC >::assign ( const_iterator  begin,
const_iterator  end 
) throw (cvmexception)
inline

(STL) assigns begin-end iteartor range to array

Definition at line 2888 of file cvm.h.

template<typename TR, typename TC>
void basic_array< TR, TC >::clear ( )
inline

(STL) clears array, dealocates memory and sets size() to zero

Definition at line 2899 of file cvm.h.

template<typename TR, typename TC>
void basic_array< TR, TC >::swap ( basic_array< TR, TC > &  v) throw (cvmexception)
inline

(STL) swaps array values, throws cvmexception if sizes are different

Definition at line 2904 of file cvm.h.

template<typename TR, typename TC>
reference basic_array< TR, TC >::at ( size_type  n) throw (cvmexception)
inline

(STL) returns reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries

Definition at line 2911 of file cvm.h.

Here is the caller graph for this function:

template<typename TR, typename TC>
const_reference basic_array< TR, TC >::at ( size_type  n) const throw (cvmexception)
inline

(STL) returns const reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries

Definition at line 2919 of file cvm.h.

template<typename TR, typename TC>
void basic_array< TR, TC >::push_back ( const TC &  x) throw (cvmexception)
inline

(STL) pushes new value to the end of array

Increases array's size() by one, throws cvmexception in case of memory allocation failure. It's provided for every class of the library to be compatible with STL algorithms and methods. Since CVM doesn't pre-allocate memory for extra storage, these functions will require memory reallocation every time they are being executed and may slow down your application.

Example:
using namespace cvm;
iarray a(5);
a.push_back(77);
std::cout << a;
a.pop_back();
std::cout << a;
prints
0 0 0 0 0 77
0 0 0 0 0
Parameters
[in]xConst reference to value to push.

Definition at line 2953 of file cvm.h.

template<typename TR, typename TC>
void basic_array< TR, TC >::pop_back ( ) throw (cvmexception)
inline

(STL) removes last element from array

Decreases array's size() by one, throws cvmexception in case of memory allocation failure. It's provided for every class of the library to be compatible with STL algorithms and methods. Since CVM doesn't pre-allocate memory for extra storage, these functions will require memory reallocation every time they are being executed and may slow down your application.

Example:
using namespace cvm;
iarray a(5);
a.push_back(77);
std::cout << a;
a.pop_back();
std::cout << a;
prints
0 0 0 0 0 77
0 0 0 0 0

Definition at line 2985 of file cvm.h.

template<typename TR, typename TC>
iterator basic_array< TR, TC >::insert ( iterator  position,
const TC &  x 
) throw (cvmexception)
inline

(STL) inserts element to given position in array

Increases array's size() by one, throws cvmexception if position is out of boundaries or in case of memory allocation failure. Returns iterator to new element. Attention - function is provided for compatibility with STL algorithms and methods. Since CVM doesn't pre-allocate memory for extra storage, this function will require memory reallocation every time it's executed and may slow down your application.

See Also
http://www.sgi.com/tech/stl/
erase()
Parameters
[in]positionWhere to insert
[in]xReference to value to insert
Example:
using namespace cvm;
iarray a(5);
iarray::iterator pos = a.begin() + 2;
a.insert(pos, 77);
std::cout << a;
pos = a.begin() + 1;
a.erase(pos);
std::cout << a;
prints
0 0 77 0 0 0
0 77 0 0 0
Returns
iterator

Definition at line 3023 of file cvm.h.

template<typename TR, typename TC>
iterator basic_array< TR, TC >::erase ( iterator  position) throw (cvmexception)
inline

(STL) removes element from given position in array

Decreases array's size() by one, throws cvmexception if position is out of boundaries or in case of memory allocation failure. Returns iterator to removed element. Attention - function is provided for compatibility with STL algorithms and methods. Since CVM doesn't pre-allocate memory for extra storage, this function will require memory reallocation every time it's executed and may slow down your application.

See Also
http://www.sgi.com/tech/stl/
insert()
Parameters
[in]positionWhere to erase
Example:
using namespace cvm;
iarray a(5);
iarray::iterator pos = a.begin() + 2;
a.insert(pos, 77);
std::cout << a;
pos = a.begin() + 1;
a.erase(pos);
std::cout << a;
prints
0 0 77 0 0 0
0 77 0 0 0
Returns
iterator

Definition at line 3069 of file cvm.h.

Friends And Related Function Documentation

template<typename TR, typename TC>
std::istream& operator>> ( std::istream &  is,
basic_array< TR, TC > &  aIn 
)
friend

Inserts elements from input stream to array.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
std::ofstream os;
os.open ("in.txt");
os << 1.2 << " " << 2.3 << std::endl << 3.4;
os.close ();
std::ifstream is("in.txt");
rvector v(5);
is >> v;
std::cout << v;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.20e+000 2.30e+000 3.40e+000 0.00e+000 0.00e+000
Parameters
[in]isInput stream.
[in]aInbasic_array to fill.
Returns
Input stream
Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
std::ofstream os;
os.open ("in.txt");
os << 1.2 << " " << 2.3 << std::endl << 3.4;
os.close ();
std::ifstream is("in.txt");
rvector v(5);
is >> v;
std::cout << v;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.20e+000 2.30e+000 3.40e+000 0.00e+000 0.00e+000
Parameters
[in]isStream to read from.
[out]aInbasic_array to write to.
Returns
Reference to stream for further reading.

Definition at line 1061 of file cvm.h.

template<typename TR, typename TC>
std::ostream& operator<< ( std::ostream &  os,
const basic_array< TR, TC > &  aOut 
)
friend

Inserts elements of array to output stream.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
cvector v(3);
v(1) = tcomplex (1., 2.);
v(2) = tcomplex (3., 4.);
std::cout << v;
prints
(1.00e+000,2.00e+000) (3.00e+000,4.00e+000) (0.00e+000,0.00e+000)
Parameters
[in]osOutput stream.
[in]aOutbasic_array to send.
Returns
Output stream
Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
cvector v(3);
v(1) = tcomplex (1., 2.);
v(2) = tcomplex (3., 4.);
std::cout << v;
prints
(1.00e+000,2.00e+000) (3.00e+000,4.00e+000) (0.00e+000,0.00e+000)
Parameters
[out]osStream to write to.
[in]aOutbasic_array to write from.
Returns
Reference to stream for further writing.

Definition at line 1098 of file cvm.h.

Member Data Documentation

template<typename TR, typename TC>
tint basic_array< TR, TC >::msz
protected

Number of elements of type TC allocated.

Definition at line 1821 of file cvm.h.

template<typename TR, typename TC>
tint basic_array< TR, TC >::mincr
protected

Increment (distance) between elements (default is 1, i.e. elements follow each other)

Definition at line 1822 of file cvm.h.

template<typename TR, typename TC>
std::shared_ptr<TC> basic_array< TR, TC >::mp
protected

native data pointer

Definition at line 1827 of file cvm.h.

template<typename TR, typename TC>
TC* basic_array< TR, TC >::mpf
protected

Foreign data pointer.

Definition at line 1828 of file cvm.h.


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