3
3
import numpy as np
4
4
from numpy .random .mtrand import RandomState
5
5
from pycompss .api .api import compss_wait_on , compss_delete_object
6
+ from pycompss .api .constraint import constraint
6
7
from pycompss .api .parameter import Type , COLLECTION_IN , Depth
7
8
from pycompss .api .task import task
8
9
from scipy import linalg
@@ -541,6 +542,7 @@ def _initialize_parameters(self, x, random_state):
541
542
compss_delete_object (resp_block )
542
543
543
544
545
+ @constraint (computing_units = "${ComputingUnits}" )
544
546
@task (x = {Type : COLLECTION_IN , Depth : 2 },
545
547
resp = {Type : COLLECTION_IN , Depth : 2 },
546
548
returns = 1 )
@@ -564,6 +566,7 @@ def _reduce_estimate_parameters(partials, arity):
564
566
return _finalize_parameters (partials [0 ])
565
567
566
568
569
+ @constraint (computing_units = "${ComputingUnits}" )
567
570
@task (returns = 1 )
568
571
def _merge_estimate_parameters (* partials_params ):
569
572
n_samples = sum (params [0 ] for params in partials_params )
@@ -572,6 +575,7 @@ def _merge_estimate_parameters(*partials_params):
572
575
return n_samples , nk , means
573
576
574
577
578
+ @constraint (computing_units = "${ComputingUnits}" )
575
579
@task (returns = 3 )
576
580
def _finalize_parameters (params ):
577
581
n_samples = params [0 ]
@@ -634,6 +638,7 @@ def _estimate_covariances(x, resp, nk, means, reg_covar, covar_type, arity):
634
638
return finalize_covariances (covar_type , reg_covar , nk , means , partials [0 ])
635
639
636
640
641
+ @constraint (computing_units = "${ComputingUnits}" )
637
642
@task (x = {Type : COLLECTION_IN , Depth : 2 },
638
643
resp = {Type : COLLECTION_IN , Depth : 2 },
639
644
returns = 1 )
@@ -654,6 +659,7 @@ def _partial_covar_full(resp, x, means):
654
659
return covariances
655
660
656
661
662
+ @constraint (computing_units = "${ComputingUnits}" )
657
663
@task (x = {Type : COLLECTION_IN , Depth : 2 },
658
664
returns = 1 )
659
665
def _partial_covar_tied (x ):
@@ -665,6 +671,7 @@ def _partial_covar_tied(x):
665
671
return avg_sample_2
666
672
667
673
674
+ @constraint (computing_units = "${ComputingUnits}" )
668
675
@task (x = {Type : COLLECTION_IN , Depth : 2 },
669
676
resp = {Type : COLLECTION_IN , Depth : 2 },
670
677
returns = 1 )
@@ -680,11 +687,13 @@ def _partial_covar_diag(resp, x, means):
680
687
return avg_resp_sample_2 - 2 * avg_sample_means
681
688
682
689
690
+ @constraint (computing_units = "${ComputingUnits}" )
683
691
@task (returns = 1 )
684
692
def _sum_covar_partials (* covar_partials ):
685
693
return sum (covar_partials )
686
694
687
695
696
+ @constraint (computing_units = "${ComputingUnits}" )
688
697
@task (returns = 2 )
689
698
def _finalize_covar_full (covar_type , reg_covar , nk , covariances ):
690
699
n_components , n_features , _ = covariances .shape
@@ -695,6 +704,7 @@ def _finalize_covar_full(covar_type, reg_covar, nk, covariances):
695
704
return covariances , precisions_chol
696
705
697
706
707
+ @constraint (computing_units = "${ComputingUnits}" )
698
708
@task (returns = 2 )
699
709
def _finalize_covar_tied (covar_type , reg_covar , nk , means , covariances ):
700
710
avg_means2 = np .dot (nk * means .T , means )
@@ -705,6 +715,7 @@ def _finalize_covar_tied(covar_type, reg_covar, nk, means, covariances):
705
715
return covariances , precisions_chol
706
716
707
717
718
+ @constraint (computing_units = "${ComputingUnits}" )
708
719
@task (returns = 2 )
709
720
def _finalize_covar_diag (covar_type , reg_covar , nk , means , covariances ):
710
721
covariances /= nk [:, np .newaxis ]
@@ -714,6 +725,7 @@ def _finalize_covar_diag(covar_type, reg_covar, nk, means, covariances):
714
725
return covariances , precisions_chol
715
726
716
727
728
+ @constraint (computing_units = "${ComputingUnits}" )
717
729
@task (returns = 2 )
718
730
def _finalize_covar_spherical (covar_type , reg_covar , nk , means , covariances ):
719
731
covariances /= nk [:, np .newaxis ]
@@ -775,18 +787,21 @@ def _compute_precision_cholesky(covariances, covariance_type):
775
787
return precisions_chol
776
788
777
789
790
+ @constraint (computing_units = "${ComputingUnits}" )
778
791
@task (returns = 1 )
779
792
def _sum_log_prob_norm (* partials ):
780
793
total , count = map (sum , zip (* partials ))
781
794
return total , count
782
795
783
796
797
+ @constraint (computing_units = "${ComputingUnits}" )
784
798
@task (returns = 1 )
785
799
def _finalize_sum_log_prob_norm (* partials ):
786
800
total , count = map (sum , zip (* partials ))
787
801
return total / count
788
802
789
803
804
+ @constraint (computing_units = "${ComputingUnits}" )
790
805
@task (x = {Type : COLLECTION_IN , Depth : 2 }, returns = 2 )
791
806
def _estimate_responsibilities (x , weights , means , precisions_cholesky ,
792
807
covariance_type ):
@@ -964,12 +979,14 @@ def _resp_argmax(resp):
964
979
return pred
965
980
966
981
982
+ @constraint (computing_units = "${ComputingUnits}" )
967
983
@task (resp = {Type : COLLECTION_IN , Depth : 2 }, returns = 1 )
968
984
def _partial_resp_argmax (resp ):
969
985
resp = Array ._merge_blocks (resp )
970
986
return resp .argmax (axis = 1 )[:, np .newaxis ]
971
987
972
988
989
+ @constraint (computing_units = "${ComputingUnits}" )
973
990
@task (labels = {Type : COLLECTION_IN , Depth : 2 }, returns = 1 )
974
991
def _resp_subset (labels , n_components ):
975
992
labels = Array ._merge_blocks (labels ).flatten ()
@@ -979,6 +996,7 @@ def _resp_subset(labels, n_components):
979
996
return resp_chunk
980
997
981
998
999
+ @constraint (computing_units = "${ComputingUnits}" )
982
1000
@task (returns = 1 )
983
1001
def _random_resp_subset (n_samples , n_components , seed ):
984
1002
resp_chunk = RandomState (seed ).rand (n_samples , n_components )
0 commit comments