NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
FgEigenvalueDecomposition.h
1
11#pragma once
12
13#undef min
14#undef max
15
16#include <NeMachineLearningLib.h>
17#include <arrayfire.h>
18
19namespace NeuralEngine
20{
21 namespace MachineLearning
22 {
36 {
37 public:
38
47
54
76 void Compute(af::array& A);
77
85 af::array Eigenvalues();
86
94 af::array Eigenvectors();
95
96 private:
97 void compute();
98
109 void orthes();
110
121 void hqr2();
122
123 void cdiv(double xr, double xi, double yr, double yi);
124
125 int n;
126 double cdivr, cdivi;
127
128 double *d, *e, *ort;
129 double **V, **H;
130
131 af::array fV, fd;
132
133 template<typename _Tp>
134 _Tp *alloc_1d(int m)
135 {
136 return new _Tp[m];
137 }
138
139 template<typename _Tp>
140 _Tp *alloc_1d(int m, _Tp val)
141 {
142 _Tp *arr = alloc_1d<_Tp>(m);
143 for (int i = 0; i < m; i++)
144 arr[i] = val;
145 return arr;
146 }
147
148 template<typename _Tp>
149 _Tp **alloc_2d(int m, int n)
150 {
151 _Tp **arr = new _Tp*[m];
152 for (int i = 0; i < m; i++)
153 arr[i] = new _Tp[n];
154 return arr;
155 }
156
157 template<typename _Tp>
158 _Tp **alloc_2d(int m, int n, _Tp val)
159 {
160 _Tp **arr = alloc_2d<_Tp>(m, n);
161 for (int i = 0; i < m; i++) {
162 for (int j = 0; j < n; j++) {
163 arr[i][j] = val;
164 }
165 }
166 return arr;
167 }
168 };
169 }
170}
void Compute(af::array &A)
Computes the eigenvalues and -vectors in decending order
void hqr2()
Nonsymmetric reduction from Hessenberg to real Schur form.
void orthes()
Nonsymmetric reduction to Hessenberg form.
af::array Eigenvectors()
Gets the corresponding eigenvectors.
af::array Eigenvalues()
Gets the eigenvalues in decending order.