[IPython-dev] How to have independent call backs for single widget
Matthias BUSSONNIER
bussonniermatthias at gmail.com
Wed May 7 04:41:10 EDT 2014
Le 6 mai 2014 à 23:31, Jason Moore a écrit :
> If I have a function that makes a plot, for example:
>
> def plot_something(parameter=1.0, view=1.0):
> axes = expensive_function(plt.gca(), parameter)
> less_expensive_function(axes, view)
>
> And I make it interactive:
>
> interactive(plot_something, parameter=(0.0, 1.0), view=(0.0, 1.0))
>
> As it stands, both the expensive_function and the less_expensive_function run whether I drag the slider for either parameter, even though if I only drag the view parameter I could theoretically only call the less_expensive_function, thus making the widget respond faster.
>
> What is a good design to have a widget depend on two or more parameters and be able to have internal knowledge in the callback function on what parameter changed? So that you can avoid overhead in computation?
I suppose this is possible by doing custom widget and/or using the comm architecture directly.
But that would be a **lot** of work.
But couldn't you just use classic memoization of the expensive_function so that recalling it becomes less expensive ?
--
M
More information about the IPython-dev
mailing list