Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #61593 > unrolled thread

Column slices

Started byluser droog <luser.droog@gmail.com>
First post2015-05-05 23:18 -0700
Last post2015-05-25 00:13 -0700
Articles 20 on this page of 50 — 10 participants

Back to article view | Back to comp.lang.c


Contents

  Column slices luser droog <luser.droog@gmail.com> - 2015-05-05 23:18 -0700
    Column slices asetofsymbols@gmail.com - 2015-05-06 00:26 -0700
      Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-06 02:33 -0700
        Re: Column slices Bartc <bc@freeuk.com> - 2015-05-06 10:46 +0100
        Re: Column slices asetofsymbols@gmail.com - 2015-05-07 11:02 -0700
          Re: Column slices asetofsymbols@gmail.com - 2015-05-07 14:05 -0700
    Re: Column slices Nobody <nobody@nowhere.invalid> - 2015-05-06 08:29 +0100
    Re: Column slices Bartc <bc@freeuk.com> - 2015-05-06 10:30 +0100
      Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-06 03:11 -0700
        Re: Column slices asetofsymbols@gmail.com - 2015-05-08 09:05 -0700
    Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-11 16:50 -0700
      Re: Column slices asetofsymbols@gmail.com - 2015-05-11 17:24 -0700
        Re: Column slices asetofsymbols@gmail.com - 2015-05-11 19:01 -0700
          Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-19 09:56 -0700
            Re: Column slices asetofsymbols@gmail.com - 2015-05-19 10:43 -0700
              Re: Column slices asetofsymbols@gmail.com - 2015-05-19 11:16 -0700
                Re: Column slices asetofsymbols@gmail.com - 2015-05-19 11:27 -0700
                Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-19 21:28 -0700
                  Re: Column slices asetofsymbols@gmail.com - 2015-05-20 08:05 -0700
              Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-19 21:20 -0700
                Re: Column slices asetofsymbols@gmail.com - 2015-05-20 08:55 -0700
                  Re: Column slices asetofsymbols@gmail.com - 2015-05-20 08:58 -0700
                    Re: Column slices asetofsymbols@gmail.com - 2015-05-21 01:22 -0700
                      Re: Column slices asetofsymbols@gmail.com - 2015-05-21 01:34 -0700
                      Re: Column slices asetofsymbols@gmail.com - 2015-05-26 19:17 -0700
                      Re: Column slices asetofsymbols@gmail.com - 2015-05-31 13:56 -0700
                        Re: Column slices Keith Thompson <kst-u@mib.org> - 2015-05-31 14:23 -0700
                          Re: Column slices Ian Collins <ian-news@hotmail.com> - 2015-06-01 09:37 +1200
                      Re: Column slices asetofsymbols@gmail.com - 2015-06-01 01:23 -0700
                        Re: Column slices Ian Collins <ian-news@hotmail.com> - 2015-06-01 20:35 +1200
                          Re: Column slices mark.bluemel@gmail.com - 2015-06-01 03:50 -0700
                          Re: Column slices luser droog <luser.droog@gmail.com> - 2015-06-01 18:04 -0700
                            Re: Column slices luser droog <luser.droog@gmail.com> - 2015-06-01 18:16 -0700
                            Re: Column slices "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-06-01 19:57 -0700
                            Re: Column slices Rosario19 <Ros@invalid.invalid> - 2015-06-02 08:30 +0200
                              Re: Column slices luser droog <luser.droog@gmail.com> - 2015-06-02 00:22 -0700
      Re: Column slices Ike Naar <ike@iceland.freeshell.org> - 2015-05-12 06:06 +0000
        Re: Column slices Ike Naar <ike@iceland.freeshell.org> - 2015-05-12 21:15 +0000
      Re: Column slices asetofsymbols@gmail.com - 2015-05-13 20:49 -0700
        Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-13 23:43 -0700
          Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-13 23:44 -0700
          Re: Column slices asetofsymbols@gmail.com - 2015-05-14 01:02 -0700
            Re: Column slices asetofsymbols@gmail.com - 2015-05-15 23:06 -0700
              Re: Column slices asetofsymbols@gmail.com - 2015-05-16 03:46 -0700
    Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-23 00:17 -0700
      Re: Column slices asetofsymbols@gmail.com - 2015-05-23 07:59 -0700
        Re: Column slices asetofsymbols@gmail.com - 2015-05-23 21:25 -0700
          Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-24 18:29 -0700
        Re: Column slices luser droog <luser.droog@gmail.com> - 2015-05-24 18:08 -0700
          Re: Column slices asetofsymbols@gmail.com - 2015-05-25 00:13 -0700

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#62346

Fromasetofsymbols@gmail.com
Date2015-05-20 08:55 -0700
Message-ID<be10e258-bd94-4000-849f-eb7cd63272f2@googlegroups.com>
In reply to#62324
luser droog wrote:"
I think it still works for this case. Remember that 
this is not a normal 'transpose' like everybody else 
does. We don't rearrange the data at all. This is more 
properly called a 'dope-vector pseudo-transpose'. 
Instead of changing the data, we just change the 
constants in the access formula, rearranging the 
coefficients of the polynomial. In a real sense, this 
is just an application of the commutativity and 
associativity of addition."

I rearrange data instead on traspose
matrices. 
Yes could be computationally not
good but
I'm sure in this way that i j index
near has a near collocation in the
memory matrix linear layout
And all matrices as
A11 A12 ... A1n
...............
Am1 Am2.....Amn
follow this linear memory configuration
A11,A12,..A1n,A2n....Am1,Am2,...Amn

[toc] | [prev] | [next] | [standalone]


#62348

Fromasetofsymbols@gmail.com
Date2015-05-20 08:58 -0700
Message-ID<ccfc958e-f44e-4ece-a516-f59a44dc5a3e@googlegroups.com>
In reply to#62346
I wrote:"
I rearrange data instead on traspose 
matrices. 
Yes could be computationally not 
good but 
I'm sure in this way that i j index 
near has a near collocation in the 
memory matrix linear layout 
And all matrices as 
A11 A12 ... A1n 
............... 
Am1 Am2.....Amn 
follow this linear memory configuration 
A11,A12,..A1n,A2n....Am1,Am2,...Amn
"
Yes I can make some errors on that

[toc] | [prev] | [next] | [standalone]


#62393

Fromasetofsymbols@gmail.com
Date2015-05-21 01:22 -0700
Message-ID<a063bfe3-3de5-4409-84c9-fc67b5601eaf@googlegroups.com>
In reply to#62348
a+b as matrixes not seems ok, better c.sum(a, b)

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <float.h>
#include <iostream.h>

#define  G(a,b)   if(a)goto b
#define  R   return
#define  P   printf
#define  M   malloc
#define  Fr  free
#define  F   for
#define  S   sizeof
#define  u8  unsigned char
#define  u16 unsigned short
#define  u32 unsigned
#define  i32 int
#define  d64 double

template<class T>  class permutazioni{
public:

permutazioni(u32  a)
{u32   i;
 n=0; arr=0; c=0; cnt=0; ji=0;
 if(a==0||a>0xFF)  {PBadAlloc=1; R;}
 arr=(T*)malloc( a*sizeof(T) );
 if(arr==0){PBadAlloc=1; R;}
 c=(u32*)malloc( a*sizeof(u32) );
 if(c==0){free(arr); PBadAlloc=1; arr=0; R;}
 n=a;
 F(i=0; i<n; ++i){c[i]=0; arr[i]=i;}
}

~permutazioni(){free(c); free(arr);}

u32  swp(T*  a, u32 i, u32 j)
{T  x;
 if(i>=n||j>=n) R -1;
 if(i==j)       R  0;
 x=a[i]; a[i]=a[j]; a[j]=x; ++cnt;
 R  0;
}

/* from Sedgewick, result in arr [3!=6] */
u32  nextP(u32  a)
{u32          k;

 if(a==0)
   {F(k=0; k<n; ++k)  c[k]=0;
    ji=0; cnt=0;
    R  1;
   }
 F( ; ji<n; )
   {if(c[ji]<ji)
       {swp(arr, ((ji+1)%2? 0: c[ji]) , ji);
        ++c[ji]; ji=1;   // can be ok ji=0; too
        R  1;  //  ok
       }
    else {c[ji++]=0; }
   }
 R  0;  // for end
}

void  print(void)
{u32  i;
 F(i=0; i<n; ++i)
        if(i==0  ) cout<<"[ "<< arr[i]<<" ";
   else if(i==n-1) cout<<arr[i]<<" ]  ";
   else            cout<<arr[i]<<" ";
}

i32  e(void){R  PBadAlloc;}

T&  operator[](i32  i){R  arr[i];}

 u32     n;     /* number of element index 0..n-1 */
 T    *arr;     /* where they are */
 u32    *c;     /* index array for find next permutation*/
 u32    ji;     /* index for next permutation: nextP()  */
 u32   cnt;     /* cnt%2?-1:1 sign of permutation nextP() return*/
 /* if some allocation error for all permutation here 1 */
 static u32  PBadAlloc;
};

template<class T> u32 permutazioni<T>::PBadAlloc=0;

// functions for detect u32 or i32 overflow
u32  omul(u32  a,  u32  b)
{asm{mov eax, a
     mov edx, b
     mul edx
     cmp edx, 0
     je  lab
     mov eax, -1
lab:
 }
 R  _EAX;
}

u32  oadd(u32  a,  u32  b)
{asm{mov eax, a
     mov edx, b
     add eax, edx
     jnc  lab
     mov eax, -1
lab:
 }
 R  _EAX;
}

u32  osub(u32  a,  u32  b)
{asm{mov eax, a
     mov edx, b
     sub eax, edx
     jnc lab
     mov eax, -1
lab:
    }
 R  _EAX;
}

