Ticket #14876: trac_14876_ntl_typedef.patch

File trac_14876_ntl_typedef.patch, 6.5 KB (added by vbraun, 10 years ago)

Initial patch

  • c_lib/include/ntl_wrap.h

    # HG changeset patch
    # User Volker Braun <vbraun.name@gmail.com>
    # Date 1373468950 14400
    #      Wed Jul 10 11:09:10 2013 -0400
    # Node ID f595d0e4210ef833f35330ede8a41012ed58390a
    # Parent  5d8c13e7b81a1e152855073f97a4d48ee97255d1
    NTL::mat<> is now a C++ template class instead of a #define hack
    
    diff --git a/c_lib/include/ntl_wrap.h b/c_lib/include/ntl_wrap.h
    a b  
    249249//////// mat_ZZ //////////
    250250
    251251#ifndef __cplusplus
    252 struct mat_ZZ;
     252typedef struct {} mat_ZZ;
    253253#endif
    254254
    255 EXTERN void mat_ZZ_SetDims(struct mat_ZZ* mZZ, long nrows, long ncols);
    256 EXTERN struct mat_ZZ* mat_ZZ_pow(const struct mat_ZZ* x, long e);
    257 EXTERN long mat_ZZ_nrows(const struct mat_ZZ* x);
    258 EXTERN long mat_ZZ_ncols(const struct mat_ZZ* x);
    259 EXTERN void mat_ZZ_setitem(struct mat_ZZ* x, int i, int j, const struct ZZ* z);
    260 EXTERN struct ZZ* mat_ZZ_getitem(const struct mat_ZZ* x, int i, int j);
    261 EXTERN struct ZZ* mat_ZZ_determinant(const struct mat_ZZ* x, long deterministic);
    262 EXTERN struct mat_ZZ* mat_ZZ_HNF(const struct mat_ZZ* A, const struct ZZ* D);
    263 EXTERN struct ZZX* mat_ZZ_charpoly(const struct mat_ZZ* A);
    264 EXTERN long mat_ZZ_LLL(struct ZZ **det, struct mat_ZZ *x, long a, long b, long verbose);
    265 EXTERN long mat_ZZ_LLL_U(struct ZZ **det, struct mat_ZZ *x, struct mat_ZZ *U, long a, long b, long verbose);
     255EXTERN void mat_ZZ_SetDims(mat_ZZ* mZZ, long nrows, long ncols);
     256EXTERN mat_ZZ* mat_ZZ_pow(const mat_ZZ* x, long e);
     257EXTERN long mat_ZZ_nrows(const mat_ZZ* x);
     258EXTERN long mat_ZZ_ncols(const mat_ZZ* x);
     259EXTERN void mat_ZZ_setitem(mat_ZZ* x, int i, int j, const struct ZZ* z);
     260EXTERN struct ZZ* mat_ZZ_getitem(const mat_ZZ* x, int i, int j);
     261EXTERN struct ZZ* mat_ZZ_determinant(const mat_ZZ* x, long deterministic);
     262EXTERN mat_ZZ* mat_ZZ_HNF(const mat_ZZ* A, const struct ZZ* D);
     263EXTERN struct ZZX* mat_ZZ_charpoly(const mat_ZZ* A);
     264EXTERN long mat_ZZ_LLL(struct ZZ **det, mat_ZZ *x, long a, long b, long verbose);
     265EXTERN long mat_ZZ_LLL_U(struct ZZ **det, mat_ZZ *x, mat_ZZ *U, long a, long b, long verbose);
    266266
    267267/* //////// ZZ_p ////////// */
    268268/* #ifndef __cplusplus */
     
    314314//////// mat_GF2E //////////
    315315
    316316#ifndef __cplusplus
    317 struct mat_GF2E;
     317typedef struct {} mat_GF2E;
    318318#endif
    319319
    320 EXTERN void mat_GF2E_setitem(struct mat_GF2E* x, int i, int j, const struct GF2E* z);
     320EXTERN void mat_GF2E_setitem(mat_GF2E* x, int i, int j, const struct GF2E* z);
    321321
    322322//////// mat_GF2 //////////
    323323
    324324#ifndef __cplusplus
    325 struct mat_GF2;
     325typedef struct {} mat_GF2;
    326326#endif
    327327
    328 EXTERN void mat_GF2_setitem(struct mat_GF2* x, int i, int j, const struct GF2* z);
     328EXTERN void mat_GF2_setitem(mat_GF2* x, int i, int j, const struct GF2* z);
  • c_lib/src/ntl_wrap.cpp

    diff --git a/c_lib/src/ntl_wrap.cpp b/c_lib/src/ntl_wrap.cpp
    a b  
    845845
    846846//////// mat_ZZ //////////
    847847
    848 void mat_ZZ_SetDims(struct mat_ZZ* mZZ, long nrows, long ncols){
     848void mat_ZZ_SetDims(mat_ZZ* mZZ, long nrows, long ncols){
    849849    mZZ->SetDims(nrows, ncols);
    850850}
    851851
    852 struct mat_ZZ* mat_ZZ_pow(const struct mat_ZZ* x, long e)
     852mat_ZZ* mat_ZZ_pow(const mat_ZZ* x, long e)
    853853{
    854854    mat_ZZ *z = new mat_ZZ();
    855855    power(*z, *x, e);
    856856    return z;
    857857}
    858858
    859 long mat_ZZ_nrows(const struct mat_ZZ* x)
     859long mat_ZZ_nrows(const mat_ZZ* x)
    860860{
    861861    return x->NumRows();
    862862}
    863863
    864864
    865 long mat_ZZ_ncols(const struct mat_ZZ* x)
     865long mat_ZZ_ncols(const mat_ZZ* x)
    866866{
    867867    return x->NumCols();
    868868}
    869869
    870 void mat_ZZ_setitem(struct mat_ZZ* x, int i, int j, const struct ZZ* z)
     870void mat_ZZ_setitem(mat_ZZ* x, int i, int j, const struct ZZ* z)
    871871{
    872872    (*x)[i][j] = *z;
    873873 
    874874}
    875875
    876 struct ZZ* mat_ZZ_getitem(const struct mat_ZZ* x, int i, int j)
     876struct ZZ* mat_ZZ_getitem(const mat_ZZ* x, int i, int j)
    877877{
    878878    return new ZZ((*x)(i,j));
    879879}
    880880
    881 struct ZZ* mat_ZZ_determinant(const struct mat_ZZ* x, long deterministic)
     881struct ZZ* mat_ZZ_determinant(const mat_ZZ* x, long deterministic)
    882882{
    883883    ZZ* d = new ZZ();
    884884    determinant(*d, *x, deterministic);
    885885    return d;
    886886}
    887887
    888 struct mat_ZZ* mat_ZZ_HNF(const struct mat_ZZ* A, const struct ZZ* D)
     888mat_ZZ* mat_ZZ_HNF(const mat_ZZ* A, const struct ZZ* D)
    889889{
    890     struct mat_ZZ* W = new mat_ZZ();
     890    mat_ZZ* W = new mat_ZZ();
    891891    HNF(*W, *A, *D);
    892892    return W;
    893893}
    894894
    895 long mat_ZZ_LLL(struct ZZ **det, struct mat_ZZ *x, long a, long b, long verbose)
     895long mat_ZZ_LLL(struct ZZ **det, mat_ZZ *x, long a, long b, long verbose)
    896896{
    897897    *det = new ZZ();
    898898    return LLL(**det,*x,a,b,verbose);
    899899}
    900900
    901 long mat_ZZ_LLL_U(struct ZZ **det, struct mat_ZZ *x, struct mat_ZZ *U, long a, long b, long verbose)
     901long mat_ZZ_LLL_U(struct ZZ **det, mat_ZZ *x, mat_ZZ *U, long a, long b, long verbose)
    902902{
    903903    *det = new ZZ();
    904904    return LLL(**det,*x,*U,a,b,verbose);
    905905}
    906906
    907907
    908 struct ZZX* mat_ZZ_charpoly(const struct mat_ZZ* A)
     908struct ZZX* mat_ZZ_charpoly(const mat_ZZ* A)
    909909{
    910910    ZZX* f = new ZZX();
    911911    CharPoly(*f, *A);
     
    928928}
    929929
    930930
    931 void mat_GF2E_setitem(struct mat_GF2E* x, int i, int j, const struct GF2E* z)
     931void mat_GF2E_setitem(mat_GF2E* x, int i, int j, const struct GF2E* z)
    932932{
    933933    (*x)[i][j] = *z;
    934934}
    935935
    936 void mat_GF2_setitem(struct mat_GF2* x, int i, int j, const struct GF2* z)
     936void mat_GF2_setitem(mat_GF2* x, int i, int j, const struct GF2* z)
    937937{
    938938    (*x)[i][j] = *z;
    939939}
  • sage/libs/ntl/decl.pxi

    diff --git a/sage/libs/ntl/decl.pxi b/sage/libs/ntl/decl.pxi
    a b  
    2222
    2323cdef extern from "ntl_wrap.h":
    2424    #### mat_ZZ_c
    25     ctypedef struct mat_ZZ_c "struct mat_ZZ":
     25    cdef cppclass mat_ZZ_c "mat_ZZ":
    2626        pass
    2727
    2828    # Some boiler-plate
     
    260260    object vec_GF2E_to_PyString "_to_PyString<vec_GF2E>"(vec_GF2E_c *x)
    261261
    262262    #### mat_GF2E_c
    263     ctypedef struct mat_GF2E_c "struct mat_GF2E":
     263    cdef cppclass mat_GF2E_c "mat_GF2E":
    264264        void (*SetDims)(long nrows, long ncols)
    265265        long (*NumRows)()
    266266        long (*NumCols)()
     
    311311
    312312
    313313    #### mat_GF2_c
    314     ctypedef struct mat_GF2_c "struct mat_GF2":
     314    cdef cppclass mat_GF2_c "mat_GF2":
    315315        void (*SetDims)(long nrows, long ncols)
    316316        long (*NumRows)()
    317317        long (*NumCols)()
  • sage/schemes/hyperelliptic_curves/hypellfrob.pyx

    diff --git a/sage/schemes/hyperelliptic_curves/hypellfrob.pyx b/sage/schemes/hyperelliptic_curves/hypellfrob.pyx
    a b  
    119119
    120120   cdef int result
    121121   sig_on()
    122    result = hypellfrob_matrix(mm.x, pp.x, N, QQ.x)
     122   cdef mat_ZZ_c *mm_x = &mm.x    # workaround for Cython misfeature
     123   result = hypellfrob_matrix(mm_x[0], pp.x, N, QQ.x)
    123124   sig_off()
    124125
    125126   if not result: