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-2007, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 package System
.Generic_Array_Operations
is
35 pragma Pure
(Generic_Array_Operations
);
37 --------------------------
38 -- Square_Matrix_Length --
39 --------------------------
42 type Scalar
is private;
43 type Matrix
is array (Integer range <>, Integer range <>) of Scalar
;
44 function Square_Matrix_Length
(A
: Matrix
) return Natural;
45 -- If A is non-square, raise Constraint_Error, else return its dimension
47 ----------------------------------
48 -- Vector_Elementwise_Operation --
49 ----------------------------------
52 type X_Scalar
is private;
53 type Result_Scalar
is private;
54 type X_Vector
is array (Integer range <>) of X_Scalar
;
55 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
56 with function Operation
(X
: X_Scalar
) return Result_Scalar
;
57 function Vector_Elementwise_Operation
(X
: X_Vector
) return Result_Vector
;
59 ----------------------------------
60 -- Matrix_Elementwise_Operation --
61 ----------------------------------
64 type X_Scalar
is private;
65 type Result_Scalar
is private;
66 type X_Matrix
is array (Integer range <>, Integer range <>) of X_Scalar
;
67 type Result_Matrix
is array (Integer range <>, Integer range <>)
69 with function Operation
(X
: X_Scalar
) return Result_Scalar
;
70 function Matrix_Elementwise_Operation
(X
: X_Matrix
) return Result_Matrix
;
72 -----------------------------------------
73 -- Vector_Vector_Elementwise_Operation --
74 -----------------------------------------
77 type Left_Scalar
is private;
78 type Right_Scalar
is private;
79 type Result_Scalar
is private;
80 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
81 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
82 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
83 with function Operation
85 Right
: Right_Scalar
) return Result_Scalar
;
86 function Vector_Vector_Elementwise_Operation
88 Right
: Right_Vector
) return Result_Vector
;
90 ------------------------------------------------
91 -- Vector_Vector_Scalar_Elementwise_Operation --
92 ------------------------------------------------
95 type X_Scalar
is private;
96 type Y_Scalar
is private;
97 type Z_Scalar
is private;
98 type Result_Scalar
is private;
99 type X_Vector
is array (Integer range <>) of X_Scalar
;
100 type Y_Vector
is array (Integer range <>) of Y_Scalar
;
101 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
102 with function Operation
105 Z
: Z_Scalar
) return Result_Scalar
;
106 function Vector_Vector_Scalar_Elementwise_Operation
109 Z
: Z_Scalar
) return Result_Vector
;
111 -----------------------------------------
112 -- Matrix_Matrix_Elementwise_Operation --
113 -----------------------------------------
116 type Left_Scalar
is private;
117 type Right_Scalar
is private;
118 type Result_Scalar
is private;
119 type Left_Matrix
is array (Integer range <>, Integer range <>)
121 type Right_Matrix
is array (Integer range <>, Integer range <>)
123 type Result_Matrix
is array (Integer range <>, Integer range <>)
125 with function Operation
127 Right
: Right_Scalar
) return Result_Scalar
;
128 function Matrix_Matrix_Elementwise_Operation
130 Right
: Right_Matrix
) return Result_Matrix
;
132 ------------------------------------------------
133 -- Matrix_Matrix_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_Matrix
is array (Integer range <>, Integer range <>) of X_Scalar
;
142 type Y_Matrix
is array (Integer range <>, Integer range <>) of Y_Scalar
;
143 type Result_Matrix
is array (Integer range <>, Integer range <>)
145 with function Operation
148 Z
: Z_Scalar
) return Result_Scalar
;
149 function Matrix_Matrix_Scalar_Elementwise_Operation
152 Z
: Z_Scalar
) return Result_Matrix
;
154 -----------------------------------------
155 -- Vector_Scalar_Elementwise_Operation --
156 -----------------------------------------
159 type Left_Scalar
is private;
160 type Right_Scalar
is private;
161 type Result_Scalar
is private;
162 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
163 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
164 with function Operation
166 Right
: Right_Scalar
) return Result_Scalar
;
167 function Vector_Scalar_Elementwise_Operation
169 Right
: Right_Scalar
) return Result_Vector
;
171 -----------------------------------------
172 -- Matrix_Scalar_Elementwise_Operation --
173 -----------------------------------------
176 type Left_Scalar
is private;
177 type Right_Scalar
is private;
178 type Result_Scalar
is private;
179 type Left_Matrix
is array (Integer range <>, Integer range <>)
181 type Result_Matrix
is array (Integer range <>, Integer range <>)
183 with function Operation
185 Right
: Right_Scalar
) return Result_Scalar
;
186 function Matrix_Scalar_Elementwise_Operation
188 Right
: Right_Scalar
) return Result_Matrix
;
190 -----------------------------------------
191 -- Scalar_Vector_Elementwise_Operation --
192 -----------------------------------------
195 type Left_Scalar
is private;
196 type Right_Scalar
is private;
197 type Result_Scalar
is private;
198 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
199 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
200 with function Operation
202 Right
: Right_Scalar
) return Result_Scalar
;
203 function Scalar_Vector_Elementwise_Operation
205 Right
: Right_Vector
) return Result_Vector
;
207 -----------------------------------------
208 -- Scalar_Matrix_Elementwise_Operation --
209 -----------------------------------------
212 type Left_Scalar
is private;
213 type Right_Scalar
is private;
214 type Result_Scalar
is private;
215 type Right_Matrix
is array (Integer range <>, Integer range <>)
217 type Result_Matrix
is array (Integer range <>, Integer range <>)
219 with function Operation
221 Right
: Right_Scalar
) return Result_Scalar
;
222 function Scalar_Matrix_Elementwise_Operation
224 Right
: Right_Matrix
) return Result_Matrix
;
231 type Left_Scalar
is private;
232 type Right_Scalar
is private;
233 type Result_Scalar
is private;
234 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
235 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
236 Zero
: Result_Scalar
;
239 Right
: Right_Scalar
) return Result_Scalar
is <>;
241 (Left
: Result_Scalar
;
242 Right
: Result_Scalar
) return Result_Scalar
is <>;
243 function Inner_Product
245 Right
: Right_Vector
) return Result_Scalar
;
252 type Left_Scalar
is private;
253 type Right_Scalar
is private;
254 type Result_Scalar
is private;
255 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
256 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
257 type Matrix
is array (Integer range <>, Integer range <>)
261 Right
: Right_Scalar
) return Result_Scalar
is <>;
262 function Outer_Product
264 Right
: Right_Vector
) return Matrix
;
266 ---------------------------
267 -- Matrix_Vector_Product --
268 ---------------------------
271 type Left_Scalar
is private;
272 type Right_Scalar
is private;
273 type Result_Scalar
is private;
274 type Matrix
is array (Integer range <>, Integer range <>)
276 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
277 type Result_Vector
is array (Integer range <>) of Result_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 Matrix_Vector_Product
287 Right
: Right_Vector
) return Result_Vector
;
289 ---------------------------
290 -- Vector_Matrix_Product --
291 ---------------------------
294 type Left_Scalar
is private;
295 type Right_Scalar
is private;
296 type Result_Scalar
is private;
297 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
298 type Matrix
is array (Integer range <>, Integer range <>)
300 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
301 Zero
: Result_Scalar
;
304 Right
: Right_Scalar
) return Result_Scalar
is <>;
306 (Left
: Result_Scalar
;
307 Right
: Result_Scalar
) return Result_Scalar
is <>;
308 function Vector_Matrix_Product
310 Right
: Matrix
) return Result_Vector
;
312 ---------------------------
313 -- Matrix_Matrix_Product --
314 ---------------------------
317 type Left_Scalar
is private;
318 type Right_Scalar
is private;
319 type Result_Scalar
is private;
320 type Left_Matrix
is array (Integer range <>, Integer range <>)
322 type Right_Matrix
is array (Integer range <>, Integer range <>)
324 type Result_Matrix
is array (Integer range <>, Integer range <>)
326 Zero
: Result_Scalar
;
329 Right
: Right_Scalar
) return Result_Scalar
is <>;
331 (Left
: Result_Scalar
;
332 Right
: Result_Scalar
) return Result_Scalar
is <>;
333 function Matrix_Matrix_Product
335 Right
: Right_Matrix
) return Result_Matrix
;
342 type Scalar
is private;
343 type Matrix
is array (Integer range <>, Integer range <>) of Scalar
;
344 procedure Transpose
(A
: Matrix
; R
: out Matrix
);
346 -------------------------------
347 -- Update_Vector_With_Vector --
348 -------------------------------
351 type X_Scalar
is private;
352 type Y_Scalar
is private;
353 type X_Vector
is array (Integer range <>) of X_Scalar
;
354 type Y_Vector
is array (Integer range <>) of Y_Scalar
;
355 with procedure Update
(X
: in out X_Scalar
; Y
: Y_Scalar
);
356 procedure Update_Vector_With_Vector
(X
: in out X_Vector
; Y
: Y_Vector
);
358 -------------------------------
359 -- Update_Matrix_With_Matrix --
360 -------------------------------
363 type X_Scalar
is private;
364 type Y_Scalar
is private;
365 type X_Matrix
is array (Integer range <>, Integer range <>) of X_Scalar
;
366 type Y_Matrix
is array (Integer range <>, Integer range <>) of Y_Scalar
;
367 with procedure Update
(X
: in out X_Scalar
; Y
: Y_Scalar
);
368 procedure Update_Matrix_With_Matrix
(X
: in out X_Matrix
; Y
: Y_Matrix
);
375 type Scalar
is private;
376 type Matrix
is array (Integer range <>, Integer range <>) of Scalar
;
381 First_1
: Integer := 1;
382 First_2
: Integer := 1) return Matrix
;
389 type Scalar
is private;
390 type Vector
is array (Integer range <>) of Scalar
;
396 First
: Integer := 1) return Vector
;
398 end System
.Generic_Array_Operations
;