multiarray 0.21.0 → 0.22.0
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 +1 -1
- data/lib/multiarray.rb +4 -4
- data/lib/multiarray/components.rb +1 -1
- data/lib/multiarray/diagonal.rb +1 -1
- data/lib/multiarray/gccvalue.rb +9 -0
- data/lib/multiarray/operations.rb +34 -31
- data/test/tc_multiarray.rb +2 -2
- data/test/tc_sequence.rb +4 -1
- metadata +3 -3
    
        data/Rakefile
    CHANGED
    
    
    
        data/lib/multiarray.rb
    CHANGED
    
    | @@ -621,8 +621,8 @@ class Array | |
| 621 621 | 
             
                    size2 = 0.5 * ( retVal.size + 2 )
         | 
| 622 622 | 
             
                    nIntegral = erf( +size2, sigma ) - erf( -size2, sigma )
         | 
| 623 623 | 
             
                    value = 0.5 * ( nIntegral - integral )
         | 
| 624 | 
            -
                    retVal.unshift | 
| 625 | 
            -
                    retVal.push | 
| 624 | 
            +
                    retVal.unshift value
         | 
| 625 | 
            +
                    retVal.push value
         | 
| 626 626 | 
             
                    integral = nIntegral
         | 
| 627 627 | 
             
                  end
         | 
| 628 628 | 
             
                  # Normalise result.
         | 
| @@ -653,8 +653,8 @@ class Array | |
| 653 653 | 
             
                    size2 = 0.5 * ( retVal.size + 2 )
         | 
| 654 654 | 
             
                    nIntegral = gauss( size2, sigma )
         | 
| 655 655 | 
             
                    value = integral - nIntegral
         | 
| 656 | 
            -
                    retVal.unshift | 
| 657 | 
            -
                    retVal.push | 
| 656 | 
            +
                    retVal.unshift +value
         | 
| 657 | 
            +
                    retVal.push -value
         | 
| 658 658 | 
             
                    sumX += value * ( retVal.size - 1 )
         | 
| 659 659 | 
             
                    integral = nIntegral
         | 
| 660 660 | 
             
                  end
         | 
| @@ -84,7 +84,7 @@ module Hornetseye | |
| 84 84 | 
             
                  @dest
         | 
| 85 85 | 
             
                end
         | 
| 86 86 |  | 
| 87 | 
            -
                # Recursive function to perform connected component  | 
| 87 | 
            +
                # Recursive function to perform connected component labeling
         | 
| 88 88 | 
             
                #
         | 
| 89 89 | 
             
                # @param [Array<Proc>] args Array with functions for locating neighbouring elements.
         | 
| 90 90 | 
             
                # @param [Array<Proc>] comp Array with functions for locating neighbouring labels.
         | 
    
        data/lib/multiarray/diagonal.rb
    CHANGED
    
    | @@ -105,7 +105,7 @@ module Hornetseye | |
| 105 105 | 
             
                  end
         | 
| 106 106 | 
             
                  j0.upto( ( @index2.size - 1 ).minor( @index0 + s1 ) ) do |j|
         | 
| 107 107 | 
             
                    i = @index0.get + s1.get - j
         | 
| 108 | 
            -
                    sub = @value.subst @index1 => INT.new( i ), @index2 => INT.new( j ) | 
| 108 | 
            +
                    sub = @value.subst @index1 => INT.new( i ), @index2 => INT.new( j )
         | 
| 109 109 | 
             
                    retval.assign @block.subst( @var1 => retval, @var2 => sub )
         | 
| 110 110 | 
             
                  end
         | 
| 111 111 | 
             
                  retval
         | 
    
        data/lib/multiarray/gccvalue.rb
    CHANGED
    
    | @@ -279,6 +279,15 @@ module Hornetseye | |
| 279 279 | 
             
                  0
         | 
| 280 280 | 
             
                end
         | 
| 281 281 |  | 
| 282 | 
            +
                def fmod( other )
         | 
| 283 | 
            +
                  if GCCValue.generic? other
         | 
| 284 | 
            +
                    GCCValue.new @function, "fmod( #{self}, #{other} )"
         | 
| 285 | 
            +
                  else
         | 
| 286 | 
            +
                    x, y = other.coerce self
         | 
