1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Number of elements of an array (i.e., 2^n)
= 4
# Scalar type of array elements; it should be unsigned, i.e. BIT, UINT8, UINT16, UINT32 or UINT64
=
# Create a context
=
# Create a graph in a given context that will be used for matrix multiplication
=
# Create the type of the input array with `n` elements.
# To find the minimum of an array, we resort to the custom operation Min (see ops.rs) that accepts only binary input.
=
# Add an input node to the empty graph g created above.
# This input node requires the input array type generated previously.
=
# We convert the input integer array into the binary representation to perform comparisons between its elements
=
# We find the minimum using the tournament method. This allows to reduce the graph size to O(n) from O(2^n) nodes.
# Namely, we split the input array into pairs, find a minimum within each pair and create a new array from these minima.
# Then, we repeat this procedure for the new array.
# For example, let [2,7,0,3,11,5,0,4] be an input array.
# The 1st iteration yields [min(2,11), min(7,5), min(0,0), min(3,4)] = [2,5,0,3]
# The 2nd iteration results in [min(2,0), min(5,3)] = [0,3]
# The 3rd iteration returns [min(0,3)] = [0]
# Extract the first half of the array using the [Graph::get_slice] operation.
# Our slicing conventions follow [the NumPy rules](https://numpy.org/doc/stable/user/basics.indexing.html).
=
# Extract the first half of the array using the [Graph::get_slice] operation.
=
# Compare the first half with the second half elementwise to find minimums.
# This is done via the custom operation Min (see ops.rs).
=
# Convert output from the binary form to the arithmetic form
=
=
# Set this graph as main to be able to finalize the context
# Serialize the context and print it to stdout