<commit_before># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
import abc

# Third-party
import numpy as np
from astropy.constants import G
import astropy.units as u
from astropy.utils import isiterable
import six

# Project
from ..integrate import *
from ..util import inherit_docs, ImmutableDict

__all__ = ["PotentialBase", "CompositePotential"]

class MetaPotential(type):
    # def __init__(cls, name, bases, dct):
    #     super(MetaPotential, cls).__init__(name, bases, dct)

    #     if name != 'PotentialBase' and 'units' not in dct:
    #         raise NotImplementedError("Potentials must have a 'units' attribute that "
    #                                   "defines a valid system of units.")

    #     if name != 'PotentialBase' and 'parameters' not in dct:
    #         raise NotImplementedError("Potentials must have a 'parameters' attribute that "
    #                                   "contains the parameters to pass to its methods.")
    pass


@six.add_metaclass(MetaPotential)
class PotentialBase(object):
    """
    A baseclass for defining gravitational potentials.

    You must specify
    a function that evaluates the potential value (func). You may also
    optionally add a function that computes derivatives (gradient), and a
    function to compute the Hessian of the potential.

    Parameters
    ----------
    func : function
        A function that computes the value of the potential.
    units : iterable
        A list of astropy.units.Unit objects that define a complete unit system.
        Must include at least a length unit, time unit, and mass unit.
    gradient : function (optional)
        A function that computes the first derivatives (gradient) of the potential.
    hessian : function (optional)
        A function that computes the second derivatives (Hessian) of the potential.
    parameters : dict (optional)
        Any extra parameters that the functions (func, gradient, hessian)
        require. All functions must take the same parameters.

    """

    @abc.abstractmethod
    def _value(self):
        raise NotImplementedError()

    def value(self, x):
        """
        Compute the value of the potential at the given position(s).

        Parameters
        ----------
        x : array_like, numeric
            Position to compute the value of the potential.
        """
        return self._value(np.atleast_2d(x), **self.parameters)

    def _gradient(self, *args, **kwargs):
        raise NotImplementedError()

    def gradient(self, x):
        """
        Compute the gradient of the potential at the given position(s).

        Parameters
        ----------
        x : array_like, numeric
            Position to compute the gradient.
        """
        if self._gradient is None:<commit_msg>added a default init<commit_after># coding: utf-8

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
import abc

# Third-party
import numpy as np
from astropy.constants import G
import astropy.units as u
from astropy.utils import isiterable
import six

# Project
from ..integrate import *
from ..util import inherit_docs, ImmutableDict

__all__ = ["PotentialBase", "CompositePotential"]

class MetaPotential(type):
    # def __init__(cls, name, bases, dct):
    #     super(MetaPotential, cls).__init__(name, bases, dct)

    #     if name != 'PotentialBase' and 'units' not in dct:
    #         raise NotImplementedError("Potentials must have a 'units' attribute that "
    #                                   "defines a valid system of units.")

    #     if name != 'PotentialBase' and 'parameters' not in dct:
    #         raise NotImplementedError("Potentials must have a 'parameters' attribute that "
    #                                   "contains the parameters to pass to its methods.")
    pass


@six.add_metaclass(MetaPotential)
class PotentialBase(object):
    """
    A baseclass for defining gravitational potentials.

    You must specify
    a function that evaluates the potential value (func). You may also
    optionally add a function that computes derivatives (gradient), and a
    function to compute the Hessian of the potential.

    Parameters
    ----------
    func : function
        A function that computes the value of the potential.
    units : iterable
        A list of astropy.units.Unit objects that define a complete unit system.
        Must include at least a length unit, time unit, and mass unit.
    gradient : function (optional)
        A function that computes the first derivatives (gradient) of the potential.
    hessian : function (optional)
        A function that computes the second derivatives (Hessian) of the potential.
    parameters : dict (optional)
        Any extra parameters that the functions (func, gradient, hessian)
        require. All functions must take the same parameters.

    """

    def __init__(self, units=None, **parameters):
        self.units = units
        self.parameters = parameters

    @abc.abstractmethod
    def _value(self):
        raise NotImplementedError()

    def value(self, x):
        """
        Compute the value of the potential at the given position(s).

        Parameters
        ----------
        x : array_like, numeric
            Position to compute the value of the potential.
        """
        return self._value(np.atleast_2d(x), **self.parameters)

    def _gradient(self, *args, **kwargs):
        raise NotImplementedError()

    def gradient(self, x):
        """
        Compute the gradient of the potential at the given position(s).

        Parameters
        ----------
        x : array_like, numeric
            Position to compute the gradient.
        """
        if self._gradient is None:
{'fraction_non_alphanumeric': 0.08244589488148403, 'fraction_numerical': 0.0006870491240123669, 'mean_word_length': 2.4394565859421147, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4786055', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1470, 'n_words': 600}