Search in sources :

Example 6 with DataExpression

use of org.apache.sysml.parser.DataExpression in project incubator-systemml by apache.

the class AutomatedTestBase method readDMLMetaDataValueType.

public static ValueType readDMLMetaDataValueType(String fileName) {
    try {
        String fname = baseDirectory + OUTPUT_DIR + fileName + ".mtd";
        JSONObject meta = new DataExpression().readMetadataFile(fname, false);
        return ValueType.valueOf(meta.get(DataExpression.VALUETYPEPARAM).toString().toUpperCase());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : DataExpression(org.apache.sysml.parser.DataExpression) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) JSONObject(org.apache.wink.json4j.JSONObject) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) IOException(java.io.IOException)

Example 7 with DataExpression

use of org.apache.sysml.parser.DataExpression in project incubator-systemml by apache.

the class CommonSyntacticValidator method buildForBuiltInFunction.

/** Checks for builtin functions and does Action 'f'.
	 * <p>
	 * Constructs the
	 * appropriate {@link AssignmentStatement} from
	 * {@link CommonSyntacticValidator#functionCallAssignmentStatementHelper(ParserRuleContext, Set, Set, Expression, StatementInfo, Token, Token, String, String, ArrayList, boolean)}
	 * or Assign to {@link Expression} from
	 * DmlSyntacticValidator's exitBuiltinFunctionExpression(BuiltinFunctionExpressionContext).
	 * </p>
	 * 
	 * @param ctx antlr rule context
	 * @param functionName Name of the builtin function
	 * @param paramExpressions Array of parameter names and values
	 * @param f action to perform
	 * @return true if a builtin function was found
	 */
protected boolean buildForBuiltInFunction(ParserRuleContext ctx, String functionName, ArrayList<ParameterExpression> paramExpressions, Action f) {
    // In global namespace, so it can be a builtin function
    // Double verification: verify passed function name is a (non-parameterized) built-in function.
    String fileName = currentFile;
    int line = ctx.start.getLine();
    int col = ctx.start.getCharPositionInLine();
    try {
        if (functions.contains(functionName)) {
            // It is a user function definition (which takes precedence if name same as built-in)
            return false;
        }
        Expression lsf = handleLanguageSpecificFunction(ctx, functionName, paramExpressions);
        if (lsf != null) {
            setFileLineColumn(lsf, ctx);
            f.execute(lsf);
            return true;
        }
        BuiltinFunctionExpression bife = BuiltinFunctionExpression.getBuiltinFunctionExpression(functionName, paramExpressions, fileName, line, col, line, col);
        if (bife != null) {
            // It is a builtin function
            f.execute(bife);
            return true;
        }
        ParameterizedBuiltinFunctionExpression pbife = ParameterizedBuiltinFunctionExpression.getParamBuiltinFunctionExpression(functionName, paramExpressions, fileName, line, col, line, col);
        if (pbife != null) {
            // It is a parameterized builtin function
            f.execute(pbife);
            return true;
        }
        // built-in read, rand ...
        DataExpression dbife = DataExpression.getDataExpression(functionName, paramExpressions, fileName, line, col, line, col, errorListener);
        if (dbife != null) {
            f.execute(dbife);
            return true;
        }
    } catch (Exception e) {
        notifyErrorListeners("unable to process builtin function expression " + functionName + ":" + e.getMessage(), ctx.start);
        return true;
    }
    return false;
}
Also used : DataExpression(org.apache.sysml.parser.DataExpression) RelationalExpression(org.apache.sysml.parser.RelationalExpression) BooleanExpression(org.apache.sysml.parser.BooleanExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataExpression(org.apache.sysml.parser.DataExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) LanguageException(org.apache.sysml.parser.LanguageException)

Aggregations

DataExpression (org.apache.sysml.parser.DataExpression)7 IOException (java.io.IOException)4 LanguageException (org.apache.sysml.parser.LanguageException)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 JSONObject (org.apache.wink.json4j.JSONObject)4 BinaryExpression (org.apache.sysml.parser.BinaryExpression)3 BooleanExpression (org.apache.sysml.parser.BooleanExpression)3 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)3 Expression (org.apache.sysml.parser.Expression)3 ParameterExpression (org.apache.sysml.parser.ParameterExpression)3 ParameterizedBuiltinFunctionExpression (org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression)3 RelationalExpression (org.apache.sysml.parser.RelationalExpression)3 DMLException (org.apache.sysml.api.DMLException)2 ParseException (org.apache.sysml.parser.ParseException)2 InputInfo (org.apache.sysml.runtime.matrix.data.InputInfo)2 HashMap (java.util.HashMap)1 DataIdentifier (org.apache.sysml.parser.DataIdentifier)1 OutputStatement (org.apache.sysml.parser.OutputStatement)1 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)1