TorontoDeepLearning / convnet

A GPU implementation of Convolutional Neural Nets in C++
BSD 2-Clause "Simplified" License
506 stars 229 forks source link

Bug in LoadChunk(DataIterator& it, Matrix& mat, vector<int>& random_rows) #27

Open junliangxing opened 9 years ago

junliangxing commented 9 years ago

There is a bug in Line 296-312 void DataHandler::LoadChunk(DataIterator& it, Matrix& mat, vector& random_rows) { float* data_ptr = mat.GetHostData(); int num_dims = it.GetDims(); int num_rand = (chunksize + random_access_chunksize - 1) / random_access_chunksize; int row, end; for (int i = 0; i < num_rand; i++) { row = random_rows[i]; end = (row + random_access_chunksize) % datasetsize; if (end < row) { it.Get(data_ptr, row, datasetsize); it.Get(data_ptr + num_dims * (datasetsize - row), 0, end); } else { it.Get(data_ptr, row, end); } data_ptr += num_dims * random_access_chunksize; } }

One possible way to fix it could be : void DataHandler::LoadChunk(DataIterator& it, Matrix& mat, vector& random_rows) { float* data_ptr = mat.GetHostData(); int num_dims = it.GetDims(); int num_rand = (chunksize + random_access_chunksize - 1) / random_access_chunksize; int row, end; for (int i = 0; i < num_rand; i++) { row = random_rows[i]; end = (row + random_access_chunksize) % datasetsize; if (end < row) { it.Get(data_ptr, row, datasetsize); int remain_size = random_access_chunksize - (datasetsize - row); if (remain_size > 0) { it.Get(data_ptr + num_dims * (datasetsize - row), 0, remain_size); } } else { it.Get(data_ptr, row, end); } data_ptr += num_dims * random_access_chunksize; } }

nitishsrivastava commented 9 years ago

Thanks for pointing this about. This has been fixed now.