<commit_before>What it is Numexpr?
===================

Numexpr is a fast numerical expression evaluator for NumPy.  With it,
expressions that operate on arrays (like "3*a+4*b") are accelerated
and use less memory than doing the same calculation in Python.

In addition, its multi-threaded capabilities can make use of all your
cores, which may accelerate computations, most specially if they are
not memory-bounded (e.g. those using transcendental functions).

Last but not least, numexpr can make use of Intel's VML (Vector Math
Library, normally integrated in its Math Kernel Library, or MKL).
This allows further acceleration of transcendent expressions.


Examples of use
===============

::

  >>> import numpy as np
  >>> import numexpr as ne

  >>> a = np.arange(1e6)   # Choose large arrays
  >>> b = np.arange(1e6)

  >>> ne.evaluate("a + 1")   # a simple expression
  array([  1.00000000e+00,   2.00000000e+00,   3.00000000e+00, ...,
           9.99998000e+05,   9.99999000e+05,   1.00000000e+06])

  >>> ne.evaluate('a*b-4.1*a > 2.5*b')   # a more complex one
  array([False, False, False, ...,  True,  True,  True], dtype=bool)

  >>> ne.evaluate("sin(a) + arcsinh(a/b)")   # you can also use functions
  array([        NaN,  1.72284457,  1.79067101, ...,  1.09567006,
          0.17523598, -0.09597844])

  >>> s = np.array(['abba', 'abbb', 'abbcdef'])
  >>> ne.evaluate("'abba' == s")   # string arrays are supported too
  array([ True, False, False], dtype=bool)


Datatypes supported internally
==============================

Numexpr operates internally only with the following types::

    * 8-bit boolean (bool)
    * 32-bit signed integer (int or int32)
    * 64-bit signed integer (long or int64)
    * 32-bit single-precision floating point number (float or float32)
    * 64-bit, double-precision floating point number (double or float64)
    * 2x64-bit, double-precision complex number (complex or complex128)
    * Raw string of bytes (str)

If the arrays in the expression does not match any of these types,
they will be upcasted to one of the above types (following the usual
type inference rules, see below).  Have this in mind when doing
estimations about the memory consumption during the computation of
your expressions.

Also, the types in Numexpr conditions are somewhat stricter than those
of Python.  For instance, the only valid constants for booleans are
`True` and `False`, and they are never automatically cast to integers.


Casting rules
=============

Casting rules in Numexpr follow closely those of NumPy.  However, for
implementation reasons, there are some known exceptions to this rule,
namely::

    * When an array with type `int8`, `uint8`, `int16` or `uint16` is
      used inside Numexpr, it is internally upcasted to an `int` (or
      `int32` in NumPy notation).

    * When an array with type `uint32` is used inside Numexpr, it is
      internally upcasted to a `long` (or `int64` in NumPy notation).

    * A floating point function (e.g. `sin`) acting on `int8` or
      `int16` types returns a `float64` type, instead of the `float32`
      that is returned by NumPy functions.  This is mainly due to the
      absence of native `int8` or `int16` types in Numexpr.

    * In operations implying a scalar and an array, the normal rules
      of casting are used in Numexpr, in contrast with NumPy, where
      array types takes priority.  For example, if 'a' is an array of
      type `float32` and 'b' is an scalar of type `float64` (or Python
      `float` type, which is equivalent), then 'a*b' returns a
      `float64` in Numexpr, but a `float32` in NumPy (i.e. array
      operands take priority in determining the result type).  If you
      need to keep the result a `float32`, be sure you use a `float32`
      scalar too.


Supported operators
===================

Numexpr supports the set of operators listed below::

    * Logical operators: &, |, ~
    * Comparison operators: <, <=, ==, !=, >=, >
    * Unary arithmetic operators: -
    * Binary arithmetic operators: +, -, *, /, **, %


Supported functions
===================

The next are the current supported set::

  * where(bool, number1, number2): number<commit_msg>Added the bit shift operators in README<commit_after>What it is Numexpr?
===================

