multiarray 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
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.14.0'
9
+ PKG_VERSION = '0.14.1'
10
10
  RB_FILES = FileList[ 'lib/**/*.rb' ]
11
11
  TC_FILES = FileList[ 'test/tc_*.rb' ]
12
12
  TS_FILES = FileList[ 'test/ts_*.rb' ]
@@ -183,7 +183,7 @@ module Hornetseye
183
183
  #
184
184
  # @return [Node] Array with results.
185
185
  def <=>( other )
186
- Hornetseye::lazy do
186
+ Hornetseye::finalise do
187
187
  ( self < other ).conditional -1, ( self > other ).conditional( 1, 0 )
188
188
  end
189
189
  end
@@ -431,14 +431,19 @@ module Hornetseye
431
431
  # @private
432
432
  def product( filter )
433
433
  filter = Node.match( filter, typecode ).new filter unless filter.is_a? Node
434
- if dimension != filter.dimension
434
+ if filter.dimension > dimension
435
435
  raise "Filter has #{filter.dimension} dimension(s) but should " +
436
- "have #{dimension}"
436
+ "not have more than #{dimension}"
437
437
  end
438
- if dimension == 0
439
- self * filter
438
+ array = self
439
+ while filter.dimension < dimension
440
+ filter = Hornetseye::lazy( 1 ) { filter }
441
+ array = array.unroll
442
+ end
443
+ if filter.dimension == 0
444
+ array * filter
440
445
  else
441
- Hornetseye::lazy { |i,j| self[j].product filter[i] }
446
+ Hornetseye::lazy { |i,j| array[j].product filter[i] }
442
447
  end
443
448
  end
444
449
 
@@ -487,6 +492,38 @@ module Hornetseye
487
492
  end
488
493
  end
489
494
 
495
+ # Warp an array
496
+ #
497
+ # @overload warp( *field, options = {} )
498
+ # @param [Array<Integer>] ret_shape Dimensions of resulting histogram.
499
+ # @option options [Object] :default (typecode.default) Default value for out of
500
+ # range warp vectors.
501
+ # @option options [Boolean] :safe (true) Apply clip to warp vectors.
502
+ #
503
+ # @return [Node] The result of the lookup operation.
504
+ def warp( *field )
505
+
506
+ #elsif shape.first > lut.dimension or dimension == 1
507
+ # reshape( *( [ 1 ] + shape ) ).map lut, options
508
+
509
+
510
+ options = field.last.is_a?( Hash ) ? field.pop : {}
511
+ options = { :safe => true, :default => typecode.default }.merge options
512
+ if options[ :safe ]
513
+ if field.size > dimension
514
+ raise "Number of arrays for warp (#{field.size}) is greater than the " +
515
+ "number of dimensions of source (#{dimension})"
516
+ end
517
+ Hornetseye::lazy do
518
+ ( 0 ... field.size ).
519
+ collect { |i| ( field[i] >= 0 ).and( field[i] < shape[i] ) }.
520
+ inject { |a,b| a.and b }
521
+ end.conditional Lut.new( *( field + [ self ] ) ), options[ :default ]
522
+ else
523
+ field.lut self
524
+ end
525
+ end
526
+
490
527
  # Compute integral image
491
528
  #
492
529
  # @return [Node] The integral image of this array.
@@ -572,7 +609,7 @@ class Array
572
609
  if options[ :safe ]
573
610
  if size > table.dimension
574
611
  raise "Number of arrays for lookup (#{size}) is greater than the " +
575
- " number of dimensions of LUT (#{table.dimension})"
612
+ "number of dimensions of LUT (#{table.dimension})"
576
613
  end
577
614
  array_types = collect { |source| source.array_type }
578
615
  source_type = array_types.inject { |a,b| a.coercion b }
@@ -593,7 +630,7 @@ class Array
593
630
  if all? { |source| source.dimension == 0 and source.variables.empty? }
594
631
  result = table
595
632
  ( table.dimension - 1 ).downto( 0 ) do |i|
596
- result = result.element self[ i ].demand
633
+ result = result.element( self[ i ].demand ).demand
597
634
  end
598
635
  result
599
636
  else
data/test/tc_lazy.rb CHANGED
@@ -41,6 +41,10 @@ class TC_Lazy < Test::Unit::TestCase
41
41
  Hornetseye::lazy *args, &action
42
42
  end
43
43
 
44
+ def finalise( *args, &action )
45
+ Hornetseye::finalise *args, &action
46
+ end
47
+
44
48
  def sum( *args, &action )
45
49
  Hornetseye::sum *args, &action
46
50
  end
@@ -114,5 +118,10 @@ class TC_Lazy < Test::Unit::TestCase
114
118
  M( I, 4, 3 ).indgen.diagonal { |a,b| a + b }.to_a
115
119
  end
116
120
 
121
+ def test_lut
122
+ assert_equal S( I, 4 )[ 4, 2, 3, 2 ],
123
+ finalise { S( I, 4 )[ 0, 2, 1, 2 ].lut( S( I, 3 )[ 3, 2, 1 ] ) + 1 }
124
+ end
125
+
117
126
  end
118
127
 
@@ -417,14 +417,17 @@ class TC_MultiArray < Test::Unit::TestCase
417
417
 
418
418
  def test_convolve
419
419
  f = M[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
420
+ s = S[ 1, 2, 3 ]
420
421
  assert_equal M[ [ 5, 6, 0 ], [ 8, 9, 0 ], [ 0, 0, 0 ] ],
421
422
  M[ [ 1, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ].convolve( f )
422
423
  assert_equal M[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ],
423
424
  M[ [ 0, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 0 ] ].convolve( f )
424
425
  assert_equal M[ [ 0, 0, 0 ], [ 1, 2, 3 ], [ 4, 5, 6 ] ],
425
426
  M[ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 1, 0 ] ].convolve( f )
427
+ assert_equal M[ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 1, 2, 3 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ],
428
+ M[ [ 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0 ] ].
429
+ convolve( s )
426
430
  assert_raise( RuntimeError ) { S[ 1, 2, 3 ].convolve f }
427
- assert_raise( RuntimeError ) { M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].convolve S[ 1, 2 ] }
428
431
  end
429
432
 
430
433
  def test_histogram
data/test/tc_sequence.rb CHANGED
@@ -333,7 +333,6 @@ class TC_Sequence < Test::Unit::TestCase
333
333
  S( t, 5 )[ 0, 0, 0, 0, 1 ].convolve( S( t, 3 )[ 1, 2, 3 ] )
334
334
  assert_equal S( t, 4 )[ 1, 2, 3, 0 ],
335
335
  S( t, 4 )[ 0, 1, 0, 0 ].convolve( S( t, 3 )[ 1, 2, 3 ] )
336
- assert_raise( RuntimeError ) { S[ 1, 2, 3 ].convolve 1 }
337
336
  end
338
337
  assert_equal S[ C( 1, 0, 0 ), C( 2, 1, 0 ), C( 3, 2, 1 ), C( 0, 3, 2 ),
339
338
  C( 0, 0, 3 ) ],
@@ -367,6 +366,15 @@ class TC_Sequence < Test::Unit::TestCase
367
366
  assert_raise( RuntimeError ) { S[ 1, 2 ].lut S[ 0, 1 ] }
368
367
  end
369
368
 
369
+ #def test_warp
370
+ # [ O, I ].each do |t1|
371
+ # [ O, I ].each do |t2|
372
+ # assert_equal S( t1, 3 )[ 1, 2, t1.default ],
373
+ # S( t1, 2 )[ 1, 2 ].warp( S( t2, 3 )[ 0, 1, 2 ] )
374
+ # end
375
+ # end
376
+ #end
377
+
370
378
  def test_zero
371
379
  [ S( O, 3 ), S( I, 3 ) ].each do |t|
372
380
  assert_equal [ false, true, false ], t[ -1, 0, 1 ].zero?.to_a
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 14
8
- - 0
9
- version: 0.14.0
8
+ - 1
9
+ version: 0.14.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Wedekind
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-14 00:00:00 +00:00
17
+ date: 2010-12-15 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency