<commit_before>import numpy

import cupy
from cupy.core.core cimport ndarray


cdef class poly1d:
    """A one-dimensional polynomial class.

    Args:
        c_or_r (array_like): The polynomial's
         coefficients in decreasing powers
        r (bool, optional): If True, ```c_or_r`` specifies the
            polynomial's roots; the default is False.
        variable (str, optional): Changes the variable used when
            printing the polynomial from ``x`` to ``variable``

    .. seealso:: :func:`numpy.poly1d`

    """
    __hash__ = None

    cdef:
        readonly ndarray _coeffs
        readonly str _variable

    @property
    def coeffs(self):
        return self._coeffs

    @coeffs.setter
    def coeffs(self, value):
        if value is not self._coeffs:
            raise AttributeError('Cannot set attribute')

    @property
    def variable(self):
        return self._variable

    @property
    def order(self):
        return self._coeffs.size - 1

    # TODO(Dahlia-Chehata): implement using cupy.roots
    @property
    def roots(self):
        raise NotImplementedError

    @property
    def r(self):
        return self.roots

    @property
    def c(self):
        return self.coeffs

    @property
    def coef(self):
        return self.coeffs

    @property
    def coefficients(self):
        return self.coeffs

    @property
    def o(self):
        return self.order

    def __init__(self, c_or_r, r=False, variable=None):
        if isinstance(c_or_r, numpy.poly1d):
            self._coeffs = cupy.empty(c_or_r.coeffs.shape,
                                     c_or_r.coeffs.dtype)
            self._coeffs.set(c_or_r.coeffs)
        if isinstance(c_or_r, poly1d):
            self._coeffs = c_or_r._coeffs
        if isinstance(c_or_r, (numpy.poly1d, poly1d)):
            self._variable = c_or_r._variable
            if variable is not None:
                self._variable = variable
            return
        # TODO(Dahlia-Chehata): if r: c_or_r = poly(c_or_r)
        if c_or_r.ndim < 1:
            c_or_r = cupy.atleast_1d(c_or_r)
        if c_or_r.ndim > 1:
            raise ValueError('Polynomial must be 1d only.')
        c_or_r = cupy.trim_zeros(c_or_r, trim='f')
        if c_or_r.size == 0:
            c_or_r = cupy.array([0.])
        self._coeffs = c_or_r
        if variable is None:
            variable = 'x'
        self._variable = variable

    def __array__(self, dtype=None):
        raise TypeError(
            'Implicit conversion to a NumPy array is not allowed. '
            'Please use `.get()` to construct a NumPy array explicitly.')
<commit_msg>fixing indentation<commit_after>import numpy

import cupy
from cupy.core.core cimport ndarray


cdef class poly1d:
    """A one-dimensional polynomial class.

    Args:
        c_or_r (array_like): The polynomial's
         coefficients in decreasing powers
        r (bool, optional): If True, ```c_or_r`` specifies the
            polynomial's roots; the default is False.
        variable (str, optional): Changes the variable used when
            printing the polynomial from ``x`` to ``variable``

    .. seealso:: :func:`numpy.poly1d`

    """
    __hash__ = None

    cdef:
        readonly ndarray _coeffs
        readonly str _variable

    @property
    def coeffs(self):
        return self._coeffs

    @coeffs.setter
    def coeffs(self, value):
        if value is not self._coeffs:
            raise AttributeError('Cannot set attribute')

    @property
    def variable(self):
        return self._variable

    @property
    def order(self):
        return self._coeffs.size - 1

    # TODO(Dahlia-Chehata): implement using cupy.roots
    @property
    def roots(self):
        raise NotImplementedError

    @property
    def r(self):
        return self.roots

    @property
    def c(self):
        return self.coeffs

    @property
    def coef(self):
        return self.coeffs

    @property
    def coefficients(self):
        return self.coeffs

    @property
    def o(self):
        return self.order

    def __init__(self, c_or_r, r=False, variable=None):
        if isinstance(c_or_r, numpy.poly1d):
            self._coeffs = cupy.empty(c_or_r.coeffs.shape,
                                      c_or_r.coeffs.dtype)
            self._coeffs.set(c_or_r.coeffs)
        if isinstance(c_or_r, poly1d):
            self._coeffs = c_or_r._coeffs
        if isinstance(c_or_r, (numpy.poly1d, poly1d)):
            self._variable = c_or_r._variable
            if variable is not None:
                self._variable = variable
            return
        # TODO(Dahlia-Chehata): if r: c_or_r = poly(c_or_r)
        if c_or_r.ndim < 1:
            c_or_r = cupy.atleast_1d(c_or_r)
        if c_or_r.ndim > 1:
            raise ValueError('Polynomial must be 1d only.')
        c_or_r = cupy.trim_zeros(c_or_r, trim='f')
        if c_or_r.size == 0:
            c_or_r = cupy.array([0.])
        self._coeffs = c_or_r
        if variable is None:
            variable = 'x'
        self._variable = variable

    def __array__(self, dtype=None):
        raise TypeError(
            'Implicit conversion to a NumPy array is not allowed. '
            'Please use `.get()` to construct a NumPy array explicitly.')

{'fraction_non_alphanumeric': 0.08997722095671981, 'fraction_numerical': 0.004935459377372817, 'mean_word_length': 1.9751552795031055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4297101', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1675, 'n_words': 437}