multiarray 0.23.1 → 0.23.2

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.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/packagetask'
6
6
  require 'rbconfig'
7
7
 
8
8
  PKG_NAME = 'multiarray'
9
- PKG_VERSION = '0.23.1'
9
+ PKG_VERSION = '0.23.2'
10
10
  RB_FILES = FileList[ 'lib/**/*.rb' ]
11
11
  TC_FILES = FileList[ 'test/tc_*.rb' ]
12
12
  TS_FILES = FileList[ 'test/ts_*.rb' ]
@@ -933,7 +933,7 @@ module Hornetseye
933
933
  if values.all? { |value| value.is_a? InternalComplex or value.is_a? Complex or
934
934
  value.is_a? Float or value.is_a? Integer }
935
935
  if values.any? { |value| value.is_a? InternalComplex or value.is_a? Complex }
936
- elements = values.inject( [] ) do |arr,value|
936
+ elements = values.inject([]) do |arr,value|
937
937
  if value.is_a? InternalComplex or value.is_a? Complex
938
938
  arr + [ value.real, value.imag ]
939
939
  else
@@ -215,9 +215,9 @@ module Hornetseye
215
215
  def strip
216
216
  stripped = [ @dest, @source, @default, @zero, @labels, @rank, @n ].
217
217
  collect { |value| value.strip }
218
- return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
219
- stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
220
- self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
218
+ return stripped.inject([]) { |vars,elem| vars + elem[0] },
219
+ stripped.inject([]) { |values,elem| values + elem[1] },
220
+ self.class.new(*stripped.collect { |elem| elem[2] })
221
221
  end
222
222
 
223
223
  # Get variables contained in this term
@@ -130,7 +130,7 @@ module Hornetseye
130
130
  #
131
131
  # @private
132
132
  def variables
133
- @values.inject( Set[] ) { |vars,value| vars + value.variables }
133
+ @values.inject(Set[]) { |vars,value| vars + value.variables }
134
134
  end
135
135
 
136
136
  # Strip of all values
@@ -144,9 +144,9 @@ module Hornetseye
144
144
  # @private
145
145
  def strip
146
146
  stripped = @values.collect { |value| value.strip }
147
- return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
148
- stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
149
- self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
147
+ return stripped.inject([]) { |vars,elem| vars + elem[0] },
148
+ stripped.inject([]) { |values,elem| values + elem[1] },
149
+ self.class.new(*stripped.collect { |elem| elem[2] })
150
150
  end
151
151
 
152
152
  # Skip elements of an array
@@ -227,7 +227,7 @@ module Hornetseye
227
227
  # @see ElementWise_.conversion
228
228
  #
229
229
  # @private
230
- def ElementWise( operation, key, conversion = lambda { |t| t.send :identity } )
230
+ def ElementWise( operation, key, conversion = proc { |t| t.send :identity } )
231
231
  retval = Class.new ElementWise_
232
232
  retval.operation = operation
233
233
  retval.key = key
@@ -93,14 +93,14 @@ module Hornetseye
93
93
  def r2c
94
94
  case @typecode
95
95
  when BOOL
96
- [ lambda { |expr| "( #{expr} ) != Qfalse" } ]
96
+ [ proc { |expr| "( #{expr} ) != Qfalse" } ]
97
97
  when BYTE, UBYTE, SINT, USINT, INT, UINT
98
- [ lambda { |expr| "NUM2INT( #{expr} )" } ]
98
+ [ proc { |expr| "NUM2INT( #{expr} )" } ]
99
99
  when SFLOAT, DFLOAT
100
- [ lambda { |expr| "NUM2DBL( #{expr} )" } ]
100
+ [ proc { |expr| "NUM2DBL( #{expr} )" } ]
101
101
  else
102
102
  if @typecode < Pointer_
103
- [ lambda { |expr| "(#{identifier})mallocToPtr( #{expr} )" } ]
103
+ [ proc { |expr| "(#{identifier})mallocToPtr( #{expr} )" } ]
104
104
  elsif @typecode < Composite
105
105
  GCCType.new( @typecode.element_type ).r2c * @typecode.num_elements
106
106
  else
