<commit_before>// $Id$

// This file is part of the DEAL Library
// DEAL is Copyright(1995) by
// <NAME>, <NAME>, <NAME>

#include <lac/dsmatrix.h>
#include <lac/dvector.h>
#include <lac/ivector.h>

#include <iostream>
#include <iomanip>
#include <algorithm>



dSMatrixStruct::dSMatrixStruct () :
		max_dim(0),
		max_vec_len(0),
		rowstart(0),
		colnums(0)
{
  reinit (0,0,0);
};



dSMatrixStruct::dSMatrixStruct (const unsigned int m, const unsigned int n,
				const unsigned int max_per_row) 
		: max_dim(0),
		  max_vec_len(0),
		  rowstart(0),
		  colnums(0)
{
  reinit (m,n,max_per_row);
};



dSMatrixStruct::dSMatrixStruct (const unsigned int n,
				const unsigned int max_per_row)
		: max_dim(0),
		  max_vec_len(0),
		  rowstart(0),
		  colnums(0)
{
  reinit (n,n,max_per_row);
};



dSMatrixStruct::~dSMatrixStruct ()
{
  if (rowstart != 0)  delete[] rowstart;
  if (colnums != 0)   delete[] colnums;
}




void
dSMatrixStruct::reinit (const unsigned int m, const unsigned int n,
			const unsigned int max_per_row)
{
  Assert ((max_per_row>0) || ((m==0) && (n==0)), ExcInvalidNumber(max_per_row));
  rows = m;
  cols = n;
  vec_len = m * max_per_row;
  max_row_len = max_per_row;

  if (m*n == 0)
    {
      if (rowstart)  delete[] rowstart;
      if (colnums)   delete[] colnums;
      rowstart = 0;
      colnums = 0;
      max_vec_len = vec_len = max_dim = rows = cols = 0;
      compressed = false;
      return;
    };
  
  if (rows > max_dim)
    {
      if (rowstart) delete[] rowstart;
      max_dim = rows;
      rowstart = new unsigned int[max_dim+1];
    };
  
  if (vec_len > max_vec_len)
    {
      if (colnums) delete[] colnums;
      max_vec_len = vec_len;
      colnums = new int[max_vec_len];
    };
  <commit_msg>Fix a stupid bug triggered by Ralf: we delete the memory of a matrix if its size is reset to zero. We check so by comparing the number of elements, which is m*n against zero. Annoyingly, m*n equals zero also, if m=n=2**16...<commit_after>// $Id$

// This file is part of the DEAL Library
// DEAL is Copyright(1995) by
// <NAME>, <NAME>, <NAME>

#include <lac/dsmatrix.h>
#include <lac/dvector.h>
#include <lac/ivector.h>

#include <iostream>
#include <iomanip>
#include <algorithm>



dSMatrixStruct::dSMatrixStruct () :
		max_dim(0),
		max_vec_len(0),
		rowstart(0),
		colnums(0)
{
  reinit (0,0,0);
};



dSMatrixStruct::dSMatrixStruct (const unsigned int m, const unsigned int n,
				const unsigned int max_per_row) 
		: max_dim(0),
		  max_vec_len(0),
		  rowstart(0),
		  colnums(0)
{
  reinit (m,n,max_per_row);
};



dSMatrixStruct::dSMatrixStruct (const unsigned int n,
				const unsigned int max_per_row)
		: max_dim(0),
		  max_vec_len(0),
		  rowstart(0),
		  colnums(0)
{
  reinit (n,n,max_per_row);
};



dSMatrixStruct::~dSMatrixStruct ()
{
  if (rowstart != 0)  delete[] rowstart;
  if (colnums != 0)   delete[] colnums;
}




void
dSMatrixStruct::reinit (const unsigned int m, const unsigned int n,
			const unsigned int max_per_row)
{
  Assert ((max_per_row>0) || ((m==0) && (n==0)), ExcInvalidNumber(max_per_row));
  rows = m;
  cols = n;
  vec_len = m * max_per_row;
  max_row_len = max_per_row;

				   // delete empty matrices
  if ((m==0) || (n==0))
    {
      if (rowstart)  delete[] rowstart;
      if (colnums)   delete[] colnums;
      rowstart = 0;
      colnums = 0;
      max_vec_len = vec_len = max_dim = rows = cols = 0;
      compressed = false;
      return;
    };
  
  if (rows > max_dim)
    {
      if (rowstart) delete[] rowstart;
      max_dim = rows;
      rowstart = new unsigned int[max_dim+1];
    };
  
  if (vec_len > max_vec_len)
    {
      if (colnums) delete[] colnums;
      max_vec_len = vec_len;
      colnums = new int[max_vec_len];
    };
  
{'fraction_non_alphanumeric': 0.13900026730820636, 'fraction_numerical': 0.01657310879443999, 'mean_word_length': 3.076252723311547, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '792688', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1465, 'n_words': 360}