Skip to main content

NumPy memory observability and explanation tool

Project description

npguard

npguard is a NumPy memory observability and explanation tool.

It helps developers understand why NumPy memory usage spikes by detecting temporary allocations and explaining their causes, with safe, opt-in suggestions to reduce memory pressure.

Features

  • Watch NumPy-heavy code blocks
  • Detect memory pressure and hidden temporaries
  • Explain causes (chained ops, broadcasting)
  • Provide safe optimization suggestions
  • No monkey-patching, no unsafe automation

What npguard does not do

  • Does not modify NumPy behavior
  • Does not automatically reuse buffers
  • Does not rewrite code

Example

import numpy as np
import npguard as ng

with ng.memory_watcher("matrix_pipeline"):
    a = np.random.rand(10_000, 100)
    ng.register_array(a, "a")

    b = a * 2 + a.mean(axis=0) - 1
    ng.register_array(b, "b")

    c = np.ascontiguousarray(b.T)
    ng.register_array(c, "c")

ng.report()
ng.suggest()

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

npguard-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

npguard-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file npguard-0.1.0.tar.gz.

File metadata

  • Download URL: npguard-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for npguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 952ee926f058d7821c53d4994b94691c4ee35cb34b3d04f9ea4719062e18b9e1
MD5 57667a8ee8ef0ebc9d7f0c4f038b7250
BLAKE2b-256 e8bd594b36819e1e02bc0e4d3c481ff3691ad48c789a77674b61afc49acab346

See more details on using hashes here.

File details

Details for the file npguard-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: npguard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for npguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce668a042e3d1323fdf63980475556d2687fc7cb2283d112d4fe4645fd643d94
MD5 3c79e544828504249766151ac9fa6cd8
BLAKE2b-256 eba76b5b1cc5d3daee256a733fbbbcc7190f694a7b4db2b570ead108d63d7eef

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