scm2cpp-learn 0.22.0__py3-none-macosx_15_0_arm64.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 (71) hide show
  1. scm2cpp_learn/.dylibs/libgcc_s.1.1.dylib +0 -0
  2. scm2cpp_learn/.dylibs/libgfortran.5.dylib +0 -0
  3. scm2cpp_learn/.dylibs/libomp.dylib +0 -0
  4. scm2cpp_learn/.dylibs/libopenblasp-r0.3.34.dylib +0 -0
  5. scm2cpp_learn/.dylibs/libquadmath.0.dylib +0 -0
  6. scm2cpp_learn/__init__.py +4794 -0
  7. scm2cpp_learn/_classifiers.cpython-312-darwin.so +0 -0
  8. scm2cpp_learn/_compat.py +354 -0
  9. scm2cpp_learn/_generated/__init__.py +0 -0
  10. scm2cpp_learn/_generated/_loader.py +41 -0
  11. scm2cpp_learn/_generated/_loader_accel_cublas.py +185 -0
  12. scm2cpp_learn/_generated/_loader_classifiers.py +308 -0
  13. scm2cpp_learn/_generated/_loader_derived_blas.py +29 -0
  14. scm2cpp_learn/_generated/_loader_derived_cublas.py +29 -0
  15. scm2cpp_learn/_generated/_loader_derived_loops.py +29 -0
  16. scm2cpp_learn/_generated/_loader_gpu_cuda.py +313 -0
  17. scm2cpp_learn/_generated/_loader_gramops_blas.py +836 -0
  18. scm2cpp_learn/_generated/_loader_gramops_loops.py +855 -0
  19. scm2cpp_learn/_generated/_loader_nmf_blas.py +29 -0
  20. scm2cpp_learn/_generated/_loader_nmf_cublas.py +29 -0
  21. scm2cpp_learn/_generated/_loader_nmf_loops.py +29 -0
  22. scm2cpp_learn/_generated/accel_cublas/accel.cpp +26 -0
  23. scm2cpp_learn/_generated/accel_cublas/accel.hpp +1250 -0
  24. scm2cpp_learn/_generated/accel_cublas/accel_capi.cpp +82 -0
  25. scm2cpp_learn/_generated/classifiers.cpp +37 -0
  26. scm2cpp_learn/_generated/classifiers.hpp +3745 -0
  27. scm2cpp_learn/_generated/classifiers_capi.cpp +115 -0
  28. scm2cpp_learn/_generated/derived_blas/lasso_design.cpp +5 -0
  29. scm2cpp_learn/_generated/derived_blas/lasso_design.hpp +156 -0
  30. scm2cpp_learn/_generated/derived_blas/lasso_design_capi.cpp +19 -0
  31. scm2cpp_learn/_generated/derived_cublas/lasso_design.cpp +5 -0
  32. scm2cpp_learn/_generated/derived_cublas/lasso_design.hpp +158 -0
  33. scm2cpp_learn/_generated/derived_cublas/lasso_design_capi.cpp +19 -0
  34. scm2cpp_learn/_generated/derived_loops/lasso_design.cpp +5 -0
  35. scm2cpp_learn/_generated/derived_loops/lasso_design.hpp +179 -0
  36. scm2cpp_learn/_generated/derived_loops/lasso_design_capi.cpp +19 -0
  37. scm2cpp_learn/_generated/gpu_cuda/gpu.cpp +37 -0
  38. scm2cpp_learn/_generated/gpu_cuda/gpu.hpp +3846 -0
  39. scm2cpp_learn/_generated/gpu_cuda/gpu_capi.cpp +308 -0
  40. scm2cpp_learn/_generated/gramops_blas/gramops.cpp +99 -0
  41. scm2cpp_learn/_generated/gramops_blas/gramops.hpp +6655 -0
  42. scm2cpp_learn/_generated/gramops_blas/gramops_capi.cpp +295 -0
  43. scm2cpp_learn/_generated/gramops_loops/gramops.cpp +99 -0
  44. scm2cpp_learn/_generated/gramops_loops/gramops.hpp +7711 -0
  45. scm2cpp_learn/_generated/gramops_loops/gramops_capi.cpp +301 -0
  46. scm2cpp_learn/_generated/lasso_cov.cpp +7 -0
  47. scm2cpp_learn/_generated/lasso_cov.hpp +152 -0
  48. scm2cpp_learn/_generated/lasso_cov_capi.cpp +25 -0
  49. scm2cpp_learn/_generated/nmf_blas/nmf_cd.cpp +5 -0
  50. scm2cpp_learn/_generated/nmf_blas/nmf_cd.hpp +132 -0
  51. scm2cpp_learn/_generated/nmf_blas/nmf_cd_capi.cpp +19 -0
  52. scm2cpp_learn/_generated/nmf_cublas/nmf_cd.cpp +5 -0
  53. scm2cpp_learn/_generated/nmf_cublas/nmf_cd.hpp +136 -0
  54. scm2cpp_learn/_generated/nmf_cublas/nmf_cd_capi.cpp +19 -0
  55. scm2cpp_learn/_generated/nmf_loops/nmf_cd.cpp +5 -0
  56. scm2cpp_learn/_generated/nmf_loops/nmf_cd.hpp +167 -0
  57. scm2cpp_learn/_generated/nmf_loops/nmf_cd_capi.cpp +19 -0
  58. scm2cpp_learn/_generated/scm2cpp-blas.hpp +176 -0
  59. scm2cpp_learn/_generated/scm2cpp-cublas.hpp +155 -0
  60. scm2cpp_learn/_generated/scm2cpp-cuda.hpp +285 -0
  61. scm2cpp_learn/_generated/scm2cpp.hpp +1641 -0
  62. scm2cpp_learn/_gramops_blas.cpython-312-darwin.so +0 -0
  63. scm2cpp_learn/_lasso_cov.cpython-312-darwin.so +0 -0
  64. scm2cpp_learn/_lasso_derived_blas.cpython-312-darwin.so +0 -0
  65. scm2cpp_learn/_libfind.py +153 -0
  66. scm2cpp_learn/_nmf_blas.cpython-312-darwin.so +0 -0
  67. scm2cpp_learn/batch_capi.cu +431 -0
  68. scm2cpp_learn-0.22.0.dist-info/METADATA +1350 -0
  69. scm2cpp_learn-0.22.0.dist-info/RECORD +71 -0
  70. scm2cpp_learn-0.22.0.dist-info/WHEEL +6 -0
  71. scm2cpp_learn-0.22.0.dist-info/top_level.txt +1 -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" std::int64_t scm2cpp_svm_liblinear(double* x, double* y, double* w, double* alpha, double* xnorm, double cost, std::int64_t iters, double tol, std::int64_t seed, std::int64_t n, std::int64_t p) {
