Statistiques
| Branche: | Révision :

cvp / src / cvp-function.sage @ ada40619

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

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