Skip to content

Commit

Permalink
Added decorators suggested by @matteofrigo
Browse files Browse the repository at this point in the history
  • Loading branch information
daducci committed Jun 1, 2018
1 parent 7070cff commit 1b69c3f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions commit/proximals.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!python
#cython: boundscheck=False, wraparound=False
"""
Author: Matteo Frigo - lts5 @ EPFL and Dep. of CS @ Univ. of Verona
Expand All @@ -10,9 +12,6 @@ cimport numpy as np
from math import sqrt
import sys

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.profile(False)

cpdef non_negativity(np.ndarray[np.float64_t] x, int compartment_start, int compartment_size):
"""
Expand All @@ -27,6 +26,7 @@ cpdef non_negativity(np.ndarray[np.float64_t] x, int compartment_start, int comp
v[i] = 0.0
return v


cpdef soft_thresholding(np.ndarray[np.float64_t] x, double lam, int compartment_start, int compartment_size) :
"""
Proximal of L1 norm
Expand All @@ -43,6 +43,7 @@ cpdef soft_thresholding(np.ndarray[np.float64_t] x, double lam, int compartment_
v[i] -= lam
return v


cpdef projection_onto_l2_ball(np.ndarray[np.float64_t] x, double lam, int compartment_start, int compartment_size) :
"""
Proximal of L2 norm
Expand All @@ -59,6 +60,7 @@ cpdef projection_onto_l2_ball(np.ndarray[np.float64_t] x, double lam, int compar
v[i] = v[i]/xn*lam
return v


cpdef omega_group_sparsity(np.ndarray[np.float64_t] v, np.ndarray[object] subtree, np.ndarray[np.float64_t] weight, double lam, double n) :
"""
References:
Expand All @@ -80,14 +82,15 @@ cpdef omega_group_sparsity(np.ndarray[np.float64_t] v, np.ndarray[object] subtre
tmp += weight[k] * max( v[idx] )
return lam*tmp


cpdef prox_group_sparsity( np.ndarray[np.float64_t] x, np.ndarray[object] subtree, np.ndarray[np.float64_t] weight, double lam, double n ) :
"""
References:
[1] Jenatton et al. - `Proximal Methods for Hierarchical Sparse Coding`
"""
cdef:
np.ndarray[np.float64_t] v
int nG = weight.size, N, rho
int nG = weight.size
size_t k, i
double r, xn

Expand Down

0 comments on commit 1b69c3f

Please sign in to comment.