pause mode and missing matrix rows: bug or feature?

pause mode and missing matrix rows: bug or feature?

Post by Dean S. Me » Sat, 07 Oct 2006 08:28:10



When I pause a function, I expect (maybe wrongly!) that copies of the
variables in the function are available to me with the values they had
at the time of the pause, so that I can "work through" the steps of
the function by hand within pause mode to debug the function. (I have
not learned to use the de *** yet :-)

Yet, things are acting strangely for me. Here's
an (abstracted) example.

Suppose foo.sci is in the current directory:

// foo.sci
function [] = foo(M)
pause;
M(3,:) = [2,4,6];
return;
endfunction

Now consider the scilab session:

-->clear;

-->getf('./foo.sci');

-->m = int(100*rand(10,3));

-->m
m =

21. 27. 32.
90. 24. 67.
14. 35. 13.
75. 83. 95.
67. 84. 14.
89. 23. 28.
20. 50. 15.
90. 30. 93.
63. 21. 74.
56. 78. 83.

-->foo();

-1->

At this point I "hand execute" the assignment line of foo():



-1->M(3,:) = [2,4,6];

-1->M
M =

0. 0. 0.
0. 0. 0.
2. 4. 6.

What happended to the rest of M ?

If, when I firsted entered pause mode, I had simple typed

-1->M

then all of M gets printed out.
Furthermore I can then execute the assigment and all
of M is still there, with the 3rd row changed.

Is this a bug? If not, how does one stop at a point
in a function and "hand execute" the lines to watch
the behaviour?

Dean
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Dean S. Me » Sat, 07 Oct 2006 08:55:57

Sorry to reply to myself but I forgot to mention
that I'm running scilab-4.0-b4-20060515.

Since writing the previous message I have discovered more
weirdness (see my previous message in thread for context):

-->foo(m)

-1->size(M)
ans =

10. 3.

So at this point, a copy of M from foo()
is available in "pause".

-1->M(3,:) = [2,4,6];

-1->size(M)
ans =

3. 3.

A "new" M seems to have been created.

-1->clear M

-1->size(M)
ans =

10. 3.

Now we are back to the old copy.

This behaviour seems wrong to me.
How does one get a full copy of the various
matrices in a function into pause mode without
having to explicity evaluate every one by typing
its name first?

Dean

 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Helmut Jar » Sat, 07 Oct 2006 16:45:15


This is undefined. Your function expects an argument.

At this point you have a new local environment.
Any changes here are lost when say 'resume'


You have just created a new variable, called 'M'

Probably, you have "imported" M from the outside environment
and modified you local version.
=====> B U T if you 'resume' your function
all changes made at the '-1' level are lost.
So, it's just useless to make changes.

I don't know how to modify something (permanently) at the pause level.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Francois V » Sun, 08 Oct 2006 04:36:36


No.
Read again help resume.
[...]=resume(...) allows you to resume execution while keeping your
changes.

For instance:

-->function [] = foo(M)
--> pause;
--> M(1,1)=99;
--> pause;
--> disp(M);
-->endfunction

-->M=[1 2;3 4];

-->foo(M)

-1->M
M =

1. 2.
3. 4.

-1->M;M(1,1)=0
M =

0. 2.
3. 4.

-1->M=resume(M)

-1->M;M(1,1)=1000
M =

1000. 2.
3. 4.

-1->M=resume(M)

1000. 2.
3. 4.

-->


The Scipad de *** uses this feature extensively for the watch window.
Try it: watch some variable, and modify it when the de *** has
stopped on a breakpoint. Change its value and continue execution/debug.
The changed value is taken into account by Scilab. The underlying
mechanism is exactly the above one.

Anyway, my overall advice would be to use directly the de *** ;-)

I know, step by step is not available in the BUILD4 branch, only in the
svn trunk, but I have already explained why in the past.

Francois
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Dean S. Me » Sun, 08 Oct 2006 05:06:32

