Skip to content

Commit c72348e

Browse files
committed
det, inv, transpose and submatrix
1 parent fc9db03 commit c72348e

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

ext/symengine/ruby_matrix.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,82 @@ VALUE cmatrix_dense_set(VALUE self, VALUE r, VALUE c, VALUE operand)
229229

230230
return self;
231231
}
232+
233+
234+
VALUE cmatrix_dense_det(VALUE self)
235+
{
236+
CDenseMatrix *this;
237+
Data_Get_Struct(self, CDenseMatrix, this);
238+
239+
basic_struct *cresult;
240+
VALUE result;
241+
242+
cresult = basic_new_heap();
243+
244+
dense_matrix_det(cresult, this);
245+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, basic_free_heap,
246+
cresult);
247+
return result;
248+
}
249+
VALUE cmatrix_dense_inv(VALUE self)
250+
{
251+
CDenseMatrix *this;
252+
Data_Get_Struct(self, CDenseMatrix, this);
253+
254+
CDenseMatrix *cresult;
255+
VALUE result;
256+
257+
cresult = dense_matrix_new();
258+
259+
dense_matrix_inv(cresult, this);
260+
result = Data_Wrap_Struct(c_dense_matrix, NULL, dense_matrix_free,
261+
cresult);
262+
return result;
263+
}
264+
265+
VALUE cmatrix_dense_transpose(VALUE self)
266+
{
267+
CDenseMatrix *this;
268+
Data_Get_Struct(self, CDenseMatrix, this);
269+
270+
CDenseMatrix *cresult;
271+
VALUE result;
272+
273+
cresult = dense_matrix_new();
274+
275+
dense_matrix_transpose(cresult, this);
276+
result = Data_Wrap_Struct(c_dense_matrix, NULL, dense_matrix_free,
277+
cresult);
278+
return result;
279+
}
280+
281+
VALUE cmatrix_dense_submatrix(VALUE self, VALUE r1, VALUE c1, VALUE r2, VALUE c2, VALUE r_, VALUE c_)
282+
{
283+
CDenseMatrix *this;
284+
Data_Get_Struct(self, CDenseMatrix, this);
285+
286+
CDenseMatrix *cresult;
287+
VALUE result;
288+
289+
unsigned long cbasic_r1;
290+
cbasic_r1 = NUM2ULONG(r1);
291+
unsigned long cbasic_c1;
292+
cbasic_c1 = NUM2ULONG(c1);
293+
294+
unsigned long cbasic_r2;
295+
cbasic_r2 = NUM2ULONG(r2);
296+
unsigned long cbasic_c2;
297+
cbasic_c2 = NUM2ULONG(c2);
298+
299+
unsigned long cbasic_r;
300+
cbasic_r = NUM2ULONG(r_);
301+
unsigned long cbasic_c;
302+
cbasic_c = NUM2ULONG(c_);
303+
304+
cresult = dense_matrix_new();
305+
306+
dense_matrix_submatrix(cresult, this, cbasic_r1, cbasic_c1, cbasic_r2, cbasic_c2, cbasic_r, cbasic_c);
307+
result = Data_Wrap_Struct(c_dense_matrix, NULL, dense_matrix_free,
308+
cresult);
309+
return result;
310+
}

ext/symengine/ruby_matrix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ VALUE cmatrix_dense_init(VALUE self, VALUE args);
1414
VALUE cmatrix_dense_to_str(VALUE self);
1515
VALUE cmatrix_dense_get(VALUE self, VALUE r, VALUE c);
1616
VALUE cmatrix_dense_set(VALUE self, VALUE r, VALUE c, VALUE operand);
17+
VALUE cmatrix_dense_det(VALUE self);
18+
VALUE cmatrix_dense_inv(VALUE self);
19+
VALUE cmatrix_dense_transpose(VALUE self);
20+
VALUE cmatrix_dense_submatrix(VALUE self, VALUE r1, VALUE c1, VALUE r2, VALUE c2, VALUE r_, VALUE c_);
1721

1822
void cmatrix_sparse_free(void *ptr);
1923
VALUE cmatrix_sparse_alloc(VALUE klass);

ext/symengine/symengine.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ void Init_symengine()
239239
rb_define_method(c_dense_matrix, "to_s", cmatrix_dense_to_str, 0);
240240
rb_define_method(c_dense_matrix, "get", cmatrix_dense_get, 2);
241241
rb_define_method(c_dense_matrix, "set", cmatrix_dense_set, 3);
242+
rb_define_method(c_dense_matrix, "det", cmatrix_dense_det, 0);
243+
rb_define_method(c_dense_matrix, "inv", cmatrix_dense_inv, 0);
244+
rb_define_method(c_dense_matrix, "transpose", cmatrix_dense_transpose, 0);
245+
rb_define_method(c_dense_matrix, "submatrix", cmatrix_dense_submatrix, 6);
242246

243247
// SparseMatrix Methods
244248
rb_define_alloc_func(c_sparse_matrix, cmatrix_sparse_alloc);

0 commit comments

Comments
 (0)