22 #include <dlib/matrix/matrix.h>
24 # define M_PI 3.14159265358979323846
43 static double mean(T *input,
int inputSize)
46 for (
int i = 0; i < inputSize; i++)
59 static double sum(T* input,
int inputSize)
62 for (
int i = 0; i < inputSize; i++)
77 for (
int i = 0; i < inputSize - 1; i++)
79 output[i] = input[i + 1] - input[i];
89 static void sort(T*
output,
int* outputIndex, T* input,
int inputSize)
93 tempInput =
new double[inputSize];
94 std::copy(input, input + inputSize, tempInput);
98 for (
int i = 1; i < inputSize; i++)
100 outputIndex[i] = outputIndex[i - 1] + 1;
103 for (
int i = 0; i < inputSize; i++)
105 for (
int j = inputSize - 1; j > i; j--)
107 if (input[j] < input[j - 1])
110 tempIndex = outputIndex[j - 1];
111 input[j - 1] = input[j];
112 outputIndex[j - 1] = outputIndex[j];
114 outputIndex[j] = tempIndex;
118 std::memcpy(&
output[0], &input[0], inputSize *
sizeof(
double));
119 std::memcpy(&input[0], &tempInput[0], inputSize *
sizeof(
double));
131 template <
typename T>
132 static bool any(T *input,
int inputSize,
const char* condition,
double ref)
135 switch(
hashit(condition) )
138 for (
int i = 0; i < inputSize; i++)
148 for (
int i = 0; i < inputSize; i++)
158 for (
int i = 0; i < inputSize; i++)
168 for (
int i = 0; i < inputSize; i++)
178 for (
int i = 0; i < inputSize; i++)
188 printf(
"\n %c", condition[0]);
189 printf(
"\nError:(any) Please choose a correct condition");
190 printf(
"\nG for greater, E for equal, L for less");
191 printf(
"\nGE for greater equal, LE for less equal");
205 template <
typename T>
206 static std::vector<int>
find(T *input,
int inputSize,
const char *condition,
double ref)
209 switch(
hashit(condition) )
212 for(
int i=0; i<inputSize; i++)
222 for(
int i=0; i<inputSize; i++)
231 for(
int i=0; i<inputSize; i++)
240 for(
int i=0; i<inputSize; i++)
249 for(
int i=0; i<inputSize; i++)
257 default: printf(
"\nNOT VALID CONDITION FOR adore::mad::ArrayMatrixTools::find");
break;
268 template <
typename T>
269 static std::vector<int>
find(std::vector<T>* input,
const char *condition,
double ref)
271 return find (input->data(), input->size(),condition, ref);
283 template <
typename T>
284 static void find(
int *
output,
int *outputSize, T *input,
int inputSize,
const char *condition,
double ref)
286 auto solution =
find (input, inputSize ,condition, ref);
287 std::memcpy(&
output[0],&solution.data()[0],solution.size()*
sizeof(
int));
288 *outputSize = solution.size() ;
297 template <
typename T>
300 for (
int i = 0; i < input_row; i++)
302 for (
int j = 0; j < input_column; j++)
304 output[j*input_row + i] = input[i*input_column + j];
318 static void matrixMultiplication(
double *
output,
double *input_1,
int input_1_row,
int input_1_column,
double *input_2,
int input_2_row,
int input_2_column)
320 if (input_1_column != input_2_row)
321 printf(
"\n Error, invalid matrix size");
323 for (
int i = 0; i < input_1_row*input_2_column; i++)
326 for (
int r_1 = 0; r_1 < input_1_row; r_1++)
328 for (
int c_2 = 0; c_2 < input_2_column; c_2++)
330 for (
int c_1 = 0; c_1 < input_1_column; c_1++)
332 output[(r_1*input_2_column) + c_2] += input_1[(r_1*input_1_column) + c_1] * input_2[(c_1*input_2_column) + c_2];
344 template <
typename T>
347 for (
int i = 0; i < inputSize; i++)
349 output[i] = input_1[i] * input_2[i];
359 template <
typename T>
363 for (
int i = start; i <= end; i++)
365 output[counter] = input[i];
378 template <
typename T>
379 static void sparseDiagonalMatrix(T *sparse, T *input,
int output_row,
int output_column,
int inputSize,
int StartingReference)
382 int offsetColumn = 0;
384 if (StartingReference > 0)
385 offsetColumn = StartingReference;
386 if (StartingReference < 0)
387 offsetRow = std::abs(StartingReference);
389 if (inputSize <
std::min(output_row - offsetRow, output_column - offsetColumn) || output_row - offsetRow == 0 || output_column - offsetColumn == 0)
391 printf(
"\nError, DiagonalSparseMatrix, requested matrix has bigger diagonal than delivered input");
394 if (output_column > output_row)
396 for (
int i = 0; i < output_row; i++)
398 for (
int j = 0; j < output_column; j++)
400 if (i - offsetRow == j - offsetColumn)
402 sparse[i*output_column + j] = input[counter + offsetRow];
407 sparse[i*output_column + j] = 0;
412 if (output_column <= output_row)
414 for (
int i = 0; i < output_row; i++)
416 for (
int j = 0; j < output_column; j++)
418 if (i - offsetRow == j - offsetColumn)
420 sparse[(i*output_column) + j] = input[counter + offsetColumn];
425 sparse[(i*output_column) + j] = 0;
449 static double unwrap(
double prev,
double now)
474 template <
typename T>
477 if(
x>=0.0000)
return 1;
486 template <
typename T>
494 for(
int i=0; i<inputSize;i++)
510 template <
typename T>
514 tmp =
new double [inputSize];
515 std::memcpy(&tmp[0],&input[1],(inputSize-1)*
sizeof(
double));
516 std::memcpy(&input[0],&tmp[0],(inputSize-1)*
sizeof(
double));
517 input[inputSize-1] = newValue;
528 for(
int i = 0; i < dim; i++)
530 magV1 += v1[i] * v1[i];
531 magV2 += v2[i] * v2[i];
533 dotProd += v1[i] * v2[i];
536 magV1 = std::sqrt(magV1);
537 magV2 = std::sqrt(magV2);
539 return acos(dotProd / (magV1 * magV2));
544 return acos(v1.dot(v2) / (v1.length() * v2.length()));
547 static double geoDistance(dlib::vector<double,T> v1, dlib::vector<double,T> v2)
551 return dlib::length(temp);
555 if (inString ==
"E")
return EQUAL;
556 if (inString ==
"G")
return GREATER;
557 if (inString ==
"L")
return LOWER;
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
string output
Definition: adore_set_goal.py:23
x
Definition: adore_set_goal.py:30
w
Definition: adore_set_pose.py:40
Definition: areaofeffectconverter.h:20