Enum Type

Source
pub enum Type {
    Scalar(ScalarType),
    Array(ArrayShape, ScalarType),
    Vector(u64, Arc<Type>),
    Tuple(Vec<Arc<Type>>),
    NamedTuple(Vec<(String, Arc<Type>)>),
}
Expand description

This enum represents the input or output type of a computation Node within the parent computational Graph.

Variants§

§

Scalar(ScalarType)

Each scalar corresponds to a signed or an unsigned number modulo m, where m = {2, 28, 216, 232, 264}.

Scalar types supported by CipherCore are provided as parameters. These scalar types could be BIT, UINT8, INT8, UINT16, INT16, UINT32, INT32, UINT64 or INT64.

§Example

let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let t = scalar_type(BIT);
let i0 = g.input(t.clone()).unwrap();
assert_eq!(i0.get_type().unwrap(), t);
§

Array(ArrayShape, ScalarType)

Array entries are scalars and arrays could be multi-dimensional.

Array is analogous to NumPy’s numpy.array.

An array is defined using a valid shape and a supported scalar type.

§Example

let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let a_shape = vec![10, 1, 20];
let at = array_type(a_shape, UINT32);
assert!(at.is_valid());
let i0 = g.input(at.clone()).unwrap();
assert_eq!(i0.get_type().unwrap(), at);
§

Vector(u64, Arc<Type>)

Vector type is a one-dimensional list of entries of some constituent type, which can be any valid type including the vector or tuple type.

A vector type is defined by the number of entries and a pointer to the type of those entries.

§Example

let c = create_context().unwrap();
let g = c.create_graph().unwrap();
let a_shape = vec![10, 1, 20];
let at = array_type(a_shape, UINT32);
let vt0 = vector_type(10, at);
assert!(vt0.is_valid());
let vt1 = vector_type(10, vt0);
let i0 = g.input(vt1).unwrap();
assert!(i0.get_type().unwrap().is_valid());
§

Tuple(Vec<Arc<Type>>)

Tuples are fixed-length lists consisting of entries of given type(s).

tuple(T0, T1, …, Tn-1) corresponds to a list of types T0, T1, …, Tn-1.

tuple() can be interpreted as a void type.

§Example

let a_shape = vec![10, 1, 20];
let at = array_type(a_shape, UINT32);
let vt0 = vector_type(10, at.clone());
let vt1 = vector_type(10, at);
let tt = tuple_type(vec![vt0, vt1]);
assert!(tt.is_valid());
§

NamedTuple(Vec<(String, Arc<Type>)>)

Named tuples are fixed-length lists that consist of tuples of element-name and associated element-type.

An element’s name can be used to access a particular element within the named tuple.

A valid named tuple should have all the element-types valid.

Element-names for the element-types should be unique.

Named tuple is similar to the tuple type.

§Example

let st = scalar_type(UINT64);
let at = array_type(vec![64], UINT8);
let nt = named_tuple_type(vec![("ID".to_owned(), st), ("Name".to_owned(), at)]);
assert!(nt.is_valid());

Implementations§

Source§

impl Type

Source

pub fn is_valid(&self) -> bool

Tests whether a given type is valid.

Recursively checks if all the arrays that constitute the type have valid shapes, and all the named tuples have unique field names.

§Returns

true, if type instance and its sub-type(s) are valid, otherwise false

§Example
let s0 = INT16;
let t0 = Type::Scalar(s0.clone());
assert!(t0.is_valid());

let a1 = array_type(vec![2, 0, 2], s0.clone());
assert!(!a1.is_valid());

let a2 = array_type(vec![2, 1, 2], s0);
assert!(a2.is_valid());
Source

pub fn is_scalar(&self) -> bool

Tests if a type is scalar.

§Returns

true, if the type instance is scalar, otherwise false

§Example
let t0 = Type::Scalar(INT16);
assert!(t0.is_scalar());
let a1 = array_type(vec![2, 1, 2], INT16);
assert!(!a1.is_scalar());
Source

pub fn is_array(&self) -> bool

Tests if a type is array.

§Returns

true, if type is an array, otherwise false

