14 template <
typename T,
typename indexT,
bool columnMajor>
15 void SparseMatrix<T, indexT, 1, columnMajor>::encodeValueType() {
16 uint8_t byte0 =
sizeof(T);
17 uint8_t byte1 = std::is_floating_point<T>::value ? 1 : 0;
18 uint8_t byte2 = std::is_signed_v<T> ? 1 : 0;
19 uint8_t byte3 = columnMajor ? 1 : 0;
21 val_t = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;
25 template <
typename T,
typename indexT,
bool columnMajor>
26 void SparseMatrix<T, indexT, 1, columnMajor>::checkValueType() {
27 uint8_t byte0 = val_t & 0xFF;
28 uint8_t byte1 = (val_t >> 8) & 0xFF;
29 uint8_t byte2 = (val_t >> 16) & 0xFF;
30 uint8_t byte3 = (val_t >> 24) & 0xFF;
31 assert(byte0 ==
sizeof(T) &&
"Value type size does not match");
32 assert(byte1 == std::is_floating_point_v<T> &&
33 "Value type is not floating point");
34 assert(byte2 == std::is_signed_v<T> &&
"Value type is not signed");
35 assert(byte3 == columnMajor &&
"Major direction does not match");
39 template <
typename T,
typename indexT,
bool columnMajor>
40 void SparseMatrix<T, indexT, 1, columnMajor>::userChecks() {
41 assert((innerDim > 1 || outerDim > 1 || nnz > 1) &&
42 "The matrix must have at least one row, column, and nonzero value");
43 assert(std::is_floating_point<indexT>::value ==
false &&
44 "The index type must be a non-floating point type");
45 assert((std::is_arithmetic<T>::value && std::is_arithmetic<indexT>::value) &&
46 "The value and index types must be numeric types");
47 assert((std::is_same<indexT, bool>::value ==
false) &&
48 "The index type must not be bool");
49 assert((innerDim < std::numeric_limits<indexT>::max() &&
50 outerDim < std::numeric_limits<indexT>::max()) &&
51 "The number of rows and columns must be less than the maximum value "
57 template <
typename T,
typename indexT,
bool columnMajor>
58 void SparseMatrix<T, indexT, 1, columnMajor>::calculateCompSize() {
63 compSize += META_DATA_SIZE;
66 compSize +=
sizeof(T) * nnz;
67 compSize +=
sizeof(indexT) * nnz;
68 compSize +=
sizeof(indexT) * (outerDim + 1);