Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion implicit/gpu/matrix.cu
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ COOMatrix::COOMatrix(int rows, int cols, int nonzeros, const int *row_,

CHECK_CUDA(cudaMallocManaged(&data, nonzeros * sizeof(float)));
CHECK_CUDA(
cudaMemcpy(data, data_, nonzeros * sizeof(int), cudaMemcpyHostToDevice));
cudaMemcpy(data, data_, nonzeros * sizeof(float), cudaMemcpyHostToDevice));
}

COOMatrix::~COOMatrix() {
Expand Down
12 changes: 12 additions & 0 deletions tests/gpu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
from numpy.testing import assert_allclose, assert_array_equal
from recommender_base_test import get_checker_board
from scipy.sparse import coo_matrix

import implicit

Expand Down Expand Up @@ -81,3 +82,14 @@ def test_cpu_gpu_conversion(model_class, from_gpu):
rtol=1e-3,
atol=1e-3,
)


@pytest.mark.skipif(not implicit.gpu.HAS_CUDA, reason="needs cuda build")
def test_coo_matrix_copies_float_data():
row = np.array([0, 1, 2, 0, 1, 2], dtype=np.int32)
col = np.array([0, 1, 2, 1, 2, 0], dtype=np.int32)
data = np.array([1.5, 2.7, 3.14159, 0.1, 1000.5, -1.5], dtype=np.float32)

matrix = implicit.gpu.COOMatrix(coo_matrix((data, (row, col)), shape=(3, 3)))

assert matrix is not None