Class: MatrixBoost::NativeHelpers

Inherits:
Object
  • Object
show all
Defined in:
ext/matrix_boost/extension.c

Class Method Summary collapse

Class Method Details

.inv_matrix(m) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/matrix_boost/extension.c', line 67

static VALUE inv_matrix(VALUE self, VALUE m) {
  Check_Type(m, T_ARRAY);

  Matrix *mc = rb_array_to_matrix(m);
  Matrix *inverted = matrix_invert(mc);

  matrix_destroy(mc);

  if (inverted) {
    VALUE result = matrix_to_rb_array(inverted);
    matrix_destroy(inverted);
    return result;
  } else {
    return Qnil;
  }
}

.mul_matrix(m1, m2) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'ext/matrix_boost/extension.c', line 46

static VALUE mul_matrix(VALUE self, VALUE m1, VALUE m2) {
  Check_Type(m1, T_ARRAY);
  Check_Type(m2, T_ARRAY);

  Matrix *m1c = rb_array_to_matrix(m1);
  Matrix *m2c = rb_array_to_matrix(m2);

  Matrix *multiplied = matrix_multiply(m1c, m2c);

  matrix_destroy(m1c);
  matrix_destroy(m2c);

  if (multiplied) {
    VALUE result = matrix_to_rb_array(multiplied);
    matrix_destroy(multiplied);
    return result;
  } else {
    return Qnil;
  }
}