-
Notifications
You must be signed in to change notification settings - Fork 22.1k
/
Functions.h
77 lines (66 loc) · 2.09 KB
/
Functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
// ${generated_comment}
#include <c10/core/Scalar.h>
#include <ATen/Tensor.h>
#include <c10/core/Storage.h>
#include <ATen/core/Generator.h>
#include <c10/util/Deprecated.h>
#include <ATen/NativeFunctions.h>
#include <ATen/DeviceGuard.h>
#include <c10/core/TensorOptions.h>
#include <ATen/core/Reduction.h>
#include <c10/util/Optional.h>
#include <ATen/TensorUtils.h>
#include <ATen/core/ATenDispatch.h>
#include <ATen/Context.h>
#include <ATen/core/EnableNamedTensor.h>
namespace at {
using native::tensor;
${function_declarations}
inline Tensor from_blob(
void* data,
IntArrayRef sizes,
IntArrayRef strides,
const std::function<void(void*)>& deleter,
const TensorOptions& options = {}) {
auto device = globalContext().getDeviceFromPtr(data, options.device().type());
if (options.device().has_index()) {
TORCH_CHECK(
options.device() == device,
"Specified device ", options.device(),
" does not match device of data ", device);
}
auto storage = Storage(
options.dtype(),
detail::computeStorageSize(sizes, strides),
InefficientStdFunctionContext::makeDataPtr(
data, deleter, device),
/*allocator=*/nullptr,
/*resizable=*/false);
return empty({0}, options).set_(storage, 0, sizes, strides);
}
inline Tensor from_blob(
void* data,
IntArrayRef sizes,
const std::function<void(void*)>& deleter,
const TensorOptions& options = {}) {
return from_blob(data, sizes, detail::defaultStrides(sizes), deleter, options);
}
inline Tensor from_blob(
void* data,
IntArrayRef sizes,
IntArrayRef strides,
const TensorOptions& options = {}) {
return from_blob(data, sizes, strides, [](void*) {}, options);
}
inline Tensor from_blob(
void* data,
IntArrayRef sizes,
const TensorOptions& options = {}) {
return from_blob(data, sizes, detail::defaultStrides(sizes), [](void*) {}, options);
}
// function definitions are all static inline because
// they are one-line statically dispatched functions that
// invoke the actual dynamic dispatch on the correct argument
${function_definitions}
}