def test_init(self): """Solve example from the spec sheet. In-place scaling. http://www.hsl.rl.ac.uk/specs/mc29.pdf """ irow = np.array([3, 0, 3, 1, 2, 2], dtype=np.int32) jcol = np.array([2, 0, 1, 1, 0, 2], dtype=np.int32) values = np.array([16000, 100, 14000, 6, 900, 110000], dtype=np.float64) # Obtain row and column scaling val = values.copy() row_scale, col_scale = MC29AD_scale(4, 3, irow, jcol, val) assert np.allclose(val, np.array( [0.8790, 1.8123, 1.2811, 0.7806, 0.5518, 1.1377]), 1e-4) unscale(4, 3, row_scale, col_scale, irow, jcol, val) assert np.allclose(val, values)
import numpy as np irow = np.array([3, 0, 3, 1, 2, 2], dtype=np.int32) jcol = np.array([2, 0, 1, 1, 0, 2], dtype=np.int32) values = np.array([16000, 100, 14000, 6, 900, 110000], dtype=np.float64) print 'orignal values:' print '%2s % 2s %6s' % ('i', 'j', 'val') for i in range(0, len(values)): print '%2d % 2d %6.5e' % (irow[i], jcol[i], values[i]) # Obtain row and column scaling row_scale, col_scale = MC29AD_scale(4, 3, irow, jcol, values) print '\nrow scaling factors:' print row_scale print '\ncolumn scaling factors:' print col_scale print '\nscaled values:' print '%2s % 2s %6s' % ('i', 'j', 'val') for i in range(0, len(values)): print '%2d % 2d %6.5e' % (irow[i], jcol[i], values[i]) unscale(4, 3, row_scale, col_scale, irow, jcol, values) print '\nunscaled values:' print '%2s % 2s %6s' % ('i', 'j', 'val') for i in range(0, len(values)): print '%2d % 2d %6.5e' % (irow[i], jcol[i], values[i])