Charles Greathouse on Fri, 28 Mar 2014 16:41:41 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Unidentified subject!


Incidentally, is there any reason to use stoi(2) rather than gen_2?

Charles Greathouse
Analyst/Programmer
Case Western Reserve University


On Fri, Mar 28, 2014 at 11:32 AM, Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Fri, Mar 28, 2014 at 02:34:11PM +0100, Giacomo Mulas wrote:
> >>Then I create the extended matrix with
> >>
> >>  GEN coeffs2 = cgetg(cols+2, t_MAT);
> >>  for (j=1; j<=cols; j++) {
> >>    gel(coeffs2,j) = gel(coeffs1,j);
> >>  }
>
> >This is where the bug lies: you need to copy gel(coeffs1,j):
> >gel(coeffs2,j) = gcopy(gel(coeffs1,j));
> >or even simply
> >GEN coeffs2 = gcopy(coeffs1);
> >otherwise the columns of coeffs2 and coeffs1 are sharing the same memory.
>
> Indeed that's what I intended: coeffs2 is a matrix with one more column than
> coeffs1, and apart from the additional one it is (and remains throughout the
> calculation) identical to coeffs1. So I saw nothing wrong with them sharing
> the same memory.

But your code is doing
  gmael2(coeffs2,2,4) = stoi(2);
so it is modifying the older columns.

maybe you wanted to do
  gmael2(coeffs2,4,2) = stoi(2);
in which case you would be correct.

Cheers,
Bill.