@@ -120,7 +120,7 @@ module Hornetseye
120
120
  #
121
121
  # @private
122
122
  def variables
123
- @sources.inject( @dest.variables + @weight.variables ) { |a,b| a + b.variables }
123
+ @sources.inject(@dest.variables + @weight.variables) { |a,b| a + b.variables }
124
124
  end
125
125
 
126
126
  # Strip of all values
@@ -134,9 +134,9 @@ module Hornetseye
134
134
  # @private
135
135
  def strip
136
136
  stripped = ( [ @dest, @weight ] + @sources ).collect { |source| source.strip }
137
- return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
138
- stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
139
- self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
137
+ return stripped.inject([]) { |vars,elem| vars + elem[0] },
138
+ stripped.inject([]) { |values,elem| values + elem[1] },
139
+ self.class.new( *stripped.collect { |elem| elem[2] } )
140
140
  end
141
141
 
142
142
  # Check whether this term is compilable
@@ -101,7 +101,7 @@ module Hornetseye
101
101
  #
102
102
  # @private
103
103
  def variables
104
- @sources.inject( @table.variables ) { |a,b| a + b.variables }
104
+ @sources.inject(@table.variables) { |a,b| a + b.variables }
105
105
  end
106
106
 
107
107
  # Strip of all values
@@ -115,9 +115,9 @@ module Hornetseye
115
115
  # @private
116
116
  def strip
117
117
  stripped = ( @sources + [ @table ] ).collect { |source| source.strip }
118
- return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
119
- stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
120
- self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
118
+ return stripped.inject([]) { |vars,elem| vars + elem[0] },
119
+ stripped.inject([]) { |values,elem| values + elem[1] },
120
+ self.class.new( *stripped.collect { |elem| elem[2] } )
121
121
  end
122
122
 
123
123
  # Skip elements of an array
@@ -134,9 +134,9 @@ module Hornetseye
134
134
  # @private
135
135
  def strip
136
136
  stripped = [ @dest, @source, @m, @index ].collect { |value| value.strip }
137
- return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
138
- stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
139
- self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
137
+ return stripped.inject([]) { |vars,elem| vars + elem[0] },
138
+ stripped.inject([]) { |values,elem| values + elem[1] },
139
+ self.class.new( *stripped.collect { |elem| elem[2] } )
140
140
  end
141
141
 
142
142
  # Check whether this term is compilable
@@ -63,9 +63,9 @@ module Hornetseye
63
63
  target = a.typecode.send conversion
64
64
  target.new mod.send( op, a.simplify.get )
65
65
  else
66
- Hornetseye::ElementWise( lambda { |x| mod.send op, x },
66
+ Hornetseye::ElementWise( proc { |x| mod.send op, x },
67
67
  "#{mod}.#{op}",
68
- lambda { |x| x.send conversion } ).
68
+ proc { |x| x.send conversion } ).
69
69
  new(a.sexp).force
70
70
  end
71
71
  else
@@ -99,9 +99,9 @@ module Hornetseye
99
99
  target = a.typecode.send coercion, b.typecode
100
100
  target.new mod.send(op, a.simplify.get, b.simplify.get)
101
101
  else
102
- Hornetseye::ElementWise( lambda { |x,y| mod.send op, x, y },
102
+ Hornetseye::ElementWise( proc { |x,y| mod.send op, x, y },
103
103
  "#{mod}.#{op}",
104
- lambda { |t,u| t.send coercion, u } ).
104
+ proc { |t,u| t.send coercion, u } ).
105
105
  new(a.sexp, b.sexp).force
106
106
  end
107
107
  else
@@ -320,7 +320,7 @@ module Hornetseye
320
320
  #
321
321
  # @return [Integer] Returns number of elements of this value.
322
322
  def size
323
- shape.inject(1) { |a,b| a * b }
323
+ shape.inject 1, :*
324
324
  end
325
325
 
326
326
  # Duplicate array expression if it is not in row-major format
@@ -329,7 +329,7 @@ module Hornetseye
329
329
  def memorise
330
330
  if memory
331
331
  contiguous_strides = (0 ... dimension).collect do |i|
332
- shape[0 ... i].inject(1) { |a,b| a * b }
332
+ shape[0 ... i].inject 1, :*
333
333
  end
