1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
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-2009, 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 |
|
|
-- Square_Matrix_Length --
|
37 |
|
|
--------------------------
|
38 |
|
|
|
39 |
|
|
generic
|
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
|
44 |
|
|
|
45 |
|
|
----------------------------------
|
46 |
|
|
-- Vector_Elementwise_Operation --
|
47 |
|
|
----------------------------------
|
48 |
|
|
|
49 |
|
|
generic
|
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;
|
56 |
|
|
|
57 |
|
|
----------------------------------
|
58 |
|
|
-- Matrix_Elementwise_Operation --
|
59 |
|
|
----------------------------------
|
60 |
|
|
|
61 |
|
|
generic
|
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 <>)
|
66 |
|
|
of Result_Scalar;
|
67 |
|
|
with function Operation (X : X_Scalar) return Result_Scalar;
|
68 |
|
|
function Matrix_Elementwise_Operation (X : X_Matrix) return Result_Matrix;
|
69 |
|
|
|
70 |
|
|
-----------------------------------------
|
71 |
|
|
-- Vector_Vector_Elementwise_Operation --
|
72 |
|
|
-----------------------------------------
|
73 |
|
|
|
74 |
|
|
generic
|
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
|
82 |
|
|
(Left : Left_Scalar;
|
83 |
|
|
Right : Right_Scalar) return Result_Scalar;
|
84 |
|
|
function Vector_Vector_Elementwise_Operation
|
85 |
|
|
(Left : Left_Vector;
|
86 |
|
|
Right : Right_Vector) return Result_Vector;
|
87 |
|
|
|
88 |
|
|
------------------------------------------------
|
89 |
|
|
-- Vector_Vector_Scalar_Elementwise_Operation --
|
90 |
|
|
------------------------------------------------
|
91 |
|
|
|
92 |
|
|
generic
|
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
|
101 |
|
|
(X : X_Scalar;
|
102 |
|
|
Y : Y_Scalar;
|
103 |
|
|
Z : Z_Scalar) return Result_Scalar;
|
104 |
|
|
function Vector_Vector_Scalar_Elementwise_Operation
|
105 |
|
|
(X : X_Vector;
|
106 |
|
|
Y : Y_Vector;
|
107 |
|
|
Z : Z_Scalar) return Result_Vector;
|
108 |
|
|
|
109 |
|
|
-----------------------------------------
|
110 |
|
|
-- Matrix_Matrix_Elementwise_Operation --
|
111 |
|
|
-----------------------------------------
|
112 |
|
|
|
113 |
|
|
generic
|
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 <>)
|
118 |
|
|
of Left_Scalar;
|
119 |
|
|
type Right_Matrix is array (Integer range <>, Integer range <>)
|
120 |
|
|
of Right_Scalar;
|
121 |
|
|
type Result_Matrix is array (Integer range <>, Integer range <>)
|
122 |
|
|
of Result_Scalar;
|
123 |
|
|
with function Operation
|
124 |
|
|
(Left : Left_Scalar;
|
125 |
|
|
Right : Right_Scalar) return Result_Scalar;
|
126 |
|
|
function Matrix_Matrix_Elementwise_Operation
|
127 |
|
|
(Left : Left_Matrix;
|
128 |
|
|
Right : Right_Matrix) return Result_Matrix;
|
129 |
|
|
|
130 |
|
|
------------------------------------------------
|
131 |
|
|
-- Matrix_Matrix_Scalar_Elementwise_Operation --
|
132 |
|
|
------------------------------------------------
|
133 |
|
|
|
134 |
|
|
generic
|
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 <>)
|
142 |
|
|
of Result_Scalar;
|
143 |
|
|
with function Operation
|
144 |
|
|
(X : X_Scalar;
|
145 |
|
|
Y : Y_Scalar;
|
146 |
|
|
Z : Z_Scalar) return Result_Scalar;
|
147 |
|
|
function Matrix_Matrix_Scalar_Elementwise_Operation
|
148 |
|
|
(X : X_Matrix;
|
149 |
|
|
Y : Y_Matrix;
|
150 |
|
|
Z : Z_Scalar) return Result_Matrix;
|
151 |
|
|
|
152 |
|
|
-----------------------------------------
|
153 |
|
|
-- Vector_Scalar_Elementwise_Operation --
|
154 |
|
|
-----------------------------------------
|
155 |
|
|
|
156 |
|
|
generic
|
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
|
163 |
|
|
(Left : Left_Scalar;
|
164 |
|
|
Right : Right_Scalar) return Result_Scalar;
|
165 |
|
|
function Vector_Scalar_Elementwise_Operation
|
166 |
|
|
(Left : Left_Vector;
|
167 |
|
|
Right : Right_Scalar) return Result_Vector;
|
168 |
|
|
|
169 |
|
|
-----------------------------------------
|
170 |
|
|
-- Matrix_Scalar_Elementwise_Operation --
|
171 |
|
|
-----------------------------------------
|
172 |
|
|
|
173 |
|
|
generic
|
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 <>)
|
178 |
|
|
of Left_Scalar;
|
179 |
|
|
type Result_Matrix is array (Integer range <>, Integer range <>)
|
180 |
|
|
of Result_Scalar;
|
181 |
|
|
with function Operation
|
182 |
|
|
(Left : Left_Scalar;
|
183 |
|
|
Right : Right_Scalar) return Result_Scalar;
|
184 |
|
|
function Matrix_Scalar_Elementwise_Operation
|
185 |
|
|
(Left : Left_Matrix;
|
186 |
|
|
Right : Right_Scalar) return Result_Matrix;
|
187 |
|
|
|
188 |
|
|
-----------------------------------------
|
189 |
|
|
-- Scalar_Vector_Elementwise_Operation --
|
190 |
|
|
-----------------------------------------
|
191 |
|
|
|
192 |
|
|
generic
|
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
|
199 |
|
|
(Left : Left_Scalar;
|
200 |
|
|
Right : Right_Scalar) return Result_Scalar;
|
201 |
|
|
function Scalar_Vector_Elementwise_Operation
|
202 |
|
|
(Left : Left_Scalar;
|
203 |
|
|
Right : Right_Vector) return Result_Vector;
|
204 |
|
|
|
205 |
|
|
-----------------------------------------
|
206 |
|
|
-- Scalar_Matrix_Elementwise_Operation --
|
207 |
|
|
-----------------------------------------
|
208 |
|
|
|
209 |
|
|
generic
|
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 <>)
|
214 |
|
|
of Right_Scalar;
|
215 |
|
|
type Result_Matrix is array (Integer range <>, Integer range <>)
|
216 |
|
|
of Result_Scalar;
|
217 |
|
|
with function Operation
|
218 |
|
|
(Left : Left_Scalar;
|
219 |
|
|
Right : Right_Scalar) return Result_Scalar;
|
220 |
|
|
function Scalar_Matrix_Elementwise_Operation
|
221 |
|
|
(Left : Left_Scalar;
|
222 |
|
|
Right : Right_Matrix) return Result_Matrix;
|
223 |
|
|
|
224 |
|
|
-------------------
|
225 |
|
|
-- Inner_Product --
|
226 |
|
|
-------------------
|
227 |
|
|
|
228 |
|
|
generic
|
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;
|
235 |
|
|
with function "*"
|
236 |
|
|
(Left : Left_Scalar;
|
237 |
|
|
Right : Right_Scalar) return Result_Scalar is <>;
|
238 |
|
|
with function "+"
|
239 |
|
|
(Left : Result_Scalar;
|
240 |
|
|
Right : Result_Scalar) return Result_Scalar is <>;
|
241 |
|
|
function Inner_Product
|
242 |
|
|
(Left : Left_Vector;
|
243 |
|
|
Right : Right_Vector) return Result_Scalar;
|
244 |
|
|
|
245 |
|
|
-------------------
|
246 |
|
|
-- Outer_Product --
|
247 |
|
|
-------------------
|
248 |
|
|
|
249 |
|
|
generic
|
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 <>)
|
256 |
|
|
of Result_Scalar;
|
257 |
|
|
with function "*"
|
258 |
|
|
(Left : Left_Scalar;
|
259 |
|
|
Right : Right_Scalar) return Result_Scalar is <>;
|
260 |
|
|
function Outer_Product
|
261 |
|
|
(Left : Left_Vector;
|
262 |
|
|
Right : Right_Vector) return Matrix;
|
263 |
|
|
|
264 |
|
|
---------------------------
|
265 |
|
|
-- Matrix_Vector_Product --
|
266 |
|
|
---------------------------
|
267 |
|
|
|
268 |
|
|
generic
|
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 <>)
|
273 |
|
|
of Left_Scalar;
|
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;
|
277 |
|
|
with function "*"
|
278 |
|
|
(Left : Left_Scalar;
|
279 |
|
|
Right : Right_Scalar) return Result_Scalar is <>;
|
280 |
|
|
with function "+"
|
281 |
|
|
(Left : Result_Scalar;
|
282 |
|
|
Right : Result_Scalar) return Result_Scalar is <>;
|
283 |
|
|
function Matrix_Vector_Product
|
284 |
|
|
(Left : Matrix;
|
285 |
|
|
Right : Right_Vector) return Result_Vector;
|
286 |
|
|
|
287 |
|
|
---------------------------
|
288 |
|
|
-- Vector_Matrix_Product --
|
289 |
|
|
---------------------------
|
290 |
|
|
|
291 |
|
|
generic
|
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 <>)
|
297 |
|
|
of Right_Scalar;
|
298 |
|
|
type Result_Vector is array (Integer range <>) of Result_Scalar;
|
299 |
|
|
Zero : Result_Scalar;
|
300 |
|
|
with function "*"
|
301 |
|
|
(Left : Left_Scalar;
|
302 |
|
|
Right : Right_Scalar) return Result_Scalar is <>;
|
303 |
|
|
with function "+"
|
304 |
|
|
(Left : Result_Scalar;
|
305 |
|
|
Right : Result_Scalar) return Result_Scalar is <>;
|
306 |
|
|
function Vector_Matrix_Product
|
307 |
|
|
(Left : Left_Vector;
|
308 |
|
|
Right : Matrix) return Result_Vector;
|
309 |
|
|
|
310 |
|
|
---------------------------
|
311 |
|
|
-- Matrix_Matrix_Product --
|
312 |
|
|
---------------------------
|
313 |
|
|
|
314 |
|
|
generic
|
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 <>)
|
319 |
|
|
of Left_Scalar;
|
320 |
|
|
type Right_Matrix is array (Integer range <>, Integer range <>)
|
321 |
|
|
of Right_Scalar;
|
322 |
|
|
type Result_Matrix is array (Integer range <>, Integer range <>)
|
323 |
|
|
of Result_Scalar;
|
324 |
|
|
Zero : Result_Scalar;
|
325 |
|
|
with function "*"
|
326 |
|
|
(Left : Left_Scalar;
|
327 |
|
|
Right : Right_Scalar) return Result_Scalar is <>;
|
328 |
|
|
with function "+"
|
329 |
|
|
(Left : Result_Scalar;
|
330 |
|
|
Right : Result_Scalar) return Result_Scalar is <>;
|
331 |
|
|
function Matrix_Matrix_Product
|
332 |
|
|
(Left : Left_Matrix;
|
333 |
|
|
Right : Right_Matrix) return Result_Matrix;
|
334 |
|
|
|
335 |
|
|
---------------
|
336 |
|
|
-- Transpose --
|
337 |
|
|
---------------
|
338 |
|
|
|
339 |
|
|
generic
|
340 |
|
|
type Scalar is private;
|
341 |
|
|
type Matrix is array (Integer range <>, Integer range <>) of Scalar;
|
342 |
|
|
procedure Transpose (A : Matrix; R : out Matrix);
|
343 |
|
|
|
344 |
|
|
-------------------------------
|
345 |
|
|
-- Update_Vector_With_Vector --
|
346 |
|
|
-------------------------------
|
347 |
|
|
|
348 |
|
|
generic
|
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);
|
355 |
|
|
|
356 |
|
|
-------------------------------
|
357 |
|
|
-- Update_Matrix_With_Matrix --
|
358 |
|
|
-------------------------------
|
359 |
|
|
|
360 |
|
|
generic
|
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);
|
367 |
|
|
|
368 |
|
|
-----------------
|
369 |
|
|
-- Unit_Matrix --
|
370 |
|
|
-----------------
|
371 |
|
|
|
372 |
|
|
generic
|
373 |
|
|
type Scalar is private;
|
374 |
|
|
type Matrix is array (Integer range <>, Integer range <>) of Scalar;
|
375 |
|
|
Zero : Scalar;
|
376 |
|
|
One : Scalar;
|
377 |
|
|
function Unit_Matrix
|
378 |
|
|
(Order : Positive;
|
379 |
|
|
First_1 : Integer := 1;
|
380 |
|
|
First_2 : Integer := 1) return Matrix;
|
381 |
|
|
|
382 |
|
|
-----------------
|
383 |
|
|
-- Unit_Vector --
|
384 |
|
|
-----------------
|
385 |
|
|
|
386 |
|
|
generic
|
387 |
|
|
type Scalar is private;
|
388 |
|
|
type Vector is array (Integer range <>) of Scalar;
|
389 |
|
|
Zero : Scalar;
|
390 |
|
|
One : Scalar;
|
391 |
|
|
function Unit_Vector
|
392 |
|
|
(Index : Integer;
|
393 |
|
|
Order : Positive;
|
394 |
|
|
First : Integer := 1) return Vector;
|
395 |
|
|
|
396 |
|
|
end System.Generic_Array_Operations;
|