Helmut Jarausch wrote:
: Dean S. Messing wrote:
: > When I pause a function, I expect (maybe wrongly!) that copies of
: > the
: > variables in the function are available to me with the values they had
: > at the time of the pause, so that I can "work through" the steps of
: > the function by hand within pause mode to debug the function. (I have
: > not learned to use the debugger yet :-)
: > Yet, things are acting strangely for me. Here's
: > an (abstracted) example.
: > Suppose foo.sci is in the current directory:
: > // foo.sci
: > function [] = foo(M)
: > pause;
: > M(3,:) = [2,4,6];
: > return;
: > endfunction
: > Now consider the scilab session:
: > -->clear;
: > -->getf('./foo.sci');
: > -->m = int(100*rand(10,3));
: > -->m
: > m =
: >
: > 21. 27. 32.
: > 90. 24. 67.
: > 14. 35. 13.
: > 75. 83. 95.
: > 67. 84. 14.
: > 89. 23. 28.
: > 20. 50. 15.
: > 90. 30. 93.
: > 63. 21. 74.
: > 56. 78. 83.
: >
: > -->foo();
: >
:

: This is undefined. Your function expects an argument.

You are, of course, correct.

Unfortunately I must now confess that I have sinned. The "transcript"
I sent was cut and pasted from an earlier experiment where "m" was a
global variable and I thought globality was causing the problem.

Then I took out the "global" declarations and added M as a parameter
to foo(); And I called foo(m) not foo() in the later experiments.
Then I simply editted (the SIN!) my already written message to reflect
the changes but forgot to add "m" to this one spot. Else what I wrote
afterward would have been impossible since M is a different name from
m and would be undefined upon invoking foo().

I repent in dust and ashes :-)

: > -1->
:
: At this point you have a new local environment.
: Any changes here are lost when say 'resume'

I understand this.

: > At this point I "hand execute" the assignment line of foo():
: > -1->M(3,:) = [2,4,6];
: > -1->M
: > M =
: > 0. 0. 0.
: > 0. 0. 0.
: > 2. 4. 6.
: > What happended to the rest of M ?
:
: You have just created a new variable, called 'M'

Ok.

: > If, when I firsted entered pause mode, I had simple typed
: > -1->M
: > then all of M gets printed out.
: > Furthermore I can then execute the assigment and all
: > of M is still there, with the 3rd row changed.
:
: Probably, you have "imported" M from the outside environment
: and modified you local version.

Let me make sure I understand; If I first assign to M I create a new
variable. But by simply evaluating M, I import (a copy of) it from
foo()? Seems odd. I would think that when I pause, there should sit
copies of all the variables in existence at the time of the pause.

: =====> B U T if you 'resume' your function
: all changes made at the '-1' level are lost.

I understand this.

: So, it's just useless to make changes.

Not really. Since I don't know how to
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Dean S. Me » Sun, 08 Oct 2006 05:28:56

Francois Vogel wrote:
: Helmut Jarausch wrote:
: > Any changes here are lost when say 'resume'
: > if you 'resume' your function
: > all changes made at the '-1' level are lost.
: > So, it's just useless to make changes.
:
: No.
: Read again help resume.
: [...]=resume(...) allows you to resume execution while keeping your
: changes.
:
: For instance:
:
: -->function [] = foo(M)
: --> pause;
: --> M(1,1)=99;
: --> pause;
: --> disp(M);
: -->endfunction
:
: -->M=[1 2;3 4];
:
: -->foo(M)
:
: -1->M
: M =
:
: 1. 2.
: 3. 4.
:
: -1->M;M(1,1)=0
: M =
:
: 0. 2.
: 3. 4.

I noticed that you said M;M(1,1)=0;

not simply M(1,1)=0;
I take it this is a reflection of the
behaviour I wrote about?

