Search code examples
pythonpython-3.xnumpyperfplot

Perfplot raised a "TypeError: bench() got an unexpected keyword argument 'logx'". How to fix?


After a search on SO for numpy array mixed dtype filling I found a nice little numpy array fill performance tester perfplot. When the posted code answer from Nico Schlömer was ran, I saw a dip in the performance chart. So I changed the perflot.show(..snippet..) to perflot.bench(..snippet..) as suggest here and got the following error:

  File "X:\ScriYpts\Z.py", line 40, in <module>
    xlabel='length(a)'
TypeError: bench() got an unexpected keyword argument 'logx'

How to fix?

My code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import perfplot


def fill(n):
    a = np.empty(n)
    a.fill(val)
    return a


def colon(n):
    a = np.empty(n)
    a[:] = val
    return a


def full(n):
    return np.full(n, val)


def ones_times(n):
    return val * np.ones(n)


def mlist(n):
    return np.array(n * [val])

val = 42.0


out = perfplot.bench(
    setup=lambda n: n,
    kernels=[fill, colon, full, ones_times, mlist],
    n_range=[2**k for k in range(20)],
    logx=True,
    logy=True,
    xlabel='length(a)'
    )

out.show()

Solution

  • After a dive into perfplot main.py I figured out there is no logx' and logy **kwargs available.

    My solution:

    out = perfplot.bench(
        setup=lambda n: n,
        kernels=[fill, colon, full, ones_times, mlist],
        n_range=[2**k for k in range(20)],
    #    logx=True,  # disabled here
    #    logy=True,  # disabled here
        xlabel='length(a)'
        )
    
    out.show(logx=True, logy=True)  # both "log" **kwargs added here in `show()`
    

    For some unknown reason xlabel='length(a)' is not accepted as **kwarg in .show() directly. And it works to leave it in .bench().