Skip to content

g.ad.forward.series __add__ is not commutative with numpy arrays #139

@daknuett

Description

@daknuett
fad = g.ad.forward
alpha = fad.infinitesimal("alpha")

On = fad.landau(alpha**2)

series = fad.series(3, On)

arr = np.arange(1, 10, 1)

print(((series + arr) - (arr + series)))

This should print a series of zeroes. Instead, a series of series is printed.

One can fix this by monkey-patching the series class:

fad = g.ad.forward
alpha = fad.infinitesimal("alpha")

On = fad.landau(alpha**2)

fad.series.__array_ufunc__ = None 
# For numpy < 13, add also __numpy_ufunc__.

series = fad.series(3, On)

arr = np.arange(1, 10, 1)

print(((series + arr) - (arr + series)))

The patch to fix this appears straight forward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions