ML functions
 
Loading...
Searching...
No Matches
UtilFunction.h File Reference

Implementation of utility functions and classes for machine learning tasks. More...

#include <Eigen/Dense>
#include <cmath>
#include <filesystem>
#include <iostream>
#include "BaseFunction.h"
#include "velox/exec/tests/utils/AssertQueryBuilder.h"
#include "velox/exec/tests/utils/PlanBuilder.h"
#include "velox/exec/tests/utils/TempDirectoryPath.h"
#include "velox/vector/tests/utils/VectorTestBase.h"

Go to the source code of this file.

Classes

class  ChangeRating
 Implements a function to change ratings to binary values. More...
 
class  ConvertToIntArray
 Implements a function to convert an integer vector to an integer array. More...
 
class  ConvertToFloatArray
 Implements a function to convert a float vector to a float array. More...
 
class  ConvertDoubleToFloatArray
 Implements a function to convert a double vector to a float array. More...
 
class  ConvertDoubleArrayToFloatArray
 Implements a function to convert a double array to a float array. More...
 

Functions

std::string LoadBytesFromFile (const std::string &path)
 Loads bytes from a file into a string.
 
bool stringToBool (const std::string &str)
 Converts a string to a boolean value.
 
std::string getEnvVar (std::string const &key)
 Retrieves the value of an environment variable.
 
void readDataStats (const std::string &path, int &numRows, int &numCols)
 Reads the number of rows and columns from a data statistics file.
 
template<typename T>
T * flattenVectorToPointer (const std::vector< std::vector< T > > &vec2D, size_t &totalSize)
 Flattens a 2D vector into a 1D array.
 
template<typename T>
T * flattenVectorToPointer (const std::vector< std::vector< T > > &vec2D)
 Flattens a 2D vector into a 1D array (overloaded version without totalSize).
 
int countWords (const std::string &input)
 Counts the number of words in a string.
 

Detailed Description

Implementation of utility functions and classes for machine learning tasks.

Function Documentation

◆ countWords()

int countWords ( const std::string & input)

Counts the number of words in a string.

Parameters
inputThe input string.
Returns
The number of words in the string.

◆ flattenVectorToPointer() [1/2]

template<typename T>
T * flattenVectorToPointer ( const std::vector< std::vector< T > > & vec2D)

Flattens a 2D vector into a 1D array (overloaded version without totalSize).

Template Parameters
TThe type of elements in the vector.
Parameters
vec2DThe 2D vector to flatten.
Returns
A pointer to the flattened array.

◆ flattenVectorToPointer() [2/2]

template<typename T>
T * flattenVectorToPointer ( const std::vector< std::vector< T > > & vec2D,
size_t & totalSize )

Flattens a 2D vector into a 1D array.

Template Parameters
TThe type of elements in the vector.
Parameters
vec2DThe 2D vector to flatten.
totalSizeReference to store the total size of the flattened array.
Returns
A pointer to the flattened array.

◆ getEnvVar()

std::string getEnvVar ( std::string const & key)

Retrieves the value of an environment variable.

Parameters
keyThe name of the environment variable.
Returns
The value of the environment variable, or an empty string if not found.

◆ LoadBytesFromFile()

std::string LoadBytesFromFile ( const std::string & path)

Loads bytes from a file into a string.

Parameters
pathPath to the file.
Returns
A string containing the file's contents.

◆ readDataStats()

void readDataStats ( const std::string & path,
int & numRows,
int & numCols )

Reads the number of rows and columns from a data statistics file.

Parameters
pathPath to the data statistics file.
numRowsReference to store the number of rows.
numColsReference to store the number of columns.

◆ stringToBool()

bool stringToBool ( const std::string & str)

Converts a string to a boolean value.

Parameters
strThe string to convert.
Returns
The boolean value corresponding to the string.