<commit_before>// $Id$

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


#ifndef __lac_dsmatrix_h
#define __lac_dsmatrix_h

#include <math.h>
#ifndef __lac_dvector_h
#include <lac/dvector.h>
#endif
#ifndef __lac_ivector_h
#include <lac/ivector.h>
#endif

#include <base/exceptions.h>



class ostream;
template <int dim> class DoFHandler;

/*
CLASS
   dSMatrixStruct
   */
class dSMatrixStruct
{
  friend class dSMatrix;
  int max_dim;
  int rows, cols;
  int vec_len, max_vec_len;
  int max_row_len;
  int* rowstart;
  int* colnums;
  int compressed;

public:
  //////////
  void reinit(int m, int n, int max_per_row);
  //////////
  dSMatrixStruct(int m, int n, int max_per_row) 
    : max_dim(0), max_vec_len(0), rowstart(0), colnums(0)
      {
	reinit(m,n,max_per_row);
      }
  //////////
  dSMatrixStruct(int n, int max_per_row)
    : max_dim(0), max_vec_len(0), rowstart(0), colnums(0)
      {
	reinit(n,n,max_per_row);
      }
  //////////
  ~dSMatrixStruct()
    {
      delete[] rowstart;
      delete[] colnums;
    }
  //////////
  void compress();
  //////////
  int operator () (int i, int j);
  //////////
  void add(int i, int j);
  //////////
  void add_matrix(int n, int* rowcols);
  //////////
  void add_matrix(int m, int n, int* rows, int* cols);
  //////////
  void add_matrix(const iVector& rowcols);
  //////////
  void add_matrix(const iVector& rows, const iVector& cols);

  void print_gnuplot (ostream &) const;
  int n_rows () const {  return rows;   };
  int n_cols () const {  return cols;   };
  int bandwidth () const;

    friend class ConstraintMatrix;
    friend class DoFHandler<1>;
    friend class DoFHandler<2>;

				     /**
				      * Exception
				      */
    DeclException1 (ExcInvalidNumber,
		    int,
		    << "The provided number is invalid here: " << arg1);
    				     /**
				      * Exception
				      */
    DeclException2 (ExcInvalidIndex,
		    int, int,
		    << "The given index " << arg1
		    << " should be less than " << arg2 << ".");

};






/*
CLASS
   dSMatrix
   */
class dSMatrix
{
    dSMatrixStruct * cols;
    double* val;
    int max_len;
  public:

				     /**
				      * Constructor; initializes the matrix to be
				      * empty, without any structure, i.e. the
				      * matrix is not usable at all. This constructor
				      * is therefore only useful for matrices which
				      * are members of a class. You have to initialize
				      * the matrix before usage with
				      * #reinit(dSMatrixStruct)#.
				      */
    dSMatrix ();
    
				     //
    dSMatrix(dSMatrixStruct& c)
		    : cols(&c), val(0), max_len(0)
      {
	reinit();
      }
				     //
    ~dSMatrix()
      {
	delete[] val;
      }


				     //
    void reinit();
				     //
    void reinit (dSMatrixStruct &);

				     //
    int m() const { return cols->rows; }
				     //
    int n() const { return cols->cols; }

				     //
    void set(int i,int j,double value) { val[cols->operator()(i,j)] = value; }
				     //
    void add(int i,int j,double value) { val[cols->operator()(i,j)]+= value; }
  
				     //
    void vmult (dVector& dst,const dVector& src) const;
				     //
    void Tvmult(dVector& dst,const dVector& src) const;
  
				     //
    double residual (dVector& dst,const dVector& x,const dVector& b);
				     //
    void Jacobi_precond(dVector& dst,const dVector& src,double om = 1.);
				     //
    void SSOR_precond(dVector& dst,const dVector& src,double om = 1.);
				     //
    void SOR_precond(dVector& dst,const dVector& src,double om = 1.);
				     //
    void SSOR(dVector& dst,double om = 1.);
				     //
    void SOR(dVector& dst,double om = 1.);
				     //
    void precondition(dVector& dst,const dVector& src) { dst=src; }

    const dSMatrixStruct & get_sparsity_pattern () const;
    
    void print (ostream &) const;

				     /**
				      * Exception
				      */
    DeclException0 (ExcNotCompressed);
				     /**
				      * Exception
				      */
    DeclException0 (ExcMatrixNotInitialized);
				     /**
				      * Exception
				      */
    DeclException2 (ExcDimensionsDontMatch,
		    int, int,
		    << "The dimensions " << arg1 << " and " << arg2
		    << " do not match properly.");
    friend class ConstraintMatrix;
};
#endif<commit_msg>Perform bounds checking in dSMatrix<commit_after>// $Id$

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


#ifndef __lac_dsmatrix_h
#define __lac_dsmatrix_h

#include <math.h>
#ifndef __lac_dvector_h
#include <lac/dvector.h>
#endif
#ifndef __lac_ivector_h
#include <lac/ivector.h>
#endif

#include <base/exceptions.h>



class ostream;
template <int dim> class DoFHandler;

