<commit_before>"""
Created on 22. apr. 2015

@author: pab

References
----------
A METHODOLOGY FOR ROBUST OPTIMIZATION OF
LOW-THRUST TRAJECTORIES IN MULTI-BODY
ENVIRONMENTS
<NAME> (2010)
Phd thesis, Georgia Institute of Technology

USING MULTICOMPLEX VARIABLES FOR AUTOMATIC
COMPUTATION OF HIGH-ORDER DERIVATIVES
<NAME>, <NAME> , and <NAME>
ACM Transactions on Mathematical Software, Vol. 38, No. 3, Article 16,
April 2012, 21 pages,
http://doi.acm.org/10.1145/2168773.2168774


<NAME>, <NAME>, <NAME>, <NAME> (2012)
CUBO A Mathematical Journal
Vol. 14, No 2, (61-80). June 2012.

Computation of higher-order derivatives using the multi-complex
step method
<NAME>, (2014)
Project report, NTNU

"""
from __future__ import division
import numpy as np

_TINY = np.finfo(float).machar.tiny


def c_atan2(x, y):
    a, b = np.real(x), np.imag(x)
    c, d = np.real(y), np.imag(y)
    return np.arctan2(a, c) + 1j * (c * b - a * d) / (a**2 + c**2)


def c_max(x, y):
    return np.where(x.real < y.real, y, x)


def c_min(x, y):
    return np.where(x.real > y.real, y, x)


def c_abs(z):
    return np.where(np.real(z) >= 0, z, -z)


class Bicomplex(object):

    """
    BICOMPLEX(z1, z2)

    Creates an instance of a Bicomplex object.
    zeta = z1 + j*z2, where z1 and z2 are complex numbers.
    """

    def __init__(self, z1, z2):
        z1, z2 = np.broadcast_arrays(z1, z2)
        self.z1 = np.asanyarray(z1, dtype=np.complex128)
        self.z2 = np.asanyarray(z2, dtype=np.complex128)

    @property
    def shape(self):
        return self.z1.shape

    @property
    def size(self):
        return self.z1.size

    def mod_c(self):
        """Complex modulus"""
        r12, r22 = self.z1*self.z1, self.z2*self.z2
        r = np.sqrt(r12 + r22)
        return r<commit_msg>Fixed c_abs so it works with algopy on python 3.6.<commit_after>"""
Created on 22. apr. 2015

@author: pab

References
----------
A METHODOLOGY FOR ROBUST OPTIMIZATION OF
LOW-THRUST TRAJECTORIES IN MULTI-BODY
ENVIRONMENTS
<NAME> (2010)
Phd thesis, Georgia Institute of Technology

USING MULTICOMPLEX VARIABLES FOR AUTOMATIC
COMPUTATION OF HIGH-ORDER DERIVATIVES
<NAME>, <NAME> , and <NAME>
ACM Transactions on Mathematical Software, Vol. 38, No. 3, Article 16,
April 2012, 21 pages,
http://doi.acm.org/10.1145/2168773.2168774


<NAME>, <NAME>, <NAME>, <NAME> (2012)
CUBO A Mathematical Journal
Vol. 14, No 2, (61-80). June 2012.

Computation of higher-order derivatives using the multi-complex
step method
<NAME>, (2014)
Project report, NTNU

"""
from __future__ import division
import numpy as np

_TINY = np.finfo(float).machar.tiny


def c_atan2(x, y):
    a, b = np.real(x), np.imag(x)
    c, d = np.real(y), np.imag(y)
    return np.arctan2(a, c) + 1j * (c * b - a * d) / (a**2 + c**2)


def c_max(x, y):
    return np.where(x.real < y.real, y, x)


def c_min(x, y):
    return np.where(x.real > y.real, y, x)


def c_abs(z):
    if np.all(np.iscomplex(z)):
        return np.where(np.real(z) >= 0, z, -z)
    return np.abs(z)


class Bicomplex(object):

    """
    BICOMPLEX(z1, z2)

    Creates an instance of a Bicomplex object.
    zeta = z1 + j*z2, where z1 and z2 are complex numbers.
    """

    def __init__(self, z1, z2):
        z1, z2 = np.broadcast_arrays(z1, z2)
        self.z1 = np.asanyarray(z1, dtype=np.complex128)
        self.z2 = np.asanyarray(z2, dtype=np.complex128)

    @property
    def shape(self):
        return self.z1.shape

    @property
    def size(self):
        return self.z1.size

    def mod_c(self):
        """Complex modulus"""
        r12, r22 = self.z1*self.z1, self.z2*self.z2
        r = np.sqrt(r12 + r22)
        return r
{'fraction_non_alphanumeric': 0.13996719518862766, 'fraction_numerical': 0.056314926189174414, 'mean_word_length': 2.88016967126193, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4989851', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1439, 'n_words': 410}