15
+ return svm_liblinear(x, y, w, alpha, xnorm, cost, iters, tol, seed, n, p);
16
+ }
17
+ extern "C" std::int64_t scm2cpp_svm_smo(double* k, double* y, double* alpha, double* rho, double cost, std::int64_t iters, double eps, std::int64_t n) {
18
+ return svm_smo(k, y, alpha, rho, cost, iters, eps, n);
19
+ }
20
+ extern "C" std::int64_t scm2cpp_smo_solve(double* k, double* y, double* lin, double* alpha, double* rho, double cost, std::int64_t iters, double eps, std::int64_t n, std::int64_t 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" std::int64_t scm2cpp_shrinkable_P(double* yy, double* a, double* g, double cost, double gmax1, double gmax2, std::int64_t t) {
24
+ return shrinkable_P(yy, a, g, cost, gmax1, gmax2, t);
25
+ }
26
+ extern "C" std::int64_t scm2cpp_swap_position(int* index, int* krow, double* pp, double* yy, double* a, double* g, double* gbar, double* qd, std::int64_t s, std::int64_t t) {
27
+ return swap_position(index, krow, pp, yy, a, g, gbar, qd, s, t);
28
+ }
29
+ extern "C" std::int64_t scm2cpp_reconstruct_gradient(double* k, int* krow, double* pp, double* yy, double* a, double* g, double* gbar, double cost, std::int64_t active, std::int64_t n, std::int64_t nk) {
30
+ return reconstruct_gradient(k, krow, pp, yy, a, g, gbar, cost, active, n, nk);
31
+ }
32
+ extern "C" std::int64_t scm2cpp_select_working_set(double* k, int* krow, double* yy, double* a, double* g, double* qd, double cost, double eps, std::int64_t active, std::int64_t 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" std::int64_t scm2cpp_svr_smo(double* k, double* z, double* beta, double* rho, double cost, double epsilon, std::int64_t iters, double eps, std::int64_t n) {
36
+ return svr_smo(k, z, beta, rho, cost, epsilon, iters, eps, n);
37
+ }
38
+ extern "C" std::int64_t scm2cpp_rbf_from_products(double* g, double* sa, double* sb, double gamma, std::int64_t na, std::int64_t nb) {
39
+ return rbf_from_products(g, sa, sb, gamma, na, nb);
40
+ }
41
+ extern "C" std::int64_t scm2cpp_logistic_l1(double* x, double* y, double* w, double cost, double tol, std::int64_t maxnewton, std::int64_t seed, std::int64_t n, std::int64_t p) {
42
+ return logistic_l1(x, y, w, cost, tol, maxnewton, seed, n, p);
43
+ }
44
+ extern "C" std::int64_t scm2cpp_svr_liblinear(double* x, double* y, double* w, double* beta, double* xnorm, double cost, double epsilon, std::int64_t iters, double tol, std::int64_t seed, std::int64_t n, std::int64_t 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, std::int64_t m, double* w, double* g, double* c, double* l, double* z, double* xm, std::int64_t n, std::int64_t p) {
48
+ return ols_rows(x, y, rows, m, w, g, c, l, z, xm, n, p);
49
+ }
50
+ extern "C" std::int64_t scm2cpp_ransac(double* x, double* y, int* subsets, double* coef, double* mask, double* out, double maxtrials, std::int64_t minsamples, double thresh, double stopprob, std::int64_t n, std::int64_t p) {
51
+ return ransac(x, y, subsets, coef, mask, out, maxtrials, minsamples, thresh, stopprob, n, p);
52
+ }
53
+ extern "C" double scm2cpp_sgd_loss(std::int64_t loss, double y, double p, double epsilon) {
54
+ return sgd_loss(loss, y, p, epsilon);
55
+ }
56
+ extern "C" double scm2cpp_sgd_grad(std::int64_t loss, double y, double p, double epsilon) {
57
+ return sgd_grad(loss, y, p, epsilon);
58
+ }
59
+ extern "C" std::int64_t scm2cpp_sgd(double* x, double* y, double* w, double* out, std::int64_t loss, std::int64_t lr, std::int64_t pen, double alpha, double eta0, double powert, double epsilon, std::int64_t maxiter, double tol, std::int64_t niternochange, std::int64_t fitint, std::int64_t n, std::int64_t 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, std::int64_t 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" std::int64_t scm2cpp_cholesky_delete(double* l, std::int64_t go, std::int64_t n, std::int64_t k) {
72
+ return cholesky_delete(l, go, n, k);
73
+ }
74
+ extern "C" std::int64_t scm2cpp_swap_rc(double* g, std::int64_t a, std::int64_t b, std::int64_t p) {
75
+ return swap_rc(g, a, b, p);
76
+ }
77
+ extern "C" std::int64_t scm2cpp_lars(double* g, double* cov, double* coef, double* path, double* alphas, std::int64_t rec, double nsamples, double alphamin, std::int64_t method, std::int64_t maxiter, double eps, std::int64_t p) {
78
+ return lars(g, cov, coef, path, alphas, rec, nsamples, alphamin, method, maxiter, eps, p);
79
+ }
80
+ extern "C" std::int64_t scm2cpp_svm_l1(double* x, double* y, double* w, double cost, double tol, std::int64_t maxiter, std::int64_t seed, std::int64_t n, std::int64_t 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" std::int64_t scm2cpp_sym_eigen(double* a, double* v, double* ev, double* e, std::int64_t 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" std::int64_t scm2cpp_eig_order(double* ev, int* ord, std::int64_t m) {
96
+ return eig_order(ev, ord, m);
97
+ }
98
+ extern "C" std::int64_t scm2cpp_sym_eigen_top(double* a, double* v, double* ev, double* e, std::int64_t m, std::int64_t k) {
99
+ return sym_eigen_top(a, v, ev, e, m, k);
100
+ }
101
+ extern "C" std::int64_t scm2cpp_sym_eigen_gen(double* a, double* b, double* v, double* ev, double* e, std::int64_t m) {
102
+ return sym_eigen_gen(a, b, v, ev, e, m);
103
+ }
104
+ extern "C" std::int64_t scm2cpp_ts_minnorm(double* x, double* y, int* idx, double* w, double* aa, double* v, double* ev, double* e, double* ab, std::int64_t s, std::int64_t ns, std::int64_t fitint, std::int64_t p, std::int64_t d) {
105
+ return ts_minnorm(x, y, idx, w, aa, v, ev, e, ab, s, ns, fitint, p, d);
106
+ }
107
+ extern "C" std::int64_t 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, std::int64_t s, std::int64_t ns, std::int64_t fitint, std::int64_t p, std::int64_t 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" std::int64_t scm2cpp_theilsen(double* x, double* y, int* idx, double* w, double* coef, std::int64_t nsub, std::int64_t ns, std::int64_t fitint, std::int64_t maxiter, double tol, std::int64_t 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
+ std::int64_t
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, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t 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 std::int64_t
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, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t nlam )
33
+ { std::int64_t swept = 0;
34
+ if( p < n ) {
35
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
36
+ resid[ i ] = y[i] ;
37
+ } ;
38
+ 0 ;
39
+ std::vector<double> b0471(p,0.0);
40
+ std::vector<double> g470((p*p),0.0);
41
+ std::vector<double> c469(p,0.0);
42
+ scm2cpp::blas_syrk(g470, x, 1.0, 0.0, 1, p, n) ;
43
+ scm2cpp::blas_gemv(c469, x, resid, 1.0, 0.0, 1, p, n) ;
44
+ for( std::int64_t l = 0 ; !(l == nlam) ; l = (l+1) ) {
45
+ double lam = lams[l];
46
+ std::int64_t stop = 0;
47
+ for( std::int64_t sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
48
+ swept = (swept+1) ;
49
+ double maxmove = 0.0;
50
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
51
+ double rho = c469[j];
52
+ double old = beta[j];
53
+ rho = (rho+(old*g470[(((long long)j*p)+j)])) ;
54
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/g470[(((long long)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
+ b0471[ j ] = (b0471[j]+(bnew-old)) ;
68
+ for( std::int64_t k473 = 0 ; !(k473 == p) ; k473 = (k473+1) ) {
69
+ c469[ k473 ] = (c469[k473]-(g470[(((long long)j*p)+k473)]*(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( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
86
+ betas[ (((long long)l*p)+j) ] = beta[j] ;
87
+ } ;
88
+ ;
89
+ } ;
90
+ scm2cpp::blas_gemv(resid, x, b0471, -1.0, 1.0, 0, n, p) ;
91
+ 0 ;
92
+ ;
93
+ } else {
94
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
95
+ resid[ i ] = y[i] ;
96
+ } ;
97
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
98
+ double acc = 0.0;
99
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
100
+ acc = (acc+(x[(((long long)i*p)+j)]*x[(((long long)i*p)+j)])) ;
101
+ } ;
102
+ xnorm[ j ] = acc ;
103
+ ;
104
+ } ;
105
+ for( std::int64_t l = 0 ; !(l == nlam) ; l = (l+1) ) {
106
+ double lam = lams[l];
107
+ std::int64_t stop = 0;
108
+ for( std::int64_t sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
109
+ swept = (swept+1) ;
110
+ double maxmove = 0.0;
111
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
112
+ double rho = 0.0;
113
+ double old = beta[j];
114
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
115
+ rho = (rho+(x[(((long long)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( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
132
+ resid[ i ] = (resid[i]-(x[(((long long)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( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
149
+ betas[ (((long long)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" std::int64_t scm2cpp_lasso_design(double* x, double* y, double* resid, double* xnorm, double* beta, double* lams, double* betas, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t 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
+ std::int64_t
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, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t 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 std::int64_t
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, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t nlam )
33
+ { std::int64_t swept = 0;
34
+ if( p < n ) {
35
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
36
+ resid[ i ] = y[i] ;
37
+ } ;
38
+ 0 ;
39
+ std::vector<double> b0471(p,0.0);
40
+ std::vector<double> g470((p*p),0.0);
41
+ std::vector<double> c469(p,0.0);
42
+ scm2cpp::device_matrix d479 = scm2cpp::dmat_upload(x, (n*p), 1);
43
+ scm2cpp::blas_syrk(g470, d479, 1.0, 0.0, 1, p, n) ;
44
+ scm2cpp::blas_gemv(c469, d479, resid, 1.0, 0.0, 1, p, n) ;
45
+ for( std::int64_t l = 0 ; !(l == nlam) ; l = (l+1) ) {
46
+ double lam = lams[l];
47
+ std::int64_t stop = 0;
48
+ for( std::int64_t sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
49
+ swept = (swept+1) ;
50
+ double maxmove = 0.0;
51
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
52
+ double rho = c469[j];
53
+ double old = beta[j];
54
+ rho = (rho+(old*g470[(((long long)j*p)+j)])) ;
55
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/g470[(((long long)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
+ b0471[ j ] = (b0471[j]+(bnew-old)) ;
69
+ for( std::int64_t k473 = 0 ; !(k473 == p) ; k473 = (k473+1) ) {
70
+ c469[ k473 ] = (c469[k473]-(g470[(((long long)j*p)+k473)]*(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( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
87
+ betas[ (((long long)l*p)+j) ] = beta[j] ;
88
+ } ;
89
+ ;
90
+ } ;
91
+ scm2cpp::blas_gemv(resid, d479, b0471, -1.0, 1.0, 0, n, p) ;
92
+ 0 ;
93
+ ;
94
+ ;
95
+ } else {
96
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
97
+ resid[ i ] = y[i] ;
98
+ } ;
99
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
100
+ double acc = 0.0;
101
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
102
+ acc = (acc+(x[(((long long)i*p)+j)]*x[(((long long)i*p)+j)])) ;
103
+ } ;
104
+ xnorm[ j ] = acc ;
105
+ ;
106
+ } ;
107
+ for( std::int64_t l = 0 ; !(l == nlam) ; l = (l+1) ) {
108
+ double lam = lams[l];
109
+ std::int64_t stop = 0;
110
+ for( std::int64_t sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
111
+ swept = (swept+1) ;
112
+ double maxmove = 0.0;
113
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
114
+ double rho = 0.0;
115
+ double old = beta[j];
116
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
117
+ rho = (rho+(x[(((long long)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( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
134
+ resid[ i ] = (resid[i]-(x[(((long long)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( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
151
+ betas[ (((long long)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" std::int64_t scm2cpp_lasso_design(double* x, double* y, double* resid, double* xnorm, double* beta, double* lams, double* betas, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t 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
+ std::int64_t
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, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t 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 std::int64_t
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, std::int64_t iters, double tol, std::int64_t n, std::int64_t p, std::int64_t nlam )
32
+ { std::int64_t swept = 0;
33
+ if( p < n ) {
34
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
35
+ resid[ i ] = y[i] ;
36
+ } ;
37
+ 0 ;
38
+ std::vector<double> b0471(p,0.0);
39
+ std::vector<double> g470((p*p),0.0);
40
+ std::vector<double> c469(p,0.0);
41
+ for( std::int64_t y2501 = 0 ; !(y2501 == p) ; y2501 = (y2501+1) ) {
42
+ for( std::int64_t y2502 = y2501 ; !(y2502 == p) ; y2502 = (y2502+1) ) {
43
+ g470[ (((long long)y2501*p)+y2502) ] = ([&]() -> double { std::int64_t k2503 = 0; double sum2508 = 0.0; while (!(k2503 == n)) {
44
+ std::int64_t k2503_next479 = (k2503+1);
45
+ double sum2508_next480 = (sum2508+(x[(((long long)k2503*p)+y2501)]*x[(((long long)k2503*p)+y2502)]));
46
+ k2503 = k2503_next479;
47
+ sum2508 = sum2508_next480;
48
+ } return sum2508; })() ;
49
+ g470[ (((long long)y2502*p)+y2501) ] = g470[(((long long)y2501*p)+y2502)] ;
50
+ } ;
51
+ } ;
52
+ for( std::int64_t y2504 = 0 ; !(y2504 == p) ; y2504 = (y2504+1) ) {
53
+ c469[ y2504 ] = ([&]() -> double { std::int64_t k2505 = 0; double sum2510 = 0.0; while (!(k2505 == n)) {
54
+ std::int64_t k2505_next481 = (k2505+1);
55
+ double sum2510_next482 = (sum2510+(x[(((long long)k2505*p)+y2504)]*resid[k2505]));
56
+ k2505 = k2505_next481;
57
+ sum2510 = sum2510_next482;
58
+ } return sum2510; })() ;
59
+ } ;
60
+ for( std::int64_t l = 0 ; !(l == nlam) ; l = (l+1) ) {
61
+ double lam = lams[l];
62
+ std::int64_t stop = 0;
63
+ for( std::int64_t sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
64
+ swept = (swept+1) ;
65
+ double maxmove = 0.0;
66
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
67
+ double rho = c469[j];
68
+ double old = beta[j];
69
+ rho = (rho+(old*g470[(((long long)j*p)+j)])) ;
70
+ double bnew = (soft_threshold(rho,double((lam*(1.0*n))))/g470[(((long long)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
+ b0471[ j ] = (b0471[j]+(bnew-old)) ;
84
+ for( std::int64_t k473 = 0 ; !(k473 == p) ; k473 = (k473+1) ) {
85
+ c469[ k473 ] = (c469[k473]-(g470[(((long long)j*p)+k473)]*(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( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
102
+ betas[ (((long long)l*p)+j) ] = beta[j] ;
103
+ } ;
104
+ ;
105
+ } ;
106
+ for( std::int64_t y2506 = 0 ; !(y2506 == n) ; y2506 = (y2506+1) ) {
107
+ resid[ y2506 ] = (resid[y2506]-([&]() -> double { std::int64_t k2507 = 0; double sum2512 = 0.0; while (!(k2507 == p)) {
108
+ std::int64_t k2507_next483 = (k2507+1);
109
+ double sum2512_next484 = (sum2512+(b0471[k2507]*x[(((long long)y2506*p)+k2507)]));
110
+ k2507 = k2507_next483;
111
+ sum2512 = sum2512_next484;
112
+ } return sum2512; })()) ;
113
+ } ;
114
+ 0 ;
115
+ ;
116
+ } else {
117
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
118
+ resid[ i ] = y[i] ;
119
+ } ;
120
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
121
+ double acc = 0.0;
122
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
123
+ acc = (acc+(x[(((long long)i*p)+j)]*x[(((long long)i*p)+j)])) ;
124
+ } ;
125
+ xnorm[ j ] = acc ;
126
+ ;
127
+ } ;
128
+ for( std::int64_t l = 0 ; !(l == nlam) ; l = (l+1) ) {
129
+ double lam = lams[l];
130
+ std::int64_t stop = 0;
131
+ for( std::int64_t sweep = 0 ; !((sweep == iters || stop == 1)) ; sweep = (sweep+1) ) {
132
+ swept = (swept+1) ;
133
+ double maxmove = 0.0;
134
+ for( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
135
+ double rho = 0.0;
136
+ double old = beta[j];
137
+ for( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
138
+ rho = (rho+(x[(((long long)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( std::int64_t i = 0 ; !(i == n) ; i = (i+1) ) {
155
+ resid[ i ] = (resid[i]-(x[(((long long)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( std::int64_t j = 0 ; !(j == p) ; j = (j+1) ) {
172
+ betas[ (((long long)l*p)+j) ] = beta[j] ;
173
+ } ;
174
+ ;
175
+ } ;
176
+ } ;
177
+ return swept ;
178
+ }
179
+ #endif // LASSO_DESIGN_HPP