@@ -70,19 +70,18 @@ static struct feature_node **dense_to_sparse(double *x, npy_intp *dims,
70
70
/*
71
71
* Convert scipy.sparse.csr to libsvm's sparse data structure
72
72
*/
73
- static struct feature_node * * csr_to_sparse (double * values ,
74
- npy_intp * shape_indices , int * indices , npy_intp * shape_indptr ,
75
- int * indptr , double bias , int n_features )
73
+ static struct feature_node * * csr_to_sparse (double * values , int * indices ,
74
+ int * indptr , int n_samples , int n_features , double bias )
76
75
{
77
76
struct feature_node * * sparse , * temp ;
78
77
int i , j = 0 , k = 0 , n ;
79
78
int have_bias = (bias > 0 );
80
79
81
- sparse = malloc (( shape_indptr [ 0 ] - 1 ) * sizeof (struct feature_node * ));
80
+ sparse = malloc (n_samples * sizeof (struct feature_node * ));
82
81
if (sparse == NULL )
83
82
return NULL ;
84
83
85
- for (i = 0 ; i < shape_indptr [ 0 ] - 1 ; ++ i ) {
84
+ for (i = 0 ; i < n_samples ; ++ i ) {
86
85
n = indptr [i + 1 ] - indptr [i ]; /* count elements in row i */
87
86
88
87
sparse [i ] = malloc ((n + have_bias + 1 ) * sizeof (struct feature_node ));
@@ -140,14 +139,14 @@ struct problem * set_problem(char *X,char *Y, npy_intp *dims, double bias, char*
140
139
return problem ;
141
140
}
142
141
143
- struct problem * csr_set_problem (char * values , npy_intp * n_indices ,
144
- char * indices , npy_intp * n_indptr , char * indptr , char * Y ,
145
- npy_intp n_features , double bias , char * sample_weight ) {
142
+ struct problem * csr_set_problem (char * values , char * indices , char * indptr ,
143
+ char * Y , int n_samples , int n_features , double bias ,
144
+ char * sample_weight ) {
146
145
147
146
struct problem * problem ;
148
147
problem = malloc (sizeof (struct problem ));
149
148
if (problem == NULL ) return NULL ;
150
- problem -> l = ( int ) n_indptr [ 0 ] - 1 ;
149
+ problem -> l = n_samples ;
151
150
problem -> sample_weight = (double * ) sample_weight ;
152
151
153
152
if (bias > 0 ){
@@ -157,8 +156,8 @@ struct problem * csr_set_problem (char *values, npy_intp *n_indices,
157
156
}
158
157
159
158
problem -> y = (double * ) Y ;
160
- problem -> x = csr_to_sparse ((double * ) values , n_indices , (int * ) indices ,
161
- n_indptr , (int * ) indptr , bias , n_features );
159
+ problem -> x = csr_to_sparse ((double * ) values , (int * ) indices ,
160
+ (int * ) indptr , n_samples , n_features , bias );
162
161
problem -> bias = bias ;
163
162
problem -> sample_weight = sample_weight ;
164
163
0 commit comments