From b2e86435b9264bc734bb589cac233956ebec7bb8 Mon Sep 17 00:00:00 2001 From: Parth Date: Fri, 12 Dec 2025 18:00:52 +0530 Subject: [PATCH 1/2] Fix SYSTEMDS-3898: ensure quantile VALUEPICK computes output for non-inmem path (materialize and pick with averaging for even-length arrays) --- .../cp/QuantilePickCPInstruction.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java b/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java index a7bfbf5a16c..82acc3fe040 100644 --- a/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java +++ b/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java @@ -83,31 +83,33 @@ else if( parts.length == 6 ) { public void processInstruction(ExecutionContext ec) { switch( _type ) { - case VALUEPICK: - if( _inmem ) //INMEM VALUEPICK - { - MatrixBlock matBlock = ec.getMatrixInput(input1.getName()); - - if ( input2.getDataType() == DataType.SCALAR ) { - ScalarObject quantile = ec.getScalarInput(input2); - //pick value w/ explicit averaging for even-length arrays - double picked = matBlock.pickValue( - quantile.getDoubleValue(), matBlock.getLength()%2==0); - ec.setScalarOutput(output.getName(), new DoubleObject(picked)); - } - else { - MatrixBlock quantiles = ec.getMatrixInput(input2.getName()); - //pick value w/ explicit averaging for even-length arrays - MatrixBlock resultBlock = matBlock.pickValues( - quantiles, new MatrixBlock(), matBlock.getLength()%2==0); - quantiles = null; - ec.releaseMatrixInput(input2.getName()); - ec.setMatrixOutput(output.getName(), resultBlock); - } - ec.releaseMatrixInput(input1.getName()); - } - break; + case VALUEPICK: +// Handle both in-memory and non-in-memory VALUEPICK by materializing +// the input matrix and invoking the pick routines. Previously only +// the in-memory branch was executed which left the output unset +// when _inmem==false (see SYSTEMDS-3898). +{ +MatrixBlock matBlock = ec.getMatrixInput(input1.getName()); +if ( input2.getDataType() == DataType.SCALAR ) { +ScalarObject quantile = ec.getScalarInput(input2); +// pick value w/ explicit averaging for even-length arrays +double picked = matBlock.pickValue( +quantile.getDoubleValue(), matBlock.getLength()%2==0); +ec.setScalarOutput(output.getName(), new DoubleObject(picked)); +} +else { +MatrixBlock quantiles = ec.getMatrixInput(input2.getName()); +// pick values w/ explicit averaging for even-length arrays +MatrixBlock resultBlock = matBlock.pickValues( +quantiles, new MatrixBlock(), matBlock.getLength()%2==0); +quantiles = null; +ec.releaseMatrixInput(input2.getName()); +ec.setMatrixOutput(output.getName(), resultBlock); +} +ec.releaseMatrixInput(input1.getName()); +} +break; case MEDIAN: if( _inmem ) //INMEM MEDIAN { From 01546c846122abbed3bb3c2153c166ff149814b8 Mon Sep 17 00:00:00 2001 From: Parth Date: Fri, 12 Dec 2025 18:08:42 +0530 Subject: [PATCH 2/2] Fix SYSTEMDS-3898: ensure quantile VALUEPICK computes output for non-inmem path (materialize and pick with averaging for even-length arrays) --- .../cp/QuantilePickCPInstruction.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java b/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java index 82acc3fe040..3edb145e92c 100644 --- a/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java +++ b/src/main/java/org/apache/sysds/runtime/instructions/cp/QuantilePickCPInstruction.java @@ -84,32 +84,32 @@ public void processInstruction(ExecutionContext ec) { switch( _type ) { case VALUEPICK: -// Handle both in-memory and non-in-memory VALUEPICK by materializing -// the input matrix and invoking the pick routines. Previously only -// the in-memory branch was executed which left the output unset -// when _inmem==false (see SYSTEMDS-3898). -{ -MatrixBlock matBlock = ec.getMatrixInput(input1.getName()); + // Handle both in-memory and non-in-memory VALUEPICK by materializing + // the input matrix and invoking the pick routines. Previously only + // the in-memory branch was executed which left the output unset + // when _inmem==false (see SYSTEMDS-3898). + { + MatrixBlock matBlock = ec.getMatrixInput(input1.getName()); -if ( input2.getDataType() == DataType.SCALAR ) { -ScalarObject quantile = ec.getScalarInput(input2); -// pick value w/ explicit averaging for even-length arrays -double picked = matBlock.pickValue( -quantile.getDoubleValue(), matBlock.getLength()%2==0); -ec.setScalarOutput(output.getName(), new DoubleObject(picked)); -} -else { -MatrixBlock quantiles = ec.getMatrixInput(input2.getName()); -// pick values w/ explicit averaging for even-length arrays -MatrixBlock resultBlock = matBlock.pickValues( -quantiles, new MatrixBlock(), matBlock.getLength()%2==0); -quantiles = null; -ec.releaseMatrixInput(input2.getName()); -ec.setMatrixOutput(output.getName(), resultBlock); -} -ec.releaseMatrixInput(input1.getName()); -} -break; + if ( input2.getDataType() == DataType.SCALAR ) { + ScalarObject quantile = ec.getScalarInput(input2); + // pick value w/ explicit averaging for even-length arrays + double picked = matBlock.pickValue( + quantile.getDoubleValue(), matBlock.getLength()%2==0); + ec.setScalarOutput(output.getName(), new DoubleObject(picked)); + } + else { + MatrixBlock quantiles = ec.getMatrixInput(input2.getName()); + // pick values w/ explicit averaging for even-length arrays + MatrixBlock resultBlock = matBlock.pickValues( + quantiles, new MatrixBlock(), matBlock.getLength()%2==0); + quantiles = null; + ec.releaseMatrixInput(input2.getName()); + ec.setMatrixOutput(output.getName(), resultBlock); + } + ec.releaseMatrixInput(input1.getName()); + } + break; case MEDIAN: if( _inmem ) //INMEM MEDIAN {