org.apache.commons.nabla.forward.analysis
Class MethodDifferentiator

java.lang.Object
  extended by org.apache.commons.nabla.forward.analysis.MethodDifferentiator

public class MethodDifferentiator
extends Object

Class transforming a method computing a value to a method computing both a value and its differential.

Version:
$Id$

Constructor Summary
MethodDifferentiator(Set<String> mathClasses, String derivedName)
          Build a differentiator for a method.
 
Method Summary
 void differentiate(String primitiveName, org.objectweb.asm.tree.MethodNode method)
          Differentiate a method.
 org.objectweb.asm.tree.InsnList doubleToDerivativeStructureConversion()
          Create instructions to convert a double on top of stack to a DerivativeStructure.
 int getInputDSIndex()
          Get the index of the input derivative structure variable.
 int getTmp(int number)
          Get index of a size 2 temporary variable.
 boolean isMathImplementationClass(String name)
          Test if a class is a math implementation class.
 void useLocal(int index, int size)
          Set a local variable as used by the modified code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodDifferentiator

public MethodDifferentiator(Set<String> mathClasses,
                            String derivedName)
Build a differentiator for a method.

Parameters:
mathClasses - math implementation classes
derivedName - name of the derived class
Method Detail

getInputDSIndex

public int getInputDSIndex()
Get the index of the input derivative structure variable.

Returns:
index of the input derivative structure variable

differentiate

public void differentiate(String primitiveName,
                          org.objectweb.asm.tree.MethodNode method)
                   throws DifferentiationException
Differentiate a method.

Parameters:
primitiveName - primitive class name
method - method to differentiate (will be modified)
Throws:
DifferentiationException - if method cannot be differentiated

isMathImplementationClass

public boolean isMathImplementationClass(String name)
Test if a class is a math implementation class.

Parameters:
name - name of the class to test
Returns:
true if the named class is a math implementation class

doubleToDerivativeStructureConversion

public org.objectweb.asm.tree.InsnList doubleToDerivativeStructureConversion()
Create instructions to convert a double on top of stack to a DerivativeStructure.

Returns:
list of conversion instructions

useLocal

public void useLocal(int index,
                     int size)
              throws DifferentiationException
Set a local variable as used by the modified code.

Parameters:
index - index of the variable
size - size of the variable (1 or 2 for standard variables, 4 for special expanded derivative structures)
Throws:
DifferentiationException - if the number of the temporary variable lies outside of the allowed range

getTmp

public int getTmp(int number)
           throws DifferentiationException
Get index of a size 2 temporary variable.

Temporary variables can be used for very short duration storage of size 2 values (i.e one double, or one long or two integers). These variables are reused in many replacement instructions sequences, so their content may be overridden at any time: they should be considered to have a scope limited to one replacement sequence only. This means that one should not store a value in a variable in one replacement sequence and retrieve it later in another replacement sequence as it may have been overridden in between.

At most 5 temporary variables may be used.

Parameters:
number - number of the temporary variable (must be between 1 and the maximal number of available temporary variables)
Returns:
index of the variable within the local variables array
Throws:
DifferentiationException - if the number of the temporary variable lies outside of the allowed range


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.