Skip to content

Commit c589771

Browse files
committed
Commit current state of repo
1 parent 078ab1d commit c589771

File tree

6 files changed

+115
-30
lines changed

6 files changed

+115
-30
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ set(DOXYGEN_USE_MATHJAX YES)
2929

3030
if(UNIX)
3131

32-
add_compile_options(-Wall -march=native)
32+
add_compile_options(-Wall -Wpedantic -Wextra -march=native)
3333

3434
add_library(${PROJECT_NAME} SHARED ${EntropicMFG_SOURCES} ${EntropicMFG_HEADERS})
3535
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

include/Kernels.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class KernelBase {
2121
using KernelPtr = std::shared_ptr<KernelBase<double>>;
2222

2323

24-
/// Heat kernel on Euclidean space.
24+
/// Gaussian (heat) kernel on Euclidean space.
2525
template <size_t Dim, typename S = double>
2626
class EuclideanHeatKernelTpl : public KernelBase<S> {
2727
typedef S Scalar;
@@ -40,10 +40,11 @@ class EuclideanHeatKernelTpl : public KernelBase<S> {
4040
};
4141

4242

43-
44-
43+
/// Separable Gaussian kernel on Euclidean space.
44+
/// Assumes a kernel \f$ K = K_1\otimes K_2\f$.
4545
class SeparableEuclideanKernel2D : public EuclideanHeatKernelTpl<2, double> {
4646
public:
47+
/// Individual sub-kernels.
4748
MatrixXd K1_, K2_;
4849
double dx, dy;
4950
SeparableEuclideanKernel2D(

include/RectangularGridLaplacian.h

-23
This file was deleted.

include/kernels/Geometric.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include "Kernels.h"
4+
#include "RectangularGridLaplacian.h"
5+
6+
7+
namespace kernels
8+
{
9+
10+
11+
12+
13+
}
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#pragma once
2+
3+
#include <Eigen/Core>
4+
#include <Eigen/SparseCore>
5+
#include <Eigen/SparseCholesky>
6+
7+
8+
using namespace Eigen;
9+
10+
namespace kernels
11+
{
12+
namespace laplacian
13+
{
14+
15+
/// Define a matrix for the 1D Laplacian using the central
16+
/// differences stencil.
17+
auto make_laplacian_matrix1d(size_t nx, double h)
18+
{
19+
double h_2 = h * h;
20+
SparseMatrix<double> out(nx, nx);
21+
22+
for (size_t i = 0; i < nx; i++) {
23+
out.coeffRef(i, i) = 2. / h_2;
24+
if (i > 0) {
25+
out.coeffRef(i, i-1) = 1. / h_2;
26+
}
27+
if (i < nx) {
28+
out.coeffRef(i, i+1) = 1. / h_2;
29+
}
30+
}
31+
out.makeCompressed();
32+
return out;
33+
}
34+
35+
/// Given a mask of the discretization grid for the domain, define the graph obtained by
36+
/// removing the masked nodes from the classical grid graph.
37+
///
38+
/// Our convention is that a 1 in the mask indicates an obstacle.
39+
/// The \a x coord index is \c i.
40+
struct MaskedStencilGraph
41+
{
42+
/// Array type for grid mask.
43+
typedef Array<bool, -1, -1> Mask_t;
44+
Mask_t mask_;
45+
size_t n_nodes;
46+
std::vector<std::vector<size_t>> neighbors_;
47+
48+
MaskedStencilGraph(const Mask_t& mask
49+
) : mask_(mask) {
50+
size_t nx = mask.cols();
51+
size_t ny = mask.rows();
52+
n_nodes = 0;
53+
int v_id;
54+
for (size_t i = 0; i < nx; i++)
55+
{
56+
for (size_t j = 0; j < ny; j++)
57+
{
58+
if (mask_(i, j) == 0) {
59+
std::vector<size_t> nlist { n_nodes };
60+
n_nodes++;
61+
neighbors_.push_back(nlist);
62+
}
63+
}
64+
}
65+
66+
//
67+
for (size_t i = 0; i < nx; i++)
68+
{
69+
for (size_t j = 0; j < ny; j++)
70+
{
71+
if (mask_(i, j) == 0)
72+
{
73+
std::vector<size_t> nlist{n_nodes};
74+
n_nodes++;
75+
neighbors_.push_back(nlist);
76+
}
77+
}
78+
}
79+
};
80+
81+
/// @param i row index
82+
/// @param j columns index
83+
size_t grid_idx_to_node_id(size_t i, size_t j) {
84+
size_t nx = mask_.cols();
85+
size_t ny = mask_.rows();
86+
int v = j * nx + i;
87+
return v;
88+
}
89+
90+
};
91+
92+
}
93+
94+
}

src/MultiSinkhorn.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ bool MultimarginalSinkhorn::solve(size_t num_iterations, std::vector<MatrixXd> &
4949
std::cout << BLUE << "> MultiSinkhorn solver" << RESET << std::endl;
5050

5151
nsteps_ = potentials.size();
52-
metric_vals_.resize(0);
53-
_old_potentials.resize(nsteps_);
54-
potentials_.resize(nsteps_);
52+
metric_vals_.reserve(nsteps_);
53+
_old_potentials.reserve(nsteps_);
54+
potentials_.reserve(nsteps_);
5555

5656
for (size_t t = 0; t < nsteps_; t++) {
5757
potentials_[t].noalias() = potentials[t];

0 commit comments

Comments
 (0)