Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 33969a03 authored by hhakim's avatar hhakim
Browse files

Change the default config of batch_size and full_array in...

Change the default config of batch_size and full_array in matfaust/pyfaust.Faust.norm and update the doc consequently.
parent d1d87775
Branches
Tags
No related merge requests found
...@@ -1375,9 +1375,9 @@ classdef Faust ...@@ -1375,9 +1375,9 @@ classdef Faust
%> %>
%> The norm of F is equal to the norm of full(F). %> The norm of F is equal to the norm of full(F).
%> %>
%> @warning for the norm the computation time can be expected to be of order %> @warning The norm computation time can be expected to be of order
%> n*min(F.shape) with n the time for multipliying F by a vector. %> n*min(F.shape) with n the time for multipliying F by a vector.
%> Nevertheless, in many cases the implementation ensures that memory usage remains %> Nevertheless, the implementation allows that memory usage remains
%> controlled by avoiding to explicitly compute full(F). Please pay %> controlled by avoiding to explicitly compute full(F). Please pay
%> attention to the full_array (and batch_size) arguments for a better %> attention to the full_array (and batch_size) arguments for a better
%> understanding. %> understanding.
...@@ -1395,22 +1395,21 @@ classdef Faust ...@@ -1395,22 +1395,21 @@ classdef Faust
%> @param p (optional) the norm order or type. Respectively 1, 2 or inf for the 1-norm, 2-norm and inf-norm or 'fro' for the Frobenius norm (by default the 2-norm is computed). %> @param p (optional) the norm order or type. Respectively 1, 2 or inf for the 1-norm, 2-norm and inf-norm or 'fro' for the Frobenius norm (by default the 2-norm is computed).
%> @param 'threshold',real (optional) power iteration algorithm threshold (default to .001). Used only for norm(2). It's passed in a key-value pair fashion: 'threshold', .001 %> @param 'threshold',real (optional) power iteration algorithm threshold (default to .001). Used only for norm(2). It's passed in a key-value pair fashion: 'threshold', .001
%> @param 'max_num_its',int (optional) maximum number of iterations for power iteration algorithm. Used only for norm(2). It's passed in a key-value pair fashion: 'max_num_its', 1000. %> @param 'max_num_its',int (optional) maximum number of iterations for power iteration algorithm. Used only for norm(2). It's passed in a key-value pair fashion: 'max_num_its', 1000.
%> @param 'full_array',bool (optional) this argument is only used for 1-norm, %> @param 'full_array',bool (optional) this argument applies only for 1-norm,
%> inf-norm and Frobenius norm. If true the Faust full array %> inf-norm and Frobenius norm. If true the Faust full array
%> is computed before computing the norm otherwise it is not. By %> is computed before computing the norm otherwise it is not. By
%> default, if the Faust is composed of only sparse factors full_array %> default it is set to false. Many configurations exist in which
%> is set to false. In other cases, full_array is set to true but note %> full_array == False can be more efficient but it needs to
%> that in this case too configurations may exist in which full_array == false can be %> finetune the batch_size argument.
%> more efficient but it needs to finetune the batch_size argument. %> @param 'batch_size',int (optional) this argument applies only when the
%> @param 'batch_size',int (optional) this argument is only used when the %> full_array argument is set to false (for the 1-norm, inf-norm and
%> full_array argument is set to true (for the 1-norm, inf-norm and
%> Frobenius norm). It determines the number of Faust columns (resp. rows) %> Frobenius norm). It determines the number of Faust columns (resp. rows)
%> that are built in memory in order to compute the Frobenius norm and %> that are built in memory in order to compute the Frobenius norm and
%> the 1-norm (resp. the inf-norm). This parameter is primary in the %> the 1-norm (resp. the inf-norm). This parameter is primary in the
%> efficiency of the computation and memory consumption. By default, if all the factors %> efficiency of the computation and memory consumption. By default,
%> composing the Faust are sparse this parameter is set to %> it is set to 1 (which is certainly not the optimal configuration in
%> nnz_sum(F)/size(F, 1) (resp. nnz_sum(F)/size(F, 2)), a value that has %> many cases in matter of computation time but always the best in
%> experimentally shown good performances. %> term of memory cost).
%> %>
%> @retval n the norm (real). %> @retval n the norm (real).
%> %>
...@@ -1486,20 +1485,6 @@ classdef Faust ...@@ -1486,20 +1485,6 @@ classdef Faust
end end
end end
end end
if issparse(F) && ord ~= 2
% default values of batch_size and full_array in case the norm computed is not the 2-norm
% and the Faust is composed of only sparse factors
if full_array_is_default
full_array = false;
end
if batch_size_is_default
if strcmp(ord, 'fro') || ord == 1
batch_size = floor(nnz_sum(F)/size(F,1));
else
batch_size = floor(nnz_sum(F)/size(F,2));
end
end
end
if(ord == 2) if(ord == 2)
extra_opts = {threshold, max_num_its}; extra_opts = {threshold, max_num_its};
else % fro, 1, inf else % fro, 1, inf
......
...@@ -1465,9 +1465,9 @@ class Faust(numpy.lib.mixins.NDArrayOperatorsMixin): ...@@ -1465,9 +1465,9 @@ class Faust(numpy.lib.mixins.NDArrayOperatorsMixin):
The norm of F is equal to the numpy.linalg.norm of F.toarray(). The norm of F is equal to the numpy.linalg.norm of F.toarray().
WARNING: for the norm the computation time can be expected to be of order WARNING: the norm computation time can be expected to be of order
n*min(F.shape) with n the time for multipliying F by a vector. n*min(F.shape) with n the time for multipliying F by a vector.
Nevertheless, in many cases the implementation ensures that memory usage remains Nevertheless, the implementation allows that memory usage remains
controlled by avoiding to explicitly compute F.toarray(). Please pay controlled by avoiding to explicitly compute F.toarray(). Please pay
attention to the full_array (and batch_size) arguments for a better attention to the full_array (and batch_size) arguments for a better
understanding. understanding.
...@@ -1480,22 +1480,21 @@ class Faust(numpy.lib.mixins.NDArrayOperatorsMixin): ...@@ -1480,22 +1480,21 @@ class Faust(numpy.lib.mixins.NDArrayOperatorsMixin):
to .001). Used only for norm(2). to .001). Used only for norm(2).
max_num_its: (optional) maximum number of iterations for max_num_its: (optional) maximum number of iterations for
power iteration algorithm (default to 100). Used only for norm(2). power iteration algorithm (default to 100). Used only for norm(2).
full_array: (optional) this argument is only used for 1-norm, full_array: (optional) this argument applies only for 1-norm,
inf-norm and Frobenius norm. If True the Faust full array inf-norm and Frobenius norm. If True the Faust full array
is computed before computing the norm otherwise it is not. By is computed before computing the norm otherwise it is not. By
default, if the Faust is composed of only sparse factors full_array default it is set to False. Many configurations exist in which
is set to False. In other cases, full_array is set to True but note full_array == False can be more efficient but it needs to
that in this case too configurations may exist in which full_array == False can be finetune the batch_size argument.
more efficient but it needs to finetune the batch_size argument. batch_size: (optional) this argument applies only when the
batch_size: (optional) this argument is only used when the full_array argument is set to False (for the 1-norm, inf-norm and
full_array argument is set to True (for the 1-norm, inf-norm and
Frobenius norm). It determines the number of Faust columns (resp. rows) Frobenius norm). It determines the number of Faust columns (resp. rows)
that are built in memory in order to compute the Frobenius norm and that are built in memory in order to compute the Frobenius norm and
the 1-norm (resp. the inf-norm). This parameter is primary in the the 1-norm (resp. the inf-norm). This parameter is primary in the
efficiency of the computation and memory consumption. By default, if all the factors efficiency of the computation and memory consumption. By default,
composing the Faust are sparse this parameter is set to it is set to 1 (which is certainly not the optimal configuration in
F.nnz_sum()/F.shape\[0\] (resp. F.nnz_sum()/F.shape\[1\])), a value many cases in matter of computation time but always the best in
that has experimentally shown good performances. term of memory cost).
Returns: Returns:
the norm (float). the norm (float).
...@@ -1530,15 +1529,6 @@ class Faust(numpy.lib.mixins.NDArrayOperatorsMixin): ...@@ -1530,15 +1529,6 @@ class Faust(numpy.lib.mixins.NDArrayOperatorsMixin):
""" """
if ord not in [1, 2, "fro", np.inf]: if ord not in [1, 2, "fro", np.inf]:
raise ValueError("ord must have the value 1, 2, 'fro' or numpy.inf.") raise ValueError("ord must have the value 1, 2, 'fro' or numpy.inf.")
if ord != 2 and F.issparse():
# set full_array and batch_size arguments if not already set
if 'full_array' not in kwargs:
kwargs['full_array'] = False
if 'batch_size' not in kwargs:
if ord == 1 or ord == 'fro':
kwargs['batch_size'] = F.nnz_sum()/F.shape[0]
else: # ord == inf
kwargs['batch_size'] = F.nnz_sum()/F.shape[1]
return F.m_faust.norm(ord, **kwargs) return F.m_faust.norm(ord, **kwargs)
def power_iteration(self, threshold=1e-3, maxiter=100): def power_iteration(self, threshold=1e-3, maxiter=100):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment