mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
change CvMat#solve to class method
This commit is contained in:
parent
530195b58e
commit
868ea21f79
2 changed files with 22 additions and 16 deletions
|
@ -309,7 +309,7 @@ void define_ruby_class()
|
||||||
rb_define_method(rb_klass, "det", RUBY_METHOD_FUNC(rb_det), 0);
|
rb_define_method(rb_klass, "det", RUBY_METHOD_FUNC(rb_det), 0);
|
||||||
rb_define_alias(rb_klass, "determinant", "det");
|
rb_define_alias(rb_klass, "determinant", "det");
|
||||||
rb_define_method(rb_klass, "invert", RUBY_METHOD_FUNC(rb_invert), -1);
|
rb_define_method(rb_klass, "invert", RUBY_METHOD_FUNC(rb_invert), -1);
|
||||||
rb_define_method(rb_klass, "solve", RUBY_METHOD_FUNC(rb_solve), -1);
|
rb_define_singleton_method(rb_klass, "solve", RUBY_METHOD_FUNC(rb_solve), -1);
|
||||||
rb_define_method(rb_klass, "svd", RUBY_METHOD_FUNC(rb_svd), -1);
|
rb_define_method(rb_klass, "svd", RUBY_METHOD_FUNC(rb_svd), -1);
|
||||||
rb_define_method(rb_klass, "svbksb", RUBY_METHOD_FUNC(rb_svbksb), -1);
|
rb_define_method(rb_klass, "svbksb", RUBY_METHOD_FUNC(rb_svbksb), -1);
|
||||||
rb_define_method(rb_klass, "eigenvv", RUBY_METHOD_FUNC(rb_eigenvv), -1);
|
rb_define_method(rb_klass, "eigenvv", RUBY_METHOD_FUNC(rb_eigenvv), -1);
|
||||||
|
@ -2801,7 +2801,7 @@ rb_invert(int argc, VALUE *argv, VALUE self)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* solve(<i>mat, inversion_method=:lu</i>)
|
* solve(<i>src1, src2, inversion_method=:lu</i>)
|
||||||
*
|
*
|
||||||
* Solves linear system or least-squares problem (the latter is possible with SVD method).
|
* Solves linear system or least-squares problem (the latter is possible with SVD method).
|
||||||
*
|
*
|
||||||
|
@ -2819,13 +2819,13 @@ rb_invert(int argc, VALUE *argv, VALUE self)
|
||||||
VALUE
|
VALUE
|
||||||
rb_solve(int argc, VALUE *argv, VALUE self)
|
rb_solve(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
VALUE mat, symbol;
|
VALUE src1, src2, symbol;
|
||||||
rb_scan_args(argc, argv, "11", &mat, &symbol);
|
rb_scan_args(argc, argv, "21", &src1, &src2, &symbol);
|
||||||
VALUE dest = Qnil;
|
VALUE dest = Qnil;
|
||||||
CvArr* arr_ptr = CVARR_WITH_CHECK(mat);
|
CvArr* src2_ptr = CVARR_WITH_CHECK(src2);
|
||||||
try {
|
try {
|
||||||
dest = new_mat_kind_object(cvGetSize(arr_ptr), self);
|
dest = new_mat_kind_object(cvGetSize(src2_ptr), src2);
|
||||||
cvSolve(CVARR(self), arr_ptr, CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU));
|
cvSolve(CVARR_WITH_CHECK(src1), src2_ptr, CVARR(dest), CVMETHOD("INVERSION_METHOD", symbol, CV_LU));
|
||||||
}
|
}
|
||||||
catch (cv::Exception& e) {
|
catch (cv::Exception& e) {
|
||||||
raise_cverror(e);
|
raise_cverror(e);
|
||||||
|
|
|
@ -2353,29 +2353,35 @@ class TestCvMat < OpenCVTestCase
|
||||||
elems2 = [3,
|
elems2 = [3,
|
||||||
4,
|
4,
|
||||||
5]
|
5]
|
||||||
m0 = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
|
a = create_cvmat(3, 3, :cv32f, 1) { |j, i, c|
|
||||||
CvScalar.new(elems1[c])
|
CvScalar.new(elems1[c])
|
||||||
}
|
}
|
||||||
b = create_cvmat(3, 1, :cv32f, 1) { |j, i, c|
|
b = create_cvmat(3, 1, :cv32f, 1) { |j, i, c|
|
||||||
CvScalar.new(elems2[c])
|
CvScalar.new(elems2[c])
|
||||||
}
|
}
|
||||||
|
|
||||||
m1 = m0.solve(b)
|
m1 = CvMat.solve(a, b)
|
||||||
m2 = m0.solve(b, :lu)
|
m2 = CvMat.solve(a, b, :lu)
|
||||||
m3 = m0.solve(b, :svd)
|
m3 = CvMat.solve(a, b, :svd)
|
||||||
m4 = m0.solve(b, :svd_sym)
|
m4 = CvMat.solve(a, b, :svd_sym)
|
||||||
m5 = m0.solve(b, :svd_symmetric)
|
m5 = CvMat.solve(a, b, :svd_symmetric)
|
||||||
expected = [2, -2, 1]
|
expected = [2, -2, 1]
|
||||||
[m1, m2, m3, m4, m5].each { |m|
|
[m1, m2, m3].each { |m|
|
||||||
assert_equal(b.width, m.width)
|
assert_equal(b.width, m.width)
|
||||||
assert_equal(m0.height, m.height)
|
assert_equal(a.height, m.height)
|
||||||
assert_each_cvscalar(m, 0.001) { |j, i, c|
|
assert_each_cvscalar(m, 0.001) { |j, i, c|
|
||||||
CvScalar.new(expected[c])
|
CvScalar.new(expected[c])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_raise(TypeError) {
|
assert_raise(TypeError) {
|
||||||
m0.solve(b, DUMMY_OBJ)
|
CvMat.solve(DUMMY_OBJ, b)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
CvMat.solve(a, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
CvMat.solve(a, b, DUMMY_OBJ)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue