refactor: usability

aka The Cleanening, part 2

- Add clearer documentation and examples for more things.
- Rework string tensors by introducing `PrimitiveTensorElementType` for primitive (i.e. f32) types, and again re-implementing `IntoTensorElementType` for `String`. This allows string tensors to be used via `Tensor<String>` instead of exclusively via `DynTensor`. Additionally, string tensors no longer require an `Allocator` to be created (which didn't make sense, since string data in Rust can only ever be stored on the CPU anyway). This also now applies to `Map`s, since their data also needed to be on the CPU anyway. (`Sequence`s are currently unaffected because I think a custom allocator could be useful for them?)
- Rework the `IoBinding` interface, and add an example clarifying the intended usage of it (ref #209). Thanks to AAce from the pyke Discord for pointing out the mutability issue in the old interface, which should be addressed now.
- Refactor `OperatorDomain::add` from the slightly-nicer-looking-but-more-confusing `fn<T>(t: T)` to just `fn<T>()` to further enforce the fact that `Operator`s are zero-sized.
- Maps can now have `String` keys.
- Remove some unused errors.
This commit is contained in:
Carson M.
2024-06-21 15:37:39 -05:00
parent 19d66de302
commit c64b8ea990
20 changed files with 1090 additions and 544 deletions

View File

@@ -3,7 +3,7 @@
use std::path::Path;
use ndarray::{ArrayD, IxDyn};
use ort::{inputs, DynTensor, GraphOptimizationLevel, Session};
use ort::{inputs, GraphOptimizationLevel, Session, Tensor};
use test_log::test;
#[test]
@@ -22,7 +22,7 @@ fn vectorizer() -> ort::Result<()> {
let array = ndarray::CowArray::from(ndarray::Array::from_shape_vec((1,), vec!["document".to_owned()]).unwrap());
// Just one input
let input_tensor_values = inputs![DynTensor::from_string_array(session.allocator(), &array)?]?;
let input_tensor_values = inputs![Tensor::from_string_array(&array)?]?;
// Perform the inference
let outputs = session.run(input_tensor_values)?;