gnat_math_extensions_1.1.0_e1f68c35/src/ada_numerics-generic_arrays.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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
--  This package is free software; you can redistribute it and/or
--  modify it under terms of the GNU General Public License as
--  published by the Free Software Foundation; either version 3, or
--  (at your option) any later version.  It is distributed in the
--  hope that it will be useful, but WITHOUT ANY WARRANTY; without
--  even the implied warranty of MERCHANTABILITY or FITNESS FOR A
--  PARTICULAR PURPOSE.
--
--  As a special exception under Section 7 of GPL version 3, you are
--  granted additional permissions described in the GCC Runtime
--  Library Exception, version 3.1, as published by the Free Software
--  Foundation.
--
--  You should have received a copy of the GNU General Public License
--  and a copy of the GCC Runtime Library Exception along with this
--  program; see the files COPYING3 and COPYING.RUNTIME respectively.
--  If not, see <http://www.gnu.org/licenses/>.
--
--  Copyright Simon Wright <simon@pushface.org>

pragma License (Modified_GPL);

with Ada.Numerics.Generic_Complex_Arrays;

generic
   with package Complex_Arrays
      is new Ada.Numerics.Generic_Complex_Arrays (<>);
package Ada_Numerics.Generic_Arrays is
   pragma Pure (Generic_Arrays);

   package Complex_Types renames Complex_Arrays.Complex_Types;
   package Real_Arrays renames Complex_Arrays.Real_Arrays;

   --  Obtain the eigenvalues of a non-hermitian complex matrix.
   --
   --  The range of the result is A'Range (1).
   function Eigenvalues (A : Complex_Arrays.Complex_Matrix)
                        return Complex_Arrays.Complex_Vector
   with
     Pre => A'Length (1) = A'Length (2),
     Post => Eigenvalues'Result'First = A'First (1)
             and then Eigenvalues'Result'Last = A'Last (1);

   --  Obtain the eigenvalues and eigenvectors of a non-hermitian
   --  complex matrix.
   --
   --  Values'Range must be the same as Vectors'Range (1).
   --  The ranges of Vectors must be the same as those of A.
   --
   --  The eigenvector corresponding to the jth element of Values is
   --  output in the jth column of Vectors.
   procedure Eigensystem
     (A       :     Complex_Arrays.Complex_Matrix;
      Values  : out Complex_Arrays.Complex_Vector;
      Vectors : out Complex_Arrays.Complex_Matrix)
   with
     Pre =>
       A'Length (1) = A'Length (2)
       and then Values'First = Vectors'First (1)
       and then Values'Last = Vectors'Last (1)
       and then A'First (1) = Vectors'First (1)
       and then A'Last (1) = Vectors'Last (1);

   --  Obtain the eigenvalues of a non-symmetric real matrix.
   --
   --  The range of the result is A'Range (1).
   function Eigenvalues (A : Real_Arrays.Real_Matrix)
                        return Complex_Arrays.Complex_Vector
   with
     Pre => A'Length (1) = A'Length (2),
     Post =>
       Eigenvalues'Result'First = A'First (1)
       and then Eigenvalues'Result'Last = A'Last (1);

   --  Obtain the eigenvalues and eigenvectors of a non-symmetric real
   --  matrix.
   --
   --  Values'Range must be the same as Vectors'Range (1).
   --  The ranges of Vectors must be the same as those of A.
   --
   --  The eigenvector corresponding to the jth element of Values is
   --  output in the jth column of Vectors.
   procedure Eigensystem
     (A       :     Real_Arrays.Real_Matrix;
      Values  : out Complex_Arrays.Complex_Vector;
      Vectors : out Complex_Arrays.Complex_Matrix)
   with
     Pre =>
       A'Length (1) = A'Length (2)
       and then Values'First = Vectors'First (1)
       and then Values'Last = Vectors'Last (1)
       and then A'First (1) = Vectors'First (1)
       and then A'Last (1) = Vectors'Last (1);

   --  A generalized eigenvalue for a pair of matrices (A,B) is a
   --  scalar lambda or a ratio alpha/beta = lambda, such that A -
   --  lambda*B is singular (or, equivalently, beta*A - alpha*B is
   --  singular).
   --
   --  It is usually represented as the pair (alpha,beta), as there
   --  is a reasonable interpretation for beta = 0, and even for both
   --  being zero.
   type Generalized_Eigenvalue is record
      Alpha : Complex_Types.Complex;
      Beta  : Complex_Types.Complex;
   end record;
   type Generalized_Eigenvalue_Vector
      is array (Integer range <>) of Generalized_Eigenvalue;

   --  Obtain the generalized eigenvalues and the right generalized
   --  eigenvectors of a pair of non-hermitian complex matrices.
   --
   --  The right eigenvector v(j) corresponding to the eigenvalue
   --  lambda(j) of (A,B) satisfies
   --            A * v(j) = lambda(j) * B * v(j).
   --
   --  Values'Range must be the same as A'Range (1).
   --  The ranges of A, B and Vectors must be the same.
   procedure Eigensystem
     (A       :     Complex_Arrays.Complex_Matrix;
      B       :     Complex_Arrays.Complex_Matrix;
      Values  : out Generalized_Eigenvalue_Vector;
      Vectors : out Complex_Arrays.Complex_Matrix)
   with
     Pre =>
       A'First (1) = B'First (1)
       and then A'Last (1) = B'Last (1)
       and then A'First (2) = B'First (2)
       and then A'Last (2) = B'Last (2)
       and then B'First (2) = Vectors'First (2)
       and then B'Last (2) = Vectors'Last (2)
       and then B'First (1) = Vectors'First (1)
       and then B'Last (1) = Vectors'Last (1)
       and then Values'First = A'First (1)
       and then Values'Last = A'Last (1);

   --  Obtain the generalized eigenvalues and the right generalized
   --  eigenvectors of a pair of non-symmetric real matrices.
   --
   --  The right eigenvector v(j) corresponding to the eigenvalue
   --  lambda(j) of (A,B) satisfies
   --            A * v(j) = lambda(j) * B * v(j).
   --
   --  Values'Range must be the same as A'Range (1).
   --  The ranges of A, B and Vectors must be the same.
   procedure Eigensystem
     (A       :     Real_Arrays.Real_Matrix;
      B       :     Real_Arrays.Real_Matrix;
      Values  : out Generalized_Eigenvalue_Vector;
      Vectors : out Complex_Arrays.Complex_Matrix)
   with
     Pre =>
       A'First (1) = B'First (1)
       and then A'Last (1) = B'Last (1)
       and then A'First (2) = B'First (2)
       and then A'Last (2) = B'Last (2)
       and then B'First (2) = Vectors'First (2)
       and then B'Last (2) = Vectors'Last (2)
       and then B'First (1) = Vectors'First (1)
       and then B'Last (1) = Vectors'Last (1)
       and then Values'First = A'First (1)
       and then Values'Last = A'Last (1);

end Ada_Numerics.Generic_Arrays;