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

A class that computes the cosine similarity between two input arrays, inheriting from MLFunction. More...

#include <CosineSimilarity.h>

Inheritance diagram for CosineSimilarity:
MLFunction

Public Member Functions

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

Static Public Member Functions

static std::vector< std::shared_ptr< exec::FunctionSignature > > signatures ()
 Returns the function signatures supported by this class.
 
static std::string getName ()
 Returns 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 computes the cosine similarity between two input arrays, inheriting from MLFunction.

This class provides functionality to calculate the cosine similarity between two arrays of real numbers (floats). Cosine similarity measures the cosine of the angle between two vectors, providing a value between -1 and 1.

Constructor & Destructor Documentation

◆ CosineSimilarity()

CosineSimilarity::CosineSimilarity ( int dim)
inline

Constructor that initializes the cosine similarity computation with the dimension of the input arrays.

Parameters
dimThe dimension (number of features) of the input arrays.

Member Function Documentation

◆ apply()

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

Applies the cosine similarity computation to the input arrays.

This method processes the input arrays, computes the cosine similarity between corresponding vectors, and stores the result in the output vector.

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

◆ getCost()

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

Estimates the computational cost of applying the cosine similarity computation.

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

Reimplemented from MLFunction.

◆ getName()

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

Returns the name of the function.

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

◆ getTensor()

float * CosineSimilarity::getTensor ( ) const
inlineoverridevirtual

Returns the tensor associated with this function.

Returns
A null pointer (no tensor is associated with this function).

Implements MLFunction.

◆ signatures()

static std::vector< std::shared_ptr< exec::FunctionSignature > > CosineSimilarity::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: