How to have independent call backs for single widget

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to have independent call backs for single widget

Jason Moore
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?

Jason
moorepants.info
+01 530-601-9791

_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to have independent call backs for single widget

Matthias Bussonnier

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
_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to have independent call backs for single widget

Jason Moore
What would be classic memoization in this application? Just store axes globally or something?


Jason
moorepants.info
+01 530-601-9791


On Wed, May 7, 2014 at 4:41 AM, Matthias BUSSONNIER <[hidden email]> wrote:

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
_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev


_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to have independent call backs for single widget

Doug Blank
On Wed, May 7, 2014 at 12:35 PM, Jason Moore <[hidden email]> wrote:
What would be classic memoization in this application? Just store axes globally or something?

Maybe something like:


-Doug
 


Jason
moorepants.info
+01 <a href="tel:530-601-9791" value="+15306019791" target="_blank">530-601-9791


On Wed, May 7, 2014 at 4:41 AM, Matthias BUSSONNIER <[hidden email]> wrote:

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
_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev


_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev



_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to have independent call backs for single widget

Jason Moore
Thank's Doug. Perfect simple example.


Jason
moorepants.info
+01 530-601-9791


On Wed, May 7, 2014 at 12:55 PM, Doug Blank <[hidden email]> wrote:
On Wed, May 7, 2014 at 12:35 PM, Jason Moore <[hidden email]> wrote:
What would be classic memoization in this application? Just store axes globally or something?

Maybe something like:


-Doug
 


Jason
moorepants.info
+01 <a href="tel:530-601-9791" value="+15306019791" target="_blank">530-601-9791


On Wed, May 7, 2014 at 4:41 AM, Matthias BUSSONNIER <[hidden email]> wrote:

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
_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev


_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev



_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev



_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev