Struct caffe2_operator::OpSchema
source · pub struct OpSchema { /* private fields */ }
Expand description
| ———– | @brief | | A class to record the schema of an op. | | OpSchema records the common interface | of an op specified by its name. This is | optional for each operator implemented | in Caffe2 but is strongly recommended. | | To register an OpSchema, one can use | the macro | | OPERATOR_SCHEMA(name) and then append | the various functions in the class. | For example, for an op that takes in two | inputs, one output, and the first input | and output could be in-place, can be | written as | | OPERATOR_SCHEMA(name) | .NumInputs(2) | .NumOutputs(1) | .AllowInplace({{0, 0}}); |
Implementations§
source§impl OpSchema
impl OpSchema
pub fn has_cost_inference_function(&self) -> bool
pub fn infer_cost( &self, def: &OperatorDef, input_tensor_shape: &Vec<TensorShape> ) -> OpSchemaCost
pub fn input_desc(&self) -> &Vec<(*const u8, *const u8)>
pub fn output_desc(&self) -> &Vec<(*const u8, *const u8)>
sourcepub fn num_inputs_with_function(
&mut self,
func: fn(_u0: i32) -> bool
) -> &mut OpSchema
pub fn num_inputs_with_function( &mut self, func: fn(_u0: i32) -> bool ) -> &mut OpSchema
| Functions to set the property of the | operator schemas. | | Sets the number of inputs, either a fixed | number or a min and a max.
| ———– | @brief | | Input is checked with a specified function. |
sourcepub fn num_outputs_from_function(
&mut self,
func: fn(_u0: i32) -> bool
) -> &mut OpSchema
pub fn num_outputs_from_function( &mut self, func: fn(_u0: i32) -> bool ) -> &mut OpSchema
| ———– | @brief | | Output is checked with a specified function. |
sourcepub fn num_inputs_outputs(
&mut self,
func: fn(_u0: i32, _u1: i32) -> bool
) -> &mut OpSchema
pub fn num_inputs_outputs( &mut self, func: fn(_u0: i32, _u1: i32) -> bool ) -> &mut OpSchema
| ———– | @brief | | Relationship between inputs and outputs | is checked with a specified function. |
sourcepub fn output_calculator(&mut self, calc: fn(_u0: i32) -> i32) -> &mut OpSchema
pub fn output_calculator(&mut self, calc: fn(_u0: i32) -> i32) -> &mut OpSchema
| ———– | @brief | | Set the output calculator to a user-defined | function. | | Set the function that can calculate | the number of output based on the number | of input. Use only one function in the | set below. |
sourcepub fn allow_inplace_with_functor(
&mut self,
inplace: fn(_u0: i32, _u1: i32) -> bool
) -> &mut OpSchema
pub fn allow_inplace_with_functor( &mut self, inplace: fn(_u0: i32, _u1: i32) -> bool ) -> &mut OpSchema
| Sets the rule to allow optional in-place | operation. |
pub fn allow_inplace(&mut self, inplace: HashSet<(i32, i32)>) -> &mut OpSchema
pub fn allow_one_to_one_inplace(&mut self) -> &mut OpSchema
sourcepub fn enforce_inplace_with_function(
&mut self,
inplace: fn(_u0: i32, _u1: i32) -> bool
) -> &mut OpSchema
pub fn enforce_inplace_with_function( &mut self, inplace: fn(_u0: i32, _u1: i32) -> bool ) -> &mut OpSchema
Sets the rule to enforce in-place operation.
pub fn enforce_inplace(&mut self, inplace: HashSet<(i32, i32)>) -> &mut OpSchema
pub fn enforce_one_to_one_inplace(&mut self) -> &mut OpSchema
sourcepub fn fill_using(
&mut self,
populator: fn(_u0: &mut OpSchema) -> c_void
) -> &mut OpSchema
pub fn fill_using( &mut self, populator: fn(_u0: &mut OpSchema) -> c_void ) -> &mut OpSchema
| Calls the passed function with this
as
| an argument. Useful for adding docs for
| templated/macro ops.
sourcepub fn num_inputs_from_set(
&mut self,
allowed_input_nums: HashSet<i32>
) -> &mut OpSchema
pub fn num_inputs_from_set( &mut self, allowed_input_nums: HashSet<i32> ) -> &mut OpSchema
| ———– | @brief | | Input could be one of the values specified | in allowed_input_nums. |
sourcepub fn num_outputs_bounded(&mut self, min: i32, max: i32) -> &mut OpSchema
pub fn num_outputs_bounded(&mut self, min: i32, max: i32) -> &mut OpSchema
| ———– | @brief | | Output could be in range [min, max], | inclusive. |
sourcepub fn num_outputs_fixed(&mut self, n: i32) -> &mut OpSchema
pub fn num_outputs_fixed(&mut self, n: i32) -> &mut OpSchema
| ———– | @brief | | A single output. | | Sets the number of outputs, either a | fixed number, a min and a max, or a function | that takes in the input number and produces | an output number. | | Use only one function in the set below. |
sourcepub fn num_outputs_from_set(
&mut self,
allowed_output_nums: HashSet<i32>
) -> &mut OpSchema
pub fn num_outputs_from_set( &mut self, allowed_output_nums: HashSet<i32> ) -> &mut OpSchema
| ———– | @brief | | Output could be one of the values specified | in allowed_output_nums. |
sourcepub fn same_number_of_output(&mut self) -> &mut OpSchema
pub fn same_number_of_output(&mut self) -> &mut OpSchema
| ———– | @brief | | Set the number of outputs to be the same | as the number of inputs. |
pub fn input( &mut self, n: i32, name: *const u8, description: *const u8 ) -> &mut OpSchema
pub fn output( &mut self, n: i32, name: *const u8, description: *const u8 ) -> &mut OpSchema
sourcepub fn calculate_output(&self, num_input: i32) -> i32
pub fn calculate_output(&self, num_input: i32) -> i32
| ———– | @brief | | A function to allow one to get the number | of outputs based on the number of inputs, | if this schema supports it. |
pub fn sparse_lengths_filler_helper( &mut self, shapes: &Vec<Vec<i64>>, value_index: usize, length_index: usize, fillers: *mut Vec<TensorFiller> )
pub fn sparse_weights_filler_helper( &mut self, shapes: &Vec<Vec<i64>>, weight_index: usize, fillers: *mut Vec<TensorFiller> )
pub fn sparse_segments_filler_helper( &mut self, shapes: &Vec<Vec<i64>>, value_index: usize, segment_index: usize, fillers: *mut Vec<TensorFiller> )
sourcepub fn value_key_length_input_fillers(
&mut self,
value_index: usize,
key_index: usize,
length_index: usize
) -> &mut OpSchema
pub fn value_key_length_input_fillers( &mut self, value_index: usize, key_index: usize, length_index: usize ) -> &mut OpSchema
| The helper is build sparse input with | values, keys, weights and lengths; | | e.g.: | values = [1, 2, 3, 2, 4, 6, 7, 3, 6] | keys = [0, 1, 4, 0, 1, 2, 5, 1, 2] | _/ ___/ _/ | lengths = [3, 4, 2]
sourcepub fn weighted_value_key_length_input_fillers(
&mut self,
value_index: usize,
key_index: usize,
length_index: usize,
weight_index: usize
) -> &mut OpSchema
pub fn weighted_value_key_length_input_fillers( &mut self, value_index: usize, key_index: usize, length_index: usize, weight_index: usize ) -> &mut OpSchema
| The helper is build sparse input with | values, keys, weights and lengths; | | e.g.: | values = [1, 2, 3, 2, 4, 6, 7, 3, 6] | keys = [0, 1, 4, 0, 1, 2, 5, 1, 2] | weights = [1, 1, 1, 0, 2, 2, 2, 1, 2] | _/ ___/ _/ | lengths = [3, 4, 2]
sourcepub fn value_length_input_fillers(
&mut self,
value_index: usize,
length_index: usize
) -> &mut OpSchema
pub fn value_length_input_fillers( &mut self, value_index: usize, length_index: usize ) -> &mut OpSchema
| The helper is build sparse input with | values and lengths; e.g.: | | values = [1, 2, 3, 2, 4, 6, 7, 3, 6] | _/ ___/ _/ | lengths = [3, 4, 2]
pub fn disallow_input_fillers(&mut self) -> &mut OpSchema
pub fn input_fillers(&self, shapes: &Vec<Vec<i64>>) -> Vec<TensorFiller>
pub fn supply_dense_fillers( &mut self, shapes: &Vec<Vec<i64>> ) -> Vec<TensorFiller>
pub fn new(ty: &String, file: &String, line: i32) -> Self
sourcepub fn file(&self) -> &String
pub fn file(&self) -> &String
| ———– | @brief | | Returns the file that the op schema is | registered from. |
sourcepub fn line(&self) -> i32
pub fn line(&self) -> i32
| ———– | @brief | | Returns the line in file that the op schema | is registered from. |
sourcepub fn inherit_onnx_schema_default(&mut self) -> &mut OpSchema
pub fn inherit_onnx_schema_default(&mut self) -> &mut OpSchema
| ———– | @brief | | Shortcut to InheritOnnxSchema(type_) |
sourcepub fn infer_tensor(
&self,
def: &OperatorDef,
input_type_shape: &Vec<TensorShape>
) -> Vec<TensorShape>
pub fn infer_tensor( &self, def: &OperatorDef, input_type_shape: &Vec<TensorShape> ) -> Vec<TensorShape>
| ———– | @brief | | A function to allow one to infer the type | and shape from the op schema. |
sourcepub fn verify(&self, def: &OperatorDef) -> bool
pub fn verify(&self, def: &OperatorDef) -> bool
| ———– | @brief | | Verifies if an operator definition | protobuf matches the pattern specified | in the schema. |
sourcepub fn num_inputs_bounded(&mut self, min: i32, max: i32) -> &mut OpSchema
pub fn num_inputs_bounded(&mut self, min: i32, max: i32) -> &mut OpSchema
| ———– | @brief | | Input could be in range [min, max], inclusive. |
sourcepub fn num_inputs_fixed(&mut self, n: i32) -> &mut OpSchema
pub fn num_inputs_fixed(&mut self, n: i32) -> &mut OpSchema
| ———– | @brief | | A single input. |
pub fn onnx_schema(&self) -> &String
pub fn min_input(&self) -> i32
pub fn max_input(&self) -> i32
pub fn min_output(&self) -> i32
pub fn max_output(&self) -> i32
pub fn num_inputs_allowed(&self, x: i32) -> bool
pub fn num_outputs_allowed(&self, x: i32) -> bool
pub fn num_inputs_outputs_allowed(&self, x: i32, y: i32) -> bool
pub fn inf(&self) -> i32
pub fn inplace_enforced(&self, x: i32, y: i32) -> bool
pub fn args(&self) -> &Vec<SchemaArgument>
pub fn private_op(&mut self) -> bool
pub fn can_inputs_cross_devices(&self) -> bool
sourcepub fn infer_device(
&self,
def: &OperatorDef
) -> (Vec<DeviceOption>, Vec<DeviceOption>)
pub fn infer_device( &self, def: &OperatorDef ) -> (Vec<DeviceOption>, Vec<DeviceOption>)
| ———– | @brief | | Infer required device location of an | op’s inputs and outputs |
sourcepub fn inputs_can_cross_devices(&mut self) -> &mut OpSchema
pub fn inputs_can_cross_devices(&mut self) -> &mut OpSchema
This op can pass data across devices
sourcepub fn tensor_inference_function(
&mut self,
function: TensorInferenceFunctionType
) -> &mut OpSchema
pub fn tensor_inference_function( &mut self, function: TensorInferenceFunctionType ) -> &mut OpSchema
| Functions to deal with type and shape | inference. Basically, this registers | a function that takes in an OperatorDef | and a series of input type and shape specified | by | | TensorProto objects (whose data fields | are empty), and produces a series of | output type and shape. |
| ———– | @brief | | Sets the tensor inference function, | which is a std::function object defined | in operator_schema.h. |
sourcepub fn needs_all_input_shapes(
f: TensorInferenceFunctionType
) -> TensorInferenceFunctionType
pub fn needs_all_input_shapes( f: TensorInferenceFunctionType ) -> TensorInferenceFunctionType
| A wrapper that makes an infer tensor | function to return unknown shape for | all outputs if any one of the inputs has | unknown shape |
sourcepub fn inherit_onnx_schema(
&mut self,
onnx_schema_name: &String
) -> &mut OpSchema
pub fn inherit_onnx_schema( &mut self, onnx_schema_name: &String ) -> &mut OpSchema
| ———– | @brief | | Sets the corresponding onnx schema | name |
sourcepub fn identical_type_and_shape(&mut self) -> &mut OpSchema
pub fn identical_type_and_shape(&mut self) -> &mut OpSchema
| ———– | @brief | | Sets the tensor inference function | to produce the same output as the input. |
pub fn identical_type_and_shape_of_input(&mut self, idx: i32) -> &mut OpSchema
pub fn identical_type_and_shape_of_multiple_inputs( &mut self, indices: &Vec<i32> ) -> &mut OpSchema
pub fn identical_type_and_shape_of_input_dim( &mut self, idx: i32, dim: i32 ) -> &mut OpSchema
pub fn scalar_type(&mut self, dt: TensorProto_DataType) -> &mut OpSchema
sourcepub fn cost_inference_function(
&mut self,
function: CostInferenceFunctionType
) -> &mut OpSchema
pub fn cost_inference_function( &mut self, function: CostInferenceFunctionType ) -> &mut OpSchema
| ———– | @brief | | Register the Cost inference function. |
sourcepub fn device_inference_function(
&mut self,
function: DeviceInferenceFunctionType
) -> &mut OpSchema
pub fn device_inference_function( &mut self, function: DeviceInferenceFunctionType ) -> &mut OpSchema
| ———– | @brief | | Returns the required device location | of inputs and outputs. |
sourcepub fn set_doc(&mut self, doc: &String) -> &mut OpSchema
pub fn set_doc(&mut self, doc: &String) -> &mut OpSchema
| Functions to do documentation for the | operator schema. |
pub fn arg( &mut self, name: *const u8, description: *const u8, required: Option<bool> ) -> &mut OpSchema
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for OpSchema
impl !Send for OpSchema
impl !Sync for OpSchema
impl Unpin for OpSchema
impl UnwindSafe for OpSchema
Blanket Implementations§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.