Разреженные матрицыШаблонный класс mapped_matrix<T, F, A> является базовым контейнером-адаптером для разреженных матриц, использующих элементные отображения.
Для (m xn)-размерной разреженной матрицы и 0 <= i < m,
0 <= j < n ненулевые элементы mi, j отображаются через (i x n +
j) при ориентации через главную строку или через (i + j x m) при ориентации через главный столбец в последовательные элементы ассоциативного (сочетательного) контейнера, т. е. для элементов контейнера k = mi1
,j1 и k + 1 =
mi2
,j2  элементами являются
i1 <
i2 или (i1
= i2 и
j1 <
j2) при ориентации через главную строку или
j1 <
j2 или (j1
= j2 и
i1 <
i2) при ориентации через главный столбец.
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
    using namespace boost::numeric::ublas;
    mapped_matrix<double> m (3, 3, 3 * 3);
    for (unsigned i = 0; i < m.size1 (); ++ i)
        for (unsigned j = 0; j < m.size2 (); ++ j)
            m (i, j) = 3 * i + j;
    std::cout << m << std::endl;
}
Будет выведено на экран:
[3,3]((0,1,2),(3,4,5),(6,7,8))
Определен в заголовочном файле matrix_sparse.hpp.
| Параметр | Описание | Значение по-умолчанию | 
|---|---|---|
T | 
Тип объектов, размещаемых в отображенной матрице. | |
F | 
Функция, определяющая организацию хранения. [1] | row_major | 
A | 
Тип приспособленного (adapted) массива. [2] | map_std<std::size_t, T> | 
Для которых базовый класс матрица (matrix) .
matrix_container<mapped_matrix<T, F, A>
>
Приведенные ниже функции-члены в основном аналогичны функциям, перевод которым дан в разделе матрица. Характерные только для mapped_matrix функции-члены переведены в таблице ниже.
| Функция-член | Описание | 
|---|---|
mapped_matrix () | 
Создает mapped_matrix размером "0" строк и "0" столбцов. | 
mapped_matrix (size_type size1, size_type2, size_type non_zeros = 0) | 
Allocates a mapped_matrix that holds at most
size1 rows of size2 elements. | 
mapped_matrix (const mapped_matrix &m) | 
The copy constructor. | 
template<class AE> | 
The extended copy constructor. | 
void resize (size_type size1, size_type size2, bool preserve = true) | 
Reallocates a mapped_matrix to hold at most
size1 rows of size2 elements. The
existing elements of the mapped_matrix are preseved
when specified. | 
size_type size1 () const | 
Returns the number of rows. | 
size_type size2 () const | 
Returns the number of columns. | 
const_reference operator () (size_type i, size_type j)
const | 
Returns the value of the j-th element in the
i-th row. | 
reference operator () (size_type i, size_type
j) | 
Returns a reference of the j-th element in the
i-th row. | 
mapped_matrix &operator = (const mapped_matrix
&m) | 
The assignment operator. | 
mapped_matrix &assign_temporary (mapped_matrix
&m) | 
Assigns a temporary. May change the mapped matrix
m . | 
template<class AE> | 
The extended assignment operator. | 
template<class AE> | 
Assigns a matrix expression to the mapped matrix. Left and right hand side of the assignment should be independent. | 
template<class AE> | 
A computed assignment operator. Adds the matrix expression to the mapped matrix. | 
template<class AE> | 
Adds a matrix expression to the mapped matrix. Left and right hand side of the assignment should be independent. | 
template<class AE> | 
A computed assignment operator. Subtracts the matrix expression from the mapped matrix. | 
template<class AE> | 
Subtracts a matrix expression from the mapped matrix. Left and right hand side of the assignment should be independent. | 
template<class AT> | 
A computed assignment operator. Multiplies the mapped matrix with a scalar. | 
template<class AT> | 
A computed assignment operator. Divides the mapped matrix through a scalar. | 
void swap (mapped_matrix &m) | 
Swaps the contents of the mapped matrices. | 
true_refrence insert_element (size_type i, size_type j, const_reference
t) | 
Вставляет значение t в j-ый
элемент i-ой строки. Повтор элементов не допустим. | 
void erase_element (size_type i, size_type j) | 
Erases the value at the j-th element of the
i-th row. | 
void clear () | 
Clears the mapped matrix. | 
const_iterator1 begin1 () const | 
Returns a const_iterator1 pointing to the
beginning of the mapped_matrix. | 
const_iterator1 end1 () const | 
Returns a const_iterator1 pointing to the end of
the mapped_matrix. | 
iterator1 begin1 () | 
Returns a iterator1 pointing to the beginning of
the mapped_matrix. | 
iterator1 end1 () | 
Returns a iterator1 pointing to the end of the
mapped_matrix. | 
const_iterator2 begin2 () const | 
Returns a const_iterator2 pointing to the
beginning of the mapped_matrix. | 
const_iterator2 end2 () const | 
Returns a const_iterator2 pointing to the end of
the mapped_matrix. | 
iterator2 begin2 () | 
Returns a iterator2 pointing to the beginning of
the mapped_matrix. | 
iterator2 end2 () | 
Returns a iterator2 pointing to the end of the
mapped_matrix. | 
const_reverse_iterator1 rbegin1 () const | 
Returns a const_reverse_iterator1 pointing to the
beginning of the reversed mapped_matrix. | 
const_reverse_iterator1 rend1 () const | 
Returns a const_reverse_iterator1 pointing to the
end of the reversed mapped_matrix. | 
reverse_iterator1 rbegin1 () | 
Returns a reverse_iterator1 pointing to the
beginning of the reversed mapped_matrix. | 
reverse_iterator1 rend1 () | 
Returns a reverse_iterator1 pointing to the end of
the reversed mapped_matrix. | 
const_reverse_iterator2 rbegin2 () const | 
Returns a const_reverse_iterator2 pointing to the
beginning of the reversed mapped_matrix. | 
const_reverse_iterator2 rend2 () const | 
Returns a const_reverse_iterator2 pointing to the
end of the reversed mapped_matrix. | 
reverse_iterator2 rbegin2 () | 
Returns a reverse_iterator2 pointing to the
beginning of the reversed mapped_matrix. | 
reverse_iterator2 rend2 () | 
Returns a reverse_iterator2 pointing to the end of
the reversed mapped_matrix. | 
[1] Поддерживаемые параметры организации хранения: row_major и column_major.
[2] Поддерживаемые параметры приспособленного массива:
map_array<std::size_t, T> и map_std<std::size_t, T>. Последнее выражение эквивалентно std::map<std::size_t, T>.
Шаблонный класс compressed_matrix<T, F, IB, IA,
TA> является базовым контейнером-адаптером для сжатых матриц. Для (m x n)-размерной сжатой матрицы и 0 <= i < m, 0 <= j < n ненулевые элементы mi, j отображаются через (i x n + j) при ориентации через главную строку или через (i + j x m)
при ориентации через главный столбец в последовательные элементы контейнеров индекса и значения, т. е. для элементов контейнера k = mi1
,j1 и k + 1 =
mi2
,j2 элементами являются
i1 <
i2 or (i1
= i2 и
j1 <
j2) при ориентации через главную строку или
j1 <
j2 или (j1
= j2 и
i1 <
i2) при ориентации через главный столбец.
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
    using namespace boost::numeric::ublas;
    compressed_matrix<double> m (3, 3, 3 * 3);
    for (unsigned i = 0; i < m.size1 (); ++ i)
        for (unsigned j = 0; j < m.size2 (); ++ j)
            m (i, j) = 3 * i + j;
    std::cout << m << std::endl;
}
Будет выведено на экран:
[3,3]((0,1,2),(3,4,5),(6,7,8))
Определен в заголовочном matrix_sparse.hpp.
| Параметр | Описание | Значение по-умолчанию | 
|---|---|---|
T | 
Тип объектов, размещаемых в матрице. | |
F | 
Функция, определяющая организацию хранения. [1] | row_major | 
IB | 
Индекс начала отсчета координатного вектора. [2] | 0 | 
IA | 
Тип приспособленного (adapted) массива для индексов. [3] | unbounded_array<std::size_t> | 
TA | 
Тип приспособленного (adapted) массива для значений. [3] | unbounded_array<T> | 
Matrix .
Для которых базовый класс Matrix .
matrix_container<compressed_matrix<T, F, IB, IA,
TA> >
Приведенные ниже функции-члены в основном аналогичны функциям, перевод которым дан в разделе матрица. Характерные только для compressed_matrix функции-члены переведены в таблице ниже.
| Функция-член | Описание | 
|---|---|
compressed_matrix () | 
Allocates a compressed_matrix that holds at most
zero rows of zero elements. | 
compressed_matrix (size_type size1, size_type2, size_type non_zeros = 0) | 
Allocates a compressed_matrix that holds at most
size1 rows of size2 elements. | 
compressed_matrix (const compressed_matrix
&m) | 
The copy constructor. | 
template<class AE> | 
The extended copy constructor. | 
void resize (size_type size1, size_type size2, bool preserve = true) | 
Reallocates a compressed_matrix to hold at most
size1 rows of size2 elements. The
existing elements of the compressed_matrix are
preseved when specified. | 
size_type size1 () const | 
Returns the number of rows. | 
size_type size2 () const | 
Returns the number of columns. | 
const_reference operator () (size_type i, size_type j)
const | 
Returns the value of the j-th element in the
i-th row. | 
reference operator () (size_type i, size_type
j) | 
Returns a reference of the j-th element in the
i-th row. | 
compressed_matrix &operator = (const
compressed_matrix &m) | 
The assignment operator. | 
compressed_matrix &assign_temporary
(compressed_matrix &m) | 
Assigns a temporary. May change the compressed matrix
m. | 
template<class AE> | 
The extended assignment operator. | 
template<class AE> | 
Assigns a matrix expression to the compressed matrix. Left and right hand side of the assignment should be independent. | 
template<class AE> | 
A computed assignment operator. Adds the matrix expression to the compressed matrix. | 
template<class AE> | 
Adds a matrix expression to the compressed matrix. Left and right hand side of the assignment should be independent. | 
template<class AE> | 
A computed assignment operator. Subtracts the matrix expression from the compressed matrix. | 
template<class AE> | 
Subtracts a matrix expression from the compressed matrix. Left and right hand side of the assignment should be independent. | 
template<class AT> | 
A computed assignment operator. Multiplies the compressed matrix with a scalar. | 
template<class AT> | 
A computed assignment operator. Divides the compressed matrix through a scalar. | 
void swap (compressed_matrix &m) | 
Swaps the contents of the compressed matrices. | 
true_reference insert_element (size_type i, size_type j, const_reference
t) | 
Вставляет значение t в j-ый
элемент i-ой строки. Повтор элементов не допустим. | 
void erase_element (size_type i, size_type j) | 
Erases the value at the j-th element of the
i-th row. | 
void clear () | 
Clears the compressed matrix. | 
const_iterator1 begin1 () const | 
Returns a const_iterator1 pointing to the
beginning of the compressed_matrix. | 
const_iterator1 end1 () const | 
Returns a const_iterator1 pointing to the end of
the compressed_matrix. | 
iterator1 begin1 () | 
Returns a iterator1 pointing to the beginning of
the compressed_matrix. | 
iterator1 end1 () | 
Returns a iterator1 pointing to the end of the
compressed_matrix. | 
const_iterator2 begin2 () const | 
Returns a const_iterator2 pointing to the
beginning of the compressed_matrix. | 
const_iterator2 end2 () const | 
Returns a const_iterator2 pointing to the end of
the compressed_matrix. | 
iterator2 begin2 () | 
Returns a iterator2 pointing to the beginning of
the compressed_matrix. | 
iterator2 end2 () | 
Returns a iterator2 pointing to the end of the
compressed_matrix. | 
const_reverse_iterator1 rbegin1 () const | 
Returns a const_reverse_iterator1 pointing to the
beginning of the reversed compressed_matrix. | 
const_reverse_iterator1 rend1 () const | 
Returns a const_reverse_iterator1 pointing to the
end of the reversed compressed_matrix. | 
reverse_iterator1 rbegin1 () | 
Returns a reverse_iterator1 pointing to the
beginning of the reversed compressed_matrix. | 
reverse_iterator1 rend1 () | 
Returns a reverse_iterator1 pointing to the end of
the reversed compressed_matrix. | 
const_reverse_iterator2 rbegin2 () const | 
Returns a const_reverse_iterator2 pointing to the
beginning of the reversed compressed_matrix. | 
const_reverse_iterator2 rend2 () const | 
Returns a const_reverse_iterator2 pointing to the
end of the reversed compressed_matrix. | 
reverse_iterator2 rbegin2 () | 
Returns a reverse_iterator2 pointing to the
beginning of the reversed compressed_matrix. | 
reverse_iterator2 rend2 () | 
Returns a reverse_iterator2 pointing to the end of
the reversed compressed_matrix. | 
[1]
Поддерживаемые параметры организации хранения:
row_major и column_major.
[2]
Поддерживаемые параметры для индекса начала отсчета: 0 и по крайней мере
1.
[3]
Поддерживаемые параметры для приспособленного (adapted) массива:
unbounded_array<> ,
bounded_array<> и
std::vector<> .
Шаблонный класс coordinate_matrix<T, F, IB, IA,
TA> является базовым контейнером-адаптером для сжатых матриц. Для (m x n)-размерной сортированной матрицы и 0 <= i < m, 0 <= j < n ненулевые элементы mi, j отображаются через (i x n + j) при ориентации через главную строку или через (i + j x m) при ориентации через главный столбец в последовательные элементы контейнеров индекса и значения, т. е. для элементов контейнера k =
mi1
,j1 и k + 1 =
mi2
,j2 элементами являются
i1 <
i2 или (i1
= i2 и
j1 <
j2) при ориентации через главную строку или
j1 <
j2 или (j1
= j2 или
i1 <
i2) при ориентации через главный столбец.
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
    using namespace boost::numeric::ublas;
    coordinate_matrix<double> m (3, 3, 3 * 3);
    for (unsigned i = 0; i < m.size1 (); ++ i)
        for (unsigned j = 0; j < m.size2 (); ++ j)
            m (i, j) = 3 * i + j;
    std::cout << m << std::endl;
}
Будет выведено на экран:
[3,3]((0,1,2),(3,4,5),(6,7,8))
Определен в заголовочном файле matrix_sparse.hpp.
| Параметр | Описание | Значение по-умолчанию | 
|---|---|---|
T | 
Тип объектов, размещаемых в матрице. | |
F | 
Функция, определяющая организацию хранения. [1] | row_major | 
IB | 
Индекс начала отсчета координатной матрицы. [2] | 0 | 
IA | 
Тип приспособленного (adapted) массива для индексов. [3] | unbounded_array<std::size_t> | 
TA | 
Тип приспособленного (adapted) массива для значений. [3] | unbounded_array<T> | 
Matrix .
Для которых базовый класс Matrix .
matrix_container<coordinate_matrix<T, F, IB, IA,
TA> >
Приведенные ниже функции-члены в основном аналогичны функциям, перевод которым дан в разделе матрица. Характерные только для coordinate_matrix функции-члены переведены в таблице ниже.
| Функция-член | Описание | 
|---|---|
coordinate_matrix () | 
Allocates a coordinate_matrix that holds at most
zero rows of zero elements. | 
coordinate_matrix (size_type size1, size_type2, size_type non_zeros = 0) | 
Allocates a coordinate_matrix that holds at most
size1 rows of size2 elements. | 
coordinate_matrix (const coordinate_matrix
&m) | 
The copy constructor. | 
template<class AE> | 
The extended copy constructor. | 
void resize (size_type size1, size_type size2, bool preserve = true) | 
Reallocates a coordinate_matrix to hold at most
size1 rows of size2 elements. The
existing elements of the coordinate_matrix are
preseved when specified. | 
size_type size1 () const | 
Returns the number of rows. | 
size_type size2 () const | 
Returns the number of columns. | 
const_reference operator () (size_type i, size_type j)
const | 
Returns the value of the j-th element in the
i-th row. | 
reference operator () (size_type i, size_type
j) | 
Returns a reference of the j-th element in the
i-th row. | 
coordinate_matrix &operator = (const
coordinate_matrix &m) | 
The assignment operator. | 
coordinate_matrix &assign_temporary
(coordinate_matrix &m) | 
Assigns a temporary. May change the coordinate matrix
m. | 
template<class AE> | 
The extended assignment operator. | 
template<class AE> | 
Assigns a matrix expression to the coordinate matrix. Left and right hand side of the assignment should be independent. | 
template<class AE> | 
A computed assignment operator. Adds the matrix expression to the coordinate matrix. | 
template<class AE> | 
Adds a matrix expression to the coordinate matrix. Left and right hand side of the assignment should be independent. | 
template<class AE> | 
A computed assignment operator. Subtracts the matrix expression from the coordinate matrix. | 
template<class AE> | 
Subtracts a matrix expression from the coordinate matrix. Left and right hand side of the assignment should be independent. | 
template<class AT> | 
A computed assignment operator. Multiplies the coordinate matrix with a scalar. | 
template<class AT> | 
A computed assignment operator. Divides the coordinate matrix through a scalar. | 
void swap (coordinate_matrix &m) | 
Swaps the contents of the coordinate matrices. | 
true_reference insert_element (size_type i, size_type j, const_reference
t) | 
Вставляет значение t в j-ый
элемент i-ой строки. Повтор элементов не допустим. | 
void append_element (size_type i, size_type j, const_reference t) | 
Appends the value t at the j-th element of the i-th row.
Duplicate elements can be appended to a coordinate_matrix. They are merged into a single
arithmetically summed element by the sort function. | 
void erase_element (size_type i, size_type j) | 
Erases the value at the j-th element of the
i-th row. | 
void clear () | 
Clears the coordinate matrix. | 
const_iterator1 begin1 () const | 
Returns a const_iterator1 pointing to the
beginning of the coordinate_matrix. | 
const_iterator1 end1 () const | 
Returns a const_iterator1 pointing to the end of
the coordinate_matrix. | 
iterator1 begin1 () | 
Returns a iterator1 pointing to the beginning of
the coordinate_matrix. | 
iterator1 end1 () | 
Returns a iterator1 pointing to the end of the
coordinate_matrix. | 
const_iterator2 begin2 () const | 
Returns a const_iterator2 pointing to the
beginning of the coordinate_matrix. | 
const_iterator2 end2 () const | 
Returns a const_iterator2 pointing to the end of
the coordinate_matrix. | 
iterator2 begin2 () | 
Returns a iterator2 pointing to the beginning of
the coordinate_matrix. | 
iterator2 end2 () | 
Returns a iterator2 pointing to the end of the
coordinate_matrix. | 
const_reverse_iterator1 rbegin1 () const | 
Returns a const_reverse_iterator1 pointing to the
beginning of the reversed coordinate_matrix. | 
const_reverse_iterator1 rend1 () const | 
Returns a const_reverse_iterator1 pointing to the
end of the reversed coordinate_matrix. | 
reverse_iterator1 rbegin1 () | 
Returns a reverse_iterator1 pointing to the
beginning of the reversed coordinate_matrix. | 
reverse_iterator1 rend1 () | 
Returns a reverse_iterator1 pointing to the end of
the reversed coordinate_matrix. | 
const_reverse_iterator2 rbegin2 () const | 
Returns a const_reverse_iterator2 pointing to the
beginning of the reversed coordinate_matrix. | 
const_reverse_iterator2 rend2 () const | 
Returns a const_reverse_iterator2 pointing to the
end of the reversed coordinate_matrix. | 
reverse_iterator2 rbegin2 () | 
Returns a reverse_iterator2 pointing to the
beginning of the reversed coordinate_matrix. | 
reverse_iterator2 rend2 () | 
Returns a reverse_iterator2 pointing to the end of
the reversed coordinate_matrix. | 
[1]
Поддерживаемые параметры организации хранения:
row_major и column_major.
[2]
Поддерживаемые параметры для индекса начала отсчета: 0 и по крайней мере
1.
[3]
Поддерживаемые параметры для приспособленного (adapted) массива:
unbounded_array<> ,
bounded_array<> и
std::vector<> .
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Permission to copy, use, modify, sell and distribute this document
is granted provided this copyright notice appears in all copies.
This document is provided ``as is'' without express or implied
warranty, and with no claim as to its suitability for any
purpose.
Перевод с оригинала: Кулиш. В. И. 2006 год.