i32  omul(i32  a,  i32  b)
{asm{mov  eax, a
     mov  edx, b
     imul edx
     jno  lab
     mov  eax, 0x80000000
lab: 
    }
 R  _EAX;
}


i32  oadd(i32  a,  i32  b)
{asm{mov eax, a
     mov edx, b
     add eax, edx
     jno lab
     mov eax, 0x80000000
lab:
    }
 R  _EAX;
}

i32  osub(i32  a,  i32  b)
{asm{mov eax, a
     mov edx, b
     sub eax, edx
     jno lab
     mov eax, 0x80000000
lab: 
    }
 R  _EAX;
}

// 32 bit unsigned and signed with overflow
class ou32{
public:
ou32(){v=0;}
ou32(u32  a){v=a;}
//operator u32() const{R  v;}
ou32  operator=(u32  h){v=h; R *this;}


ou32 operator=( ou32 a){v=a.v; R *this;}
ou32 operator*=(ou32 a){v=omul(v, a.v); R *this;}
ou32 operator*=( u32 a){v=omul(v, a);   R *this;}

ou32 operator+=(ou32 a){v=oadd(v, a.v); R *this;}
ou32 operator+=( u32 a){v=oadd(v, a  ); R *this;}

ou32 operator-=(ou32 a){v=osub(v, a.v); R *this;}
ou32 operator-=( u32 a){v=osub(v, a  ); R *this;}

ou32 operator/=(ou32 a){if(v==-1||a.v==-1) v=-1;
                        else  v=v/a.v;
                        R *this;
                       }
ou32 operator/=(u32 a){if(v==-1||a==-1) v=-1;
                        else  v=v/a;
                        R *this;
                       }
ou32 operator++(){v=(v==-1? -1: ++v); R  *this;}
ou32 operator++(int){ou32  t=*this; if(v!=-1) ++v; R  t;}
ou32 operator--(){v=(v==-1? -1: --v); R  *this;}
ou32 operator--(int){ou32  t=*this; if(v!=-1) --v; R  t;}
friend ou32 operator*(ou32  a, ou32  b){ou32  r; r.v=omul(a.v, b.v); R  r;}
friend ou32 operator*(ou32  a,  u32  b){ou32  r; r.v=omul(a.v, b  ); R  r;}
friend ou32 operator*(u32   a, ou32  b){ou32  r; r.v=omul(a  , b.v); R  r;}

friend ou32 operator+(ou32  a, ou32  b){ou32  r; r.v=oadd(a.v, b.v); R  r;}
friend ou32 operator-(ou32  a, ou32  b){ou32  r; r.v=osub(a.v, b.v); R  r;}
friend ou32 operator/(ou32  a, ou32  b)
{ou32  r; 
 if(a.v==-1||b.v==-1)  r.v=-1;
 else                  r.v=a.v/b.v;
 R  r;
}
friend ostream& operator<<(ostream&  ostr, ou32  a)
{if( a.v==-1 ) ostr<<"ErrElm"; else  ostr<<a.v; R  ostr;}
friend i32  operator==(ou32 a, ou32 b){R  a.v==b.v;}
friend i32  operator!=(ou32 a, ou32 b){R  a.v==b.v;}
friend i32  operator<=(ou32 a, ou32 b){R  a.v<=b.v;}
friend i32  operator>=(ou32 a, ou32 b){R  a.v>=b.v;}
friend i32  operator<( ou32 a, ou32 b){R  a.v< b.v;}
friend i32  operator>( ou32 a, ou32 b){R  a.v> b.v;}

u32  v;
};

class oi32{
public:
oi32(){v=0;}

operator i32() const{R  v;}
oi32  operator=(i32  h){v=h; R *this;}

oi32  operator=(oi32 a){v=a.v; R *this;}
oi32 operator*=(oi32 a){v=omul(v, a.v); R *this;}
oi32 operator+=(oi32 a){v=oadd(v, a.v); R *this;}
oi32 operator-=(oi32 a){v=osub(v, a.v); R *this;}
oi32 operator/=(oi32 a)
{if(v==0x80000000||a.v==0x80000000) v=0x80000000;
 else                               v=v/a.v;
 R   *this;
}
oi32 operator++(){v=(v==0x80000000? 0x80000000: ++v); R  *this;}
oi32 operator++(int){oi32  t=*this; if(v!=0x80000000) ++v; R  t;}
oi32 operator--(){v=(v==0x80000000? 0x80000000: --v); R  *this;}
oi32 operator--(int){oi32  t=*this; if(v!=0x80000000) --v; R  t;}
friend oi32 operator*(oi32  a, oi32  b){oi32  r; r.v=omul(a.v, b.v); R  r;}
friend oi32 operator+(oi32  a, oi32  b){oi32  r; r.v=oadd(a.v, b.v); R  r;}
friend oi32 operator-(oi32  a, oi32  b){oi32  r; r.v=osub(a.v, b.v); R  r;}
friend oi32 operator/(oi32  a, oi32  b)
{oi32  r;
 if(a.v==0x80000000||b.v==0x80000000)  r.v=0x80000000;
 else                                  r.v=a.v/b.v;
 R  r;
}
friend ostream& operator<<(ostream&  ostr, oi32  a)
{if( a.v==0x80000000 ) ostr<<"ErrElm"; else  ostr<<a.v; R  ostr;}
friend i32  operator==(oi32 a, oi32 b){R  a.v==b.v;}
friend i32  operator!=(oi32 a, oi32 b){R  a.v==b.v;}
friend i32  operator<=(oi32 a, oi32 b){R  a.v<=b.v;}
friend i32  operator>=(oi32 a, oi32 b){R  a.v>=b.v;}
friend i32  operator<( oi32 a, oi32 b){R  a.v< b.v;}
friend i32  operator>( oi32 a, oi32 b){R  a.v> b.v;}

i32  v;
};

/*
I[0],I[1],I[2],I[3],I[4],sizeElement, sz, led,  [matrix data]
0    1    2    3    4    5            6   7     8
1    2    3    4    5    6            7   8     9
               I[I[0]+1]=I[3]
                    I[I[0]+I[0]]=I[4]

I[0],I[1],..,I[p[0]], sizeElement, sz,      led,     [matrix data]
0    1       I[0]     2*I[0]+1     2*I[0]+2 2*I[0]+3 2*I[0]+4  indirizzo
1    2       I[0]+1   2*I[0]+2     2*I[0]+3 2*I[0]+4 2*I[0]+5  nelement
I[0]:         is the number of index as 32 bit
I[1]:         is the first max index as 32 bit
....
I[I[0]]:      is the last max index
I[I[0]+1]:    is w[0]
...
I[2*I[0]]:    is w[I[0]]
I[2*I[0]+1]:  is the size of element as 32 bit 5
I[2*I[0]+2]:  is sz size of   "data" area      6
I[2*I[0]+3]:  is led: 0 matrix is ok, 1 overflow or errors in matrix 7
sono 2*I[0]+4 elementi [8 elementi]
I[2*I[0]+4]:  is matrix "data" area            8
*/

// access to led as u32*
#define  Led(a)  ((a)+*(a)*2+3)
// access to size of matrix data    as u32*
#define  SZ(a)   ((a)+*(a)*2+2)
// access to size element of matrix as u32*
#define  SZe(a)  ((a)+*(a)*2+1)
// access to data                   as u8*
#define  Data(a) (u8*) ((a)+*(a)*2+4)

i32 Mcon(u32**  pm, u32  msize, ...);
u8*  Aelm(u32*  pm, ...);

template<class T> class Matrix{
public:
 Matrix(u32 a, u32  b){Mcon(&mtr, S(T), a, b, -1);}
 Matrix(u32 a, u32  b, u32  c){Mcon(&mtr, S(T), a, b, c, -1);}
 Matrix(u32 a, u32  b, u32  c, u32  d){Mcon(&mtr, S(T), a, b, c, d, -1);}
 Matrix(Matrix<T>& a)
{     if(a.mtr[0]==2)
    R  Mcon(&mtr, S(T), a.mtr[1], a.mtr[2], -1);
 else if(a.mtr[0]==3)
    R  Mcon(&mtr, S(T), a.mtr[1], a.mtr[2], a.mtr[3], -1);
 else if(a.mtr[0]==4)
    R  Mcon(&mtr, S(T), a.mtr[1], a.mtr[2], a.mtr[3], a.mtr[4], -1);
}
~Matrix(){Mcon(&mtr, 0);}

T&  e(u32 i, u32 j)        {R *(T*) Aelm(mtr, i,j);}
T&  e(u32 i, u32 j, u32  k){R *(T*) Aelm(mtr, i,j,k); }
T&  e(u32 i, u32 j, u32  k, u32  v){R *(T*) Aelm(mtr, i,j,k, v); }

i32  ov(u32  a){R  0;}  // mai overflow
u32  ro(u32  a){R -1;}
i32  ov(i32  a){R  0;}
i32  ro(i32  a){R -1;}

i32  ov(d64  a){R _isnan(a)|| ! _finite(a) ? 1: 0; } // overflow con NAN
d64  ro(d64  a){d64  r=1.0E800; R  r;} /* ritorna un elemento di d64 di errore*/

i32  ov(ou32 a){R a.v==-1? 1: 0; } // overflow con -1 range: 0..0FFFFFFFE
ou32 ro(ou32 a){ou32  r; r.v=-1; R  r;} /* ritorna un elemento di ou32 di errore*/

i32  ov(oi32 a){R a.v==0x80000000? 1: 0; } // overflow con 0x80000000
 /* ritorna un elemento di oi32 di errore*/
oi32 ro(oi32 a){oi32  r; r.v=0x80000000; R  r;}

Matrix<T>& operator=(Matrix<T>& a)
{u32  i;
 
 *Led(mtr)=0;
 if(a.mtr==  0)
     {
l0:   *Led(mtr)=1; G(1,z); /* errore trovato e riportato */
     }
 G(*Led(a.mtr), l0); 
 G(*SZe(mtr)!=*SZe(a.mtr), l0);
 if(a.mtr!=mtr)
   {// deve essere delle stesse dimensioni e indici massimi
    F(i=0;i<=mtr[0];++i)
         G(a.mtr[i]!=mtr[i], l0); 
    memcpy(mtr, a.mtr, *SZ(a.mtr)+(2*a.mtr[0]+4)*sizeof(u32));
   }
z:
 R  *this;
}

Matrix<T>& operator+=(Matrix<T>& a)
{u32        i;
 T    *p1,*p2;
 u8     *pmax;

 if(a.mtr==  0)
     {
l0:   *Led(mtr)=1; G(1,z); /* errore trovato e riportato */
     }
 G(*Led(mtr), z); G(*Led(a.mtr), l0);
     // deve essere delle stesse dimensioni e indici massimi
 F(i=0;i<=mtr[0];++i)
         G(a.mtr[i]!=mtr[i], l0);
 G(*SZe(mtr)!=*SZe(a.mtr), l0);
 p1=(T*) Data(mtr); p2=(T*) Data(a.mtr);
 i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax ;++p1,++p2)
        {*p1=*p1+*p2; G(ov(*p1),l0);}
z:
 R  *this;
}

