multiarray 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Makefile CHANGED
@@ -2,13 +2,15 @@
2
2
  .SUFFIXES: .gem .o .cc .hh .rb .tar .gz .bz2
3
3
 
4
4
  RUBY_VERSION = 1.8
5
- MULTIARRAY_VERSION = 0.2.0
5
+ MULTIARRAY_VERSION = 0.2.1
6
6
 
7
7
  CP = cp
8
- RM = rm -f
8
+ RM = rm -Rf
9
9
  MKDIR = mkdir -p
10
10
  GEM = gem$(RUBY_VERSION)
11
11
  RUBY = ruby$(RUBY_VERSION)
12
+ YARDOC = yardoc
13
+ RI = ri$(RUBY_VERSION)
12
14
  TAR = tar
13
15
  GIT = git
14
16
  SITELIBDIR = $(shell $(RUBY) -r mkmf -e "puts \"\#{Config::CONFIG['sitelibdir']}\"")
@@ -41,6 +43,9 @@ install-gem:: multiarray-$(MULTIARRAY_VERSION).gem
41
43
  uninstall-gem::
42
44
  $(GEM) uninstall multiarray || echo Nothing to uninstall
43
45
 
46
+ yardoc:: README $(LIB)
47
+ $(YARDOC)
48
+
44
49
  check:: $(LIB) $(PKG_LIB) $(TEST)
45
50
  $(RUBY) -rrubygems -Ilib -Itest test/ts_multiarray.rb
46
51
 
@@ -70,4 +75,4 @@ multiarray-$(MULTIARRAY_VERSION).tar.bz2: $(SOURCES)
70
75
  $(TAR) cjf $@ $(SOURCES)
71
76
 
72
77
  clean::
73
- rm -f *~ lib/*~ lib/multiarray/*~ test/*~ doc/*~ *.gem
78
+ $(RM) *~ lib/*~ lib/multiarray/*~ test/*~ *.gem doc
data/lib/multiarray.rb CHANGED
@@ -2,13 +2,14 @@ require 'malloc'
2
2
  require 'multiarray/storage'
3
3
  require 'multiarray/list'
4
4
  require 'multiarray/memory'
5
- require 'multiarray/type_operation'
6
5
  require 'multiarray/type'
6
+ require 'multiarray/type_operation'
7
7
  require 'multiarray/descriptortype'
8
- require 'multiarray/int'
8
+ require 'multiarray/int_'
9
9
  require 'multiarray/composite_type'
10
- require 'multiarray/sequence_operation'
10
+ require 'multiarray/sequence_'
11
11
  require 'multiarray/sequence'
12
+ require 'multiarray/sequence_operation'
12
13
  require 'multiarray/multiarray'
13
14
 
14
15
  class Proc
File without changes
@@ -1,130 +1,17 @@
1
1
  module Hornetseye
2
2
 
3
- class Sequence_ < CompositeType
3
+ class Sequence
4
4
 
5
5
  class << self
6
6
 
7
- attr_accessor :stride
8
-
9
- def inspect
10
- to_s
11
- end
12
-
13
- def default
14
- retval = new
15
- retval.set
16
- retval
17
- end
18
-
19
- def to_s
20
- "Sequence(#{element_type.to_s},#{num_elements.to_s})"
21
- end
22
-
23
- def typecode
24
- element_type.typecode
25
- end
26
-
27
- def empty?
28
- num_elements == 0
29
- end
30
-
31
- def shape
32
- element_type.shape + [ num_elements ]
7
+ def new( element_type, num_elements )
8
+ Hornetseye::Sequence( element_type, num_elements ).new
33
9
  end
34
10
 
35
11
  end
36
12
 
37
- def stride
38
- self.class.stride
39
- end
40
-
41
- def inspect( indent = nil, lines = nil )
42
- if indent
43
- prepend = ''
44
- else
45
- prepend = "#{self.class.inspect}:\n"
46
- indent = 0
47
- lines = 0
48
- end
49
- if empty?
50
- retval = '[]'
51
- else
52
- retval = '[ '
53
- for i in 0 ... num_elements
54
- x = at i
55
- if x.is_a? Sequence_
56
- if i > 0
57
- retval += ",\n "
58
- lines += 1
59
- if lines >= 10
60
- retval += '...' if indent == 0
61
- break
62
- end
63
- retval += ' ' * indent
64
- end
65
- str = x.inspect indent + 1, lines
66
- lines += str.count "\n"
67
- retval += str
68
- if lines >= 10
69
- retval += '...' if indent == 0
70
- break
71
- end
72
- else
73
- retval += ', ' if i > 0
74
- str = x.inspect
75
- if retval.size + str.size >= 74 - '...'.size -
76
- '[ ]'.size * indent.succ
77
- retval += '...'
78
- break
79
- else
80
- retval += str
81
- end
82
- end
83
- end
84
- retval += ' ]' unless lines >= 10
85
- end
86
- prepend + retval
87
- end
88
-
89
- def to_a
90
- ( 0 ... num_elements ).collect do |i|
91
- x = at i
92
- x.is_a?( Sequence_ ) ? x.to_a : x
93
- end
94
- end
95
-
96
- def set( value = typecode.default )
97
- if value.is_a? Array
98
- for i in 0 ... num_elements
99
- assign i, i < value.size ? value[ i ] : typecode.default
100
- end
101
- else
102
- op( value ) { |x| set x }
103
- end
104
- value
105
- end
106
-
107
- def get
108
- self
109
- end
110
-
111
- def sel( *indices )
112
- if indices.empty?
113
- super *indices
114
- else
115
- unless ( 0 ... num_elements ).member? indices.last
116
- raise "Index must be in 0 ... #{num_elements} " +
117
- "(was #{indices.last.inspect})"
118
- end
119
- element_memory = @memory + indices.last * stride * typecode.bytesize
120
- element_type.new( :memory => element_memory ).sel *indices[ 0 ... -1 ]
121
- end
122
- end
123
-
124
13
  end
125
14
 
126
- Sequence_.class_eval { include SequenceOperation }
127
-
128
15
  def Sequence( element_type, num_elements,
129
16
  stride = element_type.size )
130
17
  retval = Class.new Sequence_
@@ -0,0 +1,112 @@
1
+ module Hornetseye
2
+
3
+ class Sequence_ < CompositeType
4
+
5
+ class << self
6
+
7
+ attr_accessor :stride
8
+
9
+ def inspect
10
+ to_s
11
+ end
12
+
13
+ def default
14
+ retval = new
15
+ retval.set
16
+ retval
17
+ end
18
+
19
+ def to_s
20
+ if element_type
21
+ shortcut = element_type < Sequence_ ? 'MultiArray' : 'Sequence'
22
+ typename = typecode.to_s
23
+ if typename =~ /^[A-Z]+$/
24
+ "#{shortcut}.#{typename.downcase}(#{shape.join ','})"
25
+ else
26
+ "#{shortcut}(#{typename},#{shape.join ','})"
27
+ end
28
+ else
29
+ 'Sequence_'
30
+ end
31
+ end
32
+
33
+ def typecode
34
+ element_type.typecode
35
+ end
36
+
37
+ def empty?
38
+ num_elements == 0
39
+ end
40
+
41
+ def shape
42
+ element_type.shape + [ num_elements ]
43
+ end
44
+
45
+ end
46
+
47
+ def stride
48
+ self.class.stride
49
+ end
50
+
51
+ def inspect( indent = nil, lines = nil )
52
+ if indent
53
+ prepend = ''
54
+ else
55
+ prepend = "#{self.class.inspect}:\n"
56
+ indent = 0
57
+ lines = 0
58
+ end
59
+ if empty?
60
+ retval = '[]'
61
+ else
62
+ retval = '[ '
63
+ for i in 0 ... num_elements
64
+ x = at i
65
+ if x.is_a? Sequence_
66
+ if i > 0
67
+ retval += ",\n "
68
+ lines += 1
69
+ if lines >= 10
70
+ retval += '...' if indent == 0
71
+ break
72
+ end
73
+ retval += ' ' * indent
74
+ end
75
+ str = x.inspect indent + 1, lines
76
+ lines += str.count "\n"
77
+ retval += str
78
+ if lines >= 10
79
+ retval += '...' if indent == 0
80
+ break
81
+ end
82
+ else
83
+ retval += ', ' if i > 0
84
+ str = x.inspect
85
+ if retval.size + str.size >= 74 - '...'.size -
86
+ '[ ]'.size * indent.succ
87
+ retval += '...'
88
+ break
89
+ else
90
+ retval += str
91
+ end
92
+ end
93
+ end
94
+ retval += ' ]' unless lines >= 10
95
+ end
96
+ prepend + retval
97
+ end
98
+
99
+ def to_s
100
+ to_a.to_s
101
+ end
102
+
103
+ def to_a
104
+ ( 0 ... num_elements ).collect do |i|
105
+ x = at i
106
+ x.is_a?( Sequence_ ) ? x.to_a : x
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -2,6 +2,34 @@ module Hornetseye
2
2
 
3
3
  module SequenceOperation
4
4
 
5
+ def set( value = typecode.default )
6
+ if value.is_a? Array
7
+ for i in 0 ... num_elements
8
+ assign i, i < value.size ? value[ i ] : typecode.default
9
+ end
10
+ else
11
+ op( value ) { |x| set x }
12
+ end
13
+ value
14
+ end
15
+
16
+ def get
17
+ self
18
+ end
19
+
20
+ def sel( *indices )
21
+ if indices.empty?
22
+ super *indices
23
+ else
24
+ unless ( 0 ... num_elements ).member? indices.last
25
+ raise "Index must be in 0 ... #{num_elements} " +
26
+ "(was #{indices.last.inspect})"
27
+ end
28
+ element_memory = @memory + indices.last * stride * typecode.bytesize
29
+ element_type.wrap( element_memory ).sel *indices[ 0 ... -1 ]
30
+ end
31
+ end
32
+
5
33
  def op( *args, &action )
6
34
  for i in 0 ... num_elements
7
35
  sub_args = args.collect do |arg|
@@ -14,4 +42,6 @@ module Hornetseye
14
42
 
15
43
  end
16
44
 
45
+ Sequence_.class_eval { include SequenceOperation }
46
+
17
47
  end
@@ -8,6 +8,10 @@ module Hornetseye
8
8
  memory.alloc bytesize
9
9
  end
10
10
 
11
+ def wrap( memory )
12
+ new :memory => memory
13
+ end
14
+
11
15
  def typecode
12
16
  self
13
17
  end
@@ -76,19 +80,6 @@ module Hornetseye
76
80
  get.to_a
77
81
  end
78
82
 
79
- def set( value = typecode.default )
80
- @memory.store self.class, value
81
- value
82
- end
83
-
84
- def get
85
- @memory.load self.class
86
- end
87
-
88
- def sel
89
- self
90
- end
91
-
92
83
  def at( *indices )
93
84
  sel( *indices ).get
94
85
  end
@@ -103,6 +94,4 @@ module Hornetseye
103
94
 
104
95
  end
105
96
 
106
- Type.class_eval { include TypeOperation }
107
-
108
97
  end
@@ -2,6 +2,19 @@ module Hornetseye
2
2
 
3
3
  module TypeOperation
4
4
 
5
+ def set( value = typecode.default )
6
+ @memory.store self.class, value
7
+ value
8
+ end
9
+
10
+ def get
11
+ @memory.load self.class
12
+ end
13
+
14
+ def sel
15
+ self
16
+ end
17
+
5
18
  def op( *args, &action )
6
19
  instance_exec *args, &action
7
20
  self
@@ -9,4 +22,6 @@ module Hornetseye
9
22
 
10
23
  end
11
24
 
25
+ Type.class_eval { include TypeOperation }
26
+
12
27
  end
data/source.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'date'
2
2
  Gem::Specification.new do |s|
3
3
  s.name = %q{multiarray}
4
- s.version = '0.2.0'
4
+ s.version = '0.2.1'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.date = Date.today.to_s
7
7
  s.summary = %q{Multi-dimensional and uniform Ruby arrays}
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.test_files = Dir.glob( 'test/tc_*.rb' )
17
17
  s.require_paths = [ 'lib' ]
18
18
  s.rubyforge_project = %q{hornetseye}
19
- s.has_rdoc = true
20
- s.extra_rdoc_files = [ 'README' ]
21
- s.rdoc_options = %w{--exclude=/Makefile|.*\.(rb)/ --main README}
19
+ s.has_rdoc = 'yard'
20
+ # s.extra_rdoc_files = [ 'README' ]
21
+ # s.rdoc_options = %w{--exclude=/Makefile|.*\.(rb)/ --main README}
22
22
  s.add_dependency %q<malloc>, [ '~> 0.2' ]
23
23
  end
data/test/tc_int.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'multiarray'
2
+ Kernel::require 'multiarray'
3
3
 
4
4
  class TC_Int < Test::Unit::TestCase
5
5
 
data/test/tc_sequence.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'multiarray'
2
+ Kernel::require 'multiarray'
3
3
 
4
4
  class TC_Sequence < Test::Unit::TestCase
5
5
 
@@ -24,15 +24,24 @@ class TC_Sequence < Test::Unit::TestCase
24
24
  end
25
25
  end
26
26
 
27
+ def test_sequence_new
28
+ for t in @@types
29
+ s = Hornetseye::Sequence.new t, 3
30
+ s.set
31
+ assert_equal [ 0, 0, 0 ], s.to_a
32
+ end
33
+ end
34
+
27
35
  def test_sequence_to_s
28
36
  for t in @@types
29
- assert_equal "Sequence(#{t.to_s},3)", Hornetseye::Sequence( t, 3 ).to_s
37
+ assert_equal "Sequence.#{t.to_s.downcase}(3)",
38
+ Hornetseye::Sequence( t, 3 ).to_s
30
39
  end
31
40
  end
32
41
 
33
42
  def test_sequence_inspect
34
43
  for t in @@types
35
- assert_equal "Sequence(#{t.inspect},3)",
44
+ assert_equal "Sequence.#{t.inspect.downcase}(3)",
36
45
  Hornetseye::Sequence( t, 3 ).inspect
37
46
  end
38
47
  end
@@ -72,7 +81,15 @@ class TC_Sequence < Test::Unit::TestCase
72
81
  for t in @@types
73
82
  s = Hornetseye::Sequence( t, 3 ).new
74
83
  s[] = [ 1, 2, 3 ]
75
- assert_equal "Sequence(#{t.inspect},3):\n[ 1, 2, 3 ]", s.inspect
84
+ assert_equal "Sequence.#{t.inspect.downcase}(3):\n[ 1, 2, 3 ]", s.inspect
85
+ end
86
+ end
87
+
88
+ def test_to_s
89
+ for t in @@types
90
+ s = Hornetseye::Sequence( t, 3 ).new
91
+ s[] = [ 1, 2, 3 ]
92
+ assert_equal '123', s.to_s
76
93
  end
77
94
  end
78
95
 
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.0
4
+ version: 0.2.1
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-09 00:00:00 +00:00
12
+ date: 2009-12-10 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,37 +28,36 @@ executables: []
28
28
 
29
29
  extensions: []
30
30
 
31
- extra_rdoc_files:
32
- - README
31
+ extra_rdoc_files: []
32
+
33
33
  files:
34
34
  - source.gemspec
35
35
  - Makefile
36
36
  - README
37
37
  - COPYING
38
38
  - lib/multiarray.rb
39
+ - lib/multiarray/sequence_.rb
39
40
  - lib/multiarray/composite_type.rb
40
41
  - lib/multiarray/multiarray.rb
41
42
  - lib/multiarray/sequence.rb
42
43
  - lib/multiarray/list.rb
43
44
  - lib/multiarray/descriptortype.rb
44
45
  - lib/multiarray/type_operation.rb
45
- - lib/multiarray/int.rb
46
46
  - lib/multiarray/type.rb
47
47
  - lib/multiarray/storage.rb
48
+ - lib/multiarray/int_.rb
48
49
  - lib/multiarray/memory.rb
49
50
  - lib/multiarray/sequence_operation.rb
50
51
  - test/ts_multiarray.rb
51
52
  - test/tc_int.rb
52
53
  - test/tc_sequence.rb
53
- has_rdoc: true
54
+ has_rdoc: yard
54
55
  homepage: http://wedesoft.github.com/multiarray/
55
56
  licenses: []
56
57
 
57
58
  post_install_message:
58
- rdoc_options:
59
- - --exclude=/Makefile|.*\.(rb)/
60
- - --main
61
- - README
59
+ rdoc_options: []
60
+
62
61
  require_paths:
63
62
  - lib
64
63
  required_ruby_version: !ruby/object:Gem::Requirement