scm2cpp-learn 0.18.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. scm2cpp_learn/__init__.py +3836 -0
  2. scm2cpp_learn/_classifiers.cp312-win_amd64.pyd +0 -0
  3. scm2cpp_learn/_compat.py +284 -0
  4. scm2cpp_learn/_generated/__init__.py +0 -0
  5. scm2cpp_learn/_generated/_loader.py +41 -0
  6. scm2cpp_learn/_generated/_loader_accel_cublas.py +173 -0
  7. scm2cpp_learn/_generated/_loader_classifiers.py +308 -0
  8. scm2cpp_learn/_generated/_loader_derived_blas.py +29 -0
  9. scm2cpp_learn/_generated/_loader_derived_cublas.py +29 -0
  10. scm2cpp_learn/_generated/_loader_derived_loops.py +29 -0
  11. scm2cpp_learn/_generated/_loader_gpu_cuda.py +313 -0
  12. scm2cpp_learn/_generated/_loader_gramops_blas.py +692 -0
  13. scm2cpp_learn/_generated/_loader_gramops_loops.py +711 -0
  14. scm2cpp_learn/_generated/_loader_nmf_blas.py +29 -0
  15. scm2cpp_learn/_generated/_loader_nmf_cublas.py +29 -0
  16. scm2cpp_learn/_generated/_loader_nmf_loops.py +29 -0
  17. scm2cpp_learn/_generated/accel_cublas/accel.cpp +24 -0
  18. scm2cpp_learn/_generated/accel_cublas/accel.hpp +1178 -0
  19. scm2cpp_learn/_generated/accel_cublas/accel_capi.cpp +76 -0
  20. scm2cpp_learn/_generated/classifiers.cpp +37 -0
  21. scm2cpp_learn/_generated/classifiers.hpp +3745 -0
  22. scm2cpp_learn/_generated/classifiers_capi.cpp +115 -0
  23. scm2cpp_learn/_generated/derived_blas/lasso_design.cpp +5 -0
  24. scm2cpp_learn/_generated/derived_blas/lasso_design.hpp +156 -0
  25. scm2cpp_learn/_generated/derived_blas/lasso_design_capi.cpp +19 -0
  26. scm2cpp_learn/_generated/derived_cublas/lasso_design.cpp +5 -0
  27. scm2cpp_learn/_generated/derived_cublas/lasso_design.hpp +158 -0
  28. scm2cpp_learn/_generated/derived_cublas/lasso_design_capi.cpp +19 -0
  29. scm2cpp_learn/_generated/derived_loops/lasso_design.cpp +5 -0
  30. scm2cpp_learn/_generated/derived_loops/lasso_design.hpp +179 -0
  31. scm2cpp_learn/_generated/derived_loops/lasso_design_capi.cpp +19 -0
  32. scm2cpp_learn/_generated/gpu_cuda/gpu.cpp +37 -0
  33. scm2cpp_learn/_generated/gpu_cuda/gpu.hpp +3846 -0
  34. scm2cpp_learn/_generated/gpu_cuda/gpu_capi.cpp +308 -0
  35. scm2cpp_learn/_generated/gramops_blas/gramops.cpp +82 -0
  36. scm2cpp_learn/_generated/gramops_blas/gramops.hpp +5411 -0
  37. scm2cpp_learn/_generated/gramops_blas/gramops_capi.cpp +244 -0
  38. scm2cpp_learn/_generated/gramops_loops/gramops.cpp +82 -0
  39. scm2cpp_learn/_generated/gramops_loops/gramops.hpp +6395 -0
  40. scm2cpp_learn/_generated/gramops_loops/gramops_capi.cpp +250 -0
  41. scm2cpp_learn/_generated/lasso_cov.cpp +7 -0
  42. scm2cpp_learn/_generated/lasso_cov.hpp +152 -0
  43. scm2cpp_learn/_generated/lasso_cov_capi.cpp +25 -0
  44. scm2cpp_learn/_generated/nmf_blas/nmf_cd.cpp +5 -0
  45. scm2cpp_learn/_generated/nmf_blas/nmf_cd.hpp +132 -0
  46. scm2cpp_learn/_generated/nmf_blas/nmf_cd_capi.cpp +19 -0
  47. scm2cpp_learn/_generated/nmf_cublas/nmf_cd.cpp +5 -0
  48. scm2cpp_learn/_generated/nmf_cublas/nmf_cd.hpp +136 -0
  49. scm2cpp_learn/_generated/nmf_cublas/nmf_cd_capi.cpp +19 -0
  50. scm2cpp_learn/_generated/nmf_loops/nmf_cd.cpp +5 -0
  51. scm2cpp_learn/_generated/nmf_loops/nmf_cd.hpp +167 -0
  52. scm2cpp_learn/_generated/nmf_loops/nmf_cd_capi.cpp +19 -0
  53. scm2cpp_learn/_generated/scm2cpp-blas.hpp +158 -0
  54. scm2cpp_learn/_generated/scm2cpp-cublas.hpp +155 -0
  55. scm2cpp_learn/_generated/scm2cpp-cuda.hpp +285 -0
  56. scm2cpp_learn/_generated/scm2cpp.hpp +1627 -0
  57. scm2cpp_learn/_gramops_blas.cp312-win_amd64.pyd +0 -0
  58. scm2cpp_learn/_lasso_cov.cp312-win_amd64.pyd +0 -0
  59. scm2cpp_learn/_lasso_derived_blas.cp312-win_amd64.pyd +0 -0
  60. scm2cpp_learn/_libfind.py +153 -0
  61. scm2cpp_learn/_nmf_blas.cp312-win_amd64.pyd +0 -0
  62. scm2cpp_learn/batch_capi.cu +428 -0
  63. scm2cpp_learn-0.18.0.dist-info/DELVEWHEEL +2 -0
  64. scm2cpp_learn-0.18.0.dist-info/METADATA +1171 -0
  65. scm2cpp_learn-0.18.0.dist-info/RECORD +72 -0
  66. scm2cpp_learn-0.18.0.dist-info/WHEEL +5 -0
  67. scm2cpp_learn-0.18.0.dist-info/top_level.txt +1 -0
  68. scm2cpp_learn.libs/.load-order-scm2cpp_learn-0.18.0 +4 -0
  69. scm2cpp_learn.libs/libopenblas-0486735c359a67419d8832e3c40e2837.dll +4 -0
  70. scm2cpp_learn.libs/msvcp140-73438573e87f9a2fd944b01def13566d.dll +0 -0
  71. scm2cpp_learn.libs/vcruntime140-052ad6a20d375957e82aa6a3c441ea54.dll +0 -0
  72. scm2cpp_learn.libs/vcruntime140_1-a198370e11c6e7469d1cf0ef5b3f433d.dll +0 -0
