package batteries

  1. Overview
  2. Docs
A community-maintained standard library extension

Install

Dune Dependency

Authors

Maintainers

Sources

v3.9.0.tar.gz
md5=ea26b5c72e6731e59d856626049cca4d
sha512=55975b62c26f6db77433a3ac31f97af609fc6789bb62ac38b267249c78fd44ff37fe81901f1cf560857b9493a6046dd37b0d1c0234c66bd59e52843aac3ce6cb

doc/batteries.unthreaded/BatBigarray/Array1/index.html

Module BatBigarray.Array1Source

One-dimensional arrays. The Array1 structure provides operations similar to those of Bigarray.Genarray, but specialized to the case of one-dimensional arrays. (The Array2 and Array3 structures below provide operations specialized for two- and three-dimensional arrays.) Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking.

Sourcetype ('a, 'b, 'c) t = ('a, 'b, 'c) Bigarray.Array1.t

The type of one-dimensional big arrays whose elements have OCaml type 'a, representation kind 'b, and memory layout 'c.

Sourceval create : ('a, 'b) kind -> 'c layout -> int -> ('a, 'b, 'c) t

Array1.create kind layout dim returns a new bigarray of one dimension, whose size is dim. kind and layout determine the array element kind and the array layout as described for Genarray.create.

Sourceval dim : ('a, 'b, 'c) t -> int

Return the size (dimension) of the given one-dimensional big array.

Sourceval kind : ('a, 'b, 'c) t -> ('a, 'b) kind

Return the kind of the given big array.

Sourceval layout : ('a, 'b, 'c) t -> 'c layout

Return the layout of the given big array.

Sourceval change_layout : ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t

Array1.change_layout a layout returns a bigarray with the specified layout, sharing the data with a (and hence having the same dimension as a). No copying of elements is involved: the new array and the original array share the same storage space.

  • since 4.06.0
Sourceval size_in_bytes : ('a, 'b, 'c) t -> int

size_in_bytes a is the number of elements in a multiplied by a's kind_size_in_bytes.

  • since 2.5.0
Sourceval get : ('a, 'b, 'c) t -> int -> 'a

Array1.get a x, or alternatively a.{x}, returns the element of a at index x. x must be greater or equal than 0 and strictly less than Array1.dim a if a has C layout. If a has Fortran layout, x must be greater or equal than 1 and less or equal than Array1.dim a.

Sourceval set : ('a, 'b, 'c) t -> int -> 'a -> unit

Array1.set a x v, also written a.{x} <- v, stores the value v at index x in a. x must be inside the bounds of a as described in Bigarray.Array1.get;

Sourceval sub : ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t

Extract a sub-array of the given one-dimensional big array. See Genarray.sub_left for more details.

Sourceval slice : ('a, 'b, 'c) t -> int -> ('a, 'b, 'c) Array0.t

Extract a scalar (zero-dimensional slice) of the given one-dimensional big array. The integer parameter is the index of the scalar to extract. See Bigarray.Genarray.slice_left and Bigarray.Genarray.slice_right for more details.

  • since 2.7.0 and OCaml 4.05.0
Sourceval blit : ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit

Copy the first big array to the second big array. See Genarray.blit for more details.

Sourceval fill : ('a, 'b, 'c) t -> 'a -> unit

Fill the given big array with the given value. See Genarray.fill for more details.

Sourceval of_array : ('a, 'b) kind -> 'c layout -> 'a array -> ('a, 'b, 'c) t

Build a one-dimensional big array initialized from the given array.

Sourceval map_file : Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout -> bool -> int -> ('a, 'b, 'c) t

Memory mapping of a file as a one-dimensional big array. See Bigarray.Genarray.map_file for more details.

Sourceval enum : ('a, 'b, 'c) t -> 'a BatEnum.t

Array1.enum e returns an enumeration on the elements of e. Contrarily to the multi-dimensional case, order of elements is specified: elements are in sequential order, from smaller to larger indices.

Sourceval of_enum : ('a, 'b) kind -> 'c layout -> 'a BatEnum.t -> ('a, 'b, 'c) t

Array1.of_enum kind layout enum returns a new one-dimensional big array of kind kind and layout layout, with elements taken from the enumeration enum in order.

  • since 2.1
Sourceval map : ('a -> 'b) -> ('b, 'c) Bigarray.kind -> ('a, 'd, 'e) t -> ('b, 'c, 'e) t

Array1.map f a applies function f to all the elements of a, and builds a Bigarray.Array1.t with the results returned by f.

Sourceval mapi : (int -> 'a -> 'b) -> ('b, 'c) Bigarray.kind -> ('a, 'd, 'e) t -> ('b, 'c, 'e) t

Same as Bigarray.Array1.map, but the function is applied to the index of the element as the first argument, and the element itself as the second argument.

Sourceval modify : ('a -> 'a) -> ('a, 'b, 'c) t -> unit

modify f a changes each element x in a to f x in-place.

Sourceval modifyi : (int -> 'a -> 'a) -> ('a, 'b, 'c) t -> unit

Same as Bigarray.Array1.modify, but the function is applied to the index of the element as the first argument, and the element itself as the second argument.

Sourceval to_array : ('a, 'b, 'c) t -> 'a array

Build a one-dimensional array initialized from the given big array.

Unsafe operations

In case of doubt, don't use them.

Sourceval unsafe_get : ('a, 'b, 'c) t -> int -> 'a

Like Bigarray.Array1.get, but bounds checking is not always performed. Use with caution and only when the program logic guarantees that the access is within bounds.

Sourceval unsafe_set : ('a, 'b, 'c) t -> int -> 'a -> unit

Like Bigarray.Array1.set, but bounds checking is not always performed. Use with caution and only when the program logic guarantees that the access is within bounds.

OCaml

Innovation. Community. Security.

On This Page
  1. Unsafe operations