Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 281ebfe8 authored by hhakim's avatar hhakim
Browse files

Update py. wrapper code doc.

parent 765f513c
Branches
Tags
No related merge requests found
...@@ -55,11 +55,24 @@ class Faust: ...@@ -55,11 +55,24 @@ class Faust:
""" """
def __init__(F, list_factors=None, filepath=None, core_obj=None): def __init__(F, list_factors=None, filepath=None, core_obj=None):
""" Creates a Faust from a list of factors or a file. """ Creates a Faust from a list of factors or alternatively from a file.
Another easy way to create a Faust is to call the static method Faust.randFaust().
Args: Args:
list_factors : list/tuple of numpy matrices or filepath of the Faust in list_factors: list/tuple of numpy matrices or filepath of the Faust in
matlab binary format (.mat). matlab binary format (.mat).
filepath: the file in Matlab format (.mat) from which a Faust will
be created (the file must have been saved before with
Faust.save()).
core_obj: for internal purpose only. Please don't fill this argument.
Examples:
>>> from FaustPy import Faust
>>> F = Faust(filepath="myFaust.mat")
>>> import numpy as np
>>> G = Faust(list_factors=[np.random.rand(5,5)*10 for i in range(0,5)])
""" """
if(core_obj): if(core_obj):
F.m_faust = core_obj F.m_faust = core_obj
...@@ -76,7 +89,7 @@ class Faust: ...@@ -76,7 +89,7 @@ class Faust:
def randFaust(faust_type, field, min_num_factors, max_num_factors, min_dim_size, def randFaust(faust_type, field, min_num_factors, max_num_factors, min_dim_size,
max_dim_size, density=0.1): max_dim_size, density=0.1):
""" """
Generates a random Faust. Generates a random Faust.
Args: Args:
faust_type: must be one of RandFaustType.DENSE, RandFaustType.SPARSE or RandFaustType.MIXTE. faust_type: must be one of RandFaustType.DENSE, RandFaustType.SPARSE or RandFaustType.MIXTE.
...@@ -86,7 +99,14 @@ class Faust: ...@@ -86,7 +99,14 @@ class Faust:
min_dim_size: the minimal size of column and row dimensions. min_dim_size: the minimal size of column and row dimensions.
max_dim_size: the maximal size of column and row dimensions. max_dim_size: the maximal size of column and row dimensions.
density: the approximate density of factors. density: the approximate density of factors.
"""
Returns:
the random generated Faust.
Examples:
>>> from FaustPy import Faust, RandFaustType
>>> F = Faust.randFaust(RandFaustType.MIXTE, RandFaustType.COMPLEX, 2, 3, 10, 20,.5)
"""
if(not isinstance(faust_type, int) or faust_type not in [RandFaustType.SPARSE, if(not isinstance(faust_type, int) or faust_type not in [RandFaustType.SPARSE,
RandFaustType.DENSE, RandFaustType.DENSE,
RandFaustType.MIXTE]): RandFaustType.MIXTE]):
...@@ -108,7 +128,7 @@ class Faust: ...@@ -108,7 +128,7 @@ class Faust:
Gives the Faust's number of rows. Gives the Faust's number of rows.
Returns: Returns:
The Faust number of rows. the number of rows.
""" """
return F.m_faust.shape()[0] return F.m_faust.shape()[0]
...@@ -117,7 +137,7 @@ class Faust: ...@@ -117,7 +137,7 @@ class Faust:
Gives the Faust's number of columns. Gives the Faust's number of columns.
Returns: Returns:
The Faust number of columns. the number of columns.
""" """
return F.m_faust.shape()[1] return F.m_faust.shape()[1]
...@@ -126,7 +146,7 @@ class Faust: ...@@ -126,7 +146,7 @@ class Faust:
Gives the size of the Faust. Gives the size of the Faust.
Returns: Returns:
The Faust size tuple: get_nb_rows(), get_nb_cols(). the Faust size tuple: get_nb_rows(), get_nb_cols().
""" """
#return F.shape[0], F.shape[1] #return F.shape[0], F.shape[1]
return F.m_faust.shape() return F.m_faust.shape()
...@@ -170,7 +190,7 @@ class Faust: ...@@ -170,7 +190,7 @@ class Faust:
np.ndararray() must be equal 'F'). np.ndararray() must be equal 'F').
Returns: Returns:
The result of the multiplication as a numpy matrix. the result of the multiplication as a numpy matrix.
Raises: Raises:
ValueError ValueError
...@@ -198,14 +218,14 @@ class Faust: ...@@ -198,14 +218,14 @@ class Faust:
""" """
Returns a coefficient of the Faust by its indices. Returns a coefficient of the Faust by its indices.
This function overloads the Python built-in. This function is a Python built-in overload.
Args: Args:
indices: array of length 2, its elements must be of kind: slice, integer or indices: array of length 2, its elements must be of kind: slice, integer or
Ellipsis (...). Ellipsis (...).
Returns: Returns:
The float element requested. the float element requested.
Examples: Examples:
>>> F[2, 3] >>> F[2, 3]
...@@ -243,7 +263,7 @@ class Faust: ...@@ -243,7 +263,7 @@ class Faust:
computed at Faust creation time and kept in cache. computed at Faust creation time and kept in cache.
Returns: Returns:
The number of non-zero elements as an integer. the number of non-zero elements as an integer.
Examples: Examples:
>>> F.nnz() >>> F.nnz()
...@@ -255,12 +275,11 @@ class Faust: ...@@ -255,12 +275,11 @@ class Faust:
Calculates the normalized rate of non-zero coefficients. Calculates the normalized rate of non-zero coefficients.
Returns: Returns:
The density value as a float. the density value (float).
Examples: Examples:
>>> F.density() >>> F.density()
""" """
#return float(F.nnz())/(F.shape[0]*F.shape[1])
return float(F.nnz()/(F.get_nb_cols()*F.get_nb_rows())) return float(F.nnz()/(F.get_nb_cols()*F.get_nb_rows()))
def RCG(F): def RCG(F):
...@@ -268,7 +287,7 @@ class Faust: ...@@ -268,7 +287,7 @@ class Faust:
Computes the Relative Complexity Gain (inverse of the density). Computes the Relative Complexity Gain (inverse of the density).
Returns: Returns:
The RCG value as a float. the RCG value (float).
If the density is zero it will be float("inf"). If the density is zero it will be float("inf").
If the density is negative it will be -1. If the density is negative it will be -1.
...@@ -285,16 +304,14 @@ class Faust: ...@@ -285,16 +304,14 @@ class Faust:
def norm(F, ord=2): def norm(F, ord=2):
""" """
Computes the norm of the Faust. Several types of norm are available: Computes the norm of the Faust. Several types of norm are available: 1-norm, 2-norm and Frobenius norm.
L1, L2 and Frobenius.
Args: Args:
ord: (Optional) Set it to 1 for L1, 2 for L2 and "fro" for ord: (Optional) the norm order (1 or 2) or "fro" for
Frobenius norm. Frobenius norm (by default the 2-norm is computed).
(by default the computed norm is L2).
Returns: Returns:
The norm as a float. the norm (float).
Raises: Raises:
ValueError. ValueError.
...@@ -306,8 +323,7 @@ class Faust: ...@@ -306,8 +323,7 @@ class Faust:
>>> F.norm('fro') >>> F.norm('fro')
""" """
if(ord not in [1, 2, "fro"]): if(ord not in [1, 2, "fro"]):
raise ValueError("Only L1, L2 and Frobenius norms are supported (values 1," raise ValueError("ord must have the value 1, 2 or 'fro'.")
"2 or 'fro' expected.")
return F.m_faust.norm(ord) return F.m_faust.norm(ord)
def get_nb_factors(F): def get_nb_factors(F):
...@@ -315,7 +331,7 @@ class Faust: ...@@ -315,7 +331,7 @@ class Faust:
Gives the Faust's number of factors. Gives the Faust's number of factors.
Returns: Returns:
The number of factors. the number of factors.
Examples: Examples:
>>> F.get_nb_factors() >>> F.get_nb_factors()
...@@ -327,10 +343,10 @@ class Faust: ...@@ -327,10 +343,10 @@ class Faust:
Returns the Faust's i-th factor as a numpy.ndarray. Returns the Faust's i-th factor as a numpy.ndarray.
Args: Args:
i: The integer index of the factor to get back. i: the integer index of the factor to get back.
Returns: Returns:
The i-th factor as a dense matrix (of type numpy.ndarray). the i-th factor as a dense matrix (of type numpy.ndarray).
Raises: Raises:
ValueError. ValueError.
...@@ -351,7 +367,7 @@ class Faust: ...@@ -351,7 +367,7 @@ class Faust:
if Matlab format used). It can be either an absolute or relative path. if Matlab format used). It can be either an absolute or relative path.
format: (Optional) It designates the format to use for format: (Optional) It designates the format to use for
writing. By default, it's "Matlab" to save the Faust in a .mat writing. By default, it's "Matlab" to save the Faust in a .mat
file (and it's currently the only format available). file (currently only that format is available).
Raises: Raises:
ValueError. ValueError.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment