45 #include "DenseLinAlgPack_DMatrixClass.hpp"
47 namespace DenseLinAlgPack {
52 DVectorSlice DMatrixSlice::p_diag(difference_type k)
const {
54 validate_col_subscript(k+1);
60 validate_row_subscript(-k+1);
61 return DVectorSlice( const_cast<value_type*>(
col_ptr(1)) - k
65 EOverLap DMatrixSlice::overlap(
const DMatrixSlice& gms)
const
67 typedef DMatrixSlice::size_type
size_type;
69 const DVectorSlice::value_type
71 *raw_ptr2 = gms.col_ptr(1);
73 if( !raw_ptr1 || !raw_ptr2 )
76 DVectorSlice::size_type
78 max_rows2 = gms.max_rows(),
85 if(raw_ptr1 > raw_ptr2) {
86 std::swap(raw_ptr1,raw_ptr2);
87 std::swap(max_rows1,max_rows2);
88 std::swap(rows1,rows2);
89 std::swap(cols1,cols2);
92 if( raw_ptr2 > (raw_ptr1 + (cols1 - 1) * max_rows1 + (rows1 - 1)) ) {
96 DVectorSlice::size_type
98 start2 = raw_ptr2 - raw_ptr1;
100 if(start1 == start2 && max_rows1 == max_rows2 && rows1 == rows2 && cols1 == cols2)
102 if(start1 + (rows1 - 1) + (cols1 - 1) * max_rows1 < start2)
109 size_type row_i = (start2 - start1 + 1) % max_rows1;
113 size_type lower_rows = max_rows1 - (start1 % max_rows1 + rows1);
114 if(row_i < rows1 + lower_rows)
118 if(row_i + rows2 - 1 <= max_rows1)
123 #ifdef LINALGPACK_CHECK_RANGE
124 void DMatrixSlice::validate_row_subscript(size_type i)
const
126 if( i >
rows() || !i )
127 throw std::out_of_range(
"DMatrixSlice::validate_row_subscript(i) :"
128 "row index i is out of bounds" );
132 #ifdef LINALGPACK_CHECK_RANGE
133 void DMatrixSlice::validate_col_subscript(size_type j)
const
135 if( j >
cols() || !j )
136 throw std::out_of_range(
"DMatrixSlice::validate_col_subscript(j) :"
137 "column index j is out of bounds" );
141 #ifdef LINALGPACK_CHECK_SLICE_SETUP
142 void DMatrixSlice::validate_setup(size_type size)
const
147 throw std::out_of_range(
"DMatrixSlice::validate_setup() : "
148 " DMatrixSlice constructed that goes past end of array" );
155 DVectorSlice DMatrix::p_diag(difference_type k)
const {
157 validate_col_subscript(k+1);
159 return DVectorSlice( const_cast<value_type*>(
col_ptr(1)) + k *
rows()
163 validate_row_subscript(-k+1);
164 return DVectorSlice( const_cast<value_type*>(
col_ptr(1)) - k
168 EOverLap DMatrix::overlap(
const DMatrixSlice& gms)
const {
169 return (*
this)().overlap(gms);
172 #ifdef LINALGPACK_CHECK_RANGE
173 void DMatrix::validate_row_subscript(size_type i)
const {
174 if( i >
rows() || !i )
175 throw std::out_of_range(
"DMatrix::validate_row_subscript(i) : row index out of bounds");
179 #ifdef LINALGPACK_CHECK_RANGE
180 void DMatrix::validate_col_subscript(size_type j)
const {
181 if( j >
cols() || !j )
182 throw std::out_of_range(
"DMatrix::validate_col_subscript(j) : column index out of bounds");
191 void DenseLinAlgPack::assert_gms_sizes(
const DMatrixSlice& gms1,
BLAS_Cpp::Transp trans1
196 gms1.rows() == gms2.rows() && gms1.cols() == gms2.cols()
197 : gms1.rows() == gms2.cols() && gms1.cols() == gms2.rows()
201 throw std::length_error(
"Matrix sizes are not the compatible");
value_type * col_ptr(size_type j)
size_type cols() const
Return the number of columns.
size_type max_rows() const
Return the number of rows in the full matrix. Equivalent to BLAS LDA argument.
size_type rows() const
Return the number of rows.
value_type * col_ptr(size_type j)
size_type rows() const
Return the number of rows.
size_type cols() const
Return the number of columns.