@@ -22,9 +22,17 @@ size_t csr_matrix_memsize(const void *ptr)
22
22
return sizeof (* csr );
23
23
}
24
24
25
+ const rb_data_type_t csr_matrix_type = {
26
+ "SpatialStats::Weights::CSRMatrix" ,
27
+ {NULL , csr_matrix_free , csr_matrix_memsize },
28
+ 0 ,
29
+ 0 ,
30
+ RUBY_TYPED_FREE_IMMEDIATELY
31
+ };
32
+
25
33
VALUE csr_matrix_alloc (VALUE self )
26
34
{
27
- csr_matrix * csr = malloc ( sizeof ( csr_matrix ) );
35
+ csr_matrix * csr = ALLOC ( csr_matrix );
28
36
return TypedData_Wrap_Struct (self , & csr_matrix_type , csr );
29
37
}
30
38
@@ -64,7 +72,7 @@ void mat_to_sparse(csr_matrix *csr, VALUE data, VALUE keys, VALUE num_rows)
64
72
// if it is, add array len to nnz
65
73
row = rb_hash_aref (data , key );
66
74
Check_Type (row , T_ARRAY );
67
- nnz += rb_array_len ( row );
75
+ nnz += ( int ) RARRAY_LEN ( row ); // Explicit cast to int
68
76
}
69
77
70
78
values = malloc (sizeof (double ) * nnz );
@@ -82,7 +90,7 @@ void mat_to_sparse(csr_matrix *csr, VALUE data, VALUE keys, VALUE num_rows)
82
90
83
91
key = rb_ary_entry (keys , i );
84
92
row = rb_hash_aref (data , key );
85
- m = rb_array_len ( row );
93
+ m = ( int ) RARRAY_LEN ( row ); // Explicit cast to int
86
94
87
95
for (j = 0 ; j < m ; j ++ )
88
96
{
@@ -140,7 +148,7 @@ VALUE csr_matrix_initialize(VALUE self, VALUE data, VALUE num_rows)
140
148
keys = rb_funcall (data , rb_intern ("keys" ), 0 );
141
149
142
150
// check dimensions are correct
143
- if (NUM2INT (num_rows ) != rb_array_len ( keys ))
151
+ if (NUM2INT (num_rows ) != ( int ) RARRAY_LEN ( keys )) // Explicit cast to int
144
152
{
145
153
rb_raise (rb_eArgError , "n_rows != keys.size, check your dimensions" );
146
154
}
@@ -249,7 +257,7 @@ VALUE csr_matrix_mulvec(VALUE self, VALUE vec)
249
257
250
258
TypedData_Get_Struct (self , csr_matrix , & csr_matrix_type , csr );
251
259
252
- if (rb_array_len (vec ) != csr -> n )
260
+ if (RARRAY_LEN (vec ) != csr -> n )
253
261
{
254
262
rb_raise (rb_eArgError , "Dimension Mismatch CSRMatrix.n != vec.size" );
255
263
}
@@ -294,7 +302,7 @@ VALUE csr_matrix_dot_row(VALUE self, VALUE vec, VALUE row)
294
302
295
303
TypedData_Get_Struct (self , csr_matrix , & csr_matrix_type , csr );
296
304
297
- if (rb_array_len (vec ) != csr -> n )
305
+ if (RARRAY_LEN (vec ) != csr -> n )
298
306
{
299
307
rb_raise (rb_eArgError , "Dimension Mismatch CSRMatrix.n != vec.size" );
300
308
}
0 commit comments