| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AtanhTransformer |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
| 3 | * contributor license agreements. See the NOTICE file distributed with | |
| 4 | * this work for additional information regarding copyright ownership. | |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| 6 | * (the "License"); you may not use this file except in compliance with | |
| 7 | * the License. You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.apache.commons.nabla.automatic.functions; | |
| 18 | ||
| 19 | import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator; | |
| 20 | import org.objectweb.asm.Opcodes; | |
| 21 | import org.objectweb.asm.tree.InsnList; | |
| 22 | import org.objectweb.asm.tree.InsnNode; | |
| 23 | import org.objectweb.asm.tree.MethodInsnNode; | |
| 24 | ||
| 25 | /** Differentiation transformer for the atanh function invocation instructions. | |
| 26 | * <p>As of java 6, the JVM does not supply an inverse hyperbolic | |
| 27 | * tangent function (see <a | |
| 28 | * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4919337">bug | |
| 29 | * 4919337</a>), so this generator will not be triggered for java 6 and below.</p> | |
| 30 | */ | |
| 31 | 1 | public class AtanhTransformer implements MathInvocationTransformer { |
| 32 | ||
| 33 | /** {@inheritDoc} */ | |
| 34 | public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) { | |
| 35 | ||
| 36 | // generate differential code | |
| 37 | // ... u0, u1 --> ... atanh(u0), u1 / (1 - u0 * u0) | |
| 38 | 1 | final InsnList list = new InsnList(); |
| 39 | 1 | list.add(new InsnNode(Opcodes.DUP2_X2)); |
| 40 | 1 | list.add(new InsnNode(Opcodes.POP2)); |
| 41 | 1 | list.add(new InsnNode(Opcodes.DUP2_X2)); |
| 42 | 1 | list.add(new InsnNode(Opcodes.DUP2)); |
| 43 | 1 | list.add(new InsnNode(Opcodes.DMUL)); |
| 44 | 1 | list.add(new InsnNode(Opcodes.DCONST_1)); |
| 45 | 1 | list.add(new InsnNode(Opcodes.DSUB)); |
| 46 | 1 | list.add(new InsnNode(Opcodes.DNEG)); |
| 47 | 1 | list.add(new InsnNode(Opcodes.DDIV)); |
| 48 | 1 | list.add(new InsnNode(Opcodes.DUP2_X2)); |
| 49 | 1 | list.add(new InsnNode(Opcodes.POP2)); |
| 50 | 1 | list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "atanh", D_RETURN_D_DESCRIPTOR)); |
| 51 | 1 | list.add(new InsnNode(Opcodes.DUP2_X2)); |
| 52 | 1 | list.add(new InsnNode(Opcodes.POP2)); |
| 53 | 1 | return list; |
| 54 | ||
| 55 | } | |
| 56 | } |