2012-03-08 04:18:08 +08:00
|
|
|
"""Efficient (dense) parameter vector implementation for linear models. """
|
2012-03-08 03:09:05 +08:00
|
|
|
|
|
|
|
|
cimport numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cdef extern from "math.h":
|
|
|
|
|
cdef extern double sqrt(double x)
|
|
|
|
|
|
|
|
|
|
|
2012-03-08 04:18:08 +08:00
|
|
|
cdef class WeightVector(object):
|
2012-03-08 03:09:05 +08:00
|
|
|
cdef np.ndarray w
|
2014-09-13 00:25:18 +08:00
|
|
|
cdef np.ndarray aw
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef double *w_data_ptr
|
2014-09-13 00:25:18 +08:00
|
|
|
cdef double *aw_data_ptr
|
2012-03-08 03:09:05 +08:00
|
|
|
cdef double wscale
|
2014-10-03 21:44:15 +08:00
|
|
|
cdef double average_a
|
|
|
|
|
cdef double average_b
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef int n_features
|
2012-03-19 03:55:25 +08:00
|
|
|
cdef double sq_norm
|
2012-03-08 03:09:05 +08:00
|
|
|
|
2013-09-07 22:38:53 +08:00
|
|
|
cdef void add(self, double *x_data_ptr, int *x_ind_ptr,
|
2014-10-03 15:51:16 +08:00
|
|
|
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
|
2013-09-07 22:38:53 +08:00
|
|
|
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
|