334
334
  if strides == contiguous_strides
335
335
  self
@@ -37,8 +37,8 @@ module Hornetseye
37
37
  target = typecode.send conversion
38
38
  target.new simplify.get.send(op)
39
39
  else
40
- Hornetseye::ElementWise(lambda { |x| x.send op }, op,
41
- lambda { |t| t.send conversion }).
40
+ Hornetseye::ElementWise(proc { |x| x.send op }, op,
41
+ proc { |t| t.send conversion }).
42
42
  new(self).force
43
43
  end
44
44
  end
@@ -61,8 +61,8 @@ module Hornetseye
61
61
  target = typecode.send coercion, other.typecode
62
62
  target.new simplify.get.send(op, other.simplify.get)
63
63
  else
64
- Hornetseye::ElementWise(lambda { |x,y| x.send op, y }, op,
65
- lambda { |t,u| t.send coercion, u } ).
64
+ Hornetseye::ElementWise(proc { |x,y| x.send op, y }, op,
65
+ proc { |t,u| t.send coercion, u } ).
66
66
  new(sexp, other.sexp).force
67
67
  end
68
68
  end
@@ -141,8 +141,8 @@ module Hornetseye
141
141
  target.new(simplify.get).simplify
142
142
  else
143
143
  key = "to_#{dest.to_s.downcase}"
144
- Hornetseye::ElementWise( lambda { |x| x.to_type dest }, key,
145
- lambda { |t| t.to_type dest } ).new(self).force
144
+ Hornetseye::ElementWise( proc { |x| x.to_type dest }, key,
145
+ proc { |t| t.to_type dest } ).new(self).force
146
146
  end
147
147
  end
148
148
 
@@ -195,7 +195,7 @@ module Hornetseye
195
195
  #
196
196
  # @return [Node] Array with desired shape.
197
197
  def reshape(*ret_shape)
198
- target_size = ret_shape.inject { |a,b| a * b }
198
+ target_size = ret_shape.inject 1, :*
199
199
  if target_size != size
200
200
  raise "Target is of size #{target_size} but should be of size #{size}"
201
201
  end
@@ -219,8 +219,8 @@ module Hornetseye
219
219
  target.new simplify.get.conditional(proc { a.simplify.get },
220
220
  proc { b.simplify.get })
221
221
  else
222
- Hornetseye::ElementWise(lambda { |x,y,z| x.conditional y, z }, :conditional,
223
- lambda { |t,u,v| t.cond u, v }).
222
+ Hornetseye::ElementWise(proc { |x,y,z| x.conditional y, z }, :conditional,
223
+ proc { |t,u,v| t.cond u, v }).
224
224
  new(self, a.sexp, b.sexp).force
225
225
  end
226
226
  end
@@ -280,7 +280,7 @@ module Hornetseye
280
280
  var
281
281
  end.reverse
282
282
  order.collect { |o| variables[o] }.
283
- inject( term ) { |retval,var| Lambda.new var, retval }
283
+ inject(term) { |retval,var| Lambda.new var, retval }
284
284
  end
285
285
 
286
286
  # Cycle indices of array
@@ -318,10 +318,10 @@ module Hornetseye
318
318
  # @param [Proc] action Operation(s) to perform on elements.
319
319
  #
320
320
  # @return [Node] The resulting array.
321
- def collect( &action )
321
+ def collect(&action)
322
322
  var = Variable.new typecode
323
323
  block = action.call var
324
- conversion = lambda { |t| t.to_type action.call(Variable.new(t.typecode)).typecode }
324
+ conversion = proc { |t| t.to_type action.call(Variable.new(t.typecode)).typecode }
325
325
  Hornetseye::ElementWise( action, block.to_s, conversion ).new( self ).force
326
326
  end
327
327
 
@@ -334,14 +334,29 @@ module Hornetseye
334
334
 
335
335
  # Perform cummulative operation on array
336
336
  #
337
- # @param [Object] initial Initial value for cummulative operation.
338
- # @option options [Variable] :var1 First variable defining operation.
339
- # @option options [Variable] :var1 Second variable defining operation.
340
- # @option options [Variable] :block (yield( var1, var2 )) The operation to
341
- # apply.
337
+ # @overload inject(initial = nil, options = {}, &action)
338
+ # @param [Object] initial Initial value for cummulative operation.
339
+ # @option options [Variable] :var1 First variable defining operation.
340
+ # @option options [Variable] :var1 Second variable defining operation.
341
+ # @option options [Variable] :block (action.call(var1, var2)) The operation to apply.
342
+ #
343
+ # @overload inject(initial = nil, symbol)
344
+ # @param [Object] initial Initial value for cummulative operation.
345
+ # @param [Symbol,String] symbol The operation to apply.
342
346
  #
343
347
  # @return [Object] Result of injection.
344
- def inject( initial = nil, options = {} )
348
+ def inject(*args, &action)
349
+ options = args.last.is_a?(Hash) ? args.pop : {}
350
+ unless action or options[:block]
351
+ unless [1, 2].member? args.size
352
+ raise "Inject expected 1 or 2 arguments but got #{args.size}"
353
+ end
354
+ initial, symbol = args[-2], args[-1]
355
+ action = proc { |a,b| a.send symbol, b }
356
+ else
357
+ raise "Inject expected 0 or 1 arguments but got #{args.size}" if args.size > 1
358
+ initial = args.empty? ? nil : args.first
359
+ end
345
360
  unless initial.nil?
346
361
  initial = Node.match( initial ).new initial unless initial.matched?
347
362
  initial_typecode = initial.typecode
@@ -350,7 +365,7 @@ module Hornetseye
350
365
  end
351
366
  var1 = options[ :var1 ] || Variable.new( initial_typecode )
352
367
  var2 = options[ :var2 ] || Variable.new( typecode )
353
- block = options[ :block ] || yield( var1, var2 )
368
+ block = options[ :block ] || action.call( var1, var2 )
354
369
  if dimension == 0
355
370
  if initial
356
371
  block.subst( var1 => initial, var2 => self ).simplify
@@ -384,7 +399,7 @@ module Hornetseye
384
399
  if other.matched?
385
400
  if variables.empty?
386
401
  if other.typecode == typecode and other.shape == shape
387
- Hornetseye::finalise { eq(other).inject( true ) { |a,b| a.and b } }
402
+ Hornetseye::finalise { eq(other).inject true, :and }
388
403
  else
389
404
  false
390
405
  end
@@ -404,7 +419,7 @@ module Hornetseye
404
419
  #
405
420
  # @return [Object] Minimum value of array.
406
421
  def min( initial = nil )
407
- inject( initial ) { |a,b| a.minor b }
422
+ inject initial, :minor
408
423
  end
409
424
 
410
425
  # Find maximum value of array
@@ -413,14 +428,14 @@ module Hornetseye
413
428
  #
414
429
  # @return [Object] Maximum value of array.
415
430
  def max( initial = nil )
416
- inject( initial ) { |a,b| a.major b }
431
+ inject initial, :major
417
432
  end
418
433
 
419
434
  # Compute sum of array
420
435
  #
421
436
  # @return [Object] Sum of array.
422
437
  def sum
423
- Hornetseye::lazy { to_type typecode.maxint }.inject { |a,b| a + b }
438
+ Hornetseye::lazy { to_type typecode.maxint }.inject :+
424
439
  end
425
440
 
426
441
  # Find range of values of array
@@ -696,7 +711,7 @@ module Hornetseye
696
711
  Hornetseye::lazy do
697
712
  ( 0 ... field.size ).
698
713
  collect { |i| ( field[i] >= 0 ).and( field[i] < shape[i] ) }.
699
- inject { |a,b| a.and b }
714
+ inject :and
700
715
  end.conditional Lut.new( *( field + [ self ] ) ), options[ :default ]
701
716
  else
702
717
  field.lut self, :safe => false
@@ -475,7 +475,7 @@ module Hornetseye
475
475
  if values.all? { |value| value.is_a? RGB or value.is_a? Float or
476
476
  value.is_a? Integer }
477
477
  if values.any? { |value| value.is_a? RGB }
478
- elements = values.inject( [] ) do |arr,value|
478
+ elements = values.inject([]) do |arr,value|
479
479
  if value.is_a? RGB
