Globals - types and support functions used throughout
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 *
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.
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
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
Probably suitable to be migrated to Owl
val ba_fold
: ('a ‑> 'b
‑> 'a) ‑>
'a ‑>
('b, 'c) ODM.t ‑> 'a
ba_fold f acc ba
Fold a function over the big array
Returns f applied to acc and every element of ba
The order of the elements of ba that f is applied to is not
specified; in some implementations f may be applied in parallel to
many elements (with some acc); the final result, though, is the
application of f to every element of ba exactly once. Hence an
application of ba_fold min infinity ba
will always return the minimum value in ba, but ba_fold (fun x->Some x) None ba
will return an
Some x where x is any element of ba.
val
ba_foldi : (int ‑> 'a ‑>
'b ‑>
'a) ‑> 'a
‑> ('b, 'c) ODM.t ‑> 'a
ba_foldi f acc ba
Fold a function over the big array with flattened element index
Returns f applied to acc and every element of ba
The order of the elements of ba that f is applied to is not
specified; in some implementations f may be applied in parallel to
many elements (with some acc); the final result, though, is the
application of f to every element of ba exactly once. Hence an
application of ba_fold min infinity ba
will always return the minimum value in ba, but ba_fold (fun x->Some x) None ba
will return an
Some x where x is any element of ba.
val
ba_fold2d : (int ‑> int
‑> 'a
‑> 'b
‑> 'a) ‑>
'a ‑>
('b, 'c) ODM.t ‑> 'a
ba_fold2d f acc ba
Fold a function over the 2D big array
Returns f applied to acc and every element of ba
The order of the elements of ba that f is applied to is not specified; in some implementations f may be applied in parallel to many elements (with some acc); the final result, though, is the application of f to every element of ba exactly once.
ba_map_ f ba
Map a function over the big array in-place
Returns ba after f has been applied to each element
The order of the elements of ba that f is applied to is not specified; in some implementations f may be applied in parallel to many elements; the final result, though, is the application of f to every element of ba exactly once.
ba_mapi_ f ba
Map a function over the big array in-place using element index
Returns ba after f has been applied to each element
The order of the elements of ba that f is applied to is not specified; in some implementations f may be applied in parallel to many elements; the final result, though, is the application of f to every element of ba exactly once.
val
ba_filter : int ‑> int ‑> ((int ‑> int
‑> 'a) ‑> int
‑> int ‑> 'b)
‑> 'b
‑> ('a, 'c) ODM.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.
Returns dst
The order of the elements of src that f is applied to is not specified; in some implementations f may be applied in parallel to many elements. f is invoked with a 'get' function and x and y as arguments; an example function would be
let gradient_x get x y = ((get (x+1) y) -. (get (x-1) y)) *. 0.5
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.
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.