Class: FastMatrix::Matrix::LUPDecomposition

Inherits:
Data
  • Object
show all
Defined in:
lib/lup_decomposition/lup_decomposition.rb,
ext/fast_matrix/LUPDecomposition/lup.c

Overview

LUP decomposition for Matrix

Instance Method Summary collapse

Instance Method Details

#detObject Also known as: determinant



72
73
74
75
76
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 72

VALUE lup_determinant(VALUE self)
{
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
    return DBL2NUM(c_lup_determinant(lp->n, lp->data, lp->pivot_sign));
}

#lObject



48
49
50
51
52
53
54
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 48

VALUE lup_l(VALUE self)
{
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
    MAKE_MATRIX_AND_RB_VALUE(R, result, lp->n, lp->n);
    c_lup_l(lp->n, lp->data, R->data);
    return result;
}

#pObject



64
65
66
67
68
69
70
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 64

VALUE lup_p(VALUE self)
{
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
    MAKE_MATRIX_AND_RB_VALUE(R, result, lp->n, lp->n);
    c_lup_p(lp->n, lp->permutation, R->data);
    return result;
}

#pivotsObject



86
87
88
89
90
91
92
93
94
95
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 86

VALUE lup_pivots(VALUE self)
{
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
    VALUE* v = malloc(lp->n * sizeof(VALUE));
    for(int i = 0; i < lp->n; ++i)
        v[i] = INT2NUM(lp->permutation[i]);
    VALUE res = rb_ary_new_from_values(lp->n, v);
    free(v);
    return res;
}

#singular?Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 78

VALUE lup_singular(VALUE self)
{
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
    if(lp->singular)
        return Qtrue;
    return Qfalse;
}

#solve(mtrx) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 97

VALUE lup_solve(VALUE self, VALUE mtrx)
{
    raise_check_rbasic(mtrx, cMatrix, "matrix");
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
	struct matrix* M = get_matrix_from_rb_value(mtrx);
    if(lp->singular)
        rb_raise(fm_eIndexError, "Matrix is singular");
    if(lp->n != M->n)
        rb_raise(fm_eIndexError, "Columns of different size");

    MAKE_MATRIX_AND_RB_VALUE(C, result, M->m, lp->n);
    c_lup_solve(M->m, lp->n, lp->data, M->data, lp->permutation, C->data);
    return result;
}

#to_aryObject Also known as: to_a

Returns L, U, P in an array



11
12
13
# File 'lib/lup_decomposition/lup_decomposition.rb', line 11

def to_ary
    [l, u, p]
end

#uObject



56
57
58
59
60
61
62
# File 'ext/fast_matrix/LUPDecomposition/lup.c', line 56

VALUE lup_u(VALUE self)
{
	struct lupdecomposition* lp = get_lup_from_rb_value(self);
    MAKE_MATRIX_AND_RB_VALUE(R, result, lp->n, lp->n);
    c_lup_u(lp->n, lp->data, R->data);
    return result;
}