File: matrix.cpp

package info (click to toggle)
gfan 0.3dfsg-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 2,012 kB
  • ctags: 1,935
  • sloc: cpp: 17,728; makefile: 251
file content (47 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "matrix.h"

IntegerMatrix rowsToIntegerMatrix(IntegerVectorList const &rows, int width)
{
  int height=rows.size();
  int a=-1;
  for(IntegerVectorList::const_iterator i=rows.begin();i!=rows.end();i++)
    {
      if(a==-1)
	a=i->size();
      else
	{
	  assert(a==i->size());
	}
    }
  if(a==-1)
    {
      assert(width!=-1);
    }
  else
    {
      if(width!=-1)
	{
	  assert(width==a);
	}
    }
  if(width==-1)width=a;
  IntegerMatrix ret(height,width);

  int j=0;
  for(IntegerVectorList::const_iterator i=rows.begin();i!=rows.end();i++)
    ret[j++]=*i;

  return ret;
}


FloatMatrix integerToFloatMatrix(IntegerMatrix const &m)
{
  FloatMatrix ret(m.getHeight(),m.getWidth());

  for(int i=0;i<m.getHeight();i++)
    for(int j=0;j<m.getWidth();j++)
      ret[i][j]=m[i][j];

  return ret;
}