Skip to content

Commit b4812ab

Browse files
committed
fix for single col
1 parent 793b68f commit b4812ab

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

src/main/java/org/apache/sysds/runtime/compress/CompressedMatrixBlock.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,6 @@ public MatrixBlock pickValues(MatrixValue quantiles, MatrixValue ret) {
12401240
return getUncompressed("pickValues").pickValues(quantiles, ret);
12411241
}
12421242

1243-
@Override
1244-
public double pickValue(double quantile, boolean average) {
1245-
return getUncompressed("pickValue").pickValue(quantile, average);
1246-
}
1247-
12481243
@Override
12491244
public double sumWeightForQuantile() {
12501245
return getUncompressed("sumWeightForQuantile").sumWeightForQuantile();

src/main/java/org/apache/sysds/runtime/matrix/data/MatrixBlock.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4753,6 +4753,16 @@ public static double computeIQMCorrection(double sum, double sum_wt,
47534753
return (sum + q25Part*q25Val - q75Part*q75Val) / (sum_wt*0.5);
47544754
}
47554755

4756+
/**
4757+
* Pick the quantiles out of this matrix. If this matrix contains two columns it is weighted quantile picking.
4758+
* If a single column it is unweighted.
4759+
*
4760+
* Note the values are assumed to be sorted
4761+
*
4762+
* @param quantiles The quantiles to pick
4763+
* @param ret The result matrix
4764+
* @return The result matrix
4765+
*/
47564766
public MatrixBlock pickValues(MatrixValue quantiles, MatrixValue ret) {
47574767

47584768
MatrixBlock qs=checkType(quantiles);
@@ -4774,17 +4784,58 @@ public MatrixBlock pickValues(MatrixValue quantiles, MatrixValue ret) {
47744784

47754785
return output;
47764786
}
4777-
4787+
4788+
/**
4789+
* Pick the median quantile from this matrix. if this matrix is two columns, it is weighted picking else it is unweighted.
4790+
*
4791+
* Note the values are assumed to be sorted
4792+
*
4793+
* @param quantile The quantile to pick
4794+
* @return The quantile
4795+
*/
47784796
public double median() {
47794797
double sum_wt = sumWeightForQuantile();
47804798
return pickValue(0.5, sum_wt%2==0);
47814799
}
4782-
4800+
4801+
/**
4802+
* Pick a specific quantile from this matrix. if this matrix is two columns, it is weighted picking else it is unweighted.
4803+
*
4804+
* Note the values are assumed to be sorted
4805+
*
4806+
* @param quantile The quantile to pick
4807+
* @return The quantile
4808+
*/
47834809
public final double pickValue(double quantile){
47844810
return pickValue(quantile, false);
47854811
}
47864812

4787-
public double pickValue(double quantile, boolean average) {
4813+
/**
4814+
* Pick a specific quantile from this matrix. if this matrix is two columns, it is weighted picking else it is unweighted.
4815+
*
4816+
* Note the values are assumed to be sorted
4817+
*
4818+
* @param quantile The quantile to pick
4819+
* @param average If the quantile is averaged.
4820+
* @return The quantile
4821+
*/
4822+
public final double pickValue(double quantile, boolean average) {
4823+
if(this.getNumColumns() == 1)
4824+
return pickUnweightedValue(quantile, average);
4825+
4826+
4827+
return pickWeightedValue(quantile, average);
4828+
}
4829+
4830+
private double pickUnweightedValue(double quantile, boolean average) {
4831+
double pos = quantile * rlen;
4832+
if(average && (int) pos != pos)
4833+
return (get((int) Math.floor(pos), 0) + get(Math.min(rlen - 1, (int) Math.ceil(pos)), 0)) / 2;
4834+
else
4835+
return get(Math.min(rlen - 1, (int) Math.round(pos)), 0);
4836+
}
4837+
4838+
private double pickWeightedValue(double quantile, boolean average) {
47884839
double sum_wt = sumWeightForQuantile();
47894840

47904841
// do averaging only if it is asked for; and sum_wt is even

0 commit comments

Comments
 (0)