ML functions
 
Loading...
Searching...
No Matches
Relu Class Reference

A class that implements the Rectified Linear Unit (ReLU) activation function, inheriting from MLFunction. More...

#include <functions.h>

Inheritance diagram for Relu:
MLFunction

Public Member Functions

 Relu ()
 Default constructor.
 
void apply (const SelectivityVector &rows, std::vector< VectorPtr > &args, const TypePtr &type, exec::EvalCtx &context, VectorPtr &output) const override
 Applies the ReLU function to the input array.
 
float * getTensor () const override
 Returns the tensor associated with this function.
 
std::string getFuncName ()
 Returns the name of the function.
 
CostEstimate getCost (std::vector< int > inputDims)
 Estimates the computational cost of applying the ReLU function.
 
- Public Member Functions inherited from MLFunction
virtual ~MLFunction ()=default
 Virtual destructor.
 
virtual std::vector< int > getDims ()
 Returns the dimensions of the function.
 
virtual int getNumDims ()
 Returns the number of dimensions of the function.
 

Static Public Member Functions

static float reluFunction (float x)
 Computes the ReLU function for a single input value.
 
static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures ()
 Returns the function signatures supported by this class.
 
static std::string getName ()
 Static method to return the name of the function.
 

Additional Inherited Members

- Protected Member Functions inherited from MLFunction
double getWeightedCost (std::string name, float cost)
 Calculates the weighted cost of the function.
 
std::vector< double > getCoefficientVector (std::string name)
 Retrieves the cost coefficients for the function.
 
- Protected Attributes inherited from MLFunction
std::vector< int > dims
 Dimensions of the function.
 

Detailed Description

A class that implements the Rectified Linear Unit (ReLU) activation function, inheriting from MLFunction.

The ReLU function returns the input value if it is positive; otherwise, it returns 0. This class provides functionality to apply the ReLU function element-wise to an input array and produce an output array.

Member Function Documentation

◆ apply()

void Relu::apply ( const SelectivityVector & rows,
std::vector< VectorPtr > & args,
const TypePtr & type,
exec::EvalCtx & context,
VectorPtr & output ) const
inlineoverride

Applies the ReLU function to the input array.

This method processes the input array, applies the ReLU function element-wise, and stores the result in the output vector.

Parameters
rowsA SelectivityVector specifying the rows to process.
argsA vector of input arguments (e.g., the input array).
typeThe type of the output vector.
contextThe execution context.
outputThe output vector where the result will be stored.

◆ getCost()

CostEstimate Relu::getCost ( std::vector< int > inputDims)
inlinevirtual

Estimates the computational cost of applying the ReLU function.

Parameters
inputDimsA vector containing the dimensions of the input.
Returns
A CostEstimate object representing the estimated cost.

Reimplemented from MLFunction.

◆ getFuncName()

std::string Relu::getFuncName ( )
inlinevirtual

Returns the name of the function.

Returns
The name of the function as a string.

Reimplemented from MLFunction.

◆ getName()

static std::string Relu::getName ( )
inlinestatic

Static method to return the name of the function.

Returns
The name of the function as a string ("relu").

◆ getTensor()

float * Relu::getTensor ( ) const
inlineoverridevirtual

Returns the tensor associated with this function.

Returns
A pointer to an empty float array (no weights for ReLU).

Implements MLFunction.

◆ reluFunction()

static float Relu::reluFunction ( float x)
inlinestatic

Computes the ReLU function for a single input value.

Parameters
xThe input value.
Returns
The result of the ReLU function: max(0, x).

◆ signatures()

static std::vector< std::shared_ptr< exec::FunctionSignature > > Relu::signatures ( )
inlinestatic

Returns the function signatures supported by this class.

Returns
A vector of shared pointers to FunctionSignature objects.

The documentation for this class was generated from the following file: