Owl_lazy.Make
module A : Owl_types.Ndarray_Mutable
val value_to_float : value -> float
retrieve float type from value type input
val node_to_arr : attr Owl_graph.node -> arr
get Arr type from node
val arr_to_node : arr -> attr Owl_graph.node
pack Arr type into node
val node_to_elt : attr Owl_graph.node -> elt
get Elt type from node
val elt_to_node : elt -> attr Owl_graph.node
pack Elt type into node
val float_to_elt : float -> elt
build Elt type to float
val elt_to_float : elt -> float
get float value from Elt type
val graph_to_dot : graph -> string
convert graph to dot string, which can be saved into file and later rendered into figures to show graph structure
val graph_to_trace : graph -> string
print graph structure
val var_arr : ?shape:int array -> string -> arr
create Arr
val var_elt : string -> elt
create Elt
val empty : int array -> arr
empty shape
creates an uninitialized array with the specified shape
.
val zeros : int array -> arr
zeros shape
creates an array of the specified shape
filled with zeros.
val ones : int array -> arr
ones shape
creates an array of the specified shape
filled with ones.
create shape value
creates an array of the specified shape
filled with the given value
.
sequential ?a ?step shape
creates an array of the specified shape
filled with sequential values starting from a
and incremented by step
.
uniform ?a ?b shape
creates an array of the specified shape
filled with values drawn from a uniform distribution between a
and b
.
gaussian ?mu ?sigma shape
creates an array of the specified shape
filled with values drawn from a Gaussian distribution with mean mu
and standard deviation sigma
.
bernoulli ?p shape
creates an array of the specified shape
filled with values drawn from a Bernoulli distribution with probability p
.
init shape f
creates an array of the specified shape
where each element is initialized by the function f
, which takes the index of the element as input.
val shape : arr -> int array
shape arr
returns the shape of the array arr
.
val numel : arr -> int
numel arr
returns the total number of elements in the array arr
.
get arr indices
retrieves the value at the specified indices
from the array arr
.
set arr indices value
sets the value at the specified indices
in the array arr
to value
.
get_slice slice_spec arr
extracts a slice from the array arr
according to the slice specification slice_spec
.
set_slice slice_spec src dst
sets the specified slice in the array dst
to the values from src
according to the slice specification slice_spec
.
val reset : arr -> unit
reset arr
resets all elements in the array arr
to zero.
reshape arr shape
returns a new array with the elements of arr
rearranged into the specified shape
.
reverse arr
returns a new array with the elements of arr
reversed along all axes.
tile arr reps
creates a new array by repeating the array arr
according to the repetition pattern reps
.
repeat arr reps
repeats the elements of arr
along each axis according to the repetition pattern reps
.
concatenate ?axis arrs
concatenates the arrays in arrs
along the specified axis
.
split ?axis indices arr
splits the array arr
into multiple sub-arrays along the specified axis
at the given indices
.
draw ?axis arr n
randomly selects n
elements from the array arr
along the specified axis
, returning the selected elements and their corresponding indices.
map f arr
applies the function f
to each element of the array arr
, returning a new array with the results.
fold ?axis f init arr
reduces the array arr
along the specified axis
using the function f
, starting with the initial value init
.
scan ?axis f arr
performs a cumulative reduction of the array arr
along the specified axis
using the function f
.
one_hot depth arr
converts the array arr
into a one-hot encoded array with the specified depth.
val lazy_print :
?max_row:int ->
?max_col:int ->
?header:bool ->
?fmt:(A.elt -> string) ->
arr ->
arr
lazy_print ?max_row ?max_col ?header ?fmt arr
returns a formatted string representation of the array arr
, potentially truncated based on max_row
and max_col
, with an optional header
and custom formatting function fmt
. The array itself is returned unchanged.
print ?max_row ?max_col ?header ?fmt arr
prints a formatted string representation of the array arr
to the standard output, potentially truncated based on max_row
and max_col
, with an optional header
and custom formatting function fmt
.
abs arr
returns a new array where each element is the absolute value of the corresponding element in arr
.
neg arr
returns a new array where each element is the negation of the corresponding element in arr
.
floor arr
returns a new array where each element is the floor of the corresponding element in arr
.
ceil arr
returns a new array where each element is the ceiling of the corresponding element in arr
.
round arr
returns a new array where each element is rounded to the nearest integer.
sqr arr
returns a new array where each element is the square of the corresponding element in arr
.
sqrt arr
returns a new array where each element is the square root of the corresponding element in arr
.
log arr
returns a new array where each element is the natural logarithm of the corresponding element in arr
.
log2 arr
returns a new array where each element is the base-2 logarithm of the corresponding element in arr
.
log10 arr
returns a new array where each element is the base-10 logarithm of the corresponding element in arr
.
exp arr
returns a new array where each element is the exponential of the corresponding element in arr
.
sin arr
returns a new array where each element is the sine of the corresponding element in arr
.
cos arr
returns a new array where each element is the cosine of the corresponding element in arr
.
tan arr
returns a new array where each element is the tangent of the corresponding element in arr
.
sinh arr
returns a new array where each element is the hyperbolic sine of the corresponding element in arr
.
cosh arr
returns a new array where each element is the hyperbolic cosine of the corresponding element in arr
.
tanh arr
returns a new array where each element is the hyperbolic tangent of the corresponding element in arr
.
asin arr
returns a new array where each element is the arc sine of the corresponding element in arr
.
acos arr
returns a new array where each element is the arc cosine of the corresponding element in arr
.
atan arr
returns a new array where each element is the arc tangent of the corresponding element in arr
.
asinh arr
returns a new array where each element is the inverse hyperbolic sine of the corresponding element in arr
.
acosh arr
returns a new array where each element is the inverse hyperbolic cosine of the corresponding element in arr
.
atanh arr
returns a new array where each element is the inverse hyperbolic tangent of the corresponding element in arr
.
min ?axis ?keep_dims arr
returns the minimum value along the specified axis in the array arr
.
max ?axis ?keep_dims arr
returns the maximum value along the specified axis in the array arr
.
sum ?axis ?keep_dims arr
returns the sum of elements along the specified axis in the array arr
.
sum_reduce ?axis arr
reduces the array arr
by summing along the specified axes.
signum arr
returns a new array where each element is the sign of the corresponding element in arr
.
sigmoid arr
returns a new array where each element is the sigmoid function applied to the corresponding element in arr
.
relu arr
returns a new array where each element is the result of applying the ReLU (Rectified Linear Unit) function to the corresponding element in arr
.
l1norm' arr
returns the L1 norm (sum of absolute values) of all elements in the array arr
.
l2norm' arr
returns the L2 norm (Euclidean norm) of all elements in the array arr
.
l2norm_sqr' arr
returns the squared L2 norm of all elements in the array arr
.
clip_by_value ?amin ?amax arr
clips the values in the array arr
to be within the range amin, amax
.
clip_by_l2norm max_norm arr
clips the values in the array arr
so that its L2 norm does not exceed max_norm
.
pow arr1 arr2
returns a new array where each element is the result of raising the corresponding element in arr1
to the power of the corresponding element in arr2
.
scalar_pow scalar arr
returns a new array where each element in arr
is raised to the power of scalar
.
pow_scalar arr scalar
returns a new array where each element in arr
is raised to the power of scalar
.
atan2 arr1 arr2
returns a new array where each element is the result of applying the two-argument arctangent function to the corresponding elements in arr1
and arr2
.
scalar_atan2 scalar arr
returns a new array where each element is the result of applying the two-argument arctangent function to scalar
and the corresponding element in arr
.
atan2_scalar arr scalar
returns a new array where each element is the result of applying the two-argument arctangent function to the corresponding element in arr
and scalar
.
hypot arr1 arr2
returns a new array where each element is the result of applying the hypotenuse function to the corresponding elements in arr1
and arr2
.
min2 arr1 arr2
returns a new array where each element is the minimum of the corresponding elements in arr1
and arr2
.
max2 arr1 arr2
returns a new array where each element is the maximum of the corresponding elements in arr1
and arr2
.
add arr1 arr2
returns a new array where each element is the sum of the corresponding elements in arr1
and arr2
.
sub arr1 arr2
returns a new array where each element is the difference between the corresponding elements in arr1
and arr2
.
mul arr1 arr2
returns a new array where each element is the product of the corresponding elements in arr1
and arr2
.
div arr1 arr2
returns a new array where each element is the quotient of the corresponding elements in arr1
and arr2
.
add_scalar arr scalar
returns a new array where each element in arr
is incremented by scalar
.
sub_scalar arr scalar
returns a new array where each element in arr
is decremented by scalar
.
mul_scalar arr scalar
returns a new array where each element in arr
is multiplied by scalar
.
div_scalar arr scalar
returns a new array where each element in arr
is divided by scalar
.
scalar_add scalar arr
returns a new array where scalar
is added to each element in arr
.
scalar_sub scalar arr
returns a new array where scalar
is subtracted from each element in arr
.
scalar_mul scalar arr
returns a new array where each element in arr
is multiplied by scalar
.
scalar_div scalar arr
returns a new array where scalar
is divided by each element in arr
.
fma arr1 arr2 arr3
returns a new array where each element is the result of a fused multiply-add operation applied to the corresponding elements in arr1
, arr2
, and arr3
.
elt_equal arr1 arr2
returns a new array where each element is 1
if the corresponding elements in arr1
and arr2
are equal, otherwise 0
.
elt_not_equal arr1 arr2
returns a new array where each element is 1
if the corresponding elements in arr1
and arr2
are not equal, otherwise 0
.
elt_less arr1 arr2
returns a new array where each element is 1
if the corresponding element in arr1
is less than the corresponding element in arr2
, otherwise 0
.
elt_greater arr1 arr2
returns a new array where each element is 1
if the corresponding element in arr1
is greater than the corresponding element in arr2
, otherwise 0
.
elt_less_equal arr1 arr2
returns a new array where each element is 1
if the corresponding element in arr1
is less than or equal to the corresponding element in arr2
, otherwise 0
.
elt_greater_equal arr1 arr2
returns a new array where each element is 1
if the corresponding element in arr1
is greater than or equal to the corresponding element in arr2
, otherwise 0
.
elt_equal_scalar arr scalar
returns a new array where each element is 1
if the corresponding element in arr
is equal to scalar
, otherwise 0
.
elt_not_equal_scalar arr scalar
returns a new array where each element is 1
if the corresponding element in arr
is not equal to scalar
, otherwise 0
.
elt_less_scalar arr scalar
returns a new array where each element is 1
if the corresponding element in arr
is less than scalar
, otherwise 0
.
elt_greater_scalar arr scalar
returns a new array where each element is 1
if the corresponding element in arr
is greater than scalar
, otherwise 0
.
elt_less_equal_scalar arr scalar
returns a new array where each element is 1
if the corresponding element in arr
is less than or equal to scalar
, otherwise 0
.
elt_greater_equal_scalar arr scalar
returns a new array where each element is 1
if the corresponding element in arr
is greater than or equal to scalar
, otherwise 0
.
val conv1d : ?padding:Owl_types.padding -> arr -> arr -> int array -> arr
conv1d ?padding kernel arr stride
performs a 1D convolution of the array arr
with the kernel kernel
, using the specified stride and optional padding.
val conv2d : ?padding:Owl_types.padding -> arr -> arr -> int array -> arr
conv2d ?padding kernel arr stride
performs a 2D convolution of the array arr
with the kernel kernel
, using the specified stride and optional padding.
val conv3d : ?padding:Owl_types.padding -> arr -> arr -> int array -> arr
conv3d ?padding kernel arr stride
performs a 3D convolution of the array arr
with the kernel kernel
, using the specified stride and optional padding.
val transpose_conv2d :
?padding:Owl_types.padding ->
arr ->
arr ->
int array ->
arr
transpose_conv2d ?padding kernel arr stride
performs a 2D transposed convolution (also known as a deconvolution) of the array arr
with the kernel kernel
, using the specified stride and optional padding.
val max_pool1d :
?padding:Owl_types.padding ->
arr ->
int array ->
int array ->
arr
max_pool1d ?padding arr size stride
performs a 1D max pooling operation on the array arr
using the specified size and stride, with optional padding.
val max_pool2d :
?padding:Owl_types.padding ->
arr ->
int array ->
int array ->
arr
max_pool2d ?padding arr size stride
performs a 2D max pooling operation on the array arr
using the specified size and stride, with optional padding.
val max_pool3d :
?padding:Owl_types.padding ->
arr ->
int array ->
int array ->
arr
max_pool3d ?padding arr size stride
performs a 3D max pooling operation on the array arr
using the specified size and stride, with optional padding.
val avg_pool1d :
?padding:Owl_types.padding ->
arr ->
int array ->
int array ->
arr
avg_pool1d ?padding arr size stride
performs a 1D average pooling operation on the array arr
using the specified size and stride, with optional padding.
val avg_pool2d :
?padding:Owl_types.padding ->
arr ->
int array ->
int array ->
arr
avg_pool2d ?padding arr size stride
performs a 2D average pooling operation on the array arr
using the specified size and stride, with optional padding.
val avg_pool3d :
?padding:Owl_types.padding ->
arr ->
int array ->
int array ->
arr
avg_pool3d ?padding arr size stride
performs a 3D average pooling operation on the array arr
using the specified size and stride, with optional padding.
conv1d_backward_input kernel output_grad stride input_grad
computes the gradient of the input with respect to the 1D convolution, given the kernel, output gradient, and stride.
conv1d_backward_kernel input output_grad stride kernel_grad
computes the gradient of the kernel with respect to the 1D convolution, given the input, output gradient, and stride.
conv2d_backward_input kernel output_grad stride input_grad
computes the gradient of the input with respect to the 2D convolution, given the kernel, output gradient, and stride.
conv2d_backward_kernel input output_grad stride kernel_grad
computes the gradient of the kernel with respect to the 2D convolution, given the input, output gradient, and stride.
conv3d_backward_input kernel output_grad stride input_grad
computes the gradient of the input with respect to the 3D convolution, given the kernel, output gradient, and stride.
conv3d_backward_kernel input output_grad stride kernel_grad
computes the gradient of the kernel with respect to the 3D convolution, given the input, output gradient, and stride.
transpose_conv2d_backward_input kernel output_grad stride input_grad
computes the gradient of the input with respect to the 2D transposed convolution, given the kernel, output gradient, and stride.
transpose_conv2d_backward_kernel input output_grad stride kernel_grad
computes the gradient of the kernel with respect to the 2D transposed convolution, given the input, output gradient, and stride.
val max_pool1d_backward :
Owl_types.padding ->
arr ->
int array ->
int array ->
arr ->
arr
max_pool1d_backward padding input size stride output_grad
computes the gradient of the input with respect to the 1D max pooling operation, given the padding, input, size, stride, and output gradient.
val max_pool2d_backward :
Owl_types.padding ->
arr ->
int array ->
int array ->
arr ->
arr
max_pool2d_backward padding input size stride output_grad
computes the gradient of the input with respect to the 2D max pooling operation, given the padding, input, size, stride, and output gradient.
val max_pool3d_backward :
Owl_types.padding ->
arr ->
int array ->
int array ->
arr ->
arr
max_pool3d_backward padding input size stride output_grad
computes the gradient of the input with respect to the 3D max pooling operation, given the padding, input, size, stride, and output gradient.
val avg_pool1d_backward :
Owl_types.padding ->
arr ->
int array ->
int array ->
arr ->
arr
avg_pool1d_backward padding input size stride output_grad
computes the gradient of the input with respect to the 1D average pooling operation, given the padding, input, size, stride, and output gradient.
val avg_pool2d_backward :
Owl_types.padding ->
arr ->
int array ->
int array ->
arr ->
arr
avg_pool2d_backward padding input size stride output_grad
computes the gradient of the input with respect to the 2D average pooling operation, given the padding, input, size, stride, and output gradient.
val avg_pool3d_backward :
Owl_types.padding ->
arr ->
int array ->
int array ->
arr ->
arr
avg_pool3d_backward padding input size stride output_grad
computes the gradient of the input with respect to the 3D average pooling operation, given the padding, input, size, stride, and output gradient.
val row_num : arr -> int
row_num arr
returns the number of rows in the array arr
.
val col_num : arr -> int
col_num arr
returns the number of columns in the array arr
.
rows arr indices
returns the rows of the array arr
specified by indices
.
val copy_row_to : arr -> 'a -> 'b -> unit
copy_row_to src src_index dst
copies the row at index src_index
in the array src
to the array dst
.
val copy_col_to : arr -> 'a -> 'b -> unit
copy_col_to src src_index dst
copies the column at index src_index
in the array src
to the array dst
.
transpose ?axis arr
returns a new array where the axes of the array arr
are transposed according to axis
.
val to_rows : arr -> 'a array
to_rows arr
converts the array arr
into an array of rows.
val to_cols : arr -> 'a array
to_cols arr
converts the array arr
into an array of columns.
of_array data shape
creates an array of the specified shape
from the 1D array data
.
val make_graph :
input:attr Owl_graph.node array ->
output:attr Owl_graph.node array ->
string ->
graph
build a computation graph
val get_inputs : graph -> attr Owl_graph.node array
get input nodes of graph
val get_outputs : graph -> attr Owl_graph.node array
get output nodes of graph
val make_iopair :
graph ->
attr Owl_graph.node array ->
attr Owl_graph.node array ->
unit
connect iopairs in a graph
val update_iopair : graph -> unit
update iopairs in a graph
val init_inputs : (attr Owl_graph.node -> value) -> graph -> unit
initialize input nodes of a graph with given function f
val optimise : graph -> unit
optimise graph structures
val eval_elt : elt array -> unit
evaluate each Elt element in an array
val eval_arr : arr array -> unit
evaluate each Arr element in an array
val eval_graph : graph -> unit
evaluate all nodes in a computation graph