hornetseye-linalg 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef HORNETSEYE_NODE_HH
17
+ #define HORNETSEYE_NODE_HH
18
+ #include "rubyinc.hh"
19
+
20
+ class Node {
21
+ public:
22
+ static VALUE cRubyClass;
23
+ static VALUE mModule;
24
+ static VALUE registerRubyClass(VALUE module);
25
+ static VALUE wrapToDMatrix(VALUE rbSelf);
26
+ static VALUE wrapToSMatrix(VALUE rbSelf);
27
+ };
28
+
29
+ #endif
@@ -0,0 +1,54 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef HORNETSEYE_RUBYINC_HH
17
+ #define HORNETSEYE_RUBYINC_HH
18
+
19
+ #ifdef RSHIFT
20
+ #undef RSHIFT
21
+ #endif
22
+
23
+ #define gettimeofday rubygettimeofday
24
+ #define timezone rubygettimezone
25
+ #include <ruby.h>
26
+ // #include <version.h>
27
+ #undef timezone
28
+ #undef gettimeofday
29
+ #ifdef read
30
+ #undef read
31
+ #endif
32
+ #ifdef write
33
+ #undef write
34
+ #endif
35
+ #ifdef RGB
36
+ #undef RGB
37
+ #endif
38
+
39
+ #ifndef RUBY_VERSION_NUMBER
40
+ #define RUBY_VERSION_NUMBER ( RUBY_VERSION_MAJOR * 10000 + \
41
+ RUBY_VERSION_MINOR * 100 + \
42
+ RUBY_VERSION_TEENY )
43
+ #endif
44
+
45
+ #ifndef RUBY_METHOD_FUNC
46
+ #define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
47
+ #endif
48
+
49
+ #ifndef xfree
50
+ #define xfree free
51
+ #endif
52
+
53
+ #endif
54
+
@@ -0,0 +1,33 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef HORNETSEYE_RUBYTOOLS_HH
17
+ #define HORNETSEYE_RUBYTOOLS_HH
18
+
19
+ #include <complex>
20
+ #include "rubyinc.hh"
21
+
22
+ void checkType( VALUE rbValue, VALUE rbClass );
23
+
24
+ void checkStruct( VALUE rbValue, VALUE rbClass );
25
+
26
+ #define dataGetStruct(obj,klass,type,sval) { \
27
+ checkStruct( obj, klass ); \
28
+ Data_Get_Struct( obj, type, sval ); \
29
+ }
30
+
31
+ #include "rubytools.tcc"
32
+
33
+ #endif
@@ -0,0 +1,32 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #include <cassert>
17
+ #include "error.hh"
18
+
19
+ inline void checkType( VALUE rbValue, VALUE rbClass )
20
+ {
21
+ ERRORMACRO( rb_funcall( rbValue, rb_intern( "kind_of?" ), 1, rbClass ) ==
22
+ Qtrue, Error, ,
23
+ "Argument must be of class \"" << rb_class2name( rbClass )
24
+ << "\"." );
25
+ }
26
+
27
+ inline void checkStruct( VALUE rbValue, VALUE rbClass )
28
+ {
29
+ Check_Type( rbValue, T_DATA );
30
+ checkType( rbValue, rbClass );
31
+ }
32
+
@@ -0,0 +1,60 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #include <algorithm>
17
+ #include <boost/shared_array.hpp>
18
+ #include "error.hh"
19
+ #include "rubytools.hh"
20
+ #include "smatrix.hh"
21
+
22
+ using namespace std;
23
+
24
+ VALUE SMatrix::mModule = Qnil;
25
+
26
+ VALUE SMatrix::cRubyClass = Qnil;
27
+
28
+ VALUE SMatrix::registerRubyClass(VALUE module)
29
+ {
30
+ mModule = module;
31
+ cRubyClass = rb_define_class_under(module, "SMatrix", rb_cObject);
32
+ rb_define_method(cRubyClass, "to_multiarray", RUBY_METHOD_FUNC(wrapToMultiArray), 0);
33
+ return cRubyClass;
34
+ }
35
+
36
+ void SMatrix::deleteRubyObject(void *ptr)
37
+ {
38
+ free((SMatrix *)ptr);
39
+ }
40
+
41
+ VALUE SMatrix::wrapToMultiArray(VALUE rbSelf)
42
+ {
43
+ VALUE rbRetVal = Qnil;
44
+ try {
45
+ VALUE mHornetseye = rb_define_module( "Hornetseye" );
46
+ SMatrix_ *smatrix;
47
+ dataGetStruct(rbSelf, cRubyClass, SMatrix_, smatrix);
48
+ int width = smatrix->hsize;
49
+ int height = smatrix->vsize;
50
+ VALUE cMalloc = rb_define_class_under(mHornetseye, "Malloc", rb_cObject);
51
+ VALUE rbMemory = Data_Wrap_Struct(cMalloc, 0, 0, smatrix->data);
52
+ rb_ivar_set(rbMemory, rb_intern("@size"), INT2NUM(width * height * sizeof(float)));
53
+ VALUE rbTypecode = rb_const_get(mHornetseye, rb_intern("SFLOAT"));
54
+ rbRetVal = rb_funcall(rb_const_get(mHornetseye, rb_intern("MultiArray")),
55
+ rb_intern("import"), 4, rbTypecode, rbMemory, INT2NUM(height), INT2NUM(width));
56
+ } catch( std::exception &e ) {
57
+ rb_raise( rb_eRuntimeError, "%s", e.what() );
58
+ };
59
+ return rbRetVal;
60
+ }
@@ -0,0 +1,36 @@
1
+ /* HornetsEye - Computer Vision with Ruby
2
+ Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Jan Wedekind
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ #ifndef HORNETSEYE_SMATRIX_HH
17
+ #define HORNETSEYE_SMATRIX_HH
18
+ #include "rubyinc.hh"
19
+
20
+ typedef struct {
21
+ int vsize;
22
+ int hsize;
23
+ float *data;
24
+ } SMatrix_;
25
+
26
+ class SMatrix {
27
+ public:
28
+ static VALUE cRubyClass;
29
+ static VALUE mModule;
30
+ static VALUE registerRubyClass(VALUE module);
31
+ static void deleteRubyObject(void *ptr);
32
+ static VALUE wrapToMultiArray(VALUE rbSelf);
33
+ };
34
+
35
+ #endif
36
+
@@ -0,0 +1,33 @@
1
+ # hornetseye-linalg - Linalg integration for Hornetseye
2
+ # Copyright (C) 2011 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ module Linalg
17
+
18
+ class DMatrix
19
+
20
+ alias_method :orig_to_multiarray, :to_multiarray
21
+
22
+ def to_multiarray
23
+ source = self
24
+ retval = orig_to_multiarray.roll
25
+ retval.instance_eval { @source = source }
26
+ retval
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+
@@ -0,0 +1,41 @@
1
+ # hornetseye-linalg - Linalg integration for Hornetseye
2
+ # Copyright (C) 2011 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ module Hornetseye
17
+
18
+ class Node
19
+
20
+ alias_method :orig_to_dmatrix, :to_dmatrix
21
+
22
+ def to_dmatrix
23
+ source = roll.to_dfloat.memorise
24
+ retval = source.orig_to_dmatrix
25
+ retval.instance_eval { @source = source }
26
+ retval
27
+ end
28
+
29
+ alias_method :orig_to_smatrix, :to_smatrix
30
+
31
+ def to_smatrix
32
+ source = roll.to_sfloat.memorise
33
+ retval = source.orig_to_smatrix
34
+ retval.instance_eval { @source = source }
35
+ retval
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,34 @@
1
+ # hornetseye-linalg - Linalg integration for Hornetseye
2
+ # Copyright (C) 2011 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ module Linalg
17
+
18
+ class SMatrix
19
+
20
+ alias_method :orig_to_multiarray, :to_multiarray
21
+
22
+ def to_multiarray
23
+ source = self
24
+ retval = orig_to_multiarray.roll
25
+ retval.instance_eval { @source = source }
26
+ retval
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+
34
+
@@ -0,0 +1,24 @@
1
+ # hornetseye-hypercomplex - Linalg integration for Hornetseye
2
+ # Copyright (C) 2011 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'malloc'
18
+ require 'multiarray'
19
+ require 'linalg'
20
+
21
+ require 'hornetseye-linalg/node'
22
+ require 'hornetseye-linalg/dmatrix'
23
+ require 'hornetseye-linalg/smatrix'
24
+
@@ -0,0 +1,62 @@
1
+ # hornetseye-hypercomplex - Linalg integration for Hornetseye
2
+ # Copyright (C) 2011 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test/unit'
18
+ begin
19
+ require 'rubygems'
20
+ rescue LoadError
21
+ end
22
+ Kernel::require 'hornetseye_linalg'
23
+
24
+ class TC_Hornetseye_Linalg < Test::Unit::TestCase
25
+
26
+ D = Hornetseye::DFLOAT
27
+ S = Hornetseye::SFLOAT
28
+
29
+ def M( *args )
30
+ Hornetseye::MultiArray *args
31
+ end
32
+
33
+ def setup
34
+ @m1 = M(D, 2)[[1, 2, 3], [4, 5, 6]]
35
+ @m2 = M(S, 2)[[1, 2, 3], [4, 5, 6]]
36
+ end
37
+
38
+ def teardown
39
+ end
40
+
41
+ def test_to_dmatrix
42
+ d = @m1.to_dmatrix
43
+ for j in 0 ... @m1.shape[1]
44
+ for i in 0 ... @m1.shape[0]
45
+ assert_equal @m1[j][i], d[j, i]
46
+ end
47
+ end
48
+ assert_equal @m1, d.to_multiarray
49
+ end
50
+
51
+ def test_to_smatrix
52
+ s = @m2.to_smatrix
53
+ for j in 0 ... @m2.shape[1]
54
+ for i in 0 ... @m2.shape[0]
55
+ assert_equal @m2[j][i], s[j, i]
56
+ end
57
+ end
58
+ assert_equal @m2, s.to_multiarray
59
+ end
60
+
61
+ end
62
+