<commit_before>//----------------------------  full_matrix.templates.h  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------  full_matrix.templates.h  ---------------------------
#ifndef __deal2__full_matrix_templates_h
#define __deal2__full_matrix_templates_h


#include <lac/vector.h>
#include <lac/full_matrix.h>

#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>


template <typename number>
FullMatrix<number>::FullMatrix (const unsigned int n) :
		val (0),
		dim_range (0),
		dim_image (0),
		val_size (0)
{
  reinit (n,n);
};


template <typename number>
FullMatrix<number>::FullMatrix (const unsigned int m,
				const unsigned int n) :
		val (0),
		dim_range (0),
		dim_image (0),
		val_size (0)
{
  reinit (m,n);
};


template <typename number>
FullMatrix<number>::FullMatrix (const FullMatrix &m) :
		Subscriptor (),
		val (0),
		dim_range (0),
		dim_image (0),
		val_size (0)
{
  reinit (m.dim_image, m.dim_range);
  if (dim_range*dim_image != 0)
    copy (&m.val[0], &m.val[dim_image*dim_range],
	  &val[0]);
};


template <typename number>
FullMatrix<number>::~FullMatrix ()
{
  if (val != 0)
    delete[] val;
};


template <typename number>
void
FullMatrix<number>::reinit (const unsigned int mm,
			    const unsigned int nn)
{
  dim_range = nn;
  dim_image = mm;

				   // if zero size was given: free all
				   // memory
  if ((dim_range==0) || (dim_image == 0))
    {
      if (val != 0)
	delete[] val;

      val      = 0;
      val_size = 0;

				       // set both sizes to zero, even
				       // if one was previously
				       // nonzero. This simplifies
				       // some Assertions.
      dim_range = dim_image = 0;

      return;
    };
  
				   // if new size is nonzero:
				   // if necessary: allocate
				   // additional memory
  if (val_size<nn*mm)
    {
      if (val != 0)
	delete[] val;

      val_size = dim_range * dim_image;
      val      = new number[val_size];
    };

				   // Clear contents of old or new
				   // memory.
  clear ();
};


template <typename number>
void
FullMatrix<number>::reinit (const unsigned int n)
{
  reinit (n, n);
};


template <typename number>
template <typename number2>
void
FullMatrix<number>::reinit (const FullMatrix<number2> &B)
{
  reinit (B.m(), B.n());
};


template <typename number>
bool
FullMatrix<number>::all_zero () const
{
  Assert (val != 0, ExcEmptyMatrix());
  
  const number *p = &val[0],
	       *e = &val[n()*m()];
  while (p!=e)
    if (*p++ != 0.0)
      return false;

  return true;
};


