-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatArg.h
More file actions
86 lines (86 loc) · 1.57 KB
/
matArg.h
File metadata and controls
86 lines (86 loc) · 1.57 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
#ifndef _MATH_
#include <math.h>
#define _MATH_
#endif
int argmaxRow(int row,int begin=1,int end=-1){
Matrix mat=*this;
int i,maxIndex=begin;
if (end==-1){
end=mat.col();
}
if(begin>end){
IntSwap(begin,end);
}
for(i=begin;i<=end;++i){
if (mat(row,i)>mat(row,maxIndex)){
maxIndex=i;
}
}
return maxIndex;
}
int argmaxCol(int col,int begin=1,int end=-1){
Matrix mat=*this;
int i,maxIndex=begin;
if (end==-1){
end=mat.row();
}
if(begin>end){
IntSwap(begin,end);
}
for(i=begin;i<=end;++i){
if (mat(i,col)>mat(maxIndex,col)){
maxIndex=i;
}
}
return maxIndex;
}
int argmax(int line,int begin,int end,int dim)
{
if (dim==0){
return (*this).argmaxRow(line,begin,end);
}
if (dim==1){
return (*this).argmaxCol(line,begin,end);
}
}
int argabsmaxRow(int row,int begin=1,int end=-1){
Matrix mat=*this;
int i,maxIndex=begin;
if (end==-1){
end=mat.col();
}
if(begin>end){
IntSwap(begin,end);
}
for(i=begin;i<=end;++i){
if (fabs(mat(row,i))>fabs(mat(row,maxIndex))){
maxIndex=i;
}
}
return maxIndex;
}
int argabsmaxCol(int col,int begin=1,int end=-1){
Matrix mat=*this;
int i,maxIndex=begin;
if (end==-1){
end=mat.row();
}
if(begin>end){
IntSwap(begin,end);
}
for(i=begin;i<=end;++i){
if ( fabs(mat(i,col))> fabs(mat(maxIndex,col))){
maxIndex=i;
}
}
return maxIndex;
}
int argabsmax(int line,int begin,int end,int dim)
{
if (dim==0){
return (*this).argabsmaxRow(line,begin,end);
}
if (dim==1){
return (*this).argabsmaxCol(line,begin,end);
}
}