File: test_pruner.py

package info (click to toggle)
fpylll 0.2.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 648 kB
  • ctags: 527
  • sloc: python: 818; makefile: 18
file content (36 lines) | stat: -rw-r--r-- 868 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-

from fpylll import IntegerMatrix, GSO, LLL, prune

try:
    from fpylll.numpy import dump_r
    have_numpy = True
except ImportError:
    have_numpy = False


def prepare(n, m):
    A = [IntegerMatrix.random(n, "qary", bits=n, k=n) for _ in range(m)]
    M = [GSO.Mat(a) for a in A]
    L = [LLL.Reduction(m) for m in M]
    [l() for l in L]
    return M


def test_pruner_gso(n=20, m=20):
    M = prepare(n, m)
    radius = sum([mat.get_r(0, 0) for mat in M])/len(M)
    pruning = prune(radius, 0, 0.9, M)
    assert pruning.probability >= 0.89


def test_pruner_vec(n=20, m=20):
    M = prepare(n, m)
    if have_numpy:
        vec = []
        for m in M:
            vec.append(tuple(dump_r(m, 0, n)))

    radius = sum([mat.get_r(0, 0) for mat in M])/len(M)
    pruning = prune(radius, 0, 0.9, vec)
    assert pruning.probability >= 0.89