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

Function scalar2storage

imperative/python/src/tensor.cpp:183–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181
182template <typename T>
183auto scalar2storage(T val, CompNode cn, DType dtype) {
184 using max_ctype_t = DTypeScalar::max_ctype;
185 DTypeScalar scalar(dtype);
186 scalar.set_retain_dtype(val);
187 HostTensorStorage storage(cn);
188 auto* raw_ptr = reinterpret_cast<dt_byte*>(new max_ctype_t());
189 std::shared_ptr<dt_byte> raw_storage = {
190 raw_ptr, [](dt_byte* ptr) { delete reinterpret_cast<max_ctype_t*>(ptr); }};
191 storage.only_reset_raw_storage(cn, dtype.size(), raw_storage, 0);
192 std::memcpy(storage.ptr(), scalar.storage(), dtype.size());
193 return HostStorage::make(std::move(storage));
194}
195
196template <typename ctype>
197auto vec2storage(Span<DTypeScalar> vec, CompNode cn, DType dtype) {

Callers 2

pyint2hvalFunction · 0.85
pyfloat2hvalFunction · 0.85

Calls 6

set_retain_dtypeMethod · 0.80
storageMethod · 0.80
makeFunction · 0.50
sizeMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected