do(); do(); not same as while(n<2){do();}

E

er

hi,

could someone please point to a strategy to debug CODE 2?

//CODE 1
A tmp_nxt(var);
A tmp = tmp_nxt;

tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp = Terms_total_degree::make_from_previous(tmp);
tmp_nxt = tmp;

//content of tmp and tmp_alt is as expected.

//CODE 2


A tmp_nxt(var);
A tmp = tmp_nxt;

for(unsigned int i=0; i<2;++i){
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
};

//content of tmp and tmp_nxt is garbage.


A is something like:
class A{
ublas::vector_type var;
std::vector<ublas::vector_range_type> vrs;// each vr is a section of
var
A(const std::vector<ublas::vector_range_type>& previous){/*...*/}
A make_from_previous(const A& p){
//p.vrs is fine at this point
A a(p.vrs);// content of p.vrs is garbage a this point
return a;
}
};
 
V

Victor Bazarov

er said:
could someone please point to a strategy to debug CODE 2?

//CODE 1
A tmp_nxt(var);
A tmp = tmp_nxt;

tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp = Terms_total_degree::make_from_previous(tmp);
tmp_nxt = tmp;

//content of tmp and tmp_alt is as expected.

//CODE 2


A tmp_nxt(var);
A tmp = tmp_nxt;

for(unsigned int i=0; i<2;++i){
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
};

What's the trailing semicolon for?
//content of tmp and tmp_nxt is garbage.

Where, after the loop? Inside? Which run of the loop? First?
Second? Both?
A is something like:
class A{
ublas::vector_type var;
std::vector<ublas::vector_range_type> vrs;// each vr is a section of
var
A(const std::vector<ublas::vector_range_type>& previous){/*...*/}
A make_from_previous(const A& p){
//p.vrs is fine at this point
A a(p.vrs);// content of p.vrs is garbage a this point
return a;
}
};

Simplify. Divide and conquer. Reduce the program to the bare
minimum that still exhibits the problem. If it's not clear after
that, post it here. But it is *essential* for the code to be the
*bare minimum*. Nothing unnecessary should be present to avoid
murkying the waters.

V
 
C

Christopher Pisz

er said:
hi,

could someone please point to a strategy to debug CODE 2?

//CODE 1
A tmp_nxt(var);
A tmp = tmp_nxt;

tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp = Terms_total_degree::make_from_previous(tmp);
tmp_nxt = tmp;

//content of tmp and tmp_alt is as expected.

//CODE 2


A tmp_nxt(var);
A tmp = tmp_nxt;

for(unsigned int i=0; i<2;++i){
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
};

//content of tmp and tmp_nxt is garbage.


A is something like:
class A{
ublas::vector_type var;
std::vector<ublas::vector_range_type> vrs;// each vr is a section of
var
A(const std::vector<ublas::vector_range_type>& previous){/*...*/}
A make_from_previous(const A& p){
//p.vrs is fine at this point
A a(p.vrs);// content of p.vrs is garbage a this point
return a;
}
};


I'd start by commenting what you expect the code to accomplish. Renaming you
variables such that people can tell what they are for simply by reading the
name, indenting properly, naming your functions such that thier names
reflect thier chore, and using a consistant style.

"A make_from_previous(const A& p)"
What the heck is an A? What's a p? why is it called p? What's a "var" is
that supposed to mean variable? what kind? what's it being used for? What's
an a? What does make_from_previous do? Does it only make_from_previous if it
is called using something that IS "previous" as an argument? or is it more
like a copy constructor? Or perhaps it is some kind of linked list if A is a
node with a pointer to another element, but who would know with a name like
"A", if that's the case, lets call it "Node" or something better...

If Joe Bob off the street cannot tell what your code is doing, you probably
won't either after some time passes. Names like "a" "A" "p" "x1,x2,x3" make
really make Debugging a chore for anyone.
 
I

Ioannis Gyftos

//CODE 1
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp = Terms_total_degree::make_from_previous(tmp);
tmp_nxt = tmp;
//CODE 2
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;

Should these be equivalent?

In terms of your thread title, you are comparing {do1(); do2();} with
while(n<2){do1();}
 
V

Victor Bazarov

Ioannis said:
//CODE 1
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp = Terms_total_degree::make_from_previous(tmp);
tmp_nxt = tmp;
//CODE 2
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;
tmp_nxt = A::make_from_previous(tmp);
tmp = tmp_nxt;

Should these be equivalent?

My guess is that the OP tried (for our benefit) to rename the 'Terms..'
namespace (or class) to 'A' and missed one occurrance.
In terms of your thread title, you are comparing {do1(); do2();} with
while(n<2){do1();}

It useful observation, but somehow I don't think it's the cause of the
problem.

V
 
E

er

I'd start by commenting what you expect the code to accomplish. Renaming you
variables such that people can tell what they are for simply by reading the
name, indenting properly, naming your functions such that thier names
reflect thier chore, and using a consistant style.

"A make_from_previous(const A& p)"
What the heck is an A? What's a p? why is it called p? What's a "var" is
that supposed to mean variable? what kind? what's it being used for? What's
an a? What does make_from_previous do? Does it only make_from_previous if it
is called using something that IS "previous" as an argument? or is it more
like a copy constructor? Or perhaps it is some kind of linked list if A is a
node with a pointer to another element, but who would know with a name like
"A", if that's the case, lets call it "Node" or something better...

If Joe Bob off the street cannot tell what your code is doing, you probably
won't either after some time passes. Names like "a" "A" "p" "x1,x2,x3" make
really make Debugging a chore for anyone.

thanks for your comments. actually classes and member functions i used
are named after their functionality but for the sake of this post i
have renamed the bare essentials A (class), a (instance), p
(previous). sorry if this created confusion, but giving away the
original code would have created a bloated post and would have begged
for more questions than answers.

thank you ALL for your recommendations, i'll probably refine my
question later by taking into account previous suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top