§Example
let t0 = Type::Scalar(INT16);
assert!(!t0.is_array());

let a1 = array_type(vec![2, 1, 2], INT16);
assert!(a1.is_array());
Source

pub fn is_vector(&self) -> bool

Tests if a type is vector.

§Returns

true, if type is a vector, otherwise false

§Example
let t0 = Type::Scalar(INT16);
assert!(!t0.is_vector());
let a0 = array_type(vec![2, 1, 2], INT16);
assert!(!a0.is_vector());
let v0 = vector_type(2, a0);
assert!(v0.is_vector());
Source

pub fn is_tuple(&self) -> bool

Tests if a type is tuple.

§Returns

true, if type is a tuple, otherwise false

§Example
let s0 = INT32;
let t0 = Type::Scalar(s0.clone());
assert!(!t0.is_tuple());
let a0 = array_type(vec![2, 1, 2], s0.clone());
assert!(!a0.is_tuple());
let v0 = vector_type(2, a0.clone());
assert!(!v0.is_tuple());
let v1 = vector_type(2, a0);
let t1 = tuple_type(vec![v0, v1]);
assert!(t1.is_tuple());
Source

pub fn is_named_tuple(&self) -> bool

Tests if a type is named tuple.

§Returns

true, if type is a named tuple, otherwise false

§Example
let s0 = INT16;
let a0 = array_type(vec![2, 1, 2], s0.clone());
assert!(!a0.is_tuple());
let nt0 = named_tuple_type(vec![
    ("Name".to_owned(), a0.clone()),
    ("Zip".to_owned(), a0)
]);
assert!(nt0.is_named_tuple());
Source

pub fn get_scalar_type(&self) -> ScalarType

Returns the underlying scalar type of a scalar or an array.

§Panics

Panics if self is neither a scalar nor an array

§Returns

Copy of the underlying scalar type for a scalar or an array

§Example
let s0 = INT16;
let st0 = Type::Scalar(s0.clone());
let a0 = array_type(vec![2, 1, 2], s0.clone());
assert!(st0.get_scalar_type().eq(&s0));
assert!(a0.get_scalar_type().eq(&s0));
Source

pub fn get_shape(&self) -> ArrayShape

Returns the shape of an array.

§Panics

Panics if self is not an array

§Returns

Copy of the shape of an array

§Example
let s0 = INT16;
let st0 = Type::Scalar(s0.clone());
let a0_shape = vec![2, 1, 2];
let a0 = array_type(a0_shape.clone(), s0.clone());
assert_eq!(a0_shape, a0.get_shape());
Source

pub fn get_dimensions(&self) -> ArrayShape

Returns the array shape for an array type or [1] for a scalar type.

§Panics

Panics if self is neither a scalar nor an array

§Returns
  • Copy of the shape of a given array, or
  • Shape [1], if a scalar type is given
§Example
let s0 = INT16;
let st0 = Type::Scalar(s0.clone());
let a0_shape = vec![2, 1, 2];
let a0 = array_type(a0_shape.clone(), s0.clone());
assert!(a0.get_dimensions().eq(&a0_shape));
assert_eq!(vec![1], st0.get_dimensions());
Source

pub fn size_in_bits(&self) -> Result<u64>

Returns the size of a type in bits.

Returns a runtime error if type is not valid.

Within named tuple types, the bit size of name strings is omitted.

§Returns

Type size in bits

Source§

impl Type

Source

pub fn get_named_types(&self) -> Result<Vec<(String, Type)>>

Returns a vector of tuples created from the named tuple.

This function reverse the result of named_tuple_type().

§Returns

Vector of tuples (type name, type)

§Example
let st0 = Type::Scalar(UINT8);
let st1 = Type::Scalar(UINT32);
let vec_t = vec![("age".to_owned(), st0), ("zip".to_owned(), st1)];
let t = named_tuple_type(vec_t.clone());
assert_eq!(vec_t, t.get_named_types().unwrap());

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type

Source§

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

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

impl<'de> Deserialize<'de> for Type

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Type

Source§

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

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

impl Hash for Type

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Type

Source§

fn eq(&self, other: &Type) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Type

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Type

Source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,