| 287 | 
            +
                    x.send op, y
         | 
| 288 | 
            +
                  end
         | 
| 289 | 
            +
                end
         | 
| 290 | 
            +
             | 
| 282 291 | 
             
                # Create code for conditional selection of value
         | 
| 283 292 | 
             
                #
         | 
| 284 293 | 
             
                # @param [GCCValue,Object] a First value.
         | 
| @@ -87,6 +87,7 @@ module Hornetseye | |
| 87 87 | 
             
                define_binary_op :**, :coercion_maxint
         | 
| 88 88 | 
             
                define_binary_op :/
         | 
| 89 89 | 
             
                define_binary_op :%
         | 
| 90 | 
            +
                define_binary_op :fmod
         | 
| 90 91 | 
             
                define_binary_op :and, :coercion_bool
         | 
| 91 92 | 
             
                define_binary_op :or, :coercion_bool
         | 
| 92 93 | 
             
                define_binary_op :&
         | 
| @@ -113,6 +114,25 @@ module Hornetseye | |
| 113 114 | 
             
                  self
         | 
| 114 115 | 
             
                end
         | 
| 115 116 |  | 
| 117 | 
            +
                # Modulo operation for floating point numbers
         | 
| 118 | 
            +
                #
         | 
| 119 | 
            +
                # This operation takes account of the problem that '%' does not work with
         | 
| 120 | 
            +
                # floating-point numbers in C.
         | 
| 121 | 
            +
                #
         | 
| 122 | 
            +
                # @return [Node] Array with result of operation.
         | 
| 123 | 
            +
                def fmod_with_float( other )
         | 
| 124 | 
            +
                  unless other.is_a? Node
         | 
| 125 | 
            +
                    other = Node.match( other, typecode ).new other
         | 
| 126 | 
            +
                  end
         | 
| 127 | 
            +
                  if typecode < FLOAT_ or other.typecode < FLOAT_
         | 
| 128 | 
            +
                    fmod other
         | 
| 129 | 
            +
                  else
         | 
| 130 | 
            +
                    fmod_without_float other
         | 
| 131 | 
            +
                  end
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                alias_method_chain :%, :float, :fmod
         | 
| 135 | 
            +
             | 
| 116 136 | 
             
                # Convert array elements to different element type
         | 
| 117 137 | 
             
                #
         | 
| 118 138 | 
             
                # @param [Class] dest Element type to convert to.
         | 
| @@ -517,18 +537,19 @@ module Hornetseye | |
| 517 537 | 
             
                  end
         | 
| 518 538 | 
             
                end
         | 
| 519 539 |  | 
| 520 | 
            -
                # Compute  | 
| 540 | 
            +
                # Compute table from two arrays
         | 
| 521 541 | 
             
                #
         | 
| 522 | 
            -
                # Used internally to implement convolutions.
         | 
| 542 | 
            +
                # Used internally to implement convolutions and other operations.
         | 
| 523 543 | 
             
                #
         | 
| 524 | 
            -
                # @param [Node] filter Filter to form  | 
| 544 | 
            +
                # @param [Node] filter Filter to form table with.
         | 
| 545 | 
            +
                # @param [Proc] action Operation to make table for.
         | 
| 525 546 | 
             
                #
         | 
| 526 547 | 
             
                # @return [Node] Result of operation.
         | 
| 527 548 | 
             
                #
         | 
| 528 549 | 
             
                # @see #convolve
         | 
| 529 550 | 
             
                #
         | 
| 530 551 | 
             
                # @private
         | 
| 531 | 
            -
                def  | 
| 552 | 
            +
                def table( filter, &action )
         | 
| 532 553 | 
             
                  filter = Node.match( filter, typecode ).new filter unless filter.is_a? Node
         | 
| 533 554 | 
             
                  if filter.dimension > dimension
         | 
| 534 555 | 
             
                    raise "Filter has #{filter.dimension} dimension(s) but should " +
         | 
| @@ -536,9 +557,9 @@ module Hornetseye | |
| 536 557 | 
             
                  end
         | 
| 537 558 | 
             
                  filter = Hornetseye::lazy( 1 ) { filter } while filter.dimension < dimension
         | 
| 538 559 | 
             
                  if filter.dimension == 0
         | 
| 539 | 
            -
                    self  | 
| 560 | 
            +
                    action.call self, filter
         | 
| 540 561 | 
             
                  else
         | 
| 541 | 
            -
                    Hornetseye::lazy { |i,j| self[j]. | 
| 562 | 
            +
                    Hornetseye::lazy { |i,j| self[j].table filter[i], &action }
         | 
| 542 563 | 
             
                  end
         | 
| 543 564 | 
             
                end
         | 
| 544 565 |  | 
| @@ -551,27 +572,7 @@ module Hornetseye | |
| 551 572 | 
             
                  filter = Node.match( filter, typecode ).new filter unless filter.is_a? Node
         | 
| 552 573 | 
             
                  array = self
         | 
| 553 574 | 
             
                  ( dimension - filter.dimension ).times { array = array.roll }
         | 
| 554 | 
            -
                  array. | 
| 555 | 
            -
                end
         | 
| 556 | 
            -
             | 
| 557 | 
            -
                # Create spread array similar to product array
         | 
| 558 | 
            -
                #
         | 
| 559 | 
            -
                # Used internally to implement erosion and dilation.
         | 
| 560 | 
            -
                #
         | 
| 561 | 
            -
                # @param [Integer] n Size of spread.
         | 
| 562 | 
            -
                #
         | 
| 563 | 
            -
                # @return [Node] Result of operation.
         | 
| 564 | 
            -
                #
         | 
| 565 | 
            -
                # @see #erode
         | 
| 566 | 
            -
                # @see #dilate
         | 
| 567 | 
            -
                #
         | 
| 568 | 
            -
                # @private
         | 
| 569 | 
            -
                def spread( n = 3 )
         | 
| 570 | 
            -
                  if dimension > 0
         | 
| 571 | 
            -
                    Hornetseye::lazy( n, shape.last ) { |i,j| self[j].spread n }
         | 
| 572 | 
            -
                  else
         | 
| 573 | 
            -
                    self
         | 
| 574 | 
            -
                  end
         | 
| 575 | 
            +
                  array.table( filter ) { |a,b| a* b }.diagonal { |s,x| s + x }
         | 
| 575 576 | 
             
                end
         | 
| 576 577 |  | 
| 577 578 | 
             
                # Erosion
         | 
| @@ -582,7 +583,8 @@ module Hornetseye | |
| 582 583 | 
             
                #
         | 
| 583 584 | 
             
                # @return [Node] Result of operation.
         | 
| 584 585 | 
             
                def erode( n = 3 )
         | 
| 585 | 
            -
                   | 
| 586 | 
            +
                  filter = Hornetseye::lazy( *( [ n ] * dimension ) ) { 0 }
         | 
| 587 | 
            +
                  table( filter ) { |a,b| a }.diagonal { |m,x| m.minor x }
         | 
| 586 588 | 
             
                end
         | 
| 587 589 |  | 
| 588 590 | 
             
                # Dilation
         | 
| @@ -593,7 +595,8 @@ module Hornetseye | |
| 593 595 | 
             
                #
         | 
| 594 596 | 
             
                # @return [Node] Result of operation.
         | 
| 595 597 | 
             
                def dilate( n = 3 )
         | 
| 596 | 
            -
                   | 
| 598 | 
            +
                  filter = Hornetseye::lazy( *( [ n ] * dimension ) ) { 0 }
         | 
| 599 | 
            +
                  table( filter ) { |a,b| a }.diagonal { |m,x| m.major x }
         | 
| 597 600 | 
             
                end
         | 
| 598 601 |  | 
| 599 602 | 
             
                # Sobel operator
         | 
| @@ -603,7 +606,7 @@ module Hornetseye | |
| 603 606 | 
             
                # @return [Node] Result of Sobel operator.
         | 
| 604 607 | 
             
                def sobel( direction )
         | 
| 605 608 | 
             
                  ( dimension - 1 ).downto( 0 ).inject self do |retval,i|
         | 
| 606 | 
            -
                    filter = i == direction ? Hornetseye::Sequence( SINT, 3 )[  | 
| 609 | 
            +
                    filter = i == direction ? Hornetseye::Sequence( SINT, 3 )[ 1, 0, -1 ] :
         | 
| 607 610 | 
             
                                              Hornetseye::Sequence( SINT, 3 )[ 1, 2, 1 ]
         | 
| 608 611 | 
             
                    Hornetseye::lazy { retval.convolve filter }
         | 
| 609 612 | 
             
                  end.force
         | 
| @@ -725,7 +728,7 @@ module Hornetseye | |
| 725 728 | 
             
                  left
         | 
| 726 729 | 
             
                end
         | 
| 727 730 |  | 
| 728 | 
            -
                # Perform connected component  | 
| 731 | 
            +
                # Perform connected component labeling
         | 
| 729 732 | 
             
                #
         | 
| 730 733 | 
             
                # @option options [Object] :default (typecode.default) Value of background elements.
         | 
| 731 734 | 
             
                # @option options [Class] :target (UINT) Typecode of labels.
         | 
    
        data/test/tc_multiarray.rb
    CHANGED
    
    | @@ -450,9 +450,9 @@ class TC_MultiArray < Test::Unit::TestCase | |
| 450 450 |  | 
| 451 451 | 
             
              def test_sobel
         | 
| 452 452 | 
             
                m = M[ [ 0, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 0, 0 ] ]
         | 
| 453 | 
            -
                assert_equal [ [  | 
| 453 | 
            +
                assert_equal [ [ 1, 0, -1, 0 ], [ 2, 0, -2, 0 ], [ 1, 0, -1, 0 ] ],
         | 
| 454 454 | 
             
                             m.sobel( 0 ).to_a
         | 
| 455 | 
            -
                assert_equal [ [  | 
| 455 | 
            +
                assert_equal [ [ 1, 2, 1, 0 ], [ 0, 0, 0, 0 ], [ -1, -2, -1, 0 ] ],
         | 
| 456 456 | 
             
                             m.sobel( 1 ).to_a
         | 
| 457 457 | 
             
              end
         | 
| 458 458 |  | 
    
        data/test/tc_sequence.rb
    CHANGED
    
    | @@ -393,7 +393,7 @@ class TC_Sequence < Test::Unit::TestCase | |
| 393 393 | 
             
              end
         | 
| 394 394 |  | 
| 395 395 | 
             
              def test_sobel
         | 
| 396 | 
            -
                assert_equal [ 0,  | 
| 396 | 
            +
                assert_equal [ 0, 1, 0, -1, 0 ], S[ 0, 0, 1, 0, 0 ].sobel( 0 ).to_a
         | 
| 397 397 | 
             
              end
         | 
| 398 398 |  | 
| 399 399 | 
             
              def test_histogram
         | 
| @@ -621,6 +621,9 @@ class TC_Sequence < Test::Unit::TestCase | |
| 621 621 |  | 
| 622 622 | 
             
              def test_mod
         | 
| 623 623 | 
             
                assert_equal S[ 2, 0, 1 ], S[ 2, 3, 4 ] % 3
         | 
| 624 | 
            +
                assert_equal S[ 1, 0, 3 ], 3 % S[ 2, 3, 4 ]
         | 
| 625 | 
            +
                assert_equal S[ 2, 0.5, 1.5 ], S[ 2, 3, 4 ] % 2.5
         | 
| 626 | 
            +
                assert_equal S[ 0.5, 2.5, 2.5 ], 2.5 % S[ 2, 3, 4 ]
         | 
| 624 627 | 
             
              end
         | 
| 625 628 |  | 
| 626 629 | 
             
              def test_pow
         | 
    
        metadata
    CHANGED
    
    | @@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version | |
| 4 4 | 
             
              prerelease: false
         | 
| 5 5 | 
             
              segments: 
         | 
| 6 6 | 
             
              - 0
         | 
| 7 | 
            -
              -  | 
| 7 | 
            +
              - 22
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              version: 0. | 
| 9 | 
            +
              version: 0.22.0
         | 
| 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: 2011- | 
| 17 | 
            +
            date: 2011-04-12 00:00:00 +01:00
         | 
| 18 18 | 
             
            default_executable: 
         | 
| 19 19 | 
             
            dependencies: 
         | 
| 20 20 | 
             
            - !ruby/object:Gem::Dependency 
         |