[081fbe]: / src / modules / bugs / functions / MatMult.cc  Maximize  Restore  History

Download this file

92 lines (74 with data), 1.6 kB

 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <config.h>
#include "MatMult.h"
#include <util/dim.h>
#include "lapack.h"
using std::vector;
namespace bugs {
//FIXME: deparse?
MatMult::MatMult()
: ArrayFunction("%*%", 2)
{
}
void
MatMult::evaluate (double *value, vector<double const *> const &args,
vector<vector<unsigned int> > const &dims) const
{
int d1, d2, d3;
if (dims[0].size() == 1) {
d1 = 1;
d2 = dims[0][0];
}
else {
d1 = dims[0][0];
d2 = dims[0][1];
}
if (dims[1].size() == 1) {
d3 = 1;
}
else {
d3 = dims[1][1];
}
double one = 1, zero = 0;
F77_DGEMM ("N", "N", &d1, &d3, &d2, &one,
args[0], &d1, args[1], &d2, &zero, value, &d1);
}
vector<unsigned int>
MatMult::dim (vector <vector<unsigned int> > const &dims) const
{
vector<unsigned int> ans(2,1);
if (dims[0].size() == 2) {
ans[0] = dims[0][0];
}
if (dims[1].size() == 2) {
ans[1] = dims[1][1];
}
return drop(ans);
}
bool
MatMult::checkParameterDim (vector<vector<unsigned int> > const &dims) const
{
if (dims[0].size() > 2 || dims[1].size() > 2) {
return false;
}
if (dims[0].size() == 1) {
return dims[0][0] == dims[1][0];
}
else {
return dims[0][1] == dims[1][0];
}
}
bool
MatMult::isScale(vector<bool> const &mask, vector<bool> const &fix) const
{
//Test for quadratic terms
if (mask[0] && mask[1]) {
return false;
}
if (fix.empty()) {
return true;
}
else {
return (mask[0] || fix[0]) && (mask[1] || fix[1]);
}
}
}