: -1->M=resume(M)
:
: -1->M;M(1,1)=1000
: M =
:
: 1000. 2.
: 3. 4.
:
: -1->M=resume(M)
:
: 1000. 2.
: 3. 4.
:
: -->

But I have many matrices so this is impractical.

:
: The Scipad debugger uses this feature extensively for the watch window.
: Try it: watch some variable, and modify it when the debugger has
: stopped on a breakpoint. Change its value and continue execution/debug.
: The changed value is taken into account by Scilab. The underlying
: mechanism is exactly the above one.

Francois, I know you are the main (only?) current contributor
to scipad. Please do not misunderstand what I am going to say.

I only discovered scipad a week or so ago (having, I'm ashamed to say
used scilab off and on for a few years).

The reason is that I am a big-time emacs user, living in an emacs
widnow nearly 90% of my work life, including e-mail and this message.
The 10's of different commands I use are now second nature and I am
very quick at the keyboard.

Alex Vigodner, some time ago, wrote a great scilab.el mode emacs and
that is how I run scilab. Code in a file in one window, scilab in the
other. I can highlight lines and execute them very quickly, change
things, re-arrange, and re-execute extremely fast. That is why, when
I discovered "pause" a few weeks ago, I started this way to "debug".

I tried scibad a few days ago and it appears very nice! But alas I
had trouble figuring stuff out (like why my .sci file was being
flagged as .sce) I found the old messages saying to wrap in a function
but wasted time doing so.

Nonetheless I was not able to figure things out fast enough and I am
VERY pressed right now to get a certain algorithm I've working on
debugged. It is very overdue. So I abandoned scipad for the time
being. When I pick it up again, I'm sure I will have many questions.

: Anyway, my overall advice would be to use directly the debugger ;-)

How do you do this. When I do "help debugger" I get nothing. "help
debug" gets me (very little) information about "debug level" where I'm
told its for experts only. Is there a way to run a debugger apart
from scipad? Is debugging well-documented? I've used gdb (in emacs
of course -) for a long time to debug C so I'm familiar with this
style. I certainly wish such a thing existed for scilab.


: I know, step by step is not available in the BUILD4 branch, only in the
: svn trunk, but I have already explained why in the past.

Sorry I don't understand why but no time to understand now.
Thanks for all your help on this list, and the great work
you (and many othe
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Francois V » Sun, 08 Oct 2006 05:35:49


Let me just quote a very old post from Serge Steer (the following
version is a bit tuned and trimmed by me):

When you are under pause (-n->), the variable you're looking at is not
"locally defined", it is a variable of the calling environment. It may
be read but not modified. If you want to modify it you need to make a
copy before.

http://www.yqcomputer.com/ +local+group%3Acomp.soft-sys.math.scilab+author%3Asteer&rnum=4&hl=en#c8624f1293ed6578

(erm... where is this wiki again? this item deserves an entry...)



I think that what you're experiencing is... well let's not say
"correct" (this is subjective), but "as designed". You can see the
variables values of the calling environment but you must make a local
copy before modifying them.

To make a local copy of the calling environment variable V, and name
this copy V in the local environment, just say:
-1->V=V
or even just
-1->V

Francois
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Francois V » Sun, 08 Oct 2006 05:59:19


Yes, see my other answers in this thread. If still unclear, please come
back.


Not the only one. Enrico Segre is also contributing. However, the
de *** is my baby ;-)


I'll try ;-)
Well, out of the joke, I'm always happy to read comments, this is very
useful, even and maybe especially if these comments are explaining why
another tool is better. I'm very interested, and I really appreciate
the time you spent to write them down.


I understand that very well, no problem with that for me! Enjoy!


