1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
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 --
9 -- Copyright (C) 2006-2011, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 package System.Generic_Array_Operations is
33 pragma Pure (Generic_Array_Operations);
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);
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;
58 -----------------------
59 -- Forward_Eliminate --
60 -----------------------
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.
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 <>;
74 procedure Forward_Eliminate
79 --------------------------
80 -- Square_Matrix_Length --
81 --------------------------
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
89 ----------------------------------
90 -- Vector_Elementwise_Operation --
91 ----------------------------------
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;
101 ----------------------------------
102 -- Matrix_Elementwise_Operation --
103 ----------------------------------
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 <>)
111 with function Operation (X : X_Scalar) return Result_Scalar;
112 function Matrix_Elementwise_Operation (X : X_Matrix) return Result_Matrix;
114 -----------------------------------------
115 -- Vector_Vector_Elementwise_Operation --
116 -----------------------------------------
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
127 Right : Right_Scalar) return Result_Scalar;
128 function Vector_Vector_Elementwise_Operation
130 Right : Right_Vector) return Result_Vector;
132 ------------------------------------------------
133 -- Vector_Vector_Scalar_Elementwise_Operation --
134 ------------------------------------------------
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
147 Z : Z_Scalar) return Result_Scalar;
148 function Vector_Vector_Scalar_Elementwise_Operation
151 Z : Z_Scalar) return Result_Vector;
153 -----------------------------------------
154 -- Matrix_Matrix_Elementwise_Operation --
155 -----------------------------------------
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 <>)
163 type Right_Matrix is array (Integer range <>, Integer range <>)
165 type Result_Matrix is array (Integer range <>, Integer range <>)
167 with function Operation
169 Right : Right_Scalar) return Result_Scalar;
170 function Matrix_Matrix_Elementwise_Operation
172 Right : Right_Matrix) return Result_Matrix;
174 ------------------------------------------------
175 -- Matrix_Matrix_Scalar_Elementwise_Operation --
176 ------------------------------------------------
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 <>)
187 with function Operation
190 Z : Z_Scalar) return Result_Scalar;
191 function Matrix_Matrix_Scalar_Elementwise_Operation
194 Z : Z_Scalar) return Result_Matrix;
196 -----------------------------------------
197 -- Vector_Scalar_Elementwise_Operation --
198 -----------------------------------------
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
208 Right : Right_Scalar) return Result_Scalar;
209 function Vector_Scalar_Elementwise_Operation
211 Right : Right_Scalar) return Result_Vector;
213 -----------------------------------------
214 -- Matrix_Scalar_Elementwise_Operation --
215 -----------------------------------------
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 <>)
223 type Result_Matrix is array (Integer range <>, Integer range <>)
225 with function Operation
227 Right : Right_Scalar) return Result_Scalar;
228 function Matrix_Scalar_Elementwise_Operation
230 Right : Right_Scalar) return Result_Matrix;
232 -----------------------------------------
233 -- Scalar_Vector_Elementwise_Operation --
234 -----------------------------------------
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
244 Right : Right_Scalar) return Result_Scalar;
245 function Scalar_Vector_Elementwise_Operation
247 Right : Right_Vector) return Result_Vector;
249 -----------------------------------------
250 -- Scalar_Matrix_Elementwise_Operation --
251 -----------------------------------------
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 <>)
259 type Result_Matrix is array (Integer range <>, Integer range <>)
261 with function Operation
263 Right : Right_Scalar) return Result_Scalar;
264 function Scalar_Matrix_Elementwise_Operation
266 Right : Right_Matrix) return Result_Matrix;
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;
281 Right : Right_Scalar) return Result_Scalar is <>;
283 (Left : Result_Scalar;
284 Right : Result_Scalar) return Result_Scalar is <>;
285 function Inner_Product
287 Right : Right_Vector) return Result_Scalar;
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;
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 <>)
314 Right : Right_Scalar) return Result_Scalar is <>;
315 function Outer_Product
317 Right : Right_Vector) return Matrix;
319 ---------------------------
320 -- Matrix_Vector_Product --
321 ---------------------------
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 <>)
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;
334 Right : Right_Scalar) return Result_Scalar is <>;
336 (Left : Result_Scalar;
337 Right : Result_Scalar) return Result_Scalar is <>;
338 function Matrix_Vector_Product
340 Right : Right_Vector) return Result_Vector;
342 ---------------------------
343 -- Vector_Matrix_Product --
344 ---------------------------
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 <>)
353 type Result_Vector is array (Integer range <>) of Result_Scalar;
354 Zero : Result_Scalar;
357 Right : Right_Scalar) return Result_Scalar is <>;
359 (Left : Result_Scalar;
360 Right : Result_Scalar) return Result_Scalar is <>;
361 function Vector_Matrix_Product
363 Right : Matrix) return Result_Vector;
365 ---------------------------
366 -- Matrix_Matrix_Product --
367 ---------------------------
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 <>)
375 type Right_Matrix is array (Integer range <>, Integer range <>)
377 type Result_Matrix is array (Integer range <>, Integer range <>)
379 Zero : Result_Scalar;
382 Right : Right_Scalar) return Result_Scalar is <>;
384 (Left : Result_Scalar;
385 Right : Result_Scalar) return Result_Scalar is <>;
386 function Matrix_Matrix_Product
388 Right : Right_Matrix) return Result_Matrix;
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);
404 type Scalar is private;
405 type Matrix is array (Integer range <>, Integer range <>) of Scalar;
406 procedure Transpose (A : Matrix; R : out Matrix);
408 -------------------------------
409 -- Update_Vector_With_Vector --
410 -------------------------------
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);
420 -------------------------------
421 -- Update_Matrix_With_Matrix --
422 -------------------------------
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);
437 type Scalar is private;
438 type Matrix is array (Integer range <>, Integer range <>) of Scalar;
443 First_1 : Integer := 1;
444 First_2 : Integer := 1) return Matrix;
451 type Scalar is private;
452 type Vector is array (Integer range <>) of Scalar;
458 First : Integer := 1) return Vector;
460 end System.Generic_Array_Operations;