1#ifndef EVE_TENSOR_TENSOR_H
2#define EVE_TENSOR_TENSOR_H
49 explicit Tensor(
const int *dims,
int rank);
54 Tensor(
int d0,
int d1,
int d2);
55 Tensor(
int d0,
int d1,
int d2,
int d3);
56 Tensor(
int d0,
int d1,
int d2,
int d3,
int d4);
57 Tensor(
int d0,
int d1,
int d2,
int d3,
int d4,
int d5);
62 bool isSymbolic()
const {
return kind_ == Kind::Symbolic; }
63 bool isEager()
const {
return kind_ == Kind::Eager; }
65 int nodeId()
const {
return nodeId_; }
69 int getDim(
int axis)
const;
88 const std::vector<float> &
qScales()
const {
return qScales_; }
89 int qGroup()
const {
return qGroup_; }
90 const std::vector<uint8_t> &
qBytes()
const {
return bytes_; }
92 float get(
int flatIndex)
const;
93 void set(
int flatIndex,
float value);
100 float get4(
int i0,
int i1,
int i2,
int i3)
const;
102 float get5(
int i0,
int i1,
int i2,
int i3,
int i4)
const;
104 float get6(
int i0,
int i1,
int i2,
int i3,
int i4,
int i5)
const;
105 void set6(
int i0,
int i1,
int i2,
int i3,
int i4,
int i5,
float value);
160 Tensor *
reshape6(
int d0,
int d1,
int d2,
int d3,
int d4,
int d5)
const;
165 const float *
data()
const;
169 static int product(
const int *dims,
int rank);
177 enum class Kind { Eager, Symbolic };
179 void initDims(
DType dtype,
const int *dims,
int rank);
180 void checkSameShape(
const Tensor *other,
const char *op)
const;
181 int offset2(
int i0,
int i1)
const;
182 int offset3(
int i0,
int i1,
int i2)
const;
183 int offset4(
int i0,
int i1,
int i2,
int i3)
const;
184 int offset5(
int i0,
int i1,
int i2,
int i3,
int i4)
const;
185 int offset6(
int i0,
int i1,
int i2,
int i3,
int i4,
int i5)
const;
187 Kind kind_ = Kind::Eager;
188 Graph *graph_ =
nullptr;
191 int dims_[
kMaxRank] = {0, 0, 0, 0, 0, 0};
194 std::vector<float> data_;
195 std::vector<uint8_t> bytes_;
196 std::vector<float> qScales_;
198 std::string device_ =
"cpu";
Optimized / scheduled graph ready to run with feeds.
Trace builder — TF2 tf.function analogue (tf.func in scripts). While active, TF ops record into this ...
TF2-like namespace module. Script: tf <- eve.TF(); Default eager; tf.func() traces a graph for compil...
float32 / int32 tensor (rank 1–6), row-major. Eager: owns a buffer. Symbolic: node in a Func graph (n...
Tensor * mulScalar(float s) const
const std::vector< float > & qScales() const
Tensor * reshape5(int d0, int d1, int d2, int d3, int d4) const
Tensor * sub(const Tensor *other) const
std::string getDtype() const
float reduceSum() const
归约:求和 / 均值 / 最小 / 最大。
void ensureEager(const char *op) const
Tensor * add(const Tensor *other) const
Eager 逐元素运算(符号张量会抛异常)。
void copyFrom(const Tensor *other)
void set3(int i0, int i1, int i2, float value)
void addScalarInPlace(float s)
static constexpr int kMaxRank
Tensor * reshape4(int d0, int d1, int d2, int d3) const
float get3(int i0, int i1, int i2) const
float get4(int i0, int i1, int i2, int i3) const
std::vector< float > dequantized() const
const std::vector< uint8_t > & qBytes() const
std::string getDevice() const
void mulScalarInPlace(float s)
float get5(int i0, int i1, int i2, int i3, int i4) const
Tensor * reshape6(int d0, int d1, int d2, int d3, int d4, int d5) const
Tensor * reshape2(int d0, int d1) const
float * data()
原始数据指针(eager)。
Tensor * clamp(float lo, float hi) const
Tensor * reshape1(int d0) const
float dot(const Tensor *other) const
float get6(int i0, int i1, int i2, int i3, int i4, int i5) const
Tensor * divScalar(float s) const
Tensor * multiply(const Tensor *other) const
float get2(int i0, int i1) const
Tensor * powScalar(float exp) const
Tensor * subScalar(float s) const
void set1(int i0, float value)
int getDim(int axis) const
Tensor * transpose() const
void set(int flatIndex, float value)
void set4(int i0, int i1, int i2, int i3, float value)
float get(int flatIndex) const
Tensor * maximumScalar(float s) const
Tensor * div(const Tensor *other) const
static Tensor * makeSymbolic(Graph *graph, int nodeId, const int *dims, int rank)
Symbolic handle into a graph node.
void set2(int i0, int i1, float value)
Tensor * reshape3(int d0, int d1, int d2) const
void multiplyInPlace(const Tensor *other)
void setDtype(DType dtype)
Tensor * matmul(const Tensor *other) const
矩阵乘法 / 转置 / 变形。
Tensor * minimumScalar(float s) const
Tensor * addScalar(float s) const
Tensor * permute(const int *order, int rank) const
static int product(const int *dims, int rank)
void addInPlace(const Tensor *other)
Eager 原地运算。
void set6(int i0, int i1, int i2, int i3, int i4, int i5, float value)
void set5(int i0, int i1, int i2, int i3, int i4, float value)
bool isQuantDType(DType dt)
bool parseDType(const std::string &name, DType &out)
DType
Tensor element types.
const char * dtypeName(DType dtype)