Matrix<T>& operator-=(Matrix<T>& a)
{u32        i;
 T    *p1,*p2;
 u8     *pmax;

 if(a.mtr==  0)
     {
l0:   *Led(mtr)=1; G(1,z); /* errore trovato e riportato */
     }
 G(*Led(mtr), z); G(*Led(a.mtr), l0);
 // deve essere delle stesse dimensioni e indici massimi
 F(i=0;i<=mtr[0];++i)
         G(a.mtr[i]!=mtr[i], l0);
 G(*SZe(mtr)!=*SZe(a.mtr), l0);
 p1=(T*) Data(mtr); p2=(T*) Data(a.mtr);
 i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax ;++p1,++p2)
     {*p1=*p1-*p2; G(ov(*p1),l0);}
z:
 R  *this;
}

Matrix<T>& operator*=(T& a)
{u32        i;
 T        *p1;
 u8     *pmax;

 G(*Led(mtr), z);
 p1=(T*) Data(mtr);
 i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax ;++p1)
     {*p1 = *p1 * a;
      if(ov(*p1)) {*Led(mtr)=1; G(1,z);}
     }
z:
 R  *this;
}


Matrix<T>& operator*=(T  a)
{u32        i;
 T        *p1;
 u8     *pmax;

 G(*Led(mtr), z);
 p1=(T*) Data(mtr);
 i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax ;++p1)   
       {*p1 = *p1 * a;
        if(ov(*p1)) {*Led(mtr)=1; G(1,z);}        
       }
z:
 R  *this;
}

// *this=a*b
// ove *this e' come a mxn e b e' nxj
i32  mul(Matrix<T>&  a, Matrix<T>&  b)
{u32  i, j, z, i0, i1;
 T    a1, a2,  s, t1, t2;

 *Led(mtr)=0;  
 G( *Led(a.mtr)||*Led(b.mtr), l0);
//     la 1xn si puo' moltiplicare per nx1
// ovvero jxn si puo' moltiplicare per nxm
 if(a.mtr[0]!=2||b.mtr[0]!=2||(*this).mtr[0]!=2)
     { l0: *Led(mtr)=1; l1: R  -1; }
 G( *SZe(mtr) != *SZe(a.mtr),                      l0);
 G(a[1]!=b[0]||(*this)[0]!=a[0]||(*this)[1]!=a[1], l0);

 if(this!= &a && this!= &b)
    {i0=(*this)[0]; i1=(*this)[1];
     F(i=0; i<i0; ++i)
       {F(j=0; j<i1; ++j)
          {F(z=0, s=0u; z<i1; ++z)
             {a1=a.e(i,z); a2=b.e(z,j); s=s+(a1*a2);
              G(ov(s),l0);
             }
          (*this).e(i,j)=s;
          }
      }
    }
 else {Matrix<T>  t(mtr[1], mtr[2]);
       t.mul(a,b); *this=t;
      }

 R  0;
}

// *this=a-b
i32 sub(Matrix<T>&  a, Matrix<T>&  b)
{u32            i;
 T    *p1,*p2, p3;
 u8         *pmax;

*Led(mtr)=0;
 if(a.mtr==0||b.mtr==0)
     {
l0:   *Led(mtr)=1; R  -1;
     }
 G( *Led(a.mtr)||*Led(b.mtr), l0);  
 // deve essere delle stesse dimensioni e indici massimi
 F(i=0;i<=mtr[0];++i)
    G(a.mtr[i]!=mtr[i]||b.mtr[i]!=mtr[i], l0);
 G(*SZe(mtr)!=*SZe(a.mtr), l0);
 G(*SZe(mtr)!=*SZe(b.mtr), l0);
 p1=(T*)Data(mtr); p2=(T*)Data(a.mtr); p3=(T*) Data(b.mtr);
 i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax; ++p1, ++p2) 
        {*p1=*p2-*p3; G(ov(*p1),l0);}
 R  0;
}

// *this=a+b
i32 add(Matrix<T>&  a, Matrix<T>&  b)
{u32            i;
 T    *p1,*p2, p3;
 u8         *pmax;

*Led(mtr)=0;
 if(a.mtr==0||b.mtr==0)
     {
l0:   *Led(mtr)=1; R  -1;
     }
 // deve essere delle stesse dimensioni e indici massimi
 G( *Led(a.mtr)||*Led(b.mtr), l0);
 F(i=0;i<=mtr[0];++i)
    G(a.mtr[i]!=mtr[i]||b.mtr[i]!=mtr[i], l0);
 G(*SZe(mtr)!=*SZe(a.mtr), l0);
 G(*SZe(mtr)!=*SZe(b.mtr), l0);
 p1=(T*)Data(mtr); p2=(T*)Data(a.mtr); p3=(T*) Data(b.mtr);
 i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax ;++p1,++p2) 
     { *p1=*p2+*p3; G(ov(*p1),l0); }
 R  0;
}

i32  transpose(Matrix<T>&  a)
{u32    t, i, j, i0, i1;

 *Led(mtr)=0;
 if(a.mtr==0)
     {
l0:   *Led(mtr)=1; l1: R  -1;
     }
 G(*Led(a.mtr), l0);
 G(*SZe(mtr)!=*SZe(a.mtr), l0);
 G(a.mtr[0]!=2||mtr[0]!=2, l0);
 G(mtr[1]*mtr[2]!=a.mtr[1]*a.mtr[2], l0);
 mtr[1]=a.mtr[2]; mtr[2]=a.mtr[1]; 
 mtr[4]=a.mtr[4]; mtr[3]=a.mtr[1];
 i0=mtr[1]; i1=mtr[2];
 F(i=0; i<i0; ++i)
    {F(j=0; j<i1; ++j)
          (*this).e(i,j)=a.e(j,i);
    }
 R  0;
}

i32  transpose(void)
{u32   i, j, i0;
 T            t;

 if(mtr[0]!=2)
     {
l0:   *Led(mtr)=1; l1: R  -1;
     }
 G( *Led(mtr), l1 );
 if(mtr[1]==mtr[2]) // NxN matrix
    {i0=mtr[1];
     F(i=0; i<i0; ++i)
        {F(j=0; j<i; ++j)
             {t=(*this).e(i,j);
              (*this).e(i,j)=(*this).e(j,i);
              (*this).e(j,i)=t;
             }
        }
    }
 else {Matrix<T>  a(mtr[2], mtr[1]);
       G(a.e(), l0);
       G( a.transpose(*this)==-1 , l0);
       i =mtr[1]; mtr[1]=mtr[2]; mtr[2]=i;
       mtr[3]=i;   // cambia gli indici per poter copiare
       *this=a;    // qui
      }
 R 0;
}

T  det(void)
{u32                  t, i1, k;
 permutazioni<u32>  pe(mtr[1]);
 T         rtn,           p, s;

 rtn=ro(rtn); // riempie rtn con valore errato
 if(mtr[0]!=2u||pe.e())
     {
l1:    R  rtn;
     }
 G(     *Led(mtr), l1);
 G(mtr[1]!=mtr[2], l1);
 i1=mtr[1]; s=0;
la:    F(k=0, p=1; k<i1; ++k)
           p=p*(*this).e(k, pe[k]);
       G(ov(p),l1);
       if(pe.cnt%2!=0) {s=s-p; // cout<<"-"<<(i32)p;
                       }
       else            {s=s+p; // cout<<"+"<<(i32)p;
                       }
       G(ov(s),l1);
       G( (t=pe.nextP(1))==-1, l1);
       G( t==1, la);
 R  s;
}

i32  e(void){R  MtrBadAlloc;}

i32  ini(T*  a)
{ T  *p1, *p2;
  u8    *pmax;
  u32       i;

  if(a==0)  R  -1;
  *Led(mtr)=0;
  p1=(T*) Data(mtr); p2=a;
  i=*SZ(mtr); pmax=(u8*) p1; pmax+=i;
  F(; p1<pmax ;++p1, ++p2)
        *p1=*p2;
  R  0;
}

/* ritorna il sup dell'indice consentito */
/* indici = 0, 1, 2 ,3 ,4 */
/* 2  i0  i1 => 2<=0  2<=1  2<=2*  */
i32  operator[](i32  i)
{if(mtr==0||mtr[0]<=i||*Led(mtr)!=0)  R  0;
 R  mtr[i+1];
}

friend Matrix<T>  operator+(Matrix<T>&  a, Matrix<T>&  b)
{Matrix<T>  r; r.add(a,b); R  r;}

friend Matrix<T>  operator-(Matrix<T>&  a, Matrix<T>&  b)
{Matrix<T>  r; r.sub(a,b); R  r;}