/*
CLASS
   dSMatrixStruct
   */
class dSMatrixStruct
{
  friend class dSMatrix;
  int max_dim;
  int rows, cols;
  int vec_len, max_vec_len;
  int max_row_len;
  int* rowstart;
  int* colnums;
  int compressed;

public:
  //////////
  void reinit(int m, int n, int max_per_row);
  //////////
  dSMatrixStruct(int m, int n, int max_per_row) 
    : max_dim(0), max_vec_len(0), rowstart(0), colnums(0)
      {
	reinit(m,n,max_per_row);
      }
  //////////
  dSMatrixStruct(int n, int max_per_row)
    : max_dim(0), max_vec_len(0), rowstart(0), colnums(0)
      {
	reinit(n,n,max_per_row);
      }
  //////////
  ~dSMatrixStruct()
    {
      delete[] rowstart;
      delete[] colnums;
    }
  //////////
  void compress();
  //////////
  int operator () (int i, int j);
  //////////
  void add(int i, int j);
  //////////
  void add_matrix(int n, int* rowcols);
  //////////
  void add_matrix(int m, int n, int* rows, int* cols);
  //////////
  void add_matrix(const iVector& rowcols);
  //////////
  void add_matrix(const iVector& rows, const iVector& cols);

  void print_gnuplot (ostream &) const;
  int n_rows () const {  return rows;   };
  int n_cols () const {  return cols;   };
  int bandwidth () const;

    friend class ConstraintMatrix;
    friend class DoFHandler<1>;
    friend class DoFHandler<2>;

				     /**
				      * Exception
				      */
    DeclException1 (ExcInvalidNumber,
		    int,
		    << "The provided number is invalid here: " << arg1);
    				     /**
				      * Exception
				      */
    DeclException2 (ExcInvalidIndex,
		    int, int,
		    << "The given index " << arg1
		    << " should be less than " << arg2 << ".");

};






/*
CLASS
   dSMatrix
   */
class dSMatrix
{
    dSMatrixStruct * cols;
    double* val;
    int max_len;
  public:

				     /**
				      * Constructor; initializes the matrix to be
				      * empty, without any structure, i.e. the
				      * matrix is not usable at all. This constructor
				      * is therefore only useful for matrices which
				      * are members of a class. You have to initialize
				      * the matrix before usage with
				      * #reinit(dSMatrixStruct)#.
				      */
    dSMatrix ();
    
				     //
    dSMatrix(dSMatrixStruct& c)
		    : cols(&c), val(0), max_len(0)
      {
	reinit();
      }
				     //
    ~dSMatrix()
      {
	delete[] val;
      }


				     //
    void reinit();
				     //
    void reinit (dSMatrixStruct &);

				     //
    int m() const { return cols->rows; }
				     //
    int n() const { return cols->cols; }

				     //
    void set(int i,int j,double value) {
      Assert (cols->operator()(i,j) != -1,
	      ExcInvalidIndex(i,j));
      val[cols->operator()(i,j)] = value;
    }
				     //
    void add(int i,int j,double value) {
      Assert (cols->operator()(i,j) != -1,
	      ExcInvalidIndex(i,j));
      val[cols->operator()(i,j)]+= value;
    }
  
				     //
    void vmult (dVector& dst,const dVector& src) const;
				     //
    void Tvmult(dVector& dst,const dVector& src) const;
  
				     //
    double residual (dVector& dst,const dVector& x,const dVector& b);
				     //
    void Jacobi_precond(dVector& dst,const dVector& src,double om = 1.);
				     //
    void SSOR_precond(dVector& dst,const dVector& src,double om = 1.);
				     //
    void SOR_precond(dVector& dst,const dVector& src,double om = 1.);
				     //
    void SSOR(dVector& dst,double om = 1.);
				     //
    void SOR(dVector& dst,double om = 1.);
				     //
    void precondition(dVector& dst,const dVector& src) { dst=src; }

    const dSMatrixStruct & get_sparsity_pattern () const;
    
    void print (ostream &) const;

				     /**
				      * Exception
				      */
    DeclException0 (ExcNotCompressed);
				     /**
				      * Exception
				      */
    DeclException0 (ExcMatrixNotInitialized);
				     /**
				      * Exception
				      */
    DeclException2 (ExcDimensionsDontMatch,
		    int, int,
		    << "The dimensions " << arg1 << " and " << arg2
		    << " do not match properly.");
				     /**
				      * Exception
				      */
    DeclException2 (ExcInvalidIndex,
		    int, int,
		    << "The entry with index <" << arg1 << ',' << arg2
		    << "> does not exist.");

  friend class ConstraintMatrix;
};
#endif
{'fraction_non_alphanumeric': 0.1482138895052141, 'fraction_numerical': 0.007432882183270468, 'mean_word_length': 1.9203109815354713, 'pattern_counts': {'":': 0, '<': 82, '<?xml version=': 0, '>': 34, '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': '2212201', 'n_tokens_mistral': 3474, 'n_tokens_neox': 2997, 'n_words': 763}