Skip to content
Snippets Groups Projects
Commit 3acd94ae authored by Lukas Cejka's avatar Lukas Cejka Committed by Tomáš Oberhuber
Browse files

Added checking for negative number of elements, in case of int overflow. Debugging prints included.

parent 0b132c07
No related branches found
No related tags found
1 merge request!45Matrices revision
......@@ -109,6 +109,20 @@ template< typename Real,
typename Index >
void Sparse< Real, Device, Index >::allocateMatrixElements( const IndexType& numberOfMatrixElements )
{
std::cout << " Allocating matrix elements..." << std::endl;
// CHECKING: if the number of matrix elements is larger than the highest number the IndexType can go to?
// INT OVERFLOW
// CORRECT? ELL stores certain matrices in such a way, which could cause the number of matrix elements
// to be greater than the maximum value IndexType can store, thus causing int overflow when
// creating the arrays "values" and "indexes".
// PROBLEM: int can overflow in such a way that it is still positive, thus rendering this assert useless.
// HOW FIX? Do we have to create special conditions for every format in its allocation method? We can't
// tell from within this method, if numberOfMatrixElements is an overflown value or not.
TNL_ASSERT_GE( numberOfMatrixElements, 0, "Number of matrix elements must be non-negative." );
std::cout << " numberOfMatrixElements = " << numberOfMatrixElements << std::endl;
this->values.setSize( numberOfMatrixElements );
this->columnIndexes.setSize( numberOfMatrixElements );
......@@ -118,6 +132,8 @@ void Sparse< Real, Device, Index >::allocateMatrixElements( const IndexType& num
*/
if( numberOfMatrixElements > 0 )
this->columnIndexes.setValue( this->columns );
std::cout << "->END OF allocateMatrixElements!!!" << std::endl;
}
template< typename Real,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment