Overstack flow

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Overstack flow

nmichel
Hello,

I am running the following function, which practically is the how to  
delete rows with a certain label macro found on the macro examples on  
the site. If the number of results in a results' table is less than  
100 it works fine but when I have more than 100 results I get a stack  
overflow error. Anybody can tell me why and how to fix it?

Thanks!

Nick


var label = "Nucleus";

all = getBoolean("Refine results?");

deleteChosenRows(label, all);

function deleteChosenRows(string, recursive) {
   for (i=0; i<nResults; i++) {
       l = getResultLabel(i);
       if (indexOf(l, string)!=-1) {
           IJ.deleteRows(i, i);
           if (recursive)
               deleteChosenRows(string, true);
           else
               return;
       }
   }
}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Overstack flow

Stephan Saalfeld
This is Javascript and I assume that, like Java, it just has a small
stack.  That is, you cannot really do deep recursions.  But you're
lucky, what you do here doesn't require recursion at all:

function deleteChosenRows(string, recursive) {
   for (i=0; i<nResults; i++) {
       l = getResultLabel(i);
       if (indexOf(l, string)!=-1) {
           IJ.deleteRows(i, i);
           if (!recursive)
               return;
           nResults--;
           i--;
       }
   }
}

should actually do it (also quicker).  I do not know where the nResults
comes from---here I assume that you globally set it before.  If ImageJ
is taking care for it then you do not have to decrement it.

I expect Clojure to do better with deep recursions if you really want to
go this route :)

Cheers,
Stephan




On Mon, 2012-11-12 at 17:24 +0000, Nikolaos Michelarakis wrote:

> Hello,
>
> I am running the following function, which practically is the how to  
> delete rows with a certain label macro found on the macro examples on  
> the site. If the number of results in a results' table is less than  
> 100 it works fine but when I have more than 100 results I get a stack  
> overflow error. Anybody can tell me why and how to fix it?
>
> Thanks!
>
> Nick
>
>
> var label = "Nucleus";
>
> all = getBoolean("Refine results?");
>
> deleteChosenRows(label, all);
>
> function deleteChosenRows(string, recursive) {
>    for (i=0; i<nResults; i++) {
>        l = getResultLabel(i);
>        if (indexOf(l, string)!=-1) {
>            IJ.deleteRows(i, i);
>            if (recursive)
>                deleteChosenRows(string, true);
>            else
>                return;
>        }
>    }
> }
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Overstack flow

nmichel
I think this is macro language, which, from what I understand looks a  
bit like java or javascript. nResults= the whole results table, and  
it's set from Imagej. I don't know what clojure is? I just want to be  
able to delete the rows from larger tables, not just 100 results :P

Thanks

Nick

----- Message from [hidden email] ---------
     Date: Mon, 12 Nov 2012 21:30:53 +0100
     From: Stephan Saalfeld <[hidden email]>
Reply-To: [hidden email]
  Subject: Re: Overstack flow
       To: [hidden email]


> This is Javascript and I assume that, like Java, it just has a small
> stack.  That is, you cannot really do deep recursions.  But you're
> lucky, what you do here doesn't require recursion at all:
>
> function deleteChosenRows(string, recursive) {
>    for (i=0; i<nResults; i++) {
>        l = getResultLabel(i);
>        if (indexOf(l, string)!=-1) {
>            IJ.deleteRows(i, i);
>            if (!recursive)
>                return;
>            nResults--;
>            i--;
>        }
>    }
> }
>
> should actually do it (also quicker).  I do not know where the nResults
> comes from---here I assume that you globally set it before.  If ImageJ
> is taking care for it then you do not have to decrement it.
>
> I expect Clojure to do better with deep recursions if you really want to
> go this route :)
>
> Cheers,
> Stephan
>
>
>
>
> On Mon, 2012-11-12 at 17:24 +0000, Nikolaos Michelarakis wrote:
>> Hello,
>>
>> I am running the following function, which practically is the how to
>> delete rows with a certain label macro found on the macro examples on
>> the site. If the number of results in a results' table is less than
>> 100 it works fine but when I have more than 100 results I get a stack
>> overflow error. Anybody can tell me why and how to fix it?
>>
>> Thanks!
>>
>> Nick
>>
>>
>> var label = "Nucleus";
>>
>> all = getBoolean("Refine results?");
>>
>> deleteChosenRows(label, all);
>>
>> function deleteChosenRows(string, recursive) {
>>    for (i=0; i<nResults; i++) {
>>        l = getResultLabel(i);
>>        if (indexOf(l, string)!=-1) {
>>            IJ.deleteRows(i, i);
>>            if (recursive)
>>                deleteChosenRows(string, true);
>>            else
>>                return;
>>        }
>>    }
>> }
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


----- End message from [hidden email] -----

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Overstack flow

nmichel
In reply to this post by Stephan Saalfeld
In the function you sent me, how do I set which rows, with a certain  
label, I want to be deleted?

Nick

----- Message from [hidden email] ---------
     Date: Mon, 12 Nov 2012 21:30:53 +0100
     From: Stephan Saalfeld <[hidden email]>
Reply-To: [hidden email]
  Subject: Re: Overstack flow
       To: [hidden email]


> This is Javascript and I assume that, like Java, it just has a small
> stack.  That is, you cannot really do deep recursions.  But you're
> lucky, what you do here doesn't require recursion at all:
>
> function deleteChosenRows(string, recursive) {
>    for (i=0; i<nResults; i++) {
>        l = getResultLabel(i);
>        if (indexOf(l, string)!=-1) {
>            IJ.deleteRows(i, i);
>            if (!recursive)
>                return;
>            nResults--;
>            i--;
>        }
>    }
> }
>
> should actually do it (also quicker).  I do not know where the nResults
> comes from---here I assume that you globally set it before.  If ImageJ
> is taking care for it then you do not have to decrement it.
>
> I expect Clojure to do better with deep recursions if you really want to
> go this route :)
>
> Cheers,
> Stephan
>
>
>
>
> On Mon, 2012-11-12 at 17:24 +0000, Nikolaos Michelarakis wrote:
>> Hello,
>>
>> I am running the following function, which practically is the how to
>> delete rows with a certain label macro found on the macro examples on
>> the site. If the number of results in a results' table is less than
>> 100 it works fine but when I have more than 100 results I get a stack
>> overflow error. Anybody can tell me why and how to fix it?
>>
>> Thanks!
>>
>> Nick
>>
>>
>> var label = "Nucleus";
>>
>> all = getBoolean("Refine results?");
>>
>> deleteChosenRows(label, all);
>>
>> function deleteChosenRows(string, recursive) {
>>    for (i=0; i<nResults; i++) {
>>        l = getResultLabel(i);
>>        if (indexOf(l, string)!=-1) {
>>            IJ.deleteRows(i, i);
>>            if (recursive)
>>                deleteChosenRows(string, true);
>>            else
>>                return;
>>        }
>>    }
>> }
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


----- End message from [hidden email] -----

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Overstack flow

Rasband, Wayne (NIH/NIMH) [E]
On Nov 12, 2012, at 5:23 PM, Nikolaos Michelarakis wrote:

> In the function you sent me, how do I set which rows, with a certain  
> label, I want to be deleted?

Here is a macro function that deletes all the rows that have a specified label.

  function deleteChosenRows(label) {
     for (i=nResults-1; i>=0; i--) {
        l = getResultLabel(i);
        if (indexOf(l,label)!=-1)
            IJ.deleteRows(i, i);
     }
  }

-wayne