friend Matrix<T>  operator*(Matrix<T>&  a, Matrix<T>&  b)
{Matrix<T>  r; r.mul(a,b); R  r;}

friend i32 operator==(Matrix<T>&  a, Matrix<T>&  b)
{T  *p1, *p2;
 u8    *pmax;
 u32       i;

 if( *Led(a.mtr)||*Led(b.mtr) )
                            R  -1;
 F(i=0; i<=a.mtr[0]; ++i)
    if(a.mtr[i]!=b.mtr[i])  R  0;

 p1=(T*)Data(a.mtr); p2=(T*) Data(b.mtr); i=*SZ(mtr);
 if(i!=sizeof(T))  R  -1;
 pmax=(u8*) p1; pmax+=i;
 F(; p1<pmax ;++p1,++p2)
     if( *p1!=*p2 )    R  0;
 R  1;
}

friend i32 operator!=(Matrix<T>&  a, Matrix<T>&  b){R !(a==b);}

friend ostream&  operator<<(ostream&  ostr, Matrix<T>&  a)
{T       *p1;
 u8    *pmax;
 u32    i, j;

 ostr<<"\n";
 if( *Led(a.mtr)  ) {cout<<"[Me]\n";    R  ostr;}
 if( a.mtr[0]!=2  ) {cout<<"[M_Big]\n"; R  ostr;}
 p1=(T*)Data(a.mtr); i=*SZ(a.mtr);
 pmax=(u8*) p1; pmax+=i; i=*SZe(a.mtr);
 if(i>8||i==0) {cout<<"Out Error\n"; R  ostr;}
 F(j=0 ; p1<pmax ;++p1, ++j)
    {     if(i==1) cout.width(3);
     else if(i==2) cout.width(5);
     else if(i==4) cout.width(10);
     else if(i==8){cout.width(10); cout.precision(2);}
     cout<< *p1;
     if((j+1)%a.mtr[2]==0) cout<<"\n";
     else                  cout<< " ";
    }
 R  ostr;
}

friend istream&  operator>>(istream&  istr, Matrix<T>&  a)
{T       *p1;
 u8    *pmax;
 u32       i;

 *Led(a.mtr)=0;
 p1=(T*)Data(a.mtr); i=*SZ(a.mtr); pmax=(u8*) p1; pmax+=i;
 F( ; p1<pmax ;++p1)
             cin>>*p1;
 R  istr;
}

// for now only nxm matrix of u8,i8 u16,i16 u32,i32  d64[double]
void  print(void)
{d64               dv;
 u8         *p, *pmax;
 u32    i,j,maxn, max, size, v;
 u32       Index[256];
 T      a;

    a=-1;
    G(mtr, l1);
l0:     R;  // error
la: P("[Me]"); G(1,l0);
l1: G(mtr[0]!=2, l0);
    size= *SZe(mtr);
    G(size>8||size==0, l0);
    G( *Led(mtr) , la);
    i=0; p=Data(mtr); pmax=p+(size*mtr[1]*mtr[2]);
m0: G(size==1,l2);G(size==2,l3);G(size==4,l4);G(size==8,l11);G(1,l0);
l11:  dv=*(d64*)p;  P("%10.2f",dv); G(1,l5);
l2:   v =*(u8*) p; G(a<0,l21);  P("%3u ", (u32)  v); G(1,l5);
l21:                            P("%3d ", (i32)  v); G(1,l5);
l3:   v =*(u16*)p; G(a<0,l31);  P("%5u ", (u32)  v); G(1,l5);
l31:                            P("%5d ", (i32)  v); G(1,l5);
l4:   v =*(u32*)p; G(a<0,l41);  P("%10u ",(u32)  v); G(1,l5);
l41:                            P("%10d ",(i32)  v);
l5:   G( (i+1)%mtr[2]!=0, l6); P("\n");
l6:   p+=size; ++i; G(p<pmax, m0);
    R;
}

void show(void)
{if(mtr)
   {cout<<"n Index="<<mtr[0]<<"; i0="<<mtr[1]<<" ;i1="<<mtr[2];
    cout<<"; w0="<<mtr[3]<<"; W1="<<mtr[4]<<"\n";
   }
}

T  A(u32  i,  u32  j)
{T              rtn;
 u32 i1, i2, j1, j2;

 rtn=ro(rtn); // riempie rtn con valore errato
 if(*Led(mtr))                       R  rtn;
 if(mtr[0]!=2||   mtr[1]!=mtr[2]  )  R  rtn;
 if(i>=mtr[1]||j>=mtr[2]||mtr[1]<2)  R  rtn;
 if(mtr[1]==2)  // 2x2  1 elemento
   {if(i==0 && j==0) R  (*this).e(1,1);
    if(i==0 && j==1) R  (*this).e(1,0);
    if(i==1 && j==0) R  (*this).e(0,1);
    if(i==1 && j==1) R  (*this).e(0,0);
   }
 else {Matrix<T>   a(mtr[1]-1, mtr[1]-1);

       if(a.e())                     R  rtn;
       j1=0; j2=0;
       F(i1=0; i1<mtr[1]; ++i1)
         F(i2=0; i2<mtr[1]; ++i2)
            {if(i!=i1 && j!=i2)
               {a.e(j1, j2++)=(*this).e(i1, i2);
                if(j2==a.mtr[2]){j2=0; ++j1;}
               }
            }
       rtn=a.det();
      }
 R  rtn;
}

/* Return -1 if a has not inverse or error
   Retrun  0 if make right calc with (*this)== a^(-1)
*/
i32  inverse(Matrix<T>&  a)
{T   adet, r;
 u32  i,j;
 *Led(mtr)=0;
 if(mtr[0]!=2||a.mtr[0]!=2)
    {
l0:  *Led(mtr)=1;
     R  -1;
    }
 G( mtr[1]!=a.mtr[1]||mtr[2]!=a.mtr[2]||mtr[1]!=mtr[2] , l0);
 adet=2; adet/=2;
 G(adet==0,  l0);  /* il tipo non ammette inversa */
 adet=a.det();
 G(adet==0u, l0);
 F(i=0; i<mtr[1]; ++i)
    F(j=0; j<mtr[1]; ++j)
       {r=((i+j)%2==0? +1: -1 )* a.A(j,i)/adet;
        G(ov(r), l0);
        (*this).e(i,j)=r;
       }
 R   0;
}

u32    *mtr;
static  u32  MtrBadAlloc;
};

template<class T> u32 Matrix<T>::MtrBadAlloc=0;

/*
  reserve mem space to matrix of element msize for dimension
  i0xi1x...xin taken as input
  where i0, i1 etc are max+1 index and n<=255
  the last max+1 index is -1 that end the input
  Return -1 for error
  Return  0 all ok
NB
 **The first function to call on pm [construct matrix] **
 **the last  function to call on pm [destruct  matrix] **
*/
i32 Mcon(u32**  pm, u32  msize, ...)
{va_list           ap;
 u32       v, i, s, j;
 u32         arr[256];

    G(pm, l1);
l0:     Matrix<u32>::MtrBadAlloc=1; R -1;    // for error
n0:     va_end(ap); *pm=0; G(1,l0);
l1: G(msize, l3);Fr(*pm); *pm=0;/* free the Matrix */
l2:     R  0;                   // for all ok
y0:     va_end(ap); G(1,l2);
l3: va_start(ap, msize); G(msize>0xFFF, n0); G(msize==0, n0); i=0;
l4:    v=va_arg(ap, u32); //v the first index;if i==0 means no element
       G(v>0xFFFF && v!= -1, n0); G(v!=-1, la); G(i==0, n0);
           s=1; j=1;
l5:        s*=arr[j-1]; G(s>0xFFFFF, n0); ++j; G( j<=i, l5);
           s*=msize;    G(s>0xFFFFF, n0);
           *pm=(u32*)M((2*i+4)*sizeof(u32)+s); G(*pm==0, n0);
           (*pm)[0]=i; *SZe(*pm)=msize; *SZ(*pm)=s; *Led(*pm)=0;
           j=1; s=1;
l6:        (*pm)[j]=arr[j-1]; (*pm)[2*i+1-j]=s;
                        s*=arr[i-j]; ++j; G(j<=i, l6);
           G(1,y0);
la:    G(i>255, n0); arr[i++]=v; G(1,l4);
}

// return one pointer to element
// or 0 if find some error
/*
2x2             y*n  +x  (y,  x)e{0..m -1}x{0..n -1}
2   elm(i0,i1)=i0*M1+i1  (i0,i1)e{0..M0-1}x{0..M1-1}  Max=(M0-1)*M1+M1-1=M0*M1-1
se M0=7  M1=1    7x1   (1,1)
elm(i0,i1)=i0+i1  (i0,i1)e{0..6}x{0..0}  Max=(7-1)*1+1-1=6
se M0=1  M1=7    1x7   (7,1)
elm(i0,i1)=i0*7+i1   (i0,i1)e{0..0}x{0..6}  Max=(0)*7+7-1=6

3   elm(i0,i1,i2)=i0*M1*M2+i1*M1+i2  (i0,i1,i2)e{0..M0-1}x{0..M1-1}x{0..M2-1}
    Max=(M0-1)*M1*M2+(M1-1)*M2+(M2-1)=M0*M1*M2-M1*M2+M1*M2-M2+M2-1=M0*M1*M2-1
*/
u8*  Aelm(u32*  pm, ...)
{va_list              ap;
 u8                   *r;
 u32 maxn, size, v, s, i;

    G(pm,l1);
l0:   R  0;
n0:   va_end(ap); G(1,l0);
l1: maxn=pm[0]; size= *SZe(pm); G(size>0xFFFF, l0);
                              //                0 1
    G(maxn>=256||maxn==0,l0); //for 2x2 y*n+x  (y,x)e[0..m-1]x[0..n-1]
    va_start(ap, pm);         // gets all index       i0 i1  maxn=2
    i=1; s=0;                 /*  I[0]+1..2*I[0]  */
l3: v=va_arg(ap,u32); G(v>=pm[i],n0); s+=v*pm[maxn+i]; ++i; G(i<=maxn, l3);
    v=s*size; r=Data(pm); r+=v;
    va_end(ap);
    R r;
}


u32  f(void)
{Matrix<ou32>  m1(2,2),m2(2,3),m6(2,2),m7(2,2),m8(1,2),m9(1,2);
 Matrix<d64>  m3(2,2), md1(2,2), md2(2,2), mdd(2,2), md3(3,3), md4(3,3);
 Matrix<ou32> m10(2,2);
 Matrix<u8>   m4(1,7), m5(7,1);
 Matrix<oi32> m12(4,4), m13(3,3);
 Matrix<oi32> m20(4,2), m21(2,4), m23(2,4), m24(2,4);

 u32  d, i, j;
 ou32 dd;
 i32  vm[] ={ 2,9,9,4,  2,-3,12,8,  4,8,3,-5,  1,2,6,4 }, r;
 i32  vm1[]={ 1,2,3,  4,5,6,  7,8,9};

 /* if some Matrix<T> object is not allocated return 0 */
 if(m1.e()) R  0;
 F(i=0; i<m2[0]; ++i)
   F(j=0; j<m2[1]; ++j)
        m2.e(i,j)=10*i+j;

 F(i=0; i<m4[0]; ++i)
   F(j=0; j<m4[1]; ++j)
        m4.e(i,j)=10*i+j;

 F(i=0; i<m5[0]; ++i)
   F(j=0; j<m5[1]; ++j)
         m5.e(i,j)=10*i+j;

 m1.e(0,0)=1; m1.e(0,1)=2;
 m1.e(1,0)=3; m1.e(1,1)=4;

 dd = m1.det();
 m6.inverse(m1);


 m12.ini( (oi32*) vm ); /* can be wrong etc */
 m13.ini( (oi32*) vm1);

 m6.e(0,0)=5; m6.e(0,1)=6;
 m6.e(1,0)=7; m6.e(1,1)=8;

 m7.mul(m1, m6);

 F(i=0; i<m3[0]; ++i)
    F(j=0; j<m3[1]; ++j)
        m3.e(i,j)=10.23*i+j;

 m8.e(0,0)=1; m8.e(0,1)=2;
 m9.mul(m8, m1);

 P("M1:\n"); m1.print(); P("\n\n");
 P("m1.det()=%d\n", d);

 P("M2:\n"); m2.print(); P("\n\n");
 P("M3:\n"); m3.print(); P("\n\n");
 P("M4:\n"); m4.print(); P("\n\n");

 m4.show();
 P("M5:\n"); m5.print(); P("\n\n");
 m5.show();

 P("M6:\n"); m6.print(); P("\n\n");
 P("M7=m1*m6:\n"); m7.print(); P("\n\n");
 P("M8\n"); m8.print(); P("\n\n");
 P("M9=m8*m1\n"); m9.print(); P("\n\n");
 P("M12\n");m12.print(); P("\n\n");
 r=m12.det();
 P("DET(M12)=%d\n", r);
 F(i=0; i<m12.mtr[1]; ++i)
    F(j=0; j<m12.mtr[2]; ++j)
             cout<< "A("<<i<<", "<< j<< ")="<< m12.A(i,j) << "  ";
 m7=m1;
 P("M7: m7=m1\n"); m7.print(); P("\n\n");
 m1*=(ou32)10u;
 P("M1=M1*10:\n"); m1.print(); P("\n\n");
 m1+=m1;
 P("M1+=M1:\n"); m1.print(); P("\n\n");
 P("M13:\n"); m13.print(); P("\n\n");
 r=m13.det();
 P("DET(M13)=%d\n", r);
 m1.transpose();
 P("M1 traspose:\n"); m1.print(); P("\n\n");

 m20.ini( (oi32*) vm1); /* can be wrong etc */
 m21.ini( (oi32*) vm1);
 P("M20:\n"); m20.print(); P("\n"); m20.show(); P("\n\n");
 P("M21:\n"); m21.print(); P("\n"); m21.show(); P("\n\n");

 m23.transpose(m20);
 P("M23:\n"); m23.print(); P("\n"); m23.show(); P("\n\n");

 m24.transpose(m21);
 P("M24:\n"); m24.print(); P("\n"); m24.show(); P("\n\n");

 m20.transpose();
 P("M20:\n"); m20.print(); P("\n"); m20.show(); P("\n\n");
 m21.transpose();
 P("M21:\n"); m21.print(); P("\n"); m21.show(); P("\n\n");
 cout<<"M1 M2="<< m1 << m21;
 //cin>>m1; cout<<m1;
 m6.inverse(m1);
 cout<<"M1-1==\n"<<m6<<"\n\n";
 F(i=0; i<md1.mtr[1]; ++i)
   F(j=0;  j<md1.mtr[2]; ++j)
             md1.e(i, j)=10.0*i+j;
 cout<<"Md1:"<< md1;
 md2.inverse(md1);
 cout<<"Md1-1"<<md2;
 md1.mul(md1, md2);
 cout<<"I="<< md1;
 d=70; 
 F(i=0; i<md3.mtr[1]; ++i)
   F(j=0;  j<md3.mtr[2]; ++j)
             md3.e(i, j)=d++;
 ++md3.e(1,1);
 cout<<"Md3:"<< md3;
 cout<<"|Md3|="<< md3.det()<<" ";
 md4.inverse(md3);
 cout<<"Md3-1"<<md4;
 md3.mul(md3, md4);
 cout<<"I="<< md3; 

 R  0;
}

i32  g(void)
{u32             i, r, j;
 permutazioni<u32>  m(3);
 permutazioni<u8>   v(4);
 char      *ptr="mare";

 if(m.e())  R  0;
 F(i=0; i<m.n; ++i)
          m[i]=i;
 F(;;){m.print();
       G( (r=m.nextP(1))==-1 || r==0,  m1);
      }
 m1:
 F(i=0; i<v.n; ++i)
         v[i]=ptr[i];

 F(;;){v.print();
       G( (r=v.nextP(1))==-1 || r==0,  la);
      }
la:
 P("\n");
 R 0;
}

int main(void)
{if( sizeof(u32)!=4 || sizeof(u16)!=2 )
       {P("Basic type error\n"); R  0;}
 f();
 R 0;
}

[toc] | [prev] | [next] | [standalone]


#62394

Fromasetofsymbols@gmail.com
Date2015-05-21 01:34 -0700
Message-ID<ba65d21e-8ded-426b-aec0-bb29efdd8224@googlegroups.com>
In reply to#62393
I wrote:"
adet=2; adet/=2; 
 G(adet==0,  l0);  /* il tipo non ammette inversa */"

This would be:
adet=1; adet/=2; 
 G(adet==0,  l0);  
It would be some float Point type etc

[toc] | [prev] | [next] | [standalone]


#62666

Fromasetofsymbols@gmail.com
Date2015-05-26 19:17 -0700
Message-ID<bdacf12d-e90e-4166-8438-6f17e53cbf3d@googlegroups.com>
In reply to#62393
// functions for detect u32 or i32 overflow 
u32  omul(u32  a,  u32  b) 
{asm{mov eax, a 
     cmp eax, -1
     je  lab
     mov edx, b 
     cmp edx, -1
     je  m1
     mul edx 
     cmp edx, 0 
     je  lab 
m1:
     mov eax, -1 
lab: 
 } 
 R  _EAX; 
} 

u32  oadd(u32  a,  u32  b) 
{asm{mov eax, a 
     mov edx, b 
     add eax, edx 
     jnc  lab 
     mov eax, -1 
lab: 
 } 
 R  _EAX; 
} 

u32  osub(u32  a,  u32  b) 
{asm{mov eax, a 
     cmp eax, -1
     je  lab
     mov edx, b 
     cmp edx, -1
     je  m1
     sub eax, edx 
     jnc lab 
m1:
     mov eax, -1 
lab: 
    } 
 R  _EAX; 
} 

i32  omul(i32  a,  i32  b) 
{asm{mov  eax, a 
     cmp  eax, 0x80000000
     je   lab
     mov  edx, b 
     cmp  edx, 0x80000000
     je    m1
     imul edx 
     jno  lab 
m1:
     mov  eax, 0x80000000 
lab: 
    } 
 R  _EAX; 
} 


i32  oadd(i32  a,  i32  b) 
{asm{mov eax, a 
     cmp eax, 0x80000000
     je  lab
     mov edx, b 
     cmp edx, 0x80000000
     je  m1
     add eax, edx 
     jno lab 
m1:
     mov eax, 0x80000000 
lab: 
    } 
 R  _EAX; 
} 

i32  osub(i32  a,  i32  b) 
{asm{mov eax, a 
     cmp eax, 0x80000000
     je  lab
     mov edx, b 
     cmp edx, 0x80000000
     je  m1
     sub eax, edx 
     jno lab 
m1:
     mov eax, 0x80000000 
lab: 
    } 
 R  _EAX; 
}

[toc] | [prev] | [next] | [standalone]


#62888

Fromasetofsymbols@gmail.com
Date2015-05-31 13:56 -0700
Message-ID<a6f7a2cd-835d-4092-a28d-7219008daeae@googlegroups.com>
In reply to#62393
I wrote:"friend ou32 operator*(ou32  a, ou32  b){ou32  r; r.v=omul(a.v, b.v); R  r;}"
This should be wrong because here
it return the address in the stack
of r. But as all it can be easily
corrected using one ou32
circular array

[toc] | [prev] | [next] | [standalone]


#62892

FromKeith Thompson <kst-u@mib.org>
Date2015-05-31 14:23 -0700
Message-ID<871thwigpy.fsf@kst-u.example.com>
In reply to#62888
asetofsymbols@gmail.com writes:
> I wrote:"friend ou32 operator*(ou32  a, ou32  b){ou32  r; r.v=omul(a.v, b.v); R  r;}"

That's C++, not C.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#62894

FromIan Collins <ian-news@hotmail.com>
Date2015-06-01 09:37 +1200
Message-ID<ct1d86FlfgfU1@mid.individual.net>
In reply to#62892
Keith Thompson wrote:
> asetofsymbols@gmail.com writes:
>> I wrote:"friend ou32 operator*(ou32  a, ou32  b){ou32  r; r.v=omul(a.v, b.v); R  r;}"
>
> That's C++, not C.

I'd call it gobbledegook!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#62901

Fromasetofsymbols@gmail.com
Date2015-06-01 01:23 -0700
Message-ID<6f80e574-39cf-4fde-85cc-874b9ebc4f6c@googlegroups.com>
In reply to#62393
I wrote:"
T  det(void) 
{u32                  t, i1, k; 
 permutazioni<u32>  pe(mtr[1]); 
 T         rtn,           p, s; 

 rtn=ro(rtn); // riempie rtn con valore errato 
 if(mtr[0]!=2u||pe.e()) 
     { 
l1:    R  rtn; 
     } 
 G(     *Led(mtr), l1); 
 G(mtr[1]!=mtr[2], l1); 
 i1=mtr[1]; s=0; 
la:    F(k=0, p=1; k<i1; ++k) 
           p=p*(*this).e(k, pe[k]); 
       G(ov(p),l1); 
       if(pe.cnt%2!=0) {s=s-p; // cout<<"-"<<(i32)p; 
                       } 
       else            {s=s+p; // cout<<"+"<<(i32)p; 
                       } 
       G(ov(s),l1); 
       G( (t=pe.nextP(1))==-1, l1); 
       G( t==1, la); 
 R  s; 
}"
i32 det(T* result)
Should be the ok as prototype...

How can note G(,) macro it is the
right way for build such functions

[toc] | [prev] | [next] | [standalone]


#62902

FromIan Collins <ian-news@hotmail.com>
Date2015-06-01 20:35 +1200
Message-ID<ct2jrdFrf5eU2@mid.individual.net>
In reply to#62901
asetofsymbols@gmail.com wrote:
> I wrote:"

More gobbledegook?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#62906

Frommark.bluemel@gmail.com
Date2015-06-01 03:50 -0700
Message-ID<dcfb57df-d6e7-4f93-8b4e-18d1119d9b9e@googlegroups.com>
In reply to#62902
On Monday, 1 June 2015 09:36:14 UTC+1, Ian Collins  wrote:
> asetofsymbols@gmail.com wrote:
> > I wrote:"
> 
> More gobbledegook?

His approach to C seems to me to be that of someone who really doesn't like the language and wants to punish it.

[toc] | [prev] | [next] | [standalone]


#62935

Fromluser droog <luser.droog@gmail.com>
Date2015-06-01 18:04 -0700
Message-ID<7beb4e90-e514-45e4-bee6-77211b33abe9@googlegroups.com>
In reply to#62902
On Monday, June 1, 2015 at 3:36:14 AM UTC-5, Ian Collins wrote:
> asetofsymbols@gmail.com wrote:
> > I wrote:"
> 
> More gobbledegook?
> 

If you like gobbledegook, here's my code all golfed-
up and gook. There's even a little whitespace in there.
A very little.

$ cat arrg.c
#include<stdarg.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include"ppnarg.h" //https://github.com/luser-dr00g/inca/blob/master/ppnarg.h
typedef char C; typedef int I;
typedef struct a{I r,*d,*w,*p;}*A;
#define R return
#define DO(n,x){I i=0,N=(n);for(;i<N;++i){x;}}/*loop i=[0..n)*/
I tr(I r,I*d){ I z=1; DO(r,z*=d[i]) R z; } /* productdims */
dw(I r,I*d,I*w){ I x=1; DO(r,w[r-1-i]=x; x*=d[r-1-i]) } /* calculate weights */
A ah(I r,I*d,I sz){ A z=malloc((sizeof*z)+(sizeof(I)*(r+r+sz))); /* array header + sz extra */
    z->r=r; z->d=(I*)(((C*)z)+sizeof*z); z->w=z->d+r; z->p=NULL;
    memcpy(z->d,d,r*sizeof(I)); dw(r,d,z->w); R z; }
A ara(I r,I*d){ I sz=tr(r,d); A z=ah(r,d,sz); z->p=z->w+r; R z; } /* arraya */
dv(I r,I*d,va_list v){ DO(r,d[i]=va_arg(v,I)) } /* loaddimsv */
A ar(I r,...){ va_list v; I d[r]; va_start(v,r); dv(r,d,v); va_end(v); R ara(r,d); } /* array rm */
#define ar(...)ar(PP_NARG(__VA_ARGS__),__VA_ARGS__)
A caa(I*p,I r,I*d){ A z=ah(r,d,0); z->p=p; R z; } /* casta rm */
A ca(I*p,I r,...){ va_list v; I d[r]; va_start(v,r); dv(r,d,v); va_end(v); R caa((I*)p,r,d); }
#define ca(p,...)ca((I*)p,PP_NARG(__VA_ARGS__),__VA_ARGS__)
A cl(A a){ A z=ah(a->r,a->d,0);
    memcpy(z->d,a->d,z->r*sizeof(I));
    memcpy(z->w,a->w,z->r*sizeof(I)); z->p=a->p; R z; } /* clone */
I*ela(A a,I*j){ I x=0; DO(a->r, x+=j[i]*a->w[i]) R a->p+x; } /* elema */
I*elv(A a,va_list v){ I j[a->r]; dv(a->r,j,v); R ela(a,j); } /* elemv */
I*el(A a,...){ I*z; va_list v; va_start(v,a); z=elv(a,v); va_end(v); R z; } /* elem */
int *vx(I x,I*d,I r,I*v){ DO(r, v[r-1-i]=x%d[r-1-i]; x/=d[r-1-i]) R v; } /* vector_index */
int rx(I*v,I*d,I r){ I z=*v; DO(r-1, z*=d[i+1]; z+=v[i+1]) R z; } /* ravel_index */
A cp(A a){ I sz=tr(a->r,a->d); A z=ah(a->r,a->d,sz); z->p=z->w+z->r;
    I j[z->r]; DO(sz, vx(i,z->d,z->r,j); z->p[i]=*ela(a,j)) R z; } /* copy rm */
#define CASE ;break;case

#define OP(x,y)((((x))*256)+((y)))
#define OPS(_)  _("+", '+', 0, +,  0) \
                _("*", '*', 0, *,  1) \
                _("=", '=', 0, ==, 1) \
                _("==",'=','=',==, 1) \
                /* f   f0  f1  F  id */
#define BINOP(f,f0,f1,F,id) CASE OP(f0,f1): *el(z,i) = *el(x,i) F *el(y,i);
A bin(A x,C*f,A y){ A z=cp(x); DO(x->d[0], switch(OP(*f,f[1])){ OPS(BINOP) }) R z; }
#define bin(X,F,Y) bin(X,#F,Y)
#define REDID(f,f0,f1,F,id) CASE OP(f0,f1): z = id;
#define REDOP(f,f0,f1,F,id) CASE OP(f0,f1): z = *el(y,n-2-i) F z;
int red(C*f,A y){ I z; I n=y->d[0];
    switch(OP(*f,f[1])){ OPS(REDID) }
    if (n){ z=*el(y,n-1);
            if (n-1>0) DO(n-1, switch(OP(*f,f[1])){ OPS(REDOP) }) }
    R z; }
#define red(F,Y) red(#F,Y)

A xt(A a,I x){ I r=a->r+x; I d[r];
    DO(x, d[i]=1) memcpy(d+x,a->d,a->r*sizeof(I)); R caa(a->p,r,d); } /* extend */
A iot(I n){ A z=ar(n); DO(n,*el(z,i)=i) R z; } /* index generator */

A xp(A a,I*j){
    I d[a->r]; I w[a->r];
    DO(a->r, d[i]=a->d[j[i]];
             w[i]=a->w[j[i]])
    A z=caa(a->p,r,d);
    memcpy(z->w,w,a->r*sizeof(I)); R z; } /* transpose */

A sl0(A a,I x){ I r=a->r-1; A z=ah(r,a->d+1,0);
    memcpy(z->w,a->w+1,r*sizeof(I));
    z->p=a->p+x*a->w[0]; R z; }

A sl(A a,I*s,I*f){ I r=0;
    DO(a->r, r+=s[i]!=f[i])
    I d[r]; I w[r]; I j=0;
    DO(r,   while(s[j]==f[j])++j;
            d[i]=1+(s[j]<f[j]? f[j]-s[j] : s[j]-f[j]);
            w[i]=   s[j]<f[j]? a->w[j]   : -a->w[j];
            ++j)
    A z=caa(a->p,r,d);
    memcpy(z->w,w,r*sizeof(I)); DO(a->r, z->p += s[i] * a->w[i]) R z; } /* slices [s[i]..f[i]] */

I contig(A a){ I x=1;
    DO(a->r, if(a->w[a->r-1-i]!=x) R 0;
             x*=a->d[a->r-1-i])
    R 1; }

pr(A a,I wid){ I max; I copy=0;
    if (wid){ max=wid; } else {
        I sz=tr(a->r,a->d);
        if (!contig(a)){
            a=cp(a);
            copy=1;
        }
        max=0;
        DO(sz,
            sz=snprintf(NULL,0,"%d",a->p[i]);
            if (sz>max) max=sz)
    }
    switch(a->r){
    case 0: printf("%*d\n", max, *a->p); break;
    case 1: {
                I sep=0;
                DO(a->d[0],
                    if (sep) printf(" ");
                    printf("%*d", max, *el(a,i));
                    sep=1) }
            if (wid==0) printf("\n"); break;
    default:DO(a->d[0], A t=sl0(a,i);
                        pr(t,max);
                        printf("\n");
                        free(t)) break;
    }
    if(copy)free(a); }

