Class InstructionUtils


  • public class InstructionUtils
    extends Object
    • Constructor Detail

      • InstructionUtils

        public InstructionUtils()
    • Method Detail

      • getStringBuilder

        public static StringBuilder getStringBuilder()
      • checkNumFields

        public static int checkNumFields​(String str,
                                         int expected)
      • checkNumFields

        public static int checkNumFields​(String[] parts,
                                         int expected)
      • checkNumFields

        public static int checkNumFields​(String[] parts,
                                         int expected1,
                                         int expected2)
      • checkNumFields

        public static int checkNumFields​(String[] parts,
                                         int... expected)
      • checkNumFields

        public static int checkNumFields​(String str,
                                         int... expected)
      • checkNumFields

        public static int checkNumFields​(String str,
                                         int expected1,
                                         int expected2)
      • getInstructionParts

        public static String[] getInstructionParts​(String str)
        Given an instruction string, strip-off the execution type and return opcode and all input/output operands WITHOUT their data/value type. i.e., ret.length = parts.length-1 (-1 for execution type)
        Parameters:
        str - instruction string
        Returns:
        instruction parts as string array
      • getInstructionPartsWithValueType

        public static String[] getInstructionPartsWithValueType​(String str)
        Given an instruction string, this function strips-off the execution type (CP or SPARK) and returns the remaining parts, which include the opcode as well as the input and output operands. Each returned part will have the datatype and valuetype associated with the operand. This function is invoked mainly for parsing CPInstructions.
        Parameters:
        str - instruction string
        Returns:
        instruction parts as string array
      • stripThreadCount

        public static String stripThreadCount​(String str)
      • getOpCode

        public static String getOpCode​(String str)
      • isBuiltinFunction

        public static boolean isBuiltinFunction​(String opcode)
      • isUnaryMetadata

        public static boolean isUnaryMetadata​(String opcode)
      • parseBasicAggregateUnaryOperator

        public static AggregateUnaryOperator parseBasicAggregateUnaryOperator​(String opcode,
                                                                              int numThreads)
        Parse the given opcode into an aggregate unary operator.
        Parameters:
        opcode - opcode
        numThreads - number of threads
        Returns:
        Parsed aggregate unary operator object. Caller must handle possible null return value.
      • parseAggregateUnaryRowIndexOperator

        public static AggregateUnaryOperator parseAggregateUnaryRowIndexOperator​(String opcode,
                                                                                 int numOutputs,
                                                                                 int numThreads)
      • parseUnaryOperator

        public static UnaryOperator parseUnaryOperator​(String opcode,
                                                       int k)
      • parseTernaryOperator

        public static TernaryOperator parseTernaryOperator​(String opcode,
                                                           int numThreads)
      • parseScalarBinaryOperator

        public static ScalarOperator parseScalarBinaryOperator​(String opcode,
                                                               boolean arg1IsScalar)
        scalar-matrix operator
        Parameters:
        opcode - the opcode
        arg1IsScalar - ?
        Returns:
        scalar operator
      • parseScalarBinaryOperator

        public static ScalarOperator parseScalarBinaryOperator​(String opcode,
                                                               boolean arg1IsScalar,
                                                               double constant)
        scalar-matrix operator
        Parameters:
        opcode - the opcode
        arg1IsScalar - ?
        constant - ?
        Returns:
        scalar operator
      • parseExtendedBinaryOperator

        public static BinaryOperator parseExtendedBinaryOperator​(String opcode)
      • deriveAggregateOperatorOpcode

        public static String deriveAggregateOperatorOpcode​(String opcode)
      • isDistQuaternaryOpcode

        public static boolean isDistQuaternaryOpcode​(String opcode)
      • parseGroupedAggOperator

        public static Operator parseGroupedAggOperator​(String fn,
                                                       String other)
      • createOperand

        public static String createOperand​(CPOperand operand)
      • replaceOperand

        public static String replaceOperand​(String instStr,
                                            int operand,
                                            String newValue)
      • removeOperand

        public static String removeOperand​(String instStr,
                                           int operand)
      • replaceOperandName

        public static String replaceOperandName​(String instStr)
      • concatOperands

        public static String concatOperands​(String... inputs)
        Concat the inputs as operands to generate the instruction string. The inputs are separated by the operand delimiter and appended using a ThreadLocal StringBuilder.
        Parameters:
        inputs - operand inputs given as strings
        Returns:
        the instruction string with the given inputs concatenated
      • concatOperandParts

        public static String concatOperandParts​(String... inputs)
        Concat the input parts with the value type delimiter.
        Parameters:
        inputs - input operand parts as strings
        Returns:
        concatenated input parts
      • concatStrings

        public static String concatStrings​(String... inputs)
      • instructionStringFEDPrepare

        public static String instructionStringFEDPrepare​(String inst,
                                                         CPOperand varOldOut,
                                                         long id,
                                                         CPOperand[] varOldIn,
                                                         long[] varNewIn,
                                                         boolean rmFederatedOutput)
        Prepare instruction string for sending in a FederatedRequest as a CP instruction. This involves replacing the coordinator operand names with the worker operand names, changing the execution type, and removing the federated output flag if necessary.
        Parameters:
        inst - instruction string to prepare for federated request
        varOldOut - current output operand (to be replaced)
        id - new output operand (always a number)
        varOldIn - current input operand (to be replaced)
        varNewIn - new input operand names (always numbers)
        rmFederatedOutput - remove federated output flag
        Returns:
        instruction string prepared for federated request
      • removeFEDOutputFlag

        public static String removeFEDOutputFlag​(String linst)
        Removes federated output flag from the end of the instruction string if the flag is present.
        Parameters:
        linst - instruction string
        Returns:
        instruction string with no federated output flag