Bigarray.Array2(3)
โจ Bigarray.Array2 โจ
okay so bestie, this is the Bigarray.Array2 page straight out of the OCaml library manual (section 3, iykyk) โ and it's literally the whole glow-up of two-dimensional arrays ๐ฆ
๐ NAME ๐
Bigarray.Array2 โ two-dimensional arrays. that's it, that's the vibe ๐
๐งฉ Module ๐งฉ
Module Bigarray.Array2
๐ Documentation ๐
Module Array2 : sig end
Two-dimensional arrays, bestie!! The Array2 structure gives you operations similar to the ones in Bigarray.Genarray, except highkey specialized to the case where your array is two-dimensional. same energy, just locked in for 2D ๐ฅ
๐ธ type (!'a, !'b, !'c) t
The type of two-dimensional Bigarrays whose elements have OCaml type 'a, representation kind 'b, and memory layout 'c. three little type params, one iconic array ๐
๐ซถ val create
val create : ('a, 'b) Bigarray.kind -> 'c Bigarray.layout -> int -> int
-> ('a, 'b, 'c) t
Array2.create kind layout dim1 dim2 returns a new Bigarray of two dimensions, whose size is dim1 in the first dimension and dim2 in the second dimension. kind and layout decide the array element kind and the array layout, exactly as described for Bigarray.Genarray.create. no cap, it's giving "just make me a 2D array already" โจ
๐ง val init
val init : ('a, 'b) Bigarray.kind -> 'c Bigarray.layout -> int -> int ->
(int -> int -> 'a) -> ('a, 'b, 'c) t
Array2.init kind layout dim1 dim2 f returns a new Bigarray b of two dimensions, whose size is dim2 in the first dimension and dim2 in the second dimension. kind and layout decide the array element kind and the array layout as described for Bigarray.Genarray.create.
real talk: the docs literally say dim2 for both dimensions up there โ i'm just reading it to you, don't come for me ๐ญ๐
Each element Array2.get b i j of the array gets initialized to the result of f i j.
In other words (and this part is kinda slay), Array2.init kind layout dim1 dim2 f tabulates the results of f applied to the indices of a brand-new Bigarray whose layout is described by kind, layout, dim1 and dim2. it's literally a tabulation main character ๐
Since 4.12
๐ฆ val dim1
val dim1 : ('a, 'b, 'c) t -> int
Returns the first dimension of the given two-dimensional Bigarray. the OG dimension ๐
๐ฆ val dim2
val dim2 : ('a, 'b, 'c) t -> int
Returns the second dimension of the given two-dimensional Bigarray. the sequel dimension, we love a part two ๐
โญ val kind
val kind : ('a, 'b, 'c) t -> ('a, 'b) Bigarray.kind
Returns the kind of the given Bigarray. tell me what you are bestie ๐
๐ val layout
val layout : ('a, 'b, 'c) t -> 'c Bigarray.layout
Returns the layout of the given Bigarray. C-layout girlie or Fortran-layout girlie, no judgment either way ๐ซถ
๐ฅ val change_layout
val change_layout : ('a, 'b, 'c) t -> 'd Bigarray.layout -> ('a, 'b, 'd)
t
Array2.change_layout a layout returns a Bigarray with the specified layout, sharing the data with a (and hence having the same dimensions as a). No copying of elements is involved: the new array and the original array share the same storage space โ they're literally sharing a brain, obsessed ๐ฏโโ๏ธ
The dimensions are reversed, such that get v [| a; b |] in C layout becomes get v [| b+1; a+1 |] in Fortran layout. keep that exact swap in mind or you will get got ๐
Since 4.06
๐ val size_in_bytes
val size_in_bytes : ('a, 'b, 'c) t -> int
size_in_bytes a is the number of elements in a multiplied by a's Bigarray.kind_size_in_bytes. math girlies rise ๐งฎโจ
Since 4.03
๐ val get
val get : ('a, 'b, 'c) t -> int -> int -> 'a
Array2.get a x y, also written a.{x,y}, returns the element of a at coordinates (x, y). x and y must be within the bounds of a, as described for Bigarray.Genarray.get; otherwise, Invalid_argument is raised. stay in bounds or get formally rejected ๐
๐ val set
val set : ('a, 'b, 'c) t -> int -> int -> 'a -> unit
Array2.set a x y v, or alternatively a.{x,y} <- v, stores the value v at coordinates (x, y) in a. x and y must be within the bounds of a, as described for Bigarray.Genarray.set; otherwise, Invalid_argument is raised. put it in its place, respectfully ๐
๐ธ val sub_left
val sub_left : ('a, 'b, Bigarray.c_layout) t -> int -> int -> ('a, 'b,
Bigarray.c_layout) t
Extracts a two-dimensional sub-array of the given two-dimensional Bigarray by restricting the first dimension. See Bigarray.Genarray.sub_left for more details. Array2.sub_left applies only to arrays with C layout โ sorry Fortran besties, this one's not for you ๐ซ
๐ธ val sub_right
val sub_right : ('a, 'b, Bigarray.fortran_layout) t -> int -> int ->
('a', 'b, Bigarray.fortran_layout) t
Extracts a two-dimensional sub-array of the given two-dimensional Bigarray by restricting the second dimension. See Bigarray.Genarray.sub_right for more details. Array2.sub_right applies only to arrays with Fortran layout. now it's the Fortran girlies' turn ๐
heads up: the signature above is exactly what the page shows, ('a', trailing quote and all โ not me, don't shoot the messenger ๐ญ
๐ val slice_left
val slice_left : ('a, 'b, Bigarray.c_layout) t -> int -> ('a, 'b,
Bigarray.c_layout) Bigarray.Array1.t
Extracts a row (a one-dimensional slice) of the given two-dimensional Bigarray. The integer parameter is the index of the row to extract. See Bigarray.Genarray.slice_left for more details. Array2.slice_left applies only to arrays with C layout. one row, served fresh ๐
๐ val slice_right
val slice_right : ('a, 'b, Bigarray.fortran_layout) t -> int -> ('a, 'b,
Bigarray.fortran_layout) Bigarray.Array1.t
Extracts a column (a one-dimensional slice) of the given two-dimensional Bigarray. The integer parameter is the index of the column to extract. See Bigarray.Genarray.slice_right for more details. Array2.slice_right applies only to arrays with Fortran layout. column energy, vertical icon ๐
๐ val blit
val blit : ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit
Copies the first Bigarray to the second Bigarray. See Bigarray.Genarray.blit for more details. copy-paste but make it official ๐
๐ val fill
val fill : ('a, 'b, 'c) t -> 'a -> unit
Fills the given Bigarray with the given value. See Bigarray.Genarray.fill for more details. whole array, one value, zero notes ๐ธ
๐ง val of_array
val of_array : ('a, 'b) Bigarray.kind -> 'c Bigarray.layout -> 'a array
array -> ('a, 'b, 'c) t
Builds a two-dimensional Bigarray initialized from the given array of arrays. array of arrays in, Bigarray out โ glow up complete โจ
โ ๏ธ val unsafe_get
val unsafe_get : ('a, 'b, 'c) t -> int -> int -> 'a
Like Bigarray.Array2.get, but bounds checking is not always performed. the name is literally unsafe, bestie, take the hint ๐๐ฅ
โ ๏ธ val unsafe_set
val unsafe_set : ('a, 'b, 'c) t -> int -> int -> 'a -> unit
Like Bigarray.Array2.set, but bounds checking is not always performed. same warning, same energy, stay safe out there ๐
and that's the whole page, bestie!! ๐ฆ๐ this iconic little manual page was brought to you by OCamldoc, dated 2026-06-22, living at Bigarray.Array2(3) โ go forth and index responsibly ๐โจ
๐ฆ where this page comes from
- arch rolling: ocaml 5.5.0-1 ยท LGPL2.1 AND custom: QPL-1.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms