I am trying to reproduce a C++
code that I found here about the LevenshteinDistance
.
More precisely, I am trying to reproduce the part starting by
static int LevenshteinDistance(string s, string t)
until
return d[n, m];
}
However, I am experiencing an error with Math.Min(Math.Min(
. I am not sure what is the translation in rcpp
. I tried with min
but it doesn't seem to work. Any clue ?
// [[Rcpp::export]]
NumericVector LevenshteinDistance(NumericVector s, NumericVector t) {
int n = s.size();
int m = t.size();
NumericMatrix d(n+1, m+1);
if (n == 0)
{
return m;
}
if (m == 0){
return n;
}
for (int i = 0; i < n; i++)
d(i, 0) = i;
for (int j = 0; j < m; j++)
d(0, j) = j;
for (int j = 1; j < m; j++)
for (int i = 1; i < n; i++)
if (s(i - 1) == t(j - 1))
d(i, j) = d(i - 1, j - 1); //no operation
else
d(i, j) = min(
d(i - 1, j) + 1, //a deletion
d(i, j - 1) + 1), //an insertion
d(i - 1, j - 1) + 1 //a substitution
);
return d(n, m);
}
So with
d(i, j) = min(
I get this error message : no matching function
.