This solves a least squares problem using SVD similar to
This only returns the least-squares solution, while
If it's necessary to have 100% return syntax match to
Edit 04-28-2019 22:54 EDT.
I have a benchmark comparing the performance of this
python3 sine_benchmark_fixed_six_break_points.py python3 sine_benchmark_fixed_six_break_points_TFnoGPU.py python3 sine_benchmark_fixed_twenty_break_points.py python3 sine_benchmark_fixed_twenty_break_points_TFnoGPU.py python3 plot_results.py
The text was updated successfully, but these errors were encountered:
Is this the return other values?
I added the other return values, and now
The new overhead comes from calculating the sum of square of the residuals (L-2 norm):
if rank != n or m <= n: resids = cupy.array(, dtype=a.dtype) elif b.ndim > 1: # note that this should be the same (and faster?) than the next couple of lines # e = b - core.dot(a, x) # resids = cupy.diagonal(core.dot(e.T, e)) k = b.shape resids = cupy.zeros(k, dtype=a.dtype) for i in range(k): e = b[:, i] - core.dot(a, x[:, i]) resids[i] = core.dot(e.T, e) else: e = b - core.dot(a, x) resids = core.dot(e.T, e).reshape(-1)
Sometimes test fail, in particular
import numpy as np a = np.array([[2., 5., 1., 2.], [2., 2., 3., 8.], [4., 8., 1., 8.], [1., 3., 5., 1.]], dtype=np.float32) b = np.array((9., 6., 0., 3.), dtype=np.float32)
where lstsq is solved in the following manner
x, resid, rank, s = np.linalg.lstsq(a, b)
produces (x_cpu == numpy.linalg.lstsq solution, x_gpu == cupy.linalg.lstsq solution)
AssertionError: Not equal to tolerance rtol=1e-07, atol=0.001 Mismatch: 50% Max absolute difference: 0.0032959 Max relative difference: 1.6645674e-05 x_cpu: array([198. , -64.71429 , 6.857143, -35.142857], dtype=float32) x_gpu: array([198.0033 , -64.71534 , 6.857244, -35.14343 ], dtype=float32)
Should I make the tests deterministic to avoid such failures? this could be done by supplying a random seed for each configuration of
Yes, It seems preferred to make the tests deterministic.
@asi1024 Thanks for your recommendations.
I remove the retry condition, and use fixed random seeds to generate the arrays now.
The tests have been reworked to generate a singular matrix. If a singular matrix was generated, the tests no longer check if the first return element is close to NumPy solution. All other return elements are still checked.