in flink-ml-lib/src/main/java/org/apache/flink/ml/feature/polynomialexpansion/PolynomialExpansion.java [244:288]
private static int expandSparseVector(
int[] indices,
double[] values,
int lastIdx,
int lastFeatureIdx,
int degree,
double factor,
Tuple2<Integer, int[]> polyIndices,
Tuple2<Integer, double[]> polyValues,
int curPolyIdx) {
if (!Double.valueOf(factor).equals(0.0)) {
if (degree == 0 || lastIdx < 0) {
if (curPolyIdx >= 0) {
polyIndices.f1[polyIndices.f0] = curPolyIdx;
polyValues.f1[polyValues.f0] = factor;
polyIndices.f0++;
polyValues.f0++;
}
} else {
double v = values[lastIdx];
int lastIdx1 = lastIdx - 1;
int lastFeatureIdx1 = indices[lastIdx] - 1;
double alpha = factor;
int curStart = curPolyIdx;
int i = 0;
while (i <= degree && Math.abs(alpha) > 0.0) {
curStart =
expandSparseVector(
indices,
values,
lastIdx1,
lastFeatureIdx1,
degree - i,
alpha,
polyIndices,
polyValues,
curStart);
i++;
alpha *= v;
}
}
}
return curPolyIdx + getResultVectorSize(lastFeatureIdx + 1, degree);
}