Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chipkent authored Feb 26, 2024
1 parent 0d68bc4 commit 86b2078
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 86 deletions.
46 changes: 23 additions & 23 deletions engine/function/src/templates/Numeric.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1589,45 +1589,45 @@ public class Numeric {
}

/**
* Returns the difference between elements in the input vector.
* A stride of 2 returns v(i)=e(i+2)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* A stride of -2 returns v(i)=e(i-2)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* The result is the same length as the input vector.
* Differences off the end of the input vector are null.
* Returns the differences between elements in the input vector separated by a stride.
* A stride of k returns v(i)=e(i+k)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* A stride of -k returns v(i)=e(i-k)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* The result has the same length as the input vector.
* Differences off the end of the input vector are the null value.
*
* @param stride number of elements to skip between consecutive elements.
* @param stride number of elements separating the elements to be differenced.
* @param values input vector.
* @return difference between elements.
* @return a vector containing the differences between elements.
*/
public static ${pt.primitive}[] diff(int stride, ${pt.boxed}[] values) {
return diff(stride, unbox(values));
}

/**
* Returns the difference between elements in the input vector.
* A stride of 2 returns v(i)=e(i+2)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* A stride of -2 returns v(i)=e(i-2)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* The result is the same length as the input vector.
* Differences off the end of the input vector are null.
* Returns the differences between elements in the input vector separated by a stride.
* A stride of k returns v(i)=e(i+k)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* A stride of -k returns v(i)=e(i-k)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* The result has the same length as the input vector.
* Differences off the end of the input vector are the null value.
*
* @param stride number of elements to skip between consecutive elements.
* @param stride number of elements separating the elements to be differenced.
* @param values input vector.
* @return difference between elements.
* @return a vector containing the differences between elements.
*/
public static ${pt.primitive}[] diff(int stride, ${pt.primitive}... values) {
return diff(stride, new ${pt.vectorDirect}(values));
}