@@ -0,0 +1,115 @@
1
+ // extern "C" wrappers over the translated functions, for Python and
2
+ // any other caller that speaks the C ABI. Array parameters arrive as
3
+ // element pointers: a view parameter takes the pointer as it is, so
4
+ // the caller's buffer is read and written in place with no copy; a
5
+ // fixed-extent one is reinterpreted as the std::array the function
6
+ // expects. The caller guarantees the length either way.
7
+ // Build (boost includes only if the generated header asks for them,
8
+ // which a numeric kernel's does not):
9
+ // g++ -O2 -std=c++17 -shared -fPIC -I. -o libclassifiers.so classifiers_capi.cpp
10
+ #include "classifiers.hpp"
11
+ #include <vector>
12
+ #include <algorithm>
13
+
14
+ extern "C" int scm2cpp_svm_liblinear(double* x, double* y, double* w, double* alpha, double* xnorm, double cost, int iters, double tol, int seed, int n, int p) {
15
+ return svm_liblinear(x, y, w, alpha, xnorm, cost, iters, tol, seed, n, p);
16
+ }
17
+ extern "C" int scm2cpp_svm_smo(double* k, double* y, double* alpha, double* rho, double cost, int iters, double eps, int n) {
18
+ return svm_smo(k, y, alpha, rho, cost, iters, eps, n);
19
+ }
20
+ extern "C" int scm2cpp_smo_solve(double* k, double* y, double* lin, double* alpha, double* rho, double cost, int iters, double eps, int n, int nk) {
21
+ return smo_solve(k, y, lin, alpha, *reinterpret_cast<std::array<double,1>*>(rho), cost, iters, eps, n, nk);
22
+ }
23
+ extern "C" int scm2cpp_shrinkable_P(double* yy, double* a, double* g, double cost, double gmax1, double gmax2, int t) {
24
+ return shrinkable_P(yy, a, g, cost, gmax1, gmax2, t);
25
+ }
26
+ extern "C" int scm2cpp_swap_position(int* index, int* krow, double* pp, double* yy, double* a, double* g, double* gbar, double* qd, int s, int t) {
27
+ return swap_position(index, krow, pp, yy, a, g, gbar, qd, s, t);
28
+ }
29
+ extern "C" int scm2cpp_reconstruct_gradient(double* k, int* krow, double* pp, double* yy, double* a, double* g, double* gbar, double cost, int active, int n, int nk) {
30
+ return reconstruct_gradient(k, krow, pp, yy, a, g, gbar, cost, active, n, nk);
31
+ }
32
+ extern "C" int scm2cpp_select_working_set(double* k, int* krow, double* yy, double* a, double* g, double* qd, double cost, double eps, int active, int nk, int* wi) {
33
+ return select_working_set(k, krow, yy, a, g, qd, cost, eps, active, nk, *reinterpret_cast<std::array<int,2>*>(wi));
34
+ }
35
+ extern "C" int scm2cpp_svr_smo(double* k, double* z, double* beta, double* rho, double cost, double epsilon, int iters, double eps, int n) {
36
+ return svr_smo(k, z, beta, rho, cost, epsilon, iters, eps, n);
37
+ }
38
+ extern "C" int scm2cpp_rbf_from_products(double* g, double* sa, double* sb, double gamma, int na, int nb) {
39
+ return rbf_from_products(g, sa, sb, gamma, na, nb);
40
+ }
41
+ extern "C" int scm2cpp_logistic_l1(double* x, double* y, double* w, double cost, double tol, int maxnewton, int seed, int n, int p) {
42
+ return logistic_l1(x, y, w, cost, tol, maxnewton, seed, n, p);
43
+ }
44
+ extern "C" int scm2cpp_svr_liblinear(double* x, double* y, double* w, double* beta, double* xnorm, double cost, double epsilon, int iters, double tol, int seed, int n, int p) {
45
+ return svr_liblinear(x, y, w, beta, xnorm, cost, epsilon, iters, tol, seed, n, p);
46
+ }
47
+ extern "C" double scm2cpp_ols_rows(double* x, double* y, int* rows, int m, double* w, double* g, double* c, double* l, double* z, double* xm, int n, int p) {
48
+ return ols_rows(x, y, rows, m, w, g, c, l, z, xm, n, p);
49
+ }
50
+ extern "C" int scm2cpp_ransac(double* x, double* y, int* subsets, double* coef, double* mask, double* out, double maxtrials, int minsamples, double thresh, double stopprob, int n, int p) {
51
+ return ransac(x, y, subsets, coef, mask, out, maxtrials, minsamples, thresh, stopprob, n, p);
52
+ }
53
+ extern "C" double scm2cpp_sgd_loss(int loss, double y, double p, double epsilon) {
54
+ return sgd_loss(loss, y, p, epsilon);
55
+ }
56
+ extern "C" double scm2cpp_sgd_grad(int loss, double y, double p, double epsilon) {
57
+ return sgd_grad(loss, y, p, epsilon);
58
+ }
59
+ extern "C" int scm2cpp_sgd(double* x, double* y, double* w, double* out, int loss, int lr, int pen, double alpha, double eta0, double powert, double epsilon, int maxiter, double tol, int niternochange, int fitint, int n, int p) {
60
+ return sgd(x, y, w, out, loss, lr, pen, alpha, eta0, powert, epsilon, maxiter, tol, niternochange, fitint, n, p);
61
+ }
62
+ extern "C" double scm2cpp_sgd_min(double a, double b) {
63
+ return sgd_min(a, b);
64
+ }
65
+ extern "C" double scm2cpp_min_pos(double* v, int m) {
66
+ return min_pos(v, m);
67
+ }
68
+ extern "C" double scm2cpp_round_even(double y) {
69
+ return round_even(y);
70
+ }
71
+ extern "C" int scm2cpp_cholesky_delete(double* l, int go, int n, int k) {
72
+ return cholesky_delete(l, go, n, k);
73
+ }
74
+ extern "C" int scm2cpp_swap_rc(double* g, int a, int b, int p) {
75
+ return swap_rc(g, a, b, p);
76
+ }
77
+ extern "C" int scm2cpp_lars(double* g, double* cov, double* coef, double* path, double* alphas, int rec, double nsamples, double alphamin, int method, int maxiter, double eps, int p) {
78
+ return lars(g, cov, coef, path, alphas, rec, nsamples, alphamin, method, maxiter, eps, p);
79
+ }
80
+ extern "C" int scm2cpp_svm_l1(double* x, double* y, double* w, double cost, double tol, int maxiter, int seed, int n, int p) {
81
+ return svm_l1(x, y, w, cost, tol, maxiter, seed, n, p);
82
+ }
83
+ extern "C" double scm2cpp_svm_l1_abs(double a) {
84
+ return svm_l1_abs(a);
85
+ }
86
+ extern "C" double scm2cpp_eig_hypot(double a, double b) {
87
+ return eig_hypot(a, b);
88
+ }
89
+ extern "C" int scm2cpp_sym_eigen(double* a, double* v, double* ev, double* e, int m) {
90
+ return sym_eigen(a, v, ev, e, m);
91
+ }
92
+ extern "C" double scm2cpp_eig_abs(double a) {
93
+ return eig_abs(a);
94
+ }
95
+ extern "C" int scm2cpp_eig_order(double* ev, int* ord, int m) {
96
+ return eig_order(ev, ord, m);
97
+ }
98
+ extern "C" int scm2cpp_sym_eigen_top(double* a, double* v, double* ev, double* e, int m, int k) {
99
+ return sym_eigen_top(a, v, ev, e, m, k);
100
+ }
101
+ extern "C" int scm2cpp_sym_eigen_gen(double* a, double* b, double* v, double* ev, double* e, int m) {
102
+ return sym_eigen_gen(a, b, v, ev, e, m);
103
+ }
104
+ extern "C" int scm2cpp_ts_minnorm(double* x, double* y, int* idx, double* w, double* aa, double* v, double* ev, double* e, double* ab, int s, int ns, int fitint, int p, int d) {
105
+ return ts_minnorm(x, y, idx, w, aa, v, ev, e, ab, s, ns, fitint, p, d);
106
+ }
107
+ extern "C" int scm2cpp_ts_fit(double* x, double* y, int* idx, double* w, double* a, double* b, double* aa, double* v, double* ev, double* e, double* ab, int s, int ns, int fitint, int p, int d) {
108
+ return ts_fit(x, y, idx, w, a, b, aa, v, ev, e, ab, s, ns, fitint, p, d);
109
+ }
110
+ extern "C" double scm2cpp_ts_abs(double v) {
111
+ return ts_abs(v);
112
+ }
113
+ extern "C" int scm2cpp_theilsen(double* x, double* y, int* idx, double* w, double* coef, int nsub, int ns, int fitint, int maxiter, double tol, int p) {
114
+ return theilsen(x, y, idx, w, coef, nsub, ns, fitint, maxiter, tol, p);
115
+ }
@@ -0,0 +1,5 @@
1
+
2
+ #include "lasso_design.hpp"
3
+ // #include "scm2cpp.hpp"
4
+
5
+
@@ -0,0 +1,156 @@
1
+
2
+ #ifndef LASSO_DESIGN_HPP
3
+ #define LASSO_DESIGN_HPP
4
+ #define SCM2CPP_MINIMAL
5
+ #include "scm2cpp-blas.hpp"
6
+ #include <vector>
7
+ #include "scm2cpp.hpp"
8
+
9
+ SCM2CPP_FN double
10
+ soft_threshold( double z, double g );
11
+ int
12
+ lasso_design( scm2cpp::cspan<double> x, scm2cpp::cspan<double> y, scm2cpp::span<double> resid, scm2cpp::span<double> xnorm, scm2cpp::span<double> beta, scm2cpp::cspan<double> lams, scm2cpp::span<double> betas, int iters, double tol, int n, int p, int nlam );
13
+
14
+
15
+
16
+ SCM2CPP_FN inline double
17
+ soft_threshold( double z, double g )
18
+ {
19
+ if(z > g) {
20
+ return (z-g) ;
21
+ }
22
+ else if(z < (0.0-g)) {
23
+ return (z+g) ;
24
+ }
25
+ else {
26
+ return 0.0 ;
27
+ }
28
+ }
29
+
30
+
31
+ inline int
32
+ lasso_design( scm2cpp::cspan<double> x, scm2cpp::cspan<double> y, scm2cpp::span<double> resid, scm2cpp::span<double> xnorm, scm2cpp::span<double> beta, scm2cpp::cspan<double> lams, scm2cpp::span<double> betas, int iters, double tol, int n, int p, int nlam )
33
+ { int swept = 0;
34
+ if( p < n ) {
35
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
36
+ resid[ i ] = y[i] ;
37
+ } ;
38
+ 0 ;
39
+ std::vector<double> b03446(p,0.0);
40
+ std::vector<double> g3445((p*p),0.0);
41
+ std::vector<double> c3444(p,0.0);
42
+ scm2cpp::blas_syrk(g3445, x, 1.0, 0.0, 1, p, n) ;
43
+ scm2cpp::blas_gemv(c3444, x, resid, 1.0, 0.0, 1, p, n) ;
44
+ for( int l = 0 ; !(l == nlam) ; l = (l+1) ) {
45
+ double lam = lams[l];
46
+ int stop = 0;
47
+ for( int sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
48
+ swept = (swept+1) ;
49
+ double maxmove = 0.0;
50
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
51
+ double rho = c3444[j];
52
+ double old = beta[j];
53
+ rho = (rho+(old*g3445[((j*p)+j)])) ;
54
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/g3445[((j*p)+j)]);
55
+ beta[ j ] = bnew ;
56
+ if( !(bnew == old) ) {
57
+ if( (bnew-old) > maxmove ) {
58
+ maxmove = (bnew-old) ;
59
+ } else {
60
+ 0 ;
61
+ } ;
62
+ if( (old-bnew) > maxmove ) {
63
+ maxmove = (old-bnew) ;
64
+ } else {
65
+ 0 ;
66
+ } ;
67
+ b03446[ j ] = (b03446[j]+(bnew-old)) ;
68
+ for( int k3448 = 0 ; !(k3448 == p) ; k3448 = (k3448+1) ) {
69
+ c3444[ k3448 ] = (c3444[k3448]-(g3445[((j*p)+k3448)]*(bnew-old))) ;
70
+ } ;
71
+ } else {
72
+ false ;
73
+ } ;
74
+ ;
75
+ ;
76
+ } ;
77
+ if( maxmove <= tol ) {
78
+ stop = 1 ;
79
+ } else {
80
+ 0 ;
81
+ } ;
82
+ ;
83
+ } ;
84
+ ;
85
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
86
+ betas[ ((l*p)+j) ] = beta[j] ;
87
+ } ;
88
+ ;
89
+ } ;
90
+ scm2cpp::blas_gemv(resid, x, b03446, -1.0, 1.0, 0, n, p) ;
91
+ 0 ;
92
+ ;
93
+ } else {
94
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
95
+ resid[ i ] = y[i] ;
96
+ } ;
97
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
98
+ double acc = 0.0;
99
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
100
+ acc = (acc+(x[((i*p)+j)]*x[((i*p)+j)])) ;
101
+ } ;
102
+ xnorm[ j ] = acc ;
103
+ ;
104
+ } ;
105
+ for( int l = 0 ; !(l == nlam) ; l = (l+1) ) {
106
+ double lam = lams[l];
107
+ int stop = 0;
108
+ for( int sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
109
+ swept = (swept+1) ;
110
+ double maxmove = 0.0;
111
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
112
+ double rho = 0.0;
113
+ double old = beta[j];
114
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
115
+ rho = (rho+(x[((i*p)+j)]*resid[i])) ;
116
+ } ;
117
+ rho = (rho+(old*xnorm[j])) ;
118
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/xnorm[j]);
119
+ beta[ j ] = bnew ;
120
+ if( !(bnew == old) ) {
121
+ if( (bnew-old) > maxmove ) {
122
+ maxmove = (bnew-old) ;
123
+ } else {
124
+ 0 ;
125
+ } ;
126
+ if( (old-bnew) > maxmove ) {
127
+ maxmove = (old-bnew) ;
128
+ } else {
129
+ 0 ;
130
+ } ;
131
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
132
+ resid[ i ] = (resid[i]-(x[((i*p)+j)]*(bnew-old))) ;
133
+ } ;
134
+ } else {
135
+ false ;
136
+ } ;
137
+ ;
138
+ ;
139
+ } ;
140
+ if( maxmove <= tol ) {
141
+ stop = 1 ;
142
+ } else {
143
+ 0 ;
144
+ } ;
145
+ ;
146
+ } ;
147
+ ;
148
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
149
+ betas[ ((l*p)+j) ] = beta[j] ;
150
+ } ;
151
+ ;
152
+ } ;
153
+ } ;
154
+ return swept ;
155
+ }
156
+ #endif // LASSO_DESIGN_HPP
@@ -0,0 +1,19 @@
1
+ // extern "C" wrappers over the translated functions, for Python and
2
+ // any other caller that speaks the C ABI. Array parameters arrive as
3
+ // element pointers: a view parameter takes the pointer as it is, so
4
+ // the caller's buffer is read and written in place with no copy; a
5
+ // fixed-extent one is reinterpreted as the std::array the function
6
+ // expects. The caller guarantees the length either way.
7
+ // Build (boost includes only if the generated header asks for them,
8
+ // which a numeric kernel's does not):
9
+ // g++ -O2 -std=c++17 -shared -fPIC -I. -o liblasso_design.so lasso_design_capi.cpp
10
+ #include "lasso_design.hpp"
11
+ #include <vector>
12
+ #include <algorithm>
13
+
14
+ extern "C" double scm2cpp_soft_threshold(double z, double g) {
15
+ return soft_threshold(z, g);
16
+ }
17
+ extern "C" int scm2cpp_lasso_design(double* x, double* y, double* resid, double* xnorm, double* beta, double* lams, double* betas, int iters, double tol, int n, int p, int nlam) {
18
+ return lasso_design(x, y, resid, xnorm, beta, lams, betas, iters, tol, n, p, nlam);
19
+ }
@@ -0,0 +1,5 @@
1
+
2
+ #include "lasso_design.hpp"
3
+ // #include "scm2cpp.hpp"
4
+
5
+
@@ -0,0 +1,158 @@
1
+
2
+ #ifndef LASSO_DESIGN_HPP
3
+ #define LASSO_DESIGN_HPP
4
+ #define SCM2CPP_MINIMAL
5
+ #include "scm2cpp-cublas.hpp"
6
+ #include <vector>
7
+ #include "scm2cpp.hpp"
8
+
9
+ SCM2CPP_FN double
10
+ soft_threshold( double z, double g );
11
+ int
12
+ lasso_design( scm2cpp::cspan<double> x, scm2cpp::cspan<double> y, scm2cpp::span<double> resid, scm2cpp::span<double> xnorm, scm2cpp::span<double> beta, scm2cpp::cspan<double> lams, scm2cpp::span<double> betas, int iters, double tol, int n, int p, int nlam );
13
+
14
+
15
+
16
+ SCM2CPP_FN inline double
17
+ soft_threshold( double z, double g )
18
+ {
19
+ if(z > g) {
20
+ return (z-g) ;
21
+ }
22
+ else if(z < (0.0-g)) {
23
+ return (z+g) ;
24
+ }
25
+ else {
26
+ return 0.0 ;
27
+ }
28
+ }
29
+
30
+
31
+ inline int
32
+ lasso_design( scm2cpp::cspan<double> x, scm2cpp::cspan<double> y, scm2cpp::span<double> resid, scm2cpp::span<double> xnorm, scm2cpp::span<double> beta, scm2cpp::cspan<double> lams, scm2cpp::span<double> betas, int iters, double tol, int n, int p, int nlam )
33
+ { int swept = 0;
34
+ if( p < n ) {
35
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
36
+ resid[ i ] = y[i] ;
37
+ } ;
38
+ 0 ;
39
+ std::vector<double> b03446(p,0.0);
40
+ std::vector<double> g3445((p*p),0.0);
41
+ std::vector<double> c3444(p,0.0);
42
+ scm2cpp::device_matrix d3454 = scm2cpp::dmat_upload(x, (n*p), 1);
43
+ scm2cpp::blas_syrk(g3445, d3454, 1.0, 0.0, 1, p, n) ;
44
+ scm2cpp::blas_gemv(c3444, d3454, resid, 1.0, 0.0, 1, p, n) ;
45
+ for( int l = 0 ; !(l == nlam) ; l = (l+1) ) {
46
+ double lam = lams[l];
47
+ int stop = 0;
48
+ for( int sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
49
+ swept = (swept+1) ;
50
+ double maxmove = 0.0;
51
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
52
+ double rho = c3444[j];
53
+ double old = beta[j];
54
+ rho = (rho+(old*g3445[((j*p)+j)])) ;
55
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/g3445[((j*p)+j)]);
56
+ beta[ j ] = bnew ;
57
+ if( !(bnew == old) ) {
58
+ if( (bnew-old) > maxmove ) {
59
+ maxmove = (bnew-old) ;
60
+ } else {
61
+ 0 ;
62
+ } ;
63
+ if( (old-bnew) > maxmove ) {
64
+ maxmove = (old-bnew) ;
65
+ } else {
66
+ 0 ;
67
+ } ;
68
+ b03446[ j ] = (b03446[j]+(bnew-old)) ;
69
+ for( int k3448 = 0 ; !(k3448 == p) ; k3448 = (k3448+1) ) {
70
+ c3444[ k3448 ] = (c3444[k3448]-(g3445[((j*p)+k3448)]*(bnew-old))) ;
71
+ } ;
72
+ } else {
73
+ false ;
74
+ } ;
75
+ ;
76
+ ;
77
+ } ;
78
+ if( maxmove <= tol ) {
79
+ stop = 1 ;
80
+ } else {
81
+ 0 ;
82
+ } ;
83
+ ;
84
+ } ;
85
+ ;
86
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
87
+ betas[ ((l*p)+j) ] = beta[j] ;
88
+ } ;
89
+ ;
90
+ } ;
91
+ scm2cpp::blas_gemv(resid, d3454, b03446, -1.0, 1.0, 0, n, p) ;
92
+ 0 ;
93
+ ;
94
+ ;
95
+ } else {
96
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
97
+ resid[ i ] = y[i] ;
98
+ } ;
99
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
100
+ double acc = 0.0;
101
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
102
+ acc = (acc+(x[((i*p)+j)]*x[((i*p)+j)])) ;
103
+ } ;
104
+ xnorm[ j ] = acc ;
105
+ ;
106
+ } ;
107
+ for( int l = 0 ; !(l == nlam) ; l = (l+1) ) {
108
+ double lam = lams[l];
109
+ int stop = 0;
110
+ for( int sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
111
+ swept = (swept+1) ;
112
+ double maxmove = 0.0;
113
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
114
+ double rho = 0.0;
115
+ double old = beta[j];
116
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
117
+ rho = (rho+(x[((i*p)+j)]*resid[i])) ;
118
+ } ;
119
+ rho = (rho+(old*xnorm[j])) ;
120
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/xnorm[j]);
121
+ beta[ j ] = bnew ;
122
+ if( !(bnew == old) ) {
123
+ if( (bnew-old) > maxmove ) {
124
+ maxmove = (bnew-old) ;
125
+ } else {
126
+ 0 ;
127
+ } ;
128
+ if( (old-bnew) > maxmove ) {
129
+ maxmove = (old-bnew) ;
130
+ } else {
131
+ 0 ;
132
+ } ;
133
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
134
+ resid[ i ] = (resid[i]-(x[((i*p)+j)]*(bnew-old))) ;
135
+ } ;
136
+ } else {
137
+ false ;
138
+ } ;
139
+ ;
140
+ ;
141
+ } ;
142
+ if( maxmove <= tol ) {
143
+ stop = 1 ;
144
+ } else {
145
+ 0 ;
146
+ } ;
147
+ ;
148
+ } ;
149
+ ;
150
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
151
+ betas[ ((l*p)+j) ] = beta[j] ;
152
+ } ;
153
+ ;
154
+ } ;
155
+ } ;
156
+ return swept ;
157
+ }
158
+ #endif // LASSO_DESIGN_HPP
@@ -0,0 +1,19 @@
1
+ // extern "C" wrappers over the translated functions, for Python and
2
+ // any other caller that speaks the C ABI. Array parameters arrive as
3
+ // element pointers: a view parameter takes the pointer as it is, so
4
+ // the caller's buffer is read and written in place with no copy; a
5
+ // fixed-extent one is reinterpreted as the std::array the function
6
+ // expects. The caller guarantees the length either way.
7
+ // Build (boost includes only if the generated header asks for them,
8
+ // which a numeric kernel's does not):
9
+ // g++ -O2 -std=c++17 -shared -fPIC -I. -o liblasso_design.so lasso_design_capi.cpp
10
+ #include "lasso_design.hpp"
11
+ #include <vector>
12
+ #include <algorithm>
13
+
14
+ extern "C" double scm2cpp_soft_threshold(double z, double g) {
15
+ return soft_threshold(z, g);
16
+ }
17
+ extern "C" int scm2cpp_lasso_design(double* x, double* y, double* resid, double* xnorm, double* beta, double* lams, double* betas, int iters, double tol, int n, int p, int nlam) {
18
+ return lasso_design(x, y, resid, xnorm, beta, lams, betas, iters, tol, n, p, nlam);
19
+ }
@@ -0,0 +1,5 @@
1
+
2
+ #include "lasso_design.hpp"
3
+ // #include "scm2cpp.hpp"
4
+
5
+
@@ -0,0 +1,179 @@
1
+
2
+ #ifndef LASSO_DESIGN_HPP
3
+ #define LASSO_DESIGN_HPP
4
+ #define SCM2CPP_MINIMAL
5
+ #include <vector>
6
+ #include "scm2cpp.hpp"
7
+
8
+ SCM2CPP_FN double
9
+ soft_threshold( double z, double g );
10
+ int
11
+ lasso_design( scm2cpp::cspan<double> x, scm2cpp::cspan<double> y, scm2cpp::span<double> resid, scm2cpp::span<double> xnorm, scm2cpp::span<double> beta, scm2cpp::cspan<double> lams, scm2cpp::span<double> betas, int iters, double tol, int n, int p, int nlam );
12
+
13
+
14
+
15
+ SCM2CPP_FN inline double
16
+ soft_threshold( double z, double g )
17
+ {
18
+ if(z > g) {
19
+ return (z-g) ;
20
+ }
21
+ else if(z < (0.0-g)) {
22
+ return (z+g) ;
23
+ }
24
+ else {
25
+ return 0.0 ;
26
+ }
27
+ }
28
+
29
+
30
+ inline int
31
+ lasso_design( scm2cpp::cspan<double> x, scm2cpp::cspan<double> y, scm2cpp::span<double> resid, scm2cpp::span<double> xnorm, scm2cpp::span<double> beta, scm2cpp::cspan<double> lams, scm2cpp::span<double> betas, int iters, double tol, int n, int p, int nlam )
32
+ { int swept = 0;
33
+ if( p < n ) {
34
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
35
+ resid[ i ] = y[i] ;
36
+ } ;
37
+ 0 ;
38
+ std::vector<double> b03446(p,0.0);
39
+ std::vector<double> g3445((p*p),0.0);
40
+ std::vector<double> c3444(p,0.0);
41
+ for( int y2491 = 0 ; !(y2491 == p) ; y2491 = (y2491+1) ) {
42
+ for( int y2492 = y2491 ; !(y2492 == p) ; y2492 = (y2492+1) ) {
43
+ g3445[ ((y2491*p)+y2492) ] = ([&]() -> double { int k2493 = 0; double sum2498 = 0.0; while (!(k2493 == n)) {
44
+ int k2493_next3454 = (k2493+1);
45
+ double sum2498_next3455 = (sum2498+(x[((k2493*p)+y2491)]*x[((k2493*p)+y2492)]));
46
+ k2493 = k2493_next3454;
47
+ sum2498 = sum2498_next3455;
48
+ } return sum2498; })() ;
49
+ g3445[ ((y2492*p)+y2491) ] = g3445[((y2491*p)+y2492)] ;
50
+ } ;
51
+ } ;
52
+ for( int y2494 = 0 ; !(y2494 == p) ; y2494 = (y2494+1) ) {
53
+ c3444[ y2494 ] = ([&]() -> double { int k2495 = 0; double sum2500 = 0.0; while (!(k2495 == n)) {
54
+ int k2495_next3456 = (k2495+1);
55
+ double sum2500_next3457 = (sum2500+(x[((k2495*p)+y2494)]*resid[k2495]));
56
+ k2495 = k2495_next3456;
57
+ sum2500 = sum2500_next3457;
58
+ } return sum2500; })() ;
59
+ } ;
60
+ for( int l = 0 ; !(l == nlam) ; l = (l+1) ) {
61
+ double lam = lams[l];
62
+ int stop = 0;
63
+ for( int sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
64
+ swept = (swept+1) ;
65
+ double maxmove = 0.0;
66
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
67
+ double rho = c3444[j];
68
+ double old = beta[j];
69
+ rho = (rho+(old*g3445[((j*p)+j)])) ;
70
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/g3445[((j*p)+j)]);
71
+ beta[ j ] = bnew ;
72
+ if( !(bnew == old) ) {
73
+ if( (bnew-old) > maxmove ) {
74
+ maxmove = (bnew-old) ;
75
+ } else {
76
+ 0 ;
77
+ } ;
78
+ if( (old-bnew) > maxmove ) {
79
+ maxmove = (old-bnew) ;
80
+ } else {
81
+ 0 ;
82
+ } ;
83
+ b03446[ j ] = (b03446[j]+(bnew-old)) ;
84
+ for( int k3448 = 0 ; !(k3448 == p) ; k3448 = (k3448+1) ) {
85
+ c3444[ k3448 ] = (c3444[k3448]-(g3445[((j*p)+k3448)]*(bnew-old))) ;
86
+ } ;
87
+ } else {
88
+ false ;
89
+ } ;
90
+ ;
91
+ ;
92
+ } ;
93
+ if( maxmove <= tol ) {
94
+ stop = 1 ;
95
+ } else {
96
+ 0 ;
97
+ } ;
98
+ ;
99
+ } ;
100
+ ;
101
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
102
+ betas[ ((l*p)+j) ] = beta[j] ;
103
+ } ;
104
+ ;
105
+ } ;
106
+ for( int y2496 = 0 ; !(y2496 == n) ; y2496 = (y2496+1) ) {
107
+ resid[ y2496 ] = (resid[y2496]-([&]() -> double { int k2497 = 0; double sum2502 = 0.0; while (!(k2497 == p)) {
108
+ int k2497_next3458 = (k2497+1);
109
+ double sum2502_next3459 = (sum2502+(b03446[k2497]*x[((y2496*p)+k2497)]));
110
+ k2497 = k2497_next3458;
111
+ sum2502 = sum2502_next3459;
112
+ } return sum2502; })()) ;
113
+ } ;
114
+ 0 ;
115
+ ;
116
+ } else {
117
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
118
+ resid[ i ] = y[i] ;
119
+ } ;
120
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
121
+ double acc = 0.0;
122
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
123
+ acc = (acc+(x[((i*p)+j)]*x[((i*p)+j)])) ;
124
+ } ;
125
+ xnorm[ j ] = acc ;
126
+ ;
127
+ } ;
128
+ for( int l = 0 ; !(l == nlam) ; l = (l+1) ) {
129
+ double lam = lams[l];
130
+ int stop = 0;
131
+ for( int sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
132
+ swept = (swept+1) ;
133
+ double maxmove = 0.0;
134
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
135
+ double rho = 0.0;
136
+ double old = beta[j];
137
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
138
+ rho = (rho+(x[((i*p)+j)]*resid[i])) ;
139
+ } ;
140
+ rho = (rho+(old*xnorm[j])) ;
141
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/xnorm[j]);
142
+ beta[ j ] = bnew ;
143
+ if( !(bnew == old) ) {
144
+ if( (bnew-old) > maxmove ) {
145
+ maxmove = (bnew-old) ;
146
+ } else {
147
+ 0 ;
148
+ } ;
149
+ if( (old-bnew) > maxmove ) {
150
+ maxmove = (old-bnew) ;
151
+ } else {
152
+ 0 ;
153
+ } ;
154
+ for( int i = 0 ; !(i == n) ; i = (i+1) ) {
155
+ resid[ i ] = (resid[i]-(x[((i*p)+j)]*(bnew-old))) ;
156
+ } ;
157
+ } else {
158
+ false ;
159
+ } ;
160
+ ;
161
+ ;
162
+ } ;
163
+ if( maxmove <= tol ) {
164
+ stop = 1 ;
165
+ } else {
166
+ 0 ;
167
+ } ;
168
+ ;
169
+ } ;
170
+ ;
171
+ for( int j = 0 ; !(j == p) ; j = (j+1) ) {
172
+ betas[ ((l*p)+j) ] = beta[j] ;
173
+ } ;
174
+ ;
175
+ } ;
176
+ } ;
177
+ return swept ;
178
+ }
179
+ #endif // LASSO_DESIGN_HPP