template <typename number>
template <typename number2>
void
FullMatrix<number>::vmult (Vector<number2>& dst,
			   const Vector<number2>& src,
			   const bool adding) const
{
  Assert (val != 0, ExcEmptyMatrix());
  
  Assert(dst.size() == m(), ExcDimensionMismatch(dst.size(), m()));
  Assert(src.size() == n(), ExcDimensionMismatch(src.size(), n()));

  number2 s;
  if ((n()==3) && (m()==3))
  {
    number2 s0,s1,s2;
    s   = src(0);
    s0  = s*val[0]; s1  = s*val[3]; s2  = s*val[6]; 
    s   = src(1);
    s0 += s*val[1]; s1 += s*val[4]; s2 += s*val[7];
    s   = src(2);
    s0 += s*val[2]; s1 += s*val[5]; s2 += s*val[8];

    if (!adding)
    {
      dst(0) = s0;
      dst(1) = s1;
      dst(2) = s2;
    }
    else
    {
      dst(0) += s0;
      dst(1) += s1;
      dst(2) += s2;
    }
  }
  else if ((n()==4) && (m()==4))
  {
    number2 s0,s1,s2,s3;
    s = src(0);
    s0  = s*val[0]; s1  = s*val[4]; s2  = s*val[8];  s3  = s*val[12];
    s = src(1);
    s0 += s*val[1]; s1 += s*val[5]; s2 += s*val[9];  s3 += s*val[13];
    s = src(2);
    s0 += s*val[2]; s1 += s*val[6]; s2 += s*val[10]; s3 += s*val[14];
    s = src(3);
    s0 += s*val[3]; s1 += s*val[7]; s2 += s*val[11]; s3 += s*val[15];
    
    if (!adding)
    {
      dst(0) = s0;
      dst(1) = s1;
      dst(2) = s2;
      dst(3) = s3;
    }
    else
    {
      dst(0) += s0;
      dst(1) += s1;
      dst(2) += s2;
      dst(3) += s3;
    }
  }
  else if ((n()==8) && (m()==8))
  {
    number2 s0,s1,s2,s3,s4,s5,s6,s7;
    s = src(0);
    s0 = s*val[0]; s1 = s*val[8]; s2 = s*val[16]; s3 = s*val[24];
    s4 = s*val[32]; s5 = s*val[40]; s6 = s*val[48]; s7 = s*val[56];
    s = src(1);
    s0 += s*val[1]; s1 += s*val[9]; s2 += s*val[17]; s3 += s*val[25];
    s4 += s*val[33]; s5 += s*val[41]; s6 += s*val[49]; s7 += s*val[57];
    s = src(2);
    s0 += s*val[2]; s1 += s*val[10]; s2 += s*val[18]; s3 += s*val[26];
    s4 += s*val[34]; s5 += s*val[42]; s6 += s*val[50]; s7 += s*val[58];
    s = src(3);
    s0 += s*val[3]; s1 += s*val[11]; s2 += s*val[19]; s3 += s*val[27];
    s4 += s*val[35]; s5 += s*val[43]; s6 += s*val[51]; s7 += s*val[59];
    s = src(4);
    s0 += s*val[4]; s1 += s*val[12]; s2 += s*val[20]; s3 += s*val[28];
    s4 += s*val[36]; s5 += s*val[44]; s6 += s*val[52]; s7 += s*val[60];
    s = src(5);
    s0 += s*val[5]; s1 += s*val[13]; s2 += s*val[21]; s3 += s*val[29];
    s4 += s*val[37]; s5 += s*val[45]; s6 += s*val[53]; s7 += s*val[61];
    s = src(6);
    s0 += s*val[6]; s1 += s*val[14]; s2 += s*val[22]; s3 += s*val[30];
    s4 += s*val[38]; s5 += s*val[46]; s6 += s*val[54]; s7 += s*val[62];
    s = src(7);
    s0 += s*val[7]; s1 += s*val[15]; s2 += s*val[23]; s3 += s*val[31];
    s4 += s*val[39]; s5 += s*val[47]; s6 += s*val[55]; s7 += s*val[63];
    
    if (!adding)
    {
      dst(0) = s0;
      dst(1) = s1;
      dst(2) = s2;
      dst(3) = s3;
      dst(4) = s4;
      dst(5) = s5;
      dst(6) = s6;
      dst(7) = s7;
    }
    else
    {
      dst(0) += s0;
      dst(1) += s1;
      dst(2) += s2;
      dst(3) += s3;
      dst(4) += s4;
      dst(5) += s5;
      dst(6) += s6;
      dst(7) += s7;
    }
  }
  else
  {    
    number* e = val;
    const unsigned int size_m = m(),
		       size_n = n();
    for (unsigned int i=0; i<size_m; ++i)
    {
      s = 0.;
      for (unsigned int j=0; j<size_n; ++j)
	s += src(j) * *(e++);
      if (!adding) dst(i) = s;
      else dst(i) += s;
    }
  }
}


template <typename number>
template <typename number2>
void FullMatrix<number>::Tvmult (Vector<number2>       &dst,
				 const Vector<number2> &src,
				 const bool             adding) const
{
  Assert (val != 0, ExcEmptyMatrix());
  
  Assert(dst.size() == n(), ExcDimensionMismatch(dst.size(), n()));
  Assert(src.size() == m(), ExcDimensionMismatch(src.size(), m()));

  unsigned int i,j;
  number2 s;
  const unsigned int size_m = m(),
		     size_n = n();
  for (i=0; i<size_m; ++i)
  {
    s = 0.;
    for (j=0; j<size_n; ++j)
      s += src(j) * el(j,i);
    if(!adding) dst(i) = s;
    else dst(i) += s;
  }
}<commit_msg>Fix indexing bug.<commit_after>//----------------------------  full_matrix.templates.h  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000 by the deal.II authors
//
//    This file is subject to QPL and may not be  distributed
//    without copyright and license information. Please refer
//    to the file deal.II/doc/license.html for the  text  and
//    further information on this license.
//
//----------------------------  full_matrix.templates.h  ---------------------------
#ifndef __deal2__full_matrix_templates_h
#define __deal2__full_matrix_templates_h


