8000 Unbounded memory use when specifying otypes='d' in vectorize. · Issue #11867 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Unbounded memory use when specifying otypes='d' in vectorize. #11867
Closed
@carlohamalainen

Description

@carlohamalainen

@nadiahpk first encountered this in the way that SciPy's hypergeom uses vectorize.

Here is a stand-alone example for reproducing the memory behaviour:

import numpy as np

class myclass():
    def f_class_method(self, k): return 0

    def __init__(self):
        self.f_class_method_vec_d = np.vectorize(self.f_class_method, otypes='d')
        self.f_class_method_vec   = np.vectorize(self.f_class_method)

# Memory use keeps growing:
def main1():
    while True:
        myclass().f_class_method_vec_d(0)

# Memory use constant:
def main2():
    while True:
        myclass().f_class_method_vec(0)

# Manual workaround for main1, now has constant memory use:
def main3():
    while True:
        m = myclass()
        m.f_class_method_vec_d(0)
        del m.f_class_method_vec_d._ufunc

I believe the issue is that self._ufunc becomes a circular reference when the function being vectorized is a class method.

I have a workaround here: carlohamalainen@9b5747b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0