deepEqual for floats - something like deepTol()?

14 views
Skip to first unread message

James Gibson

unread,
Sep 5, 2014, 1:11:39 PM9/5/14
to jstat-...@googlegroups.com
Hello all,

I'm working towards implementing regression, which first requires having some working linear algebra functions, so I'm writing tests for the linearalgebra.js section (and have discovered a couple very minor bugs along the way). 

However, I need a way to test deep-approximate equality. E.G, the matrix [[1, 2], [3, 4]] has inverse [[-2, 1], [1.5, -0.5]], but because FP math is hard the function returns [[-1.9999999, 1], [1.499999, -0.49999999]], so assert.deepEqual() fails.

I can write a deepTol() function fairly easily, but I want to check - does this already exist somewhere in vows or the like? (I am not an expert on vows). And assuming I should just write a deepTol(), where should it go? 

Cheers,
James

Trevor Norris

unread,
Sep 19, 2014, 5:58:30 PM9/19/14
to jstat-...@googlegroups.com


On Friday, September 5, 2014 10:11:39 AM UTC-7, James Gibson wrote:
I can write a deepTol() function fairly easily, but I want to check - does this already exist somewhere in vows or the like? (I am not an expert on vows). And assuming I should just write a deepTol(), where should it go? 

There does exist an undocumented assert.epsilon(tol, val) that exists in vows (I PR'd it because .equal() didn't work. Though I don't remember why I named it "epsilon"). If you want to create a deepEpsilon() for use in jStat that sounds great. Just add it to test/env.js. Do it like the following so it's available at the global level:

deepEpsilon = function deepEpsilon(tol, arr) {

(Note the main thing is there's no "var")
Reply all
Reply to author
Forward
0 new messages