Exemple #1
0
PyObject*
dot_product(PyObject *self, PyObject *args)
{
    /**
     * Convert input
     */
    PyObject *a = NULL,
             *b = NULL;

    if (!PyArg_ParseTuple(args, "OO", &a, &b))
        return NULL;

    /**
     * Call the function
     */
    clann_matrix_type *x = PyCObject_AsVoidPtr(a),
                      *y = PyCObject_AsVoidPtr(b);

    if (x->cols != y->cols)
    {
        PyErr_SetString(PyExc_RuntimeError,
                        "matrices does not have the same size");
        return NULL;
    }

    clann_real_type v = metric_dot_product(x->values, y->values, x->cols);

    /**
     * Convert output
     */
    return Py_BuildValue("d", (double) v);
}
Exemple #2
0
unsigned int
metric_hausdorff_angle(const struct matrix *a,
                       const struct matrix *b,
                       clann_real_type limit)
{
    unsigned int i, j, length;
    clann_real_type inf,
               angle,
               count = 0,
               d,
               *x, *y,
               a_c[2], b_c[2];

    length = a->cols > b->cols ? b->cols - 1 : a->cols - 1;

    for (i = 0; i < a->rows; i++)
    {
        inf = (clann_real_type) INT_MAX;
        x = matrix_value(a, i, 0);

        for (j = 0; j < b->rows; j++)
        {
            y = matrix_value(b, j, 0);
            d = metric_euclidean(x, y, length);

            if (d < inf)
            {
                inf = d;
                angle = y[length];
            }
        }

        a_c[0] = CLANN_COS(x[length]);
        a_c[1] = CLANN_SIN(x[length]);

        b_c[0] = CLANN_COS(angle);
        b_c[1] = CLANN_SIN(angle);

        d = metric_dot_product(a_c, b_c, 2);

        if (d < 1 - limit)
            count++;
    }

    return count;
}