MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / Tensor

Class Tensor

imperative/python/src/tensor.h:39–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37extern PyObject* cpp_astensor1d;
38
39struct Tensor {
40private:
41 ValueRef m_data;
42 std::string m_name;
43
44public:
45 using Handle = interpreter::Interpreter::Handle;
46
47 inline explicit Tensor(ValueRef data) : m_data{data} {}
48
49 ~Tensor() = default;
50
51 inline Tensor copy() { return Tensor(imperative::apply(DupTensor(), data())[0]); }
52
53 inline DType dtype() { return *data().dtype(); }
54 inline CompNode comp_node() { return *data().device(); }
55 inline std::optional<ValueShape> shape() {
56 auto shape = data().shape();
57 if (!shape) {
58 return {};
59 }
60 return *shape;
61 }
62 inline Format format() { return *data().format(); }
63 inline void set_format(std::string format) {
64 if (!format.empty()) {
65 m_data = imperative::apply(SetFormat(format), m_data)[0];
66 }
67 }
68 inline void as_format(std::string format) {
69 if (!format.empty()) {
70 m_data = imperative::apply(AsFormat(format), m_data)[0];
71 }
72 }
73 inline HostValue::ref_t numpy() { return data().numpy(); }
74 inline void reset(ValueRef value) {
75 m_data = value;
76 if (!m_name.empty()) {
77 set_name(m_name);
78 }
79 }
80 inline ValueRef data() const { return m_data.unwrap(); }
81 bool is_scalar() { return data().is_scalar(); }
82 inline std::string name() { return m_name; }
83 inline size_t value_id() { return m_data.id(); }
84 inline void set_name(std::string name) {
85 m_name = name;
86 if (!name.empty()) {
87 auto output = imperative::apply(RenameValue(name), m_data)[0];
88 m_data = output;
89 }
90 }
91};
92
93struct TensorWrapper {
94public:

Callers 15

update_modelFunction · 0.90
workerFunction · 0.90
_test_optimizerFunction · 0.90
test_metadataFunction · 0.90
test_replace_varFunction · 0.90
test_replace_oprFunction · 0.90
test_modify_paramsFunction · 0.90
test_make_constFunction · 0.90
test_add_inputFunction · 0.90
test_add_remove_outputFunction · 0.90
test_queryFunction · 0.90

Calls

no outgoing calls

Tested by 15

update_modelFunction · 0.72
workerFunction · 0.72
_test_optimizerFunction · 0.72
test_metadataFunction · 0.72
test_replace_varFunction · 0.72
test_replace_oprFunction · 0.72
test_modify_paramsFunction · 0.72
test_make_constFunction · 0.72
test_add_inputFunction · 0.72
test_add_remove_outputFunction · 0.72
test_queryFunction · 0.72