summaryrefslogtreecommitdiff
path: root/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
diff options
context:
space:
mode:
authorwren romano <2998727+wrengr@users.noreply.github.com>2022-09-29 13:31:14 -0700
committerwren romano <2998727+wrengr@users.noreply.github.com>2022-09-29 15:00:50 -0700
commit4792b8ae869c0c2f8c588d613bddfbb9bca888f5 (patch)
treeea46a4bae2cfa907e20617fed10a533456bdb2e2 /mlir/lib/ExecutionEngine/SparseTensor/File.cpp
parent8f4f26ba5bd04f7b335836021e5e63b4236c0305 (diff)
[mlir][sparse] Cleaning up SparseTensorFile::readMMEHeader
This is a followup to the refactoring of D133462, D133830, D133831, and D133833. Depends On D133833 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D133837
Diffstat (limited to 'mlir/lib/ExecutionEngine/SparseTensor/File.cpp')
-rw-r--r--mlir/lib/ExecutionEngine/SparseTensor/File.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
index 5a01b89f2afa..2ea00b34f3f9 100644
--- a/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensor/File.cpp
@@ -117,6 +117,16 @@ static inline char *toLower(char *token) {
return token;
}
+/// Idiomatic name for checking string equality.
+static inline bool streq(const char *lhs, const char *rhs) {
+ return strcmp(lhs, rhs) == 0;
+}
+
+/// Idiomatic name for checking string inequality.
+static inline bool strne(const char *lhs, const char *rhs) {
+ return strcmp(lhs, rhs); // aka `!= 0`
+}
+
/// Read the MME header of a general sparse matrix of type real.
void SparseTensorFile::readMMEHeader() {
char header[64];
@@ -128,25 +138,29 @@ void SparseTensorFile::readMMEHeader() {
if (fscanf(file, "%63s %63s %63s %63s %63s\n", header, object, format, field,
symmetry) != 5)
MLIR_SPARSETENSOR_FATAL("Corrupt header in %s\n", filename);
+ // Convert all to lowercase up front (to avoid accidental redundancy).
+ toLower(header);
+ toLower(object);
+ toLower(format);
+ toLower(field);
+ toLower(symmetry);
// Process `field`, which specify pattern or the data type of the values.
- if (strcmp(toLower(field), "pattern") == 0)
+ if (streq(field, "pattern"))
valueKind_ = ValueKind::kPattern;
- else if (strcmp(toLower(field), "real") == 0)
+ else if (streq(field, "real"))
valueKind_ = ValueKind::kReal;
- else if (strcmp(toLower(field), "integer") == 0)
+ else if (streq(field, "integer"))
valueKind_ = ValueKind::kInteger;
- else if (strcmp(toLower(field), "complex") == 0)
+ else if (streq(field, "complex"))
valueKind_ = ValueKind::kComplex;
else
MLIR_SPARSETENSOR_FATAL("Unexpected header field value in %s\n", filename);
-
// Set properties.
- isSymmetric_ = (strcmp(toLower(symmetry), "symmetric") == 0);
+ isSymmetric_ = streq(symmetry, "symmetric");
// Make sure this is a general sparse matrix.
- if (strcmp(toLower(header), "%%matrixmarket") ||
- strcmp(toLower(object), "matrix") ||
- strcmp(toLower(format), "coordinate") ||
- (strcmp(toLower(symmetry), "general") && !isSymmetric_))
+ if (strne(header, "%%matrixmarket") || strne(object, "matrix") ||
+ strne(format, "coordinate") ||
+ (strne(symmetry, "general") && !isSymmetric_))
MLIR_SPARSETENSOR_FATAL("Cannot find a general sparse matrix in %s\n",
filename);
// Skip comments.