Skip to content

ENH use variadic templates args in scatter and figure #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Bidibulke
Copy link

@Bidibulke Bidibulke commented Mar 26, 2020

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
               ));

Bidibulke added 3 commits May 29, 2020 13:57
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 <[email protected]>
Date:   Thu Mar 26 15:46:34 2020 +0100

    @enh figure with variadic template args

commit a8a3dd018c14a5e5c98b084f566865ba936c4fec
Author: Claire Guilbaud <[email protected]>
Date:   Thu Mar 26 14:55:36 2020 +0100

    @enh close

commit 6440609657de0f47b6fd4c1a8c213704f2810a4f
Author: Claire Guilbaud <[email protected]>
Date:   Thu Mar 26 13:41:18 2020 +0100

    @enh generic form for scatter
@Bidibulke Bidibulke force-pushed the merge/var_temp_args branch from 9ae729d to 06425a4 Compare May 29, 2020 12:14
Bidibulke added 2 commits May 29, 2020 15:38
commit b9bd9d7488d0109f58d195c3964631635614e5e1
Author: Claire Guilbaud <[email protected]>
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
@Bidibulke
Copy link
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.

Bidibulke added 3 commits June 5, 2020 15:32
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 ...
@Bidibulke
Copy link
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