-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix.h
More file actions
123 lines (103 loc) · 6.56 KB
/
Copy pathmatrix.h
File metadata and controls
123 lines (103 loc) · 6.56 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
*
* matrix.h
* Hetero2
*
* CSIRO Open Source Software License Agreement (variation of the BSD / MIT License)
* Copyright (c) 2014, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230.
* All rights reserved. CSIRO is willing to grant you a license to this Hetero Version 2 on the following terms,
* except where otherwise indicated for third party material.
* Redistribution and use of this software in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* • Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* • Neither the name of CSIRO nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission of CSIRO.
* EXCEPT AS EXPRESSLY STATED IN THIS AGREEMENT AND TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, THE SOFTWARE
* IS PROVIDED "AS-IS". CSIRO MAKES NO REPRESENTATIONS, WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS REGARDING THE CONTENTS OR ACCURACY
* OF THE SOFTWARE, OR OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, THE ABSENCE
* OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE.
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL CSIRO BE LIABLE ON ANY LEGAL THEORY (INCLUDING,
* WITHOUT LIMITATION, IN AN ACTION FOR BREACH OF CONTRACT, NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR
* OTHER LIABILITY HOWSOEVER INCURRED. WITHOUT LIMITING THE SCOPE OF THE PREVIOUS SENTENCE THE EXCLUSION OF LIABILITY
* SHALL INCLUDE: LOSS OF PRODUCTION OR OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS OF
* ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL,
* INDIRECT, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT, ACCESS
* OF THE SOFTWARE OR ANY OTHER DEALINGS WITH THE SOFTWARE, EVEN IF CSIRO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* CLAIM, LOSS, DAMAGES OR OTHER LIABILITY.
* APPLICABLE LEGISLATION SUCH AS THE AUSTRALIAN CONSUMER LAW MAY APPLY REPRESENTATIONS, WARRANTIES, OR CONDITIONS, OR
* IMPOSES OBLIGATIONS OR LIABILITY ON CSIRO THAT CANNOT BE EXCLUDED, RESTRICTED OR MODIFIED TO THE FULL EXTENT SET OUT
* IN THE EXPRESS TERMS OF THIS CLAUSE ABOVE "CONSUMER GUARANTEES". TO THE EXTENT THAT SUCH CONSUMER GUARANTEES
* CONTINUE TO APPLY, THEN TO THE FULL EXTENT PERMITTED BY THE APPLICABLE LEGISLATION, THE LIABILITY OF CSIRO UNDER
* THE RELEVANT CONSUMER GUARANTEE IS LIMITED (WHERE PERMITTED AT CSIRO’S OPTION) TO ONE OF FOLLOWING REMEDIES OR
* SUBSTANTIALLY EQUIVALENT REMEDIES:
* (a) THE REPLACEMENT OF THE SOFTWARE, THE SUPPLY OF EQUIVALENT SOFTWARE, OR SUPPLYING RELEVANT SERVICES AGAIN;
* (b) THE REPAIR OF THE SOFTWARE;
* (c) THE PAYMENT OF THE COST OF REPLACING THE SOFTWARE, OF ACQUIRING EQUIVALENT SOFTWARE, HAVING THE RELEVANT
* SERVICES SUPPLIED AGAIN, OR HAVING THE SOFTWARE REPAIRED.
* IN THIS CLAUSE, CSIRO INCLUDES ANY THIRD PARTY AUTHOR OR OWNER OF ANY PART OF THE SOFTWARE OR MATERIAL DISTRIBUTED
* WITH IT. CSIRO MAY ENFORCE ANY RIGHTS ON BEHALF OF THE RELEVANT THIRD PARTY.
* Third Party Components
* The following third party components are distributed with the Software. You agree to comply with the license terms
* for these components as part of accessing the Software. Other third party software may also be identified in
* separate files distributed with the Software.
* ___________________________________________________________________
*
* JACOBI_EIGENVALUE.C (http://people.sc.fsu.edu/~jburkardt/c_src/jacobi_eigenvalue/jacobi_eigenvalue.c)
* Copyright (C) 2003-2013 John Burkardt
* This software is licensed under GNU LGPL (http://www.gnu.org/licenses/lgpl.html)
* ___________________________________________________________________
*/
#ifndef __RAL_RAS__matrix__
#define __RAL_RAS__matrix__
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "jacobi_eigenvalue.h"
using namespace std;
// The following paramaters are designed for Jacobi algorithm
// to find the eigenvalues and eigenvectors of a real symmetrix square matrix
#define MAX_ROUND 1000
#define VERY_SMALL_NUMBER 1.0e-20
// construct a matrix
// the values inside are not resetted
double* matrix(int row, int col);
// reset the matrix to zero
void resetMat(double* mat, int row, int col);
// set all entries inside the matrix to a specific value
void setMatrixToVal(double* mat, int row, int col, double value);
// reset a square matrix to an identity matrix
void ident(double* sqMat, int dim);
// set the values of the particular row of the matrix same as inArray
void setMatrix(double* matrix, int col, int row, double inArray[]);
// to set the diagional of the square matrix same as inArray
void setDiag(double* sqMatrix, double* inArray, int dim);
// output a diagional matrix from an array
double* toDiagMat(double* inArray, int dim);
// to collect the diagional of a square matrix
void diag(double* outArray, double* inSqMat, int dim);
double* diag(double* inSqMat, int dim);
// duplicate
void duplicate(double* toMat, double* frMat, int row, int col);
double* duplicate(double* frMat, int row, int col);
// print out a matrix
void printMatrix(double* matrix, int row, int col);
//=======================================//
// Matrix operations //
//=======================================//
// to compute all the eigenvectors and eigenvalues for a real symmetric square matrix
void jacobi(double* sqMatrix, int dim, double* eigenVals, double* eigenVects, int& numRound);
// to compute the transpose of a matrix with dimension row x col
void transpose(double* outMat, double* inMat, int row, int col);
double* transpose(double* inMat, int row, int col);
// to compute the multiplication of two matrice
// dimension of matrix 1: row x common_len
// dimension of matrix 2: common_len x col
void multiply(double *outMat, double* inMat1, double* inMat2, int row, int common_len, int col);
double* multiply(double * inMat1, double* inMat2, int row, int common_len, int col);
#endif /* defined(__RAL_RAS__matrix__) */