faster. See https://github.com/matiasdelellis/pdlib/pull/2. Increase the version to 1.0.2 since this is a required function for our application and we must control it. Add more compilation info in php-info(), and print a final message with the build options when configure. Fix that when dlib is not installed, the configuration returns that it cannot find pkgconfig. See https://github.com/matiasdelellis/facerecognition/issues/261 Also implement the test on travis. See for example: (https://travis-ci.com/github/matiasdelellis/pdlib/builds/161854044)
44 lines
840 B
C++
44 lines
840 B
C++
|
|
#include "../php_pdlib.h"
|
|
|
|
#include "vector.h"
|
|
|
|
#include <cmath>
|
|
#include <zend_exceptions.h>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
PHP_FUNCTION(dlib_vector_length)
|
|
{
|
|
zval *x_arg, *y_arg;
|
|
|
|
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "aa", &x_arg, &y_arg) == FAILURE) {
|
|
return;
|
|
}
|
|
|
|
zval *elem_x, *elem_y;
|
|
double sum = 0.0;
|
|
unsigned int i, len;
|
|
|
|
len = zend_hash_num_elements(Z_ARRVAL_P(x_arg));
|
|
|
|
if (len != zend_hash_num_elements(Z_ARRVAL_P(y_arg))) {
|
|
zend_throw_exception_ex(
|
|
zend_ce_exception,
|
|
0,
|
|
"The arrays have different sizes");
|
|
return;
|
|
}
|
|
|
|
for (i = 0 ; i < len ; i++) {
|
|
elem_x = zend_hash_index_find(Z_ARRVAL_P(x_arg), i);
|
|
elem_y = zend_hash_index_find(Z_ARRVAL_P(y_arg), i);
|
|
|
|
sum += (Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y))*(Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y));
|
|
}
|
|
|
|
RETURN_DOUBLE(sqrt(sum));
|
|
}
|
|
|