summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py77
-rw-r--r--numpy/lib/getlimits.py2
-rw-r--r--numpy/lib/index_tricks.py7
-rw-r--r--numpy/lib/info.py121
-rw-r--r--numpy/lib/src/_compiled_base.c4
5 files changed, 130 insertions, 81 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 694c727ed..bfaa90a94 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1,5 +1,5 @@
-l__all__ = ['logspace', 'linspace', 'round_',
+l__all__ = ['logspace', 'linspace',
'select', 'piecewise', 'trim_zeros',
'copy', 'iterable', 'base_repr', 'binary_repr',
'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',
@@ -14,60 +14,18 @@ import types
import math
import numpy.core.numeric as _nx
from numpy.core.numeric import ones, zeros, arange, concatenate, array, asarray, empty
-from numpy.core.numeric import ScalarType, dot, where, newaxis
+from numpy.core.numeric import ScalarType, dot, where, newaxis, isscalar
from numpy.core.umath import pi, multiply, add, arctan2, maximum, minimum, frompyfunc, \
isnan, absolute, cos, less_equal, sqrt, sin, mod
from numpy.core.oldnumeric import ravel, nonzero, choose, \
sometrue, alltrue, reshape, any, all, typecodes, ArrayType, squeeze,\
sort
-from type_check import ScalarType, isscalar
+from type_check import ScalarType
from shape_base import atleast_1d
from twodim_base import diag
from _compiled_base import digitize, bincount, _insert
from ufunclike import sign
-_lkup = {'0':'000',
- '1':'001',
- '2':'010',
- '3':'011',
- '4':'100',
- '5':'101',
- '6':'110',
- '7':'111',
- 'L':''}
-
-def binary_repr(num):
- """Return the binary representation of the input number as a string.
-
- This is equivalent to using base_repr with base 2, but about 25x
- faster.
- """
- ostr = oct(num)
- bin = ''
- for ch in ostr[1:]:
- bin += _lkup[ch]
- ind = 0
- while bin[ind] == '0':
- ind += 1
- return bin[ind:]
-
-def base_repr (number, base=2, padding=0):
- """Return the representation of a number in any given base.
- """
- chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-
- lnb = math.log(base)
- res = padding*chars[0]
- if number == 0:
- return res + chars[0]
- exponent = int (math.log (number)/lnb)
- while(exponent >= 0):
- term = long(base)**exponent
- lead_digit = int(number / term)
- res += chars[lead_digit]
- number -= term*lead_digit
- exponent -= 1
- return res
#end Fernando's utilities
@@ -665,35 +623,6 @@ class vectorize(object):
else:
return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)])
-
-def round_(a, decimals=0):
- """Round 'a' to the given number of decimal places. Rounding
- behaviour is equivalent to Python.
-
- Return 'a' if the array is not floating point. Round both the real
- and imaginary parts separately if the array is complex.
- """
- a = asarray(a)
- if not issubclass(a.dtype, _nx.inexact):
- return a
- if issubclass(a.dtype, _nx.complexfloating):
- return round_(a.real, decimals) + 1j*round_(a.imag, decimals)
- if decimals is not 0:
- decimals = asarray(decimals)
- s = sign(a)
- if decimals is not 0:
- a = absolute(multiply(a, 10.**decimals))
- else:
- a = absolute(a)
- rem = a-asarray(a).astype(_nx.intp)
- a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))
- # convert back
- if decimals is not 0:
- return multiply(a, s/(10.**decimals))
- else:
- return multiply(a, s)
-
-
def cov(m,y=None, rowvar=0, bias=0):
"""Estimate the covariance matrix.
diff --git a/numpy/lib/getlimits.py b/numpy/lib/getlimits.py
index 825f286e8..3b5bd9211 100644
--- a/numpy/lib/getlimits.py
+++ b/numpy/lib/getlimits.py
@@ -4,7 +4,7 @@
__all__ = ['finfo']
from machar import MachAr
-import numpy.core.numeric
+import numpy.core.numeric as numeric
from numpy.core.numeric import array
def _frz(a):
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index e2c8d2a13..c380df0d8 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -4,13 +4,12 @@ __all__ = ['mgrid','ogrid','r_', 'c_', 'index_exp', 'ix_','ndenumerate']
import sys
import types
-import numeric as _nx
-from numeric import asarray
+import numpy.core.numeric as _nx
+from numpy.core.numeric import asarray, ScalarType
-from type_check import ScalarType
import function_base
import twodim_base as matrix_base
-import matrix
+import numpy.core.defmatrix as matrix
makemat = matrix.matrix
def ix_(*args):
diff --git a/numpy/lib/info.py b/numpy/lib/info.py
new file mode 100644
index 000000000..e7b097f1b
--- /dev/null
+++ b/numpy/lib/info.py
@@ -0,0 +1,121 @@
+__doc__ = \
+""" Basic functions used by several sub-packages and useful to have in the
+main name-space
+
+Type handling
+==============
+iscomplexobj -- Test for complex object, scalar result
+isrealobj -- Test for real object, scalar result
+iscomplex -- Test for complex elements, array result
+isreal -- Test for real elements, array result
+imag -- Imaginary part
+real -- Real part
+real_if_close -- Turns complex number with tiny imaginary part to real
+isneginf -- Tests for negative infinity ---|
+isposinf -- Tests for positive infinity |
+isnan -- Tests for nans |---- array results
+isinf -- Tests for infinity |
+isfinite -- Tests for finite numbers ---|
+isscalar -- True if argument is a scalar
+nan_to_num -- Replaces NaN's with 0 and infinities with large numbers
+cast -- Dictionary of functions to force cast to each type
+common_type -- Determine the 'minimum common type code' for a group
+ of arrays
+mintypecode -- Return minimal allowed common typecode.
+
+Index tricks
+==================
+mgrid -- Method which allows easy construction of N-d 'mesh-grids'
+r_ -- Append and construct arrays: turns slice objects into
+ ranges and concatenates them, for 2d arrays appends
+ rows.
+index_exp -- Konrad Hinsen's index_expression class instance which
+ can be useful for building complicated slicing syntax.
+
+Useful functions
+==================
+select -- Extension of where to multiple conditions and choices
+extract -- Extract 1d array from flattened array according to mask
+insert -- Insert 1d array of values into Nd array according to mask
+linspace -- Evenly spaced samples in linear space
+logspace -- Evenly spaced samples in logarithmic space
+fix -- Round x to nearest integer towards zero
+mod -- Modulo mod(x,y) = x % y except keeps sign of y
+amax -- Array maximum along axis
+amin -- Array minimum along axis
+ptp -- Array max-min along axis
+cumsum -- Cumulative sum along axis
+prod -- Product of elements along axis
+cumprod -- Cumluative product along axis
+diff -- Discrete differences along axis
+angle -- Returns angle of complex argument
+unwrap -- Unwrap phase along given axis (1-d algorithm)
+sort_complex -- Sort a complex-array (based on real, then imaginary)
+trim_zeros -- trim the leading and trailing zeros from 1D array.
+
+vectorize -- a class that wraps a Python function taking scalar
+ arguments into a generalized function which
+ can handle arrays of arguments using the broadcast
+ rules of numerix Python.
+
+Shape manipulation
+===================
+squeeze -- Return a with length-one dimensions removed.
+atleast_1d -- Force arrays to be > 1D
+atleast_2d -- Force arrays to be > 2D
+atleast_3d -- Force arrays to be > 3D
+vstack -- Stack arrays vertically (row on row)
+hstack -- Stack arrays horizontally (column on column)
+column_stack -- Stack 1D arrays as columns into 2D array
+dstack -- Stack arrays depthwise (along third dimension)
+split -- Divide array into a list of sub-arrays
+hsplit -- Split into columns
+vsplit -- Split into rows
+dsplit -- Split along third dimension
+
+Matrix (2d array) manipluations
+===============================
+fliplr -- 2D array with columns flipped
+flipud -- 2D array with rows flipped
+rot90 -- Rotate a 2D array a multiple of 90 degrees
+eye -- Return a 2D array with ones down a given diagonal
+diag -- Construct a 2D array from a vector, or return a given
+ diagonal from a 2D array.
+mat -- Construct a Matrix
+bmat -- Build a Matrix from blocks
+
+Polynomials
+============
+poly1d -- A one-dimensional polynomial class
+
+poly -- Return polynomial coefficients from roots
+roots -- Find roots of polynomial given coefficients
+polyint -- Integrate polynomial
+polyder -- Differentiate polynomial
+polyadd -- Add polynomials
+polysub -- Substract polynomials
+polymul -- Multiply polynomials
+polydiv -- Divide polynomials
+polyval -- Evaluate polynomial at given argument
+
+Import tricks
+=============
+ppimport -- Postpone module import until trying to use it
+ppimport_attr -- Postpone module import until trying to use its
+ attribute
+ppresolve -- Import postponed module and return it.
+
+Machine arithmetics
+===================
+machar_single -- MachAr instance storing the parameters of system
+ single precision floating point arithmetics
+machar_double -- MachAr instance storing the parameters of system
+ double precision floating point arithmetics
+
+Threading tricks
+================
+ParallelExec -- Execute commands in parallel thread.
+"""
+
+depends = ['core','testing']
+global_symbols = ['*']
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c
index 7c20d4f96..063631c7e 100644
--- a/numpy/lib/src/_compiled_base.c
+++ b/numpy/lib/src/_compiled_base.c
@@ -427,7 +427,7 @@ DL_EXPORT(void) init_compiled_base(void) {
PyObject *m, *d, *s;
/* Create the module and add the functions */
- m = Py_InitModule("numpy.base._compiled_base", methods);
+ m = Py_InitModule("_compiled_base", methods);
/* Import the array and ufunc objects */
import_array();
@@ -439,7 +439,7 @@ DL_EXPORT(void) init_compiled_base(void) {
PyDict_SetItemString(d, "__version__", s);
Py_DECREF(s);
- ErrorObject = PyString_FromString("numpy.base._compiled_base.error");
+ ErrorObject = PyString_FromString("numpy.lib._compiled_base.error");
PyDict_SetItemString(d, "error", ErrorObject);
Py_DECREF(ErrorObject);