Statistiques
| Branche: | Révision :

cvp / src / functions_for_cvp.sage @ ada40619

Historique | Voir | Annoter | Télécharger (926 octet)

1
def common_scaling_factor(precision, floatBasis, precisionFraction = None):
2
   """
3
   Compute the common scaling factor (a power of 2).
4
   The exponent is made of:
5
       - a fraction of the precision;
6
       - an integer depending on the smallest norm of the vectors of the basis.
7
   """
8
   ## Set a default value for the precisionFraction to 1/2.
9
   if precisionFraction is None:
10
       precisionFraction = 1/2
11
   ## Compute the norms of the vectors and get the smallest one.
12
   #  Start with  "oo" (+Infinty)
13
   minBasisVectsNorm = oo
14
   currentNorm = 0
15
   for vect in floatBasis.rows():
16
       currentNorm = vect.norm()
17
       if currentNorm < minBasisVectNorm:
18
           minBasisVectNorm = currentNorm
19
   powerForMinNorm = floor(log(minBasisVectsNorm)/log2)
20
   if powerForMinNorm < 0:
21
       return 2^(ceil(precision*precisionFraction) - powerFromMinNorm)
22
   else:
23
       return 2^(ceil(precision*precisionFraction))
24