dmp(A a){
    printf("%d\n",a->r);
    DO(a->r,printf("%d ",a->d[i])) printf("\n");
    DO(a->r,printf("%d ",a->w[i])) printf("\n");
    printf("%p %p %p %p\n",
            (void*)a, (void*)a->d, (void*)a->w, (void*)a->p); }

int main(){
    A x=ar(3);
    *el(x,0)=5;
    *el(x,1)=6;
    *el(x,2)=7;
    dmp(x);
    pr(x,0);

    A a=iot(24);
    dmp(a);
    pr(a,0);
    A b=ca(a->p,2,3,4);
    dmp(b);
    pr(b,0);
    A c=sl(b,(I[]){0,1,1},(I[]){0,2,3});
    pr(c,0);
    A d=xp(c,(I[]){1,0});
    pr(d,0);
    return 0;
}

[toc] | [prev] | [next] | [standalone]


#62936

Fromluser droog <luser.droog@gmail.com>
Date2015-06-01 18:16 -0700
Message-ID<c39ca82c-6bee-4788-9fd7-d5786b1fa840@googlegroups.com>
In reply to#62935
On Monday, June 1, 2015 at 8:04:25 PM UTC-5, luser droog wrote:
> On Monday, June 1, 2015 at 3:36:14 AM UTC-5, Ian Collins wrote:
> > asetofsymbols@gmail.com wrote:
> > > I wrote:"
> > 
> > More gobbledegook?
> > 
> 
> If you like gobbledegook, here's my code all golfed-
> up and gook. 

And buggy.
<snip>
> A xp(A a,I*j){
>     I d[a->r]; I w[a->r];
>     DO(a->r, d[i]=a->d[j[i]];
>              w[i]=a->w[j[i]])
>     A z=caa(a->p,r,d);

s.b.  A z=caa(a->p,a->r,d);

>     memcpy(z->w,w,a->r*sizeof(I)); R z; } /* transpose */

[toc] | [prev] | [next] | [standalone]


#62938

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2015-06-01 19:57 -0700
Message-ID<mkj634$8p6$1@speranza.aioe.org>
In reply to#62935
> > "luser droog"  wrote in message 
> > news:7beb4e90-e514-45e4-bee6-77211b33abe9@googlegroups.com...

> On Monday, June 1, 2015 at 3:36:14 AM UTC-5, Ian Collins wrote:
> More gobbledegook?

> > If you like gobbledegook, here's my code all golfed-
> > up and gook. There's even a little whitespace in there.
> > A very little.

[...]

Holy Shi%!

;^o 

[toc] | [prev] | [next] | [standalone]


#62939

FromRosario19 <Ros@invalid.invalid>
Date2015-06-02 08:30 +0200
Message-ID<jhiqmate7sgdnru0uanachmtqf0sttf092@4ax.com>
In reply to#62935
On Mon, 1 Jun 2015 18:04:07 -0700 (PDT), luser droog
<luser.droog@gmail.com> wrote:

>On Monday, June 1, 2015 at 3:36:14 AM UTC-5, Ian Collins wrote:
>> asetofsymbols@gmail.com wrote:
>> > I wrote:"
>> 
>> More gobbledegook?
>> 
>
>If you like gobbledegook, here's my code all golfed-
>up and gook. There's even a little whitespace in there.
>A very little.
>
>$ cat arrg.c
>#include<stdarg.h>
>#include<stdlib.h>
>#include<stdio.h>
>#include<string.h>
>#include"ppnarg.h" //https://github.com/luser-dr00g/inca/blob/master/ppnarg.h
>typedef char C; typedef int I;
>typedef struct a{I r,*d,*w,*p;}*A;
>#define R return
>#define DO(n,x){I i=0,N=(n);for(;i<N;++i){x;}}/*loop i=[0..n)*/
>I tr(I r,I*d){ I z=1; DO(r,z*=d[i]) R z; } /* productdims */
>dw(I r,I*d,I*w){ I x=1; DO(r,w[r-1-i]=x; x*=d[r-1-i]) } /* calculate weights */
>A ah(I r,I*d,I sz){ A z=malloc((sizeof*z)+(sizeof(I)*(r+r+sz))); /* array header + sz extra */
>    z->r=r; z->d=(I*)(((C*)z)+sizeof*z); z->w=z->d+r; z->p=NULL;
>    memcpy(z->d,d,r*sizeof(I)); dw(r,d,z->w); R z; }
>A ara(I r,I*d){ I sz=tr(r,d); A z=ah(r,d,sz); z->p=z->w+r; R z; } /* arraya */
>dv(I r,I*d,va_list v){ DO(r,d[i]=va_arg(v,I)) } /* loaddimsv */
>A ar(I r,...){ va_list v; I d[r]; va_start(v,r); dv(r,d,v); va_end(v); R ara(r,d); } /* array rm */
>#define ar(...)ar(PP_NARG(__VA_ARGS__),__VA_ARGS__)
>A caa(I*p,I r,I*d){ A z=ah(r,d,0); z->p=p; R z; } /* casta rm */
>A ca(I*p,I r,...){ va_list v; I d[r]; va_start(v,r); dv(r,d,v); va_end(v); R caa((I*)p,r,d); }
>#define ca(p,...)ca((I*)p,PP_NARG(__VA_ARGS__),__VA_ARGS__)
>A cl(A a){ A z=ah(a->r,a->d,0);
>    memcpy(z->d,a->d,z->r*sizeof(I));
>    memcpy(z->w,a->w,z->r*sizeof(I)); z->p=a->p; R z; } /* clone */
>I*ela(A a,I*j){ I x=0; DO(a->r, x+=j[i]*a->w[i]) R a->p+x; } /* elema */
>I*elv(A a,va_list v){ I j[a->r]; dv(a->r,j,v); R ela(a,j); } /* elemv */
>I*el(A a,...){ I*z; va_list v; va_start(v,a); z=elv(a,v); va_end(v); R z; } /* elem */
>int *vx(I x,I*d,I r,I*v){ DO(r, v[r-1-i]=x%d[r-1-i]; x/=d[r-1-i]) R v; } /* vector_index */
>int rx(I*v,I*d,I r){ I z=*v; DO(r-1, z*=d[i+1]; z+=v[i+1]) R z; } /* ravel_index */
>A cp(A a){ I sz=tr(a->r,a->d); A z=ah(a->r,a->d,sz); z->p=z->w+z->r;
>    I j[z->r]; DO(sz, vx(i,z->d,z->r,j); z->p[i]=*ela(a,j)) R z; } /* copy rm */
>#define CASE ;break;case
>
>#define OP(x,y)((((x))*256)+((y)))
>#define OPS(_)  _("+", '+', 0, +,  0) \
>                _("*", '*', 0, *,  1) \
>                _("=", '=', 0, ==, 1) \
>                _("==",'=','=',==, 1) \
>                /* f   f0  f1  F  id */
>#define BINOP(f,f0,f1,F,id) CASE OP(f0,f1): *el(z,i) = *el(x,i) F *el(y,i);
>A bin(A x,C*f,A y){ A z=cp(x); DO(x->d[0], switch(OP(*f,f[1])){ OPS(BINOP) }) R z; }
>#define bin(X,F,Y) bin(X,#F,Y)
>#define REDID(f,f0,f1,F,id) CASE OP(f0,f1): z = id;
>#define REDOP(f,f0,f1,F,id) CASE OP(f0,f1): z = *el(y,n-2-i) F z;
>int red(C*f,A y){ I z; I n=y->d[0];
>    switch(OP(*f,f[1])){ OPS(REDID) }
>    if (n){ z=*el(y,n-1);
>            if (n-1>0) DO(n-1, switch(OP(*f,f[1])){ OPS(REDOP) }) }
>    R z; }
>#define red(F,Y) red(#F,Y)
>
>A xt(A a,I x){ I r=a->r+x; I d[r];
>    DO(x, d[i]=1) memcpy(d+x,a->d,a->r*sizeof(I)); R caa(a->p,r,d); } /* extend */
>A iot(I n){ A z=ar(n); DO(n,*el(z,i)=i) R z; } /* index generator */
>
>A xp(A a,I*j){
>    I d[a->r]; I w[a->r];
>    DO(a->r, d[i]=a->d[j[i]];
>             w[i]=a->w[j[i]])
>    A z=caa(a->p,r,d);
>    memcpy(z->w,w,a->r*sizeof(I)); R z; } /* transpose */
>
>A sl0(A a,I x){ I r=a->r-1; A z=ah(r,a->d+1,0);
>    memcpy(z->w,a->w+1,r*sizeof(I));
>    z->p=a->p+x*a->w[0]; R z; }
>
>A sl(A a,I*s,I*f){ I r=0;
>    DO(a->r, r+=s[i]!=f[i])
>    I d[r]; I w[r]; I j=0;
>    DO(r,   while(s[j]==f[j])++j;
>            d[i]=1+(s[j]<f[j]? f[j]-s[j] : s[j]-f[j]);
>            w[i]=   s[j]<f[j]? a->w[j]   : -a->w[j];
>            ++j)

What DO the macro above?
int  i;
for(i=0; i<r; ++i)
      {
       while(s[j]==f[j])++j;
       d[i]=1+(s[j]<f[j]? f[j]-s[j] : s[j]-f[j]);
       w[i]=   s[j]<f[j]? a->w[j]   : -a->w[j];
            ++j
^^^^^^^^^^^^^^^^^^^^^
       here at last there is need ';'
       no it is ok... in macro DO() the ';' is in the macro
      }

what is sl?

>    A z=caa(a->p,r,d);
>    memcpy(z->w,w,r*sizeof(I)); DO(a->r, z->p += s[i] * a->w[i]) R z; } /* slices [s[i]..f[i]] */
>
>I contig(A a){ I x=1;
>    DO(a->r, if(a->w[a->r-1-i]!=x) R 0;
>             x*=a->d[a->r-1-i])
>    R 1; }
>
>pr(A a,I wid){ I max; I copy=0;
>    if (wid){ max=wid; } else {
>        I sz=tr(a->r,a->d);
>        if (!contig(a)){
>            a=cp(a);
>            copy=1;
>        }
>        max=0;
>        DO(sz,
>            sz=snprintf(NULL,0,"%d",a->p[i]);
>            if (sz>max) max=sz)
>    }
>    switch(a->r){
>    case 0: printf("%*d\n", max, *a->p); break;
>    case 1: {
>                I sep=0;
>                DO(a->d[0],
>                    if (sep) printf(" ");
>                    printf("%*d", max, *el(a,i));
>                    sep=1) }
>            if (wid==0) printf("\n"); break;
>    default:DO(a->d[0], A t=sl0(a,i);
>                        pr(t,max);
>                        printf("\n");
>                        free(t)) break;
>    }
>    if(copy)free(a); }
>
>dmp(A a){
>    printf("%d\n",a->r);
>    DO(a->r,printf("%d ",a->d[i])) printf("\n");
>    DO(a->r,printf("%d ",a->w[i])) printf("\n");
>    printf("%p %p %p %p\n",
>            (void*)a, (void*)a->d, (void*)a->w, (void*)a->p); }
>
>int main(){
>    A x=ar(3);
>    *el(x,0)=5;
>    *el(x,1)=6;
>    *el(x,2)=7;
>    dmp(x);
>    pr(x,0);
>
>    A a=iot(24);
>    dmp(a);
>    pr(a,0);
>    A b=ca(a->p,2,3,4);
>    dmp(b);
>    pr(b,0);
>    A c=sl(b,(I[]){0,1,1},(I[]){0,2,3});
>    pr(c,0);
>    A d=xp(c,(I[]){1,0});
>    pr(d,0);
>    return 0;
>}
>

