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,354 @@
1
+ """The scikit-learn estimator interface, with scikit-learn optional.
2
+
3
+ With scikit-learn installed the estimators derive from its
4
+ BaseEstimator and mixins, and their inputs go through its
5
+ validate_data, so clone, get_params / set_params, GridSearchCV,
6
+ Pipeline and check_estimator see ordinary estimators. Without it
7
+ (numpy alone, as the wheels need) a small stand-in gives the same
8
+ get_params / set_params / score and the checks that matter for the
9
+ kernels: a 2-D float64 C-ordered X, finite values, the feature count
10
+ remembered at fit and compared at predict.
11
+ """
12
+ import inspect
13
+
14
+ import numpy as np
15
+
16
+ try:
17
+ from sklearn.base import (BaseEstimator, ClassifierMixin, RegressorMixin,
18
+ TransformerMixin, DensityMixin)
19
+ from sklearn.utils.validation import check_is_fitted
20
+ from sklearn.utils.multiclass import check_classification_targets
21
+ try:
22
+ from sklearn.utils.validation import validate_data as _sk_validate
23
+ except ImportError: # scikit-learn before 1.6
24
+ def _sk_validate(est, *args, **kw):
25
+ return est._validate_data(*args, **kw)
26
+ HAVE_SKLEARN = True
27
+ except ImportError:
28
+ HAVE_SKLEARN = False
29
+
30
+ class NotFittedError(ValueError, AttributeError):
31
+ pass
32
+
33
+ class BaseEstimator:
34
+ @classmethod
35
+ def _get_param_names(cls):
36
+ sig = inspect.signature(cls.__init__)
37
+ return sorted(p.name for p in sig.parameters.values()
38
+ if p.name != "self" and p.kind not in
39
+ (p.VAR_POSITIONAL, p.VAR_KEYWORD))
40
+
41
+ def get_params(self, deep=True):
42
+ return {k: getattr(self, k) for k in self._get_param_names()}
43
+
44
+ def set_params(self, **params):
45
+ valid = self._get_param_names()
46
+ for k, v in params.items():
47
+ if k not in valid:
48
+ raise ValueError(f"invalid parameter {k!r} for {type(self).__name__}")
49
+ setattr(self, k, v)
50
+ return self
51
+
52
+ def __repr__(self):
53
+ args = ", ".join(f"{k}={v!r}" for k, v in self.get_params().items())
54
+ return f"{type(self).__name__}({args})"
55
+
56
+ class ClassifierMixin:
57
+ _estimator_type = "classifier"
58
+
59
+ def score(self, X, y, sample_weight=None):
60
+ return float(np.average(self.predict(X) == np.asarray(y),
61
+ weights=sample_weight))
62
+
63
+ class RegressorMixin:
64
+ _estimator_type = "regressor"
65
+
66
+ def score(self, X, y, sample_weight=None):
67
+ y = np.asarray(y, dtype=np.float64)
68
+ r = y - self.predict(X)
69
+ w = None if sample_weight is None else np.asarray(sample_weight)
70
+ ss_res = np.average(r * r, axis=0, weights=w)
71
+ ym = np.average(y, axis=0, weights=w)
72
+ ss_tot = np.average((y - ym) ** 2, axis=0, weights=w)
73
+ return float(np.mean(1.0 - ss_res / ss_tot))
74
+
75
+ class TransformerMixin:
76
+ def fit_transform(self, X, y=None, **fit_params):
77
+ return self.fit(X, y, **fit_params).transform(X)
78
+
79
+ class DensityMixin:
80
+ _estimator_type = "DensityEstimator"
81
+
82
+ def score(self, X, y=None):
83
+ pass
84
+
85
+ def check_is_fitted(est, attributes=None):
86
+ if not any(k.endswith("_") and not k.startswith("__") for k in vars(est)):
87
+ raise NotFittedError(f"This {type(est).__name__} instance is not fitted yet; "
88
+ "call fit first")
89
+
90
+ def check_classification_targets(y):
91
+ if np.asarray(y).dtype.kind == "f" and not np.all(np.mod(y, 1) == 0):
92
+ raise ValueError("Unknown label type: continuous")
93
+
94
+ def _as_x(X):
95
+ X = np.ascontiguousarray(X, dtype=np.float64)
96
+ if X.ndim != 2:
97
+ raise ValueError(f"Expected a 2D array, got {X.ndim}D; reshape it")
98
+ if X.shape[0] < 1 or X.shape[1] < 1:
99
+ raise ValueError(f"Found array with shape {X.shape}; a minimum of 1 is required")
100
+ with np.errstate(over="ignore", invalid="ignore"):
101
+ finite = np.isfinite(X.sum()) or np.isfinite(X).all()
102
+ if not finite:
103
+ raise ValueError("Input X contains NaN or infinity")
104
+ return X
105
+
106
+ def _sk_validate(est, X="no_validation", y="no_validation", reset=True,
107
+ multi_output=False, y_numeric=False, dtype=None, order=None,
108
+ ensure_min_samples=1, ensure_min_features=1, **kw):
109
+ out = []
110
+ if not (isinstance(X, str) and X == "no_validation"):
111
+ X = _as_x(X)
112
+ if X.shape[0] < ensure_min_samples or X.shape[1] < ensure_min_features:
113
+ raise ValueError(f"Found array with shape {X.shape}; a minimum of "
114
+ f"{ensure_min_samples} samples and {ensure_min_features} "
115
+ f"features is required by {type(est).__name__}")
116
+ if reset:
117
+ est.n_features_in_ = X.shape[1]
118
+ elif X.shape[1] != getattr(est, "n_features_in_", X.shape[1]):
119
+ raise ValueError(f"X has {X.shape[1]} features, but {type(est).__name__} "
120
+ f"is expecting {est.n_features_in_} features as input")
121
+ out.append(X)
122
+ if not (isinstance(y, str) and y == "no_validation"):
123
+ if y is None:
124
+ raise ValueError(f"{type(est).__name__} requires y to be passed, "
125
+ "but the target y is None")
126
+ y = np.asarray(y)
127
+ if not multi_output and y.ndim == 2 and y.shape[1] == 1:
128
+ y = y.ravel()
129
+ if y_numeric or y.dtype.kind in "biuf":
130
+ y = np.ascontiguousarray(y, dtype=np.float64) if y_numeric else y
131
+ if out and len(y) != out[0].shape[0]:
132
+ raise ValueError("X and y have inconsistent numbers of samples")
133
+ out.append(y)
134
+ return out[0] if len(out) == 1 else tuple(out)
135
+
136
+
137
+ __all__ = ["BaseEstimator", "ClassifierMixin", "RegressorMixin", "TransformerMixin",
138
+ "DensityMixin", "check_is_fitted", "HAVE_SKLEARN",
139
+ "fit_xy", "fit_x", "pred_x", "classes_of", "Tagged", "as_csr"]
140
+
141
+
142
+ # The fast path. scikit-learn's validate_data costs about 100 us a
143
+ # call whatever the size (feature names, array namespaces, the config),
144
+ # which is most of a small fit and nearly all of a small predict. An
145
+ # input that is already what the kernels take -- a plain ndarray,
146
+ # float64, C-ordered, 2-D, non-empty, finite -- needs none of that
147
+ # machinery, so it is checked here directly; anything else (a list, a
148
+ # DataFrame, another dtype, NaN, a wrong feature count) goes through
149
+ # validate_data, which raises the error scikit-learn would. Finiteness
150
+ # is tested by one sum, as scikit-learn tests it first, and skipped
151
+ # under sklearn.set_config(assume_finite=True).
152
+ if HAVE_SKLEARN:
153
+ from sklearn import get_config as _get_config
154
+
155
+ def _assume_finite():
156
+ return _get_config()["assume_finite"]
157
+ else:
158
+ def _assume_finite():
159
+ return False
160
+
161
+
162
+ def _plain(X):
163
+ return (type(X) is np.ndarray and X.dtype == np.float64 and X.ndim == 2
164
+ and X.flags.c_contiguous and X.shape[0] > 0 and X.shape[1] > 0)
165
+
166
+
167
+ def _finite(a):
168
+ if _assume_finite():
169
+ return True
170
+ with np.errstate(over="ignore", invalid="ignore"):
171
+ return bool(np.isfinite(a.sum()))
172
+
173
+
174
+ def _labels_ok(y):
175
+ # what check_classification_targets accepts, in the cheap cases:
176
+ # integer or boolean labels, or floats that are all integral
177
+ k = y.dtype.kind
178
+ if k in "biu":
179
+ return True
180
+ if k == "f":
181
+ with np.errstate(invalid="ignore"):
182
+ return bool(np.isfinite(y.sum())) and bool((y == np.floor(y)).all())
183
+ return False
184
+
185
+
186
+ def _reset_names(est):
187
+ # what validate_data does on fit with an ndarray: no feature names
188
+ if "feature_names_in_" in vars(est):
189
+ del est.feature_names_in_
190
+
191
+
192
+ def _issparse(X):
193
+ try:
194
+ import scipy.sparse as sp
195
+ except ImportError:
196
+ return False
197
+ return sp.issparse(X)
198
+
199
+
200
+ def as_csr(X):
201
+ """X (any scipy.sparse format) as CSR the kernels take: float64 data,
202
+ int32 column indices, int64 row pointers (so nnz may pass 2^31; the
203
+ rows and columns, which index into both CSR and CSC, may not). The
204
+ caller's matrix is not changed; duplicate entries may stay (both
205
+ kernels add them, which is what they mean)."""
206
+ X = X.tocsr()
207
+ if X.dtype != np.float64:
208
+ X = X.astype(np.float64)
209
+ if max(X.shape) >= 2 ** 31:
210
+ raise ValueError("a sparse X with 2^31 or more rows or columns is not taken")
211
+ if X.indices.dtype != np.int32 or X.indptr.dtype != np.int64:
212
+ X = X.copy()
213
+ X.indices, X.indptr = X.indices.astype(np.int32), X.indptr.astype(np.int64)
214
+ return X
215
+
216
+
217
+ def _sparse_validate(est, X, *args, reset=True, **kw):
218
+ # a sparse X for an estimator that takes one (_sparse): scikit-learn's
219
+ # checks with accept_sparse, then CSR; without scikit-learn, the shape
220
+ if HAVE_SKLEARN:
221
+ kw.pop("order", None)
222
+ out = _sk_validate(est, X, *args, reset=reset, accept_sparse=True, **kw)
223
+ X, rest = (out[0], out[1:]) if isinstance(out, tuple) else (out, ())
224
+ else:
225
+ rest = ()
226
+ if args:
227
+ y = np.asarray(args[0])
228
+ if not kw.get("multi_output") and y.ndim == 2 and y.shape[1] == 1:
229
+ y = y.ravel()
230
+ if kw.get("y_numeric"):
231
+ y = np.ascontiguousarray(y, dtype=np.float64)
232
+ if len(y) != X.shape[0]:
233
+ raise ValueError("X and y have inconsistent numbers of samples")
234
+ rest = (y,)
235
+ if reset:
236
+ est.n_features_in_ = X.shape[1]
237
+ elif X.shape[1] != getattr(est, "n_features_in_", X.shape[1]):
238
+ raise ValueError(f"X has {X.shape[1]} features, but {type(est).__name__} "
239
+ f"is expecting {est.n_features_in_} features as input")
240
+ X = as_csr(X)
241
+ return (X,) + tuple(rest) if rest else X
242
+
243
+
244
+ def fit_xy(est, X, y, *, y_numeric=True, multi_output=False, classifier=False):
245
+ """X as a float64 C-ordered 2-D array and y, validated, n_features_in_ set
246
+ (a scipy.sparse X, for an estimator with _sparse, as CSR)."""
247
+ if getattr(est, "_sparse", False) and _issparse(X):
248
+ X, y = _sparse_validate(est, X, y, dtype=np.float64, multi_output=multi_output,
249
+ y_numeric=y_numeric and not classifier)
250
+ if classifier:
251
+ check_classification_targets(y)
252
+ elif y_numeric:
253
+ y = np.ascontiguousarray(y, dtype=np.float64)
254
+ return X, y
255
+ if (_plain(X) and type(y) is np.ndarray and y.shape[0:1] == X.shape[0:1]
256
+ and (y.ndim == 1 or (multi_output and y.ndim == 2 and y.shape[1] > 1))
257
+ and _finite(X)):
258
+ if classifier:
259
+ ok = _labels_ok(y)
260
+ elif y_numeric:
261
+ ok = y.dtype == np.float64 and y.flags.c_contiguous and _finite(y)
262
+ else:
263
+ ok = y.dtype.kind in "biuf" and _finite(y)
264
+ if ok:
265
+ est.n_features_in_ = X.shape[1]
266
+ _reset_names(est)
267
+ return X, y
268
+ X, y = _sk_validate(est, X, y, dtype=np.float64, order="C",
269
+ y_numeric=y_numeric and not classifier, multi_output=multi_output)
270
+ if classifier:
271
+ check_classification_targets(y)
272
+ elif y_numeric:
273
+ y = np.ascontiguousarray(y, dtype=np.float64)
274
+ return X, y
275
+
276
+
277
+ def fit_x(est, X, ensure_min_samples=1, ensure_min_features=1):
278
+ """X alone (unsupervised fit), validated, n_features_in_ set."""
279
+ if getattr(est, "_sparse", False) and _issparse(X):
280
+ return _sparse_validate(est, X, dtype=np.float64, ensure_min_samples=ensure_min_samples,
281
+ ensure_min_features=ensure_min_features)
282
+ if (_plain(X) and X.shape[0] >= ensure_min_samples and X.shape[1] >= ensure_min_features
283
+ and _finite(X)):
284
+ est.n_features_in_ = X.shape[1]
285
+ _reset_names(est)
286
+ return X
287
+ return _sk_validate(est, X, dtype=np.float64, order="C",
288
+ ensure_min_samples=ensure_min_samples,
289
+ ensure_min_features=ensure_min_features)
290
+
291
+
292
+ def pred_x(est, X, **kw):
293
+ """X at predict / transform time: fitted, and as many features as at fit."""
294
+ d = vars(est)
295
+ if getattr(est, "_sparse", False) and _issparse(X):
296
+ check_is_fitted(est)
297
+ return _sparse_validate(est, X, reset=False, dtype=np.float64, **kw)
298
+ if (not kw and _plain(X) and X.shape[1] == d.get("n_features_in_")
299
+ and "feature_names_in_" not in d and _finite(X)):
300
+ return X
301
+ check_is_fitted(est)
302
+ return _sk_validate(est, X, reset=False, dtype=np.float64, order="C", **kw)
303
+
304
+
305
+ def classes_of(y):
306
+ """classes_ and the 0-based label index, as LabelEncoder has them."""
307
+ return np.unique(np.asarray(y), return_inverse=True)
308
+
309
+
310
+ class Tagged:
311
+ """Declares scikit-learn tags from a few class attributes.
312
+
313
+ _binary_only: the solver is a two-class one (multi_class False).
314
+ _positive_X / _positive_y: the input or target must be non-negative.
315
+ _multi_output: y may be (n, k), and must be for _multi_output == "only".
316
+ _sparse: fit and predict take a scipy.sparse X (as_csr's CSR reaches fit).
317
+ _no_y: an unsupervised fit (y ignored).
318
+ """
319
+ _binary_only = False
320
+ _positive_X = False
321
+ _positive_y = False
322
+ _multi_output = False
323
+ _pairwise = False
324
+ _sparse = False
325
+
326
+ def __sklearn_tags__(self):
327
+ tags = super().__sklearn_tags__()
328
+ tags.input_tags.sparse = self._sparse
329
+ tags.input_tags.positive_only = self._positive_X
330
+ tags.input_tags.pairwise = bool(self._pairwise_now())
331
+ if tags.target_tags is not None:
332
+ tags.target_tags.positive_only = self._positive_y
333
+ if self._multi_output:
334
+ tags.target_tags.multi_output = True
335
+ if self._multi_output == "only":
336
+ tags.target_tags.single_output = False
337
+ if self._binary_only and tags.classifier_tags is not None:
338
+ tags.classifier_tags.multi_class = False
339
+ return tags
340
+
341
+ def _more_tags(self): # scikit-learn before 1.6
342
+ t = {"binary_only": self._binary_only, "pairwise": bool(self._pairwise_now())}
343
+ if self._positive_X:
344
+ t["requires_positive_X"] = True
345
+ if self._positive_y:
346
+ t["requires_positive_y"] = True
347
+ if self._multi_output:
348
+ t["multioutput"] = True
349
+ if self._multi_output == "only":
350
+ t["multioutput_only"] = True
351
+ return t
352
+
353
+ def _pairwise_now(self):
354
+ return self._pairwise and getattr(self, "kernel", None) == "precomputed"
File without changes
@@ -0,0 +1,41 @@
1
+ # ctypes loader for liblasso_cov.so, generated alongside it.
2
+ # Arrays are numpy arrays of the declared dtype; they are made
3
+ # contiguous on the way in and mutated in place where the translated
4
+ # function mutates them.
5
+ import ctypes
6
+ import numpy as np
7
+ from pathlib import Path
8
+
9
+ from .._libfind import load_kernel_lib as _load_kernel_lib
10
+
11
+ _lib = _load_kernel_lib()
12
+
13
+ _lib.scm2cpp_soft_threshold.restype = ctypes.c_double
14
+ _lib.scm2cpp_soft_threshold.argtypes = [ctypes.c_double, ctypes.c_double]
15
+ def soft_threshold(z, g):
16
+ return _lib.scm2cpp_soft_threshold(z, g)
17
+
18
+ _lib.scm2cpp_cov_descend.restype = ctypes.c_int64
19
+ _lib.scm2cpp_cov_descend.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_double, ctypes.c_int64, ctypes.c_double, ctypes.c_int64]
20
+ def cov_descend(g, c, beta, lam, iters, nobs, p):
21
+ g = np.ascontiguousarray(g, dtype=np.float64)
22
+ c = np.ascontiguousarray(c, dtype=np.float64)
23
+ beta = np.ascontiguousarray(beta, dtype=np.float64)
24
+ return _lib.scm2cpp_cov_descend(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), c.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), beta.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), lam, iters, nobs, p)
25
+
26
+ _lib.scm2cpp_enet_descend.restype = ctypes.c_int64
27
+ _lib.scm2cpp_enet_descend.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_double, ctypes.c_double, ctypes.c_int64, ctypes.c_double, ctypes.c_int64]
28
+ def enet_descend(g, c, beta, lam1, lam2, iters, nobs, p):
29
+ g = np.ascontiguousarray(g, dtype=np.float64)
30
+ c = np.ascontiguousarray(c, dtype=np.float64)
31
+ beta = np.ascontiguousarray(beta, dtype=np.float64)
32
+ return _lib.scm2cpp_enet_descend(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), c.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), beta.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), lam1, lam2, iters, nobs, p)
33
+
34
+ _lib.scm2cpp_mt_descend.restype = ctypes.c_int64
35
+ _lib.scm2cpp_mt_descend.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_double, ctypes.c_double, ctypes.c_int64, ctypes.c_double, ctypes.c_int64, ctypes.c_int64]
36
+ def mt_descend(g, c, w, lam1, lam2, iters, nobs, p, ntask):
37
+ g = np.ascontiguousarray(g, dtype=np.float64)
38
+ c = np.ascontiguousarray(c, dtype=np.float64)
39
+ w = np.ascontiguousarray(w, dtype=np.float64)
40
+ return _lib.scm2cpp_mt_descend(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), c.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), w.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), lam1, lam2, iters, nobs, p, ntask)
41
+
@@ -0,0 +1,185 @@
1
+ # ctypes loader for libaccel.so, generated alongside it.
2
+ # Arrays are numpy arrays of the declared dtype; they are made
3
+ # contiguous on the way in and mutated in place where the translated
4
+ # function mutates them.
5
+ import ctypes
6
+ import numpy as np
7
+ from pathlib import Path
8
+
9
+ from .._libfind import load_accel_lib as _load_accel_lib
10
+
11
+ _lib = _load_accel_lib()
12
+
13
+ _lib.scm2cpp_f_regression.restype = ctypes.c_int64
14
+ _lib.scm2cpp_f_regression.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64, ctypes.c_int64, ctypes.c_int64]
15
+ def f_regression(x, y, r, f, center, n, p, q):
16
+ x = np.ascontiguousarray(x, dtype=np.float64)
17
+ y = np.ascontiguousarray(y, dtype=np.float64)
18
+ r = np.ascontiguousarray(r, dtype=np.float64)
19
+ f = np.ascontiguousarray(f, dtype=np.float64)
20
+ return _lib.scm2cpp_f_regression(x.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), y.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), r.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), f.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), center, n, p, q)
21
+
22
+ _lib.scm2cpp_f_classif.restype = ctypes.c_int64
23
+ _lib.scm2cpp_f_classif.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64, ctypes.c_int64]
24
+ def f_classif(x, lab, f, n, p, k):
25
+ x = np.ascontiguousarray(x, dtype=np.float64)
26
+ lab = np.ascontiguousarray(lab, dtype=np.int32)
27
+ f = np.ascontiguousarray(f, dtype=np.float64)
28
+ return _lib.scm2cpp_f_classif(x.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), lab.ctypes.data_as(ctypes.POINTER(ctypes.c_int)), f.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), n, p, k)
29
+
30
+ _lib.scm2cpp_min_pos.restype = ctypes.c_double
31
+ _lib.scm2cpp_min_pos.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_int64]
32
+ def min_pos(v, m):
33
+ v = np.ascontiguousarray(v, dtype=np.float64)
34
+ return _lib.scm2cpp_min_pos(v.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), m)
35
+
36
+ _lib.scm2cpp_round_even.restype = ctypes.c_double
37
+ _lib.scm2cpp_round_even.argtypes = [ctypes.c_double]
38
+ def round_even(y):
39
+ return _lib.scm2cpp_round_even(y)
40
+
41
+ _lib.scm2cpp_cholesky_delete.restype = ctypes.c_int64
42
+ _lib.scm2cpp_cholesky_delete.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64, ctypes.c_int64]
43
+ def cholesky_delete(l, go, n, k):
44
+ l = np.ascontiguousarray(l, dtype=np.float64)
45
+ return _lib.scm2cpp_cholesky_delete(l.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), go, n, k)
46
+
47
+ _lib.scm2cpp_swap_rc.restype = ctypes.c_int64
48
+ _lib.scm2cpp_swap_rc.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64, ctypes.c_int64]
49
+ def swap_rc(g, a, b, p):
50
+ g = np.ascontiguousarray(g, dtype=np.float64)
51
+ return _lib.scm2cpp_swap_rc(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), a, b, p)
52
+
53
+ _lib.scm2cpp_lars.restype = ctypes.c_int64
54
+ _lib.scm2cpp_lars.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_double, ctypes.c_double, ctypes.c_int64, ctypes.c_int64, ctypes.c_double, ctypes.c_int64]
55
+ def lars(g, cov, coef, path, alphas, rec, nsamples, alphamin, method, maxiter, eps, p):
56
+ g = np.ascontiguousarray(g, dtype=np.float64)
57
+ cov = np.ascontiguousarray(cov, dtype=np.float64)
58
+ coef = np.ascontiguousarray(coef, dtype=np.float64)
59
+ path = np.ascontiguousarray(path, dtype=np.float64)
60
+ alphas = np.ascontiguousarray(alphas, dtype=np.float64)
61
+ return _lib.scm2cpp_lars(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), cov.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), coef.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), path.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), alphas.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), rec, nsamples, alphamin, method, maxiter, eps, p)
62
+
63
+ _lib.scm2cpp_rfe_chol.restype = ctypes.c_int64
64
+ _lib.scm2cpp_rfe_chol.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_double), ctypes.c_double, ctypes.c_int64, ctypes.c_int64]
65
+ def rfe_chol(g, idx, l, alpha, k, p):
66
+ g = np.ascontiguousarray(g, dtype=np.float64)
67
+ idx = np.ascontiguousarray(idx, dtype=np.int32)
68
+ l = np.ascontiguousarray(l, dtype=np.float64)
69
+ return _lib.scm2cpp_rfe_chol(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), idx.ctypes.data_as(ctypes.POINTER(ctypes.c_int)), l.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), alpha, k, p)
70
+
71
+ _lib.scm2cpp_rfe_solve.restype = ctypes.c_int64
72
+ _lib.scm2cpp_rfe_solve.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64]
73
+ def rfe_solve(c, idx, w, l, k, p):
74
+ c = np.ascontiguousarray(c, dtype=np.float64)
75
+ idx = np.ascontiguousarray(idx, dtype=np.int32)
76
+ w = np.ascontiguousarray(w, dtype=np.float64)
77
+ l = np.ascontiguousarray(l, dtype=np.float64)
78
+ return _lib.scm2cpp_rfe_solve(c.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), idx.ctypes.data_as(ctypes.POINTER(ctypes.c_int)), w.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), l.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), k, p)
79
+
80
+ _lib.scm2cpp_rfe.restype = ctypes.c_int64
81
+ _lib.scm2cpp_rfe.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.c_double, ctypes.c_int64, ctypes.c_int64, ctypes.c_int64, ctypes.c_int64]
82
+ def rfe(x, y, coef, support, ranking, alpha, nsel, step, n, p):
83
+ x = np.ascontiguousarray(x, dtype=np.float64)
84
+ y = np.ascontiguousarray(y, dtype=np.float64)
85
+ coef = np.ascontiguousarray(coef, dtype=np.float64)
86
+ support = np.ascontiguousarray(support, dtype=np.int32)
87
+ ranking = np.ascontiguousarray(ranking, dtype=np.int32)
88
+ return _lib.scm2cpp_rfe(x.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), y.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), coef.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), support.ctypes.data_as(ctypes.POINTER(ctypes.c_int)), ranking.ctypes.data_as(ctypes.POINTER(ctypes.c_int)), alpha, nsel, step, n, p)
89
+
90
+ _lib.scm2cpp_eig_hypot.restype = ctypes.c_double
91
+ _lib.scm2cpp_eig_hypot.argtypes = [ctypes.c_double, ctypes.c_double]
92
+ def eig_hypot(a, b):
93
+ return _lib.scm2cpp_eig_hypot(a, b)
94
+
95
+ _lib.scm2cpp_sym_eigen.restype = ctypes.c_int64
96
+ _lib.scm2cpp_sym_eigen.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64]
97
+ def sym_eigen(a, v, ev, e, m):
98
+ a = np.ascontiguousarray(a, dtype=np.float64)
99
+ v = np.ascontiguousarray(v, dtype=np.float64)
100
+ ev = np.ascontiguousarray(ev, dtype=np.float64)
101
+ e = np.ascontiguousarray(e, dtype=np.float64)
102
+ return _lib.scm2cpp_sym_eigen(a.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), v.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ev.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), e.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), m)
103
+
104
+ _lib.scm2cpp_eig_abs.restype = ctypes.c_double
105
+ _lib.scm2cpp_eig_abs.argtypes = [ctypes.c_double]
106
+ def eig_abs(a):
107
+ return _lib.scm2cpp_eig_abs(a)
108
+
109
+ _lib.scm2cpp_eig_order.restype = ctypes.c_int64
110
+ _lib.scm2cpp_eig_order.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_int), ctypes.c_int64]
111
+ def eig_order(ev, ord, m):
112
+ ev = np.ascontiguousarray(ev, dtype=np.float64)
113
+ ord = np.ascontiguousarray(ord, dtype=np.int32)
114
+ return _lib.scm2cpp_eig_order(ev.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ord.ctypes.data_as(ctypes.POINTER(ctypes.c_int)), m)
115
+
116
+ _lib.scm2cpp_sym_eigen_top.restype = ctypes.c_int64
117
+ _lib.scm2cpp_sym_eigen_top.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64]
118
+ def sym_eigen_top(a, v, ev, e, m, k):
119
+ a = np.ascontiguousarray(a, dtype=np.float64)
120
+ v = np.ascontiguousarray(v, dtype=np.float64)
121
+ ev = np.ascontiguousarray(ev, dtype=np.float64)
122
+ e = np.ascontiguousarray(e, dtype=np.float64)
123
+ return _lib.scm2cpp_sym_eigen_top(a.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), v.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ev.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), e.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), m, k)
124
+
125
+ _lib.scm2cpp_sym_eigen_gen.restype = ctypes.c_int64
126
+ _lib.scm2cpp_sym_eigen_gen.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64]
127
+ def sym_eigen_gen(a, b, v, ev, e, m):
128
+ a = np.ascontiguousarray(a, dtype=np.float64)
129
+ b = np.ascontiguousarray(b, dtype=np.float64)
130
+ v = np.ascontiguousarray(v, dtype=np.float64)
131
+ ev = np.ascontiguousarray(ev, dtype=np.float64)
132
+ e = np.ascontiguousarray(e, dtype=np.float64)
133
+ return _lib.scm2cpp_sym_eigen_gen(a.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), b.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), v.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ev.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), e.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), m)
134
+
135
+ _lib.scm2cpp_pca.restype = ctypes.c_int64
136
+ _lib.scm2cpp_pca.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64]
137
+ def pca(x, comps, ev, sv, mean, n, p):
138
+ x = np.ascontiguousarray(x, dtype=np.float64)
139
+ comps = np.ascontiguousarray(comps, dtype=np.float64)
140
+ ev = np.ascontiguousarray(ev, dtype=np.float64)
141
+ sv = np.ascontiguousarray(sv, dtype=np.float64)
142
+ mean = np.ascontiguousarray(mean, dtype=np.float64)
143
+ return _lib.scm2cpp_pca(x.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), comps.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), ev.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), sv.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), mean.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), n, p)
144
+
145
+ _lib.scm2cpp_gram_xx.restype = ctypes.c_int64
146
+ _lib.scm2cpp_gram_xx.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64]
147
+ def gram_xx(x, g, n, p):
148
+ x = np.ascontiguousarray(x, dtype=np.float64)
149
+ g = np.ascontiguousarray(g, dtype=np.float64)
150
+ return _lib.scm2cpp_gram_xx(x.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), n, p)
151
+
152
+ _lib.scm2cpp_gram_xy.restype = ctypes.c_int64
153
+ _lib.scm2cpp_gram_xy.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64, ctypes.c_int64]
154
+ def gram_xy(x, y, c, n, p, q):
155
+ x = np.ascontiguousarray(x, dtype=np.float64)
156
+ y = np.ascontiguousarray(y, dtype=np.float64)
157
+ c = np.ascontiguousarray(c, dtype=np.float64)
158
+ return _lib.scm2cpp_gram_xy(x.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), y.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), c.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), n, p, q)
159
+
160
+ _lib.scm2cpp_spd_solve.restype = ctypes.c_int64
161
+ _lib.scm2cpp_spd_solve.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64]
162
+ def spd_solve(a, b, m, q):
163
+ a = np.ascontiguousarray(a, dtype=np.float64)
164
+ b = np.ascontiguousarray(b, dtype=np.float64)
165
+ return _lib.scm2cpp_spd_solve(a.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), b.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), m, q)
166
+
167
+ _lib.scm2cpp_gram_abs.restype = ctypes.c_double
168
+ _lib.scm2cpp_gram_abs.argtypes = [ctypes.c_double]
169
+ def gram_abs(x):
170
+ return _lib.scm2cpp_gram_abs(x)
171
+
172
+ _lib.scm2cpp_spd_solve_rcond.restype = ctypes.c_double
173
+ _lib.scm2cpp_spd_solve_rcond.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_int64, ctypes.c_int64]
174
+ def spd_solve_rcond(a, b, m, q):
175
+ a = np.ascontiguousarray(a, dtype=np.float64)
176
+ b = np.ascontiguousarray(b, dtype=np.float64)
177
+ return _lib.scm2cpp_spd_solve_rcond(a.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), b.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), m, q)
178
+
179
+ _lib.scm2cpp_gram_ridge_solve.restype = ctypes.c_int64
180
+ _lib.scm2cpp_gram_ridge_solve.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.c_double, ctypes.c_int64, ctypes.c_int64]
181
+ def gram_ridge_solve(g, c, alpha, m, q):
182
+ g = np.ascontiguousarray(g, dtype=np.float64)
183
+ c = np.ascontiguousarray(c, dtype=np.float64)
184
+ return _lib.scm2cpp_gram_ridge_solve(g.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), c.ctypes.data_as(ctypes.POINTER(ctypes.c_double)), alpha, m, q)
185
+