P_S_real.py 1.26 KB
Newer Older
robin.requadt's avatar
robin.requadt committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
from proxoperators import ProxOperator
"""
#original matlab comment
%                      P_S_real.m
%             written on May 23, 2002 by 
%                   Russell Luke
%   Inst. Fuer Numerische und Angewandte Mathematik
%                Universitaet Gottingen
%
% DESCRIPTION:  Projection subroutine for projecting onto
%               support constraints
%
% INPUT:        input = data structure with .supp_ampl a vector of indeces of the nonzero elements of the array.
%
%               u = array to be projected
%
% OUTPUT:       p_S    = the projection 
%               
% USAGE: p_S = P_S(input,u)
%
% Nonstandard Matlab function calls:  
"""
class P_S_real(ProxOperator):

	def __init__(self,config):
		"""
		Initialization
        
        Parameters
        ----------
        config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
		'support_idx' : array_like
		"""
		self.support_idx = config['support_idx']

	def work(self,u):
		"""
		Parameters
        ----------
        u : array_like - Input
        
        Returns
        -------
		p_S : array_like
		"""
		support_idx = self.support_idx
		p_S = np.zeros(u.shape, dtype=u.dtype)
		p_S[support_idx] = np.real(u[support_idx])
		return p_S