UtilsData
-
namespace utilsdata
Functions
-
static inline void printVector(vector<double> &vecData)
Print a 1D vector of doubles.
- Parameters:
vecData – Vector to print.
-
static inline void print2DMatrix(vector<vector<double>> matrix2D)
Print a 2D matrix of doubles.
- Parameters:
matrix2D – Matrix to print.
-
static inline void print3DMatrix(vector<vector<vector<double>>> matrix3D)
Print a 3D matrix of doubles.
- Parameters:
matrix3D – Matrix to print.
-
static inline vector<double> createVector(int cols, int minValue, int maxValue)
Create a 1D vector with random values.
- Parameters:
cols – Number of elements.
minValue – Minimum random value.
maxValue – Maximum random value.
- Returns:
Random vector of doubles.
-
static inline vector<vector<double>> create2DMatrix(int rows, int cols, int minValue, int maxValue)
Create a 2D matrix with random values.
- Parameters:
rows – Number of rows.
cols – Number of columns.
minValue – Minimum random value.
maxValue – Maximum random value.
- Returns:
Random 2D matrix.
-
static inline vector<vector<vector<double>>> create3DMatrix(int depth, int rows, int cols, int minValue, int maxValue)
Create a 3D matrix with random values.
- Parameters:
depth – Depth of matrix.
rows – Number of rows per slice.
cols – Number of columns per slice.
minValue – Minimum random value.
maxValue – Maximum random value.
- Returns:
Random 3D matrix.
-
static inline vector<double> flatten3DMatrix(const vector<vector<vector<double>>> matrix3D)
Flatten a 3D matrix into a 1D vector.
- Parameters:
matrix3D – Matrix to flatten.
- Returns:
Flattened vector.
-
static inline void printPtextVector(Plaintext packedVec)
Print a plaintext vector after decryption.
- Parameters:
packedVec – Plaintext vector to print.
-
static inline vector<double> generate_mixed_mask(int ones_width, int vector_size)
Generate a binary mask of ones followed by zeros.
- Parameters:
ones_width – Number of ones.
vector_size – Total size of mask.
- Returns:
Mask vector.
-
static inline vector<double> generate_scale_mask(int scale_value, int vector_size)
Generate a scaled mask with uniform values.
- Parameters:
scale_value – Scaling factor.
vector_size – Total size of mask.
- Returns:
Scaled mask vector.
-
static inline vector<double> generate_value_mask(double scale_value, int vector_size)
Generate a value mask with a fixed value.
- Parameters:
scale_value – Value to assign.
vector_size – Total size of mask.
- Returns:
Value mask vector.
-
static inline int greaterFunction(double x)
Approximate greater-than function for spiking.
- Parameters:
x – Input value.
- Returns:
Spike value if x > 0, else 0.
-
static inline double approximateGreaterFunction(double x)
Approximate smooth greater-than step function.
- Parameters:
x – Input value.
- Returns:
Smoothed spike value.
-
static inline double innerRelu(double x, double scale)
ReLU with scaling factor.
- Parameters:
x – Input value.
scale – Scaling factor.
- Returns:
ReLU output.
-
static inline vector<double> avgpoolFilter(int kernel_width)
Create an average pooling filter.
- Parameters:
kernel_width – Width of pooling kernel.
- Returns:
Averaging filter vector.
-
static inline int nextPowerOf2(unsigned int n)
Find the next power of 2.
- Parameters:
n – Input value.
- Returns:
Next power of 2.
-
static inline vector<vector<double>> loadCSV(const string &fileName)
Load numeric data from a CSV file.
Reads a CSV file and converts each value into double. Invalid values are replaced with 0.0.
- Parameters:
fileName – Path to the CSV file.
- Returns:
2D vector of doubles with CSV contents.
-
static inline vector<double> load_bias(string fileName)
Load bias values from a CSV file.
Extracts the first row of the CSV file as bias values.
- Parameters:
fileName – Path to the CSV file.
- Returns:
1D vector containing bias values.
-
static inline vector<vector<vector<vector<double>>>> load_weights(string fileName, int outputChannels, int inputChannels, int rowsWidth, int imgCols)
Load and reshape convolution weights from a CSV file.
Reads flat weight data and reshapes into a 4D structure: [outputChannels][inputChannels][rowsWidth][imgCols].
- Parameters:
fileName – Path to the CSV file.
outputChannels – Number of output channels.
inputChannels – Number of input channels.
rowsWidth – Number of rows in each kernel.
imgCols – Number of columns in each kernel.
- Returns:
4D vector containing reshaped weights.
-
static inline vector<vector<double>> load_fc_weights(string fileName, int outputChannels, int inputChannels)
Load and reshape fully connected layer weights.
Reads flat weight data and reshapes into 2D form: [outputChannels][inputChannels].
- Parameters:
fileName – Path to the CSV file.
outputChannels – Number of output neurons.
inputChannels – Number of input neurons.
- Returns:
2D vector containing reshaped weights.
-
static inline void write_to_file(string filename, string content)
Write text content to a file.
- Parameters:
filename – Path to the output file.
content – String content to write.
-
static inline string read_from_file(string filename)
Read the first line from a file.
Reads only the first line and returns it as a string.
- Parameters:
filename – Path to the input file.
- Returns:
First line from the file.
-
static inline vector<int> serialize_rotation_keys(vector<vector<int>> rotation_keys)
Flatten and deduplicate rotation keys.
Converts a 2D vector of rotation key sets into a unique, sorted 1D vector of non-zero rotation positions.
- Parameters:
rotation_keys – 2D vector of rotation positions.
- Returns:
Unique sorted list of rotation positions.
-
static inline void printVector(vector<double> &vecData)