mathpaqs_20230121.0.0_773568e5/lin_alg/g_matrices.ads

 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
70
71
------------------------------------------------------------------------------
--  File:            gmatrice.ads or g_matrices.ads
--
--  Description:     Simple generic matrix package.
--                   The scalars (Field_elt) can be of any kind (real, complex, rationals, ...)
--
--                   NB: For Ada 2005+ and Field_elt = floating-point numbers,
--                       it is better, for performance and compatibility reasons,
--                       to use Ada.Numerics.Generic_Real_Arrays instead.
--
--  Date / Version:  3-Feb-2005 ; 16-Oct-2001 ; ... ; 22 XII 1997
--  Author:          Gautier de Montmollin
------------------------------------------------------------------------------

generic -- Requires an algebraic field with a square root
  -- e.g. floating point numbers, fixed point numbers

  type Field_elt is private; -- Element of the algebraic field
  zero, one : Field_elt;                       -- 0 and 1 elements

  with function "-" (a: Field_elt) return Field_elt;    -- unary operator
  with function Sqrt (a: Field_elt) return Field_elt;

  with function "+" (a, b: Field_elt) return Field_elt;  -- binary operator
  with function "-" (a, b: Field_elt) return Field_elt;
  with function "*" (a, b: Field_elt) return Field_elt;
  with function "/" (a, b: Field_elt) return Field_elt;
  pragma Unreferenced ("/");
  -- no more "=" for Ada 83 compatibility

  -- Change 2005: Vector, Matrix also as parameter, allows generic on generic
  -- e.g. G_Matrices in generic FEK's body.
  type Vector is array (Integer range <>) of Field_elt;
  type Matrix is array (Integer range <>, Integer range <>) of Field_elt;

package G_Matrices is

  -- 2005: ghosts of previous versions:
  -- type IVector is array (Integer range <>) of Integer;
  -- type IMatrix is array (Integer range <>, Integer range <>) of Integer;
  -- type p_Matrix is access Matrix;
  -- type p_Vector is access Vector;
  -- type p_IMatrix is access IMatrix;
  -- type p_IVector is access IVector;

  -- Vector operations

  function "*" (l: Field_elt; v: Vector) return Vector;
  function "-" (a: Vector) return Vector;
  function "+" (a, b: Vector) return Vector;
  function "-" (a, b: Vector) return Vector;
  function "*" (a, b: Vector) return Field_elt;  -- produit scalaire
  function Norm (a: Vector) return Field_elt;
  function Square_norm (a: Vector) return Field_elt;  -- norme au carr\'e
  function Distance (a, b: Vector) return Field_elt;
  function Square_dist (a, b: Vector) return Field_elt;

  -- Matrix operations

  function Transpose (A: Matrix) return Matrix;
  function Id (order: Positive) return Matrix;
  function "*" (l: Field_elt; A: Matrix) return Matrix;
  function "*" (A, B: Matrix) return Matrix;
  function "+" (A, B: Matrix) return Matrix;
  function "-" (A, B: Matrix) return Matrix;

  -- Matrix-Vector operations

  function "*" (A: Matrix; x: Vector) return Vector;

end G_Matrices;