void
 kron(const Matrix_T& x, const Matrix_T& y, Matrix_T& z)
 {
   const int rx = x.size1();
   const int cx = x.size2();
   const int ry = y.size1();
   const int cy = y.size2();
   z.resize (rx*ry, cx*cy);
   z.clear ();
   for ( typename Matrix_T::const_iterator1 i = x.begin1();
              i != x.end1(); ++i)
     for ( typename Matrix_T::const_iterator2 j = i.begin();
              j != i.end(); ++j)
       for ( typename Matrix_T::const_iterator1 k = y.begin1();
              k != y.end1(); ++k)
         for (typename Matrix_T::const_iterator2 l = k.begin();
              l != k.end(); ++l)
             z(j.index1()*ry + l.index1(), j.index2()*cy + l.index2()) =
                     (*j) * (*l);
 } 
Ejemplo n.º 2
0
  const
  Matrix_T
    kron(const Matrix_S& lhs, const Matrix_T& rhs)
    {
      typedef typename Matrix_S::size_type matrix_index_s;
      typedef typename Matrix_T::size_type matrix_index_t;
      const matrix_index_s lhs_s1 = lhs.size1();
      const matrix_index_s lhs_s2 = lhs.size2();
      const matrix_index_t rhs_s1 = rhs.size1();
      const matrix_index_t rhs_s2 = rhs.size2();
      Matrix_T result(lhs_s1*rhs_s1, lhs_s2*rhs_s2);
      typedef typename Matrix_S::value_type Scalar_S;
      typedef typename Matrix_S::const_iterator1 const_iteratorS1;
      typedef typename Matrix_S::const_iterator2 const_iteratorS2;
      typedef typename Matrix_T::value_type Scalar_T;
      typedef typename Matrix_T::const_iterator1 const_iterator1;
      typedef typename Matrix_T::const_iterator2 const_iterator2;
      for (const_iteratorS1
	     lhs_it1 = lhs.begin1();
	   lhs_it1 != lhs.end1();
	   ++lhs_it1)
	for (const_iteratorS2
	       lhs_it2 = lhs_it1.begin();
	     lhs_it2 != lhs_it1.end();
	     ++lhs_it2)
	  {
	    const matrix_index_t start1 = rhs_s1 * lhs_it2.index1();
	    const matrix_index_t start2 = rhs_s2 * lhs_it2.index2();
	    const Scalar_S& lhs_val = (*lhs_it2);
	    for (const_iterator1
		   rhs_it1 = rhs.begin1();
		 rhs_it1 != rhs.end1();
		 ++rhs_it1)
	      for (const_iterator2
		     rhs_it2 = rhs_it1.begin();
		   rhs_it2 != rhs_it1.end();
		   ++rhs_it2)
		result(start1 + rhs_it2.index1(), start2 + rhs_it2.index2()) = lhs_val * *rhs_it2;
	  }
      return result;
    }
Ejemplo n.º 3
0
int main() //Main function to initialize and run all tests above
{

	int check, errorCounter = 0;
	Matrix_T testClass;

	check = testClass.inverseTest();
	errorCounter += check;

	check = testClass.transposeTest();
	errorCounter += check;

	check = testClass.solutionTest();
	errorCounter += check;

	check = testClass.determinantTest();
	errorCounter +=  check;

	std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;

	return errorCounter; //Return the total number of errors
}