Skip to content

Commit fc9db03

Browse files
committed
Getter and setter for DenseMatrix
1 parent d7c8b29 commit fc9db03

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

ext/symengine/ruby_matrix.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,46 @@ VALUE cmatrix_sparse_init(VALUE self, VALUE args)
186186

187187
return self;
188188
}
189+
190+
191+
VALUE cmatrix_dense_get(VALUE self, VALUE r, VALUE c)
192+
{
193+
CDenseMatrix *this;
194+
Data_Get_Struct(self, CDenseMatrix, this);
195+
196+
basic_struct *cresult;
197+
VALUE result;
198+
199+
unsigned long cbasic_r;
200+
cbasic_r = NUM2ULONG(r);
201+
unsigned long cbasic_c;
202+
cbasic_c = NUM2ULONG(c);
203+
204+
cresult = basic_new_heap();
205+
206+
dense_matrix_get_basic(cresult, this, cbasic_r, cbasic_c);
207+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, basic_free_heap,
208+
cresult);
209+
return result;
210+
}
211+
212+
VALUE cmatrix_dense_set(VALUE self, VALUE r, VALUE c, VALUE operand)
213+
{
214+
CDenseMatrix *this;
215+
Data_Get_Struct(self, CDenseMatrix, this);
216+
217+
basic cbasic_operand;
218+
basic_new_stack(cbasic_operand);
219+
sympify(operand, cbasic_operand);
220+
221+
unsigned long cbasic_r;
222+
cbasic_r = NUM2ULONG(r);
223+
unsigned long cbasic_c;
224+
cbasic_c = NUM2ULONG(c);
225+
226+
dense_matrix_set_basic(this, cbasic_r, cbasic_c, cbasic_operand);
227+
228+
basic_free_stack(cbasic_operand);
229+
230+
return self;
231+
}

ext/symengine/ruby_matrix.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44
#include <ruby.h>
55
#include <symengine/cwrapper.h>
66

7+
#include "symengine.h"
8+
#include "ruby_basic.h"
9+
#include "symengine_utils.h"
10+
711
void cmatrix_dense_free(void *ptr);
812
VALUE cmatrix_dense_alloc(VALUE klass);
913
VALUE cmatrix_dense_init(VALUE self, VALUE args);
1014
VALUE cmatrix_dense_to_str(VALUE self);
15+
VALUE cmatrix_dense_get(VALUE self, VALUE r, VALUE c);
16+
VALUE cmatrix_dense_set(VALUE self, VALUE r, VALUE c, VALUE operand);
1117

1218
void cmatrix_sparse_free(void *ptr);
1319
VALUE cmatrix_sparse_alloc(VALUE klass);

ext/symengine/symengine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ void Init_symengine()
237237
rb_define_alloc_func(c_dense_matrix, cmatrix_dense_alloc);
238238
rb_define_method(c_dense_matrix, "initialize", cmatrix_dense_init, -2);
239239
rb_define_method(c_dense_matrix, "to_s", cmatrix_dense_to_str, 0);
240+
rb_define_method(c_dense_matrix, "get", cmatrix_dense_get, 2);
241+
rb_define_method(c_dense_matrix, "set", cmatrix_dense_set, 3);
240242

241243
// SparseMatrix Methods
242244
rb_define_alloc_func(c_sparse_matrix, cmatrix_sparse_alloc);

0 commit comments

Comments
 (0)