Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002     Copyright (C) 2014 Abhinav Baid
0003 
0004     This file is part of FLINT.
0005 
0006     FLINT is free software: you can redistribute it and/or modify it under
0007     the terms of the GNU Lesser General Public License (LGPL) as published
0008     by the Free Software Foundation; either version 3 of the License, or
0009     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
0010 */
0011 
0012 #ifndef D_VEC_H
0013 #define D_VEC_H
0014 
0015 #ifdef D_VEC_INLINES_C
0016 #define D_VEC_INLINE
0017 #else
0018 #define D_VEC_INLINE static inline
0019 #endif
0020 
0021 #include "flint.h"
0022 #include "double_extras.h"
0023 
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027 
0028 /*  Memory management  *******************************************************/
0029 
0030 double * _d_vec_init(slong len);
0031 
0032 void _d_vec_clear(double * vec);
0033 
0034 /*  Randomisation  ***********************************************************/
0035 
0036 void _d_vec_randtest(double * f, flint_rand_t state,
0037                         slong len, slong minexp, slong maxexp);
0038 
0039 /*  Assignment and basic manipulation  ***************************************/
0040 
0041 void _d_vec_set(double * vec1, const double * vec2, slong len2);
0042 
0043 void _d_vec_zero(double * vec, slong len);
0044 
0045 /*  Comparison  **************************************************************/
0046 
0047 int _d_vec_equal(const double * vec1, const double * vec2, slong len);
0048 
0049 int _d_vec_approx_equal(const double * vec1, const double * vec2, slong len, double eps);
0050 
0051 int _d_vec_is_zero(const double * vec, slong len);
0052 
0053 int _d_vec_is_approx_zero(const double * vec, slong len, double eps);
0054 
0055 /*  Arithmetic  ****************************************************************/
0056 
0057 void _d_vec_add(double * res, const double * vec1, const double * vec2, slong len2);
0058 
0059 void _d_vec_sub(double * res, const double * vec1, const double * vec2, slong len2);
0060 
0061 D_VEC_INLINE
0062 void _d_vec_mul_2exp(double * res, const double * x, slong len, int e)
0063 {
0064     slong i;
0065 
0066     if (e >= D_MIN_NORMAL_EXPONENT && e <= D_MAX_NORMAL_EXPONENT)
0067     {
0068         double_uint64_u u;
0069         u.i = ((int64_t) (e + D_EXPONENT_BIAS)) << D_EXPONENT_SHIFT;
0070 
0071         for (i = 0; i < len; i++)
0072             res[i] = x[i] * u.f;
0073     }
0074     else
0075     {
0076         for (i = 0; i < len; i++)
0077             res[i] = ldexp(x[i], e);
0078     }
0079 }
0080 
0081 /*  Dot product and norm  **************************************/
0082 
0083 double _d_vec_dot(const double * vec1, const double * vec2, slong len2);
0084 
0085 double _d_vec_norm(const double * vec, slong len);
0086 
0087 double _d_vec_dot_heuristic(const double * vec1, const double * vec2, slong len2, double * err);
0088 
0089 double _d_vec_dot_thrice(const double * vec1, const double * vec2, slong len2, double * err);
0090 
0091 #ifdef __cplusplus
0092 }
0093 #endif
0094 
0095 #endif