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-2009, 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
);
35 --------------------------
36 -- Square_Matrix_Length --
37 --------------------------
40 type Scalar
is private;
41 type Matrix
is array (Integer range <>, Integer range <>) of Scalar
;
42 function Square_Matrix_Length
(A
: Matrix
) return Natural;
43 -- If A is non-square, raise Constraint_Error, else return its dimension
45 ----------------------------------
46 -- Vector_Elementwise_Operation --
47 ----------------------------------
50 type X_Scalar
is private;
51 type Result_Scalar
is private;
52 type X_Vector
is array (Integer range <>) of X_Scalar
;
53 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
54 with function Operation
(X
: X_Scalar
) return Result_Scalar
;
55 function Vector_Elementwise_Operation
(X
: X_Vector
) return Result_Vector
;
57 ----------------------------------
58 -- Matrix_Elementwise_Operation --
59 ----------------------------------
62 type X_Scalar
is private;
63 type Result_Scalar
is private;
64 type X_Matrix
is array (Integer range <>, Integer range <>) of X_Scalar
;
65 type Result_Matrix
is array (Integer range <>, Integer range <>)
67 with function Operation
(X
: X_Scalar
) return Result_Scalar
;
68 function Matrix_Elementwise_Operation
(X
: X_Matrix
) return Result_Matrix
;
70 -----------------------------------------
71 -- Vector_Vector_Elementwise_Operation --
72 -----------------------------------------
75 type Left_Scalar
is private;
76 type Right_Scalar
is private;
77 type Result_Scalar
is private;
78 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
79 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
80 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
81 with function Operation
83 Right
: Right_Scalar
) return Result_Scalar
;
84 function Vector_Vector_Elementwise_Operation
86 Right
: Right_Vector
) return Result_Vector
;
88 ------------------------------------------------
89 -- Vector_Vector_Scalar_Elementwise_Operation --
90 ------------------------------------------------
93 type X_Scalar
is private;
94 type Y_Scalar
is private;
95 type Z_Scalar
is private;
96 type Result_Scalar
is private;
97 type X_Vector
is array (Integer range <>) of X_Scalar
;
98 type Y_Vector
is array (Integer range <>) of Y_Scalar
;
99 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
100 with function Operation
103 Z
: Z_Scalar
) return Result_Scalar
;
104 function Vector_Vector_Scalar_Elementwise_Operation
107 Z
: Z_Scalar
) return Result_Vector
;
109 -----------------------------------------
110 -- Matrix_Matrix_Elementwise_Operation --
111 -----------------------------------------
114 type Left_Scalar
is private;
115 type Right_Scalar
is private;
116 type Result_Scalar
is private;
117 type Left_Matrix
is array (Integer range <>, Integer range <>)
119 type Right_Matrix
is array (Integer range <>, Integer range <>)
121 type Result_Matrix
is array (Integer range <>, Integer range <>)
123 with function Operation
125 Right
: Right_Scalar
) return Result_Scalar
;
126 function Matrix_Matrix_Elementwise_Operation
128 Right
: Right_Matrix
) return Result_Matrix
;
130 ------------------------------------------------
131 -- Matrix_Matrix_Scalar_Elementwise_Operation --
132 ------------------------------------------------
135 type X_Scalar
is private;
136 type Y_Scalar
is private;
137 type Z_Scalar
is private;
138 type Result_Scalar
is private;
139 type X_Matrix
is array (Integer range <>, Integer range <>) of X_Scalar
;
140 type Y_Matrix
is array (Integer range <>, Integer range <>) of Y_Scalar
;
141 type Result_Matrix
is array (Integer range <>, Integer range <>)
143 with function Operation
146 Z
: Z_Scalar
) return Result_Scalar
;
147 function Matrix_Matrix_Scalar_Elementwise_Operation
150 Z
: Z_Scalar
) return Result_Matrix
;
152 -----------------------------------------
153 -- Vector_Scalar_Elementwise_Operation --
154 -----------------------------------------
157 type Left_Scalar
is private;
158 type Right_Scalar
is private;
159 type Result_Scalar
is private;
160 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
161 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
162 with function Operation
164 Right
: Right_Scalar
) return Result_Scalar
;
165 function Vector_Scalar_Elementwise_Operation
167 Right
: Right_Scalar
) return Result_Vector
;
169 -----------------------------------------
170 -- Matrix_Scalar_Elementwise_Operation --
171 -----------------------------------------
174 type Left_Scalar
is private;
175 type Right_Scalar
is private;
176 type Result_Scalar
is private;
177 type Left_Matrix
is array (Integer range <>, Integer range <>)
179 type Result_Matrix
is array (Integer range <>, Integer range <>)
181 with function Operation
183 Right
: Right_Scalar
) return Result_Scalar
;
184 function Matrix_Scalar_Elementwise_Operation
186 Right
: Right_Scalar
) return Result_Matrix
;
188 -----------------------------------------
189 -- Scalar_Vector_Elementwise_Operation --
190 -----------------------------------------
193 type Left_Scalar
is private;
194 type Right_Scalar
is private;
195 type Result_Scalar
is private;
196 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
197 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
198 with function Operation
200 Right
: Right_Scalar
) return Result_Scalar
;
201 function Scalar_Vector_Elementwise_Operation
203 Right
: Right_Vector
) return Result_Vector
;
205 -----------------------------------------
206 -- Scalar_Matrix_Elementwise_Operation --
207 -----------------------------------------
210 type Left_Scalar
is private;
211 type Right_Scalar
is private;
212 type Result_Scalar
is private;
213 type Right_Matrix
is array (Integer range <>, Integer range <>)
215 type Result_Matrix
is array (Integer range <>, Integer range <>)
217 with function Operation
219 Right
: Right_Scalar
) return Result_Scalar
;
220 function Scalar_Matrix_Elementwise_Operation
222 Right
: Right_Matrix
) return Result_Matrix
;
229 type Left_Scalar
is private;
230 type Right_Scalar
is private;
231 type Result_Scalar
is private;
232 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
233 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
234 Zero
: Result_Scalar
;
237 Right
: Right_Scalar
) return Result_Scalar
is <>;
239 (Left
: Result_Scalar
;
240 Right
: Result_Scalar
) return Result_Scalar
is <>;
241 function Inner_Product
243 Right
: Right_Vector
) return Result_Scalar
;
250 type Left_Scalar
is private;
251 type Right_Scalar
is private;
252 type Result_Scalar
is private;
253 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
254 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
255 type Matrix
is array (Integer range <>, Integer range <>)
259 Right
: Right_Scalar
) return Result_Scalar
is <>;
260 function Outer_Product
262 Right
: Right_Vector
) return Matrix
;
264 ---------------------------
265 -- Matrix_Vector_Product --
266 ---------------------------
269 type Left_Scalar
is private;
270 type Right_Scalar
is private;
271 type Result_Scalar
is private;
272 type Matrix
is array (Integer range <>, Integer range <>)
274 type Right_Vector
is array (Integer range <>) of Right_Scalar
;
275 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
276 Zero
: Result_Scalar
;
279 Right
: Right_Scalar
) return Result_Scalar
is <>;
281 (Left
: Result_Scalar
;
282 Right
: Result_Scalar
) return Result_Scalar
is <>;
283 function Matrix_Vector_Product
285 Right
: Right_Vector
) return Result_Vector
;
287 ---------------------------
288 -- Vector_Matrix_Product --
289 ---------------------------
292 type Left_Scalar
is private;
293 type Right_Scalar
is private;
294 type Result_Scalar
is private;
295 type Left_Vector
is array (Integer range <>) of Left_Scalar
;
296 type Matrix
is array (Integer range <>, Integer range <>)
298 type Result_Vector
is array (Integer range <>) of Result_Scalar
;
299 Zero
: Result_Scalar
;
302 Right
: Right_Scalar
) return Result_Scalar
is <>;
304 (Left
: Result_Scalar
;
305 Right
: Result_Scalar
) return Result_Scalar
is <>;
306 function Vector_Matrix_Product
308 Right
: Matrix
) return Result_Vector
;
310 ---------------------------
311 -- Matrix_Matrix_Product --
312 ---------------------------
315 type Left_Scalar
is private;
316 type Right_Scalar
is private;
317 type Result_Scalar
is private;
318 type Left_Matrix
is array (Integer range <>, Integer range <>)
320 type Right_Matrix
is array (Integer range <>, Integer range <>)
322 type Result_Matrix
is array (Integer range <>, Integer range <>)
324 Zero
: Result_Scalar
;
327 Right
: Right_Scalar
) return Result_Scalar
is <>;
329 (Left
: Result_Scalar
;
330 Right
: Result_Scalar
) return Result_Scalar
is <>;
331 function Matrix_Matrix_Product
333 Right
: Right_Matrix
) return Result_Matrix
;
340 type Scalar
is private;
341 type Matrix
is array (Integer range <>, Integer range <>) of Scalar
;
342 procedure Transpose
(A
: Matrix
; R
: out Matrix
);
344 -------------------------------
345 -- Update_Vector_With_Vector --
346 -------------------------------
349 type X_Scalar
is private;
350 type Y_Scalar
is private;
351 type X_Vector
is array (Integer range <>) of X_Scalar
;
352 type Y_Vector
is array (Integer range <>) of Y_Scalar
;
353 with procedure Update
(X
: in out X_Scalar
; Y
: Y_Scalar
);
354 procedure Update_Vector_With_Vector
(X
: in out X_Vector
; Y
: Y_Vector
);
356 -------------------------------
357 -- Update_Matrix_With_Matrix --
358 -------------------------------
361 type X_Scalar
is private;
362 type Y_Scalar
is private;
363 type X_Matrix
is array (Integer range <>, Integer range <>) of X_Scalar
;
364 type Y_Matrix
is array (Integer range <>, Integer range <>) of Y_Scalar
;
365 with procedure Update
(X
: in out X_Scalar
; Y
: Y_Scalar
);
366 procedure Update_Matrix_With_Matrix
(X
: in out X_Matrix
; Y
: Y_Matrix
);
373 type Scalar
is private;
374 type Matrix
is array (Integer range <>, Integer range <>) of Scalar
;
379 First_1
: Integer := 1;
380 First_2
: Integer := 1) return Matrix
;
387 type Scalar
is private;
388 type Vector
is array (Integer range <>) of Scalar
;
394 First
: Integer := 1) return Vector
;
396 end System
.Generic_Array_Operations
;