Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/mext/array/fill.rb,
lib/mext/array/dotop.rb,
lib/mext/array/choose.rb,
lib/mext/array/scalarop.rb,
lib/mext/array/vectorize.rb

Direct Known Subclasses

Mext::EndlessArray

Defined Under Namespace

Classes: SizeMismatch

Constant Summary collapse

MINIMUM_STEP =

fill_float(end_value, start_value = 0.0, step = 1.0)

fill a blank newly created array with Float numbers which will range from start_value to end_value in steps of step

1e-32
DOT_OPERATIONS =
{
  :dotplus => :+,
  :dotminus => :-,
  :dotmul  => :*,
  :dotdiv  => :/,
  :dotmod  => :%,
  :dotpow  => :**,
  :dotaddsemi => :addsemi,
}
SCALAR_OPERATIONS =

modifying the behaviour of scalar multiplication for Arrays has the unintended side-effect of killing any File.join() path which contains a [‘..’] * n idiomatic figure.

Better not tamper with it and use another name

[ :+, :-, ]
SCALAR_NEW_OPERATIONS =
[ :smul, :/, :%, :**, ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fill_float(end_value, start_value = 0.0, step = 1.0) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/mext/array/fill.rb', line 13

def fill_float(end_value, start_value = 0.0, step = 1.0)
  raise ArgumentError.new("step too small") unless step.abs > MINIMUM_STEP
  res = new
  ev = end_value - step
  start_value.step(ev, step).each { |f| res << f }
  res
end

Instance Method Details

#chooseObject

choose: choose a random element in the array

returns a random element from the array

:nodoc:



10
11
12
13
# File 'lib/mext/array/choose.rb', line 10

def choose
  idx = (rand()*(self.size-1)).round
  self[idx]
end