> ----- Message from [hidden email] ---------
>
>> This is Javascript and I assume that, like Java, it just has a small
>> stack.  That is, you cannot really do deep recursions.  But you're
>> lucky, what you do here doesn't require recursion at all:
>>
>> function deleteChosenRows(string, recursive) {
>>   for (i=0; i<nResults; i++) {
>>       l = getResultLabel(i);
>>       if (indexOf(l, string)!=-1) {
>>           IJ.deleteRows(i, i);
>>           if (!recursive)
>>               return;
>>           nResults--;
>>           i--;
>>       }
>>   }
>> }
>>
>> should actually do it (also quicker).  I do not know where the nResults
>> comes from---here I assume that you globally set it before.  If ImageJ
>> is taking care for it then you do not have to decrement it.
>>
>> I expect Clojure to do better with deep recursions if you really want to
>> go this route :)
>>
>> Cheers,
>> Stephan
>>
>>
>> On Mon, 2012-11-12 at 17:24 +0000, Nikolaos Michelarakis wrote:
>>> Hello,
>>>
>>> I am running the following function, which practically is the how to
>>> delete rows with a certain label macro found on the macro examples on
>>> the site. If the number of results in a results' table is less than
>>> 100 it works fine but when I have more than 100 results I get a stack
>>> overflow error. Anybody can tell me why and how to fix it?
>>>
>>> Thanks!
>>>
>>> Nick
>>>
>>>
>>> var label = "Nucleus";
>>>
>>> all = getBoolean("Refine results?");
>>>
>>> deleteChosenRows(label, all);
>>>
>>> function deleteChosenRows(string, recursive) {
>>>   for (i=0; i<nResults; i++) {
>>>       l = getResultLabel(i);
>>>       if (indexOf(l, string)!=-1) {
>>>           IJ.deleteRows(i, i);
>>>           if (recursive)
>>>               deleteChosenRows(string, true);
>>>           else
>>>               return;
>>>       }
>>>   }
>>> }
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
>
> ----- End message from [hidden email] -----
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Overstack flow

nmichel
Thank you very much, that does the trick!

Nick

----- Message from [hidden email] ---------
     Date: Mon, 12 Nov 2012 17:50:40 -0500
     From: "Rasband, Wayne (NIH/NIMH) [E]" <[hidden email]>
Reply-To: [hidden email]
  Subject: Re: Overstack flow
       To: [hidden email]


> On Nov 12, 2012, at 5:23 PM, Nikolaos Michelarakis wrote:
>
>> In the function you sent me, how do I set which rows, with a certain
>> label, I want to be deleted?
>
> Here is a macro function that deletes all the rows that have a  
> specified label.
>
>   function deleteChosenRows(label) {
>      for (i=nResults-1; i>=0; i--) {
>         l = getResultLabel(i);
>         if (indexOf(l,label)!=-1)
>             IJ.deleteRows(i, i);
>      }
>   }
>
> -wayne
>
>> ----- Message from [hidden email] ---------
>>
>>> This is Javascript and I assume that, like Java, it just has a small
>>> stack.  That is, you cannot really do deep recursions.  But you're
>>> lucky, what you do here doesn't require recursion at all:
>>>
>>> function deleteChosenRows(string, recursive) {
>>>   for (i=0; i<nResults; i++) {
>>>       l = getResultLabel(i);
>>>       if (indexOf(l, string)!=-1) {
>>>           IJ.deleteRows(i, i);
>>>           if (!recursive)
>>>               return;
>>>           nResults--;
>>>           i--;
>>>       }
>>>   }
>>> }
>>>
>>> should actually do it (also quicker).  I do not know where the nResults
>>> comes from---here I assume that you globally set it before.  If ImageJ
>>> is taking care for it then you do not have to decrement it.
>>>
>>> I expect Clojure to do better with deep recursions if you really want to
>>> go this route :)
>>>
>>> Cheers,
>>> Stephan
>>>
>>>
>>> On Mon, 2012-11-12 at 17:24 +0000, Nikolaos Michelarakis wrote:
>>>> Hello,
>>>>
>>>> I am running the following function, which practically is the how to
>>>> delete rows with a certain label macro found on the macro examples on
>>>> the site. If the number of results in a results' table is less than
>>>> 100 it works fine but when I have more than 100 results I get a stack
>>>> overflow error. Anybody can tell me why and how to fix it?
>>>>
>>>> Thanks!
>>>>
>>>> Nick
>>>>
>>>>
>>>> var label = "Nucleus";
>>>>
>>>> all = getBoolean("Refine results?");
>>>>
>>>> deleteChosenRows(label, all);
>>>>
>>>> function deleteChosenRows(string, recursive) {
>>>>   for (i=0; i<nResults; i++) {
>>>>       l = getResultLabel(i);
>>>>       if (indexOf(l, string)!=-1) {
>>>>           IJ.deleteRows(i, i);
>>>>           if (recursive)
>>>>               deleteChosenRows(string, true);
>>>>           else
>>>>               return;
>>>>       }
>>>>   }
>>>> }
>>>>
>>>> --
>>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>
>>
>>
>> ----- End message from [hidden email] -----
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


----- End message from [hidden email] -----

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Overstack flow

Stephan Saalfeld
In reply to this post by nmichel
As in your original function.  With recursive = false, it deletes only
the first match, with recursive = true, it deletes all matches. If this
is the macro language, nResults is part of the machine, do not
nResults--; then.

Best,
Stephan




On Mon, 2012-11-12 at 22:23 +0000, Nikolaos Michelarakis wrote:

> In the function you sent me, how do I set which rows, with a certain  
> label, I want to be deleted?
>
> Nick
>
> ----- Message from [hidden email] ---------
>      Date: Mon, 12 Nov 2012 21:30:53 +0100
>      From: Stephan Saalfeld <[hidden email]>
> Reply-To: [hidden email]
>   Subject: Re: Overstack flow
>        To: [hidden email]
>
>
> > This is Javascript and I assume that, like Java, it just has a small
> > stack.  That is, you cannot really do deep recursions.  But you're
> > lucky, what you do here doesn't require recursion at all:
> >
> > function deleteChosenRows(string, recursive) {
> >    for (i=0; i<nResults; i++) {
> >        l = getResultLabel(i);
> >        if (indexOf(l, string)!=-1) {
> >            IJ.deleteRows(i, i);
> >            if (!recursive)
> >                return;
> >            nResults--;
> >            i--;
> >        }
> >    }
> > }
> >
> > should actually do it (also quicker).  I do not know where the nResults
> > comes from---here I assume that you globally set it before.  If ImageJ
> > is taking care for it then you do not have to decrement it.
> >
> > I expect Clojure to do better with deep recursions if you really want to
> > go this route :)
> >
> > Cheers,
> > Stephan
> >
> >
> >
> >
> > On Mon, 2012-11-12 at 17:24 +0000, Nikolaos Michelarakis wrote:
> >> Hello,
> >>
> >> I am running the following function, which practically is the how to
> >> delete rows with a certain label macro found on the macro examples on
> >> the site. If the number of results in a results' table is less than
> >> 100 it works fine but when I have more than 100 results I get a stack
> >> overflow error. Anybody can tell me why and how to fix it?
> >>
> >> Thanks!
> >>
> >> Nick
> >>
> >>
> >> var label = "Nucleus";
> >>
> >> all = getBoolean("Refine results?");
> >>
> >> deleteChosenRows(label, all);
> >>
> >> function deleteChosenRows(string, recursive) {
> >>    for (i=0; i<nResults; i++) {
> >>        l = getResultLabel(i);
> >>        if (indexOf(l, string)!=-1) {
> >>            IJ.deleteRows(i, i);
> >>            if (recursive)
> >>                deleteChosenRows(string, true);
> >>            else
> >>                return;
> >>        }
> >>    }
> >> }
> >>
> >> --
> >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
>
> ----- End message from [hidden email] -----
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html