Skip to content
Snippets Groups Projects
Commit e2645a56 authored by Jakhes's avatar Jakhes
Browse files

Adding new helper functions for more convertion types

parent 2950f7b1
No related branches found
No related tags found
No related merge requests found
#include "helper.hpp"
// adding some testing to the functions
// Extra functions to reduce some code for the conversion between arma and float *array
float *convertToArray(colvec vec)
......@@ -24,12 +26,39 @@ float *convertToArray(rowvec vec)
return convertToArray(newVec);
}
float *convertToArray(mat matrix)
{
vec vector = matrix.as_col();
return convertToArray(vector);
}
float *convertToArray(vector<size_t> vec)
{
colvec newVec = conv_to<colvec>::from(vec);
return convertToArray(newVec);
}
float *convertToArray(vector<double> vec)
{
colvec newVec = conv_to<colvec>::from(vec);
return convertToArray(newVec);
}
float *convertToArray(vector<vec> matrix)
{
vec newVec = matrix[0];
for (size_t i = 1; i < matrix.size(); i++)
{
vec a = newVec;
vec b = matrix[i];
vec c = arma::join_cols(a, b);
newVec = c;
}
cout << newVec << endl;
return convertToArray(newVec);
}
rowvec convertArrayToRowvec(float *arr, int vecSize)
{
rowvec rVector(vecSize);
......
......@@ -15,6 +15,10 @@ float *convertToArray(mat matrix);
float *convertToArray(vector<size_t> vec);
float *convertToArray(vector<double> vec);
float *convertToArray(vector<vec> vec);
rowvec convertArrayToRowvec(float *arr, int vecSize);
......
:- module(helper, [convert_list_to_float_array/3, convert_list_to_float_array/2, fill_float_array/3, convert_float_array_to_list/3 , convert_float_array_to_list/4, len/2, convert_record_to_arr/2, take_csv_row/1]).
:- module(helper, [convert_list_to_float_array/3, convert_list_to_float_array/2, convert_float_array_to_list/3, len/2, convert_record_to_arr/2, take_csv_row/1, convert_float_array_to_2d_list/4]).
:- use_module(library(structs)).
:- use_module(library(csv)).
%% TODO: update Comment docs
%% TODO: test the helper predicate
%% Functions for editing float arrays
......@@ -25,6 +27,7 @@ fill_float_array([H|Tail], Index, Mem) :-
New_index is Index + 1,
fill_float_array(Tail, New_index, Mem).
%% takes library(struct) array and fills a [] with the content of the array from 0 to to given Index
convert_float_array_to_list(Mem, Count, Out) :-
convert_float_array_to_list(Mem, 0, Count, Out).
......@@ -35,6 +38,22 @@ convert_float_array_to_list(Mem, Index, Count, [Val|Rest]) :-
convert_float_array_to_list(Mem, NewIndex, Count, Rest),
get_contents(Mem, Index , Val).
%% takes library(struct) array and fills a 2D [[a], [b]] with the content of the array from 0 to to given Index
convert_float_array_to_2d_list(Mem, ColNum, RowNum, Out) :-
convert_float_array_to_2d_list(Mem, ColNum, RowNum, 0, Out).
convert_float_array_to_2d_list(_, _, RowNum, RowNum, []) :- !.
convert_float_array_to_2d_list(Mem, ColNum, RowNum, RowCount, [Val | Rest]) :-
NewRowCount is RowCount + 1,
StartIndex is RowCount * ColNum,
EndIndex is (NewRowCount * ColNum),
convert_float_array_to_list(Mem, StartIndex, EndIndex, Val),
convert_float_array_to_2d_list(Mem, ColNum, RowNum, NewRowCount, Rest).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment