Skip to content

Commit 2ac1773

Browse files
edwinsolisfsyurkevi
authored andcommitted
Added descriptions to more functions and examples
1 parent 15461d4 commit 2ac1773

File tree

12 files changed

+249
-14
lines changed

12 files changed

+249
-14
lines changed

docs/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
Documentation
1+
Documentation (WIP)
22
==========
33

4+
**This documentation is a work in progress and may not contain all currently supported operations. Please check the functions signature and description for more info on it**
5+
46
We use [`Sphinx`](https://www.sphinx-doc.org/en/master/index.html) for presenting our documentation.
57

68
To build the docs follow these steps:
79

8-
1. Install the required sphinx packages and extensions from the [requirements.txt](../requirements.txt)
10+
1. Install the required sphinx packages and extensions from the [dev-requirements.txt](../dev-requirements.txt)
911
```sh
10-
pip install -r requirements.txt # install sphinx and its extensions
12+
pip install -r dev-requirements.txt # install sphinx and its extensions
1113
```
1214
2. Build docs using sphinx
1315
```sh

docs/configuringarrayfireenvironment.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ Environment Variables
66
=====================
77
The following are useful environment variable that can be used with ArrayFire.
88

9-
9+
* `AF_VERBOSE_LOADS`
10+
* `AF_CUDA_DEFAULT_DEVICE`
11+
* `AF_OPENCL_DEFAULT_DEVICE`
12+
* `AF_ONEAPI_DEFAULT_DEVICE`
13+
* `AF_TRACE`
14+
* `AF_PRINT_ERRORS`

docs/examples.rst

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@ Examples
22
========
33

44

5-
TO DO
6-
-----
7-
ADD LIST OF EXAMPLES
5+
.. collapse:: Getting Started
6+
7+
.. list-table::
8+
9+
* - :doc:`intro.py`
10+
- Shows how to set a device, initialize arrays, and do some array operations
11+
* - :doc:`convolve.py`
12+
- Shows how to do convolutions on 2D images
13+
14+
.. collapse:: Linear Algebra
15+
16+
.. list-table::
17+
18+
* - :doc:`cholesky.py`
19+
- Shows Cholesky decomposition in/out of place
20+
* - :doc:`lu.py`
21+
- Shows LU factorization in/out of place
22+
* - :doc:`qr.py`
23+
- Shows QR factorization in/out of place
24+
25+
.. collapse:: Financial
26+
27+
.. list-table::
28+
29+
* - :doc:`black_scholes_options.py`
30+
- Recreates black scholes options model utilizing ArrayFire's random and vectorization operations
31+
* - :doc:`heston_model.py`
32+
- Recreates heston model simultation utilizing ArrayFire's random and vectorization operations
33+
* - :doc:`monte_carlo_options.py`
34+
- Simulates monte carlo options model utilizing ArrayFire's random and vectorization operations
35+
36+
.. collapse:: Benchmarks
37+
38+
.. list-table::
39+
40+
* - :doc:`monte_carlo_pi.py`
41+
- Recreates a monte carlo method of calculating the digits of pi ArrayFire's random and vectorization operations

docs/functions.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Documentation grouped by category:
2222
- Creates an array filled with zeros.
2323
* - :doc:`af.ones() <functions/ones>`
2424
- Creates an array filled with ones.
25+
* - :doc:`af.constant() <functions/constant>`
26+
- Creates an array filled with a scalar value.
27+
* - :doc:`af.range() <functions/range>`
28+
- Creates an array filled with a range of linear indices along a dimension.
29+
* - :doc:`af.iota() <functions/iota>`
30+
- Creates an array filled with a range of linear indices along multiple dimensions
2531
* - :doc:`af.randu() <functions/randu>`
2632
- Creates an array with random uniform values.
2733
* - :doc:`af.randn() <functions/randn>`
@@ -54,6 +60,8 @@ Documentation grouped by category:
5460
- Computes the square root of each element.
5561
* - :doc:`af.matmul() <functions/matmul>`
5662
- Matrix multiplication.
63+
* - :doc:`af.gemm() <functions/gemm>`
64+
- General matrix multiplication.
5765
* - :doc:`af.inv() <functions/inv>`
5866
- Computes the inverse of a matrix.
5967
* - :doc:`af.det() <functions/det>`
@@ -80,6 +88,10 @@ Documentation grouped by category:
8088
- Matrix multiplication.
8189
* - :doc:`af.set_device() <functions/set_device>`
8290
- Gets the current device.
91+
* - :doc:`af.set_backend() <functions/set_backend>`
92+
- Sets the current backend.
93+
* - :doc:`af.get_backend() <functions/get_backend>`
94+
- Gets the current backend.
8395
* - :doc:`af.get() <functions/get>`
8496
- Copies data from the GPU to the CPU.
8597
* - :doc:`af.min() <functions/min>`

docs/functions/constant.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
constant
2+
========
3+
The 'af.constant()' function in the ArrayFire library is used to create arrays filled with a specific scalar value. This is a common operation when initializing arrays that will be updated or manipulated later in numerical computations. The function allows you to specify the dimensions and data type of the array, making it flexible for various use cases.
4+
5+
Function
6+
--------
7+
:literal:`af.constant()`
8+
- Python interface to create a multi-dimensional array filled with a constant value.
9+
10+
Detailed Description
11+
--------------------
12+
The 'af.constant()' function creates an ArrayFire array where every element is initialized to the scalar (integer, floating point, or complex) value specified. It is particularly useful when you need to allocate space for an array but want to ensure that all values start from zero. This is often used in numerical methods, data processing, and initialization of variables in scientific computing.
13+
14+
You can specify the dimensions of the array as well as its data type. By default, the function creates arrays with a single precision floating-point type (float), but you can specify other data types if needed.
15+
16+
Function Documentation
17+
----------------------
18+
.. sidebar:: af.constant()
19+
20+
Syntax:
21+
af.constant(scalar, dims, dtype)
22+
23+
Parameters:
24+
'scalar': value that will be used to initialize
25+
'dims': List of integers representing the dimensions of the array. You can specify multiple dimensions to create multi-dimensional arrays. For example, dim0 is the number of rows, and dim1 is the number of columns for a 2D array, etc.
26+
'dtype': type that will be used to store the value internally. For example, af.int64 for signed 64-bit integer, af.float32 for 32-bit floating-point, and af.float64 for 64-bit floating-point
27+
28+
Returns:
29+
An ArrayFire array with the specified dimensions and data type, where all elements are initialized to a scalar value.
30+
31+

docs/functions/gemm.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
gemm
2+
======
3+
The 'af.matmul()' function in ArrayFire performs general matrix multiplication. General Matrix multiplication is a fundamental operation in linear algebra and is widely used in various neural networks, scientific and engineering computations.
4+
5+
Function
6+
--------
7+
:literal:`af.gemm()`
8+
- Python interface used to perform general matrix multiplication
9+
10+
Detailed Description
11+
--------------------
12+
The af.gemm() function computes the general matrix product of various input arrays. General Matrix multiplication is defined for three matrices A, B, C and two scalars alpha and beta as the operation alpha * A * B + beta * C where the number of columns in A is equal to the number of rows in B, while C has the same number of columns as B and same number of rows as A. The result is that is a weighted average of the matrix multiplication between A and B, and the accumulator matrix C.
13+
14+
Function Documentation
15+
----------------------
16+
.. sidebar:: af.gemm()
17+
18+
Syntax:
19+
af.matmul(A, B, alpha=alpha, beta=beta, accum=C, lhs_opts=lhs_opts, rhs_opts=rhs_opts)
20+
21+
Parameters:
22+
'A': The first input array (matrix) to be multiplied.
23+
'B': The second input array (matrix) to be multiplied.
24+
'alpha': scalar that will be multiplied with the matrix multiplication. If not specified, this is taken to be one and the output is the same as 'matmul'
25+
'beta': scalar that will be multiplied with the accumulator. If not specified, this is taken to be zero and the output is the same as 'matmul'
26+
'C': The accumulator input array that will be added to the matrix multiplication. If not specified, this behaves as array full of zeros and the output is the same as 'matmul'
27+
'lhs_opts': specifies any type of transpose operation should be executed on 'A' prior to the matrix multiplication
28+
'rhs_opts': specifies any type of transpose operation should be executed on 'B' prior to the matrix multiplication
29+
30+
Returns:
31+
An ArrayFire array representing the result of the general matrix multiplication:

docs/functions/get_backend.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
get_backend
2+
===========
3+
The 'af.get_backend()' function in ArrayFire is used to retrieve the BackendType object associated with the ArrayFire context. This function provides information about the current active backend. It is useful for managing and querying the status of a compute backend in a multi-device environment.
4+
5+
Function
6+
--------
7+
:literal:`af.get_backend()`
8+
- Python interface used to retrieve the BackendType object associated with the ArrayFire context.
9+
10+
Detailed Description
11+
--------------------
12+
The 'af.get_backend()' function provides access to the BackendType object in ArrayFire. The possible return values are BackendType.cpu, BackendType.opencl, BackendType.cuda, BackendType.oneapi. This function is particularly useful in environments where multiple devices are available and you need to query or manage backend-specific information.
13+
14+
Function Documentation
15+
----------------------
16+
.. sidebar:: af.get_backend()
17+
18+
Syntax:
19+
device = af.get_backend()
20+
21+
Parameters:
22+
This function does not take any parameters.
23+
24+
Returns:
25+
An ArrayFire device object representing the current active backend in the ArrayFire context.

docs/functions/iota.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
iota
2+
=======
3+
The 'af.iota()' function in ArrayFire generates a multi-dimensional ArrayFire array with values populated based on their linear index within the array, optionally tiling the result to create larger arrays.
4+
5+
Function
6+
--------
7+
:literal:`af.iota()`
8+
- Python interface used to generate linear indices with optional tiling
9+
10+
Detailed Description
11+
--------------------
12+
The 'af.iota()' function is used to generate array of a sequence of indices starting at 0 and ending at (exclusive) the size of the 'shape' dimensions specified, filling the array in column major ordering to the 'shape' specified that it is then duplicated as specified by the 'tile_shape'.
13+
14+
Function Documentation
15+
----------------------
16+
.. sidebar:: af.iota()
17+
18+
Syntax:
19+
af.iota(shape, tile_shape, dtype)
20+
21+
Parameters:
22+
'shape': List of Integers specifying the dimensions for which the sequence of integers is generated.
23+
'tile_shape': List of integers specifying the number of times the indices should be tiled in each dimension.
24+
'dtype': type that will be used to store the value internally. For example, af.int64 for signed 64-bit integer, af.float32 for 32-bit floating-point, and af.float64 for 64-bit floating-point
25+
26+
Returns:
27+
An ArrayFire array of linear indices with the dimensions 'shape * tile_shape'
28+

docs/functions/range.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
range
2+
=======
3+
The 'af.range()' function in ArrayFire generates a multi-dimensional ArrayFire array of linear indices using the length of a dimension as a range, tiling the indices on the other dimensions.
4+
5+
Function
6+
--------
7+
:literal:`af.range()`
8+
- Python interface used to generate a range in one dimension while tiling other dimensions
9+
10+
Detailed Description
11+
--------------------
12+
The 'af.range()' function is used to generate array of a sequence of indices starting at 0 and ending at (exclusive) the size of the length of the dimension specified, then it is duplicated on the remaining dimensions specified by 'shape'.
13+
14+
Function Documentation
15+
----------------------
16+
.. sidebar:: af.range()
17+
18+
Syntax:
19+
af.range(shape, tile_shape, dtype)
20+
21+
Parameters:
22+
'shape': List of Integers specifying the dimensions for which the sequence of integers is generated.
23+
'axis': Integer from 0 to 3 (by default 0) specifying the dimension to use to generate the linear index range
24+
'dtype': type that will be used to store the value internally. For example, af.int64 for signed 64-bit integer, af.float32 for 32-bit floating-point, and af.float64 for 64-bit floating-point
25+
26+
Returns:
27+
An ArrayFire array of linear indices along 'axis' with the dimensions of 'shape'
28+
29+

docs/functions/set_backend.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set_backend
2+
===========
3+
The 'af.set_backend()' function in ArrayFire is used to specify which backend will be used for subsequent ArrayFire operations. This is useful when working with multiple devices or GPUs to ensure that computations are directed to the desired hardware and software libraries.
4+
5+
Function
6+
--------
7+
:literal:`af.set_backend()`
8+
- Python interface used to specify which backend will be used for subsequent arrayfire operations.
9+
10+
Detailed Description
11+
--------------------
12+
The 'af.set_backend()' function sets the backend for ArrayFire operations. By default, ArrayFire uses the first available backend in order of priority: 'cuda', 'opencl', 'oneapi', 'cpu' from highest to lowest priority. When you have multiple GPUs or devices, you can use this function to select which backend ArrayFire should use for subsequent operations.
13+
Note that previous instantiated af.Array's or results from functions before the backend has been set will not be migrated to the new backend and device.
14+
15+
Function Documentation
16+
----------------------
17+
.. sidebar:: af.set_backend()
18+
19+
Syntax:
20+
af.set_backend(backend)
21+
22+
Parameters:
23+
'backend': af.BackendType value that corresponds to the ArrayFire backend to be set. Available values are af.BackendType.cuda, af.BackendType.opencl, af.BackendType.oneapi, and af.BackendType.cpu
24+
25+
Returns:
26+
None

0 commit comments

Comments
 (0)