Skip to content

ENH use variadic templates args in scatter and figure - #166

Open
claireguilbaud wants to merge 9 commits into
lava:masterfrom
claireguilbaud:merge/var_temp_args
Open

claireguilbaud wants to merge 9 commits into
lava:masterfrom
claireguilbaud:merge/var_temp_args

Conversation

@claireguilbaud

@claireguilbaud claireguilbaud commented Mar 26, 2020 •

Copy link
Copy Markdown

In order to avoid adding other declaration function for the same functionnality with other arguments, I had the possibility to pass extra-arguments in a tuple of variadic templates.

The kwargs of matplotlib functions are accessible using a tuple of pair (string, T). T can be :

  • bool
  • int
  • long
  • double
  • char*
  • string
  • vector of double
  • vector of int
  • vector of vector of double

The syntax is not heavy, and if other types are needed, just implement a function such as

std::pair<std::string, PyObject*> analyze_key_value(const char* key, const T& value) {
  // Transform object of type T into an python equivalent type
  PyObject* pyobj = ....;
  return {key, pyobj};
}

Some examples:

  • streamplot
vector<vector<double>> lw;
// some code to fill lw
plt::streamplot(x, y, u, v, make_tuple("color", mag, "linewidth", lw));
  • scatter
// z is a vector<double>
plt::scatter(x, y,
                 make_tuple(
                                     "marker", "o",
                                      "c", z,
                                       "s", z,
                                      "cmap", "inferno",
                                      "alpha", 0.5
               ));

TST
* adding some unit tests using Catch2 framework
* 6 test cases with 91 assertions.
* normally there is a test for each function in matplotlibcpp.h
* `class Plot` is not tested

MISC

According to numpy documentation:
* BLD change related to building and installing (examples, module, …)
* ENH enhancement
* TST addition or modification of tests
* ...
commit 9047863bb0c1a34bc6473c2dadee720073db631e
Author: Claire Guilbaud <claire.guilbaud@cea.fr>
Date:   Thu Mar 26 15:46:34 2020 +0100

    @enh figure with variadic template args

commit a8a3dd018c14a5e5c98b084f566865ba936c4fec
Author: Claire Guilbaud <claire.guilbaud@cea.fr>
Date:   Thu Mar 26 14:55:36 2020 +0100

    @enh close

commit 6440609657de0f47b6fd4c1a8c213704f2810a4f
Author: Claire Guilbaud <claire.guilbaud@cea.fr>
Date:   Thu Mar 26 13:41:18 2020 +0100

    @enh generic form for scatter
commit b9bd9d7488d0109f58d195c3964631635614e5e1
Author: Claire Guilbaud <claire.guilbaud@cea.fr>
Date:   Fri May 29 15:29:00 2020 +0200

    ENH quiver extension / streamplot added
ENH quiver
* adding ``quiver(x, y, u, w, color)``
* adding support of variadic template args in ``quiver``

ENH streamplot
* adding ``streamplot(x, y, u, w)`` with variadic template args
* adding ``analyze_key_value`` for ``vector<vector<double>>``

TST
* new C++ Catch2 tests for new functionalities
@claireguilbaud

Copy link
Copy Markdown
Author

I added streamplot function (still with variadic template args). I also extended quiver to accept a vector color as 5th arguments (in the generic form), and new tests for those functionalities.

Interpreter has to be initialized otherwise PyLong_FromLong returns a
not null object, but null inside ...
ENH:
* New functions: `plot_surface`, `imshow`, `stem`
* Added new example
* Tests with Catch2 updated

MAINT:
* replace __function by detail::function for intern functions like for imshow

BUG FIX PyLong_FromLong in analyse_keywords
* Interpreter has to be initialized otherwise PyLong_FromLong returns a
not null object, but null inside ...
@claireguilbaud

Copy link
Copy Markdown
Author
  • New functions: plot_surface, imshow and stem.
  • Tests with Catch2 have been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant