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