multiarray 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+ require 'date'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rbconfig'
7
+
8
+ PKG_NAME = 'multiarray'
9
+ PKG_VERSION = '0.2.4'
10
+ RB_FILES = FileList[ 'lib/**/*.rb' ]
11
+ TC_FILES = FileList[ 'test/tc_*.rb' ]
12
+ TS_FILES = FileList[ 'test/ts_*.rb' ]
13
+ PKG_FILES = [ 'Rakefile', 'README', 'COPYING', '.document' ] +
14
+ RB_FILES + TS_FILES + TC_FILES
15
+ SUMMARY = %q{Multi-dimensional and uniform Ruby arrays}
16
+ DESCRIPTION = %q{This Ruby-extension defines Hornetseye::MultiArray and other native datatypes. Hornetseye::MultiArray provides multi-dimensional Ruby arrays with elements of same type. The extension is designed to be mostly compatible with Masahiro Tanaka's NArray. However it allows the definition of custom element types and operations on them. This work was also inspired by Ronald Garcia's boost::multi_array and by Todd Veldhuizen's Blitz++.}
17
+ AUTHOR = %q{Jan Wedekind}
18
+ EMAIL = %q{jan@wedesoft.de}
19
+ HOMEPAGE = %q{http://wedesoft.github.com/multiarray/}
20
+
21
+ $SITELIBDIR = Config::CONFIG[ 'sitelibdir' ]
22
+
23
+ task :default do
24
+ end
25
+
26
+ desc 'Install Ruby extension'
27
+ task :install do
28
+ verbose true do
29
+ for f in RB_FILES do
30
+ FileUtils.mkdir_p "#{$SITELIBDIR}/#{File.dirname( f[ 4 .. -1 ] )}"
31
+ FileUtils.cp_r f, "#{$SITELIBDIR}/#{f[ 4 .. -1 ]}"
32
+ end
33
+ end
34
+ end
35
+
36
+ desc 'Uninstall Ruby extension'
37
+ task :uninstall do
38
+ verbose true do
39
+ for f in RB_FILES do
40
+ FileUtils.rm_f "#{$SITELIBDIR}/#{f[ 4 .. -1 ]}"
41
+ end
42
+ end
43
+ end
44
+
45
+ Rake::TestTask.new do |t|
46
+ t.test_files = TC_FILES
47
+ end
48
+
49
+ begin
50
+ require 'yard'
51
+ YARD::Rake::YardocTask.new :yard do |y|
52
+ y.options << '--no-private'
53
+ y.files << FileList[ 'lib/**/*.rb' ]
54
+ end
55
+ rescue LoadError
56
+ STDERR.puts 'Please install \'yard\' if you want to generate documentation'
57
+ end
58
+
59
+ Rake::PackageTask.new PKG_NAME, PKG_VERSION do |p|
60
+ p.need_tar = true
61
+ p.package_files = PKG_FILES
62
+ end
63
+
64
+ begin
65
+ require 'rubygems/builder'
66
+ $SPEC = Gem::Specification.new do |s|
67
+ s.name = PKG_NAME
68
+ s.version = PKG_VERSION
69
+ s.platform = Gem::Platform::RUBY
70
+ s.date = Date.today.to_s
71
+ s.summary = SUMMARY
72
+ s.description = DESCRIPTION
73
+ s.author = AUTHOR
74
+ s.email = EMAIL
75
+ s.homepage = HOMEPAGE
76
+ s.files = PKG_FILES
77
+ s.test_files = TC_FILES
78
+ s.require_paths = [ 'lib' ]
79
+ s.rubyforge_project = %q{hornetseye}
80
+ s.extensions = %w{Rakefile}
81
+ s.has_rdoc = 'yard'
82
+ s.extra_rdoc_files = []
83
+ s.rdoc_options = %w{--no-private}
84
+ s.add_dependency %q<malloc>, [ '~> 0.2' ]
85
+ end
86
+ GEM_SOURCE = "#{PKG_NAME}-#{PKG_VERSION}.gem"
87
+ desc "Build the gem file #{GEM_SOURCE}"
88
+ task :gem => [ "pkg/#{GEM_SOURCE}" ]
89
+ file "pkg/#{GEM_SOURCE}" => [ 'pkg' ] + $SPEC.files do
90
+ Gem::Builder.new( $SPEC ).build
91
+ verbose true do
92
+ FileUtils.mv GEM_SOURCE, "pkg/#{GEM_SOURCE}"
93
+ end
94
+ end
95
+ rescue LoadError
96
+ STDERR.puts 'Please install \'rubygems\' if you want to create Gem packages'
97
+ end
98
+
99
+ CLOBBER.include 'doc'
data/lib/multiarray.rb CHANGED
@@ -5,6 +5,7 @@ require 'multiarray/memory'
5
5
  require 'multiarray/type'
6
6
  require 'multiarray/type_operation'
7
7
  require 'multiarray/descriptortype'
8
+ require 'multiarray/object'
8
9
  require 'multiarray/int_'
9
10
  require 'multiarray/int'
10
11
  require 'multiarray/composite_type'
@@ -22,8 +22,8 @@ module Hornetseye
22
22
  # @return [Class] Returns the storage type for the element type.
23
23
  #
24
24
  # @private
25
- def memory
26
- element_type.memory
25
+ def storage
26
+ element_type.storage
27
27
  end
28
28
 
29
29
  # Number of bytes for storing an object of this type
@@ -33,7 +33,7 @@ module Hornetseye
33
33
  # @return [Class] Returns +Memory+.
34
34
  #
35
35
  # @private
36
- def memory
36
+ def storage
37
37
  Memory
38
38
  end
39
39
 
@@ -49,7 +49,7 @@ module Hornetseye
49
49
 
50
50
  # Default value for integers
51
51
  #
52
- # @return [Integer] Returns +0+.
52
+ # @return [Object] Returns +0+.
53
53
  #
54
54
  # @private
55
55
  def default
@@ -0,0 +1,53 @@
1
+ module Hornetseye
2
+
3
+ # Class for representing Ruby objects
4
+ class OBJECT < Type
5
+
6
+ class << self
7
+
8
+ # Returns the type of storage object for storing values
9
+ #
10
+ # @return [Class] Returns +List+.
11
+ #
12
+ # @private
13
+ def storage
14
+ List
15
+ end
16
+
17
+ # Number of storage elements for storing an object of this type
18
+ #
19
+ # @return [Integer] Returns +1+.
20
+ #
21
+ # @private
22
+ def bytesize
23
+ 1
24
+ end
25
+
26
+ # Default value for Ruby objects.
27
+ #
28
+ # @return [Object] Returns +nil+.
29
+ #
30
+ # @private
31
+ def default
32
+ nil
33
+ end
34
+
35
+ # Get string with information about this type
36
+ #
37
+ # @return [String] Returns +'OBJECT'+.
38
+ def to_s
39
+ 'OBJECT'
40
+ end
41
+
42
+ # Get string with information about this type
43
+ #
44
+ # @return [String] Returns +'OBJECT'+.
45
+ def inspect
46
+ to_s
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -40,7 +40,6 @@ module Hornetseye
40
40
  # @see #MultiArray
41
41
  # @see CompositeType.element_type
42
42
  # @see CompositeType.num_elements
43
- # @see Sequence_.stride
44
43
  def Sequence( element_type, num_elements,
45
44
  stride = element_type.size )
46
45
  retval = Class.new Sequence_
@@ -32,7 +32,7 @@ module Hornetseye
32
32
 
33
33
  # Get default value for this array type.
34
34
  #
35
- # @return [Sequence_] Returns a multi-dimensional array filled with the
35
+ # @return [Object] Returns a multi-dimensional array filled with the
36
36
  # default value of the element type.
37
37
  #
38
38
  # @private
@@ -29,8 +29,8 @@ module Hornetseye
29
29
  raise "Index must be in 0 ... #{num_elements} " +
30
30
  "(was #{indices.last.inspect})"
31
31
  end
32
- element_memory = @memory + indices.last * stride * typecode.bytesize
33
- element_type.wrap( element_memory ).sel *indices[ 0 ... -1 ]
32
+ element_storage = @storage + indices.last * stride * typecode.bytesize
33
+ element_type.wrap( element_storage ).sel *indices[ 0 ... -1 ]
34
34
  end
35
35
  end
36
36
 
@@ -13,7 +13,7 @@ module Hornetseye
13
13
  #
14
14
  # @private
15
15
  def alloc
16
- memory.alloc bytesize
16
+ storage.alloc bytesize
17
17
  end
18
18
 
19
19
  # Create new instance viewing the data of the indicated +Storage+ object
@@ -21,8 +21,8 @@ module Hornetseye
21
21
  # @return [Type] Object of this class.
22
22
  #
23
23
  # @private
24
- def wrap( memory )
25
- new nil, :memory => memory
24
+ def wrap( storage )
25
+ new nil, :storage => storage
26
26
  end
27
27
 
28
28
  # Returns the element type for arrays. Otherwise it returns +self+
@@ -78,7 +78,7 @@ module Hornetseye
78
78
  # @return [Storage]
79
79
  #
80
80
  # @private
81
- attr_accessor :memory
81
+ attr_accessor :storage
82
82
 
83
83
  # Get number of bytes memory required to store the data of an instance
84
84
  #
@@ -144,14 +144,14 @@ module Hornetseye
144
144
  # Create new instance of this type
145
145
  #
146
146
  # @param value [Object] Optional initial value for this instance.
147
- # @option options [Storage] :memory (self.class.alloc) Use specified
147
+ # @option options [Storage] :storage (self.class.alloc) Use specified
148
148
  # +Storage+ object instead of creating a new one.
149
149
  #
150
150
  # @see alloc
151
151
  #
152
152
  # @private
153
153
  def initialize( value = nil, options = {} )
154
- @memory = options[ :memory ] ? options[ :memory ] : self.class.alloc
154
+ @storage = options[ :storage ] ? options[ :storage ] : self.class.alloc
155
155
  set value unless value.nil?
156
156
  end
157
157
 
@@ -5,13 +5,13 @@ module Hornetseye
5
5
 
6
6
  # @private
7
7
  def set( value = typecode.default )
8
- @memory.store self.class, value
8
+ @storage.store self.class, value
9
9
  value
10
10
  end
11
11
 
12
12
  # @private
13
13
  def get
14
- @memory.load self.class
14
+ @storage.load self.class
15
15
  end
16
16
 
17
17
  # @private
data/test/tc_object.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'test/unit'
2
+ Kernel::require 'multiarray'
3
+
4
+ class TC_Object < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @@t = Hornetseye::OBJECT
8
+ end
9
+
10
+ def teardown
11
+ @@t = nil
12
+ end
13
+
14
+ def test_object_default
15
+ assert_nil @@t.default
16
+ end
17
+
18
+ def test_int_to_s
19
+ assert_equal 'OBJECT', @@t.to_s
20
+ end
21
+
22
+ def test_int_inspect
23
+ assert_equal @@t.to_s, @@t.inspect
24
+ end
25
+
26
+ def test_bytesize
27
+ assert_equal 1, @@t.bytesize
28
+ end
29
+
30
+ def test_typecode
31
+ assert_equal @@t, @@t.typecode
32
+ end
33
+
34
+ def test_shape
35
+ assert_equal [], @@t.shape
36
+ end
37
+
38
+ def test_size
39
+ assert_equal 1, @@t.size
40
+ end
41
+
42
+ def test_to_s
43
+ assert_equal '42', @@t.new( 42 ).to_s
44
+ end
45
+
46
+ def test_inspect
47
+ assert_equal "OBJECT(42)", @@t.new( 42 ).inspect
48
+ end
49
+
50
+ def test_get_set
51
+ i = @@t.new nil
52
+ assert_nil i.get
53
+ assert_equal 42, i.set( 42 )
54
+ assert_equal 42, i.get
55
+ assert_nil i.set
56
+ assert_nil i.get
57
+ end
58
+
59
+ def test_at_assign
60
+ i = @@t.new nil
61
+ assert_nil i.at
62
+ assert_equal 42, i.assign( 42 )
63
+ assert_equal 42, i.at
64
+ assert_raise( ArgumentError ) { i.at 0 }
65
+ assert_raise( ArgumentError ) { i.assign 0, nil }
66
+ i = @@t.new nil
67
+ assert_nil i[]
68
+ assert_equal 42, i[] = 42
69
+ assert_equal 42, i[]
70
+ assert_raise( ArgumentError ) { i[ 0 ] }
71
+ assert_raise( ArgumentError ) { i[ 0 ] = nil }
72
+ end
73
+
74
+ def test_op
75
+ i = @@t.new 1
76
+ assert_equal 3, i.op( 2 ) { |x| set get + x }.get
77
+ end
78
+
79
+ end
data/test/tc_sequence.rb CHANGED
@@ -4,7 +4,8 @@ Kernel::require 'multiarray'
4
4
  class TC_Sequence < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @@types = [ Hornetseye::UBYTE,
7
+ @@types = [ Hornetseye::OBJECT,
8
+ Hornetseye::UBYTE,
8
9
  Hornetseye::BYTE,
9
10
  Hornetseye::USINT,
10
11
  Hornetseye::SINT,
@@ -28,7 +29,7 @@ class TC_Sequence < Test::Unit::TestCase
28
29
  for t in @@types
29
30
  s = Hornetseye::Sequence.new t, 3
30
31
  s.set
31
- assert_equal [ 0, 0, 0 ], s.to_a
32
+ assert_equal [ t.default ] * 3, s.to_a
32
33
  end
33
34
  end
34
35
 
@@ -105,13 +106,13 @@ class TC_Sequence < Test::Unit::TestCase
105
106
  for t in @@types
106
107
  s1 = Hornetseye::Sequence( t, 3 ).new
107
108
  s1[] = 2
108
- assert_equal 0, s1.set
109
- assert_equal [ 0, 0, 0 ], s1.get.to_a
110
- assert_equal [ 0, 0, 0 ], s1.to_a
109
+ assert_equal t.default, s1.set
110
+ assert_equal [ t.default ] * 3, s1.get.to_a
111
+ assert_equal [ t.default ] * 3, s1.to_a
111
112
  assert_equal 1, s1.set( 1 )
112
113
  assert_equal [ 1, 1, 1 ], s1.to_a
113
114
  assert_equal [ 2, 3 ], s1.set( [ 2, 3 ] )
114
- assert_equal [ 2, 3, 0 ], s1.to_a
115
+ assert_equal [ 2, 3, t.default ], s1.to_a
115
116
  s2 = Hornetseye::Sequence( t, 3 ).new
116
117
  s2[] = [ 1, 2, 3 ]
117
118
  s1[] = s2
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'tc_int'
3
+ require 'tc_object'
3
4
  require 'tc_sequence'
4
5
  require 'tc_multiarray'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiarray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Wedekind
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-11 00:00:00 +00:00
12
+ date: 2009-12-14 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -26,13 +26,12 @@ description: This Ruby-extension defines Hornetseye::MultiArray and other native
26
26
  email: jan@wedesoft.de
27
27
  executables: []
28
28
 
29
- extensions: []
30
-
29
+ extensions:
30
+ - Rakefile
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
- - source.gemspec
35
- - Makefile
34
+ - Rakefile
36
35
  - README
37
36
  - COPYING
38
37
  - .document
@@ -47,11 +46,13 @@ files:
47
46
  - lib/multiarray/int.rb
48
47
  - lib/multiarray/type.rb
49
48
  - lib/multiarray/storage.rb
49
+ - lib/multiarray/object.rb
50
50
  - lib/multiarray/int_.rb
51
51
  - lib/multiarray/memory.rb
52
52
  - lib/multiarray/sequence_operation.rb
53
- - test/tc_multiarray.rb
54
53
  - test/ts_multiarray.rb
54
+ - test/tc_multiarray.rb
55
+ - test/tc_object.rb
55
56
  - test/tc_int.rb
56
57
  - test/tc_sequence.rb
57
58
  has_rdoc: yard
@@ -84,5 +85,6 @@ specification_version: 3
84
85
  summary: Multi-dimensional and uniform Ruby arrays
85
86
  test_files:
86
87
  - test/tc_multiarray.rb
88
+ - test/tc_object.rb
87
89
  - test/tc_int.rb
88
90
  - test/tc_sequence.rb
data/Makefile DELETED
@@ -1,78 +0,0 @@
1
- .SUFFIXES:
2
- .SUFFIXES: .gem .o .cc .hh .rb .tar .gz .bz2
3
-
4
- RUBY_VERSION = 1.8
5
- MULTIARRAY_VERSION = 0.2.3
6
-
7
- CP = cp
8
- RM = rm -Rf
9
- MKDIR = mkdir -p
10
- GEM = gem$(RUBY_VERSION)
11
- RUBY = ruby$(RUBY_VERSION)
12
- YARDOC = yardoc
13
- RI = ri$(RUBY_VERSION)
14
- TAR = tar
15
- GIT = git
16
- SITELIBDIR = $(shell $(RUBY) -r mkmf -e "puts \"\#{Config::CONFIG['sitelibdir']}\"")
17
-
18
- MAIN = Makefile source.gemspec README COPYING .document
19
- LIB = $(wildcard lib/*.rb)
20
- PKG_LIB = $(wildcard lib/multiarray/*.rb)
21
- TEST = $(wildcard test/*.rb)
22
- DOC = $(wildcard doc/*.rb)
23
- SOURCES = $(MAIN) $(LIB) $(PKG_LIB) $(TEST) $(DOC)
24
-
25
- all:: target
26
-
27
- target::
28
-
29
- gem:: multiarray-$(MULTIARRAY_VERSION).gem
30
-
31
- install:: $(LIB) $(PKG_LIB)
32
- $(MKDIR) $(SITELIBDIR)
33
- $(MKDIR) $(SITELIBDIR)/multiarray
34
- $(CP) $(LIB) $(SITELIBDIR)
35
- $(CP) $(PKG_LIB) $(SITELIBDIR)/multiarray
36
-
37
- uninstall::
38
- $(RM) $(addprefix $(SITELIBDIR)/,$(notdir $(LIB))) $(addprefix $(SITELIBDIR)/multiarray/,$(notdir $(PKG_LIB)))
39
-
40
- install-gem:: multiarray-$(MULTIARRAY_VERSION).gem
41
- $(GEM) install --local $<
42
-
43
- uninstall-gem::
44
- $(GEM) uninstall multiarray || echo Nothing to uninstall
45
-
46
- yardoc:: README $(LIB)
47
- $(YARDOC) --no-private
48
-
49
- check:: $(LIB) $(PKG_LIB) $(TEST)
50
- $(RUBY) -rrubygems -Ilib -Itest test/ts_multiarray.rb
51
-
52
- push-gem:: multiarray-$(MULTIARRAY_VERSION).gem
53
- echo Pushing $< in 3 seconds!
54
- sleep 3
55
- $(GEM) push $<
56
-
57
- push-git::
58
- echo Pushing to origin in 3 seconds!
59
- sleep 3
60
- $(GIT) push origin master
61
-
62
- dist:: dist-gzip
63
-
64
- dist-gzip:: multiarray-$(MULTIARRAY_VERSION).tar.gz
65
-
66
- dist-bzip2:: multiarray-$(MULTIARRAY_VERSION).tar.bz2
67
-
68
- multiarray-$(MULTIARRAY_VERSION).gem: $(SOURCES)
69
- $(GEM) build source.gemspec
70
-
71
- multiarray-$(MULTIARRAY_VERSION).tar.gz: $(SOURCES)
72
- $(TAR) czf $@ $(SOURCES)
73
-
74
- multiarray-$(MULTIARRAY_VERSION).tar.bz2: $(SOURCES)
75
- $(TAR) cjf $@ $(SOURCES)
76
-
77
- clean::
78
- $(RM) *~ lib/*~ lib/multiarray/*~ test/*~ *.gem doc
data/source.gemspec DELETED
@@ -1,24 +0,0 @@
1
- require 'date'
2
- Gem::Specification.new do |s|
3
- s.name = %q{multiarray}
4
- s.version = '0.2.3'
5
- s.platform = Gem::Platform::RUBY
6
- s.date = Date.today.to_s
7
- s.summary = %q{Multi-dimensional and uniform Ruby arrays}
8
- s.description = %q{This Ruby-extension defines Hornetseye::MultiArray and other native datatypes. Hornetseye::MultiArray provides multi-dimensional Ruby arrays with elements of same type. The extension is designed to be mostly compatible with Masahiro Tanaka's NArray. However it allows the definition of custom element types and operations on them. This work was also inspired by Ronald Garcia's boost::multi_array and by Todd Veldhuizen's Blitz++.}
9
- s.author = %q{Jan Wedekind}
10
- s.email = %q{jan@wedesoft.de}
11
- s.homepage = %q{http://wedesoft.github.com/multiarray/}
12
- s.files = [ 'source.gemspec', 'Makefile', 'README', 'COPYING',
13
- '.document' ] +
14
- Dir.glob( 'lib/*.rb' ) +
15
- Dir.glob( 'lib/multiarray/*.rb' ) +
16
- Dir.glob( 'test/*.rb' )
17
- s.test_files = Dir.glob( 'test/tc_*.rb' )
18
- s.require_paths = [ 'lib' ]
19
- s.rubyforge_project = %q{hornetseye}
20
- s.has_rdoc = 'yard'
21
- s.extra_rdoc_files = []
22
- s.rdoc_options = %w{--no-private}
23
- s.add_dependency %q<malloc>, [ '~> 0.2' ]
24
- end