This function reads the file header at the given filepath, and returns the size of the sparse matrix in the clsparseCooMatrix parameter. Post-condition: clears clsparseCooMatrix, then sets pCooMatx->m, pCooMatx->n pCooMatx->nnz
| 438 | // Post-condition: clears clsparseCooMatrix, then sets pCooMatx->m, pCooMatx->n |
| 439 | // pCooMatx->nnz |
| 440 | clsparseStatus |
| 441 | clsparseHeaderfromFile( clsparseIdx_t* nnz, clsparseIdx_t* row, clsparseIdx_t* col, const char* filePath ) |
| 442 | { |
| 443 | |
| 444 | // Check that the file format is matrix market; the only format we can read right now |
| 445 | // This is not a complete solution, and fails for directories with file names etc... |
| 446 | // TODO: Should we use boost filesystem? |
| 447 | std::string strPath( filePath ); |
| 448 | if( strPath.find_last_of( '.' ) != std::string::npos ) |
| 449 | { |
| 450 | std::string ext = strPath.substr( strPath.find_last_of( '.' ) + 1 ); |
| 451 | if( ext != "mtx" ) |
| 452 | return clsparseInvalidFileFormat; |
| 453 | } |
| 454 | else |
| 455 | return clsparseInvalidFileFormat; |
| 456 | |
| 457 | MatrixMarketReader< cl_float > mm_reader; |
| 458 | |
| 459 | if( mm_reader.MMReadHeader( filePath ) ) |
| 460 | return clsparseInvalidFile; |
| 461 | |
| 462 | *row = mm_reader.GetNumRows( ); |
| 463 | *col = mm_reader.GetNumCols( ); |
| 464 | *nnz = mm_reader.GetNumNonZeroes( ); |
| 465 | |
| 466 | return clsparseSuccess; |
| 467 | } |
| 468 | |
| 469 | // This function reads the file at the given filepath, and returns the sparse |
| 470 | // matrix in the COO struct. All matrix data is written to device memory |