P_S_real.py 930 Bytes
Newer Older
robin.requadt's avatar
robin.requadt committed
1
import numpy as np
robin.requadt's avatar
robin.requadt committed
2
from .proxoperators import ProxOperator
3

4

robin.requadt's avatar
robin.requadt committed
5
class P_S_real(ProxOperator):
6
7
8
    """
    Projection subroutine for projecting onto support constraints
    """
robin.requadt's avatar
robin.requadt committed
9

10
    def __init__(self, config):
robin.requadt's avatar
robin.requadt committed
11
12
        """
        Initialization
robin.requadt's avatar
robin.requadt committed
13
14
15
16
        
        Parameters
        ----------
        config : dict - Dictionary containing the problem configuration. It must contain the following mapping:
17
        'support_idx' : array_like - vector of indeces of the nonzero elements of the array
robin.requadt's avatar
robin.requadt committed
18
19
        """
        self.support_idx = config['support_idx']
robin.requadt's avatar
robin.requadt committed
20

21
    def work(self, u):
robin.requadt's avatar
robin.requadt committed
22
23
        """
        Parameters
robin.requadt's avatar
robin.requadt committed
24
        ----------
25
        u : array_like - array to be projected
robin.requadt's avatar
robin.requadt committed
26
27
28
        
        Returns
        -------
29
        p_S : array_like - the projection 
robin.requadt's avatar
robin.requadt committed
30
        """
31
        support_idx = self.support_idx - 1
robin.requadt's avatar
robin.requadt committed
32
33
34
        p_S = np.zeros(u.shape, dtype=u.dtype)
        p_S[support_idx] = np.real(u[support_idx])
        return p_S