pythran_def in classes

Issue #3 resolved
Pierre Augier created an issue

For some simple cases, it should be useful and not difficult to support something like

from fluidpythran import Type, NDim, Array, pythran_def

import numpy as np

T = Type(int, np.float64)
N = NDim(1)

A1 = Array[T, N]
A2 = Array[float, N+1]

class MyClass:

    arr0: A1
    arr1: A1
    arr2: A2

    def __init__(self, n, dtype=int):
        self.arr0 = np.zeros(n, dtype=dtype)
        self.arr1 = np.zeros(n, dtype=dtype)
        self.arr2 = np.zeros(n)

    @pythran_def
    def compute(self, alpha: int):
        tmp = (self.arr0 + self.arr1).mean()
        return tmp ** alpha * self.arr2

Note that it is a very simple case:

  • the method does not call any other methods
  • and there is no heritage.

Comments (7)

  1. Log in to comment