Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 68bcdae7 authored by hhakim's avatar hhakim
Browse files

Move projectors in a specific package py/matfaust.proj.

parent 2987c59a
Branches
No related tags found
No related merge requests found
Showing
with 229 additions and 175 deletions
......@@ -7,10 +7,10 @@ if(BUILD_DOCUMENTATION)
string(CONCAT DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.cu *.hu")
endif()
if(BUILD_WRAPPER_MATLAB)
string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} " Faust.m StoppingCriterion.m ConstraintGeneric.m ConstraintMat.m ConstraintReal.m ConstraintInt.m ConstraintName.m ParamsFact.m ParamsHierarchical.m ParamsPalm4MSA.m FaustFactory.m hadamard.m quickstart.m fft.m bsl.m runtimecmp.m runall.m version.m faust_fact.m ParamsHierarchicalSquareMat.m ParamsHierarchicalRectMat.m license.m omp.m wht.m dft.m eye.m rand.m eigtj.m hierarchical.m fact.m palm4msa.m fgft_givens.m fgft_palm.m svdtj.m ")
string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} " Faust.m StoppingCriterion.m ConstraintGeneric.m ConstraintMat.m ConstraintReal.m ConstraintInt.m ConstraintName.m ParamsFact.m ParamsHierarchical.m ParamsPalm4MSA.m FaustFactory.m hadamard.m quickstart.m fft.m bsl.m runtimecmp.m runall.m version.m faust_fact.m ParamsHierarchicalSquareMat.m ParamsHierarchicalRectMat.m license.m omp.m wht.m dft.m eye.m rand.m eigtj.m hierarchical.m fact.m palm4msa.m fgft_givens.m fgft_palm.m svdtj.m splin.m spcol.m proj_gen.m ")
endif()
if(BUILD_WRAPPER_PYTHON)
string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} " __init__.py factparams.py demo.py tools.py fact.py")
string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} "__init__.py factparams.py demo.py tools.py fact.py proj.py")
endif()
configure_file(${FAUST_DOC_SRC_DIR}/Doxyfile.in ${PROJECT_BINARY_DIR}/doc/Doxyfile @ONLY)
# ./gen_doc/images/* files is duplicated in doc/html/ to call images documentation in the source code with relative path of image's files, from build directory.
......
%> @package matfaust.proj @brief This module provides matrix projectors.
%=========================================================
%> @brief The parent abstract class to represent projectors.
%=========================================================
classdef (Abstract) proj_gen
properties (SetAccess = protected)
constraint
end
methods
function pM = subsref(self, S)
if(~ strcmp(S.type, '()') && ~ strcmp(S.type, '.'))
error('Invalid use of projector functor object: only () or . are handled')
end
if(iscell(S.subs) && length(S.subs) == 1 && ismatrix(S.subs{1}))
%error('The projector must be called on a matrix')
M = S.subs{1};
pM = self.constraint.project(M);
elseif(ischar(S.subs) && strcmp('constraint', S.subs))
pM = self.constraint;
else
error('bad use of projector: must be projector(matrix) or projector.constraint.')
end
end
end
end
%==========================================
%> Functor that implements the SPLIN projector.
%==========================================
classdef splin < matfaust.factparams.proj_gen
properties
end
......
classdef splincol < matfaust.factparams.proj_gen
properties
end
methods
function proj = splincol(shape, k, varargin)
import matfaust.factparams.ConstraintInt
% default values
proj.constraint = ConstraintInt('splincol', shape(1), shape(2), k, varargin{:});
end
end
end
......@@ -787,6 +787,7 @@ classdef Faust
OF = matfaust.Faust(F, mexFaustCplx('optimize_storage', F.matrix.objectHandle, false));
end
end
%=====================================================================
%> @brief Returns a Faust optimized with pruneout, optimize_storage and configured with the quickest method available to compute a Faust-matrix product.
%>
......
......@@ -172,179 +172,6 @@ class ConstraintInt(ConstraintGeneric):
self._num_cols, self._cons_value,
self.normalized, self.pos)
class proj_gen(ABC):
@abstractmethod
def __init__(self):
pass
def __call__(self, M):
return self.constraint.project(M)
class toeplitz_proj(proj_gen):
def __init__(self, shape, normalized=True, pos=False):
self.constraint = ConstraintMat('toeplitz', np.empty(shape), normalized, pos)
# def __call__(self, M):
# P = np.empty(M.shape)
# for i in range(M.shape[0]):
# m = np.mean(np.diag(M,i))
# m_ = np.mean(np.diag(M,-i))
# dl = len(np.diag(M,i))
# I = list(range(0,dl))
# J = [ i+j for j in range(0,dl) ]
# P[I,J] = m
# P[J,I] = m_
# return P
class circ_proj(proj_gen):
def __init__(self, shape, normalized=True, pos=False):
self.constraint = ConstraintMat('circ', np.empty(shape), normalized, pos)
# def __call_(self, M):
# P = np.empty(M.shape)
# for i in range(M.shape[0]):
# j = i - M.shape[0]
# m = np.mean(np.hstack((np.diag(M,i), np.diag(M,j))))
# print("m=", m, "mi=", np.mean(np.diag(M,i)), "mj=",
# np.mean(np.diag(M,j)), "i=", i,
# "j=", j)
# dli = M.shape[0]-i
# dlj = M.shape[0]+j
# I = list(range(dli))
# J = [ k+i for k in range(dli) ]
# P[I,J] = m
# I = [ k+-j for k in range(dlj) ]
# J = [ k for k in range(dlj) ]
# P[I,J] = m
# return P
class hankel_proj(proj_gen):
def __init__(self, shape, normalized=True, pos=False):
self.constraint = ConstraintMat('hankel', np.empty(shape), normalized, pos)
class sp(proj_gen):
"""
Functor that implements the SP projector. A, the projected matrix, is such that \f$ \| A \|_0 = k, \| A\|_F = 1\f$.
"""
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
k: the number of nonzeros of the projection image.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('sp', shape[0], shape[1], k, normalized, pos)
class splin(proj_gen):
"""
Functor that implements the SPLIN projector. A, the projected matrix, is defined by \f$ \forall i \in \{0,...,shape[0]-1\} \| \f$ the i-th row \f$ A_{i,*}\f$ is such that \f$ \| A_{i,*}\|_0 = k, \| A\|_F = 1\f$.
"""
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
k: the number of nonzeros of the projection image.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('splin', shape[0], shape[1], k, normalized, pos)
class spcol(proj_gen):
"""
Functor that implements the SPCOL projector. A, the projected matrix, is defined by \f$ \forall j \in \{0,...,shape[1]-1\} \| \f$ the j-th column \f$ \| A_{*,j}\f$ is such that \f$ A_{*,j}\|_0 = k, \| A\|_F = 1\f$.
"""
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
S: the support matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('spcol', shape[0], shape[1], k, normalized, pos)
class splincol(proj_gen):
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
S: the support matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('splincol', shape[0], shape[1], k, normalized, pos)
class supp(proj_gen):
"""
Functor that implements the SUPP projector. A, the image matrix, is such that np.nonzero(A) == np.nonzero(S).
"""
def __init__(self, S, normalized=True, pos=False):
"""
Args:
S: the support matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintMat('supp', S, normalized, pos)
class const(proj_gen):
"""
Functor that implements the CONST projector. A, the image matrix, is such that A == C.
"""
def __init__(self, C, normalized=False):
"""
Args:
C: the constant matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintMat('const', C, normalized, pos=False)
class normcol(proj_gen):
"""
Functor that implements the NORMCOL projector. A, the image matrix, is defined by \f$ \forall j \in \{0,...,shape[1]-1\} \| A_{*,j} \|_2 = s \| \f$.
"""
def __init__(self, shape, s, normalized=False, pos=False):
"""
Args:
s: the column 2-norm.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintReal('normcol', shape[0], shape[1], s, normalized, pos)
class normlin(proj_gen):
"""
Functor that implements the NORMLIN projector. A, the image matrix, is defined by \f$ \forall j \in \{0,...,shape[0]-1\} \| A_{i,*} \|_2 = s \| \f$.
"""
def __init__(self, shape, s, normalized=False, pos=False):
"""
Args:
s: the row 2-norm.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintReal('normlin', shape[0], shape[1], s, normalized, pos)
class ConstraintMat(ConstraintGeneric):
"""
This class represents a matrix-based constraint to apply on a matrix.
......
# -*- coding: utf-8 -*-
# @PYFAUST_LICENSE_HEADER@
## @package pyfaust.proj @brief This module provides matrix projectors.
from pyfaust.factparams import *
if sys.version_info > (3,0):
from abc import ABC, abstractmethod
else:
from abc import abstractmethod
ABC = object # trick to handle py2 missing ABC
# but not using abstract class in py2.7
class proj_gen(ABC):
@abstractmethod
def __init__(self):
pass
def __call__(self, M):
return self.constraint.project(M)
class toeplitz_proj(proj_gen):
def __init__(self, shape, normalized=True, pos=False):
self.constraint = ConstraintMat('toeplitz', np.empty(shape), normalized, pos)
# def __call__(self, M):
# P = np.empty(M.shape)
# for i in range(M.shape[0]):
# m = np.mean(np.diag(M,i))
# m_ = np.mean(np.diag(M,-i))
# dl = len(np.diag(M,i))
# I = list(range(0,dl))
# J = [ i+j for j in range(0,dl) ]
# P[I,J] = m
# P[J,I] = m_
# return P
class circ_proj(proj_gen):
def __init__(self, shape, normalized=True, pos=False):
self.constraint = ConstraintMat('circ', np.empty(shape), normalized, pos)
# def __call_(self, M):
# P = np.empty(M.shape)
# for i in range(M.shape[0]):
# j = i - M.shape[0]
# m = np.mean(np.hstack((np.diag(M,i), np.diag(M,j))))
# print("m=", m, "mi=", np.mean(np.diag(M,i)), "mj=",
# np.mean(np.diag(M,j)), "i=", i,
# "j=", j)
# dli = M.shape[0]-i
# dlj = M.shape[0]+j
# I = list(range(dli))
# J = [ k+i for k in range(dli) ]
# P[I,J] = m
# I = [ k+-j for k in range(dlj) ]
# J = [ k for k in range(dlj) ]
# P[I,J] = m
# return P
class hankel_proj(proj_gen):
def __init__(self, shape, normalized=True, pos=False):
self.constraint = ConstraintMat('hankel', np.empty(shape), normalized, pos)
class sp(proj_gen):
"""
Functor that implements the SP projector. A, the projected matrix, is such that \f$ \| A \|_0 = k, \| A\|_F = 1\f$.
"""
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
k: the number of nonzeros of the projection image.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('sp', shape[0], shape[1], k, normalized, pos)
class splin(proj_gen):
"""
Functor that implements the SPLIN projector. A, the projected matrix, is defined by \f$ \forall i \in \{0,...,shape[0]-1\} \| \f$ the i-th row \f$ A_{i,*}\f$ is such that \f$ \| A_{i,*}\|_0 = k, \| A\|_F = 1\f$.
"""
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
k: the number of nonzeros of the projection image.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('splin', shape[0], shape[1], k, normalized, pos)
class spcol(proj_gen):
"""
Functor that implements the SPCOL projector. A, the projected matrix, is defined by \f$ \forall j \in \{0,...,shape[1]-1\} \| \f$ the j-th column \f$ \| A_{*,j}\f$ is such that \f$ A_{*,j}\|_0 = k, \| A\|_F = 1\f$.
"""
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
S: the support matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('spcol', shape[0], shape[1], k, normalized, pos)
class splincol(proj_gen):
def __init__(self, shape, k, normalized=True, pos=False):
"""
Args:
S: the support matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintInt('splincol', shape[0], shape[1], k, normalized, pos)
class supp(proj_gen):
"""
Functor that implements the SUPP projector. A, the image matrix, is such that np.nonzero(A) == np.nonzero(S).
"""
def __init__(self, S, normalized=True, pos=False):
"""
Args:
S: the support matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintMat('supp', S, normalized, pos)
class const(proj_gen):
"""
Functor that implements the CONST projector. A, the image matrix, is such that A == C.
"""
def __init__(self, C, normalized=False):
"""
Args:
C: the constant matrix.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintMat('const', C, normalized, pos=False)
class normcol(proj_gen):
"""
Functor that implements the NORMCOL projector. A, the image matrix, is defined by \f$ \forall j \in \{0,...,shape[1]-1\} \| A_{*,j} \|_2 = s \| \f$.
"""
def __init__(self, shape, s, normalized=False, pos=False):
"""
Args:
s: the column 2-norm.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintReal('normcol', shape[0], shape[1], s, normalized, pos)
class normlin(proj_gen):
"""
Functor that implements the NORMLIN projector. A, the image matrix, is defined by \f$ \forall j \in \{0,...,shape[0]-1\} \| A_{i,*} \|_2 = s \| \f$.
"""
def __init__(self, shape, s, normalized=False, pos=False):
"""
Args:
s: the row 2-norm.
normalized: True to normalize the projection image according to its 2-norm.
pos: True to skip negative values (replaced by zero) of the matrix to project.
"""
self.constraint = ConstraintReal('normlin', shape[0], shape[1], s, normalized, pos)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment