| Bill Allombert on Sat, 10 Jan 2026 11:03:55 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: gtransall: recursive variant of gtrans |
On Sat, Jan 10, 2026 at 07:57:52AM +0800, 管理员 wrote:
> static GEN _gtransall_wrap(void *E, GEN x) {
> (void)E; return gtransall(x);
> }
>
> GEN gtransall(GEN x) {
> long i, j, l, lc, t = typ(x);
> GEN L, res;
>
> l = lg(x);
> switch (t) {
> case t_VEC: t = t_COL; break;
> case t_COL: t = t_VEC; break;
> case t_MAT:
> if (l < 2) return cgetg(1,t_MAT);
> lc = lgcols(x);
> res = cgetg(lc, t_MAT);
> for (i = 1; i < lc; i++) {
> GEN y = cgetg(l, t_COL);
> for (j = 1; j < l; j++) gel(y,j) = gtransall(gcoeff(x,i,j));
> gel(res,i) = y;
> }
> return res;
> case t_LIST:
> return genapply(NULL, _gtransall_wrap, x);
> default:
> /* t_CLOSURE uses t_VEC for internal, convert to t_COL is invalid */
> if (is_noncalc_t(t) || !is_recursive_t(t)) return gcopy(x);
> }
>
> res = cgetg(l, t);
> i = lontyp[t];
> memcpy(res + 1, x + 1, (i - 1)*sizeof(long));
> while (i < l) {
> gel(res,i) = gtransall(gel(x,i));
> i++;
> }
> return res;
> }
Thanks! Could you explain whath this fonction does, why this is needed and give
some example ?
Also, you should use cgetg_copy, instead of memcpy.
Cheers,
Bill