Numexpr is a fast numerical expression evaluator for NumPy.  With it,
expressions that operate on arrays (like "3*a+4*b") are accelerated
and use less memory than doing the same calculation in Python.

In addition, its multi-threaded capabilities can make use of all your
cores, which may accelerate computations, most specially if they are
not memory-bounded (e.g. those using transcendental functions).

Last but not least, numexpr can make use of Intel's VML (Vector Math
Library, normally integrated in its Math Kernel Library, or MKL).
This allows further acceleration of transcendent expressions.


Examples of use
===============

::

  >>> import numpy as np
  >>> import numexpr as ne

  >>> a = np.arange(1e6)   # Choose large arrays
  >>> b = np.arange(1e6)

  >>> ne.evaluate("a + 1")   # a simple expression
  array([  1.00000000e+00,   2.00000000e+00,   3.00000000e+00, ...,
           9.99998000e+05,   9.99999000e+05,   1.00000000e+06])

  >>> ne.evaluate('a*b-4.1*a > 2.5*b')   # a more complex one
  array([False, False, False, ...,  True,  True,  True], dtype=bool)

  >>> ne.evaluate("sin(a) + arcsinh(a/b)")   # you can also use functions
  array([        NaN,  1.72284457,  1.79067101, ...,  1.09567006,
          0.17523598, -0.09597844])

  >>> s = np.array(['abba', 'abbb', 'abbcdef'])
  >>> ne.evaluate("'abba' == s")   # string arrays are supported too
  array([ True, False, False], dtype=bool)


Datatypes supported internally
==============================

Numexpr operates internally only with the following types::

    * 8-bit boolean (bool)
    * 32-bit signed integer (int or int32)
    * 64-bit signed integer (long or int64)
    * 32-bit single-precision floating point number (float or float32)
    * 64-bit, double-precision floating point number (double or float64)
    * 2x64-bit, double-precision complex number (complex or complex128)
    * Raw string of bytes (str)

If the arrays in the expression does not match any of these types,
they will be upcasted to one of the above types (following the usual
type inference rules, see below).  Have this in mind when doing
estimations about the memory consumption during the computation of
your expressions.

Also, the types in Numexpr conditions are somewhat stricter than those
of Python.  For instance, the only valid constants for booleans are
`True` and `False`, and they are never automatically cast to integers.


Casting rules
=============

Casting rules in Numexpr follow closely those of NumPy.  However, for
implementation reasons, there are some known exceptions to this rule,
namely::

    * When an array with type `int8`, `uint8`, `int16` or `uint16` is
      used inside Numexpr, it is internally upcasted to an `int` (or
      `int32` in NumPy notation).

    * When an array with type `uint32` is used inside Numexpr, it is
      internally upcasted to a `long` (or `int64` in NumPy notation).

    * A floating point function (e.g. `sin`) acting on `int8` or
      `int16` types returns a `float64` type, instead of the `float32`
      that is returned by NumPy functions.  This is mainly due to the
      absence of native `int8` or `int16` types in Numexpr.

    * In operations implying a scalar and an array, the normal rules
      of casting are used in Numexpr, in contrast with NumPy, where
      array types takes priority.  For example, if 'a' is an array of
      type `float32` and 'b' is an scalar of type `float64` (or Python
      `float` type, which is equivalent), then 'a*b' returns a
      `float64` in Numexpr, but a `float32` in NumPy (i.e. array
      operands take priority in determining the result type).  If you
      need to keep the result a `float32`, be sure you use a `float32`
      scalar too.


Supported operators
===================

Numexpr supports the set of operators listed below::

    * Logical operators: &, |, ~
    * Comparison operators: <, <=, ==, !=, >=, >
    * Unary arithmetic operators: -
    * Binary arithmetic operators: +, -, *, /, **, %, <<, >>


Supported functions
===================

The next are the current supported set::

  * where(bool, number1, number2): number
{'fraction_non_alphanumeric': 0.12055054579971523, 'fraction_numerical': 0.04295206454674893, 'mean_word_length': 3.4954666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '5229473', 'n_tokens_mistral': 2741, 'n_tokens_neox': 2407, 'n_words': 1079}