Class: MPFI::SquareMatrix

Inherits:
Matrix
  • Object
show all
Defined in:
ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Matrix

#*, #+, #-, #==, #add, #at, #bounded?, #column, #column_size, create, #div_scalar, #each_element, #each_element_with_index, #each_subdivision, #each_subdivision_by_size, #element, #include?, #inspect, #intersect, interval, #marshal_dump, #marshal_load, #max_diam_abs, #mid, #mid_interval, #mul, #mul_scalar, #neg, #pretty_print, #row, #row_size, #set_element, #size, #str_ary_for_inspect, #str_ary_for_inspect2, #strictly_include?, #sub, #subdivision, #subdivision_by_size, suitable_matrix_from_ary, #to_a, #to_a2, #to_s, #to_str_ary, #to_strf_ary, #transpose, #transpose!, #union

Class Method Details

.identityObject



1000
1001
1002
1003
1004
1005
1006
1007
# File 'ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c', line 1000

static VALUE r_mpfi_square_matrix_identity (VALUE self, VALUE size) {
  VALUE ret;
  MPFIMatrix *ptr_ret;
  int s = NUM2INT(size);
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, s, s);
  mpfi_square_matrix_identity(ptr_ret);
  return ret;
}

Instance Method Details

#determinantObject



980
981
982
983
984
985
986
987
988
# File 'ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c', line 980

static VALUE r_mpfi_square_matrix_determinant (VALUE self) {
  MPFIMatrix *ptr_self;
  MPFI *ptr_ret;
  VALUE ret;
  r_mpfi_get_matrix_struct(ptr_self, self);
  r_mpfi_make_struct_init(ret, ptr_ret);
  mpfi_square_matrix_determinant(ptr_ret, ptr_self);
  return ret;
}

#dimObject

Return row size of matrix.



938
939
940
941
942
# File 'ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c', line 938

static VALUE r_mpfi_square_matrix_dim (VALUE self) {
  MPFIMatrix *ptr_self;
  r_mpfi_get_matrix_struct(ptr_self, self);
  return INT2FIX(ptr_self->row);
}

#lu_decompObject

Return [matrix_l, matrix_r, indx].



945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
# File 'ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c', line 945

static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self) {
  MPFIMatrix *ptr_self, *ptr_ret_l, *ptr_ret_u;
  VALUE ret_l, ret_u, ret, ret_indx_ary;
  int i, j, *indx;
  r_mpfi_get_matrix_struct(ptr_self, self);
  r_mpfi_matrix_suitable_matrix_init (&ret_l, &ptr_ret_l, ptr_self->row, ptr_self->column);
  r_mpfi_matrix_suitable_matrix_init (&ret_u, &ptr_ret_u, ptr_self->row, ptr_self->column);
  indx = ALLOC_N(int, ptr_self->row);
  if (mpfi_square_matrix_lu_decomp (ptr_ret_u, indx, ptr_self) >= 0) {
    ret_indx_ary = rb_ary_new2(ptr_self->row);
    for (i = 1; i < ptr_ret_u->row; i++) {
      for (j = 0; j < i; j++) {
	mpfi_set(mpfi_matrix_get_element(ptr_ret_l, i, j), mpfi_matrix_get_element(ptr_ret_u, i, j));
	mpfi_set_si(mpfi_matrix_get_element(ptr_ret_u, i, j), 0);
      }
    }
    for (i = 0; i < ptr_ret_u->row; i++) {
      mpfi_set_si(mpfi_matrix_get_element(ptr_ret_l, i, i), 1);
    }
    for (i = 0; i < ptr_ret_u->row; i++) {
      for (j = i + 1; j < ptr_ret_u->column; j++) {
	mpfi_set_si(mpfi_matrix_get_element(ptr_ret_l, i, j), 0);
      }
    }
    for (i = 0; i < ptr_ret_u->row; i++) {
      rb_ary_store(ret_indx_ary, i, INT2NUM(indx[i]));
    }
    ret = rb_ary_new3(3, ret_l, ret_u, ret_indx_ary);
  } else {
    ret = Qnil;
  }
  free(indx);
  return ret;
}

#qr_decompObject



990
991
992
993
994
995
996
997
998
# File 'ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c', line 990

static VALUE r_mpfi_square_matrix_qr_decomp (VALUE self) {
  MPFIMatrix *ptr_self, *ptr_q, *ptr_r;
  VALUE q, r;
  r_mpfi_get_matrix_struct(ptr_self, self);
  r_mpfi_matrix_suitable_matrix_init (&q, &ptr_q, ptr_self->row, ptr_self->column);
  r_mpfi_matrix_suitable_matrix_init (&r, &ptr_r, ptr_self->column, ptr_self->column);
  mpfi_square_matrix_qr_decomp(ptr_q, ptr_r, ptr_self);
  return rb_ary_new3(2, q, r);
}