LOL!! Very funny typo!! (what?? it wasn't a typo?)


Wrapping the code into an invisible function so that the user can debug
.sce files is now automatic and fully transparent for the user (svn
trunk only, once more - this is not available in the BUILD4 branch for
the same reasons step by step is not - not my fault, guys).


They will be very welcome at that time.


All the available help about the de *** is currently in help scipad.


Hmm... you hit me. help debug should spit some man page telling a story
about the de *** . I will think about that. Maybe just a simple note
in the existing debug man page, pointing the user to the Scipad
de *** would be enough.

The current help debug is to debug the Scilab parser and only Serge
Steer is able to understand what debug(4) spits (ever tried?).

debug(-1) is undocumented and is a trick to try to figure out what's
happening when using ScilabEval from Tcl.


I don't think so. At least not the tool I developped.


Well, have a look at help scipad and come back with your comments. I
can easily improve that doc if you think it's needed.

Cheers,
Francois
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by brun » Sun, 08 Oct 2006 17:12:55


Dean,

just a remark : to debug "manually" a scilab function you could use

setbpt, delpbt, disppbt, resume and we will get a little gain over
the "pause
method". This is less practical than using the Francois 's debuger
but more than using pause. May be you already know this but
here is a small example.

Suppose you have defined the function :
function [r1,r2] = solve_quad_equ(a, b, c)
delta = b^2 - 4*a*c
r1 = (-b - sqrt(delta))/(2*a)
r2 = (-b + sqrt(delta))/(2*a)
endfunction

you load it in scilab then :

-->setbpt("solve_quad_equ") // put a break point at line 1

then :

-->[x1,x2] = solve_quad_equ(1,1,1)
Stop after row 1 in function solve_quad_equ :

here you can examine a,b and c (delta, r1 and r2 are not
yet defined)
-1->a
a =
1.

here I put a break point after line 2 :

-1->setbpt("solve_quad_equ",2)

Restart (untill the end of line 2) :
-1->resume
Stop after row 2 in function solve_quad_equ :

Now I can examine the value of delta :
-1->delta
delta =

- 3.

You can watch your breakpoint with :
-1->dispbpt()
breakpoints of function :solve_quad_equ

1
2

You can delete breakpoints :
-1->delbpt("solve_quad_equ",1)

-1->dispbpt()
breakpoints of function :solve_quad_equ

2

Note use : delbpt() to delete all the breakpoints.

hth
Bruno
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Dean S. Me » Sun, 15 Oct 2006 05:32:15


: Dean,
:
: just a remark : to debug "manually" a scilab function you could use
:
: setbpt, delpbt, disppbt, resume and we will get a little gain over
: the "pause
: method". This is less practical than using the Francois 's debuger
: but more than using pause. May be you already know this but
: here is a small example.

<snip>

I didn't know this stuff and your little tutorial is
very helpful. Thanks!

One question: in your example you only examine
varaibles, never change them.

Unfortunately the debug environemnt appears to be
just like "pause" in that I only have copies of and
not pointers to the objects. That is, in your
example, if I redefine a on the first breakpoint to
be, say, a=2, continue execution to the next
breakpoint, the value of delta is unchanged.

I also tried using resume(a) and a=resume(a) without
effect.

Anyway the "feature" of being able to stop the code,
diddle the varables, and resume is really where the
power of a du *** shows.

Again, thanks.

Dean
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by brun » Sun, 15 Oct 2006 16:04:20

> That is, in your

a = resume(a) must work (normally).

here is what I get with this debug session :

-->[x1,x2] = solve_quad_equ(1,1,1)
Stop after row 1 in function solve_quad_equ :
-1->a
a =
1.

-1->a = 2
a =
2.

-1->a = resume(a)
Stop after row 2 in function solve_quad_equ :

-1->delta
delta =
- 7.

So you see that the delta values is not -3 but -7. A shortcut is to
use :

[a,b,c] = resume(2,3,4)

if you want to restart given new values 2 for a, 3 for b and 4 for c.

hth
Bruno
 
 
 

pause mode and missing matrix rows: bug or feature?

Post by Francois V » Sat, 11 Nov 2006 05:14:54

Francois Vogel a rit :


Done (Scilab SVN trunk only).



Now also a little note about this in help debug.


Francois