A new language?
I agree if operations ca, xp, sl, dmp, pr have a full names
 

[toc] | [prev] | [next] | [standalone]


#62941

Fromluser droog <luser.droog@gmail.com>
Date2015-06-02 00:22 -0700
Message-ID<26bddb6b-08ee-46ca-bdd3-fa8d445a8737@googlegroups.com>
In reply to#62939
On Tuesday, June 2, 2015 at 1:30:21 AM UTC-5, Rosario19 wrote:
> On Mon, 1 Jun 2015 18:04:07 -0700 (PDT), luser droog
> <luser.droog@gmail.com> wrote:
> 
> >On Monday, June 1, 2015 at 3:36:14 AM UTC-5, Ian Collins wrote:
> >> asetofsymbols@gmail.com wrote:
> >> > I wrote:"
> >> 
> >> More gobbledegook?
> >> 
> >
> >If you like gobbledegook, here's my code all golfed-
> >up and gook. There's even a little whitespace in there.
> >A very little.
> >
> >$ cat arrg.c
[snip]
> >#define DO(n,x){I i=0,N=(n);for(;i<N;++i){x;}}/*loop i=[0..n)*/
[snip]
> >
> >A sl(A a,I*s,I*f){ I r=0;
> >    DO(a->r, r+=s[i]!=f[i])
> >    I d[r]; I w[r]; I j=0;
> >    DO(r,   while(s[j]==f[j])++j;
> >            d[i]=1+(s[j]<f[j]? f[j]-s[j] : s[j]-f[j]);
> >            w[i]=   s[j]<f[j]? a->w[j]   : -a->w[j];
> >            ++j)
> 
> What DO the macro above?
> int  i;
> for(i=0; i<r; ++i)
>       {
>        while(s[j]==f[j])++j;
>        d[i]=1+(s[j]<f[j]? f[j]-s[j] : s[j]-f[j]);
>        w[i]=   s[j]<f[j]? a->w[j]   : -a->w[j];
>             ++j
> ^^^^^^^^^^^^^^^^^^^^^
>        here at last there is need ';'
>        no it is ok... in macro DO() the ';' is in the macro
>       }
> 
> what is sl?

It takes slices from the array, returning a subarray.

[snip]
> >int main(){
> >    A x=ar(3);
> >    *el(x,0)=5;
> >    *el(x,1)=6;
> >    *el(x,2)=7;
> >    dmp(x);
> >    pr(x,0);
> >
> >    A a=iot(24);
> >    dmp(a);
> >    pr(a,0);
> >    A b=ca(a->p,2,3,4);
> >    dmp(b);
> >    pr(b,0);
> >    A c=sl(b,(I[]){0,1,1},(I[]){0,2,3});
> >    pr(c,0);
> >    A d=xp(c,(I[]){1,0});
> >    pr(d,0);
> >    return 0;
> >}
> >
> 
> A new language?
> I agree if operations ca, xp, sl, dmp, pr have a full names

It's a prototype for using dope vectors to manipulate array data.
It's related to my programming language 'inca'. 
https://github.com/luser-dr00g/inca
But I'm not sure whether to incorporate this code into inca3.c
or start over and build on top of this.

There is a "readable" version here:
https://github.com/luser-dr00g/inca/blob/master/arrind.c
And an explanation on SO:
http://stackoverflow.com/questions/30409991/use-a-dope-vector-to-access-arbitrary-axial-slices-of-a-multidimensional-array

[toc] | [prev] | [next] | [standalone]


#61884

FromIke Naar <ike@iceland.freeshell.org>
Date2015-05-12 06:06 +0000
Message-ID<slrn3vfsml365d.65r.ike@iceland.freeshell.org>
In reply to#61867
On 2015-05-11, luser droog <luser.droog@gmail.com> wrote:
> void transpose2(arr a){
>     int t;
>     //if (a->rank != 2) error();
>     t = a->dims[0]; a->dims[0] = a->dims[1]; a->dims[1] = t;
>     t = a->weight[0]; a->weight[0] = a->weight[1]; a->weight[1] = t;

I'm not sure if the weight array is handled correctly.
Suppose arr a has rank=2, dims={3,4}, weight={4,1}.
Then you want the transposed array to have rank=2, dims={4,3}, weight={3,1},
but not rank=2, dims={4,3}, weight={1,4}.
In other words, the elements of the transposed weight array cannot be obtained
by simply swapping the elements of the original weight array.

> }

[toc] | [prev] | [next] | [standalone]


#61927

FromIke Naar <ike@iceland.freeshell.org>
Date2015-05-12 21:15 +0000
Message-ID<slrn3vfsml4rd8.bno.ike@iceland.freeshell.org>
In reply to#61884
On 2015-05-12, Ike Naar <ike@iceland.freeshell.org> wrote:
> On 2015-05-11, luser droog <luser.droog@gmail.com> wrote:
>> void transpose2(arr a){
>>     int t;
>>     //if (a->rank != 2) error();
>>     t = a->dims[0]; a->dims[0] = a->dims[1]; a->dims[1] = t;
>>     t = a->weight[0]; a->weight[0] = a->weight[1]; a->weight[1] = t;
>
> I'm not sure if the weight array is handled correctly.
> Suppose arr a has rank=2, dims={3,4}, weight={4,1}.
> Then you want the transposed array to have rank=2, dims={4,3}, weight={3,1},
> but not rank=2, dims={4,3}, weight={1,4}.
> In other words, the elements of the transposed weight array cannot be obtained
> by simply swapping the elements of the original weight array.
>
>> }

Please disregard this post.
The code is okay, I mistook a neat trick for a mistake.
Sorry about that.

[toc] | [prev] | [next] | [standalone]


#61968

Fromasetofsymbols@gmail.com
Date2015-05-13 20:49 -0700
Message-ID<06c636bb-c877-425c-9cfc-a246ccf253a4@googlegroups.com>
In reply to#61867
But use of complex macros
 with argument can be not good 
the time one has to debug...

The max complexity in macros 
 I have to debug
it is the macro
#define G(a, b) if(a)goto b
(the only macro with argument
I remember I use)
that not show problems in debug.
I have to say the compiler traslate
that in an easy neat way

[toc] | [prev] | [next] | [standalone]


#61971

Fromluser droog <luser.droog@gmail.com>
Date2015-05-13 23:43 -0700
Message-ID<d84b73a8-902a-4f7e-b890-c1ce34cab1b3@googlegroups.com>
In reply to#61968
On Wednesday, May 13, 2015 at 10:49:35 PM UTC-5, asetof...@gmail.com wrote:
> But use of complex macros
>  with argument can be not good 
> the time one has to debug...
> 
> The max complexity in macros 
>  I have to debug
> it is the macro
> #define G(a, b) if(a)goto b
> (the only macro with argument
> I remember I use)
> that not show problems in debug.
> I have to say the compiler traslate
> that in an easy neat way

At the risk of having some of my own code
shoved in my face, I daresay that G macro
makes things just about impossible to read.
Perhaps with the aid of debugger, but, ...

I have tried to read your code posts to
try to get more ideas, but it's only a
slight exaggeration to say that all I 
could understand was "..." (which I 
promptly borrowed, so thank you).

I think your G macro is precisely the sort
of jumping that Dijkstra was talking about.
Yes, it's tremendously powerful! Yes, it
can simulate any other control structure 
you could possibly want, including the 
basic suite. But ... It makes everything
look the same. It's easier to visually 
distinguish "if" from "while" than 
"G(??)...G(???)...G(??)" from "G(?)...G(?)".

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.c


csiph-web