import numpy as N import numpy.matlib as M def load(): # x data x = M.zeros((3,3)) x[0,0] = 0.00301404794991108 x[0,1] = 0.00264742266711118 x[0,2] = -0.00112705028731085 x[1,0] = 0.0228605377994491 x[1,1] = 0.00337153112741583 x[1,2] = -0.00823674912992519 x[2,0] = 0.00447839875836716 x[2,1] = 0.00274880280576514 x[2,2] = -0.00161133933606597 # y data y = M.zeros((3,1)) y[0,0] = 0.000885398 y[1,0] = 0.00667193 y[2,0] = 0.000324727 return x, y def calc(x, y): return x * (x.T * y) def test1(nsim=100): x, y = load() z0 = calc(x, y) ndiff = 0 for i in xrange(nsim): z = calc(x, y) if (z != z0).any(): ndiff += 1 print i, 'z different', abs(z - z0).max() return ndiff def test2(nsim=100): x0, y0 = load() z0 = calc(x0, y0) ndiff = 0 for i in xrange(nsim): x, y = load() z = calc(x, y) if (x != x0).any(): print i, 'x different', abs(x - x0).max() if (y != y0).any(): print i, 'y different', abs(y - y0).max() if (z != z0).any(): print i, 'z different', abs(z - z0).max() ndiff += 1 return ndiff def test3(nsim=100): x0, y0 = load() z0 = calc(100*x0, y0) / (100 * 100) ndiff = 0 for i in xrange(nsim): x, y = load() z = calc(100*x, y) / (100 * 100) if (x != x0).any(): print i, 'x different', abs(x - x0).max() if (y != y0).any(): print i, 'y different', abs(y - y0).max() if (z != z0).any(): print i, 'z different', abs(z - z0).max() ndiff += 1 return ndiff def all(): n1 = test1() n2 = test2() n3 = test3() print print '-'*75 print 'Numpy version:',N.__version__ print print 'test1: ', n1, ' differences' print 'test2: ', n2, ' differences' print 'test3: ', n3, ' differences' all()