-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlpkinterface.cpp
More file actions
65 lines (56 loc) · 1.82 KB
/
Copy pathlpkinterface.cpp
File metadata and controls
65 lines (56 loc) · 1.82 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
#include <iostream>
#include "cokriging.h"
#include "lpkinterface.h"
using namespace std;
void inverse(double A[], int N)
{
int *IPIV = new int[N+1];
int LWORK = N*N;
double *WORK = new double[LWORK];
int INFO;
dgetrf_(&N,&N,A,&N,IPIV,&INFO);
dgetri_(&N,A,&N,IPIV,WORK,&LWORK,&INFO);
delete IPIV;
delete WORK;
}
double* matrixLeftDivision(double A[], double B[], int N,int NRHS)
{
int *IPIV = new int[N+1];
int INFO;
//Create temporary variables so the fortran code doesn't change
//input variables
double A_tmp[N*N];for(int ii =0;ii<N*N;ii++){A_tmp[ii]=A[ii];}
double* B_rtn= new double[N];for(int ii =0;ii<N;ii++){B_rtn[ii]=B[ii];}
dgesv_(&N,&NRHS,A_tmp,&N,IPIV,B_rtn,&N,&INFO);
delete [] IPIV;
return B_rtn;
}
double* matrixMultiply(double A[], double B[],int M, int N,int K)
{
//---------------------------------------------//
// Multiple A by B
// Inputs:
// A: MxK matrix
// B: N+K matrix
// M: size of A
// N: size of B
// K: size shared by A and B
// Returns:
// C: MxN matrix
//---------------------------------------------//
//Create temporary variables so the fortran code doesn't change
//input variables
double A_tmp[K*M];for(int ii =0;ii<K*M;ii++){A_tmp[ii]=A[ii];}
double B_tmp[K*N];for(int ii =0;ii<K*N;ii++){B_tmp[ii]=B[ii];}
double* C_rtn = new double[M*N];for(int ii =0;ii<<M*N;ii++){C_rtn[ii]=0;}
char transa = 'n';
char transb = 't';
double alpha =1;double beta = 0;
//cout << "\nIn lpk a:\n";
//Write1Darray(A_tmp,K,M);
//cout << "In lpk b:\n";
//Write1Darray(B_tmp,K,N);
//cout << "M " << M<< " N " << N<< " K " << K<< endl;
dgemm_(&transa, &transb, &M, &N, &K,&alpha,A_tmp,&M,B_tmp,&N,&beta,C_rtn, &K );
return C_rtn;
}