是否可以(以及如何)通过宏获取函数的主体。
例如,假设我有一个定义为
的函数import numpy as np
import matplotlib.pyplot as plt
left, width = 0.1, 0.8
rect1 = [left, 0.65, width, 0.25] # left, bottom, width, height
rect2 = [left, 0.4, width, 0.25]
rect3 = [left, 0.1, width, 0.3]
fig = plt.figure(figsize=(10, 6))
ax1 = fig.add_axes(rect1)
ax2 = fig.add_axes(rect2, sharex=ax1)
ax3 = fig.add_axes(rect3, sharex=ax1)
x = np.linspace(0, 6.5*np.pi, 200)
y1 = np.sin(x)
y2 = np.sin(2*x)
ax1.plot(x, y1, color='b', lw=2)
ax2.plot(x, y2, color='g', lw=2)
ax3.plot(x, y1+y2, color='r', lw=2)
ax3.get_xaxis().set_ticks([])
for ax in [ax1, ax2, ax3]:
ax.hlines(0, 0, 6.5*np.pi, color='black')
for key in ['right', 'top', 'bottom']:
ax.spines[key].set_visible(False)
plt.xlim(0, 6.6*np.pi)
ax3.text(2, 0.9, 'Sum signal', fontsize=14)
我想编写一个宏function foo (h::AbstractArray)
1. / (0.5 * h[i - 1, j, k] + h[i, j, k + 1])
end
,它将以某种方式更改函数主体,以使所有数组索引访问器都可以这样排列:
@permute_indices