Skip to main content

A matplotib.pyplot wrapper for gpu arrays (cupy, pytorch, etc.) without any of the .get / .detach / .cpu abracadabra

Project description

plt

A matplotib.pyplot wrapper for gpu arrays (cupy, pytorch, etc.) without any of the .get / .detach / .cpu abracadabra.

Installation and usage

plt can be installed with PyPI:

pip install plt

To use plt: simply import the module

from plt import plt

and proceed with plt as if you had just gone through the now-classic import import matplotlib.pyplot as plt. For example:

from plt import plt
import cupy as cp
arr = cp.arange(10)
plt.plot(arr)
plt.show()

The wrapper will automatically detect the type of the arrays in your pyplot call (both args and kwargs) and cast them to cpu on numpy. To test with numpy or pytorch here you would simply change import X as cp and run the exact same lines of code. Support for cupy and pytorch at the moment, but contributions welcome.

Other

To wrap any other library or matplotlib module "lib" with to-cpu casting do:

from plt import plt_wrapper
import module as lib
plt = plt_wrapper(lib)

To add support to other libraries you are very welcome to contribute here or proceed it for yourself only:

from plt import plt
plt.add_support("cupy", [lambda array_lib: array_lib._core.core.ndarray, \
                         lambda array_type, x: getattr(array_type, "get")(x)])

where here we would have added cupy support if it did not already exist.

from plt import plt imports an already-initialized class plt_wrapper(matplotlib.pyplot). plt_wrapper looks for the cupy and pytorch libraries in your env to do the setup. Alternatively, plt_wrapper_by_arraytype, and its initialized equivalent plt_arr, achieve the same wrapping results but fetching directly by array type in the .__module__:

from plt import plt_arr as plt
plt.add_support("cupy._core.core", \
                         lambda array_type, x: getattr(array_type, "get")(x))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plt-wrapper-0.0.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plt_wrapper-0.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file plt-wrapper-0.0.2.tar.gz.

File metadata

  • Download URL: plt-wrapper-0.0.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for plt-wrapper-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4080aa6c18cf07f592182a246a46f6eec6e2c10a72ee0444f1d0368a20250e18
MD5 22d21b783c33ae81d9052d582889264f
BLAKE2b-256 dd5e9bce53ec970a297171ea09a60227d9a0ec0c6f1b220d00d61b49d915a7f9

See more details on using hashes here.

File details

Details for the file plt_wrapper-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: plt_wrapper-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for plt_wrapper-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5847a5ec9fd51b35f215060600bbbaf91022cc4583c0170e1341e2c1e8618d2
MD5 ac185cd63d304d0b1b1157b70dabd056
BLAKE2b-256 c4bab8145f25c8c79d7193af7039775f3937831346bdb6f65f2dbebbdd3b1be9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page