From e1ad28bd8bd9b9585417fb4d57645ecbebc96f09 Mon Sep 17 00:00:00 2001 From: Ehsan Totoni Date: Wed, 14 Sep 2016 07:34:17 -0700 Subject: [PATCH] CGen support hcat of single values --- src/cgen-pattern-match.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/cgen-pattern-match.jl b/src/cgen-pattern-match.jl index eed84bb..27ca2cf 100644 --- a/src/cgen-pattern-match.jl +++ b/src/cgen-pattern-match.jl @@ -591,6 +591,12 @@ function from_assignment_match_hcat(lhs, rhs::Expr, linfo) s = "" if (isCall(rhs) || isInvoke(rhs)) && isBaseFunc(getCallFunction(rhs), :hcat) args = getCallArguments(rhs) + in_typ = getType(args[1], linfo) + # hcat of single values like hcat(1,2,3) => 2D array [1 2 3] + # used in quant example + if !(in_typ<:Array) + return single_value_hcat(lhs, args, linfo) + end for a in args atyp = getType(a, linfo) @assert atyp<:Array && ndims(atyp)==1 "CGen only supports hcat of 1D arrays" @@ -615,6 +621,24 @@ function from_assignment_match_hcat(lhs, rhs::ANY, linfo) return "" end +function single_value_hcat(lhs, args, linfo) + for a in args + atyp = getType(a, linfo) + @assert !(atyp<:Array) "CGen invalid hcat input (single_value_hcat)" + end + typ = getType(args[1], linfo) + size = length(args) + ctyp = toCtype(typ) + clhs = from_expr(lhs,linfo) + s = "$clhs = j2c_array<$ctyp>::new_j2c_array_2d(NULL, 1, $size);\n" + for j in 1:size + var = from_expr(args[j],linfo) + s *= "$clhs.data[$(j-1)] = $var;\n" + end + return s +end + + function from_assignment_match_vcat(lhs, rhs::Expr, linfo) s = "" if (isCall(rhs) || isInvoke(rhs)) && isBaseFunc(getCallFunction(rhs), :vcat)