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

A class that implements a convolutional neural network (CNN) using PyTorch, inheriting from MLFunction. More...

#include <functions.h>

Inheritance diagram for TorchCNN:
MLFunction

Public Member Functions

 TorchCNN (float *weights, float *bias, int *dims_)
 Constructor that initializes the CNN with weights, biases, and dimensions.
 
void apply (const SelectivityVector &rows, std::vector< VectorPtr > &args, const TypePtr &type, exec::EvalCtx &context, VectorPtr &output) const override
 Applies the CNN to the input array using PyTorch.
 
float * getTensor () const override
 Returns the tensor associated with this function.
 
float * getWeights () const
 Returns the weights of the CNN.
 
float * getBias () const
 Returns the biases of the CNN.
 
std::string getFuncName ()
 Returns the name of the 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.
 
virtual CostEstimate getCost (std::vector< int > inputDims)
 Estimates the computational cost of applying 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 ()
 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 a convolutional neural network (CNN) using PyTorch, inheriting from MLFunction.

This class provides functionality to apply a CNN to an input array using PyTorch.

Constructor & Destructor Documentation

◆ TorchCNN()

TorchCNN::TorchCNN ( float * weights,
float * bias,
int * dims_ )
inline

Constructor that initializes the CNN with weights, biases, and dimensions.

Parameters
weightsA pointer to the weight matrix for the convolution.
biasA pointer to the bias vector for the convolution.
dims_An array containing the dimensions of the CNN.

Member Function Documentation

◆ apply()

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

Applies the CNN to the input array using PyTorch.

This method processes the input array, applies the CNN, 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.

◆ getBias()

float * TorchCNN::getBias ( ) const
inline

Returns the biases of the CNN.

Returns
A pointer to the bias vector.

◆ getFuncName()

std::string TorchCNN::getFuncName ( )
inlinevirtual

Returns the name of the function.

Returns
The name of the function as a string.

Reimplemented from MLFunction.

◆ getName()

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

Static method to return the name of the function.

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

◆ getTensor()

float * TorchCNN::getTensor ( ) const
inlineoverridevirtual

Returns the tensor associated with this function.

Returns
A pointer to the weight matrix for the convolution.

Implements MLFunction.

◆ getWeights()

float * TorchCNN::getWeights ( ) const
inline

Returns the weights of the CNN.

Returns
A pointer to the weight matrix.

◆ signatures()

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