multiarray 0.15.1 → 0.15.2

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.15.1'
9
+ PKG_VERSION = '0.15.2'
10
10
  RB_FILES = FileList[ 'lib/**/*.rb' ]
11
11
  TC_FILES = FileList[ 'test/tc_*.rb' ]
12
12
  TS_FILES = FileList[ 'test/ts_*.rb' ]
data/lib/multiarray.rb CHANGED
@@ -173,7 +173,7 @@ class Object
173
173
  # @see FalseClass#conditional
174
174
  # @see NilClass#conditional
175
175
  def conditional( a, b )
176
- a
176
+ a.is_a?( Proc ) ? a.call : a
177
177
  end
178
178
 
179
179
  end
@@ -232,7 +232,7 @@ class NilClass
232
232
  # @see Object#conditional
233
233
  # @see FalseClass#conditional
234
234
  def conditional( a, b )
235
- b
235
+ b.is_a?( Proc ) ? b.call : b
236
236
  end
237
237
 
238
238
  # Check whether this term is compilable
@@ -302,7 +302,7 @@ class FalseClass
302
302
  # @see Object#conditional
303
303
  # @see NilClass#conditional
304
304
  def conditional( a, b )
305
- b
305
+ b.is_a?( Proc ) ? b.call : b
306
306
  end
307
307
 
308
308
  end
@@ -288,7 +288,11 @@ module Hornetseye
288
288
  #
289
289
  # @private
290
290
  def conditional( a, b )
291
- GCCValue.new @function, "( #{self} ) ? ( #{a} ) : ( #{b} )"
291
+ if a.is_a?( Proc ) and b.is_a?( Proc )
292
+ conditional a.call, b.call
293
+ else
294
+ GCCValue.new @function, "( #{self} ) ? ( #{a} ) : ( #{b} )"
295
+ end
292
296
  end
293
297
 
294
298
  # Create code for conditional selection of RGB value
@@ -203,7 +203,9 @@ module Hornetseye
203
203
  a.dimension == 0 and a.variables.empty? and
204
204
  b.dimension == 0 and b.variables.empty?
205
205
  target = array_type.cond a.array_type, b.array_type
206
- target.new simplify.get.conditional( a.simplify.get, b.simplify.get )
206
+ #target.new simplify.get.conditional( a.simplify.get, b.simplify.get )
207
+ target.new simplify.get.conditional( proc { a.simplify.get },
208
+ proc { b.simplify.get } )
207
209
  else
208
210
  Hornetseye::ElementWise( lambda { |x,y,z| x.conditional y, z }, :conditional,
209
211
  lambda { |t,u,v| t.cond u, v } ).
@@ -580,7 +582,7 @@ module Hornetseye
580
582
  Hornetseye::lazy( *shape ) { |*args| args[i] }
581
583
  end
582
584
  end
583
- warp *field
585
+ warp *field, :safe => false
584
586
  end
585
587
 
586
588
  def shift( *offset )
@@ -636,9 +638,18 @@ module Hornetseye
636
638
  field = ( 0 ... dimension ).collect do |i|
637
639
  Hornetseye::lazy( *ret_shape ) { |*args| args[i] * rate[i] + offset[i] }
638
640
  end
639
- warp *field
641
+ warp *field, :safe => false
640
642
  end
641
643
 
644
+ #def scale( *ret_shape )
645
+ # field = ( 0 ... dimension ).collect do |i|
646
+ # Hornetseye::lazy( *ret_shape ) do |*args|
647
+ # ( args[i] * shape[i].to_f / ret_shape[i] ).to_type INT
648
+ # end
649
+ # end
650
+ # Hornetseye::lazy { to_type typecode.float }.integral
651
+ #end
652
+
642
653
  end
643
654
 
644
655
  class Node
@@ -479,6 +479,18 @@ class TC_MultiArray < Test::Unit::TestCase
479
479
  assert_raise( RuntimeError ) { [ S[ 0, 1 ], S[ 0, 1 ] ].lut S[ 1, 2 ] }
480
480
  end
481
481
 
482
+ def test_warp
483
+ [ O, I ].each do |t1|
484
+ [ O, I ].each do |t2|
485
+ z = t1.default
486
+ assert_equal M( t1, 3, 3 )[ [ 1, 2, z ], [ 3, 4, z ], [ z, z, z ] ],
487
+ M( t1, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].
488
+ warp( M( t2, 3, 3 )[ [ 0, 1, 2 ], [ 0, 1, 2 ], [ 0, 1, 2 ] ],
489
+ M( t2, 3, 3 )[ [ 0, 0, 0 ], [ 1, 1, 1 ], [ 2, 2, 2 ] ] )
490
+ end
491
+ end
492
+ end
493
+
482
494
  def test_flip
483
495
  [ O, I ].each do |t|
484
496
  assert_equal M( t, 3, 2 )[ [ 3, 2, 1 ], [ 6, 5, 4 ] ],
data/test/tc_sequence.rb CHANGED
@@ -371,14 +371,14 @@ class TC_Sequence < Test::Unit::TestCase
371
371
  assert_raise( RuntimeError ) { S[ 1, 2 ].lut S[ 0, 1 ] }
372
372
  end
373
373
 
374
- #def test_warp
375
- # [ O, I ].each do |t1|
376
- # [ O, I ].each do |t2|
377
- # assert_equal S( t1, 3 )[ 1, 2, t1.default ],
378
- # S( t1, 2 )[ 1, 2 ].warp( S( t2, 3 )[ 0, 1, 2 ] )
379
- # end
380
- # end
381
- #end
374
+ def test_warp
375
+ [ O, I ].each do |t1|
376
+ [ O, I ].each do |t2|
377
+ assert_equal S( t1, 3 )[ 1, 2, t1.default ],
378
+ S( t1, 2 )[ 1, 2 ].warp( S( t2, 3 )[ 0, 1, 2 ] )
379
+ end
380
+ end
381
+ end
382
382
 
383
383
  def test_flip
384
384
  [ O, I ].each do |t|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 15
8
- - 1
9
- version: 0.15.1
8
+ - 2
9
+ version: 0.15.2
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-20 00:00:00 +00:00
17
+ date: 2010-12-21 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency