针对pulse-transit的工具

This commit is contained in:
2025-02-22 16:12:02 +08:00
commit 6bc25b4e3a
7719 changed files with 1530886 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,41 @@
from cython cimport floating
cpdef enum BLAS_Order:
RowMajor # C contiguous
ColMajor # Fortran contiguous
cpdef enum BLAS_Trans:
NoTrans = 110 # correspond to 'n'
Trans = 116 # correspond to 't'
# BLAS Level 1 ################################################################
cdef floating _dot(int, floating*, int, floating*, int) nogil
cdef floating _asum(int, floating*, int) nogil
cdef void _axpy(int, floating, floating*, int, floating*, int) nogil
cdef floating _nrm2(int, floating*, int) nogil
cdef void _copy(int, floating*, int, floating*, int) nogil
cdef void _scal(int, floating, floating*, int) nogil
cdef void _rotg(floating*, floating*, floating*, floating*) nogil
cdef void _rot(int, floating*, int, floating*, int, floating, floating) nogil
# BLAS Level 2 ################################################################
cdef void _gemv(BLAS_Order, BLAS_Trans, int, int, floating, floating*, int,
floating*, int, floating, floating*, int) nogil
cdef void _ger(BLAS_Order, int, int, floating, floating*, int, floating*, int,
floating*, int) nogil
# BLASLevel 3 ################################################################
cdef void _gemm(BLAS_Order, BLAS_Trans, BLAS_Trans, int, int, int, floating,
floating*, int, floating*, int, floating, floating*,
int) nogil

Binary file not shown.

View File

@@ -0,0 +1,22 @@
# Author: Gael Varoquaux
# License: BSD
"""
Uses C++ map containers for fast dict-like behavior with keys being
integers, and values float.
"""
from libcpp.map cimport map as cpp_map
# Import the C-level symbols of numpy
cimport numpy as np
ctypedef np.float64_t DTYPE_t
ctypedef np.intp_t ITYPE_t
###############################################################################
# An object to be used in Python
cdef class IntFloatDict:
cdef cpp_map[ITYPE_t, DTYPE_t] my_map
cdef _to_arrays(self, ITYPE_t [:] keys, DTYPE_t [:] values)

Binary file not shown.

14
dist/client/sklearn/utils/_heap.pxd vendored Normal file
View File

@@ -0,0 +1,14 @@
# Heap routines, used in various Cython implementations.
from cython cimport floating
from ._typedefs cimport ITYPE_t
cdef int heap_push(
floating* values,
ITYPE_t* indices,
ITYPE_t size,
floating val,
ITYPE_t val_idx,
) nogil

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,6 @@
# Helpers to access OpenMP threads information
#
# Those interfaces act as indirections which allows the non-support of OpenMP
# for implementations which have been written for it.
cdef int _openmp_thread_num() nogil

Binary file not shown.

44
dist/client/sklearn/utils/_random.pxd vendored Normal file
View File

@@ -0,0 +1,44 @@
# Authors: Arnaud Joly
#
# License: BSD 3 clause
import numpy as np
cimport numpy as np
ctypedef np.npy_uint32 UINT32_t
cdef inline UINT32_t DEFAULT_SEED = 1
cdef enum:
# Max value for our rand_r replacement (near the bottom).
# We don't use RAND_MAX because it's different across platforms and
# particularly tiny on Windows/MSVC.
RAND_R_MAX = 0x7FFFFFFF
cpdef sample_without_replacement(np.int_t n_population,
np.int_t n_samples,
method=*,
random_state=*)
# rand_r replacement using a 32bit XorShift generator
# See http://www.jstatsoft.org/v08/i14/paper for details
cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil:
"""Generate a pseudo-random np.uint32 from a np.uint32 seed"""
# seed shouldn't ever be 0.
if (seed[0] == 0): seed[0] = DEFAULT_SEED
seed[0] ^= <UINT32_t>(seed[0] << 13)
seed[0] ^= <UINT32_t>(seed[0] >> 17)
seed[0] ^= <UINT32_t>(seed[0] << 5)
# Note: we must be careful with the final line cast to np.uint32 so that
# the function behaves consistently across platforms.
#
# The following cast might yield different results on different platforms:
# wrong_cast = <UINT32_t> RAND_R_MAX + 1
#
# We can use:
# good_cast = <UINT32_t>(RAND_R_MAX + 1)
# or:
# cdef np.uint32_t another_good_cast = <UINT32_t>RAND_R_MAX + 1
return seed[0] % <UINT32_t>(RAND_R_MAX + 1)

Binary file not shown.

View File

@@ -0,0 +1,116 @@
#------------------------------------------------------------------------------
"""
Dataset abstractions for sequential data access.
WARNING: Do not edit .pxd file directly, it is generated from .pxd.tp
"""
cimport numpy as np
# SequentialDataset and its two concrete subclasses are (optionally randomized)
# iterators over the rows of a matrix X and corresponding target values y.
cdef class SequentialDataset64:
cdef int current_index
cdef np.ndarray index
cdef int *index_data_ptr
cdef Py_ssize_t n_samples
cdef np.uint32_t seed
cdef void shuffle(self, np.uint32_t seed) nogil
cdef int _get_next_index(self) nogil
cdef int _get_random_index(self) nogil
cdef void _sample(self, double **x_data_ptr, int **x_ind_ptr,
int *nnz, double *y, double *sample_weight,
int current_index) nogil
cdef void next(self, double **x_data_ptr, int **x_ind_ptr,
int *nnz, double *y, double *sample_weight) nogil
cdef int random(self, double **x_data_ptr, int **x_ind_ptr,
int *nnz, double *y, double *sample_weight) nogil
cdef class ArrayDataset64(SequentialDataset64):
cdef np.ndarray X
cdef np.ndarray Y
cdef np.ndarray sample_weights
cdef Py_ssize_t n_features
cdef np.npy_intp X_stride
cdef double *X_data_ptr
cdef double *Y_data_ptr
cdef np.ndarray feature_indices
cdef int *feature_indices_ptr
cdef double *sample_weight_data
cdef class CSRDataset64(SequentialDataset64):
cdef np.ndarray X_data
cdef np.ndarray X_indptr
cdef np.ndarray X_indices
cdef np.ndarray Y
cdef np.ndarray sample_weights
cdef double *X_data_ptr
cdef int *X_indptr_ptr
cdef int *X_indices_ptr
cdef double *Y_data_ptr
cdef double *sample_weight_data
#------------------------------------------------------------------------------
"""
Dataset abstractions for sequential data access.
WARNING: Do not edit .pxd file directly, it is generated from .pxd.tp
"""
cimport numpy as np
# SequentialDataset and its two concrete subclasses are (optionally randomized)
# iterators over the rows of a matrix X and corresponding target values y.
cdef class SequentialDataset32:
cdef int current_index
cdef np.ndarray index
cdef int *index_data_ptr
cdef Py_ssize_t n_samples
cdef np.uint32_t seed
cdef void shuffle(self, np.uint32_t seed) nogil
cdef int _get_next_index(self) nogil
cdef int _get_random_index(self) nogil
cdef void _sample(self, float **x_data_ptr, int **x_ind_ptr,
int *nnz, float *y, float *sample_weight,
int current_index) nogil
cdef void next(self, float **x_data_ptr, int **x_ind_ptr,
int *nnz, float *y, float *sample_weight) nogil
cdef int random(self, float **x_data_ptr, int **x_ind_ptr,
int *nnz, float *y, float *sample_weight) nogil
cdef class ArrayDataset32(SequentialDataset32):
cdef np.ndarray X
cdef np.ndarray Y
cdef np.ndarray sample_weights
cdef Py_ssize_t n_features
cdef np.npy_intp X_stride
cdef float *X_data_ptr
cdef float *Y_data_ptr
cdef np.ndarray feature_indices
cdef int *feature_indices_ptr
cdef float *sample_weight_data
cdef class CSRDataset32(SequentialDataset32):
cdef np.ndarray X_data
cdef np.ndarray X_indptr
cdef np.ndarray X_indices
cdef np.ndarray Y
cdef np.ndarray sample_weights
cdef float *X_data_ptr
cdef int *X_indptr_ptr
cdef int *X_indices_ptr
cdef float *Y_data_ptr
cdef float *sample_weight_data

Binary file not shown.

View File

