From e2645a56c25e889b5032fe48af7ec35569d531be Mon Sep 17 00:00:00 2001
From: Jakhes <dean.schmitz@schmitzbauer.de>
Date: Wed, 7 Sep 2022 23:08:00 +0200
Subject: [PATCH] Adding new helper functions for more convertion types

---
 src/helper_files/helper.cpp | 29 +++++++++++++++++++++++++++++
 src/helper_files/helper.hpp |  4 ++++
 src/helper_files/helper.pl  | 21 ++++++++++++++++++++-
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/helper_files/helper.cpp b/src/helper_files/helper.cpp
index 7f7568a..ec3dd05 100644
--- a/src/helper_files/helper.cpp
+++ b/src/helper_files/helper.cpp
@@ -1,6 +1,8 @@
 
 #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);
diff --git a/src/helper_files/helper.hpp b/src/helper_files/helper.hpp
index 1093c1a..5a21234 100644
--- a/src/helper_files/helper.hpp
+++ b/src/helper_files/helper.hpp
@@ -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);
 
diff --git a/src/helper_files/helper.pl b/src/helper_files/helper.pl
index 153ab43..2badf32 100644
--- a/src/helper_files/helper.pl
+++ b/src/helper_files/helper.pl
@@ -1,8 +1,10 @@
-:- 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).
+        
+        
+        
+
 
 
 
-- 
GitLab