Matrix Market 官方主页
主流稀疏和稠密矩阵数据文件交换格式
读写接口
- matlab函数
- Python: scipy.io, mminfo、mmread、mmwrite
- C读写函数
- Fortran读写函数
- Eigen库支持: unsupported/Eigen/src/SparseExtra/MarketIO.h
- CUSP支持: io/matrix_market.h(AMGX库的include路径下内含cusp)
HB格式资料
小工具
用scipy.io中的mminfo&mmread检查Matrix Market文件有效性
#!/bin/python3
'''
Validate Matrix Market format(MTX) file by using scipy.io.mminfo & scip.io.mmread
'''
import sys
import os
#https://www.geeksforgeeks.org/how-to-print-exception-stack-trace-in-python/
import traceback
from scipy.io import mminfo,mmread,mmwrite
def usage():
print('''Usage: /mtx_check.py <MTX-FILE>''');
if len(sys.argv)!=2:
usage()
exit(1)
mtx_file=sys.argv[1];
if not(os.path.isfile(mtx_file)):
print('{} is not a file'.format(mtx_file))
usage()
exit(2)
try:
mminfo(mtx_file)
except:
print('{} mminfo failed'.format(mtx_file))
#https://pythonsolved.com/python-get-first-line-of-file/
with open(mtx_file,'r') as f:
first_line=f.readline()
print('{} first line: "{}"'.format(mtx_file,first_line.rstrip('\n')))
traceback.print_exc()
exit(3)
else:
print('{} mminfo OK!'.format(mtx_file))
try:
A=mmread(mtx_file)
except:
print('{} mmread failed'.format(mtx_file))
traceback.print_exc()
exit(4)
else:
print('{} mmread OK!'.format(mtx_file))
exit(0)