Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:15:19

0001 /*
0002     Copyright (C) 2013 Mike Hansen
0003     Copyright (C) 2018 Tommy Hofmann
0004 
0005     This file is part of FLINT.
0006 
0007     FLINT is free software: you can redistribute it and/or modify it under
0008     the terms of the GNU Lesser General Public License (LGPL) as published
0009     by the Free Software Foundation; either version 3 of the License, or
0010     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
0011 */
0012 
0013 #ifdef T
0014 
0015 #include "nmod_types.h"
0016 #include "fmpz_mod_types.h"
0017 #include "templates.h"
0018 
0019 #ifdef __cplusplus
0020  extern "C" {
0021 #endif
0022 
0023 /* Memory management  ********************************************************/
0024 
0025 void TEMPLATE(T, mat_init)(TEMPLATE(T, mat_t) mat, slong rows, slong cols,
0026                       const TEMPLATE(T, ctx_t) ctx);
0027 
0028 void TEMPLATE(T, mat_init_set)(TEMPLATE(T, mat_t) mat, const TEMPLATE(T, mat_t) src,
0029                           const TEMPLATE(T, ctx_t) ctx);
0030 
0031 FQ_MAT_TEMPLATES_INLINE slong
0032 TEMPLATE(T, mat_nrows)(const TEMPLATE(T, mat_t) mat,
0033                        const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx))
0034 {
0035     return mat->r;
0036 }
0037 
0038 FQ_MAT_TEMPLATES_INLINE slong
0039 TEMPLATE(T, mat_ncols)(const TEMPLATE(T, mat_t) mat,
0040                        const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx))
0041 {
0042     return mat->c;
0043 }
0044 
0045 FQ_MAT_TEMPLATES_INLINE TEMPLATE(T, struct) *
0046 TEMPLATE(T, mat_entry)(const TEMPLATE(T, mat_t) mat, slong i, slong j)
0047 {
0048     return mat->entries + i * mat->stride + j;
0049 }
0050 
0051 void TEMPLATE(T, mat_entry_set)(TEMPLATE(T, mat_t) mat, slong i, slong j,
0052                            const TEMPLATE(T, t) x,
0053                            const TEMPLATE(T, ctx_t) ctx);
0054 
0055 void TEMPLATE(T, mat_swap)(TEMPLATE(T, mat_t) mat1, TEMPLATE(T, mat_t) mat2,
0056                       const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx));
0057 
0058 void TEMPLATE(T, mat_swap_entrywise)(TEMPLATE(T, mat_t) mat1,
0059                  TEMPLATE(T, mat_t) mat2, const TEMPLATE(T, ctx_t) ctx);
0060 
0061 void TEMPLATE(T, mat_set)(TEMPLATE(T, mat_t) mat1, const TEMPLATE(T, mat_t) mat2,
0062                      const TEMPLATE(T, ctx_t) ctx);
0063 
0064 void TEMPLATE(T, mat_clear)(TEMPLATE(T, mat_t) mat, const TEMPLATE(T, ctx_t) ctx);
0065 
0066 int TEMPLATE(T, mat_equal)(const TEMPLATE(T, mat_t) mat1,
0067                        const TEMPLATE(T, mat_t) mat2,
0068                        const TEMPLATE(T, ctx_t) ctx);
0069 
0070 int TEMPLATE(T, mat_is_zero)(const TEMPLATE(T, mat_t) mat,
0071                          const TEMPLATE(T, ctx_t) ctx);
0072 
0073 int TEMPLATE(T, mat_is_one)(const TEMPLATE(T, mat_t) mat,
0074                                  const TEMPLATE(T, ctx_t) ctx);
0075 
0076 FQ_MAT_TEMPLATES_INLINE int
0077 TEMPLATE(T, mat_is_empty)(const TEMPLATE(T, mat_t) mat,
0078                           const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx))
0079 {
0080     return (mat->r == 0) || (mat->c == 0);
0081 }
0082 
0083 FQ_MAT_TEMPLATES_INLINE int
0084 TEMPLATE(T, mat_is_square)(const TEMPLATE(T, mat_t) mat,
0085                            const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx))
0086 {
0087     return (mat->r == mat->c);
0088 }
0089 
0090 FQ_MAT_TEMPLATES_INLINE void
0091 TEMPLATE(T, mat_swap_rows)(TEMPLATE(T, mat_t) mat, slong * perm, slong r, slong s, const TEMPLATE(T, ctx_t) ctx)
0092 {
0093     if (r != s && !TEMPLATE(T, mat_is_empty)(mat, ctx))
0094     {
0095         slong i;
0096         TEMPLATE(T, struct) *u, *v;
0097 
0098         if (perm != NULL)
0099             FLINT_SWAP(slong, perm[r], perm[s]);
0100 
0101         u = TEMPLATE(T, mat_entry)(mat, r, 0);
0102         v = TEMPLATE(T, mat_entry)(mat, s, 0);
0103 
0104         for (i = 0; i < mat->c; i++)
0105             FLINT_SWAP(TEMPLATE(T, struct), u[i], v[i]);
0106     }
0107 }
0108 
0109 FQ_MAT_TEMPLATES_INLINE void
0110 TEMPLATE(T, mat_invert_rows)(TEMPLATE(T, mat_t) mat, slong * perm, const TEMPLATE(T, ctx_t) ctx)
0111 {
0112     slong i;
0113 
0114     for (i = 0; i < mat->r/2; i++)
0115         TEMPLATE(T, mat_swap_rows)(mat, perm, i, mat->r - i - 1, ctx);
0116 }
0117 
0118 void TEMPLATE(T, mat_swap_cols)(TEMPLATE(T, mat_t) mat, slong * perm, slong r, slong s, const TEMPLATE(T, ctx_t) ctx);
0119 
0120 void TEMPLATE(T, mat_invert_cols)(TEMPLATE(T, mat_t) mat, slong * perm, const TEMPLATE(T, ctx_t) ctx);
0121 
0122 /* Assignment  ***************************************************************/
0123 
0124 void TEMPLATE(T, mat_zero)(TEMPLATE(T, mat_t) A, const TEMPLATE(T, ctx_t) ctx);
0125 
0126 void TEMPLATE(T, mat_one)(TEMPLATE(T, mat_t) A, const TEMPLATE(T, ctx_t) ctx);
0127 
0128 /* Conversions ***************************************************************/
0129 
0130 void TEMPLATE(T, mat_set_nmod_mat) (TEMPLATE(T, mat_t) mat1,
0131                           const nmod_mat_t mat2, const TEMPLATE(T, ctx_t) ctx);
0132 
0133 void TEMPLATE(T, mat_set_fmpz_mod_mat) (TEMPLATE(T, mat_t) mat1,
0134                       const fmpz_mod_mat_t mat2, const TEMPLATE(T, ctx_t) ctx);
0135 
0136 /* Windows and concatenation */
0137 
0138 void TEMPLATE(T, mat_window_init)(TEMPLATE(T, mat_t) window,
0139                              const TEMPLATE(T, mat_t) mat,
0140                              slong r1, slong c1, slong r2, slong c2,
0141                              const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx));
0142 
0143 void TEMPLATE(T, mat_window_clear)(TEMPLATE(T, mat_t) FLINT_UNUSED(window),
0144                               const TEMPLATE(T, ctx_t) FLINT_UNUSED(ctx));
0145 
0146 void TEMPLATE(T, mat_concat_horizontal)(TEMPLATE(T, mat_t) res,
0147                            const TEMPLATE(T, mat_t) mat1,  const TEMPLATE(T, mat_t) mat2,
0148                            const TEMPLATE(T, ctx_t) ctx);
0149 
0150 void TEMPLATE(T, mat_concat_vertical)(TEMPLATE(T, mat_t) res,
0151                            const TEMPLATE(T, mat_t) mat1,  const TEMPLATE(T, mat_t) mat2,
0152                            const TEMPLATE(T, ctx_t) ctx);
0153 
0154 
0155 /* Input and output  *********************************************************/
0156 
0157 #ifdef FLINT_HAVE_FILE
0158 int TEMPLATE(T, mat_fprint)(FILE * file, const TEMPLATE(T, mat_t) mat, const TEMPLATE(T, ctx_t) ctx);
0159 int TEMPLATE(T, mat_fprint_pretty)(FILE * file, const TEMPLATE(T, mat_t) mat, const TEMPLATE(T, ctx_t) ctx);
0160 #endif
0161 
0162 int TEMPLATE(T, mat_print)(const TEMPLATE(T, mat_t) mat, const TEMPLATE(T, ctx_t) ctx);
0163 int TEMPLATE(T, mat_print_pretty)(const TEMPLATE(T, mat_t) mat, const TEMPLATE(T, ctx_t) ctx);
0164 
0165 /* TODO: Read functions */
0166 
0167 /* Random matrix generation  *************************************************/
0168 
0169 void TEMPLATE(T, mat_randtest)(TEMPLATE(T, mat_t) mat, flint_rand_t state,
0170                           const TEMPLATE(T, ctx_t) ctx);
0171 
0172 void TEMPLATE(T, mat_randrank)(TEMPLATE(T, mat_t) mat, flint_rand_t state,
0173                           slong rank, const TEMPLATE(T, ctx_t) ctx);
0174 
0175 int TEMPLATE(T, mat_randpermdiag)(TEMPLATE(T, mat_t) mat, flint_rand_t state,
0176                               TEMPLATE(T, struct) * diag, slong n,
0177                               const TEMPLATE(T, ctx_t) ctx);
0178 
0179 void TEMPLATE(T, mat_randops)(TEMPLATE(T, mat_t) mat,
0180                          flint_rand_t state, slong count, const TEMPLATE(T, ctx_t) ctx);
0181 
0182 void TEMPLATE(T, mat_randtril)(TEMPLATE(T, mat_t) mat, flint_rand_t state,
0183                           int unit, const TEMPLATE(T, ctx_t) ctx);
0184 
0185 void TEMPLATE(T, mat_randtriu)(TEMPLATE(T, mat_t) mat, flint_rand_t state,
0186                           int unit, const TEMPLATE(T, ctx_t) ctx);
0187 
0188 /* Norms */
0189 
0190 /* Transpose */
0191 
0192 void TEMPLATE(T, mat_transpose)(TEMPLATE(T, mat_t) B, const TEMPLATE(T, mat_t) A,
0193                            const TEMPLATE(T, ctx_t) ctx);
0194 
0195 /* Addition and subtraction */
0196 
0197 void TEMPLATE(T, mat_add)(TEMPLATE(T, mat_t) C,
0198                           const TEMPLATE(T, mat_t) A,
0199                           const TEMPLATE(T, mat_t) B,
0200                           const TEMPLATE(T, ctx_t) ctx);
0201 
0202 void TEMPLATE(T, mat_sub)(TEMPLATE(T, mat_t) C,
0203                           const TEMPLATE(T, mat_t) A,
0204                           const TEMPLATE(T, mat_t) B,
0205                           const TEMPLATE(T, ctx_t) ctx);
0206 
0207 void TEMPLATE(T, mat_neg)(TEMPLATE(T, mat_t) B,
0208                           const TEMPLATE(T, mat_t) A,
0209                           const TEMPLATE(T, ctx_t) ctx);
0210 
0211 void TEMPLATE(T, mat_submul)(TEMPLATE(T, mat_t) D,
0212                         const TEMPLATE(T, mat_t) C,
0213                         const TEMPLATE(T, mat_t) A,
0214                         const TEMPLATE(T, mat_t) B,
0215                         const TEMPLATE(T, ctx_t) ctx);
0216 
0217 /* Scalar operations */
0218 
0219 void TEMPLATE(T, mat_scalar_mul)(TEMPLATE(T, mat_t) B,
0220                           const TEMPLATE(T, mat_t) A,
0221                           const TEMPLATE(T, t) c,
0222                           const TEMPLATE(T, ctx_t) ctx);
0223 
0224 void TEMPLATE(T, mat_scalar_mul_fmpz)(TEMPLATE(T, mat_t) B,
0225                           const TEMPLATE(T, mat_t) A,
0226                           const fmpz_t c,
0227                           const TEMPLATE(T, ctx_t) ctx);
0228 
0229 void TEMPLATE(T, mat_scalar_mul_si)(TEMPLATE(T, mat_t) B,
0230                           const TEMPLATE(T, mat_t) A,
0231                           const slong c,
0232                           const TEMPLATE(T, ctx_t) ctx);
0233 
0234 void TEMPLATE(T, mat_scalar_mul_ui)(TEMPLATE(T, mat_t) B,
0235                           const TEMPLATE(T, mat_t) A,
0236                           const ulong c,
0237                           const TEMPLATE(T, ctx_t) ctx);
0238 
0239 /* Multiplication */
0240 
0241 void TEMPLATE(T, mat_mul)(TEMPLATE(T, mat_t) C,
0242                      const TEMPLATE(T, mat_t) A,
0243                      const TEMPLATE(T, mat_t) B,
0244                      const TEMPLATE(T, ctx_t) ctx);
0245 
0246 void TEMPLATE(T, mat_mul_classical)(TEMPLATE(T, mat_t) C,
0247                                const TEMPLATE(T, mat_t) A,
0248                                const TEMPLATE(T, mat_t) B,
0249                                const TEMPLATE(T, ctx_t) ctx);
0250 
0251 
0252 void TEMPLATE(T, mat_mul_KS)(TEMPLATE(T, mat_t) C,
0253                         const TEMPLATE(T, mat_t) A,
0254                         const TEMPLATE(T, mat_t) B,
0255                         const TEMPLATE(T, ctx_t) ctx);
0256 
0257 slong TEMPLATE(T, mat_lu)(slong * P,
0258                     TEMPLATE(T, mat_t) A,
0259                     int rank_check,
0260                     const TEMPLATE(T, ctx_t) ctx);
0261 
0262 /* Inverse *******************************************************************/
0263 
0264 int TEMPLATE(T, mat_inv)(TEMPLATE(T, mat_t) B, TEMPLATE(T, mat_t) A,
0265                                    const TEMPLATE(T, ctx_t) ctx);
0266 
0267 /* Solving *******************************************************************/
0268 
0269 slong TEMPLATE(T, mat_rref)(TEMPLATE(T, mat_t) B, const TEMPLATE(T, mat_t) A, const TEMPLATE(T, ctx_t) ctx);
0270 
0271 
0272 slong TEMPLATE(T, mat_reduce_row)(TEMPLATE(T, mat_t) A, slong * P, slong * L,
0273                                          slong m, const TEMPLATE(T, ctx_t) ctx);
0274 
0275 slong TEMPLATE(T, mat_nullspace)(TEMPLATE(T, mat_t) X, const TEMPLATE(T, mat_t) A,
0276                            const TEMPLATE(T, ctx_t) ctx);
0277 
0278 slong TEMPLATE(T, mat_rank)(const TEMPLATE(T, mat_t) A,
0279                       const TEMPLATE(T, ctx_t) ctx);
0280 
0281 void TEMPLATE(T, mat_solve_tril)(TEMPLATE(T, mat_t) X, const TEMPLATE(T, mat_t) L,
0282                             const TEMPLATE(T, mat_t) B, int unit,
0283                             const TEMPLATE(T, ctx_t) ctx);
0284 
0285 void TEMPLATE(T, mat_solve_triu)(TEMPLATE(T, mat_t) X, const TEMPLATE(T, mat_t) U,
0286                             const TEMPLATE(T, mat_t) B, int unit,
0287                             const TEMPLATE(T, ctx_t) ctx);
0288 
0289 void TEMPLATE(T, mat_mul_vec)(TEMPLATE(T, struct) * c,
0290                                     const TEMPLATE(T, mat_t) A,
0291                                     const TEMPLATE(T, struct) * b, slong blen,
0292                                     const TEMPLATE(T, ctx_t) ctx);
0293 
0294 void TEMPLATE(T, mat_mul_vec_ptr)(TEMPLATE(T, struct) * const * c,
0295                             const TEMPLATE(T, mat_t) A,
0296                             const TEMPLATE(T, struct) * const * b, slong blen,
0297                             const TEMPLATE(T, ctx_t) ctx);
0298 
0299 void TEMPLATE(T, mat_vec_mul)(TEMPLATE(T, struct) * c,
0300                                     const TEMPLATE(T, struct) * a, slong alen,
0301                                     const TEMPLATE(T, mat_t) B,
0302                                     const TEMPLATE(T, ctx_t) ctx);
0303 
0304 void TEMPLATE(T, mat_vec_mul_ptr)(TEMPLATE(T, struct) * const * c,
0305                             const TEMPLATE(T, struct) * const * a, slong alen,
0306                             const TEMPLATE(T, mat_t) B,
0307                             const TEMPLATE(T, ctx_t) ctx);
0308 
0309 /* Nonsingular solving *******************************************************/
0310 
0311 int TEMPLATE(T, mat_solve)(TEMPLATE(T, mat_t) X,
0312                const TEMPLATE(T, mat_t A), const TEMPLATE(T, mat_t) C,
0313                                                  const TEMPLATE(T, ctx_t) ctx);
0314 
0315 /* Solving *******************************************************************/
0316 
0317 int TEMPLATE(T, mat_can_solve)(TEMPLATE(T, mat_t) X,
0318                 const TEMPLATE(T, mat_t) A, const TEMPLATE(T, mat_t) B,
0319                                                  const TEMPLATE(T, ctx_t) ctx);
0320 
0321 /* Transforms ****************************************************************/
0322 
0323 
0324 void TEMPLATE(T, mat_similarity) (TEMPLATE(T, mat_t) A, slong r,
0325                                TEMPLATE(T, t) d, const TEMPLATE(T, ctx_t) ctx);
0326 
0327 /* Characteristic polynomial *************************************************/
0328 
0329 /* this prototype really lives in fq_poly_templates.h
0330  * FQ_MAT_TEMPLATES_INLINE
0331  * void TEMPLATE(T, mat_charpoly)(TEMPLATE(T, poly_t) p,
0332  *                          TEMPLATE(T, mat_t) A, const TEMPLATE(T, ctx_t) ctx)
0333  * {
0334  *   TEMPLATE(T, mat_charpoly) (p, A, ctx);
0335  * }
0336  */
0337 
0338 /* Minimal polynomial ********************************************************/
0339 
0340 /* this prototype really lives in fq_poly_templates.h
0341  *
0342  * void TEMPLATE(T, mat_minpoly) (TEMPLATE(T, poly_t) p,
0343  *                   const TEMPLATE(T, mat_t) X, const TEMPLATE(T, ctx_t) ctx);
0344  */
0345 
0346 #ifdef __cplusplus
0347 }
0348 #endif
0349 
0350 #endif