@@ -133,8 +133,14 @@ nmatrix* nmatrix_new(
133133 matrix -> count = count ;
134134
135135 matrix -> shape = ALLOC_N (size_t , matrix -> ndims );
136- for (size_t i = 0 ; i < ndims ; ++ i ) {
137- matrix -> shape [i ] = shape [i ];
136+ if (shape != NULL ) {
137+ for (size_t i = 0 ; i < ndims ; ++ i ) {
138+ matrix -> shape [i ] = shape [i ];
139+ }
140+ }
141+
142+ if (elements == NULL ) {
143+ return matrix ;
138144 }
139145
140146 switch (dtype ) {
@@ -211,16 +217,22 @@ nmatrix* matrix_copy(nmatrix* original_matrix) {
211217 matrix -> count = original_matrix -> count ;
212218
213219 matrix -> shape = ALLOC_N (size_t , matrix -> ndims );
214- for (size_t i = 0 ; i < ndims ; ++ i ) {
215- matrix -> shape [i ] = original_matrix -> shape [i ];
220+ if (original_matrix -> shape != NULL ) {
221+ for (size_t i = 0 ; i < original_matrix -> ndims ; ++ i ) {
222+ matrix -> shape [i ] = original_matrix -> shape [i ];
223+ }
216224 }
217225
218- switch (dtype ) {
226+ if (original_matrix -> elements == NULL ) {
227+ return matrix ;
228+ }
229+
230+ switch (original_matrix -> dtype ) {
219231 case nm_bool :
220232 {
221233 bool * temp_elements = (bool * )original_matrix -> elements ;
222234 bool * matrix_elements = ALLOC_N (bool , matrix -> count );
223- for (size_t i = 0 ; i < count ; ++ i ) {
235+ for (size_t i = 0 ; i < original_matrix -> count ; ++ i ) {
224236 matrix_elements [i ] = temp_elements [i ];
225237 }
226238 matrix -> elements = matrix_elements ;
@@ -230,7 +242,7 @@ nmatrix* matrix_copy(nmatrix* original_matrix) {
230242 {
231243 int * temp_elements = (int * )original_matrix -> elements ;
232244 int * matrix_elements = ALLOC_N (int , matrix -> count );
233- for (size_t i = 0 ; i < count ; ++ i ) {
245+ for (size_t i = 0 ; i < original_matrix -> count ; ++ i ) {
234246 matrix_elements [i ] = temp_elements [i ];
235247 }
236248 matrix -> elements = matrix_elements ;
@@ -240,7 +252,7 @@ nmatrix* matrix_copy(nmatrix* original_matrix) {
240252 {
241253 float * temp_elements = (float * )original_matrix -> elements ;
242254 float * matrix_elements = ALLOC_N (float , matrix -> count );
243- for (size_t i = 0 ; i < count ; ++ i ) {
255+ for (size_t i = 0 ; i < original_matrix -> count ; ++ i ) {
244256 matrix_elements [i ] = temp_elements [i ];
245257 }
246258 matrix -> elements = matrix_elements ;
@@ -250,7 +262,7 @@ nmatrix* matrix_copy(nmatrix* original_matrix) {
250262 {
251263 double * temp_elements = (double * )original_matrix -> elements ;
252264 double * matrix_elements = ALLOC_N (double , matrix -> count );
253- for (size_t i = 0 ; i < count ; ++ i ) {
265+ for (size_t i = 0 ; i < original_matrix -> count ; ++ i ) {
254266 matrix_elements [i ] = temp_elements [i ];
255267 }
256268 matrix -> elements = matrix_elements ;
@@ -260,7 +272,7 @@ nmatrix* matrix_copy(nmatrix* original_matrix) {
260272 {
261273 float complex * temp_elements = (float complex * )original_matrix -> elements ;
262274 float complex * matrix_elements = ALLOC_N (float complex , matrix -> count );
263- for (size_t i = 0 ; i < count ; ++ i ) {
275+ for (size_t i = 0 ; i < original_matrix -> count ; ++ i ) {
264276 matrix_elements [i ] = temp_elements [i ];
265277 }
266278 matrix -> elements = matrix_elements ;
@@ -270,7 +282,7 @@ nmatrix* matrix_copy(nmatrix* original_matrix) {
270282 {
271283 double complex * temp_elements = (double complex * )original_matrix -> elements ;
272284 double complex * matrix_elements = ALLOC_N (double complex , matrix -> count );
273- for (size_t i = 0 ; i < count ; ++ i ) {
285+ for (size_t i = 0 ; i < original_matrix -> count ; ++ i ) {
274286 matrix_elements [i ] = temp_elements [i ];
275287 }
276288 matrix -> elements = matrix_elements ;
@@ -425,7 +437,7 @@ VALUE nm_geqp3(int argc, VALUE* argv);
425437VALUE nm_orth (VALUE self );
426438VALUE nm_cholesky (VALUE self );
427439VALUE nm_cholesky_solve (VALUE self );
428- VALUE nm_qr (VALUE self , VALUE mode , VALUE pivoting );
440+ VALUE nm_qr (VALUE self );
429441
430442VALUE nm_accessor_get (int argc , VALUE * argv , VALUE self );
431443VALUE nm_accessor_set (int argc , VALUE * argv , VALUE self );
@@ -484,15 +496,15 @@ void Init_nmatrix() {
484496 rb_define_singleton_method (NumRuby , "ones" , ones_nmatrix , -1 );
485497 // rb_define_singleton_method(NumRuby, "matrix", nmatrix_init, -1);
486498
487- Lapack = rb_define_module ( " NumRuby::Linalg:: Lapack" );
499+ Lapack = rb_define_module_under ( NumRuby , " Lapack" );
488500 rb_define_singleton_method (Lapack , "geqrf" , nm_geqrf , -1 );
489- rb_define_singleton_method (Lapack , "orgqr" , nm_orgqr , -1 );
490- rb_define_singleton_method (Lapack , "geqp3" , nm_geqp3 , -1 );
501+ // rb_define_singleton_method(Lapack, "orgqr", nm_orgqr, -1);
502+ // rb_define_singleton_method(Lapack, "geqp3", nm_geqp3, -1);
491503 // rb_define_singleton_method(Lapack, "geqrf", nm_geqrf, -1);
492504 // rb_define_singleton_method(Lapack, "geqrf", nm_geqrf, -1);
493505 // rb_define_singleton_method(Lapack, "geqrf", nm_geqrf, -1);
494506
495- Blas = rb_define_module ("NumRuby::Linalg:: Blas" );
507+ Blas = rb_define_module ("Blas" );
496508
497509 /*
498510 * Exception raised when there's a problem with data.
0 commit comments