Skip to content

Commit fb787a1

Browse files
committed
numpy-like functions ones and zeros
1 parent 6d31369 commit fb787a1

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

ext/symengine/ruby_matrix.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,48 @@ VALUE cmatrix_dense_FFLDU(VALUE self)
532532

533533
return result;
534534
}
535+
536+
537+
VALUE cmatrix_dense_ones(VALUE self, VALUE r, VALUE c)
538+
{
539+
unsigned long int r_ = NUM2ULONG(r);
540+
unsigned long int c_ = NUM2ULONG(c);
541+
542+
CDenseMatrix *cresult;
543+
cresult = dense_matrix_new();
544+
VALUE result;
545+
546+
dense_matrix_ones(cresult, r_, c_);
547+
548+
result = Data_Wrap_Struct(c_dense_matrix, NULL, dense_matrix_free,
549+
cresult);
550+
551+
return result;
552+
}
553+
554+
VALUE cmatrix_dense_zeros(VALUE self, VALUE r, VALUE c)
555+
{
556+
unsigned long int r_ = NUM2ULONG(r);
557+
unsigned long int c_ = NUM2ULONG(c);
558+
559+
CDenseMatrix *cresult;
560+
cresult = dense_matrix_new();
561+
VALUE result;
562+
563+
dense_matrix_zeros(cresult, r_, c_);
564+
565+
result = Data_Wrap_Struct(c_dense_matrix, NULL, dense_matrix_free,
566+
cresult);
567+
568+
return result;
569+
}
570+
/*
571+
VALUE cmatrix_dense_diag(VALUE self, VALUE args)
572+
{
573+
574+
}
575+
576+
VALUE cmatrix_dense_eye(VALUE self, VALUE args)
577+
{
578+
579+
}*/

ext/symengine/ruby_matrix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ VALUE cmatrix_dense_LDL(VALUE self);
2727
VALUE cmatrix_dense_LU_solve(VALUE self, VALUE b);
2828
VALUE cmatrix_dense_FFLU(VALUE self);
2929
VALUE cmatrix_dense_FFLDU(VALUE self);
30+
VALUE cmatrix_dense_ones(VALUE self, VALUE r, VALUE c);
31+
VALUE cmatrix_dense_zeros(VALUE self, VALUE r, VALUE c);
32+
/*VALUE cmatrix_dense_diag(VALUE self, VALUE args);
33+
VALUE cmatrix_dense_eye(VALUE self, VALUE args);*/
3034

3135
void cmatrix_sparse_free(void *ptr);
3236
VALUE cmatrix_sparse_alloc(VALUE klass);

ext/symengine/symengine.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ void Init_symengine()
253253
rb_define_method(c_dense_matrix, "FFLU", cmatrix_dense_FFLU, 0);
254254
rb_define_method(c_dense_matrix, "FFLDU", cmatrix_dense_FFLDU, 0);
255255

256+
// Numpy-like methods for DenseMatrix as module level methods
257+
rb_define_module_function(m_symengine, "ones", cmatrix_dense_ones, 2);
258+
rb_define_module_function(m_symengine, "zeros", cmatrix_dense_zeros, 2);
259+
/*rb_define_module_function(m_symengine, "diag", cmatrix_dense_diag, -2);
260+
rb_define_module_function(m_symengine, "eye", cmatrix_dense_eye, -2);*/
261+
256262

257263
// SparseMatrix Methods
258264
rb_define_alloc_func(c_sparse_matrix, cmatrix_sparse_alloc);

0 commit comments

Comments
 (0)