@@ -183,6 +183,30 @@ inline TensorPtrMaker for_blob(
183183 return TensorPtrMaker (data, std::move (sizes), type);
184184}
185185
186+ /* *
187+ * Creates a TensorPtrMaker from a typed data pointer and tensor sizes.
188+ *
189+ * The scalar type is deduced from the pointer's element type, so a buffer of
190+ * one type does not become a Tensor of another. Pass `type` explicitly to
191+ * reinterpret the buffer as a different type.
192+ *
193+ * @tparam T The C++ type of the tensor elements, deduced from the pointer.
194+ * @param data A pointer to the raw data used by the tensor.
195+ * @param sizes A vector specifying the size of each dimension.
196+ * @param type The scalar type of the tensor elements.
197+ * @return A TensorPtrMaker instance for creating a TensorPtr.
198+ */
199+ template <
200+ typename T,
201+ executorch::aten::ScalarType deduced_type =
202+ runtime::CppTypeToScalarType<T>::value>
203+ inline TensorPtrMaker for_blob (
204+ T* data,
205+ std::vector<executorch::aten::SizesType> sizes,
206+ executorch::aten::ScalarType type = deduced_type) {
207+ return for_blob (static_cast <void *>(data), std::move (sizes), type);
208+ }
209+
186210/* *
187211 * Creates a TensorPtr from a raw data pointer and tensor sizes, with an
188212 * optional dynamism setting.
@@ -213,6 +237,38 @@ inline TensorPtr from_blob(
213237 .make_tensor_ptr ();
214238}
215239
240+ /* *
241+ * Creates a TensorPtr from a typed data pointer and tensor sizes.
242+ *
243+ * The scalar type is deduced from the pointer's element type; see `for_blob`.
244+ *
245+ * @tparam T The C++ type of the tensor elements, deduced from the pointer.
246+ * @param data A pointer to the raw data used by the tensor. The data must
247+ * outlive the TensorPtr created by this function.
248+ * @param sizes A vector specifying the size of each dimension.
249+ * @param type The scalar type of the tensor elements.
250+ * @param device The device on which `data` resides (default CPU).
251+ * @param dynamism Specifies whether the tensor's shape is static or dynamic.
252+ * @return A TensorPtr instance managing the newly created Tensor.
253+ */
254+ template <
255+ typename T,
256+ executorch::aten::ScalarType deduced_type =
257+ runtime::CppTypeToScalarType<T>::value>
258+ inline TensorPtr from_blob (
259+ T* data,
260+ std::vector<executorch::aten::SizesType> sizes,
261+ executorch::aten::ScalarType type = deduced_type,
262+ executorch::aten::Device device =
263+ executorch::aten::Device (executorch::aten::DeviceType::CPU ),
264+ executorch::aten::TensorShapeDynamism dynamism =
265+ executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) {
266+ return for_blob (static_cast <void *>(data), std::move (sizes), type)
267+ .device (device)
268+ .dynamism (dynamism)
269+ .make_tensor_ptr ();
270+ }
271+
216272/* *
217273 * Creates a TensorPtr from a raw data pointer, tensor sizes, and strides, with
218274 * an optional dynamism setting.
@@ -247,6 +303,41 @@ inline TensorPtr from_blob(
247303 .make_tensor_ptr ();
248304}
249305
306+ /* *
307+ * Creates a TensorPtr from a typed data pointer, tensor sizes, and strides.
308+ *
309+ * The scalar type is deduced from the pointer's element type; see `for_blob`.
310+ *
311+ * @tparam T The C++ type of the tensor elements, deduced from the pointer.
312+ * @param data A pointer to the raw data used by the tensor. The data must
313+ * outlive the TensorPtr created by this function.
314+ * @param sizes A vector specifying the size of each dimension.
315+ * @param strides A vector specifying the stride for each dimension.
316+ * @param type The scalar type of the tensor elements.
317+ * @param device The device on which `data` resides (default CPU).
318+ * @param dynamism Specifies whether the tensor's shape is static or dynamic.
319+ * @return A TensorPtr instance managing the newly created Tensor.
320+ */
321+ template <
322+ typename T,
323+ executorch::aten::ScalarType deduced_type =
324+ runtime::CppTypeToScalarType<T>::value>
325+ inline TensorPtr from_blob (
326+ T* data,
327+ std::vector<executorch::aten::SizesType> sizes,
328+ std::vector<executorch::aten::StridesType> strides,
329+ executorch::aten::ScalarType type = deduced_type,
330+ executorch::aten::Device device =
331+ executorch::aten::Device (executorch::aten::DeviceType::CPU ),
332+ executorch::aten::TensorShapeDynamism dynamism =
333+ executorch::aten::TensorShapeDynamism::DYNAMIC_BOUND) {
334+ return for_blob (static_cast <void *>(data), std::move (sizes), type)
335+ .strides (std::move (strides))
336+ .device (device)
337+ .dynamism (dynamism)
338+ .make_tensor_ptr ();
339+ }
340+
250341/* *
251342 * Creates a TensorPtr from a raw data pointer and tensor sizes, with an
252343 * optional dynamism setting.
0 commit comments