Skip to content

Commit

Permalink
doc: add an in-memory tensor data example
Browse files Browse the repository at this point in the history
Closes intel#136.
  • Loading branch information
abrown committed Sep 19, 2024
1 parent 190261d commit dd36646
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/openvino/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ use openvino_sys::{
};

/// See [`Tensor`](https://docs.openvino.ai/2023.3/api/c_cpp_api/group__ov__tensor__c__api.html).
///
/// To create a tensor from in-memory data, construct it and then fill it:
///
/// ```rust
/// # use openvino::{Shape, Tensor, ElementType};
/// # fn main() -> anyhow::Result<()> {
/// let data = [1u8; 1000];
/// let shape = Shape::new(&[10, 10, 10])?;
/// let mut tensor = Tensor::new(ElementType::U8, &shape)?;
/// tensor.get_raw_data_mut()?.copy_from_slice(&data);
/// # Ok(())
/// # }
/// ```
///
/// This approach currently results in a copy, which is sub-optimal. It is safe, however; passing a
/// slice to OpenVINO is unsafe unless additional lifetime constraints are added (to improve this in
/// the future, see the context in [#125]).
///
/// [#125]: https://github.com/intel/openvino-rs/pull/125
pub struct Tensor {
ptr: *mut ov_tensor_t,
}
Expand Down

0 comments on commit dd36646

Please sign in to comment.