faceidapi::logic::recognition::faceid_models

Struct OrtOwnedTensor

pub struct OrtOwnedTensor<'t, 'm, T, D>{
    pub(crate) tensor_ptr: *mut OrtValue,
    array_view: ArrayBase<ViewRepr<&'t T>, D>,
    memory_info: &'m MemoryInfo,
}
Expand description

Tensor containing data owned by the ONNX Runtime C library, used to return values from inference.

This tensor type is returned by the Session::run() method. It is not meant to be created directly.

The tensor hosts an ndarray::ArrayView of the data on the C side. This allows manipulation on the Rust side using ndarray without copying the data.

OrtOwnedTensor implements the std::deref::Deref trait for ergonomic access to the underlying ndarray::ArrayView.

Fields§

§tensor_ptr: *mut OrtValue§array_view: ArrayBase<ViewRepr<&'t T>, D>§memory_info: &'m MemoryInfo

Implementations§

Source§

impl<'t, 'm, T, D> OrtOwnedTensor<'t, 'm, T, D>

Source

pub fn softmax(&self, axis: Axis) -> ArrayBase<OwnedRepr<T>, D>

Apply a softmax on the specified axis

Methods from Deref<Target = ArrayBase<ViewRepr<&'t T>, D>>§

Source

pub fn len(&self) -> usize

Return the total number of elements in the array.

Source

pub fn len_of(&self, axis: Axis) -> usize

Return the length of axis.

The axis should be in the range Axis( 0 .. n ) where n is the number of dimensions (axes) of the array.

Panics if the axis is out of bounds.

Source

pub fn is_empty(&self) -> bool

Return whether the array has any elements

Source

pub fn ndim(&self) -> usize

Return the number of dimensions (axes) in the array

Source

pub fn dim(&self) -> <D as Dimension>::Pattern

Return the shape of the array in its “pattern” form, an integer in the one-dimensional case, tuple in the n-dimensional cases and so on.

Source

pub fn raw_dim(&self) -> D

Return the shape of the array as it’s stored in the array.

This is primarily useful for passing to other ArrayBase functions, such as when creating another array of the same shape and dimensionality.

use ndarray::Array;

let a = Array::from_elem((2, 3), 5.);

// Create an array of zeros that's the same shape and dimensionality as `a`.
let b = Array::<f64, _>::zeros(a.raw_dim());
Source

pub fn shape(&self) -> &[usize]

Return the shape of the array as a slice.

Note that you probably don’t want to use this to create an array of the same shape as another array because creating an array with e.g. Array::zeros() using a shape of type &[usize] results in a dynamic-dimensional array. If you want to create an array that has the same shape and dimensionality as another array, use .raw_dim() instead:

use ndarray::{Array, Array2};

let a = Array2::<i32>::zeros((3, 4));
let shape = a.shape();
assert_eq!(shape, &[3, 4]);

// Since `a.shape()` returned `&[usize]`, we get an `ArrayD` instance:
let b = Array::zeros(shape);
assert_eq!(a.clone().into_dyn(), b);

// To get the same dimension type, use `.raw_dim()` instead:
let c = Array::zeros(a.raw_dim());
assert_eq!(a, c);
Source

pub fn strides(&self) -> &[isize]

Return the strides of the array as a slice.

Source

pub fn stride_of(&self, axis: Axis) -> isize

Return the stride of axis.

The axis should be in the range Axis( 0 .. n ) where n is the number of dimensions (axes) of the array.

Panics if the axis is out of bounds.

Source

pub fn view(&self) -> ArrayBase<ViewRepr<&A>, D>
where S: Data,

Return a read-only view of the array

Source

pub fn to_owned(&self) -> ArrayBase<OwnedRepr<A>, D>
where A: Clone, S: Data,

Return an uniquely owned copy of the array.

If the input array is contiguous, then the output array will have the same memory layout. Otherwise, the layout of the output array is unspecified. If you need a particular layout, you can allocate a new array with the desired memory layout and .assign() the data. Alternatively, you can collectan iterator, like this for a result in standard layout:

Array::from_shape_vec(arr.raw_dim(), arr.iter().cloned().collect()).unwrap()

or this for a result in column-major (Fortran) layout:

Array::from_shape_vec(arr.raw_dim().f(), arr.t().iter().cloned().collect()).unwrap()
Source

pub fn to_shared(&self) -> ArrayBase<OwnedArcRepr<A>, D>
where A: Clone, S: Data,

Return a shared ownership (copy on write) array, cloning the array elements if necessary.

