C0 code coverage information
Generated on Tue Nov 04 04:48:28 -0200 2008 with
rcov 0.8.1.2
Code reported as executed by Ruby looks like
this... and this: this line is also marked as
covered. Lines considered as run by rcov, but
not reported by Ruby, look like this, and
this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not
executed.
1
module GridSearch 2
3 # Finds the argument
which maximizes the function given in the block trhu grid-search
maximization. 4 #
[-1,0,1,2].argmax {|x| x**2 } #=> 2 5 # 6
def argmax(&block) 7
argbest(:>, &block) 8 end
9 10 # Finds the
argument which minimizes the function given in the block trhu grid-search
minimization. 11 #
[-1,0,1,2].argmin {|x| x**2 } #=> 0 12 # 13
def argmin(&block) 14
argbest(:<, &block) 15 end 16 17
private 18 19 def argbest(cmp) 20 best_arg, best_val = nil, nil
21 self.each do
|*curr_arg| 22 curr_val =
yield(*curr_arg) 23 if
best_val.nil? || curr_val.send(cmp, best_val) 24 best_val = curr_val 25 best_arg = curr_arg 26 end 27 end 28 best_arg 29 end 30 31 end 32 33
module Enumerable 34
include GridSearch 35
end 36 37 class Array 38 include GridSearch 39 end
Generated using the rcov
code coverage analysis tool for Ruby version 0.8.1.2.