This is an automated email from the ASF dual-hosted git repository.
mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new b6831400c7 [MINOR] Fix centralMoment instruction generation
b6831400c7 is described below
commit b6831400c7734a15441b1eb79b4e18a8d87aa7c8
Author: Matthias Boehm <[email protected]>
AuthorDate: Tue Apr 4 22:10:09 2023 +0200
[MINOR] Fix centralMoment instruction generation
By reusing thread-local string builders we need to be careful about
calling primitives that internally use the build. We now extended these
signatures to optionally allow passing a partially filled string builder
as well.
---
src/main/java/org/apache/sysds/lops/CentralMoment.java | 8 ++++----
.../sysds/runtime/instructions/InstructionUtils.java | 16 +++++++++++-----
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/apache/sysds/lops/CentralMoment.java
b/src/main/java/org/apache/sysds/lops/CentralMoment.java
index 13558afdcf..8972b4f4c2 100644
--- a/src/main/java/org/apache/sysds/lops/CentralMoment.java
+++ b/src/main/java/org/apache/sysds/lops/CentralMoment.java
@@ -82,19 +82,19 @@ public class CentralMoment extends Lop
public String getInstructions(String input1, String input2, String
input3, String output) {
StringBuilder sb = InstructionUtils.getStringBuilder();
if( input3 == null ) {
- sb.append(InstructionUtils.concatOperands(
+ InstructionUtils.concatOperands(sb,
getExecType().toString(), "cm",
getInputs().get(0).prepInputOperand(input1),
getInputs().get((input3!=null)?2:1).prepScalarInputOperand(getExecType()),
- prepOutputOperand(output)));
+ prepOutputOperand(output));
}
else {
- sb.append(InstructionUtils.concatOperands(
+ InstructionUtils.concatOperands(sb,
getExecType().toString(), "cm",
getInputs().get(0).prepInputOperand(input1),
getInputs().get(1).prepInputOperand(input2),
getInputs().get((input3!=null)?2:1).prepScalarInputOperand(getExecType()),
- prepOutputOperand(output)));
+ prepOutputOperand(output));
}
if( getExecType() == ExecType.CP || getExecType() ==
ExecType.FED ) {
sb.append(OPERAND_DELIMITOR);
diff --git
a/src/main/java/org/apache/sysds/runtime/instructions/InstructionUtils.java
b/src/main/java/org/apache/sysds/runtime/instructions/InstructionUtils.java
index 6d1325cc0c..dd731c3583 100644
--- a/src/main/java/org/apache/sysds/runtime/instructions/InstructionUtils.java
+++ b/src/main/java/org/apache/sysds/runtime/instructions/InstructionUtils.java
@@ -1140,7 +1140,13 @@ public class InstructionUtils {
* @return the instruction string with the given inputs concatenated
*/
public static String concatOperands(String... inputs) {
- return concatBaseOperandsWithDelim(Lop.OPERAND_DELIMITOR,
inputs);
+ StringBuilder sb = _strBuilders.get();
+ sb.setLength(0); //reuse allocated space
+ return concatOperands(sb, inputs);
+ }
+
+ public static String concatOperands(StringBuilder sb, String... inputs)
{
+ return concatBaseOperandsWithDelim(sb, Lop.OPERAND_DELIMITOR,
inputs);
}
/**
@@ -1149,12 +1155,12 @@ public class InstructionUtils {
* @return concatenated input parts
*/
public static String concatOperandParts(String... inputs) {
- return
concatBaseOperandsWithDelim(Instruction.VALUETYPE_PREFIX, inputs);
- }
-
- private static String concatBaseOperandsWithDelim(String delim,
String... inputs){
StringBuilder sb = _strBuilders.get();
sb.setLength(0); //reuse allocated space
+ return concatBaseOperandsWithDelim(sb,
Instruction.VALUETYPE_PREFIX, inputs);
+ }
+
+ private static String concatBaseOperandsWithDelim(StringBuilder sb,
String delim, String... inputs){
for( int i=0; i<inputs.length-1; i++ ) {
sb.append(inputs[i]);
sb.append(delim);