Current section
Files
Jump to
Current section
Files
nifs/tensor/tensor.hpp
/**
* @file
* @brief Tensor is a multi-dimentional matrix (sometimes caled ND-Array)
* contaning elements of a single data type.
* @author Igor Lesik 2019
* @copyright Igor Lesik 2019-2020
*
*/
#pragma once
#include <cstdint>
namespace numy {
struct Tensor
{
static unsigned constexpr MAX_DIMS = 32;
static uint64_t constexpr MAGIC = 0xbadc01dc0ffe;
uint64_t magic = MAGIC; ///< to check we are actually dealing with Tensor
enum {T_DBL, T_FLT} dtype;
unsigned nrDims; ///< number of dimensions
unsigned shape[MAX_DIMS]; ///< size of each dimension
void* data;
unsigned nrElements;
unsigned dataSize; /// size of data in bytes
inline bool isValid() const {
return nrDims > 0 and nrDims < MAX_DIMS and
magic == MAGIC and data != nullptr;
}
inline unsigned nr_cols() const {
return shape[0];
}
inline unsigned nr_rows() const {
return (nrDims == 1)? 1u : shape[1];
}
inline double* dbl_data() { return (double*) data; }
};
} // end of namespace numy