File: matrix.cpp

package info (click to toggle)
gfan 0.5%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,296 kB
  • ctags: 5,612
  • sloc: cpp: 39,675; makefile: 453; sh: 1
file content (67 lines) | stat: -rw-r--r-- 1,151 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#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;
}


IntegerVector flattenMatrix(IntegerMatrix const &m)
{
  IntegerVector ret(m.getHeight()*m.getWidth());

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

  return ret;
}


#include "linalg.h"

int rank(IntegerMatrix const &m)
{
  return integerMatrixToFieldMatrix(m,Q).rank();
}