FastDeploy  latest
Fast & Easy to Deploy!
Functions
fastdeploy::function Namespace Reference

All C++ FDTensor Operation APIs are defined inside this namespace. More...

Functions

void Cast (const FDTensor &x, FDTensor *out, FDDataType output_dtype)
 
void Clip (const FDTensor &x, double min, double max, FDTensor *out)
 
void Concat (const std::vector< FDTensor > &x, FDTensor *out, int axis)
 
FASTDEPLOY_DECL void CudaCast (const FDTensor &in, FDTensor *out, cudaStream_t stream)
 
void Cumprod (const FDTensor &x, FDTensor *out, int axis)
 
void Add (const FDTensor &x, const FDTensor &y, FDTensor *out)
 
void Subtract (const FDTensor &x, const FDTensor &y, FDTensor *out)
 
void Multiply (const FDTensor &x, const FDTensor &y, FDTensor *out)
 
void Divide (const FDTensor &x, const FDTensor &y, FDTensor *out)
 
void Maximum (const FDTensor &x, const FDTensor &y, FDTensor *out)
 
void Full (const Scalar &value, const std::vector< int64_t > &shape, FDTensor *out, FDDataType dtype)
 
void FullLike (const FDTensor &x, const Scalar &value, FDTensor *out, FDDataType dtype)
 
void GatherAlongAxis (const FDTensor &x, const FDTensor &index, FDTensor *result, int axis)
 
void GaussianRandom (const std::vector< int64_t > &shape, FDTensor *out, FDDataType dtype, float mean, float std, int seed)
 
void IsNan (const FDTensor &x, FDTensor *out, FDDataType dtype)
 
void IsInf (const FDTensor &x, FDTensor *out, FDDataType dtype)
 
void IsFinite (const FDTensor &x, FDTensor *out, FDDataType dtype)
 
void Linspace (double start, double end, int num, FDTensor *out, FDDataType dtype)
 
void Sqrt (const FDTensor &x, FDTensor *out)
 
void Log (const FDTensor &x, FDTensor *out)
 
void Round (const FDTensor &x, FDTensor *out)
 
void Exp (const FDTensor &x, FDTensor *out)
 
void Abs (const FDTensor &x, FDTensor *out)
 
void Ceil (const FDTensor &x, FDTensor *out)
 
void Floor (const FDTensor &x, FDTensor *out)
 
void Pad (const FDTensor &x, FDTensor *out, const std::vector< int > &pads, float value)
 
void Quantile (const FDTensor &x, const std::vector< double > &q, const std::vector< int > &axis, FDTensor *out)
 
void Max (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void Min (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void Sum (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void All (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void Any (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void Mean (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void Prod (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims, bool keep_dim, bool reduce_all)
 
void ArgMax (const FDTensor &x, FDTensor *out, int64_t axis, FDDataType output_dtype, bool keep_dim, bool flatten)
 
void ArgMin (const FDTensor &x, FDTensor *out, int64_t axis, FDDataType output_dtype, bool keep_dim, bool flatten)
 
void Slice (const FDTensor &x, const std::vector< int64_t > &axes, const std::vector< int64_t > &starts, const std::vector< int64_t > &ends, FDTensor *out)
 
void Softmax (const FDTensor &x, FDTensor *out, int axis)
 
void Sort (const FDTensor &x, FDTensor *out, FDTensor *indices, int axis=0, bool descending=false, FDDataType indices_type=FDDataType::INT64)
 Performs sorting on the input tensor along the given axis and outputs two tensors, Output(Out) and Output(Indices). They reserve the same shape with Input(X), and Output(Out) represents the sorted tensor while Output(Indices) gives the sorted order along the given axis Attr(axis). More...
 
void Split (const FDTensor &x, const std::vector< int > &num_or_sections, std::vector< FDTensor > *out, int axis)
 
void Tile (const FDTensor &x, const std::vector< int64_t > &repeat_times, FDTensor *out)
 
void Transpose (const FDTensor &x, FDTensor *out, const std::vector< int64_t > &dims)
 

Detailed Description

All C++ FDTensor Operation APIs are defined inside this namespace.

Function Documentation

◆ Abs()

FASTDEPLOY_DECL void fastdeploy::function::Abs ( const FDTensor x,
FDTensor out 
)

This operator is used to perform elementwise abs for input X. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Add()

FASTDEPLOY_DECL void fastdeploy::function::Add ( const FDTensor x,
const FDTensor y,
FDTensor out 
)

Excute the add operation for input FDTensors. *out = x + y.

Parameters
xThe input tensor.
yThe input tensor.
outThe output tensor which stores the result.

◆ All()

FASTDEPLOY_DECL void fastdeploy::function::All ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the all operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ Any()

FASTDEPLOY_DECL void fastdeploy::function::Any ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the any operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ ArgMax()

FASTDEPLOY_DECL void fastdeploy::function::ArgMax ( const FDTensor x,
FDTensor out,
int64_t  axis,
FDDataType  output_dtype = FDDataType::INT64,
bool  keep_dim = false,
bool  flatten = false 
)

Excute the argmax operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
axisThe axis which will be reduced.
output_dtypeThe data type of output FDTensor, INT64 or INT32, default to INT64.
keep_dimWhether to keep the reduced dims, default false.
flattenWhether to flatten FDTensor to get the argmin index, default false.

◆ ArgMin()

FASTDEPLOY_DECL void fastdeploy::function::ArgMin ( const FDTensor x,
FDTensor out,
int64_t  axis,
FDDataType  output_dtype = FDDataType::INT64,
bool  keep_dim = false,
bool  flatten = false 
)

Excute the argmin operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
axisThe axis which will be reduced.
output_dtypeThe data type of output FDTensor, INT64 or INT32, default to INT64.
keep_dimWhether to keep the reduced dims, default false.
flattenWhether to flatten FDTensor to get the argmin index, default false.

◆ Cast()

FASTDEPLOY_DECL void fastdeploy::function::Cast ( const FDTensor x,
FDTensor out,
FDDataType  output_dtype 
)

Cast x to output data type element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.
output_dtypeThe type of output tensor.

◆ Ceil()

FASTDEPLOY_DECL void fastdeploy::function::Ceil ( const FDTensor x,
FDTensor out 
)

Computes ceil of x element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Clip()

FASTDEPLOY_DECL void fastdeploy::function::Clip ( const FDTensor x,
double  min,
double  max,
FDTensor out 
)

This operator clip all elements in input into the range [ min, max ]. Support float32, float64, int32, int64

Parameters
xThe input tensor.
minThe lower bound
maxThe uppper bound
outThe output tensor which stores the result.

◆ Concat()

FASTDEPLOY_DECL void fastdeploy::function::Concat ( const std::vector< FDTensor > &  x,
FDTensor out,
int  axis = 0 
)

Excute the concatenate operation for input FDTensor along given axis.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
axisAxis which will be concatenated.

◆ CudaCast()

FASTDEPLOY_DECL void fastdeploy::function::CudaCast ( const FDTensor in,
FDTensor out,
cudaStream_t  stream 
)

Cast the type of the data in GPU buffer.

Parameters
inThe input tensor.
outThe output tensor
streamCUDA stream

◆ Cumprod()

FASTDEPLOY_DECL void fastdeploy::function::Cumprod ( const FDTensor x,
FDTensor out,
int  axis = 0 
)

Excute the concatenate operation for input FDTensor along given axis.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
axisiAxis which will be concatenated.

◆ Divide()

FASTDEPLOY_DECL void fastdeploy::function::Divide ( const FDTensor x,
const FDTensor y,
FDTensor out 
)

Excute the divide operation for input FDTensors. *out = x / y.

Parameters
xThe input tensor.
yThe input tensor.
outThe output tensor which stores the result.

◆ Exp()

FASTDEPLOY_DECL void fastdeploy::function::Exp ( const FDTensor x,
FDTensor out 
)

Computes exp of x element-wise with a natural number e as the base, element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Floor()

FASTDEPLOY_DECL void fastdeploy::function::Floor ( const FDTensor x,
FDTensor out 
)

Computes floor of x element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Full()

FASTDEPLOY_DECL void fastdeploy::function::Full ( const Scalar &  value,
const std::vector< int64_t > &  shape,
FDTensor out,
FDDataType  dtype = FDDataType::FP32 
)

Fill the value to tensor

Parameters
valueThe value to be filled in tensor
shapeThe shape of output tensor.
outThe output tensor which stores the result.
dtypeThe data type of output tensor. Default to float32

◆ FullLike()

FASTDEPLOY_DECL void fastdeploy::function::FullLike ( const FDTensor x,
const Scalar &  value,
FDTensor out,
FDDataType  dtype = FDDataType::FP32 
)

Fill the value to tensor

Parameters
xThe input tensor.
valueThe value to be filled in tensor
outThe output tensor which stores the result.
dtypeThe data type of output tensor. Default to float32

◆ GatherAlongAxis()

FASTDEPLOY_DECL void fastdeploy::function::GatherAlongAxis ( const FDTensor x,
const FDTensor index,
FDTensor result,
int  axis 
)

Output is obtained by gathering entries of axis of x indexed by index and concatenate them together.

Parameters
xThe input tensor.
indexThe index of a tensor to gather.
outThe output tensor which stores the result.
axisAxis which will be gathered.

◆ GaussianRandom()

void fastdeploy::function::GaussianRandom ( const std::vector< int64_t > &  shape,
FDTensor out,
FDDataType  dtype = FDDataType::FP32,
float  mean = 0.0f,
float  std = 1.0f,
int  seed = 0 
)

Output is obtained by gathering entries of axis of x indexed by index and concatenate them together.

Parameters
shapeThe output tensor shape.
outthe output tensor.
meanmean value of gaussian random
stdstandard value of gaussian random
seedThe seed of random generator.
dtypeThe data type of the output Tensor.

◆ IsFinite()

FASTDEPLOY_DECL void fastdeploy::function::IsFinite ( const FDTensor x,
FDTensor out,
FDDataType  dtype = FDDataType::BOOL 
)

Return whether every element of input tensor is finite or not.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dtypeThe output data type

◆ IsInf()

FASTDEPLOY_DECL void fastdeploy::function::IsInf ( const FDTensor x,
FDTensor out,
FDDataType  dtype = FDDataType::BOOL 
)

Return whether every element of input tensor is Inf or not.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dtypeThe output data type

◆ IsNan()

FASTDEPLOY_DECL void fastdeploy::function::IsNan ( const FDTensor x,
FDTensor out,
FDDataType  dtype = FDDataType::BOOL 
)

Return whether every element of input tensor is NaN or not.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dtypeThe output data type

◆ Linspace()

FASTDEPLOY_DECL void fastdeploy::function::Linspace ( double  start,
double  end,
int  num,
FDTensor out,
FDDataType  dtype = FDDataType::FP32 
)

Return fixed number of evenly spaced values within a given interval.

Parameters
startThe input start is start variable of range.
endThe input stop is start variable of range.
numThe input num is given num of the sequence.
outThe output tensor which stores the result.
dtypeThe data type of output tensor, default to float32.

◆ Log()

FASTDEPLOY_DECL void fastdeploy::function::Log ( const FDTensor x,
FDTensor out 
)

Calculates the natural log of the given input Tensor, element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Max()

FASTDEPLOY_DECL void fastdeploy::function::Max ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the maximum operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ Maximum()

FASTDEPLOY_DECL void fastdeploy::function::Maximum ( const FDTensor x,
const FDTensor y,
FDTensor out 
)

Excute the maximum operation for input FDTensors. *out = max(x, y).

Parameters
xThe input tensor.
yThe input tensor.
outThe output tensor which stores the result.

◆ Mean()

FASTDEPLOY_DECL void fastdeploy::function::Mean ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the mean operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ Min()

FASTDEPLOY_DECL void fastdeploy::function::Min ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the minimum operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ Multiply()

FASTDEPLOY_DECL void fastdeploy::function::Multiply ( const FDTensor x,
const FDTensor y,
FDTensor out 
)

Excute the multiply operation for input FDTensors. *out = x * y.

Parameters
xThe input tensor.
yThe input tensor.
outThe output tensor which stores the result.

◆ Pad()

FASTDEPLOY_DECL void fastdeploy::function::Pad ( const FDTensor x,
FDTensor out,
const std::vector< int > &  pads,
float  pad_value = 0 
)

Excute the pad operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
padsThe size of padding for each dimension, for 3-D tensor, the pads should be [1d-left, 1d-right, 2d-left, 2d-right, 3d-left, 3d-right]
pad_valueThe value which will fill into out tensor

◆ Prod()

FASTDEPLOY_DECL void fastdeploy::function::Prod ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the product operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ Quantile()

FASTDEPLOY_DECL void fastdeploy::function::Quantile ( const FDTensor x,
const std::vector< double > &  q,
const std::vector< int > &  axis,
FDTensor out 
)

Compute the quantile of the input along the specified axis. If any values in a reduced row are NaN, then the quantiles for that reduction will be NaN.

Parameters
xThe input tensor.
qThe q for calculate quantile, which should be in range [0, 1].
axisThe axis along which to calculate quantile. axis should be int or list of int.
outThe output tensor which stores the result.

◆ Round()

FASTDEPLOY_DECL void fastdeploy::function::Round ( const FDTensor x,
FDTensor out 
)

Rounds the values in the input to the nearest integer value, element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Slice()

FASTDEPLOY_DECL void fastdeploy::function::Slice ( const FDTensor x,
const std::vector< int64_t > &  axes,
const std::vector< int64_t > &  starts,
const std::vector< int64_t > &  ends,
FDTensor out 
)

This operator produces a slice of input along multiple axes.

Parameters
xThe input tensor.
axesAxes that starts and ends apply to.
startsIf starts is a list or tuple, the elements of it should be integers or Tensors with shape [1]. If starts is an Tensor, it should be an 1-D Tensor. It represents starting indices of corresponding axis in axes
endsIf ends is a list or tuple, the elements of it should be integers or Tensors with shape [1]. If ends is an Tensor, it should be an 1-D Tensor . It represents ending indices of corresponding axis in axes.
outThe output tensor which stores the result.

◆ Softmax()

FASTDEPLOY_DECL void fastdeploy::function::Softmax ( const FDTensor x,
FDTensor out,
int  axis = -1 
)

Excute the softmax operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
axisThe axis to be computed softmax value.

◆ Sort()

FASTDEPLOY_DECL void fastdeploy::function::Sort ( const FDTensor x,
FDTensor out,
FDTensor indices,
int  axis = 0,
bool  descending = false,
FDDataType  indices_type = FDDataType::INT64 
)

Performs sorting on the input tensor along the given axis and outputs two tensors, Output(Out) and Output(Indices). They reserve the same shape with Input(X), and Output(Out) represents the sorted tensor while Output(Indices) gives the sorted order along the given axis Attr(axis).

Parameters
xThe input of sort
outThe sorted tensor of sort op, with the same shape as x
indicesThe indices of a tensor giving the sorted order, with the same shape as x
axisThe axis along which to sort the tensor. When axis < 0, the actual axis will be the |axis|'th counting backwards
descendingThe descending attribute is a flag to tell algorithm how to sort the input data. If descending is true, will sort by descending order, else if false, sort by ascending order
indices_typeThe data type of indices, default to int64

◆ Split()

FASTDEPLOY_DECL void fastdeploy::function::Split ( const FDTensor x,
const std::vector< int > &  num_or_sections,
std::vector< FDTensor > *  out,
int  axis = 0 
)

Split the input tensor into multiple sub-Tensors.

Parameters
xThe input tensor.
num_or_sectionsf num_or_sections is an int, then num_or_sections indicates the number of equal sized sub-Tensors that the x will be divided into.
outThe output vector tensor which stores the result.
axisAxis which will be splitted.

◆ Sqrt()

FASTDEPLOY_DECL void fastdeploy::function::Sqrt ( const FDTensor x,
FDTensor out 
)

Calculates the sqrt of the given input Tensor, element-wise. Only for float type FDTensor

Parameters
xThe input tensor.
outThe output tensor which stores the result.

◆ Subtract()

FASTDEPLOY_DECL void fastdeploy::function::Subtract ( const FDTensor x,
const FDTensor y,
FDTensor out 
)

Excute the subtract operation for input FDTensors. *out = x - y.

Parameters
xThe input tensor.
yThe input tensor.
outThe output tensor which stores the result.

◆ Sum()

FASTDEPLOY_DECL void fastdeploy::function::Sum ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims,
bool  keep_dim = false,
bool  reduce_all = false 
)

Excute the sum operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which will be reduced.
keep_dimWhether to keep the reduced dims, default false.
reduce_allWhether to reduce all dims, default false.

◆ Tile()

FASTDEPLOY_DECL void fastdeploy::function::Tile ( const FDTensor x,
const std::vector< int64_t > &  repeat_times,
FDTensor out 
)

Construct a new Tensor by repeating x the number of times given by repeat_times. After tiling, the value of the i’th dimension of the output is equal to x.shape[i]*repeat_times[i]. Both the number of dimensions of x and the number of elements in repeat_times should be less than or equal to 6.Support all data types.

Parameters
xThe input tensor.
repeat_timesThe lower bound
outThe output tensor which stores the result.

◆ Transpose()

FASTDEPLOY_DECL void fastdeploy::function::Transpose ( const FDTensor x,
FDTensor out,
const std::vector< int64_t > &  dims 
)

Excute the transpose operation for input FDTensor along given dims.

Parameters
xThe input tensor.
outThe output tensor which stores the result.
dimsThe vector of axis which the input tensor will transpose.