3
���h� � @ sD d Z ddlZddlZddlZddlmZ dgZG dd� dej �Z
dS )a
Abstract base class for the various polynomial Classes.
The ABCPolyBase class provides the methods needed to implement the common API
for the various polynomial classes. It operates as a mixin, but uses the
abc module from the stdlib, hence it is only available for Python >= 2.6.
� N� )� polyutils�ABCPolyBasec @ s e Zd ZdZdZdZdZeej dd� ��Z
eej dd� ��Zeej dd � ��Zeej d
d� ��Z
eej dd
� ��Zeej dd� ��Zeej dd� ��Zeej dd� ��Zeej d�dd���Zeej dd� ��Zeej dd� ��Zeej dd� ��Zeej dd� ��Zeej dd� ��Zeej d d!� ��Zeej d"d#� ��Zd$d%� Zd&d'� Zd(d)� Zd*d+� Zd,d-� Zd�d.d/�Z d0d1� Z!d2d3� Z"e#d4d5� �Z$ed6d7� �Z%d8d9� Z&d:d;� Z'd<d=� Z(d>d?� Z)d@dA� Z*dBdC� Z+dDdE� Z,dFdG� Z-dHdI� Z.dJdK� Z/dLdM� Z0dNdO� Z1dPdQ� Z2dRdS� Z3dTdU� Z4dVdW� Z5dXdY� Z6dZd[� Z7d\d]� Z8d^d_� Z9d`da� Z:dbdc� Z;ddde� Z<dfdg� Z=dhdi� Z>djdk� Z?dldm� Z@dndo� ZAdpdq� ZBd�dsdt�ZCdudv� ZDd�dwdx�ZEdydz� ZFd{g dfd|d}�ZGd�d~d�ZHd�d�� ZId�d�d��ZJe#d�d�d���ZKe#g dfd�d���ZLe#d�d�d���ZMe#d�d�d���ZNe#d�d�d���ZOdS )�r a� An abstract base class for immutable series classes.
ABCPolyBase provides the standard Python numerical methods
'+', '-', '*', '//', '%', 'divmod', '**', and '()' along with the
methods listed below.
.. versionadded:: 1.9.0
Parameters
----------
coef : array_like
Series coefficients in order of increasing degree, i.e.,
``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``, where
``P_i`` is the basis polynomials of degree ``i``.
domain : (2,) array_like, optional
Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
to the interval ``[window[0], window[1]]`` by shifting and scaling.
The default value is the derived class domain.
window : (2,) array_like, optional
Window, see domain for its use. The default value is the
derived class window.
Attributes
----------
coef : (N,) ndarray
Series coefficients in order of increasing degree.
domain : (2,) ndarray
Domain that is mapped to window.
window : (2,) ndarray
Window that domain is mapped to.
Class Attributes
----------------
maxpower : int
Maximum power allowed, i.e., the largest number ``n`` such that
``p(x)**n`` is allowed. This is to limit runaway polynomial size.
domain : (2,) ndarray
Default domain of the class.
window : (2,) ndarray
Default window of the class.
N�d c C s d S )N� )�selfr r �;/tmp/pip-build-5_djhm0z/numpy/numpy/polynomial/_polybase.py�domainF s zABCPolyBase.domainc C s d S )Nr )r r r r �windowK s zABCPolyBase.windowc C s d S )Nr )r r r r �nicknameP s zABCPolyBase.nicknamec C s d S )Nr )r r r r �
basis_nameU s zABCPolyBase.basis_namec C s d S )Nr )�c1�c2r r r �_addZ s zABCPolyBase._addc C s d S )Nr )r
r r r r �_sub_ s zABCPolyBase._subc C s d S )Nr )r
r r r r �_muld s zABCPolyBase._mulc C s d S )Nr )r
r r r r �_divi s zABCPolyBase._divc C s d S )Nr )�c�pow�maxpowerr r r �_pown s zABCPolyBase._powc C s d S )Nr )�xr r r r �_vals s zABCPolyBase._valc C s d S )Nr )r �m�k�lbnd�sclr r r �_intx s zABCPolyBase._intc C s d S )Nr )r r r r r r �_der} s zABCPolyBase._derc C s d S )Nr )r �y�deg�rcond�fullr r r �_fit� s zABCPolyBase._fitc C s d S )Nr )�offr r r r �_line� s zABCPolyBase._linec C s d S )Nr )r r r r �_roots� s zABCPolyBase._rootsc C s d S )Nr )�rr r r �
_fromroots� s zABCPolyBase._fromrootsc C s6 t | j�t |j�krdS tj| j|jk�s.dS dS dS )aG Check if coefficients match.
.. versionadded:: 1.6.0
Parameters
----------
other : class instance
The other class must have the ``coef`` attribute.
Returns
-------
bool : boolean
True if the coefficients are the same, False otherwise.
FTN)�len�coef�np�all)r �otherr r r �has_samecoef� s
zABCPolyBase.has_samecoefc C s t j| j|jk�S )a? Check if domains match.
.. versionadded:: 1.6.0
Parameters
----------
other : class instance
The other class must have the ``domain`` attribute.
Returns
-------
bool : boolean
True if the domains are the same, False otherwise.
)r+ r, r )r r- r r r �has_samedomain� s zABCPolyBase.has_samedomainc C s t j| j|jk�S )a? Check if windows match.
.. versionadded:: 1.6.0
Parameters
----------
other : class instance
The other class must have the ``window`` attribute.
Returns
-------
bool : boolean
True if the windows are the same, False otherwise.
)r+ r, r
)r r- r r r �has_samewindow� s zABCPolyBase.has_samewindowc C s t || j�S )a Check if types match.
.. versionadded:: 1.7.0
Parameters
----------
other : object
Class instance.
Returns
-------
bool : boolean
True if other is same class as self
)�
isinstance� __class__)r r- r r r �has_sametype� s zABCPolyBase.has_sametypec C s` t |t�r\t || j�s td��n6tj| j|jk�s<td��ntj| j|jk�sVtd��|jS |S )a� Interpret other as polynomial coefficients.
The `other` argument is checked to see if it is of the same
class as self with identical domain and window. If so,
return its coefficients, otherwise return `other`.
.. versionadded:: 1.9.0
Parameters
----------
other : anything
Object to be checked.
Returns
-------
coef
The coefficients of`other` if it is a compatible instance,
of ABCPolyBase, otherwise `other`.
Raises
------
TypeError
When `other` is an incompatible instance of ABCPolyBase.
zPolynomial types differzDomains differzWindows differ) r1 r r2 � TypeErrorr+ r, r r
r* )r r- r r r �_get_coefficients� s
zABCPolyBase._get_coefficientsc C s� t j|gdd�\}|| _|d k rLt j|gdd�\}t|�dkrFtd��|| _|d k r�t j|gdd�\}t|�dkrztd��|| _d S )NF)�trim� z$Domain has wrong number of elements.z$Window has wrong number of elements.)�pu� as_seriesr* r) �
ValueErrorr r
)r r* r r
r r r �__init__ s zABCPolyBase.__init__c C sZ t | j�dd� }t | j�dd� }t | j�dd � }| jj}|� d|� d|� d|� d�S )
N� r �(z , domain=z , window=�)���r? r? )�reprr* r r
r2 �__name__)r r* r r
�namer r r �__repr__ s
zABCPolyBase.__repr__c C s t | j�}| j}|� d|� d�S )Nr= r> |