3
<link rel="stylesheet" href="style.css" type="text/css">
4
<link rel="Start" href="index.html">
5
<link rel="next" href="Bigarray.Array1.html">
6
<link rel="Up" href="Bigarray.html">
7
<link title="Index of types" rel="Appendix" href="index_types.html">
8
<link title="Index of exceptions" rel="Appendix" href="index_exceptions.html">
9
<link title="Index of values" rel="Appendix" href="index_values.html">
10
<link title="Index of class attributes" rel="Appendix" href="index_attributes.html">
11
<link title="Index of class methods" rel="Appendix" href="index_methods.html">
12
<link title="Index of classes" rel="Appendix" href="index_classes.html">
13
<link title="Index of class types" rel="Appendix" href="index_class_types.html">
14
<link title="Index of modules" rel="Appendix" href="index_modules.html">
15
<link title="Index of module types" rel="Appendix" href="index_module_types.html">
16
<link title="Arg" rel="Chapter" href="Arg.html">
18
<link title="Arith_status" rel="Chapter" href="Arith_status.html">
20
<link title="Array" rel="Chapter" href="Array.html">
22
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
24
<link title="Big_int" rel="Chapter" href="Big_int.html">
26
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
28
<link title="Buffer" rel="Chapter" href="Buffer.html">
30
<link title="Callback" rel="Chapter" href="Callback.html">
32
<link title="Char" rel="Chapter" href="Char.html">
34
<link title="Condition" rel="Chapter" href="Condition.html">
36
<link title="Dbm" rel="Chapter" href="Dbm.html">
38
<link title="Digest" rel="Chapter" href="Digest.html">
40
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
42
<link title="Event" rel="Chapter" href="Event.html">
44
<link title="Filename" rel="Chapter" href="Filename.html">
46
<link title="Format" rel="Chapter" href="Format.html">
48
<link title="Gc" rel="Chapter" href="Gc.html">
50
<link title="Genlex" rel="Chapter" href="Genlex.html">
52
<link title="Graphics" rel="Chapter" href="Graphics.html">
54
<link title="GraphicsX11" rel="Chapter" href="GraphicsX11.html">
56
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
58
<link title="Int32" rel="Chapter" href="Int32.html">
60
<link title="Int64" rel="Chapter" href="Int64.html">
62
<link title="Lazy" rel="Chapter" href="Lazy.html">
64
<link title="Lexing" rel="Chapter" href="Lexing.html">
66
<link title="List" rel="Chapter" href="List.html">
68
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
70
<link title="Map" rel="Chapter" href="Map.html">
72
<link title="Marshal" rel="Chapter" href="Marshal.html">
74
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
76
<link title="Mutex" rel="Chapter" href="Mutex.html">
78
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
80
<link title="Num" rel="Chapter" href="Num.html">
82
<link title="Obj" rel="Chapter" href="Obj.html">
84
<link title="Oo" rel="Chapter" href="Oo.html">
86
<link title="Parsing" rel="Chapter" href="Parsing.html">
88
<link title="Pervasives" rel="Chapter" href="Pervasives.html">
90
<link title="Printexc" rel="Chapter" href="Printexc.html">
92
<link title="Printf" rel="Chapter" href="Printf.html">
94
<link title="Queue" rel="Chapter" href="Queue.html">
96
<link title="Random" rel="Chapter" href="Random.html">
98
<link title="Set" rel="Chapter" href="Set.html">
100
<link title="Sort" rel="Chapter" href="Sort.html">
102
<link title="Stack" rel="Chapter" href="Stack.html">
104
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
106
<link title="Str" rel="Chapter" href="Str.html">
108
<link title="Stream" rel="Chapter" href="Stream.html">
110
<link title="String" rel="Chapter" href="String.html">
112
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
114
<link title="Sys" rel="Chapter" href="Sys.html">
116
<link title="Thread" rel="Chapter" href="Thread.html">
118
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
120
<link title="Tk" rel="Chapter" href="Tk.html">
122
<link title="Unix" rel="Chapter" href="Unix.html">
124
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
126
<link title="Weak" rel="Chapter" href="Weak.html">
127
<title>Bigarray.Genarray</title>
130
<div class="navbar"> <a href="Bigarray.html">Up</a>
131
<a href="Bigarray.Array1.html">Next</a>
133
<center><h1>Module <a href="type_Bigarray.Genarray.html">Bigarray.Genarray</a></h1></center>
135
<pre><span class="keyword">module</span> Genarray = <code><span class="keyword">struct</span> ... <span class="keyword">end</span> </code></pre><hr width="100%">
136
<br><code><span class="keyword">type</span> <a name="TYPEt"></a>(<code class="type">'a, 'b, 'c</code>) t </code>
138
The type <code><span class="constructor">Genarray</span>.t</code> is the type of big arrays with variable
139
numbers of dimensions. Any number of dimensions between 1 and 16
141
The three type parameters to <code><span class="constructor">Genarray</span>.t</code> identify the array element
142
kind and layout, as follows:<ul>
143
<li>the first parameter, <code><span class="keywordsign">'</span>a</code>, is the Caml type for accessing array
144
elements (<code>float</code>, <code>int</code>, <code>int32</code>, <code>int64</code>, <code>nativeint</code>);</li>
145
<li>the second parameter, <code><span class="keywordsign">'</span>b</code>, is the actual kind of array elements
146
(<code>float32_elt</code>, <code>float64_elt</code>, <code>int8_signed_elt</code>, <code>int8_unsigned_elt</code>,
148
<li>the third parameter, <code><span class="keywordsign">'</span>c</code>, identifies the array layout
149
(<code>c_layout</code> or <code>fortran_layout</code>).</li>
152
For instance, <code>(float, float32_elt, fortran_layout) <span class="constructor">Genarray</span>.t</code>
153
is the type of generic big arrays containing 32-bit floats
154
in Fortran layout; reads and writes in this array use the
155
Caml type <code>float</code>.<br>
158
<pre><span class="keyword">val</span> <a name="VALcreate"></a>create : <code class="type">('a, 'b) <a href="Bigarray.html#TYPEkind">Bigarray.kind</a> -><br> 'c <a href="Bigarray.html#TYPElayout">Bigarray.layout</a> -> int array -> ('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a></code></pre><div class="info">
159
<code><span class="constructor">Genarray</span>.create kind layout dimensions</code> returns a new big array
160
whose element kind is determined by the parameter <code>kind</code> (one of
161
<code>float32</code>, <code>float64</code>, <code>int8_signed</code>, etc) and whose layout is
162
determined by the parameter <code>layout</code> (one of <code>c_layout</code> or
163
<code>fortran_layout</code>). The <code>dimensions</code> parameter is an array of
164
integers that indicate the size of the big array in each dimension.
165
The length of <code>dimensions</code> determines the number of dimensions
167
For instance, <code><span class="constructor">Genarray</span>.create int32 c_layout [|4;6;8|]</code>
168
returns a fresh big array of 32-bit integers, in C layout,
169
having three dimensions, the three dimensions being 4, 6 and 8
171
Big arrays returned by <code><span class="constructor">Genarray</span>.create</code> are not initialized:
172
the initial values of array elements is unspecified.<br>
173
<code><span class="constructor">Genarray</span>.create</code> raises <code><span class="constructor">Invalid_arg</span></code> if the number of dimensions
174
is not in the range 1 to 16 inclusive, or if one of the dimensions
177
<pre><span class="keyword">val</span> <a name="VALnum_dims"></a>num_dims : <code class="type">('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> int</code></pre><div class="info">
178
Return the number of dimensions of the given big array.<br>
180
<pre><span class="keyword">val</span> <a name="VALnth_dim"></a>nth_dim : <code class="type">('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> int -> int</code></pre><div class="info">
181
<code><span class="constructor">Genarray</span>.nth_dim a n</code> returns the <code>n</code>-th dimension of the
182
big array <code>a</code>. The first dimension corresponds to <code>n = 0</code>;
183
the second dimension corresponds to <code>n = 1</code>; the last dimension,
184
to <code>n = <span class="constructor">Genarray</span>.num_dims a - 1</code>.
185
Raise <code><span class="constructor">Invalid_arg</span></code> if <code>n</code> is less than 0 or greater or equal than
186
<code><span class="constructor">Genarray</span>.num_dims a</code>.<br>
188
<pre><span class="keyword">val</span> <a name="VALget"></a>get : <code class="type">('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> int array -> 'a</code></pre><div class="info">
189
Read an element of a generic big array.
190
<code><span class="constructor">Genarray</span>.get a [|i1; ...; iN|]</code> returns the element of <code>a</code>
191
whose coordinates are <code>i1</code> in the first dimension, <code>i2</code> in
192
the second dimension, \ldots, <code>iN</code> in the <code><span class="constructor">N</span></code>-th dimension.<br>
193
If <code>a</code> has C layout, the coordinates must be greater or equal than 0
194
and strictly less than the corresponding dimensions of <code>a</code>.
195
If <code>a</code> has Fortran layout, the coordinates must be greater or equal
196
than 1 and less or equal than the corresponding dimensions of <code>a</code>.
197
Raise <code><span class="constructor">Invalid_arg</span></code> if the array <code>a</code> does not have exactly <code><span class="constructor">N</span></code>
198
dimensions, or if the coordinates are outside the array bounds.<br>
199
If <code><span class="constructor">N</span> > 3</code>, alternate syntax is provided: you can write
200
<code>a.{i1, i2, ..., iN}</code> instead of <code><span class="constructor">Genarray</span>.get a [|i1; ...; iN|]</code>.
201
(The syntax <code>a.{...}</code> with one, two or three coordinates is
202
reserved for accessing one-, two- and three-dimensional arrays
203
as described below.)<br>
205
<pre><span class="keyword">val</span> <a name="VALset"></a>set : <code class="type">('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> int array -> 'a -> unit</code></pre><div class="info">
206
Assign an element of a generic big array.
207
<code><span class="constructor">Genarray</span>.set a [|i1; ...; iN|] v</code> stores the value <code>v</code> in the
208
element of <code>a</code> whose coordinates are <code>i1</code> in the first dimension,
209
<code>i2</code> in the second dimension, \ldots, <code>iN</code> in the <code><span class="constructor">N</span></code>-th dimension.<br>
210
The array <code>a</code> must have exactly <code><span class="constructor">N</span></code> dimensions, and all coordinates
211
must lie inside the array bounds, as described for <code><span class="constructor">Genarray</span>.get</code>;
212
otherwise, <code><span class="constructor">Invalid_arg</span></code> is raised.<br>
213
If <code><span class="constructor">N</span> > 3</code>, alternate syntax is provided: you can write
214
<code>a.{i1, i2, ..., iN} <- v</code> instead of
215
<code><span class="constructor">Genarray</span>.set a [|i1; ...; iN|] v</code>.
216
(The syntax <code>a.{...} <- v</code> with one, two or three coordinates is
217
reserved for updating one-, two- and three-dimensional arrays
218
as described below.)<br>
220
<pre><span class="keyword">val</span> <a name="VALsub_left"></a>sub_left : <code class="type">('a, 'b, <a href="Bigarray.html#TYPEc_layout">Bigarray.c_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a> -><br> int -> int -> ('a, 'b, <a href="Bigarray.html#TYPEc_layout">Bigarray.c_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a></code></pre><div class="info">
221
Extract a sub-array of the given big array by restricting the
222
first (left-most) dimension. <code><span class="constructor">Genarray</span>.sub_left a ofs len</code>
223
returns a big array with the same number of dimensions as <code>a</code>,
224
and the same dimensions as <code>a</code>, except the first dimension,
225
which corresponds to the interval <code>[ofs ... ofs + len - 1]</code>
226
of the first dimension of <code>a</code>. No copying of elements is
227
involved: the sub-array and the original array share the same
228
storage space. In other terms, the element at coordinates
229
<code>[|i1; ...; iN|]</code> of the sub-array is identical to the
230
element at coordinates <code>[|i1+ofs; ...; iN|]</code> of the original
231
array <code>a</code>.<br>
232
<code><span class="constructor">Genarray</span>.sub_left</code> applies only to big arrays in C layout.
233
Raise <code><span class="constructor">Invalid_arg</span></code> if <code>ofs</code> and <code>len</code> do not designate
234
a valid sub-array of <code>a</code>, that is, if <code>ofs < 0</code>, or <code>len < 0</code>,
235
or <code>ofs + len > <span class="constructor">Genarray</span>.nth_dim a 0</code>.<br>
237
<pre><span class="keyword">val</span> <a name="VALsub_right"></a>sub_right : <code class="type">('a, 'b, <a href="Bigarray.html#TYPEfortran_layout">Bigarray.fortran_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a> -><br> int -> int -> ('a, 'b, <a href="Bigarray.html#TYPEfortran_layout">Bigarray.fortran_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a></code></pre><div class="info">
238
Extract a sub-array of the given big array by restricting the
239
last (right-most) dimension. <code><span class="constructor">Genarray</span>.sub_right a ofs len</code>
240
returns a big array with the same number of dimensions as <code>a</code>,
241
and the same dimensions as <code>a</code>, except the last dimension,
242
which corresponds to the interval <code>[ofs ... ofs + len - 1]</code>
243
of the last dimension of <code>a</code>. No copying of elements is
244
involved: the sub-array and the original array share the same
245
storage space. In other terms, the element at coordinates
246
<code>[|i1; ...; iN|]</code> of the sub-array is identical to the
247
element at coordinates <code>[|i1; ...; iN+ofs|]</code> of the original
248
array <code>a</code>.<br>
249
<code><span class="constructor">Genarray</span>.sub_right</code> applies only to big arrays in Fortran layout.
250
Raise <code><span class="constructor">Invalid_arg</span></code> if <code>ofs</code> and <code>len</code> do not designate
251
a valid sub-array of <code>a</code>, that is, if <code>ofs < 1</code>, or <code>len < 0</code>,
252
or <code>ofs + len > <span class="constructor">Genarray</span>.nth_dim a (<span class="constructor">Genarray</span>.num_dims a - 1)</code>.<br>
254
<pre><span class="keyword">val</span> <a name="VALslice_left"></a>slice_left : <code class="type">('a, 'b, <a href="Bigarray.html#TYPEc_layout">Bigarray.c_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a> -><br> int array -> ('a, 'b, <a href="Bigarray.html#TYPEc_layout">Bigarray.c_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a></code></pre><div class="info">
255
Extract a sub-array of lower dimension from the given big array
256
by fixing one or several of the first (left-most) coordinates.
257
<code><span class="constructor">Genarray</span>.slice_left a [|i1; ... ; iM|]</code> returns the ``slice''
258
of <code>a</code> obtained by setting the first <code><span class="constructor">M</span></code> coordinates to
259
<code>i1</code>, \ldots, <code>iM</code>. If <code>a</code> has <code><span class="constructor">N</span></code> dimensions, the slice has
260
dimension <code><span class="constructor">N</span> - <span class="constructor">M</span></code>, and the element at coordinates
261
<code>[|j1; ...; j(<span class="constructor">N</span>-<span class="constructor">M</span>)|]</code> in the slice is identical to the element
262
at coordinates <code>[|i1; ...; iM; j1; ...; j(<span class="constructor">N</span>-<span class="constructor">M</span>)|]</code> in the original
263
array <code>a</code>. No copying of elements is involved: the slice and
264
the original array share the same storage space.<br>
265
<code><span class="constructor">Genarray</span>.slice_left</code> applies only to big arrays in C layout.
266
Raise <code><span class="constructor">Invalid_arg</span></code> if <code><span class="constructor">M</span> >= <span class="constructor">N</span></code>, or if <code>[|i1; ... ; iM|]</code>
267
is outside the bounds of <code>a</code>.<br>
269
<pre><span class="keyword">val</span> <a name="VALslice_right"></a>slice_right : <code class="type">('a, 'b, <a href="Bigarray.html#TYPEfortran_layout">Bigarray.fortran_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a> -><br> int array -> ('a, 'b, <a href="Bigarray.html#TYPEfortran_layout">Bigarray.fortran_layout</a>) <a href="Bigarray.Genarray.html#TYPEt">t</a></code></pre><div class="info">
270
Extract a sub-array of lower dimension from the given big array
271
by fixing one or several of the last (right-most) coordinates.
272
<code><span class="constructor">Genarray</span>.slice_right a [|i1; ... ; iM|]</code> returns the ``slice''
273
of <code>a</code> obtained by setting the last <code><span class="constructor">M</span></code> coordinates to
274
<code>i1</code>, \ldots, <code>iM</code>. If <code>a</code> has <code><span class="constructor">N</span></code> dimensions, the slice has
275
dimension <code><span class="constructor">N</span> - <span class="constructor">M</span></code>, and the element at coordinates
276
<code>[|j1; ...; j(<span class="constructor">N</span>-<span class="constructor">M</span>)|]</code> in the slice is identical to the element
277
at coordinates <code>[|j1; ...; j(<span class="constructor">N</span>-<span class="constructor">M</span>); i1; ...; iM|]</code> in the original
278
array <code>a</code>. No copying of elements is involved: the slice and
279
the original array share the same storage space.<br>
280
<code><span class="constructor">Genarray</span>.slice_right</code> applies only to big arrays in Fortran layout.
281
Raise <code><span class="constructor">Invalid_arg</span></code> if <code><span class="constructor">M</span> >= <span class="constructor">N</span></code>, or if <code>[|i1; ... ; iM|]</code>
282
is outside the bounds of <code>a</code>.<br>
284
<pre><span class="keyword">val</span> <a name="VALblit"></a>blit : <code class="type">('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> ('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> unit</code></pre><div class="info">
285
Copy all elements of a big array in another big array.
286
<code><span class="constructor">Genarray</span>.blit src dst</code> copies all elements of <code>src</code> into
287
<code>dst</code>. Both arrays <code>src</code> and <code>dst</code> must have the same number of
288
dimensions and equal dimensions. Copying a sub-array of <code>src</code>
289
to a sub-array of <code>dst</code> can be achieved by applying <code><span class="constructor">Genarray</span>.blit</code>
290
to sub-array or slices of <code>src</code> and <code>dst</code>.<br>
292
<pre><span class="keyword">val</span> <a name="VALfill"></a>fill : <code class="type">('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a> -> 'a -> unit</code></pre><div class="info">
293
Set all elements of a big array to a given value.
294
<code><span class="constructor">Genarray</span>.fill a v</code> stores the value <code>v</code> in all elements of
295
the big array <code>a</code>. Setting only some elements of <code>a</code> to <code>v</code>
296
can be achieved by applying <code><span class="constructor">Genarray</span>.fill</code> to a sub-array
297
or a slice of <code>a</code>.<br>
299
<pre><span class="keyword">val</span> <a name="VALmap_file"></a>map_file : <code class="type"><a href="Unix.html#TYPEfile_descr">Unix.file_descr</a> -><br> ('a, 'b) <a href="Bigarray.html#TYPEkind">Bigarray.kind</a> -><br> 'c <a href="Bigarray.html#TYPElayout">Bigarray.layout</a> -> bool -> int array -> ('a, 'b, 'c) <a href="Bigarray.Genarray.html#TYPEt">t</a></code></pre><div class="info">
300
Memory mapping of a file as a big array.
301
<code><span class="constructor">Genarray</span>.map_file fd kind layout shared dims</code>
302
returns a big array of kind <code>kind</code>, layout <code>layout</code>,
303
and dimensions as specified in <code>dims</code>. The data contained in
304
this big array are the contents of the file referred to by
305
the file descriptor <code>fd</code> (as opened previously with
306
<code><span class="constructor">Unix</span>.openfile</code>, for example). If <code>shared</code> is <code><span class="keyword">true</span></code>,
307
all modifications performed on the array are reflected in
308
the file. This requires that <code>fd</code> be opened with write permissions.
309
If <code>shared</code> is <code><span class="keyword">false</span></code>, modifications performed on the array
310
are done in memory only, using copy-on-write of the modified
311
pages; the underlying file is not affected.<br>
312
<code><span class="constructor">Genarray</span>.map_file</code> is much more efficient than reading
313
the whole file in a big array, modifying that big array,
314
and writing it afterwards.<br>
315
To adjust automatically the dimensions of the big array to
316
the actual size of the file, the major dimension (that is,
317
the first dimension for an array with C layout, and the last
318
dimension for an array with Fortran layout) can be given as
319
<code>-1</code>. <code><span class="constructor">Genarray</span>.map_file</code> then determines the major dimension
320
from the size of the file. The file must contain an integral
321
number of sub-arrays as determined by the non-major dimensions,
322
otherwise <code><span class="constructor">Failure</span></code> is raised.<br>
323
If all dimensions of the big array are given, the file size is
324
matched against the size of the big array. If the file is larger
325
than the big array, only the initial portion of the file is
326
mapped to the big array. If the file is smaller than the big
327
array, the file is automatically grown to the size of the big array.
328
This requires write permissions on <code>fd</code>.<br>
b'\\ No newline at end of file'