#include <lac/vector.h>
#include <lac/full_matrix.h>

#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <algorithm>


template <typename number>
FullMatrix<number>::FullMatrix (const unsigned int n) :
		val (0),
		dim_range (0),
		dim_image (0),
		val_size (0)
{
  reinit (n,n);
};


template <typename number>
FullMatrix<number>::FullMatrix (const unsigned int m,
				const unsigned int n) :
		val (0),
		dim_range (0),
		dim_image (0),
		val_size (0)
{
  reinit (m,n);
};


template <typename number>
FullMatrix<number>::FullMatrix (const FullMatrix &m) :
		Subscriptor (),
		val (0),
		dim_range (0),
		dim_image (0),
		val_size (0)
{
  reinit (m.dim_image, m.dim_range);
  if (dim_range*dim_image != 0)
    copy (&m.val[0], &m.val[dim_image*dim_range],
	  &val[0]);
};


template <typename number>
FullMatrix<number>::~FullMatrix ()
{
  if (val != 0)
    delete[] val;
};


template <typename number>
void
FullMatrix<number>::reinit (const unsigned int mm,
			    const unsigned int nn)
{
  dim_range = nn;
  dim_image = mm;

				   // if zero size was given: free all
				   // memory
  if ((dim_range==0) || (dim_image == 0))
    {
      if (val != 0)
	delete[] val;

      val      = 0;
      val_size = 0;

				       // set both sizes to zero, even
				       // if one was previously
				       // nonzero. This simplifies
				       // some Assertions.
      dim_range = dim_image = 0;

      return;
    };
  
				   // if new size is nonzero:
				   // if necessary: allocate
				   // additional memory
  if (val_size<nn*mm)
    {
      if (val != 0)
	delete[] val;

      val_size = dim_range * dim_image;
      val      = new number[val_size];
    };

				   // Clear contents of old or new
				   // memory.
  clear ();
};


template <typename number>
void
FullMatrix<number>::reinit (const unsigned int n)
{
  reinit (n, n);
};


template <typename number>
template <typename number2>
void
FullMatrix<number>::reinit (const FullMatrix<number2> &B)
{
  reinit (B.m(), B.n());
};


template <typename number>
bool
FullMatrix<number>::all_zero () const
{
  Assert (val != 0, ExcEmptyMatrix());
  
  const number *p = &val[0],
	       *e = &val[n()*m()];
  while (p!=e)
    if (*p++ != 0.0)
      return false;

  return true;
};


