Back to index

texmacs  1.0.7.15
Classes | Defines | Functions
matrix.hpp File Reference
#include "vector.hpp"
#include "ntuple.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  matrix_rep
class  matrix
class  unary_properties< matrix< T > >
class  binary_properties< matrix< T >, matrix< U > >
class  binary_properties< T, matrix< U > >
class  binary_properties< matrix< T >, U >

Defines

#define TMPL   template<typename T>
#define BINARY_TMPL   template<typename T, typename U>
#define R   typename unary_properties<T>::norm_type
#define M   typename binary_properties<T,U>::product_type

Functions

TMPL int NR (matrix< T > m)
TMPL int NC (matrix< T > m)
TMPL TA (matrix< T > m)
 CONCRETE_TEMPLATE_CODE (matrix, typename, T)
TMPL tree as_tree (matrix< T > m)
TMPL tm_ostreamoperator<< (tm_ostream &out, matrix< T > m)
TMPL void parse (tree t, matrix< T > &m)
TMPL matrix< Tas_matrix (tree t)
template<typename T , typename Op >
matrix< Tunary (matrix< T > m)
TMPL matrix< Tcopy (matrix< T > m)
TMPL matrix< Toperator- (matrix< T > m)
template<typename T , typename Op >
matrix< Tbinary (matrix< T > m1, matrix< T > m2)
TMPL matrix< Toperator+ (matrix< T > m1, matrix< T > m2)
TMPL matrix< Toperator- (matrix< T > m1, matrix< T > m2)
TMPL matrix< Toperator* (matrix< T > m1, matrix< T > m2)
TMPL vector< Toperator* (matrix< T > m, vector< T > v)
TMPL array< Toperator* (matrix< T > m, array< T > v)

Define Documentation

#define BINARY_TMPL   template<typename T, typename U>

Definition at line 17 of file matrix.hpp.

#define M   typename binary_properties<T,U>::product_type

Definition at line 19 of file matrix.hpp.

#define R   typename unary_properties<T>::norm_type

Definition at line 18 of file matrix.hpp.

#define TMPL   template<typename T>

Definition at line 16 of file matrix.hpp.


Function Documentation

TMPL T * A ( matrix< T m) [inline]

Definition at line 65 of file matrix.hpp.

{ return m->a; }
TMPL matrix<T> as_matrix ( tree  t) [inline]

Definition at line 131 of file matrix.hpp.

                   {
  matrix<T> result;
  parse (t, result);
  return result;
}

Here is the call graph for this function:

TMPL tree as_tree ( matrix< T m)

Definition at line 103 of file matrix.hpp.

                      {
  int i, rows= NR (m);
  int j, cols= NC (m);
  tree t (TUPLE, rows);
  for (i=0; i<rows; i++) {
    t[i]= tree (TUPLE, cols);
    for (j=0; j<cols; j++)
      t[i][j]= as_tree (m(i,j));
  }
  return t;
}

Here is the call graph for this function:

template<typename T , typename Op >
matrix<T> binary ( matrix< T m1,
matrix< T m2 
)

Definition at line 160 of file matrix.hpp.

                                    {
  int i, n= NR(m1) * NC(m1);
  ASSERT (NR(m1) == NR(m2) && NC(m1) == NC(m2), "matrix sizes don't match");
  T* a= A(m1);
  T* b= A(m2);
  T* r= tm_new_array<T> (n);
  for (i=0; i<n; i++)
    r[i]= Op::eval (a[i], b[i]);
  return matrix<T> (r, NR(m1), NC(m1));
}

Here is the call graph for this function:

CONCRETE_TEMPLATE_CODE ( matrix  ,
typename  ,
T   
)
TMPL matrix<T> copy ( matrix< T m) [inline]

Definition at line 152 of file matrix.hpp.

                   {
  return unary<T,copy_op> (m); }
TMPL int NC ( matrix< T m) [inline]

Definition at line 64 of file matrix.hpp.

{ return m->cols; }

Here is the caller graph for this function:

TMPL int NR ( matrix< T m) [inline]

Definition at line 63 of file matrix.hpp.

{ return m->rows; }

Here is the caller graph for this function:

TMPL matrix<T> operator* ( matrix< T m1,
matrix< T m2 
) [inline]

Definition at line 184 of file matrix.hpp.

                                        {
  int i, j, k, rows= NR (m1), aux= NC (m1), cols= NC (m2);
  ASSERT (NR (m2) == aux, "dimensions don't match");
  matrix<T> prod (T(0), rows, cols);
  for (i=0; i<rows; i++)
    for (j=0; j<cols; j++)
      for (k=0; k<aux; k++)
       prod (i, j) += m1 (i, k) * m2 (k, j);
  return prod;
}

Here is the call graph for this function:

TMPL vector<T> operator* ( matrix< T m,
vector< T v 
) [inline]

Definition at line 196 of file matrix.hpp.

                                      {
  int i, j, rows= NR (m), cols= NC (m);
  ASSERT (N (v) == cols, "dimensions don't match");
  vector<T> prod (T(0), rows);
  for (i=0; i<rows; i++)
    for (j=0; j<cols; j++)
      prod [i] += m (i, j) * v[j];
  return prod;
}

Here is the call graph for this function:

TMPL array<T> operator* ( matrix< T m,
array< T v 
) [inline]

Definition at line 207 of file matrix.hpp.

                                     {
  int i, j, rows= NR (m), cols= NC (m);
  ASSERT (N (v) == cols, "dimensions don't match");
  array<T> prod (T(0), rows);
  for (i=0; i<rows; i++)
    for (j=0; j<cols; j++)
      prod [i] += m (i, j) * v[j];
  return prod;
}

Here is the call graph for this function:

TMPL matrix<T> operator+ ( matrix< T m1,
matrix< T m2 
) [inline]

Definition at line 172 of file matrix.hpp.

                                        {
  return binary<T,add_op> (m1, m2); }
TMPL matrix<T> operator- ( matrix< T m) [inline]

Definition at line 156 of file matrix.hpp.

                         {
  return unary<T,neg_op> (m); }
TMPL matrix<T> operator- ( matrix< T m1,
matrix< T m2 
) [inline]

Definition at line 176 of file matrix.hpp.

                                        {
  return binary<T,sub_op> (m1, m2); }
TMPL tm_ostream& operator<< ( tm_ostream out,
matrix< T m 
) [inline]

Definition at line 116 of file matrix.hpp.

                                           {
  return out << as_math_string (as_tree (m));
}

Here is the call graph for this function:

TMPL void parse ( tree  t,
matrix< T > &  m 
)

Definition at line 121 of file matrix.hpp.

                             {
  ASSERT (is_tuple (t) && N(t)>0 && is_tuple (t[0]), "not a matrix");
  int i, j, rows= N(t), cols= N(t[0]);
  m= matrix<T> (T(0), rows, cols);
  for (i=0; i<rows; i++)
    for (j=0; j<cols; j++)
      m(i,j)= parse_as<T> (t[i][j]);
}

Here is the call graph for this function:

template<typename T , typename Op >
matrix<T> unary ( matrix< T m)

Definition at line 142 of file matrix.hpp.

                    {
  int i, n= NR(m) * NC(m);
  T* a= A(m);
  T* r= tm_new_array<T> (n);
  for (i=0; i<n; i++)
    r[i]= Op::eval (a[i]);
  return matrix<T> (r, NR(m), NC(m));
}

Here is the call graph for this function: