OSDN Git Service

PR lto/50492
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-gearop.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --       S Y S T E M . G E N E R I C _ A R R A Y _ O P E R A T I O N S      --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2006-2011, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
17 --                                                                          --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception,   --
20 -- version 3.1, as published by the Free Software Foundation.               --
21 --                                                                          --
22 -- You should have received a copy of the GNU General Public License and    --
23 -- a copy of the GCC Runtime Library Exception along with this program;     --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25 -- <http://www.gnu.org/licenses/>.                                          --
26 --                                                                          --
27 -- GNAT was originally developed  by the GNAT team at  New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
32 package System.Generic_Array_Operations is
33 pragma Pure (Generic_Array_Operations);
34
35    ---------------------
36    -- Back_Substitute --
37    ---------------------
38
39    generic
40       type Scalar is private;
41       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
42       with function "-" (Left, Right : Scalar) return Scalar is <>;
43       with function "*" (Left, Right : Scalar) return Scalar is <>;
44       with function "/" (Left, Right : Scalar) return Scalar is <>;
45       with function Is_Non_Zero (X : Scalar) return Boolean is <>;
46    procedure Back_Substitute (M, N : in out Matrix);
47
48    --------------
49    -- Diagonal --
50    --------------
51
52    generic
53       type Scalar is private;
54       type Vector is array (Integer range <>) of Scalar;
55       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
56    function Diagonal (A : Matrix) return Vector;
57
58    -----------------------
59    -- Forward_Eliminate --
60    -----------------------
61
62    --  Use elementary row operations to put square matrix M in row echolon
63    --  form. Identical row operations are performed on matrix N, must have the
64    --  same number of rows as M.
65
66    generic
67       type Scalar is private;
68       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
69       with function "-" (Left, Right : Scalar) return Scalar is <>;
70       with function "*" (Left, Right : Scalar) return Scalar is <>;
71       with function "/" (Left, Right : Scalar) return Scalar is <>;
72       with function "<" (Left, Right : Scalar) return Boolean is <>;
73       Zero, One : Scalar;
74    procedure Forward_Eliminate
75      (M   : in out Matrix;
76       N   : in out Matrix;
77       Det : out Scalar);
78
79    --------------------------
80    -- Square_Matrix_Length --
81    --------------------------
82
83    generic
84       type Scalar is private;
85       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
86    function Square_Matrix_Length (A : Matrix) return Natural;
87    --  If A is non-square, raise Constraint_Error,  else return its dimension
88
89    ----------------------------------
90    -- Vector_Elementwise_Operation --
91    ----------------------------------
92
93    generic
94       type X_Scalar is private;
95       type Result_Scalar is private;
96       type X_Vector is array (Integer range <>) of X_Scalar;
97       type Result_Vector is array (Integer range <>) of Result_Scalar;
98       with function Operation (X : X_Scalar) return Result_Scalar;
99    function Vector_Elementwise_Operation (X : X_Vector) return Result_Vector;
100
101    ----------------------------------
102    -- Matrix_Elementwise_Operation --
103    ----------------------------------
104
105    generic
106       type X_Scalar is private;
107       type Result_Scalar is private;
108       type X_Matrix is array (Integer range <>, Integer range <>) of X_Scalar;
109       type Result_Matrix is array (Integer range <>, Integer range <>)
110         of Result_Scalar;
111       with function Operation (X : X_Scalar) return Result_Scalar;
112    function Matrix_Elementwise_Operation (X : X_Matrix) return Result_Matrix;
113
114    -----------------------------------------
115    -- Vector_Vector_Elementwise_Operation --
116    -----------------------------------------
117
118    generic
119       type Left_Scalar is private;
120       type Right_Scalar is private;
121       type Result_Scalar is private;
122       type Left_Vector is array (Integer range <>) of Left_Scalar;
123       type Right_Vector is array (Integer range <>) of Right_Scalar;
124       type Result_Vector is array (Integer range <>) of Result_Scalar;
125       with function Operation
126              (Left  : Left_Scalar;
127               Right : Right_Scalar) return Result_Scalar;
128    function Vector_Vector_Elementwise_Operation
129      (Left  : Left_Vector;
130       Right : Right_Vector) return Result_Vector;
131
132    ------------------------------------------------
133    -- Vector_Vector_Scalar_Elementwise_Operation --
134    ------------------------------------------------
135
136    generic
137       type X_Scalar is private;
138       type Y_Scalar is private;
139       type Z_Scalar is private;
140       type Result_Scalar is private;
141       type X_Vector is array (Integer range <>) of X_Scalar;
142       type Y_Vector is array (Integer range <>) of Y_Scalar;
143       type Result_Vector is array (Integer range <>) of Result_Scalar;
144       with function Operation
145              (X : X_Scalar;
146               Y : Y_Scalar;
147               Z : Z_Scalar) return Result_Scalar;
148    function Vector_Vector_Scalar_Elementwise_Operation
149      (X : X_Vector;
150       Y : Y_Vector;
151       Z : Z_Scalar) return Result_Vector;
152
153    -----------------------------------------
154    -- Matrix_Matrix_Elementwise_Operation --
155    -----------------------------------------
156
157    generic
158       type Left_Scalar is private;
159       type Right_Scalar is private;
160       type Result_Scalar is private;
161       type Left_Matrix is array (Integer range <>, Integer range <>)
162         of Left_Scalar;
163       type Right_Matrix is array (Integer range <>, Integer range <>)
164         of Right_Scalar;
165       type Result_Matrix is array (Integer range <>, Integer range <>)
166         of Result_Scalar;
167       with function Operation
168              (Left  : Left_Scalar;
169               Right : Right_Scalar) return Result_Scalar;
170    function Matrix_Matrix_Elementwise_Operation
171      (Left  : Left_Matrix;
172       Right : Right_Matrix) return Result_Matrix;
173
174    ------------------------------------------------
175    -- Matrix_Matrix_Scalar_Elementwise_Operation --
176    ------------------------------------------------
177
178    generic
179       type X_Scalar is private;
180       type Y_Scalar is private;
181       type Z_Scalar is private;
182       type Result_Scalar is private;
183       type X_Matrix is array (Integer range <>, Integer range <>) of X_Scalar;
184       type Y_Matrix is array (Integer range <>, Integer range <>) of Y_Scalar;
185       type Result_Matrix is array (Integer range <>, Integer range <>)
186         of Result_Scalar;
187       with function Operation
188              (X : X_Scalar;
189               Y : Y_Scalar;
190               Z : Z_Scalar) return Result_Scalar;
191    function Matrix_Matrix_Scalar_Elementwise_Operation
192      (X : X_Matrix;
193       Y : Y_Matrix;
194       Z : Z_Scalar) return Result_Matrix;
195
196    -----------------------------------------
197    -- Vector_Scalar_Elementwise_Operation --
198    -----------------------------------------
199
200    generic
201       type Left_Scalar is private;
202       type Right_Scalar is private;
203       type Result_Scalar is private;
204       type Left_Vector is array (Integer range <>) of Left_Scalar;
205       type Result_Vector is array (Integer range <>) of Result_Scalar;
206       with function Operation
207              (Left  : Left_Scalar;
208               Right : Right_Scalar) return Result_Scalar;
209    function Vector_Scalar_Elementwise_Operation
210      (Left  : Left_Vector;
211       Right : Right_Scalar) return Result_Vector;
212
213    -----------------------------------------
214    -- Matrix_Scalar_Elementwise_Operation --
215    -----------------------------------------
216
217    generic
218       type Left_Scalar is private;
219       type Right_Scalar is private;
220       type Result_Scalar is private;
221       type Left_Matrix is array (Integer range <>, Integer range <>)
222         of Left_Scalar;
223       type Result_Matrix is array (Integer range <>, Integer range <>)
224         of Result_Scalar;
225       with function Operation
226              (Left  : Left_Scalar;
227               Right : Right_Scalar) return Result_Scalar;
228    function Matrix_Scalar_Elementwise_Operation
229      (Left  : Left_Matrix;
230       Right : Right_Scalar) return Result_Matrix;
231
232    -----------------------------------------
233    -- Scalar_Vector_Elementwise_Operation --
234    -----------------------------------------
235
236    generic
237       type Left_Scalar is private;
238       type Right_Scalar is private;
239       type Result_Scalar is private;
240       type Right_Vector is array (Integer range <>) of Right_Scalar;
241       type Result_Vector is array (Integer range <>) of Result_Scalar;
242       with function Operation
243              (Left  : Left_Scalar;
244               Right : Right_Scalar) return Result_Scalar;
245    function Scalar_Vector_Elementwise_Operation
246      (Left  : Left_Scalar;
247       Right : Right_Vector) return Result_Vector;
248
249    -----------------------------------------
250    -- Scalar_Matrix_Elementwise_Operation --
251    -----------------------------------------
252
253    generic
254       type Left_Scalar is private;
255       type Right_Scalar is private;
256       type Result_Scalar is private;
257       type Right_Matrix is array (Integer range <>, Integer range <>)
258         of Right_Scalar;
259       type Result_Matrix is array (Integer range <>, Integer range <>)
260         of Result_Scalar;
261       with function Operation
262              (Left  : Left_Scalar;
263               Right : Right_Scalar) return Result_Scalar;
264    function Scalar_Matrix_Elementwise_Operation
265      (Left  : Left_Scalar;
266       Right : Right_Matrix) return Result_Matrix;
267
268    -------------------
269    -- Inner_Product --
270    -------------------
271
272    generic
273       type Left_Scalar is private;
274       type Right_Scalar is private;
275       type Result_Scalar is private;
276       type Left_Vector is array (Integer range <>) of Left_Scalar;
277       type Right_Vector is array (Integer range <>) of Right_Scalar;
278       Zero : Result_Scalar;
279       with function "*"
280              (Left  : Left_Scalar;
281               Right : Right_Scalar) return Result_Scalar is <>;
282       with function "+"
283              (Left  : Result_Scalar;
284               Right : Result_Scalar) return Result_Scalar is <>;
285    function Inner_Product
286      (Left  : Left_Vector;
287       Right : Right_Vector) return Result_Scalar;
288
289    -------------
290    -- L2_Norm --
291    -------------
292
293    generic
294       type Scalar is private;
295       type Vector is array (Integer range <>) of Scalar;
296       with function Inner_Product (Left, Right : Vector) return Scalar is <>;
297       with function Sqrt (X : Scalar) return Scalar is <>;
298    function L2_Norm (X : Vector) return Scalar;
299
300    -------------------
301    -- Outer_Product --
302    -------------------
303
304    generic
305       type Left_Scalar is private;
306       type Right_Scalar is private;
307       type Result_Scalar is private;
308       type Left_Vector is array (Integer range <>) of Left_Scalar;
309       type Right_Vector is array (Integer range <>) of Right_Scalar;
310       type Matrix is array (Integer range <>, Integer range <>)
311         of Result_Scalar;
312       with function "*"
313              (Left  : Left_Scalar;
314               Right : Right_Scalar) return Result_Scalar is <>;
315    function Outer_Product
316      (Left  : Left_Vector;
317       Right : Right_Vector) return Matrix;
318
319    ---------------------------
320    -- Matrix_Vector_Product --
321    ---------------------------
322
323    generic
324       type Left_Scalar is private;
325       type Right_Scalar is private;
326       type Result_Scalar is private;
327       type Matrix is array (Integer range <>, Integer range <>)
328         of Left_Scalar;
329       type Right_Vector is array (Integer range <>) of Right_Scalar;
330       type Result_Vector is array (Integer range <>) of Result_Scalar;
331       Zero : Result_Scalar;
332       with function "*"
333              (Left  : Left_Scalar;
334               Right : Right_Scalar) return Result_Scalar is <>;
335       with function "+"
336              (Left  : Result_Scalar;
337               Right : Result_Scalar) return Result_Scalar is <>;
338    function Matrix_Vector_Product
339      (Left  : Matrix;
340       Right : Right_Vector) return Result_Vector;
341
342    ---------------------------
343    -- Vector_Matrix_Product --
344    ---------------------------
345
346    generic
347       type Left_Scalar is private;
348       type Right_Scalar is private;
349       type Result_Scalar is private;
350       type Left_Vector is array (Integer range <>) of Left_Scalar;
351       type Matrix is array (Integer range <>, Integer range <>)
352         of Right_Scalar;
353       type Result_Vector is array (Integer range <>) of Result_Scalar;
354       Zero : Result_Scalar;
355       with function "*"
356              (Left  : Left_Scalar;
357               Right : Right_Scalar) return Result_Scalar is <>;
358       with function "+"
359              (Left  : Result_Scalar;
360               Right : Result_Scalar) return Result_Scalar is <>;
361    function Vector_Matrix_Product
362      (Left  : Left_Vector;
363       Right : Matrix) return Result_Vector;
364
365    ---------------------------
366    -- Matrix_Matrix_Product --
367    ---------------------------
368
369    generic
370       type Left_Scalar is private;
371       type Right_Scalar is private;
372       type Result_Scalar is private;
373       type Left_Matrix is array (Integer range <>, Integer range <>)
374         of Left_Scalar;
375       type Right_Matrix is array (Integer range <>, Integer range <>)
376         of Right_Scalar;
377       type Result_Matrix is array (Integer range <>, Integer range <>)
378         of Result_Scalar;
379       Zero : Result_Scalar;
380       with function "*"
381              (Left  : Left_Scalar;
382               Right : Right_Scalar) return Result_Scalar is <>;
383       with function "+"
384              (Left  : Result_Scalar;
385               Right : Result_Scalar) return Result_Scalar is <>;
386    function Matrix_Matrix_Product
387      (Left  : Left_Matrix;
388       Right : Right_Matrix) return Result_Matrix;
389
390    -----------------
391    -- Swap_Column --
392    -----------------
393
394    generic
395       type Scalar is private;
396       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
397    procedure Swap_Column (A : in out Matrix; Left, Right : Integer);
398
399    ---------------
400    -- Transpose --
401    ---------------
402
403    generic
404       type Scalar is private;
405       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
406    procedure Transpose (A : Matrix; R : out Matrix);
407
408    -------------------------------
409    -- Update_Vector_With_Vector --
410    -------------------------------
411
412    generic
413       type X_Scalar is private;
414       type Y_Scalar is private;
415       type X_Vector is array (Integer range <>) of X_Scalar;
416       type Y_Vector is array (Integer range <>) of Y_Scalar;
417       with procedure Update (X : in out X_Scalar; Y : Y_Scalar);
418    procedure Update_Vector_With_Vector (X : in out X_Vector; Y : Y_Vector);
419
420    -------------------------------
421    -- Update_Matrix_With_Matrix --
422    -------------------------------
423
424    generic
425       type X_Scalar is private;
426       type Y_Scalar is private;
427       type X_Matrix is array (Integer range <>, Integer range <>) of X_Scalar;
428       type Y_Matrix is array (Integer range <>, Integer range <>) of Y_Scalar;
429       with procedure Update (X : in out X_Scalar; Y : Y_Scalar);
430    procedure Update_Matrix_With_Matrix (X : in out X_Matrix; Y : Y_Matrix);
431
432    -----------------
433    -- Unit_Matrix --
434    -----------------
435
436    generic
437       type Scalar is private;
438       type Matrix is array (Integer range <>, Integer range <>) of Scalar;
439       Zero : Scalar;
440       One  : Scalar;
441    function Unit_Matrix
442      (Order   : Positive;
443       First_1 : Integer := 1;
444       First_2 : Integer := 1) return Matrix;
445
446    -----------------
447    -- Unit_Vector --
448    -----------------
449
450    generic
451       type Scalar is private;
452       type Vector is array (Integer range <>) of Scalar;
453       Zero : Scalar;
454       One  : Scalar;
455    function Unit_Vector
456      (Index : Integer;
457       Order : Positive;
458       First : Integer := 1) return Vector;
459
460 end System.Generic_Array_Operations;