Skip to content

Commit 201b31e

Browse files
committed
Documentation for modules arith, blas, data, device & image
1 parent 67d9316 commit 201b31e

File tree

5 files changed

+492
-0
lines changed

5 files changed

+492
-0
lines changed

src/arith/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ extern {
9494
fn af_isnan(out: MutAfArray, arr: AfArray) -> c_int;
9595
}
9696

97+
/// Enables use of `!` on objects of type [Array](./struct.Array.html)
9798
impl<'f> Not for &'f Array {
9899
type Output = Array;
99100

src/blas/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ extern {
2121
fn af_transpose_inplace(arr: AfArray, conjugate: c_int) -> c_int;
2222
}
2323

24+
/// Matrix multiple of two Arrays
25+
///
26+
/// # Parameters
27+
///
28+
/// - `lhs` is the Array on left hand side
29+
/// - `rhs` is the Array on right hand side
30+
/// - `optlhs` - Transpose left hand side before the function is performed, uses one of the values of [MatProp](./enum.MatProp.html)
31+
/// - `optrhs` - Transpose right hand side before the function is performed, uses one of the values of [MatProp](./enum.MatProp.html)
32+
///
33+
/// # Return Values
34+
///
35+
/// The result Array of matrix multiplication
2436
#[allow(unused_mut)]
2537
pub fn matmul(lhs: &Array, rhs: &Array,
2638
optlhs: MatProp, optrhs: MatProp) -> Result<Array, AfError> {
@@ -36,6 +48,20 @@ pub fn matmul(lhs: &Array, rhs: &Array,
3648
}
3749
}
3850

51+
/// Calculate the dot product of vectors.
52+
///
53+
/// Scalar dot product between two vectors. Also referred to as the inner product. This function returns the scalar product of two equal sized vectors or between a matrix and a vector. The second operand needs to be a vector in either case.
54+
///
55+
/// # Parameters
56+
///
57+
/// - `lhs` - Left hand side of dot operation
58+
/// - `rhs` - Right hand side of dot operation
59+
/// - `optlhs` - Options for lhs. Currently only NONE value from [MatProp](./enum.MatProp.html) is supported.
60+
/// - `optrhs` - Options for rhs. Currently only NONE value from [MatProp](./enum.MatProp.html) is supported.
61+
///
62+
/// # Return Values
63+
///
64+
/// The result of dot product.
3965
#[allow(unused_mut)]
4066
pub fn dot(lhs: &Array, rhs: &Array,
4167
optlhs: MatProp, optrhs: MatProp) -> Result<Array, AfError> {
@@ -51,6 +77,17 @@ pub fn dot(lhs: &Array, rhs: &Array,
5177
}
5278
}
5379

80+
/// Transpose of a matrix.
81+
///
82+
/// # Parameters
83+
///
84+
/// - `arr` is the input Array
85+
/// - `conjugate` is a boolean that indicates if the transpose operation needs to be a conjugate
86+
/// transpose
87+
///
88+
/// # Return Values
89+
///
90+
/// Transposed Array.
5491
#[allow(unused_mut)]
5592
pub fn transpose(arr: &Array, conjugate: bool) -> Result<Array, AfError> {
5693
unsafe {
@@ -64,6 +101,13 @@ pub fn transpose(arr: &Array, conjugate: bool) -> Result<Array, AfError> {
64101
}
65102
}
66103

104+
/// Inplace transpose of a matrix.
105+
///
106+
/// # Parameters
107+
///
108+
/// - `arr` is the input Array that has to be transposed
109+
/// - `conjugate` is a boolean that indicates if the transpose operation needs to be a conjugate
110+
/// transpose
67111
#[allow(unused_mut)]
68112
pub fn transpose_inplace(arr: &mut Array, conjugate: bool) -> Result<(), AfError> {
69113
unsafe {

src/data/mod.rs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,33 @@ cnst!(u32 , 6);
174174
cnst!(u8 , 7);
175175

176176

177+
/// Create an Array with constant value
178+
///
179+
/// # Parameters
180+
///
181+
/// - `cnst` is the constant value to be filled in the Array
182+
/// - `dims` is the size of the constant Array
183+
///
184+
/// # Return Values
185+
///
186+
/// An Array of given dimensions with constant value
177187
pub fn constant<T : ConstGenerator>(cnst: T, dims: Dim4) -> Result<Array, AfError> {
178188
cnst.generate(dims)
179189
}
180190

191+
/// Create a Range of values
192+
///
193+
/// Creates an array with [0, n] values along the `seq_dim` which is tiled across other dimensions.
194+
///
195+
/// # Parameters
196+
///
197+
/// - `dims` is the size of Array
198+
/// - `seq_dim` is the dimension along which range values are populated, all values along other
199+
/// dimensions are just repeated
200+
/// - `aftype` is the type of the Array.
201+
///
202+
/// # Return Values
203+
/// Array
181204
#[allow(unused_mut)]
182205
pub fn range(dims: Dim4, seq_dim: i32, aftype: Aftype) -> Result<Array, AfError> {
183206
unsafe {
@@ -192,6 +215,19 @@ pub fn range(dims: Dim4, seq_dim: i32, aftype: Aftype) -> Result<Array, AfError>
192215
}
193216
}
194217

218+
/// Create a range of values
219+
///
220+
/// Create an sequence [0, dims.elements() - 1] and modify to specified dimensions dims and then tile it according to tile_dims.
221+
///
222+
/// # Parameters
223+
///
224+
/// - `dims` is the dimensions of the sequence to be generated
225+
/// - `tdims` is the number of repitions of the unit dimensions
226+
/// - `aftype` is the type of Array to generate
227+
///
228+
/// # Return Values
229+
///
230+
/// Array
195231
#[allow(unused_mut)]
196232
pub fn iota(dims: Dim4, tdims: Dim4, aftype: Aftype) -> Result<Array, AfError> {
197233
unsafe {
@@ -207,6 +243,7 @@ pub fn iota(dims: Dim4, tdims: Dim4, aftype: Aftype) -> Result<Array, AfError> {
207243
}
208244
}
209245

246+
/// Set seed for random number generation
210247
pub fn set_seed(seed: u64) -> Result<(), AfError> {
211248
unsafe {
212249
let err_val = af_set_seed(seed as Uintl);
@@ -217,6 +254,7 @@ pub fn set_seed(seed: u64) -> Result<(), AfError> {
217254
}
218255
}
219256

257+
/// Get the seed of random number generator
220258
#[allow(unused_mut)]
221259
pub fn get_seed() -> Result<u64, AfError> {
222260
unsafe {
@@ -251,6 +289,17 @@ data_gen_def!(randu, af_randu);
251289
data_gen_def!(randn, af_randn);
252290
data_gen_def!(identity, af_identity);
253291

292+
/// Create a diagonal matrix
293+
///
294+
/// # Parameters
295+
///
296+
/// - `input` is the input Array
297+
/// - `dim` is the diagonal index relative to principal diagonal where values from input Array are
298+
/// to be placed
299+
///
300+
/// # Return Values
301+
///
302+
/// An Array with values as a diagonal Matrix
254303
#[allow(unused_mut)]
255304
pub fn diag_create(input: &Array, dim: i32) -> Result<Array, AfError> {
256305
unsafe {
@@ -263,6 +312,16 @@ pub fn diag_create(input: &Array, dim: i32) -> Result<Array, AfError> {
263312
}
264313
}
265314

315+
/// Extract diagonal from a given Matrix
316+
///
317+
/// # Parameters
318+
///
319+
/// - `input` is the input Matrix
320+
/// - `dim` is the index of the diagonal that has to be extracted from the input Matrix
321+
///
322+
/// # Return Values
323+
///
324+
/// An Array with values of the diagonal from input Array
266325
#[allow(unused_mut)]
267326
pub fn diag_extract(input: &Array, dim: i32) -> Result<Array, AfError> {
268327
unsafe {
@@ -276,6 +335,17 @@ pub fn diag_extract(input: &Array, dim: i32) -> Result<Array, AfError> {
276335
}
277336
}
278337

338+
/// Join two arrays
339+
///
340+
/// # Parameters
341+
///
342+
/// - `dim` is the dimension along which the concatenation has to be done
343+
/// - `first` is the Array that comes first in the concatenation
344+
/// - `second` is the Array that comes last in the concatenation
345+
///
346+
/// # Return Values
347+
///
348+
/// Concatenated Array
279349
#[allow(unused_mut)]
280350
pub fn join(dim: i32, first: &Array, second: &Array) -> Result<Array, AfError> {
281351
unsafe {
@@ -289,6 +359,16 @@ pub fn join(dim: i32, first: &Array, second: &Array) -> Result<Array, AfError> {
289359
}
290360
}
291361

362+
/// Join multiple arrays
363+
///
364+
/// # Parameters
365+
///
366+
/// - `dim` is the dimension along which the concatenation has to be done
367+
/// - `inputs` is the vector of Arrays that has to be concatenated
368+
///
369+
/// # Return Values
370+
///
371+
/// Concatenated Array
292372
#[allow(unused_mut)]
293373
pub fn join_many(dim: i32, inputs: Vec<&Array>) -> Result<Array, AfError> {
294374
unsafe {
@@ -302,6 +382,25 @@ pub fn join_many(dim: i32, inputs: Vec<&Array>) -> Result<Array, AfError> {
302382
}
303383
}
304384

385+
/// Join multiple Arrays along a given dimension
386+
///
387+
/// # Examples
388+
///
389+
/// ```
390+
/// # #[macro_use] extern crate arrayfire;
391+
/// # fn main() {
392+
/// let a = randu(Dim4::new(&[5, 3, 1, 1]), Aftype::F32).unwrap();
393+
/// let b = randu(Dim4::new(&[5, 3, 1, 1]), Aftype::F32).unwrap();
394+
/// let c = randu(Dim4::new(&[5, 3, 1, 1]), Aftype::F32).unwrap();
395+
/// let d = join_many![2, a, b, c];
396+
/// # }
397+
/// ```
398+
///
399+
/// # Panics
400+
///
401+
/// Using this macro to create an Array from multiple Arrays doesn't implicitly check for errors
402+
/// during FFI calls. Therefore, make sure your inputs are correct. In case, you do need proper
403+
/// error checking, use the [function version](./fn.join_many.html) of this macro.
305404
// Using macro to implement join many wrapper
306405
#[macro_export]
307406
macro_rules! join_many {
@@ -344,6 +443,15 @@ data_func_def!(tile, af_tile);
344443
data_func_def!(reorder, af_reorder);
345444
data_func_def!(shift, af_shift);
346445

446+
/// Change the shape of the Array
447+
///
448+
/// # Parameters
449+
///
450+
/// - `input` is the input Array
451+
/// - `dims` is the new dimensions to which the input Array is reshaped to
452+
///
453+
/// # Return Values
454+
/// Reshaped Array
347455
#[allow(unused_mut)]
348456
pub fn moddims(input: &Array, dims: Dim4) -> Result<Array, AfError> {
349457
unsafe {
@@ -357,6 +465,7 @@ pub fn moddims(input: &Array, dims: Dim4) -> Result<Array, AfError> {
357465
}
358466
}
359467

468+
/// Flatten the multidimensional Array to an 1D Array
360469
#[allow(unused_mut)]
361470
pub fn flat(input: &Array) -> Result<Array, AfError> {
362471
unsafe {
@@ -369,6 +478,16 @@ pub fn flat(input: &Array) -> Result<Array, AfError> {
369478
}
370479
}
371480

481+
/// Flip the Array
482+
///
483+
/// # Parameters
484+
///
485+
/// - `input` is the Array to be flipped
486+
/// - `dim` is the dimension along which the flip has to happen
487+
///
488+
/// # Return Values
489+
///
490+
/// Flipped Array
372491
#[allow(unused_mut)]
373492
pub fn flip(input: &Array, dim: u32) -> Result<Array, AfError> {
374493
unsafe {
@@ -381,6 +500,15 @@ pub fn flip(input: &Array, dim: u32) -> Result<Array, AfError> {
381500
}
382501
}
383502

503+
/// Create lower triangular matrix
504+
///
505+
/// # Parameters
506+
///
507+
/// - `input` is the input Array
508+
/// - `is_unit_diag` dictates if the output Array should have 1's along diagonal
509+
///
510+
/// # Return Values
511+
/// Array
384512
#[allow(unused_mut)]
385513
pub fn lower(input: &Array, is_unit_diag: bool) -> Result<Array, AfError> {
386514
unsafe {
@@ -394,6 +522,15 @@ pub fn lower(input: &Array, is_unit_diag: bool) -> Result<Array, AfError> {
394522
}
395523
}
396524

525+
/// Create upper triangular matrix
526+
///
527+
/// # Parameters
528+
///
529+
/// - `input` is the input Array
530+
/// - `is_unit_diag` dictates if the output Array should have 1's along diagonal
531+
///
532+
/// # Return Values
533+
/// Array
397534
#[allow(unused_mut)]
398535
pub fn upper(input: &Array, is_unit_diag: bool) -> Result<Array, AfError> {
399536
unsafe {

src/device/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ extern {
1111
fn af_set_device(device: c_int) -> c_int;
1212
}
1313

14+
/// Get ArrayFire Version Number
15+
///
16+
/// # Return Values
17+
/// A triplet of integers indicating major, minor & fix release version numbers.
1418
pub fn get_version() -> Result<(i32, i32, i32), AfError> {
1519
unsafe {
1620
let mut maj: i32 = 0;
@@ -25,6 +29,7 @@ pub fn get_version() -> Result<(i32, i32, i32), AfError> {
2529
}
2630
}
2731

32+
/// Print library meta-info
2833
pub fn info() -> Result<(), AfError> {
2934
unsafe {
3035
let err_val = af_info();
@@ -35,6 +40,11 @@ pub fn info() -> Result<(), AfError> {
3540
}
3641
}
3742

43+
/// Set active device
44+
///
45+
/// # Parameters
46+
///
47+
/// - `device` is the value of the device identifier which has to be set as active
3848
pub fn set_device(device: i32) -> Result<(), AfError> {
3949
unsafe {
4050
let err_val = af_set_device(device as c_int);

0 commit comments

Comments
 (0)