Add native vector_lenght() function which calculates the euclidean distance 80%
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)
This commit is contained in:
43
src/vector.cc
Normal file
43
src/vector.cc
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#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));
|
||||
}
|
||||
|
||||
10
src/vector.h
Normal file
10
src/vector.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef PHP_DLIB_VECTOR_H
|
||||
#define PHP_DLIB_VECTOR_H
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(dlib_vector_length_arginfo, 0, 0, 2)
|
||||
ZEND_ARG_ARRAY_INFO(0, x_arg, 0)
|
||||
ZEND_ARG_ARRAY_INFO(0, y_arg, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
PHP_FUNCTION(dlib_vector_length);
|
||||
|
||||
#endif //PHP_DLIB_VECTOR_H
|
||||
Reference in New Issue
Block a user