Skip to content

Commit 63ff766

Browse files
authored
Merge branch 'release/0.4' into cherry-pick-5409-by-pytorch_bot_bot_
2 parents 5feb0f7 + b5f7b85 commit 63ff766

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

extension/tensor/tensor_impl_ptr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ struct TensorImplPtrDeleter final {
5454
} // namespace
5555

5656
TensorImplPtr make_tensor_impl_ptr(
57-
exec_aten::ScalarType type,
5857
std::vector<exec_aten::SizesType> sizes,
5958
void* data,
6059
std::vector<exec_aten::DimOrderType> dim_order,
6160
std::vector<exec_aten::StridesType> strides,
61+
exec_aten::ScalarType type,
6262
exec_aten::TensorShapeDynamism dynamism,
6363
std::function<void(void*)> deleter) {
6464
const auto dim = sizes.size();
@@ -129,24 +129,24 @@ TensorImplPtr make_tensor_impl_ptr(
129129
}
130130

131131
TensorImplPtr make_tensor_impl_ptr(
132-
exec_aten::ScalarType scalar_type,
133132
std::vector<exec_aten::SizesType> sizes,
134133
std::vector<uint8_t> data,
135134
std::vector<exec_aten::DimOrderType> dim_order,
136135
std::vector<exec_aten::StridesType> strides,
136+
exec_aten::ScalarType type,
137137
exec_aten::TensorShapeDynamism dynamism) {
138138
ET_CHECK_MSG(
139139
data.size() >= exec_aten::compute_numel(sizes.data(), sizes.size()) *
140-
exec_aten::elementSize(scalar_type),
140+
exec_aten::elementSize(type),
141141
"Data size is smaller than required by sizes and scalar type.");
142142
auto raw_data_ptr = data.data();
143143
auto data_ptr = std::make_shared<std::vector<uint8_t>>(std::move(data));
144144
return make_tensor_impl_ptr(
145-
scalar_type,
146145
std::move(sizes),
147146
raw_data_ptr,
148147
std::move(dim_order),
149148
std::move(strides),
149+
type,
150150
dynamism,
151151
[data_ptr = std::move(data_ptr)](void*) {});
152152
}

extension/tensor/tensor_ptr_maker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ TensorPtr empty_strided(
105105
exec_aten::compute_numel(sizes.data(), sizes.size()) *
106106
exec_aten::elementSize(type));
107107
return make_tensor_ptr(
108-
type,
109108
std::move(sizes),
110109
std::move(data),
111110
{},
112111
std::move(strides),
112+
type,
113113
dynamism);
114114
}
115115

