5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/chainer/testing/array.rb', line 5
def assert_allclose(expect, actual, atol: 1e-5, rtol: 1e-4)
expect = Utils::Array.force_array(expect)
actual = Utils::Array.force_array(actual)
if (expect.shape != actual.shape) and (expect.ndim == 0)
expect = actual.class.new(actual.shape).fill(expect.to_f)
end
actual.each_with_index{|actual_val, *i|
if (expect[*i].to_f - actual_val.to_f).abs > atol + rtol * expect[*i].abs
raise "assert_allclose Error\n expect: #{expect.inspect}\n actual : #{actual.inspect}\n (#{i})=> #{(expect - actual).abs.max()} > #{atol + rtol * expect[*i].abs}"
end
}
end
|