Skip to content

Commit c07f5c7

Browse files
committed
All numpy-like functions wrapped for DenseMatrix
1 parent 42d3e95 commit c07f5c7

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

ext/symengine/ruby_matrix.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,34 @@ VALUE cmatrix_dense_diag(VALUE self, VALUE args)
614614

615615
return result;
616616
}
617-
/*
617+
618618
VALUE cmatrix_dense_eye(VALUE self, VALUE args)
619619
{
620+
int argc = RARRAY_LEN(args);
621+
622+
if (argc != 1 && argc != 3){
623+
rb_raise(rb_eTypeError, "Wrong number of arguments");
624+
}
625+
626+
CDenseMatrix *cresult;
627+
cresult = dense_matrix_new();
628+
VALUE result;
620629

621-
}*/
630+
VALUE operand = rb_ary_shift(args);
631+
unsigned long int N = NUM2ULONG(operand);
632+
unsigned long int M = N;
633+
int k = 0;
634+
635+
if(argc == 3) {
636+
operand = rb_ary_shift(args);
637+
M = NUM2ULONG(operand);
638+
operand = rb_ary_shift(args);
639+
k = NUM2INT(operand);
640+
}
641+
642+
dense_matrix_eye(cresult, N, M, k);
643+
644+
result = Data_Wrap_Struct(c_dense_matrix, NULL, dense_matrix_free,
645+
cresult);
646+
return result;
647+
}

ext/symengine/ruby_matrix.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ VALUE cmatrix_dense_FFLU(VALUE self);
2929
VALUE cmatrix_dense_FFLDU(VALUE self);
3030
VALUE cmatrix_dense_ones(VALUE self, VALUE r, VALUE c);
3131
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);*/
32+
VALUE cmatrix_dense_diag(VALUE self, VALUE args);
33+
VALUE cmatrix_dense_eye(VALUE self, VALUE args);
3434

3535
void cmatrix_sparse_free(void *ptr);
3636
VALUE cmatrix_sparse_alloc(VALUE klass);

ext/symengine/symengine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void Init_symengine()
257257
rb_define_module_function(m_symengine, "ones", cmatrix_dense_ones, 2);
258258
rb_define_module_function(m_symengine, "zeros", cmatrix_dense_zeros, 2);
259259
rb_define_module_function(m_symengine, "diag", cmatrix_dense_diag, -2);
260-
/*rb_define_module_function(m_symengine, "eye", cmatrix_dense_eye, -2);*/
260+
rb_define_module_function(m_symengine, "eye", cmatrix_dense_eye, -2);
261261

262262

263263
// SparseMatrix Methods

0 commit comments

Comments
 (0)