GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
PositionsFromLaplacian.hpp
Go to the documentation of this file.
1 #ifndef GL_POSITIONS_FROM_LAPLACIAN_HPP
2 #define GL_POSITIONS_FROM_LAPLACIAN_HPP
3 
4 #include "../structures/Graph.hpp"
5 
6 namespace gl
7 {
8 namespace algorithm
9 {
10 
11 #ifndef DOXYGEN_SHOULD_SKIP_THIS
12 
15 extern "C" void sgeev_(
16  const char &, const char &, const int &, float *,
17  const int &, float *, float *, float *, const int &,
18  float *, const int &, float *, const int &, int *);
19 #endif
20 
26 std::pair<std::vector<float>, std::vector<float>> PositionsFromLaplacian(std::vector<float> laplacian, double factor = 5.0)
27 {
28  int N = std::sqrt(laplacian.size());
29  int NN = N * N;
30  float wr[N]; //
31  float wi[N];
32  float eigenvectorsL[NN];
33  float eigenvectorsR[NN];
34  float work[4 * N]; // aquire enough work space, 3*N is needed
35  int info; // whether it worked
36  float data[NN];
37  for (int i = 0; i < NN; i++)
38  {
39  data[i] = laplacian.data()[i];
40  }
41  sgeev_('V', 'N', N, data, N, wr, wi, eigenvectorsR, N, eigenvectorsL, N, work, NN, &info);
42  GL_ASSERT(info == 0, "BLAS call was not correct, got " + std::to_string(info) + " instead of 0.");
43  std::vector<float> ev1(N);
44  std::vector<float> ev2(N);
45 
46  for (int i = 0; i < N; i++)
47  {
48  ev1[i] = eigenvectorsR[i * N] * (1 + laplacian[N * i + i]) * factor; // and scale by degree
49  ev2[i] = eigenvectorsR[i * N + 1] * (1 + laplacian[N * i + i]) * factor;
50  }
51  return std::make_pair(ev1, ev2);
52 }
53 
54 } // namespace algorithm
55 } // namespace gl
56 
57 #endif // GL_POSITIONS_FROM_LAPLACIAN_HPP
std::pair< std::vector< float >, std::vector< float > > PositionsFromLaplacian(std::vector< float > laplacian, double factor=5.0)
Compute Positions from Laplacian using BLAS routine.
Definition: PositionsFromLaplacian.hpp:26
#define GL_ASSERT(EXPR, ERROR_MSG)
Custom assert that supports attaching a message.
Definition: gl_assert.hpp:14