本文整理汇总了C++中SparseMatrix::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::Clear方法的具体用法?C++ SparseMatrix::Clear怎么用?C++ SparseMatrix::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix::Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Reset
//-----------------------------------------------------------------------------
void Reset()
{
min_iter = 5;
max_iter = 5000;
nmf_tolerance = 0.005;
hier_nmf2_tolerance = 0.0001;
// use two threads if the HW cannot provide concurrency info
unsigned int hw_threads = std::thread::hardware_concurrency();
if (0 == hw_threads)
hw_threads = 2;
max_threads = hw_threads;
maxterms = 5;
outprecision = 6;
clustfile_format = OutputFormat::JSON;
// default outdir is the current directory
outdir = std::string("");
dict_loaded = false;
matrix_loaded = false;
dict_filepath.clear();
matrix_filepath.clear();
A.Clear();
buf_a.clear();
buf_w.clear();
buf_h.clear();
m = n = k = nnz = ldim_a = ldim_w = ldim_h = 0u;
}
示例2: LoadMatrixMarketFile
bool LoadMatrixMarketFile(const std::string& file_path,
SparseMatrix<T>& A,
unsigned int& height,
unsigned int& width,
unsigned int& nnz)
{
std::ifstream infile(file_path);
if (!infile)
return false;
char mm_typecode[4];
// read the matrix market banner (header)
if (0 != mm_read_banner(infile, mm_typecode))
return false;
if (!mm_is_valid(mm_typecode))
return false;
// this reader supports these matrix types:
//
// sparse, real/integer/pattern, general/symm/skew
//
if (!mm_is_sparse(mm_typecode))
{
std::cerr << "Only sparse MatrixMarket files are supported." << std::endl;
return false;
}
if (!mm_is_real(mm_typecode) && !mm_is_integer(mm_typecode) && !mm_is_pattern(mm_typecode))
{
std::cerr << "Only real, integer, and pattern MatrixMarket formats are supported." << std::endl;
return false;
}
if (!mm_is_general(mm_typecode) && !mm_is_symmetric(mm_typecode) && !mm_is_skew(mm_typecode))
{
std::cerr << "Only general, symmetric, and skew-symmetric MatrixMarket formats are supported."
<< std::endl;
return false;
}
// read the number of rows, cols, nonzeros
if (0 != mm_read_mtx_crd_size(infile, height, width, nnz))
{
std::cerr << "could not read matrix coordinate information" << std::endl;
height = width = nnz = 0;
return false;
}
// read the data according to the type
bool is_real = mm_is_real(mm_typecode);
bool is_int = mm_is_integer(mm_typecode);
bool is_symmetric = mm_is_symmetric(mm_typecode);
bool is_skew = mm_is_skew(mm_typecode);
std::string line;
unsigned int reserve_size = nnz;
if (is_symmetric || is_skew)
reserve_size *= 2;
A.Clear();
A.Reserve(height, width, reserve_size);
// load num random entries of A
A.BeginLoad();
unsigned int row, col, count;
if (is_real)
{
double val;
for (count=0; count != nnz; ++count)
{
infile >> row; assert(row >= 1);
infile >> col; assert(col >= 1);
infile >> val;
// convert to 0-based indexing
row -= 1;
col -= 1;
A.Load(row, col, val);
if (row != col)
{
if (is_symmetric)
A.Load(col, row, val);
else if (is_skew)
A.Load(col, row, -val);
}
}
}
else if (is_int)