Class: Rust::MathArray

Inherits:
Array show all
Defined in:
lib/rust-core.rb

Instance Method Summary collapse

Methods inherited from Array

#distance, #distribution, #to_R

Instance Method Details

#*(other) ⇒ Object

Raises:

  • (ArgumentError)


707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/rust-core.rb', line 707

def *(other)
    raise ArgumentError, "Expected array or numeric" if !other.is_a?(::Array) && !other.is_a?(Numeric)
    raise ArgumentError, "The two arrays must have the same size" if other.is_a?(::Array) && self.size != other.size
    
    result = self.clone
    other = [other] * self.size if other.is_a?(Numeric)
    for i in 0...self.size
        result[i] *= other[i]
    end
    
    return result
end

#**(other) ⇒ Object

Raises:

  • (ArgumentError)


746
747
748
749
750
751
752
753
754
755
# File 'lib/rust-core.rb', line 746

def **(other)
    raise ArgumentError, "Expected numeric" if !other.is_a?(Numeric)
    
    result = self.clone
    for i in 0...self.size
        result[i] = result[i] ** other
    end
    
    return result
end

#+(other) ⇒ Object

Raises:

  • (ArgumentError)


720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/rust-core.rb', line 720

def +(other)
    raise ArgumentError, "Expected array or numeric" if !other.is_a?(::Array) && !other.is_a?(Numeric)
    raise ArgumentError, "The two arrays must have the same size" if other.is_a?(::Array) && self.size != other.size
    
    result = self.clone
    other = [other] * self.size if other.is_a?(Numeric)
    for i in 0...self.size
        result[i] += other[i]
    end
    
    return result
end

#-(other) ⇒ Object

Raises:

  • (ArgumentError)


694
695
696
697
698
699
700
701
702
703
704
705
# File 'lib/rust-core.rb', line 694

def -(other)
    raise ArgumentError, "Expected array or numeric" if !other.is_a?(::Array) && !other.is_a?(Numeric)
    raise ArgumentError, "The two arrays must have the same size" if other.is_a?(::Array) && self.size != other.size
    
    result = self.clone
    other = [other] * self.size if other.is_a?(Numeric)
    for i in 0...self.size
        result[i] -= other[i]
    end
    
    return result
end

#/(other) ⇒ Object

To recover the syntax highlighting but in Kate: /

Raises:

  • (ArgumentError)


733
734
735
736
737
738
739
740
741
742
743
744
# File 'lib/rust-core.rb', line 733

def /(other) #To recover the syntax highlighting but in Kate: /
    raise ArgumentError, "Expected array or numeric" if !other.is_a?(::Array) && !other.is_a?(Numeric)
    raise ArgumentError, "The two arrays must have the same size" if other.is_a?(::Array) && self.size != other.size
    
    result = self.clone
    other = [other] * self.size if other.is_a?(Numeric)
    for i in 0...self.size
        result[i] /= other[i]
    end
    
    return result
end