perpplot比较多个函数的性能与多个参数(多个)

发布于 2025-02-10 23:12:31 字数 824 浏览 3 评论 0原文

我想通过使用多个参数的perpplot来显示某些功能的性能,但是我不知道该怎么做(我对perppertplot不太熟悉代码>)。一个人说 >,但是我很困惑,但如何使用它。假设我们具有以下功能:

from scipy.ndimage import zoom
import numpy as np

f = 5
n = 3
arr = np.random.random_integers(0, 1, (f, f))

def scipy_zoom(arr, n):
    return zoom(arr, n)

def numpy_rep(arr, n):
    return arr.repeat(n, 0).repeat(n, 1)

fn需要评估更改,并且似乎最好单独绘制它们,即一旦f保持恒定,n变化,一次反之亦然。我不知道如果强> perpplot 可以绘制(如果在答案中显示,但不是这个问题的主要目的)。

I would like to show performance of some functions by perfplot that uses more than one arguments, but I don't know how could I do this (I'm not familiar much with perfplot). One said broadcast all args to just x, but I am confused yet how to use it. Assume we have the following functions:

from scipy.ndimage import zoom
import numpy as np

f = 5
n = 3
arr = np.random.random_integers(0, 1, (f, f))

def scipy_zoom(arr, n):
    return zoom(arr, n)

def numpy_rep(arr, n):
    return arr.repeat(n, 0).repeat(n, 1)

Both f and n changes need to be evaluated and it seems it will be better to plot them separately i.e. once f be constant and n varies and once vice-versa. I don't know how understandable it will be if the 3D perfplot could be plotted (this will be useful if be shown in the answers, but not the main aim of this question).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2025-02-17 23:12:31

对于两个参数,我们可以收集所有基准时间安排,以 factials.partials.partial 和 N perpplot

import perfplot
from functools import partial

res = []
for f in range(5,100,20):
    arr = np.random.randint(0, 2, (f, f))
    g = perfplot.bench(
        setup=lambda n: n,
        kernels=[partial(scipy_zoom, arr),
                 partial(numpy_rep, arr)],
        labels=['zoom','numpy'],
        n_range=[2,3,4,5,6,7,8,9,10],
        equality_check=False # results are not equal!
    )
    res.append(g)

,并绘制了2D行绘图层的3D图。

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from cycler import cycler


fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111, projection='3d')
cc = cycler(color=list('rg'))

for i, g in zip(range(5,100,20)[::-1],res[::-1]):  # plot from back to front
    ax.plot(g.n_range,g.timings_s.T, i, zdir='y', alpha=0.8)

plt.rc('axes', prop_cycle=cc)
ax.set_xlabel('n')
ax.set_ylabel('f')
ax.set_zlabel('seconds')
ax.legend(g.labels)
plt.show()

输出

For two arguments we can collect all benchmark timings, setting the range of f for arr size with functools.partial and the range of n within perfplot

import perfplot
from functools import partial

res = []
for f in range(5,100,20):
    arr = np.random.randint(0, 2, (f, f))
    g = perfplot.bench(
        setup=lambda n: n,
        kernels=[partial(scipy_zoom, arr),
                 partial(numpy_rep, arr)],
        labels=['zoom','numpy'],
        n_range=[2,3,4,5,6,7,8,9,10],
        equality_check=False # results are not equal!
    )
    res.append(g)

and plot a 3D graph of 2D line plot layers.

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from cycler import cycler


fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111, projection='3d')
cc = cycler(color=list('rg'))

for i, g in zip(range(5,100,20)[::-1],res[::-1]):  # plot from back to front
    ax.plot(g.n_range,g.timings_s.T, i, zdir='y', alpha=0.8)

plt.rc('axes', prop_cycle=cc)
ax.set_xlabel('n')
ax.set_ylabel('f')
ax.set_zlabel('seconds')
ax.legend(g.labels)
plt.show()

Output

results

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文