Skip to content

Commit

Permalink
renamed sombrero.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: soblin <[email protected]>
  • Loading branch information
soblin committed Oct 21, 2022
1 parent bb9e692 commit 8490dcf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions gallery/contrib/sombrero,cpp → gallery/contrib/sombrero.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <matplotlibcpp17/pyplot.h>
#include <NumCpp.hpp>

int main()
{
int main() {
pybind11::scoped_interpreter guard{};

const int size = 1000;
Expand All @@ -11,19 +10,21 @@ int main()
const auto i = nc::arange<double>(size) - (0.5 * size);
const auto [x, y] = nc::meshgrid<double>(i, i);

const auto xy = (nc::power(x, 2) + nc::power(y, 2)) / (-2.0 * nc::power(sigma, 2));
const auto xy =
(nc::power(x, 2) + nc::power(y, 2)) / (-2.0 * nc::power(sigma, 2));

const auto sombrero = nc::exp(xy) * (xy + 1.0) / (std::acos(-1.0) * nc::power(sigma, 4));
const auto sombrero =
nc::exp(xy) * (xy + 1.0) / (std::acos(-1.0) * nc::power(sigma, 4));
const auto pysombrero = nc::pybindInterface::nc2pybind(sombrero);

const auto min = nc::min(sombrero)[0];
const auto max = nc::max(sombrero)[0];

auto plt = matplotlibcpp17::pyplot::import();

plt.imshow(Args(pysombrero), Kwargs(
"extent"_a = pybind11::make_tuple(-1, +1, -1, +1),
"cmap"_a = "inferno"));
plt.imshow(Args(pysombrero),
Kwargs("extent"_a = pybind11::make_tuple(-1, +1, -1, +1),
"cmap"_a = "inferno"));

plt.colorbar();

Expand Down

0 comments on commit 8490dcf

Please sign in to comment.