Source

pub fn first(&self) -> Option<&A>
where S: Data,

Returns a reference to the first element of the array, or None if it is empty.

Source

pub fn iter(&self) -> Iter<'_, A, D>
where S: Data,

Return an iterator of references to the elements of the array.

Elements are visited in the logical order of the array, which is where the rightmost index is varying the fastest.

Iterator element type is &A.

Source

pub fn indexed_iter(&self) -> IndexedIter<'_, A, D>
where S: Data,

Return an iterator of indexes and references to the elements of the array.

Elements are visited in the logical order of the array, which is where the rightmost index is varying the fastest.

Iterator element type is (D::Pattern, &A).

See also Zip::indexed

Source

pub fn slice<I>( &self, info: I, ) -> ArrayBase<ViewRepr<&A>, <I as SliceArg<D>>::OutDim>
where I: SliceArg<D>, S: Data,

Return a sliced view of the array.

See Slicing for full documentation. See also s!, SliceArg, and SliceInfo.

Panics if an index is out of bounds or step size is zero.
(Panics if D is IxDyn and info does not match the number of array axes.)

Source

pub fn slice_axis( &self, axis: Axis, indices: Slice, ) -> ArrayBase<ViewRepr<&A>, D>
where S: Data,

Return a view of the array, sliced along the specified axis.

Panics if an index is out of bounds or step size is zero.
Panics if axis is out of bounds.

Source

pub fn slice_each_axis<F>(&self, f: F) -> ArrayBase<ViewRepr<&A>, D>
where F: FnMut(AxisDescription) -> Slice, S: Data,

Return a view of a slice of the array, with a closure specifying the slice for each axis.

This is especially useful for code which is generic over the dimensionality of the array.

Panics if an index is out of bounds or step size is zero.

Source

pub fn get<I>(&self, index: I) -> Option<&A>
where I: NdIndex<D>, S: Data,

Return a reference to the element at index, or return None if the index is out of bounds.

Arrays also support indexing syntax: array[index].

use ndarray::arr2;

let a = arr2(&[[1., 2.],
               [3., 4.]]);

assert!(
    a.get((0, 1)) == Some(&2.) &&
    a.get((0, 2)) == None &&
    a[(0, 1)] == 2. &&
    a[[0, 1]] == 2.
);
Source

pub unsafe fn uget<I>(&self, index: I) -> &A
where S: Data, I: NdIndex<D>,

Perform unchecked array indexing.

Return a reference to the element at index.

Note: only unchecked for non-debug builds of ndarray.

§Safety

The caller must ensure that the index is in-bounds.

Source

pub fn index_axis( &self, axis: Axis, index: usize, ) -> ArrayBase<ViewRepr<&A>, <D as Dimension>::Smaller>
where S: Data, D: RemoveAxis,

Returns a view restricted to index along the axis, with the axis removed.

See Subviews for full documentation.

Panics if axis or index is out of bounds.

use ndarray::{arr2, ArrayView, Axis};

let a = arr2(&[[1., 2. ],    // ... axis 0, row 0
               [3., 4. ],    // --- axis 0, row 1
               [5., 6. ]]);  // ... axis 0, row 2
//               .   \
//                .   axis 1, column 1
//                 axis 1, column 0
assert!(
    a.index_axis(Axis(0), 1) == ArrayView::from(&[3., 4.]) &&
    a.index_axis(Axis(1), 1) == ArrayView::from(&[2., 4., 6.])
);
Source

pub fn select( &self, axis: Axis, indices: &[usize], ) -> ArrayBase<OwnedRepr<A>, D>
where A: Copy, S: Data, D: RemoveAxis,

Along axis, select arbitrary subviews corresponding to indices and and copy them into a new array.

Panics if axis or an element of indices is out of bounds.

use ndarray::{arr2, Axis};

let x = arr2(&[[0., 1.],
               [2., 3.],
               [4., 5.],
               [6., 7.],
               [8., 9.]]);

let r = x.select(Axis(0), &[0, 4, 3]);
assert!(
        r == arr2(&[[0., 1.],
                    [8., 9.],
                    [6., 7.]])
);
Source

