P_S_real.py 931 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
class _P_S_real(ProxOperator):
5
6
7
    """
    Projection subroutine for projecting onto support constraints
    """
robin.requadt's avatar
robin.requadt committed
8

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

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