extension/tensor/tensor_ptr_maker.h

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ namespace extension {
1515

1616
/**
1717
* A helper class for creating TensorPtr instances from raw data and tensor
18-
* properties. Note that the TensorPtr created by this class will not own the
19-
* data, so it must outlive the TensorPtr.
18+
* properties. Note that the TensorPtr created by this class does not own the
19+
* data, so the data must outlive the TensorPtr.
2020
*
21-
* TensorPtrMaker provides a fluent interface for specifying various properties
22-
* of a tensor, such as its type, sizes, data pointer, dimension order, strides,
23-
* and shape dynamism. The final tensor is created by invoking make_tensor_ptr()
24-
* or converting TensorPtrMaker to TensorPtr.
21+
* TensorPtrMaker provides a fluent interface for specifying various tensor
22+
* properties, such as type, sizes, data pointer, dimension order, strides, and
23+
* shape dynamism. The final tensor is created by invoking make_tensor_ptr() or
24+
* by converting TensorPtrMaker to TensorPtr.
2525
*/
2626
class TensorPtrMaker final {
2727
public:
@@ -99,11 +99,11 @@ class TensorPtrMaker final {
9999
*/
100100
TensorPtr make_tensor_ptr() && {
101101
return ::executorch::extension::make_tensor_ptr(
102-
type_,
103102
std::move(sizes_),
104103
data_,
105104
std::move(dim_order_),
106105
std::move(strides_),
106+
type_,
107107
dynamism_,
108108
std::move(deleter_));
109109
}
@@ -167,16 +167,16 @@ inline TensorPtrMaker for_blob(
167167
* Creates a TensorPtr from a raw data pointer and tensor sizes, with an
168168
* optional dynamism setting.
169169
*
170-
* This function is a convenient way to create a tensor from existing data, with
171-
* the option to specify whether the tensor's shape is static, dynamic, or
172-
* bounded.
170+
* This function provides a convenient way to create a tensor from existing
171+
* data, with the option to specify whether the tensor's shape is static or
172+
* dynamic.
173173
*
174-
* @param data A pointer to the raw data to be used by the tensor. It must
174+
* @param data A pointer to the raw data used by the tensor. The data must
175175
* outlive the TensorPtr created by this function.
176176
* @param sizes A vector specifying the size of each dimension.
177177
* @param type The scalar type of the tensor elements.
178178
* @param dynamism Specifies whether the tensor's shape is static or dynamic.
179-
* @return A TensorPtr instance that manages the newly created Tensor.
179+
* @return A TensorPtr instance managing the newly created Tensor.
180180
*/
181181
inline TensorPtr from_blob(
182182
void* data,
@@ -195,15 +195,16 @@ inline TensorPtr from_blob(
195195
*
196196
* This function allows for the creation of a tensor from existing data, with
197197
* the option to specify custom strides for each dimension and whether the
198-
* tensor's shape is static, dynamic, or bounded.
198+
* tensors shape is static, dynamic, or bounded.
199199
*
200-
* @param data A pointer to the raw data to be used by the tensor. It must
200+
* @param data A pointer to the raw data used by the tensor. The data must
201201
* outlive the TensorPtr created by this function.
202202
* @param sizes A vector specifying the size of each dimension.
203203
* @param strides A vector specifying the stride for each dimension.
204204
* @param type The scalar type of the tensor elements.
205-
* @param dynamism Specifies whether the tensor's shape is static or dynamic.
206-
* @return A TensorPtr instance that manages the newly created Tensor.
205+
* @param dynamism Specifies whether the tensor's shape is static, dynamic, or
206+
* bounded.
207+
* @return A TensorPtr instance managing the newly created Tensor.
207208
*/
208209
inline TensorPtr from_blob(
209210
void* data,
@@ -306,9 +307,10 @@ TensorPtr empty_strided(
306307
* This function allocates memory for the tensor elements but does not
307308
* initialize them with any specific values.
308309
*
309-
* @param other A reference to another tensor, whose size and properties will be
310+
* @param other A reference to another tensor, whose size and properties are
310311
* used.
311-
* @param type The scalar type of the tensor elements.
312+
* @param type The scalar type of the tensor elements. If not provided, the
313+
* scalar type of the other tensor is used.
312314
* @param dynamism Specifies whether the tensor's shape is static or dynamic.
313315
* @return A TensorPtr instance managing the newly created Tensor.
314316
*/
@@ -397,7 +399,7 @@ inline TensorPtr full_like(
397399
* Creates a TensorPtr filled with the specified value.
398400
*
399401
* @param sizes A vector specifying the size of each dimension.
400-
* @param fill_value The value to fill the tensor with.
402+
* @param fill_value The value used to fill the tensor.
401403
* @param type The scalar type of the tensor elements.
402404
* @param dynamism Specifies whether the tensor's shape is static or dynamic.
403405
* @return A TensorPtr instance managing the newly created Tensor.
@@ -412,11 +414,10 @@ inline TensorPtr full(
412414
}
413415

414416
/**
415-
* Creates a TensorPtr that holds a scalar value.
417+
* Creates a TensorPtr holding a scalar value.
416418
*
417-
* @param value The scalar value to create the tensor with.
419+
* @param value The scalar value for the tensor.
418420
* @param type The scalar type of the tensor elements.
419-
* @param dynamism Specifies whether the tensor's shape is static or dynamic.
420421
* @return A TensorPtr instance managing the newly created scalar Tensor.
421422
*/
422423
inline TensorPtr scalar_tensor(
@@ -429,10 +430,10 @@ inline TensorPtr scalar_tensor(
429430
* Creates a TensorPtr filled with ones, with the same size and properties as
430431
* another tensor.
431432
*
432-
* @param other A reference to another tensor, whose size and properties will be
433+
* @param other A reference to another tensor, whose size and properties are
433434
* used.
434-
* @param type The scalar type of the tensor elements. If not specified, the
435-
* scalar type of the `other` tensor is used.
435+
* @param type The scalar type of the tensor elements. If not provided, the
436+
* scalar type of the other tensor is used.
436437
* @param dynamism Specifies whether the tensor's shape is static or dynamic.
437438
* @return A TensorPtr instance managing the newly created Tensor.
438439
*/
@@ -553,7 +554,8 @@ inline TensorPtr rand(
553554
}
554555

555556
/**
556-
* Creates a TensorPtr filled with random values from a normal distribution.
557+
* Creates a TensorPtr filled with random values between 0 and 1, with specified
558+
* strides.
557559
*
558560
* @param sizes A vector specifying the size of each dimension.
559561
* @param strides A vector specifying the stride for each dimension.
@@ -594,7 +596,8 @@ inline TensorPtr randn_like(
594596
}
595597

596598
/**
597-
* Creates a TensorPtr filled with random values from a normal distribution.
599+
* Creates a TensorPtr filled with random values sampled from a normal
600+
* distribution.
598601
*
599602
* @param sizes A vector specifying the size of each dimension.
600603
* @param type The scalar type of the tensor elements.
@@ -661,10 +664,11 @@ inline TensorPtr randint_like(
661664
}
662665

663666
/**
664-
* Creates a TensorPtr filled with random integer values in the given range.
667+
* Creates a TensorPtr filled with random integer values within the specified
668+
* range.
665669
*
666-
* @param low The lower bound (inclusive) of the random values.
667-
* @param high The upper bound (exclusive) of the random values.
670+
* @param low The inclusive lower bound of the random values.
671+
* @param high The exclusive upper bound of the random values.
668672
* @param sizes A vector specifying the size of each dimension.
669673
* @param type The scalar type of the tensor elements.
670674
* @param dynamism Specifies whether the tensor's shape is static or dynamic.

0 commit comments

Comments
 (0)