/**
* Returns the difference between elements in the input vector.
* A stride of 2 returns v(i)=e(i+2)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* A stride of -2 returns v(i)=e(i-2)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* The result is the same length as the input vector.
* Differences off the end of the input vector are null.
* Returns the differences between elements in the input vector separated by a stride.
* A stride of k returns v(i)=e(i+k)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* A stride of -k returns v(i)=e(i-k)-e(i), where v(i) is the ith computed value e(i) is the ith input value.
* The result has the same length as the input vector.
* Differences off the end of the input vector are the null value.
*
* @param stride number of elements to skip between consecutive elements.
* @param stride number of elements separating the elements to be differenced.
* @param values input vector.
* @return difference between elements.
* @return a vector containing the differences between elements.
*/
public static ${pt.primitive}[] diff(int stride, ${pt.vector} values) {
if (values == null) {
Expand All @@ -1641,9 +1641,9 @@ public class Numeric {
final int n = values.intSize("diff");
${pt.primitive}[] result = new ${pt.primitive}[n];

for(int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
${pt.primitive} v1 = values.get(i);
${pt.primitive} v2 = values.get(i+stride);
${pt.primitive} v2 = values.get(i + stride);

if (isNull(v1) || isNull(v2)) {
result[i] = ${pt.null};
Expand Down
66 changes: 33 additions & 33 deletions engine/function/src/templates/Sort.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ public class Sort {
* @param comparator value comparator.
* @return sorted indices.
*/
static public <T extends Comparable<? super T>> int[] sortIndexObj(final ObjectVector<T> values, final Comparator<T> comparator) {
static public <T extends Comparable<? super T>> int[] rankObj(final ObjectVector<T> values, final Comparator<T> comparator) {
if (values == null) {
return null;
}
if (values.isEmpty()) {
return new int[]{};
return new int[0];
}

return IntStream.range(0, values.intSize("sortIndex"))
.boxed().sorted((i, j) -> comparator.compare(values.get(i),values.get(j)) )
return IntStream.range(0, values.intSize("rank"))
.boxed().sorted((i, j) -> comparator.compare(values.get(i), values.get(j)))
.mapToInt(ele -> ele).toArray();
}

Expand All @@ -108,8 +108,8 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
static public <T extends Comparable<? super T>> int[] sortIndexObj(final ObjectVector<T> values) {
return sortIndexObj(values, new NullNaNAwareComparator<>());
static public <T extends Comparable<? super T>> int[] rankObj(final ObjectVector<T> values) {
return rankObj(values, new NullNaNAwareComparator<>());
}

/**
Expand All @@ -119,13 +119,13 @@ public class Sort {
* @param comparator value comparator.
* @return sorted indices.
*/
static public <T extends Comparable<? super T>> int[] sortIndexObj(final T[] values, final Comparator<T> comparator) {
static public <T extends Comparable<? super T>> int[] rankObj(final T[] values, final Comparator<T> comparator) {
if (values == null) {
return null;
}

return IntStream.range(0, values.length)
.boxed().sorted((i, j) -> comparator.compare(values[i],values[j]) )
.boxed().sorted((i, j) -> comparator.compare(values[i], values[j]))
.mapToInt(ele -> ele).toArray();
}

Expand All @@ -136,8 +136,8 @@ public class Sort {
* @return sorted indices.
*/
@SafeVarargs
static public <T extends Comparable<? super T>> int[] sortIndexObj(final T... values) {
return sortIndexObj(values, new NullNaNAwareComparator<>());
static public <T extends Comparable<? super T>> int[] rankObj(final T... values) {
return rankObj(values, new NullNaNAwareComparator<>());
}

/**
Expand Down Expand Up @@ -204,7 +204,7 @@ public class Sort {
* @param comparator value comparator.
* @return sorted indices.
*/
static public <T extends Comparable<? super T>> int[] sortDescendingIndexObj(final ObjectVector<T> values, final Comparator<T> comparator) {
static public <T extends Comparable<? super T>> int[] rankDescendingObj(final ObjectVector<T> values, final Comparator<T> comparator) {
if (values == null) {
return null;
}
Expand All @@ -213,8 +213,8 @@ public class Sort {
return new int[]{};
}

return IntStream.range(0, values.intSize("sortIndex"))
.boxed().sorted((i, j) -> -comparator.compare(values.get(i),values.get(j)) )
return IntStream.range(0, values.intSize("rank"))
.boxed().sorted((i, j) -> comparator.compare(values.get(j), values.get(i)))
.mapToInt(ele -> ele).toArray();
}

Expand All @@ -224,8 +224,8 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
static public <T extends Comparable<? super T>> int[] sortDescendingIndexObj(final ObjectVector<T> values) {
return sortDescendingIndexObj(values, new NullNaNAwareComparator<>());
static public <T extends Comparable<? super T>> int[] rankDescendingObj(final ObjectVector<T> values) {
return rankDescendingObj(values, new NullNaNAwareComparator<>());
}

/**
Expand All @@ -235,12 +235,12 @@ public class Sort {
* @param comparator value comparator.
* @return sorted indices.
*/
static public <T extends Comparable<? super T>> int[] sortDescendingIndexObj(final T[] values, final Comparator<T> comparator) {
static public <T extends Comparable<? super T>> int[] rankDescendingObj(final T[] values, final Comparator<T> comparator) {
if (values == null) {
return null;
}

return sortDescendingIndexObj(new ObjectVectorDirect<>(values), comparator);
return rankDescendingObj(new ObjectVectorDirect<>(values), comparator);
}

/**
Expand All @@ -250,8 +250,8 @@ public class Sort {
* @return sorted indices.
*/
@SafeVarargs
static public <T extends Comparable<? super T>> int[] sortDescendingIndexObj(final T... values) {
return sortDescendingIndexObj(values, new NullNaNAwareComparator<>());
static public <T extends Comparable<? super T>> int[] rankDescendingObj(final T... values) {
return rankDescendingObj(values, new NullNaNAwareComparator<>());
}

<#list primitiveTypes as pt>
Expand Down Expand Up @@ -324,7 +324,7 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
public static int[] sortIndex(final ${pt.vector} values) {
public static int[] rank(final ${pt.vector} values) {
if (values == null) {
return null;
}
Expand All @@ -333,8 +333,8 @@ public class Sort {
return new int[]{};
}

return IntStream.range(0, values.intSize("sortIndex"))
.boxed().sorted((i, j) -> ${pt.boxed}.compare(values.get(i),values.get(j)) )
return IntStream.range(0, values.intSize("rank"))
.boxed().sorted((i, j) -> ${pt.boxed}.compare(values.get(i), values.get(j)))
.mapToInt(ele -> ele).toArray();
}

Expand All @@ -344,12 +344,12 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
public static int[] sortIndex(final ${pt.primitive}... values) {
public static int[] rank(final ${pt.primitive}... values) {
if (values == null) {
return null;
}

return sortIndex(new ${pt.vectorDirect}(values));
return rank(new ${pt.vectorDirect}(values));
}

/**
Expand All @@ -358,7 +358,7 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
public static int[] sortIndex(final ${pt.boxed}[] values) {
public static int[] rank(final ${pt.boxed}[] values) {
if (values == null) {
return null;
}
Expand All @@ -372,7 +372,7 @@ public class Sort {
vs[i] = isNull(values[i]) ? ${pt.null} : values[i];
}

return sortIndex(new ${pt.vectorDirect}(vs));
return rank(new ${pt.vectorDirect}(vs));
}

/**
Expand Down Expand Up @@ -433,7 +433,7 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
public static int[] sortDescendingIndex(final ${pt.vector} values) {
public static int[] rankDescending(final ${pt.vector} values) {
if (values == null) {
return null;
}
Expand All @@ -442,8 +442,8 @@ public class Sort {
return new int[]{};
}

return IntStream.range(0, values.intSize("sortIndex"))
.boxed().sorted((i, j) -> -${pt.boxed}.compare(values.get(i),values.get(j)) )
return IntStream.range(0, values.intSize("rank"))
.boxed().sorted((i, j) -> -${pt.boxed}.compare(values.get(i), values.get(j)))
.mapToInt(ele -> ele).toArray();
}

Expand All @@ -453,12 +453,12 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
public static int[] sortDescendingIndex(final ${pt.primitive}... values) {
public static int[] rankDescending(final ${pt.primitive}... values) {
if (values == null) {
return null;
}

return sortDescendingIndex(new ${pt.vectorDirect}(values));
return rankDescending(new ${pt.vectorDirect}(values));
}

/**
Expand All @@ -467,7 +467,7 @@ public class Sort {
* @param values values.
* @return sorted indices.
*/
public static int[] sortDescendingIndex(final ${pt.boxed}[] values) {
public static int[] rankDescending(final ${pt.boxed}[] values) {
if (values == null) {
return null;
}
Expand All @@ -477,7 +477,7 @@ public class Sort {
vs[i] = isNull(values[i]) ? ${pt.null} : values[i];
}

return sortDescendingIndex(new ${pt.vectorDirect}(vs));
return rankDescending(new ${pt.vectorDirect}(vs));
}

</#if>
Expand Down
Loading

0 comments on commit 86b2078

Please sign in to comment.