@@ -0,0 +1,9 @@
from ._typedefs cimport DTYPE_t, ITYPE_t
from cython cimport floating
cdef int simultaneous_sort(
floating *dist,
ITYPE_t *idx,
ITYPE_t size,
) nogil

Binary file not shown.

17
dist/client/sklearn/utils/_typedefs.pxd vendored Normal file
View File

@@ -0,0 +1,17 @@
#!python
cimport numpy as np
# Floating point/data type
ctypedef np.float64_t DTYPE_t # WARNING: should match DTYPE in typedefs.pyx
cdef enum:
DTYPECODE = np.NPY_FLOAT64
ITYPECODE = np.NPY_INTP
INT32TYPECODE = np.NPY_INT32
INT64TYPECODE = np.NPY_INT64
# Index/integer type.
# WARNING: ITYPE_t must be a signed integer type or you will have a bad time!
ctypedef np.intp_t ITYPE_t # WARNING: should match ITYPE in typedefs.pyx
ctypedef np.int32_t INT32TYPE_t # WARNING: should match INT32TYPE in typedefs.pyx
ctypedef np.int64_t INT64TYPE_t # WARNING: should match INT32TYPE in typedefs.pyx

Binary file not shown.

View File

@@ -0,0 +1,12 @@
cimport numpy as np
from libcpp.vector cimport vector
from ..utils._typedefs cimport ITYPE_t, DTYPE_t, INT32TYPE_t, INT64TYPE_t
ctypedef fused vector_typed:
vector[DTYPE_t]
vector[ITYPE_t]
vector[INT32TYPE_t]
vector[INT64TYPE_t]
cdef np.ndarray vector_to_nd_array(vector_typed * vect_ptr)

Binary file not shown.

View File

@@ -0,0 +1,45 @@
# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp
cimport numpy as np
cdef class WeightVector64(object):
cdef readonly double[::1] w
cdef readonly double[::1] aw
cdef double *w_data_ptr
cdef double *aw_data_ptr
cdef double wscale
cdef double average_a
cdef double average_b
cdef int n_features
cdef double sq_norm
cdef void add(self, double *x_data_ptr, int *x_ind_ptr,
int xnnz, double c) nogil
cdef void add_average(self, double *x_data_ptr, int *x_ind_ptr,
int xnnz, double c, double num_iter) nogil
cdef double dot(self, double *x_data_ptr, int *x_ind_ptr,
int xnnz) nogil
cdef void scale(self, double c) nogil
cdef void reset_wscale(self) nogil
cdef double norm(self) nogil
cdef class WeightVector32(object):
cdef readonly float[::1] w
cdef readonly float[::1] aw
cdef float *w_data_ptr
cdef float *aw_data_ptr
cdef float wscale
cdef float average_a
cdef float average_b
cdef int n_features
cdef float sq_norm
cdef void add(self, float *x_data_ptr, int *x_ind_ptr,
int xnnz, float c) nogil
cdef void add_average(self, float *x_data_ptr, int *x_ind_ptr,
int xnnz, float c, float num_iter) nogil
cdef float dot(self, float *x_data_ptr, int *x_ind_ptr,
int xnnz) nogil
cdef void scale(self, float c) nogil
cdef void reset_wscale(self) nogil
cdef float norm(self) nogil

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,21 @@
"""Export fast murmurhash C/C++ routines + cython wrappers"""
cimport numpy as np
# The C API is disabled for now, since it requires -I flags to get
# compilation to work even when these functions are not used.
#cdef extern from "MurmurHash3.h":
# void MurmurHash3_x86_32(void* key, int len, unsigned int seed,
# void* out)
#
# void MurmurHash3_x86_128(void* key, int len, unsigned int seed,
# void* out)
#
# void MurmurHash3_x64_128(void* key, int len, unsigned int seed,
# void* out)
cpdef np.uint32_t murmurhash3_int_u32(int key, unsigned int seed)
cpdef np.int32_t murmurhash3_int_s32(int key, unsigned int seed)
cpdef np.uint32_t murmurhash3_bytes_u32(bytes key, unsigned int seed)
cpdef np.int32_t murmurhash3_bytes_s32(bytes key, unsigned int seed)

Binary file not shown.