template <typename number>
template <typename number2>
void
FullMatrix<number>::vmult (Vector<number2>& dst,
			   const Vector<number2>& src,
			   const bool adding) const
{
  Assert (val != 0, ExcEmptyMatrix());
  
  Assert(dst.size() == m(), ExcDimensionMismatch(dst.size(), m()));
  Assert(src.size() == n(), ExcDimensionMismatch(src.size(), n()));

  number2 s;
  if ((n()==3) && (m()==3))
  {
    number2 s0,s1,s2;
    s   = src(0);
    s0  = s*val[0]; s1  = s*val[3]; s2  = s*val[6]; 
    s   = src(1);
    s0 += s*val[1]; s1 += s*val[4]; s2 += s*val[7];
    s   = src(2);
    s0 += s*val[2]; s1 += s*val[5]; s2 += s*val[8];

    if (!adding)
    {
      dst(0) = s0;
      dst(1) = s1;
      dst(2) = s2;
    }
    else
    {
      dst(0) += s0;
      dst(1) += s1;
      dst(2) += s2;
    }
  }
  else if ((n()==4) && (m()==4))
  {
    number2 s0,s1,s2,s3;
    s = src(0);
    s0  = s*val[0]; s1  = s*val[4]; s2  = s*val[8];  s3  = s*val[12];
    s = src(1);
    s0 += s*val[1]; s1 += s*val[5]; s2 += s*val[9];  s3 += s*val[13];
    s = src(2);
    s0 += s*val[2]; s1 += s*val[6]; s2 += s*val[10]; s3 += s*val[14];
    s = src(3);
    s0 += s*val[3]; s1 += s*val[7]; s2 += s*val[11]; s3 += s*val[15];
    
    if (!adding)
    {
      dst(0) = s0;
      dst(1) = s1;
      dst(2) = s2;
      dst(3) = s3;
    }
    else
    {
      dst(0) += s0;
      dst(1) += s1;
      dst(2) += s2;
      dst(3) += s3;
    }
  }
  else if ((n()==8) && (m()==8))
  {
    number2 s0,s1,s2,s3,s4,s5,s6,s7;
    s = src(0);
    s0 = s*val[0]; s1 = s*val[8]; s2 = s*val[16]; s3 = s*val[24];
    s4 = s*val[32]; s5 = s*val[40]; s6 = s*val[48]; s7 = s*val[56];
    s = src(1);
    s0 += s*val[1]; s1 += s*val[9]; s2 += s*val[17]; s3 += s*val[25];
    s4 += s*val[33]; s5 += s*val[41]; s6 += s*val[49]; s7 += s*val[57];
    s = src(2);
    s0 += s*val[2]; s1 += s*val[10]; s2 += s*val[18]; s3 += s*val[26];
    s4 += s*val[34]; s5 += s*val[42]; s6 += s*val[50]; s7 += s*val[58];
    s = src(3);
    s0 += s*val[3]; s1 += s*val[11]; s2 += s*val[19]; s3 += s*val[27];
    s4 += s*val[35]; s5 += s*val[43]; s6 += s*val[51]; s7 += s*val[59];
    s = src(4);
    s0 += s*val[4]; s1 += s*val[12]; s2 += s*val[20]; s3 += s*val[28];
    s4 += s*val[36]; s5 += s*val[44]; s6 += s*val[52]; s7 += s*val[60];
    s = src(5);
    s0 += s*val[5]; s1 += s*val[13]; s2 += s*val[21]; s3 += s*val[29];
    s4 += s*val[37]; s5 += s*val[45]; s6 += s*val[53]; s7 += s*val[61];
    s = src(6);
    s0 += s*val[6]; s1 += s*val[14]; s2 += s*val[22]; s3 += s*val[30];
    s4 += s*val[38]; s5 += s*val[46]; s6 += s*val[54]; s7 += s*val[62];
    s = src(7);
    s0 += s*val[7]; s1 += s*val[15]; s2 += s*val[23]; s3 += s*val[31];
    s4 += s*val[39]; s5 += s*val[47]; s6 += s*val[55]; s7 += s*val[63];
    
    if (!adding)
    {
      dst(0) = s0;
      dst(1) = s1;
      dst(2) = s2;
      dst(3) = s3;
      dst(4) = s4;
      dst(5) = s5;
      dst(6) = s6;
      dst(7) = s7;
    }
    else
    {
      dst(0) += s0;
      dst(1) += s1;
      dst(2) += s2;
      dst(3) += s3;
      dst(4) += s4;
      dst(5) += s5;
      dst(6) += s6;
      dst(7) += s7;
    }
  }
  else
  {    
    number* e = val;
    const unsigned int size_m = m(),
		       size_n = n();
    for (unsigned int i=0; i<size_m; ++i)
    {
      s = 0.;
      for (unsigned int j=0; j<size_n; ++j)
	s += src(j) * *(e++);
      if (!adding) dst(i) = s;
      else dst(i) += s;
    }
  }
}


template <typename number>
template <typename number2>
void FullMatrix<number>::Tvmult (Vector<number2>       &dst,
				 const Vector<number2> &src,
				 const bool             adding) const
{
  Assert (val != 0, ExcEmptyMatrix());
  
  Assert(dst.size() == n(), ExcDimensionMismatch(dst.size(), n()));
  Assert(src.size() == m(), ExcDimensionMismatch(src.size(), m()));

  unsigned int i,j;
  number2 s;
  const unsigned int size_m = m(),
		     size_n = n();
  for (i=0; i<size_n; ++i)
  {
    s = 0.;
    for (j=0; j<size_m; ++j)
      s += src(j) * el(j,i);
    if(!adding) dst(i) = s;
    else dst(i) += s;
  }
}
{'fraction_non_alphanumeric': 0.22339660626977279, 'fraction_numerical': 0.056945642795513375, 'mean_word_length': 2.3006644518272426, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 75, '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': '6431567', 'n_tokens_mistral': 6234, 'n_tokens_neox': 5839, 'n_words': 1402}