#49: Cast Expressions ------------------------------+--------------------------------------------- Reporter: snarayan | Owner: snarayan Type: defect | Status: new Priority: minor | Milestone: Component: Canonicalization | Version: 2.0 Keywords: | ------------------------------+--------------------------------------------- There seems to be no nice way to handle a type cast expression: void mini2(double *y, double *x) { int i; double j; y[i] = x[(int)(j)]; } The XAIF created is: <xaif:AssignmentLHS> <xaif:SymbolReference annotation="28301536" scope_id="7" symbol_id="y" vertex_id="1"></xaif:SymbolReference> <xaif:ArrayElementReference vertex_id="1"> <xaif:IndexTriplet> <xaif:Index> <xaif:VariableReference vertex_id="4"> <xaif:SymbolReference annotation="28301632" scope_id="8" symbol_id="i" vertex_id="1"></xaif:SymbolReference> </xaif:VariableReference> <xaif:Intrinsic name="sub_scal_scal" vertex_id="6"></xaif:Intrinsic> <xaif:Constant type="integer" value="1" vertex_id="5"></xaif:Constant> <xaif:ExpressionEdge edge_id="1" position="1" source="4" target="6"></xaif:ExpressionEdge> <xaif:ExpressionEdge edge_id="2" position="2" source="5" target="6"></xaif:ExpressionEdge> </xaif:Index> </xaif:IndexTriplet> </xaif:ArrayElementReference> <xaif:VariableReferenceEdge edge_id="1" source="1" target="1"></xaif:VariableReferenceEdge> </xaif:AssignmentLHS> <xaif:AssignmentRHS> <xaif:VariableReference vertex_id="7"> <xaif:SymbolReference annotation="28301584" scope_id="7" symbol_id="x" vertex_id="1"></xaif:SymbolReference> <xaif:ArrayElementReference vertex_id="8"> <xaif:IndexTriplet> <xaif:Index> <xaif:VariableReference vertex_id="11"> <xaif:SymbolReference annotation="34735904" scope_id="8" symbol_id="SgCastExp_34735904" vertex_id="1"></xaif:SymbolReference> </xaif:VariableReference> </xaif:Index> </xaif:IndexTriplet> </xaif:ArrayElementReference> <xaif:VariableReferenceEdge edge_id="1" source="1" target="8"></xaif:VariableReferenceEdge> </xaif:VariableReference> </xaif:AssignmentRHS> </xaif:Assignment> With the derivative code: void ad_mini2(DERIV_TYPE *y,DERIV_TYPE *x) { DERIV_TYPE ad_TempVarprp_1; zero_deriv(&ad_TempVarprp_1); /* int i; double j; y[i - 1] =(x[(int )j]); */ int ad_i; DERIV_TYPE ad_j; DERIV_val(y[ad_i - 1]) = DERIV_val(x[(int )ad_j]); ADIC_SetDeriv(DERIV_TYPE_ref(x[(int )ad_j]),DERIV_TYPE_ref(ad_TempVarprp_1)); ADIC_SetDeriv(DERIV_TYPE_ref(ad_TempVarprp_1),DERIV_TYPE_ref(y[ad_i - 1])); } If type casting cannot be handled by XAIFBooster, then XAIFVistor should ensure that (int )ad_j becomes (int )(ad_j.val()) in the derivative code. This example is unlikely to be a problem very soon. -- Ticket URL: <http://trac.mcs.anl.gov/projects/ADIC/ticket/49> ADIC <http://trac.mcs.anl.gov/projects/ADIC> ADIC: Automatic Differentiation for C and C++