File: test_mlgmp.ml

package info (click to toggle)
mlgmp 20021123-20
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 512 kB
  • sloc: ansic: 3,257; ml: 3,126; makefile: 167
file content (69 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (7)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
open Gmp
open Format

let rng=RNG.randinit (RNG.GMP_RAND_ALG_LC 100);;

let random_matrix l c =
  let a = Array.create_matrix l c F.zero in
  for i=0 to pred l
  do
    for j=0 to pred c
    do
      a.(i).(j) <- F.urandomb ~state: rng ~nbits: 40
    done
  done;
  a

let matrix_mul a b =
  let m = Array.length a
  and l = Array.length a.(0)
  and l' = Array.length b
  and n = Array.length b.(0) in
  assert (l = l');
  let c = Array.create_matrix m n F.zero in
  for i=0 to pred m
  do
    for j=0 to pred n
    do
      let z = ref F.zero in (* missing in FR *)
      for k=0 to pred l
      do
        z := F.add !z  (F.mul a.(i).(k) b.(k).(j))
      done;
      a.(i).(j) <- !z
    done
  done;
  a;;

let pp_matrix formatter a =
  pp_open_vbox formatter 0;
  for i=0 to pred (Array.length a)
  do
    pp_open_hbox formatter ();
    pp_print_string formatter "[ ";
    for j=0 to pred (Array.length a.(0))
    do
      pp_print_string formatter ((F.to_string a.(i).(j))^" ")
    done;
    pp_print_string formatter " ]";
    pp_close_box formatter ()
  done;
  pp_close_box formatter ();;

let n = 1000 in
let a = random_matrix n n
and b = random_matrix n n in
();;

(* MPFR Athlon 850
   n    t(s) mem(Mb)
 100   0.059
 250               6
 300   1.122
 500   6.780      21
1000  97.763      85

   GMP PentiumIII 1GHz
   n   t(s)
1000  120
*)