//===- File.cpp - Reading/writing sparse tensors from/to files ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements reading and writing sparse tensor files. // //===----------------------------------------------------------------------===// #include "mlir/ExecutionEngine/SparseTensor/File.h" #include <cctype> #include <cstring> usingnamespacemlir::sparse_tensor; /// Opens the file for reading. void SparseTensorReader::openFile() { … } /// Closes the file. void SparseTensorReader::closeFile() { … } /// Attempts to read a line from the file. void SparseTensorReader::readLine() { … } /// Reads and parses the file's header. void SparseTensorReader::readHeader() { … } /// Asserts the shape subsumes the actual dimension sizes. Is only /// valid after parsing the header. void SparseTensorReader::assertMatchesShape(uint64_t rank, const uint64_t *shape) const { … } bool SparseTensorReader::canReadAs(PrimaryType valTy) const { … } /// Helper to convert C-style strings (i.e., '\0' terminated) to lower case. static inline void toLower(char *token) { … } /// Idiomatic name for checking string equality. static inline bool streq(const char *lhs, const char *rhs) { … } /// Idiomatic name for checking string inequality. static inline bool strne(const char *lhs, const char *rhs) { … } /// Read the MME header of a general sparse matrix of type real. void SparseTensorReader::readMMEHeader() { … } /// Read the "extended" FROSTT header. Although not part of the documented /// format, we assume that the file starts with optional comments followed /// by two lines that define the rank, the number of nonzeros, and the /// dimensions sizes (one per rank) of the sparse tensor. void SparseTensorReader::readExtFROSTTHeader() { … }