480
480
  arr + [ value.r, value.g, value.b ]
481
481
  else
@@ -141,9 +141,9 @@ module Hornetseye
141
141
  def strip
142
142
  stripped = [ @dest, @source, @m, @index, @default ].
143
143
  collect { |value| value.strip }
144
- return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
145
- stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
146
- self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
144
+ return stripped.inject([]) { |vars,elem| vars + elem[0] },
145
+ stripped.inject([]) { |values,elem| values + elem[1] },
146
+ self.class.new(*stripped.collect { |elem| elem[2] })
147
147
  end
148
148
 
149
149
  # Check whether this term is compilable
@@ -336,7 +336,9 @@ class TC_MultiArray < Test::Unit::TestCase
336
336
 
337
337
  def test_inject
338
338
  assert_equal 21, M[[1, 2, 3], [4, 5, 6]].inject { |a,b| a + b }
339
+ assert_equal 21, M[[1, 2, 3], [4, 5, 6]].inject(:+)
339
340
  assert_equal 28, M[[1, 2, 3], [4, 5, 6]].inject(7) { |a,b| a + b }
341
+ assert_equal 28, M[[1, 2, 3], [4, 5, 6]].inject(7, :+)
340
342
  end
341
343
 
342
344
  def test_collect
@@ -265,7 +265,9 @@ class TC_Sequence < Test::Unit::TestCase
265
265
 
266
266
  def test_inject
267
267
  assert_equal 6, S[ 1, 2, 3 ].inject { |a,b| a + b }
268
- assert_equal 10, S[ 1, 2, 3 ].inject( 4 ) { |a,b| a + b }
268
+ assert_equal 6, S[ 1, 2, 3 ].inject(:+)
269
+ assert_equal 10, S[ 1, 2, 3 ].inject(4) { |a,b| a + b }
270
+ assert_equal 10, S[ 1, 2, 3 ].inject(4, :+)
269
271
  assert_equal 'abc', S[ 'a', 'b', 'c' ].inject { |a,b| a + b }
270
272
  assert_equal 'abcd', S[ 'b', 'c', 'd' ].inject( 'a' ) { |a,b| a + b }
271
273
  assert_equal C( 3, 5, 8 ), S[ C( 1, 2, 3 ), C( 2, 3, 5 ) ].inject { |a,b| a + b }
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiarray
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 23
8
- - 1
9
- version: 0.23.1
4
+ prerelease:
5
+ version: 0.23.2
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jan Wedekind
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-06-29 00:00:00 +01:00
18
- default_executable:
13
+ date: 2011-06-29 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: malloc
@@ -25,9 +20,6 @@ dependencies:
25
20
  requirements:
26
21
  - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 1
31
23
  version: "1.1"
32
24
  type: :runtime
33
25
  version_requirements: *id001
@@ -39,8 +31,6 @@ dependencies:
39
31
  requirements:
40
32
  - - ">="
41
33
  - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
34
  version: "0"
45
35
  type: :development
46
36
  version_requirements: *id002
@@ -106,7 +96,6 @@ files:
106
96
  - test/tc_bool.rb
107
97
  - test/tc_rgb.rb
108
98
  - test/tc_sequence.rb
109
- has_rdoc: yard
110
99
  homepage: http://wedesoft.github.com/multiarray/
111
100
  licenses: []
112
101
 
@@ -120,21 +109,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
109
  requirements:
121
110
  - - ">="
122
111
  - !ruby/object:Gem::Version
123
- segments:
124
- - 0
125
112
  version: "0"
126
113
  required_rubygems_version: !ruby/object:Gem::Requirement
127
114
  none: false
128
115
  requirements:
129
116
  - - ">="
130
117
  - !ruby/object:Gem::Version
131
- segments:
132
- - 0
133
118
  version: "0"
134
119
  requirements: []
135
120
 
136
121
  rubyforge_project: hornetseye
137
- rubygems_version: 1.3.7
122
+ rubygems_version: 1.8.5
138
123
  signing_key:
139
124
  specification_version: 3
140
125
  summary: Multi-dimensional and uniform Ruby arrays