def per_item_cpu(vector_r, matrix_A, matrix_B, matrix_BT, alpha):
    vector_r_index = vector_r.nonzero()[0]
    vector_r_small = vector_r.data
    vector_c_small = alpha * vector_r_small
    matrix_B_small = np.take(matrix_B, vector_r_index, axis=0)
    matrix_BT_small = np.take(matrix_BT, vector_r_index, axis=1)
    denominator = cpu_inv(matrix_A+(matrix_BT_small*vector_c_small).dot(matrix_B_small))
    return (denominator.dot(matrix_BT_small)).dot((vector_c_small*vector_r_small+vector_r_small).T).flatten()
Exemplo n.º 2
0
 def _impl_test_inv(self, dtype):
     from scipy.linalg import inv as cpu_inv
     x = np.asarray(np.random.rand(4, 4), dtype)
     x = np.dot(x.T, x)
     x_gpu = gpuarray.to_gpu(x)
     xinv = cpu_inv(x)
     xinv_gpu = linalg.inv(x_gpu)
     assert np.allclose(xinv, xinv_gpu.get(), atol=1e-5)
     assert xinv_gpu is not x_gpu
     xinv_gpu = linalg.inv(x_gpu, overwrite=True)
     assert np.allclose(xinv, xinv_gpu.get(), atol=1e-5)
     assert xinv_gpu is x_gpu
Exemplo n.º 3
0
 def impl_test_inv(self, dtype):
     from scipy.linalg import inv as cpu_inv
     x = np.asarray(np.random.rand(4, 4), dtype)
     x = np.dot(x.T, x)
     x_gpu = gpuarray.to_gpu(x)
     xinv = cpu_inv(x)
     xinv_gpu = linalg.inv(x_gpu)
     assert np.allclose(xinv, xinv_gpu.get(), atol=1e-5)
     assert xinv_gpu is not x_gpu
     xinv_gpu = linalg.inv(x_gpu, overwrite=True)
     assert np.allclose(xinv, xinv_gpu.get(), atol=1e-5)
     assert xinv_gpu is x_gpu