Module Streamlines__Globals

Copyright (C) 2017-2018,  Colin P Stark and Gavin J Stark.  All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @file   globals.ml
 * @brief  Globally useful functions and statics for the streamlines analysis
 *
module ODM = Owl.Dense.Matrix.Generic
module ODN = Owl.Dense.Ndarray.Generic

Filename handling

These functions standardize the handling of filename generation from paths, directory and leafnames. A global rot directory is supported, to provide a base for all relative filenames. Path elements may also be environment variables, which are automatically substituted.

exception BadEnvironmentVariable of string

BadEnvironmentVariable exception

Raised if an environment variable is referenced that is not actually within the environment

val root_dir : string Pervasives.ref

root_dir - global that holds the root directory to be prepended to all relative paths

val set_root : string ‑> unit

set_root root_dir

Sets the global root directory that is used for all relative paths

val env_value_or_path : string ‑> string

env_value_or_path path

Attempt to interpret a string as an environment variable (such as $SLMDATA) else return it as a path string.

val filename_from_path : string list ‑> string ‑> string

filename_from_path path leaf

Generate a full filename from a path and a leaf filename.

Bigarray types and handling

Types

type t_ba_chars = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t

t_ba_chars

Type short-cut for a Bigarray of chars that can be used with Owl and OpenCL

type t_ba_int16s = (int, Bigarray.int16_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t

t_ba_int16s

Type short-cut for a Bigarray of 16-bit unsigned ints that can be used with Owl and OpenCL

type t_ba_ints = (int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Genarray.t

t_ba_ints

Type short-cut for a Bigarray of Ocaml ints, for use internally and with Owl. Since Ocaml int's are system-size dependent (31 or 63 bits) the t_ba_ints is less useful for OpenCL.

type t_ba_floats = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Genarray.t

t_ba_floats

Type short-cut for a Bigarray of single-precision floats for use with Owl and OpenCL

Array creation functions

val ba_chars : int ‑> (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_chars size

Create a big array of val size! unsigned chars for use with Owl and OpenCL

val ba_int16s : int ‑> (int, Bigarray.int16_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_int16s size

Create a big array of val size! unsigned 16-bit integers for use with Owl and OpenCL

val ba_ints : int ‑> (int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_ints size

Create a big array of val size! Ocaml ints chars for use internally and with Owl

val ba_floats : int ‑> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_floats size

Create a big array of val size! single-preicision floats for use with Owl and OpenCL

val ba_char2d : int ‑> int ‑> (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_char2d width height

Create a big array of val width! by val height! of unsigned chars for use with Owl and OpenCL

val ba_int162d : int ‑> int ‑> (int, Bigarray.int16_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_int162d width height

Create a big array of val width! by val height! of unsigned 16-bit integers for use with Owl and OpenCL

val ba_int2d : int ‑> int ‑> (int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_int2d width height

Create a big array of val width! by val height! of Ocaml integers for use internally and with Owl

val ba_float2d : int ‑> int ‑> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_float2d width height

Create a big array of val width! by val height! of single precision floats for use with Owl and OpenCL

val ba_int3d : int ‑> int ‑> int ‑> (int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_int3d depth width height

Create a big array of val depth! by val width! by val height! of Ocaml integers for interal use

val ba_float3d : int ‑> int ‑> int ‑> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Genarray.t

ba_float3d depth width height

Create a big array of val depth! by val width! by val height! of single precision floats for use with Owl and OpenCL

Bigarray functions - for Owl?

Probably suitable to be migrated to Owl

val ba_fold : ('a ‑> 'b ‑> 'a) ‑> 'a ‑> ('b'cODM.t ‑> 'a

ba_fold f acc ba

Fold a function over the big array

val ba_foldi : (int ‑> 'a ‑> 'b ‑> 'a) ‑> 'a ‑> ('b'cODM.t ‑> 'a

ba_foldi f acc ba

Fold a function over the big array with flattened element index

val ba_fold2d : (int ‑> int ‑> 'a ‑> 'b ‑> 'a) ‑> 'a ‑> ('b'cODM.t ‑> 'a

ba_fold2d f acc ba

Fold a function over the 2D big array

val filtered_array : (int ‑> 'a ‑> bool) ‑> ('a'bODM.t ‑> ('a'bODN.t

filtered_array f ba - may well be used by analysis in the future

val ba_map_ : ('a ‑> 'a) ‑> ('a'bODN.t ‑> ('a'bODN.t

ba_map_ f ba

Map a function over the big array in-place

val ba_mapi_ : (int ‑> 'a ‑> 'a) ‑> ('a'bODN.t ‑> ('a'bODN.t

ba_mapi_ f ba

Map a function over the big array in-place using element index

val ba_filter : int ‑> int ‑> ((int ‑> int ‑> 'a) ‑> int ‑> int ‑> 'b) ‑> 'b ‑> ('a'cODM.t ‑> ('b'd'e) Bigarray.Genarray.t ‑> ('b'd'e) Bigarray.Genarray.t

ba_filter xsize ysize f rv src dst

Apply an (xsize*ysize) filter to every element of 2D src, storing the result in dst; for regions near the edge (i.e. where the filter lies beyond the edges of src) then rv is used instead of the filter application.

Useful functions

val trace : (string * int * int * int) ‑> unit

trace pos

Trace function used to debug code, particularly when it is crashing. Use as trace __POS__ to trace execution

val sfmt : ('a, unit, string) Pervasives.format ‑> 'a

sfmt

Short-cut for Printf.sprintf, used throughout the code for reduced code clutter.

val get_padded_array : ('a'bODM.t ‑> int ‑> 'a ‑> ('a'bODM.t

get_padded_array ba width value

Pad a 2D generic big array by a certain padding width on all four sides, using the specified value for that padding.

val list_assoc_replace : ('a * 'b) list ‑> 'a ‑> 'b ‑> ('a * 'b) list

list_assoc_replace name value

Add or replace (name*value) in assoc List

val is_nan : float ‑> bool

is_nan x

Shorthand for the correct way to determine if a float is NAN