commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1392960 - in /commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward: analysis/ arithmetic/ instructions/
Date Tue, 02 Oct 2012 15:14:20 GMT
Author: luc
Date: Tue Oct  2 15:14:19 2012
New Revision: 1392960

URL: http://svn.apache.org/viewvc?rev=1392960&view=rev
Log:
Allow all instructions transformers to access a reference
DerivativeStructure.

Modified:
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/InstructionsTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DAddTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DDivTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DMulTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DNegTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DSubTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DLoadTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DReturnTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DStoreTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2Transformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X1Transformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X2Transformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/GetFieldTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/InvokeStaticTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/NarrowingTransformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Pop2Transformer.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/WideningTransformer.java

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java
Tue Oct  2 15:14:19 2012
@@ -148,7 +148,8 @@ public class ClassDifferentiator {
 
                 final MethodDifferentiator differentiator =
                         new MethodDifferentiator(mathClasses, classNode.name);
-                differentiator.differentiate(primitiveNode.name, method);
+                differentiator.differentiate(primitiveNode.name, method,
+                                             Type.getMethodType(derivativeDesc));
                 classNode.methods.add(method);
 
             }

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/InstructionsTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/InstructionsTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/InstructionsTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/InstructionsTransformer.java
Tue Oct  2 15:14:19 2012
@@ -35,12 +35,14 @@ public interface InstructionsTransformer
     /** Get the replacement instructions.
      * @param original original instruction
      * @param methodDifferentiator method differentiator driving this transformer
+     * @param dsIndex index of a reference {@link DerivativeStructure derivative structure}
variable
      * @return replacement instructions
      * @exception DifferentiationException if the method differentiator cannot provide
      * a temporary variable
      */
     InsnList getReplacement(AbstractInsnNode original,
-                            MethodDifferentiator methodDifferentiator)
+                            MethodDifferentiator methodDifferentiator,
+                            int dsIndex)
         throws DifferentiationException;
 
 }

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java
Tue Oct  2 15:14:19 2012
@@ -96,15 +96,6 @@ public class MethodDifferentiator {
         this.successors   = new IdentityHashMap<AbstractInsnNode, Set<AbstractInsnNode>>();
     }
 
-    /** Get the index of the input {@link DerivativeStructure derivative structure} variable.
-     * @return index of the input {@link DerivativeStructure derivative structure} variable
-     */
-    public int getInputDSIndex() {
-        // TODO: this should be improved in the general case,
-        // as we are not sure the variable will always remain at index 1
-        return 1;
-    }
-
     /** Get the name of the derived class.
      * @return name of the derived class
      */
@@ -116,13 +107,16 @@ public class MethodDifferentiator {
      * Differentiate a method.
      * @param primitiveName primitive class name
      * @param method method to differentiate (<em>will</em> be modified)
+     * @param derivedMethodType type of the derived method
      * @exception DifferentiationException if method cannot be differentiated
      */
-    public void differentiate(final String primitiveName, final MethodNode method)
+    public void differentiate(final String primitiveName, final MethodNode method,
+                              final Type derivedMethodType)
         throws DifferentiationException {
         try {
 
-            final Type dsType = Type.getType(DerivativeStructure.class);
+            final int     dsIndex  = method.maxLocals;
+            final boolean isStatic = (method.access & Opcodes.ACC_STATIC) != 0;
 
             // analyze the original code, tracing values production/consumption
             final FlowAnalyzer analyzer =
@@ -150,7 +144,7 @@ public class MethodDifferentiator {
                 for (final Iterator<AbstractInsnNode> i = method.instructions.iterator();
i.hasNext();) {
                     final AbstractInsnNode insn = i.next();
                     if (insn.getOpcode() == Opcodes.DRETURN) {
-                        final InsnList list = new DReturnTransformer(false).getReplacement(insn,
this);
+                        final InsnList list = new DReturnTransformer(false).getReplacement(insn,
this, dsIndex);
                         method.instructions.insert(insn, list);
                         method.instructions.remove(insn);
                     }
@@ -160,7 +154,7 @@ public class MethodDifferentiator {
 
                 // perform the code changes
                 for (final AbstractInsnNode insn : changes) {
-                    method.instructions.insert(insn, getReplacement(insn));
+                    method.instructions.insert(insn, getReplacement(insn, method.maxLocals));
                     method.instructions.remove(insn);
                 }
 
@@ -171,9 +165,13 @@ public class MethodDifferentiator {
 
             }
 
+            // insert the preservation of the reference derivative structure
+            method.instructions.insert(preserveReferenceDerivativeStructure(derivedMethodType,
isStatic, dsIndex));
+
             // set the method properties
-            method.desc    = Type.getMethodDescriptor(dsType, dsType);
-            method.access |= Opcodes.ACC_SYNTHETIC;
+            method.desc      = derivedMethodType.getDescriptor();
+            method.access   |= Opcodes.ACC_SYNTHETIC;
+            method.maxLocals = dsIndex + 1;
 
         } catch (AnalyzerException ae) {
             ae.printStackTrace(System.err);
@@ -325,60 +323,61 @@ public class MethodDifferentiator {
 
     /** Get the replacement list for an instruction.
      * @param insn instruction to replace
+     * @param dsIndex index of a reference {@link DerivativeStructure derivative structure}
variable
      * @return replacement instructions list
      * @exception DifferentiationException if some instruction cannot be handled
      */
-    private InsnList getReplacement(final AbstractInsnNode insn)
+    private InsnList getReplacement(final AbstractInsnNode insn, final int dsIndex)
         throws DifferentiationException {
 
         switch(insn.getOpcode()) {
             case Opcodes.DLOAD :
-                return new DLoadTransformer().getReplacement(insn, this);
+                return new DLoadTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DALOAD :
                 // TODO: add support for DALOAD differentiation
                 throw new RuntimeException("DALOAD not handled yet");
             case Opcodes.DSTORE :
-                return new DStoreTransformer().getReplacement(insn, this);
+                return new DStoreTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DASTORE :
                 // TODO: add support for DASTORE differentiation
                 throw new RuntimeException("DASTORE not handled yet");
             case Opcodes.DUP2 :
-                return new Dup2Transformer().getReplacement(insn, this);
+                return new Dup2Transformer().getReplacement(insn, this, dsIndex);
             case Opcodes.POP2 :
-                return new Pop2Transformer().getReplacement(insn, this);
+                return new Pop2Transformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DUP2_X1 :
-                return new Dup2X1Transformer().getReplacement(insn, this);
+                return new Dup2X1Transformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DUP2_X2 :
-                return new Dup2X2Transformer().getReplacement(insn, this);
+                return new Dup2X2Transformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DADD :
-                return new DAddTransformer().getReplacement(insn, this);
+                return new DAddTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DSUB :
-                return new DSubTransformer().getReplacement(insn, this);
+                return new DSubTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DMUL :
-                return new DMulTransformer().getReplacement(insn, this);
+                return new DMulTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DDIV :
-                return new DDivTransformer().getReplacement(insn, this);
+                return new DDivTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DREM :
-                return new DRemTransformer().getReplacement(insn, this);
+                return new DRemTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DNEG :
-                return new DNegTransformer().getReplacement(insn, this);
+                return new DNegTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DCONST_0 :
             case Opcodes.DCONST_1 :
             case Opcodes.LDC :
             case Opcodes.I2D :
             case Opcodes.L2D :
             case Opcodes.F2D :
-                return new WideningTransformer().getReplacement(insn, this);
+                return new WideningTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.D2I :
             case Opcodes.D2L :
             case Opcodes.D2F :
-                return new NarrowingTransformer().getReplacement(insn, this);
+                return new NarrowingTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DCMPL :
             case Opcodes.DCMPG :
-                return new DcmpTransformer().getReplacement(insn, this);
+                return new DcmpTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.DRETURN :
                 // TODO: the constructor parameter forced to true seems strange...
-                return new DReturnTransformer(true).getReplacement(insn, this);
+                return new DReturnTransformer(true).getReplacement(insn, this, dsIndex);
             case Opcodes.GETSTATIC :
                 // TODO: add support for GETSTATIC differentiation
                 throw new RuntimeException("GETSTATIC not handled yet");
@@ -386,7 +385,7 @@ public class MethodDifferentiator {
                 // TODO: add support for PUTSTATIC differentiation
                 throw new RuntimeException("PUTSTATIC not handled yet");
             case Opcodes.GETFIELD :
-                return new GetFieldTransformer().getReplacement(insn, this);
+                return new GetFieldTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.PUTFIELD :
                 // TODO: add support for PUTFIELD differentiation
                 throw new RuntimeException("PUTFIELD not handled yet");
@@ -397,7 +396,7 @@ public class MethodDifferentiator {
                 // TODO: add support for INVOKESPECIAL differentiation
                 throw new RuntimeException("INVOKESPECIAL not handled yet");
             case Opcodes.INVOKESTATIC :
-                return new InvokeStaticTransformer().getReplacement(insn, this);
+                return new InvokeStaticTransformer().getReplacement(insn, this, dsIndex);
             case Opcodes.INVOKEINTERFACE :
                 // TODO: add support for INVOKEINTERFACE differentiation
                 throw new RuntimeException("INVOKEINTERFACE not handled yet");
@@ -427,10 +426,40 @@ public class MethodDifferentiator {
         return mathClasses.contains(name);
     }
 
+    /** Create instructions to preserve a reference {@link DerivativeStructure} variable.
+     * @param derivedMethodType type of the derived method
+     * @param isStatic if true, the method is a static method
+     * @param dsIndex index of the reference {@link DerivativeStructure derivative structure}
variable
+     * @return list of conversion instructions
+     */
+    public InsnList preserveReferenceDerivativeStructure(final Type derivedMethodType,
+                                                         final boolean isStatic, final int
dsIndex) {
+
+        final Type dsType = Type.getType(DerivativeStructure.class);
+        final Type[] parameterTypes = derivedMethodType.getArgumentTypes();
+        for (int i = 0; i < parameterTypes.length; ++i) {
+            if (parameterTypes[i].equals(dsType)) {
+                // we have found the first derivative structure parameter
+
+                // preserve the parameter as a new variable
+                final InsnList list = new InsnList();
+                list.add(new VarInsnNode(Opcodes.ALOAD, isStatic ? i : (i + 1)));
+                list.add(new VarInsnNode(Opcodes.ASTORE, dsIndex));
+                return list;
+            }
+
+        }
+
+        // this should never happen as we build class that do use DerivativeStructure
+        throw DifferentiationException.createInternalError(null);
+
+    }
+
     /** Create instructions to convert a double on top of stack to a {@link DerivativeStructure}.
+     * @param dsIndex index of a reference {@link DerivativeStructure derivative structure}
variable
      * @return list of conversion instructions
      */
-    public InsnList doubleToDerivativeStructureConversion() {
+    public InsnList doubleToDerivativeStructureConversion(final int dsIndex) {
 
         final InsnList list = new InsnList();
 
@@ -440,7 +469,7 @@ public class MethodDifferentiator {
         list.add(new InsnNode(Opcodes.DUP_X2));                                      // =>
y_ds d y_ds
         list.add(new InsnNode(Opcodes.DUP_X2));                                      // =>
y_ds y_ds d y_ds
         list.add(new InsnNode(Opcodes.POP));                                         // =>
y_ds y_ds d
-        list.add(new VarInsnNode(Opcodes.ALOAD, getInputDSIndex()));                 // =>
y_ds y_ds d x_ds
+        list.add(new VarInsnNode(Opcodes.ALOAD, dsIndex));                           // =>
y_ds y_ds d x_ds
         list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
                                     Type.getInternalName(DerivativeStructure.class),
                                     "getFreeParameters",

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DAddTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DAddTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DAddTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DAddTransformer.java
Tue Oct  2 15:14:19 2012
@@ -36,7 +36,8 @@ public class DAddTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DDivTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DDivTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DDivTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DDivTransformer.java
Tue Oct  2 15:14:19 2012
@@ -42,7 +42,8 @@ public class DDivTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DMulTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DMulTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DMulTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DMulTransformer.java
Tue Oct  2 15:14:19 2012
@@ -36,7 +36,8 @@ public class DMulTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DNegTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DNegTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DNegTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DNegTransformer.java
Tue Oct  2 15:14:19 2012
@@ -38,7 +38,8 @@ public class DNegTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DRemTransformer.java
Tue Oct  2 15:14:19 2012
@@ -48,7 +48,8 @@ public class DRemTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DSubTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DSubTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DSubTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/arithmetic/DSubTransformer.java
Tue Oct  2 15:14:19 2012
@@ -39,7 +39,8 @@ public class DSubTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DLoadTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DLoadTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DLoadTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DLoadTransformer.java
Tue Oct  2 15:14:19 2012
@@ -40,7 +40,8 @@ public class DLoadTransformer implements
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
         final int var = ((VarInsnNode) insn).var;
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DReturnTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DReturnTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DReturnTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DReturnTransformer.java
Tue Oct  2 15:14:19 2012
@@ -45,14 +45,15 @@ public class DReturnTransformer implemen
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();
 
         if (!stack0Converted) {
             // add conversion for top level stack element
-            list.add(methodDifferentiator.doubleToDerivativeStructureConversion());
+            list.add(methodDifferentiator.doubleToDerivativeStructureConversion(dsIndex));
         }
 
         // add the return instruction for a reference type

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DStoreTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DStoreTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DStoreTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DStoreTransformer.java
Tue Oct  2 15:14:19 2012
@@ -40,7 +40,8 @@ public class DStoreTransformer implement
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
         final int var = ((VarInsnNode) insn).var;
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/DcmpTransformer.java
Tue Oct  2 15:14:19 2012
@@ -36,7 +36,8 @@ public class DcmpTransformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
         final InsnList list = new InsnList();
 

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2Transformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2Transformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2Transformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2Transformer.java
Tue Oct  2 15:14:19 2012
@@ -40,7 +40,8 @@ public class Dup2Transformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X1Transformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X1Transformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X1Transformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X1Transformer.java
Tue Oct  2 15:14:19 2012
@@ -40,7 +40,8 @@ public class Dup2X1Transformer implement
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X2Transformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X2Transformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X2Transformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Dup2X2Transformer.java
Tue Oct  2 15:14:19 2012
@@ -31,7 +31,8 @@ public class Dup2X2Transformer implement
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/GetFieldTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/GetFieldTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/GetFieldTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/GetFieldTransformer.java
Tue Oct  2 15:14:19 2012
@@ -44,7 +44,8 @@ public class GetFieldTransformer impleme
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final FieldInsnNode fieldInsn = (FieldInsnNode) insn;

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/InvokeStaticTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/InvokeStaticTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/InvokeStaticTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/InvokeStaticTransformer.java
Tue Oct  2 15:14:19 2012
@@ -35,7 +35,8 @@ public class InvokeStaticTransformer imp
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final MethodInsnNode methodInsn = (MethodInsnNode) insn;
@@ -82,10 +83,10 @@ public class InvokeStaticTransformer imp
                 } else {
 
                     // initial stack state: x, ds_y
-                    list.add(new InsnNode(Opcodes.DUP_X2));                             
   // => ds_y, x, ds_y
-                    list.add(new InsnNode(Opcodes.POP));                                
   // => ds_y, x
-                    list.add(methodDifferentiator.doubleToDerivativeStructureConversion());
// => ds_y, ds_x
-                    list.add(new InsnNode(Opcodes.SWAP));                               
   // => ds_x, ds_y
+                    list.add(new InsnNode(Opcodes.DUP_X2));                             
          // => ds_y, x, ds_y
+                    list.add(new InsnNode(Opcodes.POP));                                
          // => ds_y, x
+                    list.add(methodDifferentiator.doubleToDerivativeStructureConversion(dsIndex));
// => ds_y, ds_x
+                    list.add(new InsnNode(Opcodes.SWAP));                               
          // => ds_x, ds_y
 
                     // call the static two parameters method for DerivativeStructure
                     list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
@@ -98,14 +99,14 @@ public class InvokeStaticTransformer imp
                 if (methodDifferentiator.stackElementIsConverted(insn, 1)) {
                     if (!methodDifferentiator.stackElementIsConverted(insn, 0)) {
                         // the top level element is not a DerivativeStructure, convert it
-                        list.add(methodDifferentiator.doubleToDerivativeStructureConversion());
+                        list.add(methodDifferentiator.doubleToDerivativeStructureConversion(dsIndex));
                     }
                 } else {
                     // initial stack state: x, ds_y
-                    list.add(new InsnNode(Opcodes.DUP_X2));                             
   // => ds_y, x, ds_y
-                    list.add(new InsnNode(Opcodes.POP));                                
   // => ds_y, x
-                    list.add(methodDifferentiator.doubleToDerivativeStructureConversion());
// => ds_y, ds_x
-                    list.add(new InsnNode(Opcodes.SWAP));                               
   // => ds_x, ds_y
+                    list.add(new InsnNode(Opcodes.DUP_X2));                             
          // => ds_y, x, ds_y
+                    list.add(new InsnNode(Opcodes.POP));                                
          // => ds_y, x
+                    list.add(methodDifferentiator.doubleToDerivativeStructureConversion(dsIndex));
// => ds_y, ds_x
+                    list.add(new InsnNode(Opcodes.SWAP));                               
          // => ds_x, ds_y
                 }
 
                 // call the static two parameters method for DerivativeStructure

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/NarrowingTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/NarrowingTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/NarrowingTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/NarrowingTransformer.java
Tue Oct  2 15:14:19 2012
@@ -39,7 +39,8 @@ public class NarrowingTransformer implem
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Pop2Transformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Pop2Transformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Pop2Transformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/Pop2Transformer.java
Tue Oct  2 15:14:19 2012
@@ -40,7 +40,8 @@ public class Pop2Transformer implements 
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/WideningTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/WideningTransformer.java?rev=1392960&r1=1392959&r2=1392960&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/WideningTransformer.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/instructions/WideningTransformer.java
Tue Oct  2 15:14:19 2012
@@ -16,19 +16,14 @@
  */
 package org.apache.commons.nabla.forward.instructions;
 
-import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
 import org.apache.commons.nabla.DifferentiationException;
 import org.apache.commons.nabla.forward.analysis.InstructionsTransformer;
 import org.apache.commons.nabla.forward.analysis.MethodDifferentiator;
 import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
 import org.objectweb.asm.tree.AbstractInsnNode;
 import org.objectweb.asm.tree.InsnList;
 import org.objectweb.asm.tree.InsnNode;
 import org.objectweb.asm.tree.LdcInsnNode;
-import org.objectweb.asm.tree.MethodInsnNode;
-import org.objectweb.asm.tree.TypeInsnNode;
-import org.objectweb.asm.tree.VarInsnNode;
 
 /** Differentiation transformer for promoting a double on the stack
  * to a derivative structure.
@@ -43,7 +38,8 @@ public class WideningTransformer impleme
 
     /** {@inheritDoc} */
     public InsnList getReplacement(final AbstractInsnNode insn,
-                                   final MethodDifferentiator methodDifferentiator)
+                                   final MethodDifferentiator methodDifferentiator,
+                                   final int dsIndex)
         throws DifferentiationException {
 
         final InsnList list = new InsnList();
@@ -55,31 +51,8 @@ public class WideningTransformer impleme
             list.add(new InsnNode(insn.getOpcode()));
         }
 
-        // operand stack initial state: d
-        list.add(new TypeInsnNode(Opcodes.NEW,
-                                  Type.getInternalName(DerivativeStructure.class)));    
 // => d y_ds
-        list.add(new InsnNode(Opcodes.DUP_X2));                                         
 // => y_ds d y_ds
-        list.add(new InsnNode(Opcodes.DUP_X2));                                         
 // => y_ds y_ds d y_ds
-        list.add(new InsnNode(Opcodes.POP));                                            
 // => y_ds y_ds d
-        list.add(new VarInsnNode(Opcodes.ALOAD, methodDifferentiator.getInputDSIndex()));
// => y_ds y_ds d x_ds
-        list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
-                                    Type.getInternalName(DerivativeStructure.class),
-                                    "getFreeParameters",
-                                    Type.getMethodDescriptor(Type.INT_TYPE)));          
 // => y_ds y_ds d params
-        list.add(new VarInsnNode(Opcodes.ALOAD, 1));                                    
 // => y_ds y_ds d params x_ds
-        list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
-                                    Type.getInternalName(DerivativeStructure.class),
-                                    "getOrder",
-                                    Type.getMethodDescriptor(Type.INT_TYPE)));          
 // => y_ds y_ds d params order
-        list.add(new InsnNode(Opcodes.DUP2_X2));                                        
 // => y_ds y_ds params order d params order
-        list.add(new InsnNode(Opcodes.POP2));                                           
 // => y_ds y_ds params order d
-        list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
-                                    Type.getInternalName(DerivativeStructure.class),
-                                    "<init>",
-                                    Type.getMethodDescriptor(Type.VOID_TYPE,
-                                                             Type.INT_TYPE,
-                                                             Type.INT_TYPE,
-                                                             Type.DOUBLE_TYPE)));       
 // => y_ds
+        // convert the double element
+        list.add(methodDifferentiator.doubleToDerivativeStructureConversion(dsIndex));
 
         return list;
 



Mime
View raw message