aboutsummaryrefslogtreecommitdiff
path: root/dist.cpp
blob: f307564f2b9259744a090d01b84d5c6db42e4faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "mp.h"

#include "utils.h"

double mp::euclidean(const arma::rowvec &x1, const arma::rowvec &x2)
{
    return arma::norm(x1 - x2, 2);
}

arma::mat mp::dist(const arma::mat &X, mp::DistFunc dfunc)
{
    int n = uintToInt<arma::uword, int>(X.n_rows);
    arma::mat D(n, n, arma::fill::zeros);

    #pragma omp parallel for shared(X, D, n)
    for (int i = 0; i < n; i++) {
        for (arma::uword j = 0; j < i; j++) {
            D(i, j) = dfunc(X.row(i), X.row(j));
            D(j, i) = D(i, j);
        }
    }

    return D;
}