pub fn rows(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>
where S: Data,

Return a producer and iterable that traverses over the generalized rows of the array. For a 2D array these are the regular rows.

This is equivalent to .lanes(Axis(n - 1)) where n is self.ndim().

For an array of dimensions a × b × c × … × l × m it has a × b × c × … × l rows each of length m.

For example, in a 2 × 2 × 3 array, each row is 3 elements long and there are 2 × 2 = 4 rows in total.

Iterator element is ArrayView1<A> (1D array view).

use ndarray::{arr3, Axis, arr1};

let a = arr3(&[[[ 0,  1,  2],    // -- row 0, 0
                [ 3,  4,  5]],   // -- row 0, 1
               [[ 6,  7,  8],    // -- row 1, 0
                [ 9, 10, 11]]]); // -- row 1, 1

// `rows` will yield the four generalized rows of the array.
for row in a.rows() {
    /* loop body */
}
Source

pub fn genrows(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>
where S: Data,

👎Deprecated since 0.15.0: Renamed to .rows()
Source

pub fn columns(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>
where S: Data,

Return a producer and iterable that traverses over the generalized columns of the array. For a 2D array these are the regular columns.

This is equivalent to .lanes(Axis(0)).

For an array of dimensions a × b × c × … × l × m it has b × c × … × l × m columns each of length a.

For example, in a 2 × 2 × 3 array, each column is 2 elements long and there are 2 × 3 = 6 columns in total.

Iterator element is ArrayView1<A> (1D array view).

use ndarray::{arr3, Axis, arr1};

// The generalized columns of a 3D array:
// are directed along the 0th axis: 0 and 6, 1 and 7 and so on...
let a = arr3(&[[[ 0,  1,  2], [ 3,  4,  5]],
               [[ 6,  7,  8], [ 9, 10, 11]]]);

// Here `columns` will yield the six generalized columns of the array.
for row in a.columns() {
    /* loop body */
}
Source

pub fn gencolumns(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>
where S: Data,

👎Deprecated since 0.15.0: Renamed to .columns()

Return a producer and iterable that traverses over the generalized columns of the array. For a 2D array these are the regular columns.

Renamed to .columns()

Source

pub fn lanes(&self, axis: Axis) -> Lanes<'_, A, <D as Dimension>::Smaller>
where S: Data,

Return a producer and iterable that traverses over all 1D lanes pointing in the direction of axis.

When pointing in the direction of the first axis, they are columns, in the direction of the last axis rows; in general they are all lanes and are one dimensional.

Iterator element is ArrayView1<A> (1D array view).

use ndarray::{arr3, aview1, Axis};

let a = arr3(&[[[ 0,  1,  2],
                [ 3,  4,  5]],
               [[ 6,  7,  8],
                [ 9, 10, 11]]]);

let inner0 = a.lanes(Axis(0));
let inner1 = a.lanes(Axis(1));
let inner2 = a.lanes(Axis(2));

// The first lane for axis 0 is [0, 6]
assert_eq!(inner0.into_iter().next().unwrap(), aview1(&[0, 6]));
// The first lane for axis 1 is [0, 3]
assert_eq!(inner1.into_iter().next().unwrap(), aview1(&[0, 3]));
// The first lane for axis 2 is [0, 1, 2]
assert_eq!(inner2.into_iter().next().unwrap(), aview1(&[0, 1, 2]));
Source

pub fn outer_iter(&self) -> AxisIter<'_, A, <D as Dimension>::Smaller>
where S: Data, D: RemoveAxis,

Return an iterator that traverses over the outermost dimension and yields each subview.

This is equivalent to .axis_iter(Axis(0)).

Iterator element is ArrayView<A, D::Smaller> (read-only array view).

Source

pub fn axis_iter( &self, axis: Axis, ) -> AxisIter<'_, A, <D as Dimension>::Smaller>
where S: Data, D: RemoveAxis,

Return an iterator that traverses over axis and yields each subview along it.

For example, in a 3 × 4 × 5 array, with axis equal to Axis(2), the iterator element is a 3 × 4 subview (and there are 5 in total), as shown in the picture below.

Iterator element is ArrayView<A, D::Smaller> (read-only array view).

See Subviews for full documentation.

Panics if axis is out of bounds.

Source

pub fn axis_chunks_iter( &self, axis: Axis, size: usize, ) -> AxisChunksIter<'_, A, D>
where S: Data,

Return an iterator that traverses over axis by chunks of size, yielding non-overlapping views along that axis.

Iterator element is ArrayView<A, D>

The last view may have less elements if size does not divide the axis’ dimension.

Panics if axis is out of bounds or if size is zero.

use ndarray::Array;
use ndarray::{arr3, Axis};
use std::iter::FromIterator;

let a = Array::from_iter(0..28).into_shape((2, 7, 2)).unwrap();
let mut iter = a.axis_chunks_iter(Axis(1), 2);

// first iteration yields a 2 × 2 × 2 view
assert_eq!(iter.next().unwrap(),
           arr3(&[[[ 0,  1], [ 2, 3]],
                  [[14, 15], [16, 17]]]));

// however the last element is a 2 × 1 × 2 view since 7 % 2 == 1
assert_eq!(iter.next_back().unwrap(), arr3(&[[[12, 13]],
                                             [[26, 27]]]));
Source

pub fn exact_chunks<E>(&self, chunk_size: E) -> ExactChunks<'_, A, D>
where E: IntoDimension<Dim = D>, S: Data,

Return an exact chunks producer (and iterable).

It produces the whole chunks of a given n-dimensional chunk size, skipping the remainder along each dimension that doesn’t fit evenly.

The produced element is a ArrayView<A, D> with exactly the dimension chunk_size.

Panics if any dimension of chunk_size is zero
(Panics if D is IxDyn and chunk_size does not match the number of array axes.)

Source

pub fn windows<E>(&self, window_size: E) -> Windows<'_, A, D>
where E: IntoDimension<Dim = D>, S: Data,

Return a window producer and iterable.

The windows are all distinct overlapping views of size window_size that fit into the array’s shape.

This produces no elements if the window size is larger than the actual array size along any axis.

The produced element is an ArrayView<A, D> with exactly the dimension window_size.

Panics if any dimension of window_size is zero.
(Panics if D is IxDyn and window_size does not match the number of array axes.)

This is an illustration of the 2×2 windows in a 3×4 array:

         ──▶ Axis(1)

     │   ┏━━━━━┳━━━━━┱─────┬─────┐   ┌─────┲━━━━━┳━━━━━┱─────┐   ┌─────┬─────┲━━━━━┳━━━━━┓
     ▼   ┃ a₀₀ ┃ a₀₁ ┃     │     │   │     ┃ a₀₁ ┃ a₀₂ ┃     │   │     │     ┃ a₀₂ ┃ a₀₃ ┃
Axis(0)  ┣━━━━━╋━━━━━╉─────┼─────┤   ├─────╊━━━━━╋━━━━━╉─────┤   ├─────┼─────╊━━━━━╋━━━━━┫
         ┃ a₁₀ ┃ a₁₁ ┃     │     │   │     ┃ a₁₁ ┃ a₁₂ ┃     │   │     │     ┃ a₁₂ ┃ a₁₃ ┃
         ┡━━━━━╇━━━━━╃─────┼─────┤   ├─────╄━━━━━╇━━━━━╃─────┤   ├─────┼─────╄━━━━━╇━━━━━┩
         │     │     │     │     │   │     │     │     │     │   │     │     │     │     │
         └─────┴─────┴─────┴─────┘   └─────┴─────┴─────┴─────┘   └─────┴─────┴─────┴─────┘

         ┌─────┬─────┬─────┬─────┐   ┌─────┬─────┬─────┬─────┐   ┌─────┬─────┬─────┬─────┐
         │     │     │     │     │   │     │     │     │     │   │     │     │     │     │
         ┢━━━━━╈━━━━━╅─────┼─────┤   ├─────╆━━━━━╈━━━━━╅─────┤   ├─────┼─────╆━━━━━╈━━━━━┪
         ┃ a₁₀ ┃ a₁₁ ┃     │     │   │     ┃ a₁₁ ┃ a₁₂ ┃     │   │     │     ┃ a₁₂ ┃ a₁₃ ┃
         ┣━━━━━╋━━━━━╉─────┼─────┤   ├─────╊━━━━━╋━━━━━╉─────┤   ├─────┼─────╊━━━━━╋━━━━━┫
         ┃ a₂₀ ┃ a₂₁ ┃     │     │   │     ┃ a₂₁ ┃ a₂₂ ┃     │   │     │     ┃ a₂₂ ┃ a₂₃ ┃
         ┗━━━━━┻━━━━━┹─────┴─────┘   └─────┺━━━━━┻━━━━━┹─────┘   └─────┴─────┺━━━━━┻━━━━━┛
Source

pub fn diag(&self) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>
where S: Data,

Return a view of the diagonal elements of the array.

The diagonal is simply the sequence indexed by (0, 0, .., 0), (1, 1, …, 1) etc as long as all axes have elements.

Source

pub fn is_standard_layout(&self) -> bool

Return true if the array data is laid out in contiguous “C order” in memory (where the last index is the most rapidly varying).

Return false otherwise, i.e. the array is possibly not contiguous in memory, it has custom strides, etc.

Source

pub fn as_standard_layout(&self) -> ArrayBase<CowRepr<'_, A>, D>
where S: Data<Elem = A>, A: Clone,

Return a standard-layout array containing the data, cloning if necessary.

If self is in standard layout, a COW view of the data is returned without cloning. Otherwise, the data is cloned, and the returned array owns the cloned data.

use ndarray::Array2;

let standard = Array2::<f64>::zeros((3, 4));
assert!(standard.is_standard_layout());
let cow_view = standard.as_standard_layout();
assert!(cow_view.is_view());
assert!(cow_view.is_standard_layout());

let fortran = standard.reversed_axes();
assert!(!fortran.is_standard_layout());
let cow_owned = fortran.as_standard_layout();
assert!(cow_owned.is_owned());
assert!(cow_owned.is_standard_layout());
Source

pub fn as_ptr(&self) -> *const A

Return a pointer to the first element in the array.

Raw access to array elements needs to follow the strided indexing scheme: an element at multi-index I in an array with strides S is located at offset

Σ0 ≤ k < d Ik × Sk

where d is self.ndim().

Source

pub fn raw_view(&self) -> ArrayBase<RawViewRepr<*const A>, D>

Return a raw view of the array.

Source

pub fn as_slice(&self) -> Option<&[A]>
where S: Data,

Return the array’s data as a slice, if it is contiguous and in standard order. Return None otherwise.

If this function returns Some(_), then the element order in the slice corresponds to the logical order of the array’s elements.

Source

pub fn as_slice_memory_order(&self) -> Option<&[A]>
where S: Data,

Return the array’s data as a slice if it is contiguous, return None otherwise.

If this function returns Some(_), then the elements in the slice have whatever order the elements have in memory.

Source

pub fn reshape<E>(&self, shape: E) -> ArrayBase<S, <E as IntoDimension>::Dim>

Note: Reshape is for ArcArray only. Use .into_shape() for other arrays and array views.

Transform the array into shape; any shape with the same number of elements is accepted.

May clone all elements if needed to arrange elements in standard layout (and break sharing).

Panics if shapes are incompatible.

use ndarray::{rcarr1, rcarr2};

assert!(
    rcarr1(&[1., 2., 3., 4.]).reshape((2, 2))
    == rcarr2(&[[1., 2.],
                [3., 4.]])
);
Source

pub fn broadcast<E>( &self, dim: E, ) -> Option<ArrayBase<ViewRepr<&A>, <E as IntoDimension>::Dim>>
where E: IntoDimension, S: Data,

Act like a larger size and/or shape array by broadcasting into a larger shape, if possible.

Return None if shapes can not be broadcast together.

Background

  • Two axes are compatible if they are equal, or one of them is 1.
  • In this instance, only the axes of the smaller side (self) can be 1.

Compare axes beginning with the last axis of each shape.

For example (1, 2, 4) can be broadcast into (7, 6, 2, 4) because its axes are either equal or 1 (or missing); while (2, 2) can not be broadcast into (2, 4).

The implementation creates a view with strides set to zero for the axes that are to be repeated.

The broadcasting documentation for Numpy has more information.

use ndarray::{aview1, aview2};

assert!(
    aview1(&[1., 0.]).broadcast((10, 2)).unwrap()
    == aview2(&[[1., 0.]; 10])
);
Source

pub fn t(&self) -> ArrayBase<ViewRepr<&A>, D>
where S: Data,

Return a transposed view of the array.

This is a shorthand for self.view().reversed_axes().

See also the more general methods .reversed_axes() and .swap_axes().

Source

pub fn axes(&self) -> Axes<'_, D>

Return an iterator over the length and stride of each axis.

Source

pub fn max_stride_axis(&self) -> Axis

Return the axis with the greatest stride (by absolute value), preferring axes with len > 1.

Source

pub fn assign_to<P>(&self, to: P)
where S: Data, P: IntoNdProducer<Dim = D>, <P as IntoNdProducer>::Item: AssignElem<A>, A: Clone,

Perform an elementwise assigment of values cloned from self into array or producer to.

The destination to can be another array or a producer of assignable elements. AssignElem determines how elements are assigned.

Panics if shapes disagree.

Source

pub fn fold<'a, F, B>(&'a self, init: B, f: F) -> B
where F: FnMut(B, &'a A) -> B, A: 'a, S: Data,

Traverse the array elements and apply a fold, returning the resulting value.

Elements are visited in arbitrary order.

Source

pub fn map<'a, B, F>(&'a self, f: F) -> ArrayBase<OwnedRepr<B>, D>
where F: FnMut(&'a A) -> B, A: 'a, S: Data,

Call f by reference on each element and create a new array with the new values.

Elements are visited in arbitrary order.

Return an array with the same shape as self.

use ndarray::arr2;

let a = arr2(&[[ 0., 1.],
               [-1., 2.]]);
assert!(
    a.map(|x| *x >= 1.0)
    == arr2(&[[false, true],
              [false, true]])
);
Source

pub fn mapv<B, F>(&self, f: F) -> ArrayBase<OwnedRepr<B>, D>
where F: FnMut(A) -> B, A: Clone, S: Data,

Call f by value on each element and create a new array with the new values.

Elements are visited in arbitrary order.

Return an array with the same shape as self.

use ndarray::arr2;

let a = arr2(&[[ 0., 1.],
               [-1., 2.]]);
assert!(
    a.mapv(f32::abs) == arr2(&[[0., 1.],
                               [1., 2.]])
);
Source

pub fn for_each<'a, F>(&'a self, f: F)
where F: FnMut(&'a A), A: 'a, S: Data,

Call f for each element in the array.

Elements are visited in arbitrary order.

Source

pub fn visit<'a, F>(&'a self, f: F)
where F: FnMut(&'a A), A: 'a, S: Data,

👎Deprecated since 0.15.0: Renamed to .for_each()

Visit each element in the array by calling f by reference on each element.

Elements are visited in arbitrary order.

Source

pub fn fold_axis<B, F>( &self, axis: Axis, init: B, fold: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
where D: RemoveAxis, F: FnMut(&B, &A) -> B, B: Clone, S: Data,

Fold along an axis.

Combine the elements of each subview with the previous using the fold function and initial value init.

Return the result as an Array.

Panics if axis is out of bounds.

Source

pub fn map_axis<'a, B, F>( &'a self, axis: Axis, mapping: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
where D: RemoveAxis, F: FnMut(ArrayBase<ViewRepr<&'a A>, Dim<[usize; 1]>>) -> B, A: 'a, S: Data,

Reduce the values along an axis into just one value, producing a new array with one less dimension.

Elements are visited in arbitrary order.

Return the result as an Array.

Panics if axis is out of bounds.

Source

pub fn to_vec(&self) -> Vec<A>
where A: Clone, S: Data,

Return an vector with the elements of the one-dimensional array.

Source

pub fn row(&self, index: usize) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>
where S: Data,

Return an array view of row index.

Panics if index is out of bounds.

use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert_eq!(array.row(0), array![1., 2.]);
Source

pub fn nrows(&self) -> usize

Return the number of rows (length of Axis(0)) in the two-dimensional array.

use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert_eq!(array.nrows(), 2usize);
Source

pub fn column(&self, index: usize) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>
where S: Data,

Return an array view of column index.

Panics if index is out of bounds.

use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert_eq!(array.column(0), array![1., 3.]);
Source

pub fn ncols(&self) -> usize

Return the number of columns (length of Axis(1)) in the two-dimensional array.

use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert_eq!(array.ncols(), 2usize);
Source

pub fn is_square(&self) -> bool

Return true if the array is square, false otherwise.

§Examples

Sqaure:

use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert!(array.is_square());

Not sqaure:

use ndarray::array;
let array = array![[1., 2., 5.], [3., 4., 6.]];
assert!(!array.is_square());
Source

pub fn sum(&self) -> A
where A: Clone + Add<Output = A> + Zero,

Return the sum of all elements in the array.

use ndarray::arr2;

let a = arr2(&[[1., 2.],
               [3., 4.]]);
assert_eq!(a.sum(), 10.);
Source

pub fn scalar_sum(&self) -> A
where A: Clone + Add<Output = A> + Zero,

👎Deprecated since 0.15.0: renamed to sum

Return the sum of all elements in the array.

This method has been renamed to .sum()

Source

pub fn mean(&self) -> Option<A>
where A: Clone + FromPrimitive + Add<Output = A> + Div<Output = A> + Zero,

Returns the arithmetic mean x̅ of all elements in the array:

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

If the array is empty, None is returned.

Panics if A::from_usize() fails to convert the number of elements in the array.

Source

pub fn product(&self) -> A
where A: Clone + Mul<Output = A> + One,

Return the product of all elements in the array.

use ndarray::arr2;

let a = arr2(&[[1., 2.],
               [3., 4.]]);
assert_eq!(a.product(), 24.);
Source

pub fn var(&self, ddof: A) -> A
where A: Float + FromPrimitive,

Return variance of elements in the array.

The variance is computed using the Welford one-pass algorithm.

The parameter ddof specifies the “delta degrees of freedom”. For example, to calculate the population variance, use ddof = 0, or to calculate the sample variance, use ddof = 1.

The variance is defined as:

              1       n
variance = ――――――――   ∑ (xᵢ - x̅)²
           n - ddof  i=1

where

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

and n is the length of the array.

Panics if ddof is less than zero or greater than n

§Example
use ndarray::array;
use approx::assert_abs_diff_eq;

let a = array![1., -4.32, 1.14, 0.32];
let var = a.var(1.);
assert_abs_diff_eq!(var, 6.7331, epsilon = 1e-4);
Source

pub fn std(&self, ddof: A) -> A
where A: Float + FromPrimitive,

Return standard deviation of elements in the array.

The standard deviation is computed from the variance using the Welford one-pass algorithm.

The parameter ddof specifies the “delta degrees of freedom”. For example, to calculate the population standard deviation, use ddof = 0, or to calculate the sample standard deviation, use ddof = 1.

The standard deviation is defined as:

              ⎛    1       n          ⎞
stddev = sqrt ⎜ ――――――――   ∑ (xᵢ - x̅)²⎟
              ⎝ n - ddof  i=1         ⎠

where

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

and n is the length of the array.

Panics if ddof is less than zero or greater than n

§Example
use ndarray::array;
use approx::assert_abs_diff_eq;

let a = array![1., -4.32, 1.14, 0.32];
let stddev = a.std(1.);
assert_abs_diff_eq!(stddev, 2.59483, epsilon = 1e-4);
Source

pub fn sum_axis( &self, axis: Axis, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
where A: Clone + Zero<Output = A> + Add, D: RemoveAxis,

Return sum along axis.

use ndarray::{aview0, aview1, arr2, Axis};

let a = arr2(&[[1., 2., 3.],
               [4., 5., 6.]]);
assert!(
    a.sum_axis(Axis(0)) == aview1(&[5., 7., 9.]) &&
    a.sum_axis(Axis(1)) == aview1(&[6., 15.]) &&

    a.sum_axis(Axis(0)).sum_axis(Axis(0)) == aview0(&21.)
);

Panics if axis is out of bounds.

Source

pub fn mean_axis( &self, axis: Axis, ) -> Option<ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>>
where A: Clone + Zero<Output = A> + FromPrimitive + Add + Div<Output = A>, D: RemoveAxis,

Return mean along axis.

Return None if the length of the axis is zero.

Panics if axis is out of bounds or if A::from_usize() fails for the axis length.

use ndarray::{aview0, aview1, arr2, Axis};

let a = arr2(&[[1., 2., 3.],
               [4., 5., 6.]]);
assert!(
    a.mean_axis(Axis(0)).unwrap() == aview1(&[2.5, 3.5, 4.5]) &&
    a.mean_axis(Axis(1)).unwrap() == aview1(&[2., 5.]) &&

    a.mean_axis(Axis(0)).unwrap().mean_axis(Axis(0)).unwrap() == aview0(&3.5)
);
Source

pub fn var_axis( &self, axis: Axis, ddof: A, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>

Return variance along axis.

The variance is computed using the Welford one-pass algorithm.

The parameter ddof specifies the “delta degrees of freedom”. For example, to calculate the population variance, use ddof = 0, or to calculate the sample variance, use ddof = 1.

The variance is defined as:

              1       n
variance = ――――――――   ∑ (xᵢ - x̅)²
           n - ddof  i=1

where

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

and n is the length of the axis.

Panics if ddof is less than zero or greater than n, if axis is out of bounds, or if A::from_usize() fails for any any of the numbers in the range 0..=n.

§Example
use ndarray::{aview1, arr2, Axis};

let a = arr2(&[[1., 2.],
               [3., 4.],
               [5., 6.]]);
let var = a.var_axis(Axis(0), 1.);
assert_eq!(var, aview1(&[4., 4.]));
Source

pub fn std_axis( &self, axis: Axis, ddof: A, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>

Return standard deviation along axis.

The standard deviation is computed from the variance using the Welford one-pass algorithm.

The parameter ddof specifies the “delta degrees of freedom”. For example, to calculate the population standard deviation, use ddof = 0, or to calculate the sample standard deviation, use ddof = 1.

The standard deviation is defined as:

              ⎛    1       n          ⎞
stddev = sqrt ⎜ ――――――――   ∑ (xᵢ - x̅)²⎟
              ⎝ n - ddof  i=1         ⎠

where

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

and n is the length of the axis.

Panics if ddof is less than zero or greater than n, if axis is out of bounds, or if A::from_usize() fails for any any of the numbers in the range 0..=n.

§Example
use ndarray::{aview1, arr2, Axis};

let a = arr2(&[[1., 2.],
               [3., 4.],
               [5., 6.]]);
let stddev = a.std_axis(Axis(0), 1.);
assert_eq!(stddev, aview1(&[2., 2.]));
Source

pub fn dot<Rhs>( &self, rhs: &Rhs, ) -> <ArrayBase<S, Dim<[usize; 1]>> as Dot<Rhs>>::Output
where ArrayBase<S, Dim<[usize; 1]>>: Dot<Rhs>,

Perform dot product or matrix multiplication of arrays self and rhs.

Rhs may be either a one-dimensional or a two-dimensional array.

If Rhs is one-dimensional, then the operation is a vector dot product, which is the sum of the elementwise products (no conjugation of complex operands, and thus not their inner product). In this case, self and rhs must be the same length.

If Rhs is two-dimensional, then the operation is matrix multiplication, where self is treated as a row vector. In this case, if self is shape M, then rhs is shape M × N and the result is shape N.

Panics if the array shapes are incompatible.
Note: If enabled, uses blas dot for elements of f32, f64 when memory layout allows.

Source

pub fn dot<Rhs>( &self, rhs: &Rhs, ) -> <ArrayBase<S, Dim<[usize; 2]>> as Dot<Rhs>>::Output
where ArrayBase<S, Dim<[usize; 2]>>: Dot<Rhs>,

Perform matrix multiplication of rectangular arrays self and rhs.

Rhs may be either a one-dimensional or a two-dimensional array.

If Rhs is two-dimensional, they array shapes must agree in the way that if self is M × N, then rhs is N × K.

Return a result array with shape M × K.

Panics if shapes are incompatible or the number of elements in the result would overflow isize.

Note: If enabled, uses blas gemv/gemm for elements of f32, f64 when memory layout allows. The default matrixmultiply backend is otherwise used for f32, f64 for all memory layouts.

use ndarray::arr2;

let a = arr2(&[[1., 2.],
               [0., 1.]]);
let b = arr2(&[[1., 2.],
               [2., 3.]]);

assert!(
    a.dot(&b) == arr2(&[[5., 8.],
                        [2., 3.]])
);
Source

pub fn to_slice(&self) -> Option<&'a [A]>

Return the array’s data as a slice, if it is contiguous and in standard order. Return None otherwise.

Note that while the method is similar to ArrayBase::as_slice(), this method tranfers the view’s lifetime to the slice, so it is a bit more powerful.

Source

pub fn is_view(&self) -> bool

Returns true iff the array is the view (borrowed) variant.

Source

pub fn is_owned(&self) -> bool

Returns true iff the array is the owned variant.

Trait Implementations§

Source§

impl<'t, 'm, T, D> Debug for OrtOwnedTensor<'t, 'm, T, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'t, 'm, T, D> Deref for OrtOwnedTensor<'t, 'm, T, D>

Source§

type Target = ArrayBase<ViewRepr<&'t T>, D>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<OrtOwnedTensor<'t, 'm, T, D> as Deref>::Target

Dereferences the value.
Source§

impl<'t, 'm, T, D> Drop for OrtOwnedTensor<'t, 'm, T, D>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'t, 'm, T, D> Freeze for OrtOwnedTensor<'t, 'm, T, D>
where D: Freeze,

§

impl<'t, 'm, T, D> RefUnwindSafe for OrtOwnedTensor<'t, 'm, T, D>

§

impl<'t, 'm, T, D> !Send for OrtOwnedTensor<'t, 'm, T, D>

§

impl<'t, 'm, T, D> !Sync for OrtOwnedTensor<'t, 'm, T, D>

§

impl<'t, 'm, T, D> Unpin for OrtOwnedTensor<'t, 'm, T, D>
where D: Unpin,

§

impl<'t, 'm, T, D> UnwindSafe for OrtOwnedTensor<'t, 'm, T, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression
where Self: Sized + AsExpression<T>,

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T