[python-arrayfire] 97/250: Adding documentation for data.py
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:36 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.
commit 1b67466b3e5723377f084fd76b0f6f387134fa80
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Tue Sep 1 21:26:30 2015 -0400
Adding documentation for data.py
---
arrayfire/array.py | 44 +---
arrayfire/data.py | 686 +++++++++++++++++++++++++++++++++++++++++++++++++-
tests/simple_array.py | 5 -
tests/simple_data.py | 5 +
4 files changed, 688 insertions(+), 52 deletions(-)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index 54939a8..5e517b5 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -8,7 +8,7 @@
########################################################
"""
-Functions to create and operate on af.Array
+arrayfire.Array class and helper functions.
"""
import inspect
@@ -102,48 +102,6 @@ def _binary_funcr(lhs, rhs, c_func):
return out
-def transpose(a, conj=False):
- """
- Perform the transpose on an input.
-
- Parameters
- -----------
- a : af.Array
- Multi dimensional arrayfire array.
-
- conj : optional: bool. default: False.
- Flag to specify if a complex conjugate needs to applied for complex inputs.
-
- Returns
- --------
- out : af.Array
- Containing the tranpose of `a` for all batches.
-
- """
- out = Array()
- safe_call(backend.get().af_transpose(ct.pointer(out.arr), a.arr, conj))
- return out
-
-def transpose_inplace(a, conj=False):
- """
- Perform inplace transpose on an input.
-
- Parameters
- -----------
- a : af.Array
- - Multi dimensional arrayfire array.
- - Contains transposed values on exit.
-
- conj : optional: bool. default: False.
- Flag to specify if a complex conjugate needs to applied for complex inputs.
-
- Note
- -------
- Input `a` needs to be a square matrix or a batch of square matrices.
-
- """
- safe_call(backend.get().af_transpose_inplace(a.arr, conj))
-
def _ctype_to_lists(ctype_arr, dim, shape, offset=0):
if (dim == 0):
return list(ctype_arr[offset : offset + shape[0]])
diff --git a/arrayfire/data.py b/arrayfire/data.py
index b7db403..424f213 100644
--- a/arrayfire/data.py
+++ b/arrayfire/data.py
@@ -7,12 +7,92 @@
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
+"""
+Functions to create and manipulate arrays.
+"""
+
from sys import version_info
from .library import *
from .array import *
from .util import *
+def transpose(a, conj=False):
+ """
+ Perform the transpose on an input.
+
+ Parameters
+ -----------
+ a : af.Array
+ Multi dimensional arrayfire array.
+
+ conj : optional: bool. default: False.
+ Flag to specify if a complex conjugate needs to applied for complex inputs.
+
+ Returns
+ --------
+ out : af.Array
+ Containing the tranpose of `a` for all batches.
+
+ """
+ out = Array()
+ safe_call(backend.get().af_transpose(ct.pointer(out.arr), a.arr, conj))
+ return out
+
+def transpose_inplace(a, conj=False):
+ """
+ Perform inplace transpose on an input.
+
+ Parameters
+ -----------
+ a : af.Array
+ - Multi dimensional arrayfire array.
+ - Contains transposed values on exit.
+
+ conj : optional: bool. default: False.
+ Flag to specify if a complex conjugate needs to applied for complex inputs.
+
+ Note
+ -------
+ Input `a` needs to be a square matrix or a batch of square matrices.
+
+ """
+ safe_call(backend.get().af_transpose_inplace(a.arr, conj))
+
def constant(val, d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
+ """
+ Create a multi dimensional array whose elements contain the same value.
+
+ Parameters
+ ----------
+ val : scalar.
+ Value of each element of the constant array.
+
+ d0 : int.
+ Length of first dimension.
+
+ d1 : optional: int. default: None.
+ Length of second dimension.
+
+ d2 : optional: int. default: None.
+ Length of third dimension.
+
+ d3 : optional: int. default: None.
+ Length of fourth dimension.
+
+ dtype : optional: af.Dtype. default: af.Dtype.f32.
+ Data type of the array.
+
+ Returns
+ -------
+
+ out : af.Array
+ Multi dimensional array whose elements are of value `val`.
+ - If d1 is None, `out` is 1D of size (d0,).
+ - If d1 is not None and d2 is None, `out` is 2D of size (d0, d1).
+ - If d1 and d2 are not None and d3 is None, `out` is 3D of size (d0, d1, d2).
+ - If d1, d2, d3 are all not None, `out` is 4D of size (d0, d1, d2, d3).
+ """
+
out = Array()
out.arr = constant_array(val, d0, d1, d2, d3, dtype.value)
return out
@@ -20,8 +100,61 @@ def constant(val, d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
# Store builtin range function to be used later
_brange = range
-def range(d0, d1=None, d2=None, d3=None, dim=-1, dtype=Dtype.f32):
-
+def range(d0, d1=None, d2=None, d3=None, dim=0, dtype=Dtype.f32):
+ """
+ Create a multi dimensional array using length of a dimension as range.
+
+ Parameters
+ ----------
+ val : scalar.
+ Value of each element of the constant array.
+
+ d0 : int.
+ Length of first dimension.
+
+ d1 : optional: int. default: None.
+ Length of second dimension.
+
+ d2 : optional: int. default: None.
+ Length of third dimension.
+
+ d3 : optional: int. default: None.
+ Length of fourth dimension.
+
+ dim : optional: int. default: 0.
+ The dimension along which the range is calculated.
+
+ dtype : optional: af.Dtype. default: af.Dtype.f32.
+ Data type of the array.
+
+ Returns
+ -------
+
+ out : af.Array
+ Multi dimensional array whose elements are along `dim` fall between [0 - self.dims[dim]-1]
+ - If d1 is None, `out` is 1D of size (d0,).
+ - If d1 is not None and d2 is None, `out` is 2D of size (d0, d1).
+ - If d1 and d2 are not None and d3 is None, `out` is 3D of size (d0, d1, d2).
+ - If d1, d2, d3 are all not None, `out` is 4D of size (d0, d1, d2, d3).
+
+
+ Examples
+ --------
+ >>> import arrayfire as af
+ >>> a = af.range(3, 2) # dim is not specified, range is along first dimension.
+ >>> af.display(a) # The data ranges from [0 - 2] (3 elements along first dimension)
+ [3 2 1 1]
+ 0.0000 0.0000
+ 1.0000 1.0000
+ 2.0000 2.0000
+
+ >>> a = af.range(3, 2, dim=1) # dim is 1, range is along second dimension.
+ >>> af.display(a) # The data ranges from [0 - 1] (2 elements along second dimension)
+ [3 2 1 1]
+ 0.0000 1.0000
+ 0.0000 1.0000
+ 0.0000 1.0000
+ """
out = Array()
dims = dim4(d0, d1, d2, d3)
@@ -30,7 +163,56 @@ def range(d0, d1=None, d2=None, d3=None, dim=-1, dtype=Dtype.f32):
def iota(d0, d1=None, d2=None, d3=None, dim=-1, tile_dims=None, dtype=Dtype.f32):
-
+ """
+ Create a multi dimensional array using the number of elements in the array as the range.
+
+ Parameters
+ ----------
+ val : scalar.
+ Value of each element of the constant array.
+
+ d0 : int.
+ Length of first dimension.
+
+ d1 : optional: int. default: None.
+ Length of second dimension.
+
+ d2 : optional: int. default: None.
+ Length of third dimension.
+
+ d3 : optional: int. default: None.
+ Length of fourth dimension.
+
+ tile_dims : optional: tuple of ints. default: None.
+ The number of times the data is tiled.
+
+ dtype : optional: af.Dtype. default: af.Dtype.f32.
+ Data type of the array.
+
+ Returns
+ -------
+
+ out : af.Array
+ Multi dimensional array whose elements are along `dim` fall between [0 - self.elements() - 1].
+
+ Examples
+ --------
+ >>> import arrayfire as af
+ >>> import arrayfire as af
+ >>> a = af.iota(3,3) # tile_dim is not specified, data is not tiled
+ >>> af.display(a) # the elements range from [0 - 8] (9 elements)
+ [3 3 1 1]
+ 0.0000 3.0000 6.0000
+ 1.0000 4.0000 7.0000
+ 2.0000 5.0000 8.0000
+
+ >>> b = af.iota(3,3,tile_dims(1,2)) # Asking to tile along second dimension.
+ >>> af.display(b)
+ [3 6 1 1]
+ 0.0000 3.0000 6.0000 0.0000 3.0000 6.0000
+ 1.0000 4.0000 7.0000 1.0000 4.0000 7.0000
+ 2.0000 5.0000 8.0000 2.0000 5.0000 8.0000
+ """
out = Array()
dims = dim4(d0, d1, d2, d3)
td=[1]*4
@@ -46,7 +228,36 @@ def iota(d0, d1=None, d2=None, d3=None, dim=-1, tile_dims=None, dtype=Dtype.f32)
return out
def randu(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
+ """
+ Create a multi dimensional array containing values from a uniform distribution.
+
+ Parameters
+ ----------
+ d0 : int.
+ Length of first dimension.
+
+ d1 : optional: int. default: None.
+ Length of second dimension.
+
+ d2 : optional: int. default: None.
+ Length of third dimension.
+
+ d3 : optional: int. default: None.
+ Length of fourth dimension.
+
+ dtype : optional: af.Dtype. default: af.Dtype.f32.
+ Data type of the array.
+ Returns
+ -------
+
+ out : af.Array
+ Multi dimensional array whose elements are sampled uniformly between [0, 1].
+ - If d1 is None, `out` is 1D of size (d0,).
+ - If d1 is not None and d2 is None, `out` is 2D of size (d0, d1).
+ - If d1 and d2 are not None and d3 is None, `out` is 3D of size (d0, d1, d2).
+ - If d1, d2, d3 are all not None, `out` is 4D of size (d0, d1, d2, d3).
+ """
out = Array()
dims = dim4(d0, d1, d2, d3)
@@ -54,6 +265,36 @@ def randu(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
return out
def randn(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
+ """
+ Create a multi dimensional array containing values from a normal distribution.
+
+ Parameters
+ ----------
+ d0 : int.
+ Length of first dimension.
+
+ d1 : optional: int. default: None.
+ Length of second dimension.
+
+ d2 : optional: int. default: None.
+ Length of third dimension.
+
+ d3 : optional: int. default: None.
+ Length of fourth dimension.
+
+ dtype : optional: af.Dtype. default: af.Dtype.f32.
+ Data type of the array.
+
+ Returns
+ -------
+
+ out : af.Array
+ Multi dimensional array whose elements are sampled from a normal distribution with mean 0 and sigma of 1.
+ - If d1 is None, `out` is 1D of size (d0,).
+ - If d1 is not None and d2 is None, `out` is 2D of size (d0, d1).
+ - If d1 and d2 are not None and d3 is None, `out` is 3D of size (d0, d1, d2).
+ - If d1, d2, d3 are all not None, `out` is 4D of size (d0, d1, d2, d3).
+ """
out = Array()
dims = dim4(d0, d1, d2, d3)
@@ -62,14 +303,59 @@ def randn(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
return out
def set_seed(seed=0):
+ """
+ Set the seed for the random number generator.
+
+ Parameters
+ ----------
+ seed: int.
+ Seed for the random number generator
+ """
safe_call(backend.get().af_set_seed(ct.c_ulonglong(seed)))
def get_seed():
+ """
+ Get the seed for the random number generator.
+
+ Returns
+ ----------
+ seed: int.
+ Seed for the random number generator
+ """
seed = ct.c_ulonglong(0)
safe_call(backend.get().af_get_seed(ct.pointer(seed)))
return seed.value
-def identity(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
+def identity(d0, d1, d2=None, d3=None, dtype=Dtype.f32):
+ """
+ Create an identity matrix or batch of identity matrices.
+
+ Parameters
+ ----------
+ d0 : int.
+ Length of first dimension.
+
+ d1 : int.
+ Length of second dimension.
+
+ d2 : optional: int. default: None.
+ Length of third dimension.
+
+ d3 : optional: int. default: None.
+ Length of fourth dimension.
+
+ dtype : optional: af.Dtype. default: af.Dtype.f32.
+ Data type of the array.
+
+ Returns
+ -------
+
+ out : af.Array
+ Multi dimensional array whose first two dimensions form a identity matrix.
+ - If d2 is None, `out` is 2D of size (d0, d1).
+ - If d2 is not None and d3 is None, `out` is 3D of size (d0, d1, d2).
+ - If d2, d3 are not None, `out` is 4D of size (d0, d1, d2, d3).
+ """
out = Array()
dims = dim4(d0, d1, d2, d3)
@@ -78,6 +364,31 @@ def identity(d0, d1=None, d2=None, d3=None, dtype=Dtype.f32):
return out
def diag(a, num=0, extract=True):
+ """
+ Create a diagonal matrix or Extract the diagonal from a matrix.
+
+ Parameters
+ ----------
+ a : af.Array.
+ 1 dimensional or 2 dimensional arrayfire array.
+
+ num : optional: int. default: 0.
+ The index of the diagonal.
+ - num == 0 signifies the diagonal.
+ - num > 0 signifies super diagonals.
+ - num < 0 signifies sub diagonals.
+
+ extract : optional: bool. default: True.
+ - If True , diagonal is extracted. `a` has to be 2D.
+ - If False, diagonal matrix is created. `a` has to be 1D.
+
+ Returns
+ -------
+
+ out : af.Array
+ - if extract is True, `out` contains the num'th diagonal from `a`.
+ - if extract is False, `out` contains `a` as the num'th diagonal.
+ """
out = Array()
if extract:
safe_call(backend.get().af_diag_extract(ct.pointer(out.arr), a.arr, ct.c_int(num)))
@@ -86,6 +397,63 @@ def diag(a, num=0, extract=True):
return out
def join(dim, first, second, third=None, fourth=None):
+ """
+ Join two or more arrayfire arrays along a specified dimension.
+
+ Parameters
+ ----------
+
+ dim: int.
+ Dimension along which the join occurs.
+
+ first : af.Array.
+ Multi dimensional arrayfire array.
+
+ second : af.Array.
+ Multi dimensional arrayfire array.
+
+ third : optional: af.Array. default: None.
+ Multi dimensional arrayfire array.
+
+ fourth : optional: af.Array. default: None.
+ Multi dimensional arrayfire array.
+
+ Returns
+ -------
+
+ out : af.Array
+ An array containing the input arrays joined along the specified dimension.
+
+ Examples
+ -------
+
+ >>> import arrayfire as af
+ >>> a = af.randu(2, 3)
+ >>> b = af.randu(2, 3)
+ >>> c = af.join(0, a, b)
+ >>> d = af.join(1, a, b)
+ >>> af.display(a)
+ [2 3 1 1]
+ 0.9508 0.2591 0.7928
+ 0.5367 0.8359 0.8719
+
+ >>> af.display(b)
+ [2 3 1 1]
+ 0.3266 0.6009 0.2442
+ 0.6275 0.0495 0.6591
+
+ >>> af.display(c)
+ [4 3 1 1]
+ 0.9508 0.2591 0.7928
+ 0.5367 0.8359 0.8719
+ 0.3266 0.6009 0.2442
+ 0.6275 0.0495 0.6591
+
+ >>> af.display(d)
+ [2 6 1 1]
+ 0.9508 0.2591 0.7928 0.3266 0.6009 0.2442
+ 0.5367 0.8359 0.8719 0.6275 0.0495 0.6591
+ """
out = Array()
if (third is None and fourth is None):
safe_call(backend.get().af_join(ct.pointer(out.arr), dim, first.arr, second.arr))
@@ -105,43 +473,353 @@ def join(dim, first, second, third=None, fourth=None):
def tile(a, d0, d1=1, d2=1, d3=1):
+ """
+ Tile an array along specified dimensions.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ d0: int.
+ The number of times `a` has to be tiled along first dimension.
+
+ d1: optional: int. default: 1.
+ The number of times `a` has to be tiled along second dimension.
+
+ d2: optional: int. default: 1.
+ The number of times `a` has to be tiled along third dimension.
+
+ d3: optional: int. default: 1.
+ The number of times `a` has to be tiled along fourth dimension.
+
+ Returns
+ -------
+
+ out : af.Array
+ An array containing the input after tiling the the specified number of times.
+
+ Examples
+ -------
+
+ >>> import arrayfire as af
+ >>> a = af.randu(2, 3)
+ >>> b = af.tile(a, 2)
+ >>> c = af.tile(a, 1, 2)
+ >>> d = af.tile(a, 2, 2)
+ >>> af.display(a)
+ [2 3 1 1]
+ 0.9508 0.2591 0.7928
+ 0.5367 0.8359 0.8719
+
+ >>> af.display(b)
+ [4 3 1 1]
+ 0.4107 0.9518 0.4198
+ 0.8224 0.1794 0.0081
+ 0.4107 0.9518 0.4198
+ 0.8224 0.1794 0.0081
+
+ >>> af.display(c)
+ [2 6 1 1]
+ 0.4107 0.9518 0.4198 0.4107 0.9518 0.4198
+ 0.8224 0.1794 0.0081 0.8224 0.1794 0.0081
+
+ >>> af.display(d)
+ [4 6 1 1]
+ 0.4107 0.9518 0.4198 0.4107 0.9518 0.4198
+ 0.8224 0.1794 0.0081 0.8224 0.1794 0.0081
+ 0.4107 0.9518 0.4198 0.4107 0.9518 0.4198
+ 0.8224 0.1794 0.0081 0.8224 0.1794 0.0081
+ """
out = Array()
safe_call(backend.get().af_tile(ct.pointer(out.arr), a.arr, d0, d1, d2, d3))
return out
def reorder(a, d0=1, d1=0, d2=2, d3=3):
+ """
+ Reorder the dimensions of the input.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ d0: optional: int. default: 1.
+ The location of the first dimension in the output.
+
+ d1: optional: int. default: 0.
+ The location of the second dimension in the output.
+
+ d2: optional: int. default: 2.
+ The location of the third dimension in the output.
+
+ d3: optional: int. default: 3.
+ The location of the fourth dimension in the output.
+
+ Returns
+ -------
+
+ out : af.Array
+ - An array containing the input aftern reordering its dimensions.
+
+ Note
+ ------
+ - `af.reorder(a, 1, 0)` is the same as `transpose(a)`
+
+ Examples
+ --------
+ >>> import arrayfire as af
+ >>> a = af.randu(5, 5, 3)
+ >>> af.display(a)
+ [5 5 3 1]
+ 0.4107 0.0081 0.6600 0.1046 0.8395
+ 0.8224 0.3775 0.0764 0.8827 0.1933
+ 0.9518 0.3027 0.0901 0.1647 0.7270
+ 0.1794 0.6456 0.5933 0.8060 0.0322
+ 0.4198 0.5591 0.1098 0.5938 0.0012
+
+ 0.8703 0.9250 0.4387 0.6530 0.4224
+ 0.5259 0.3063 0.3784 0.5476 0.5293
+ 0.1443 0.9313 0.4002 0.8577 0.0212
+ 0.3253 0.8684 0.4390 0.8370 0.1103
+ 0.5081 0.6592 0.4718 0.0618 0.4420
+
+ 0.8355 0.6767 0.1033 0.9426 0.9276
+ 0.4878 0.6742 0.2119 0.4817 0.8662
+ 0.2055 0.4523 0.5955 0.9097 0.3578
+ 0.1794 0.1236 0.3745 0.6821 0.6263
+ 0.5606 0.7924 0.9165 0.6056 0.9747
+
+
+ >>> b = af.reorder(a, 2, 0, 1)
+ >>> af.display(b)
+ [3 5 5 1]
+ 0.4107 0.8224 0.9518 0.1794 0.4198
+ 0.8703 0.5259 0.1443 0.3253 0.5081
+ 0.8355 0.4878 0.2055 0.1794 0.5606
+
+ 0.0081 0.3775 0.3027 0.6456 0.5591
+ 0.9250 0.3063 0.9313 0.8684 0.6592
+ 0.6767 0.6742 0.4523 0.1236 0.7924
+
+ 0.6600 0.0764 0.0901 0.5933 0.1098
+ 0.4387 0.3784 0.4002 0.4390 0.4718
+ 0.1033 0.2119 0.5955 0.3745 0.9165
+
+ 0.1046 0.8827 0.1647 0.8060 0.5938
+ 0.6530 0.5476 0.8577 0.8370 0.0618
+ 0.9426 0.4817 0.9097 0.6821 0.6056
+
+ 0.8395 0.1933 0.7270 0.0322 0.0012
+ 0.4224 0.5293 0.0212 0.1103 0.4420
+ 0.9276 0.8662 0.3578 0.6263 0.9747
+ """
out = Array()
safe_call(backend.get().af_reorder(ct.pointer(out.arr), a.arr, d0, d1, d2, d3))
return out
def shift(a, d0, d1=0, d2=0, d3=0):
+ """
+ Shift the input along each dimension.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ d0: int.
+ The amount of shift along first dimension.
+
+ d1: optional: int. default: 0.
+ The amount of shift along second dimension.
+
+ d2: optional: int. default: 0.
+ The amount of shift along third dimension.
+
+ d3: optional: int. default: 0.
+ The amount of shift along fourth dimension.
+
+ Returns
+ -------
+
+ out : af.Array
+ - An array the same shape as `a` after shifting it by the specified amounts.
+
+ Examples
+ --------
+ >>> import arrayfire as af
+ >>> a = af.randu(3, 3)
+ >>> b = af.shift(a, 2)
+ >>> c = af.shift(a, 1, -1)
+ >>> af.display(a)
+ [3 3 1 1]
+ 0.7269 0.3569 0.3341
+ 0.7104 0.1437 0.0899
+ 0.5201 0.4563 0.5363
+
+ >>> af.display(b)
+ [3 3 1 1]
+ 0.7104 0.1437 0.0899
+ 0.5201 0.4563 0.5363
+ 0.7269 0.3569 0.3341
+
+ >>> af.display(c)
+ [3 3 1 1]
+ 0.4563 0.5363 0.5201
+ 0.3569 0.3341 0.7269
+ 0.1437 0.0899 0.7104
+ """
out = Array()
safe_call(backend.get().af_shift(ct.pointer(out.arr), a.arr, d0, d1, d2, d3))
return out
def moddims(a, d0, d1=1, d2=1, d3=1):
+ """
+ Modify the shape of the array without changing the data layout.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ d0: int.
+ The first dimension of output.
+
+ d1: optional: int. default: 1.
+ The second dimension of output.
+
+ d2: optional: int. default: 1.
+ The third dimension of output.
+
+ d3: optional: int. default: 1.
+ The fourth dimension of output.
+
+ Returns
+ -------
+
+ out : af.Array
+ - An containing the same data as `a` with the specified shape.
+ - The number of elements in `a` must match `d0 x d1 x d2 x d3`.
+ """
out = Array()
dims = dim4(d0, d1, d2, d3)
safe_call(backend.get().af_moddims(ct.pointer(out.arr), a.arr, 4, ct.pointer(dims)))
return out
def flat(a):
+ """
+ Flatten the input array.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ Returns
+ -------
+
+ out : af.Array
+ - 1 dimensional array containing all the elements from `a`.
+ """
out = Array()
safe_call(backend.get().af_flat(ct.pointer(out.arr), a.arr))
return out
def flip(a, dim=0):
+ """
+ Flip an array along a dimension.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ dim : optional: int. default: 0.
+ The dimension along which the flip is performed.
+
+ Returns
+ -------
+
+ out : af.Array
+ The output after flipping `a` along `dim`.
+
+ Examples
+ -------
+
+ >>> import arrayfire as af
+ >>> a = af.randu(3, 3)
+ >>> af.display(a)
+ [3 3 1 1]
+ 0.7269 0.3569 0.3341
+ 0.7104 0.1437 0.0899
+ 0.5201 0.4563 0.5363
+
+ >>> af.display(b)
+ [3 3 1 1]
+ 0.5201 0.4563 0.5363
+ 0.7104 0.1437 0.0899
+ 0.7269 0.3569 0.3341
+
+ >>> af.display(c)
+ [3 3 1 1]
+ 0.3341 0.3569 0.7269
+ 0.0899 0.1437 0.7104
+ 0.5363 0.4563 0.5201
+
+ """
out = Array()
safe_call(backend.get().af_flip(ct.pointer(out.arr), a.arr, ct.c_int(dim)))
return out
def lower(a, is_unit_diag=False):
+ """
+ Extract the lower triangular matrix from the input.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ is_unit_diag: optional: bool. default: False.
+ Flag specifying if the diagonal elements are 1.
+
+ Returns
+ -------
+
+ out : af.Array
+ An array containing the lower triangular elements from `a`.
+ """
out = Array()
safe_call(backend.get().af_lower(ct.pointer(out.arr), a.arr, is_unit_diag))
return out
def upper(a, is_unit_diag=False):
+ """
+ Extract the upper triangular matrix from the input.
+
+ Parameters
+ ----------
+
+ a : af.Array.
+ Multi dimensional array.
+
+ is_unit_diag: optional: bool. default: False.
+ Flag specifying if the diagonal elements are 1.
+
+ Returns
+ -------
+
+ out : af.Array
+ An array containing the upper triangular elements from `a`.
+ """
out = Array()
safe_call(backend.get().af_upper(ct.pointer(out.arr), a.arr, is_unit_diag))
return out
diff --git a/tests/simple_array.py b/tests/simple_array.py
index 0360971..f8474f2 100755
--- a/tests/simple_array.py
+++ b/tests/simple_array.py
@@ -33,11 +33,6 @@ print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())
-af.display(af.transpose(a))
-
-af.transpose_inplace(a)
-af.display(a)
-
c = a.to_ctype()
for n in range(a.elements()):
print(c[n])
diff --git a/tests/simple_data.py b/tests/simple_data.py
index 8945a6b..71fa5ac 100755
--- a/tests/simple_data.py
+++ b/tests/simple_data.py
@@ -65,3 +65,8 @@ af.display(af.lower(a, True))
af.display(af.upper(a, False))
af.display(af.upper(a, True))
+
+a = af.randu(5,5)
+af.display(af.transpose(a))
+af.transpose_inplace(a)
+af.display(a)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git
More information about the debian-science-commits
mailing list