From numpy-svn at scipy.org Mon Jul 2 10:55:14 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Jul 2007 09:55:14 -0500 (CDT) Subject: [Numpy-svn] r3877 - trunk/numpy/core Message-ID: <20070702145514.426E739C055@new.scipy.org> Author: cookedm Date: 2007-07-02 09:55:12 -0500 (Mon, 02 Jul 2007) New Revision: 3877 Modified: trunk/numpy/core/arrayprint.py Log: NaN and Inf in arrays print always as NaN or Inf (not platform-dependent) - strings used for NaN and Inf can be set with `set_printoptions` - `get_printoptions` returns a dict instead of a tuple now - an array of complex longfloats prints negative imaginary components correctly (no more 1--2j). - minor cleanups to use Python 2.3 idioms Modified: trunk/numpy/core/arrayprint.py =================================================================== --- trunk/numpy/core/arrayprint.py 2007-06-30 14:42:31 UTC (rev 3876) +++ trunk/numpy/core/arrayprint.py 2007-07-02 14:55:12 UTC (rev 3877) @@ -13,60 +13,27 @@ # and by Travis Oliphant 2005-8-22 for numpy import sys -import numeric as _gen +import numeric as _nc import numerictypes as _nt -import umath as _uf +from umath import maximum, minimum, absolute, not_equal, isnan, isinf from multiarray import format_longfloat from fromnumeric import ravel -_nc = _gen -# The following functions are emergency substitutes for numeric functions -# which sometimes get broken during development. - def product(x, y): return x*y -def _maximum_reduce(arr): - maximum = arr[0] - for i in xrange(1, arr.nelements()): - if arr[i] > maximum: maximum = arr[i] - return maximum - -def _minimum_reduce(arr): - minimum = arr[0] - for i in xrange(1, arr.nelements()): - if arr[i] < minimum: minimum = arr[i] - return minimum - -def _numeric_compress(arr): - nonzero = 0 - for i in xrange(arr.nelements()): - if arr[i] != 0: nonzero += 1 - retarr = _nc.zeros((nonzero,)) - nonzero = 0 - for i in xrange(arr.nelements()): - if arr[i] != 0: - retarr[nonzero] = abs(arr[i]) - nonzero += 1 - return retarr - -_failsafe = 0 -if _failsafe: - max_reduce = _maximum_reduce - min_reduce = _minimum_reduce -else: - max_reduce = _uf.maximum.reduce - min_reduce = _uf.minimum.reduce - _summaryEdgeItems = 3 # repr N leading and trailing items of each dimension _summaryThreshold = 1000 # total items > triggers array summarization _float_output_precision = 8 _float_output_suppress_small = False _line_width = 75 +_nan_str = 'NaN' +_inf_str = 'Inf' def set_printoptions(precision=None, threshold=None, edgeitems=None, - linewidth=None, suppress=None): + linewidth=None, suppress=None, + nanstr=None, infstr=None): """Set options associated with printing. :Parameters: @@ -84,44 +51,58 @@ suppress : bool Whether or not suppress printing of small floating point values using scientific notation (default False). + nanstr : string + String representation of floating point not-a-number (default nan). + infstr : string + String representation of floating point infinity (default inf). """ global _summaryThreshold, _summaryEdgeItems, _float_output_precision, \ - _line_width, _float_output_suppress_small - if (linewidth is not None): + _line_width, _float_output_suppress_small, _nan_str, _inf_str + if linewidth is not None: _line_width = linewidth - if (threshold is not None): + if threshold is not None: _summaryThreshold = threshold - if (edgeitems is not None): + if edgeitems is not None: _summaryEdgeItems = edgeitems - if (precision is not None): + if precision is not None: _float_output_precision = precision - if (suppress is not None): + if suppress is not None: _float_output_suppress_small = not not suppress - return + if nanstr is not None: + _nan_str = nanstr + if infstr is not None: + _inf_str = infstr def get_printoptions(): """Return the current print options. :Returns: - precision : int - threshold : int - edgeitems : int - linewidth : int - suppress : bool + dictionary of current print options with keys + - precision : int + - threshold : int + - edgeitems : int + - linewidth : int + - suppress : bool + - nanstr : string + - infstr : string :SeeAlso: - set_printoptions : parameter descriptions - """ - return _float_output_precision, _summaryThreshold, _summaryEdgeItems, \ - _line_width, _float_output_suppress_small + d = dict(precision=_float_output_precision, + threshold=_summaryThreshold, + edgeitems=_summaryEdgeItems, + linewidth=_line_width, + suppress=_float_output_suppress_small, + nanstr=_nan_str, + infstr=_inf_str) + return d - def _leading_trailing(a): if a.ndim == 1: if len(a) > 2*_summaryEdgeItems: - b = _gen.concatenate((a[:_summaryEdgeItems], + b = _nc.concatenate((a[:_summaryEdgeItems], a[-_summaryEdgeItems:])) else: b = a @@ -133,7 +114,7 @@ min(len(a), _summaryEdgeItems),0,-1)]) else: l = [_leading_trailing(a[i]) for i in range(0, len(a))] - b = _gen.concatenate(tuple(l)) + b = _nc.concatenate(tuple(l)) return b def _boolFormatter(x): @@ -168,33 +149,25 @@ # make sure True and False line up. format_function = _boolFormatter elif issubclass(dtypeobj, _nt.integer): - max_str_len = max(len(str(max_reduce(data))), - len(str(min_reduce(data)))) + max_str_len = max(len(str(maximum.reduce(data))), + len(str(mininum.reduce(data)))) format = '%' + str(max_str_len) + 'd' format_function = lambda x: _formatInteger(x, format) elif issubclass(dtypeobj, _nt.floating): if issubclass(dtypeobj, _nt.longfloat): format_function = _longfloatFormatter(precision) else: - format = _floatFormat(data, precision, suppress_small) - format_function = lambda x: _formatFloat(x, format) + format_function = FloatFormat(data, precision, suppress_small) elif issubclass(dtypeobj, _nt.complexfloating): if issubclass(dtypeobj, _nt.clongfloat): format_function = _clongfloatFormatter(precision) else: - real_format = _floatFormat( - data.real, precision, suppress_small, sign=0) - imag_format = _floatFormat( - data.imag, precision, suppress_small, sign=1) - format_function = lambda x: \ - _formatComplex(x, real_format, imag_format) + format_function = ComplexFormat(data, precision, suppress_small) elif issubclass(dtypeobj, _nt.unicode_) or \ - issubclass(dtypeobj, _nt.string_): - format = "%s" - format_function = lambda x: repr(x) + issubclass(dtypeobj, _nt.string_): + format_function = repr else: - format = '%s' - format_function = lambda x: str(x) + format_function = str next_line_prefix = " " # skip over "[" next_line_prefix += " "*len(prefix) # skip over array( @@ -208,7 +181,7 @@ def _convert_arrays(obj): newtup = [] for k in obj: - if isinstance(k, _gen.ndarray): + if isinstance(k, _nc.ndarray): k = k.tolist() elif isinstance(k, tuple): k = _convert_arrays(k) @@ -342,109 +315,138 @@ summary_insert).rstrip()+']\n' return s -def _floatFormat(data, precision, suppress_small, sign = 0): - exp_format = 0 - errstate = _gen.seterr(all='ignore') - non_zero = _uf.absolute(data.compress(_uf.not_equal(data, 0))) - ##non_zero = _numeric_compress(data) ## - if len(non_zero) == 0: - max_val = 0. - min_val = 0. - else: - max_val = max_reduce(non_zero) - min_val = min_reduce(non_zero) - if max_val >= 1.e8: - exp_format = 1 - if not suppress_small and (min_val < 0.0001 - or max_val/min_val > 1000.): - exp_format = 1 - _gen.seterr(**errstate) - if exp_format: - large_exponent = 0 < min_val < 1e-99 or max_val >= 1e100 - max_str_len = 8 + precision + large_exponent - if sign: format = '%+' - else: format = '%' - format = format + str(max_str_len) + '.' + str(precision) + 'e' - if large_exponent: format = format + '3' - else: - format = '%.' + str(precision) + 'f' - precision = min(precision, max([_digits(x, precision, format) - for x in data])) - max_str_len = len(str(int(max_val))) + precision + 2 - if sign: format = '%#+' - else: format = '%#' - format = format + str(max_str_len) + '.' + str(precision) + 'f' - return format +class FloatFormat(object): + def __init__(self, data, precision, suppress_small, sign=False): + self.precision = precision + self.suppress_small = suppress_small + self.sign = sign + self.exp_format = False + self.large_exponent = False + self.max_str_len = 0 + self.fillFormat(data) + def fillFormat(self, data): + errstate = _nc.seterr(all='ignore') + try: + special = isnan(data) | isinf(data) + non_zero = absolute(data.compress(not_equal(data, 0) & ~special)) + if len(non_zero) == 0: + max_val = 0. + min_val = 0. + else: + max_val = maximum.reduce(non_zero) + min_val = minimum.reduce(non_zero) + if max_val >= 1.e8: + self.exp_format = True + if not self.suppress_small and (min_val < 0.0001 + or max_val/min_val > 1000.): + self.exp_format = True + finally: + _nc.seterr(**errstate) + if self.exp_format: + self.large_exponent = 0 < min_val < 1e-99 or max_val >= 1e100 + self.max_str_len = 8 + self.precision + if self.large_exponent: + self.max_str_len += 1 + if self.sign: + format = '%+' + else: + format = '%' + format = format + '%d.%de' % (self.max_str_len, self.precision) + else: + format = '%%.%df' % (self.precision,) + if len(non_zero): + precision = max([_digits(x, self.precision, format) + for x in non_zero]) + else: + precision = 0 + precision = min(self.precision, precision) + self.max_str_len = len(str(int(max_val))) + precision + 2 + if _nc.any(special): + self.max_str_len = max(self.max_str_len, + len(_nan_str), + len(_inf_str)+1) + if self.sign: + format = '%#+' + else: + format = '%#' + format = format + '%d.%df' % (self.max_str_len, precision) + self.special_fmt = '%%%ds' % (self.max_str_len,) + self.format = format + + def __call__(self, x, strip_zeros=True): + if isnan(x): + return self.special_fmt % (_nan_str,) + elif isinf(x): + if x > 0: + return self.special_fmt % (_inf_str,) + else: + return self.special_fmt % ('-' + _inf_str,) + s = self.format % x + if self.large_exponent: + # 3-digit exponent + expsign = s[-3] + if expsign == '+' or expsign == '-': + s = s[1:-2] + '0' + s[-2:] + elif self.exp_format: + # 2-digit exponent + if s[-3] == '0': + s = ' ' + s[:-3] + s[-2:] + elif strip_zeros: + z = s.rstrip('0') + s = z + ' '*(len(s)-len(z)) + return s + + def _digits(x, precision, format): s = format % x - zeros = len(s) - while s[zeros-1] == '0': zeros = zeros-1 - return precision-len(s)+zeros + z = s.rstrip('0') + return precision - len(s) + len(z) _MAXINT = sys.maxint _MININT = -sys.maxint-1 def _formatInteger(x, format): - if (x < _MAXINT) and (x > _MININT): + if _MININT < x < _MAXINT: return format % x else: return "%s" % x def _longfloatFormatter(precision): + # XXX Have to add something to determine the width to use a la FloatFormat + # Right now, things won't line up properly def formatter(x): + if isnan(x): + return _nan_str + elif isinf(x): + if x > 0: + return _inf_str + else: + return '-' + _inf_str return format_longfloat(x, precision) return formatter -def _formatFloat(x, format, strip_zeros = 1): - if format[-1] == '3': - # 3-digit exponent - format = format[:-1] - s = format % x - third = s[-3] - if third == '+' or third == '-': - s = s[1:-2] + '0' + s[-2:] - elif format[-1] == 'e': - # 2-digit exponent - s = format % x - if s[-3] == '0': - s = ' ' + s[:-3] + s[-2:] - elif format[-1] == 'f': - s = format % x - if strip_zeros: - zeros = len(s) - while s[zeros-1] == '0': zeros = zeros-1 - s = s[:zeros] + (len(s)-zeros)*' ' - else: - s = format % x - return s - def _clongfloatFormatter(precision): def formatter(x): r = format_longfloat(x.real, precision) i = format_longfloat(x.imag, precision) - if x.imag < 0: - i = '-' + i - else: - i = '+' + i - return r + i + 'j' + return '%s+%sj' % (r, i) return formatter -def _formatComplex(x, real_format, imag_format): - r = _formatFloat(x.real, real_format) - i = _formatFloat(x.imag, imag_format, 0) - if imag_format[-1] == 'f': - zeros = len(i) - while zeros > 2 and i[zeros-1] == '0': zeros = zeros-1 - i = i[:zeros] + 'j' + (len(i)-zeros)*' ' - else: - i = i + 'j' - return r + i +class ComplexFormat(object): + def __init__(self, x, precision, suppress_small): + self.real_format = FloatFormat(x.real, precision, suppress_small) + self.imag_format = FloatFormat(x.imag, precision, suppress_small, + sign=True) -def _formatGeneral(x): - return str(x) + ' ' + def __call__(self, x): + r = self.real_format(x.real, strip_zeros=False) + i = self.imag_format(x.imag, strip_zeros=False) + if not self.imag_format.exp_format: + z = i.rstrip('0') + i = z + 'j' + ' '*(len(i)-len(z)) + else: + i = i + 'j' + return r + i -if __name__ == '__main__': - a = _nc.arange(10) - print array2string(a) - print array2string(_nc.array([[],[]])) +## end From numpy-svn at scipy.org Mon Jul 2 12:10:00 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Jul 2007 11:10:00 -0500 (CDT) Subject: [Numpy-svn] r3878 - trunk/numpy/core Message-ID: <20070702161000.1B14339C078@new.scipy.org> Author: chanley Date: 2007-07-02 11:09:57 -0500 (Mon, 02 Jul 2007) New Revision: 3878 Modified: trunk/numpy/core/arrayprint.py Log: Fix new typo added to arrayprint.py in r3877 Modified: trunk/numpy/core/arrayprint.py =================================================================== --- trunk/numpy/core/arrayprint.py 2007-07-02 14:55:12 UTC (rev 3877) +++ trunk/numpy/core/arrayprint.py 2007-07-02 16:09:57 UTC (rev 3878) @@ -150,7 +150,7 @@ format_function = _boolFormatter elif issubclass(dtypeobj, _nt.integer): max_str_len = max(len(str(maximum.reduce(data))), - len(str(mininum.reduce(data)))) + len(str(minimum.reduce(data)))) format = '%' + str(max_str_len) + 'd' format_function = lambda x: _formatInteger(x, format) elif issubclass(dtypeobj, _nt.floating): From numpy-svn at scipy.org Mon Jul 2 12:59:05 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Jul 2007 11:59:05 -0500 (CDT) Subject: [Numpy-svn] r3879 - trunk/numpy/core Message-ID: <20070702165905.335D939C078@new.scipy.org> Author: cookedm Date: 2007-07-02 11:59:03 -0500 (Mon, 02 Jul 2007) New Revision: 3879 Modified: trunk/numpy/core/numerictypes.py Log: Add the `inexact` dtype to the tree of types in the numerictypes.py docstring. Also add some ASCII lines to make the tree clearer. Modified: trunk/numpy/core/numerictypes.py =================================================================== --- trunk/numpy/core/numerictypes.py 2007-07-02 16:09:57 UTC (rev 3878) +++ trunk/numpy/core/numerictypes.py 2007-07-02 16:59:03 UTC (rev 3879) @@ -35,43 +35,43 @@ float_, complex_, longfloat, clongfloat, - As part of the type-hierarchy: xx -- is bit-width + As part of the type-hierarchy: xx -- is bit-width - generic - bool_ - number - integer - signedinteger (intxx) - byte - short - intc - intp int0 - int_ - longlong - unsignedinteger (uintxx) - ubyte - ushort - uintc - uintp uint0 - uint_ - ulonglong - floating (floatxx) - single - float_ (double) - longfloat - complexfloating (complexxx) - csingle - complex_ (cfloat, cdouble) - clongfloat + generic + +-> bool_ + +-> number + | integer + | signedinteger (intxx) + | byte + | short + | intc + | intp int0 + | int_ + | longlong + +-> unsignedinteger (uintxx) + | ubyte + | ushort + | uintc + | uintp uint0 + | uint_ + | ulonglong + +-> inexact + | +-> floating (floatxx) + | | single + | | float_ (double) + | | longfloat + | \-> complexfloating (complexxx) + | csingle + | complex_ (cfloat, cdouble) + | clongfloat + +-> flexible + | character + | str_ (string_) + | unicode_ + | void + | + \-> object_ (not used much) - flexible - character - str_ (string_) - unicode_ - void - - object_ (not used much) - $Id: numerictypes.py,v 1.17 2005/09/09 22:20:06 teoliphant Exp $ """ @@ -228,7 +228,7 @@ sctypeDict[charname] = typeobj sctypeDict[ucharname] = utypeobj sctypeNA[Intname] = typeobj - sctypeNA[UIntname] = utypeobj + sctypeNA[UIntname] = utypeobj sctypeNA[charname] = typeobj sctypeNA[ucharname] = utypeobj sctypeNA[typeobj] = Intname From numpy-svn at scipy.org Mon Jul 2 15:32:03 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 2 Jul 2007 14:32:03 -0500 (CDT) Subject: [Numpy-svn] r3880 - trunk/numpy/distutils/command Message-ID: <20070702193203.44C5F39C015@new.scipy.org> Author: rkern Date: 2007-07-02 14:32:02 -0500 (Mon, 02 Jul 2007) New Revision: 3880 Modified: trunk/numpy/distutils/command/build_src.py Log: Import Pyrex.Compiler.Main explicitly since in 0.9.5.1, it does not appear to be imported with a plain 'import Pyrex.Compiler' Modified: trunk/numpy/distutils/command/build_src.py =================================================================== --- trunk/numpy/distutils/command/build_src.py 2007-07-02 16:59:03 UTC (rev 3879) +++ trunk/numpy/distutils/command/build_src.py 2007-07-02 19:32:02 UTC (rev 3880) @@ -11,7 +11,7 @@ from distutils.errors import DistutilsError, DistutilsSetupError try: - import Pyrex.Compiler + import Pyrex.Compiler.Main have_pyrex = True except ImportError: have_pyrex = False From numpy-svn at scipy.org Thu Jul 5 03:01:26 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 5 Jul 2007 02:01:26 -0500 (CDT) Subject: [Numpy-svn] r3881 - trunk/numpy/core/src Message-ID: <20070705070126.E160639C06D@new.scipy.org> Author: charris Date: 2007-07-05 02:00:57 -0500 (Thu, 05 Jul 2007) New Revision: 3881 Modified: trunk/numpy/core/src/_sortmodule.c.src Log: Working in _sortmodule.c.src Reindent code to conform to later python style guidelines. Add macros for string and unicode comparisons. Todo: Fix swap macro to not use magic variable. Add tests for sorts. Add full compliment of sorting types for string and unicode. Separate out insertion sort? Modified: trunk/numpy/core/src/_sortmodule.c.src =================================================================== --- trunk/numpy/core/src/_sortmodule.c.src 2007-07-02 19:32:02 UTC (rev 3880) +++ trunk/numpy/core/src/_sortmodule.c.src 2007-07-05 07:00:57 UTC (rev 3881) @@ -31,376 +31,393 @@ #define PYA_QS_STACK 100 #define SMALL_QUICKSORT 15 #define SMALL_MERGESORT 20 +#define SWAP(a,b) {SWAP_temp = (b); (b)=(a); (a) = SWAP_temp;} #define STDC_LT(a,b) ((a) < (b)) #define STDC_LE(a,b) ((a) <= (b)) #define STDC_EQ(a,b) ((a) == (b)) -#define SWAP(a,b) {SWAP_temp = (b); (b)=(a); (a) = SWAP_temp;} #define NUMC_LT(p,q) ((((p).real==(q).real) ? ((p).imag < (q).imag): ((p).real < (q).real))) #define NUMC_LE(p,q) ((((p).real==(q).real) ? ((p).imag <= (q).imag): ((p).real <= (q).real))) #define NUMC_EQ(p,q) (((p).real==(q).real) && ((p).imag == (q).imag)) +#define STRING_LT(pa, pb, len) (strncmp(pa, pb, len) < 0) +#define STRING_LE(pa, pb, len) (strncmp(pa, pb, len) <= 0) +#define STRING_EQ(pa, pb, len) (strncmp(pa, pb, len) == 0) +#define UNICODE_LT(pa, pb, len) (PyArray_CompareUCS4(pa, pb, len) < 0) +#define UNICODE_LE(pa, pb, len) (PyArray_CompareUCS4(pa, pb, len) <= 0) +#define UNICODE_EQ(pa, pb, len) (PyArray_CompareUCS4(pa, pb, len) == 0) + /**begin repeat #TYPE=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE# #type=Bool,byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble# #lessthan=STDC_LT*14,NUMC_LT*3# #lessequal=STDC_LE*14,NUMC_LE*3# - **/ +**/ static int @TYPE at _quicksort(@type@ *start, intp num, void *unused) { - @type@ *pl = start; - @type@ *pr = start + num - 1; - @type@ vp, SWAP_temp; - @type@ *stack[PYA_QS_STACK], **sptr = stack, *pm, *pi, *pj, *pt; + @type@ *pl = start; + @type@ *pr = start + num - 1; + @type@ vp, SWAP_temp; + @type@ *stack[PYA_QS_STACK], **sptr = stack, *pm, *pi, *pj, *pt; - for(;;) { - while ((pr - pl) > SMALL_QUICKSORT) { - /* quicksort partition */ - pm = pl + ((pr - pl) >> 1); - if (@lessthan@(*pm,*pl)) SWAP(*pm,*pl); - if (@lessthan@(*pr,*pm)) SWAP(*pr,*pm); - if (@lessthan@(*pm,*pl)) SWAP(*pm,*pl); - vp = *pm; - pi = pl; - pj = pr - 1; - SWAP(*pm,*pj); - for(;;) { - do ++pi; while (@lessthan@(*pi,vp)); - do --pj; while (@lessthan@(vp,*pj)); - if (pi >= pj) break; - SWAP(*pi,*pj); - } - SWAP(*pi,*(pr-1)); - /* push largest partition on stack */ - if (pi - pl < pr - pi) { - *sptr++ = pi + 1; - *sptr++ = pr; - pr = pi - 1; - }else{ - *sptr++ = pl; - *sptr++ = pi - 1; - pl = pi + 1; - } - } - /* insertion sort */ - for(pi = pl + 1; pi <= pr; ++pi) { - vp = *pi; - for(pj = pi, pt = pi - 1; \ - pj > pl && @lessthan@(vp, *pt);) { - *pj-- = *pt--; - } - *pj = vp; - } - if (sptr == stack) break; - pr = *(--sptr); - pl = *(--sptr); + for(;;) { + while ((pr - pl) > SMALL_QUICKSORT) { + /* quicksort partition */ + pm = pl + ((pr - pl) >> 1); + if (@lessthan@(*pm,*pl)) SWAP(*pm,*pl); + if (@lessthan@(*pr,*pm)) SWAP(*pr,*pm); + if (@lessthan@(*pm,*pl)) SWAP(*pm,*pl); + vp = *pm; + pi = pl; + pj = pr - 1; + SWAP(*pm,*pj); + for(;;) { + do ++pi; while (@lessthan@(*pi,vp)); + do --pj; while (@lessthan@(vp,*pj)); + if (pi >= pj) break; + SWAP(*pi,*pj); + } + SWAP(*pi,*(pr-1)); + /* push largest partition on stack */ + if (pi - pl < pr - pi) { + *sptr++ = pi + 1; + *sptr++ = pr; + pr = pi - 1; + } + else { + *sptr++ = pl; + *sptr++ = pi - 1; + pl = pi + 1; + } } - return 0; + + /* insertion sort */ + for(pi = pl + 1; pi <= pr; ++pi) { + vp = *pi; + for(pj = pi, pt = pi - 1; pj > pl && @lessthan@(vp, *pt);) { + *pj-- = *pt--; + } + *pj = vp; + } + if (sptr == stack) break; + pr = *(--sptr); + pl = *(--sptr); + } + + return 0; } static int @TYPE at _aquicksort(@type@ *v, intp* tosort, intp num, void *unused) { - @type@ vp; - intp *pl, *pr, SWAP_temp; - intp *stack[PYA_QS_STACK], **sptr=stack, *pm, *pi, *pj, *pt, vi; + @type@ vp; + intp *pl, *pr, SWAP_temp; + intp *stack[PYA_QS_STACK], **sptr=stack, *pm, *pi, *pj, *pt, vi; - pl = tosort; - pr = tosort + num - 1; + pl = tosort; + pr = tosort + num - 1; - for(;;) { - while ((pr - pl) > SMALL_QUICKSORT) { - /* quicksort partition */ - pm = pl + ((pr - pl) >> 1); - if (@lessthan@(v[*pm],v[*pl])) SWAP(*pm,*pl); - if (@lessthan@(v[*pr],v[*pm])) SWAP(*pr,*pm); - if (@lessthan@(v[*pm],v[*pl])) SWAP(*pm,*pl); - vp = v[*pm]; - pi = pl; - pj = pr - 1; - SWAP(*pm,*pj); - for(;;) { - do ++pi; while (@lessthan@(v[*pi],vp)); - do --pj; while (@lessthan@(vp,v[*pj])); - if (pi >= pj) break; - SWAP(*pi,*pj); - } - SWAP(*pi,*(pr-1)); - /* push largest partition on stack */ - if (pi - pl < pr - pi) { - *sptr++ = pi + 1; - *sptr++ = pr; - pr = pi - 1; - }else{ - *sptr++ = pl; - *sptr++ = pi - 1; - pl = pi + 1; - } - } - /* insertion sort */ - for(pi = pl + 1; pi <= pr; ++pi) { - vi = *pi; - vp = v[vi]; - for(pj = pi, pt = pi - 1; \ - pj > pl && @lessthan@(vp, v[*pt]);) - { - *pj-- = *pt--; - } - *pj = vi; - } - if (sptr == stack) break; - pr = *(--sptr); - pl = *(--sptr); + for(;;) { + while ((pr - pl) > SMALL_QUICKSORT) { + /* quicksort partition */ + pm = pl + ((pr - pl) >> 1); + if (@lessthan@(v[*pm],v[*pl])) SWAP(*pm,*pl); + if (@lessthan@(v[*pr],v[*pm])) SWAP(*pr,*pm); + if (@lessthan@(v[*pm],v[*pl])) SWAP(*pm,*pl); + vp = v[*pm]; + pi = pl; + pj = pr - 1; + SWAP(*pm,*pj); + for(;;) { + do ++pi; while (@lessthan@(v[*pi],vp)); + do --pj; while (@lessthan@(vp,v[*pj])); + if (pi >= pj) break; + SWAP(*pi,*pj); + } + SWAP(*pi,*(pr-1)); + /* push largest partition on stack */ + if (pi - pl < pr - pi) { + *sptr++ = pi + 1; + *sptr++ = pr; + pr = pi - 1; + } + else { + *sptr++ = pl; + *sptr++ = pi - 1; + pl = pi + 1; + } } - return 0; + + /* insertion sort */ + for(pi = pl + 1; pi <= pr; ++pi) { + vi = *pi; + vp = v[vi]; + for(pj = pi, pt = pi - 1; pj > pl && @lessthan@(vp, v[*pt]);) { + *pj-- = *pt--; + } + *pj = vi; + } + if (sptr == stack) break; + pr = *(--sptr); + pl = *(--sptr); + } + + return 0; } static int @TYPE at _heapsort(@type@ *start, intp n, void *unused) { + @type@ tmp, *a; + intp i,j,l; - @type@ tmp, *a; - intp i,j,l; + /* The array needs to be offset by one for heapsort indexing */ + a = start - 1; - /* The array needs to be offset by one for heapsort indexing */ - a = start - 1; + for (l = n>>1; l > 0; --l) { + tmp = a[l]; + for (i = l, j = l<<1; j <= n;) { + if (j < n && @lessthan@(a[j], a[j+1])) + j += 1; + if (@lessthan@(tmp, a[j])) { + a[i] = a[j]; + i = j; + j += j; + } + else + break; + } + a[i] = tmp; + } - for (l = n>>1; l > 0; --l) { - tmp = a[l]; - for (i = l, j = l<<1; j <= n;) { - if (j < n && @lessthan@(a[j], a[j+1])) - j += 1; - if (@lessthan@(tmp, a[j])) { - a[i] = a[j]; - i = j; - j += j; - }else - break; - } - a[i] = tmp; + for (; n > 1;) { + tmp = a[n]; + a[n] = a[1]; + n -= 1; + for (i = 1, j = 2; j <= n;) { + if (j < n && @lessthan@(a[j], a[j+1])) + j++; + if (@lessthan@(tmp, a[j])) { + a[i] = a[j]; + i = j; + j += j; + } + else + break; } + a[i] = tmp; + } - for (; n > 1;) { - tmp = a[n]; - a[n] = a[1]; - n -= 1; - for (i = 1, j = 2; j <= n;) { - if (j < n && @lessthan@(a[j], a[j+1])) - j++; - if (@lessthan@(tmp, a[j])) { - a[i] = a[j]; - i = j; - j += j; - }else - break; - } - a[i] = tmp; - } - return 0; + return 0; } static int @TYPE at _aheapsort(@type@ *v, intp *tosort, intp n, void *unused) { - intp *a, i,j,l, tmp; - /* The arrays need to be offset by one for heapsort indexing */ - a = tosort - 1; + intp *a, i,j,l, tmp; + /* The arrays need to be offset by one for heapsort indexing */ + a = tosort - 1; - for (l = n>>1; l > 0; --l) { - tmp = a[l]; - for (i = l, j = l<<1; j <= n;) { - if (j < n && @lessthan@(v[a[j]], v[a[j+1]])) - j += 1; - if (@lessthan@(v[tmp], v[a[j]])) { - a[i] = a[j]; - i = j; - j += j; - }else - break; - } - a[i] = tmp; + for (l = n>>1; l > 0; --l) { + tmp = a[l]; + for (i = l, j = l<<1; j <= n;) { + if (j < n && @lessthan@(v[a[j]], v[a[j+1]])) + j += 1; + if (@lessthan@(v[tmp], v[a[j]])) { + a[i] = a[j]; + i = j; + j += j; + } + else + break; } + a[i] = tmp; + } - for (; n > 1;) { - tmp = a[n]; - a[n] = a[1]; - n -= 1; - for (i = 1, j = 2; j <= n;) { - if (j < n && @lessthan@(v[a[j]], v[a[j+1]])) - j++; - if (@lessthan@(v[tmp], v[a[j]])) { - a[i] = a[j]; - i = j; - j += j; - }else - break; - } - a[i] = tmp; + for (; n > 1;) { + tmp = a[n]; + a[n] = a[1]; + n -= 1; + for (i = 1, j = 2; j <= n;) { + if (j < n && @lessthan@(v[a[j]], v[a[j+1]])) + j++; + if (@lessthan@(v[tmp], v[a[j]])) { + a[i] = a[j]; + i = j; + j += j; + } + else + break; } + a[i] = tmp; + } - return 0; + return 0; } static void @TYPE at _mergesort0(@type@ *pl, @type@ *pr, @type@ *pw) { - @type@ vp, *pi, *pj, *pk, *pm; + @type@ vp, *pi, *pj, *pk, *pm; - if (pr - pl > SMALL_MERGESORT) { - /* merge sort */ - pm = pl + ((pr - pl + 1)>>1); - @TYPE at _mergesort0(pl,pm-1,pw); - @TYPE at _mergesort0(pm,pr,pw); - for(pi = pw, pj = pl; pj < pm; ++pi, ++pj) { - *pi = *pj; - } - for(pk = pw, pm = pl; pk < pi && pj <= pr; ++pm) { - if (@lessequal@(*pk,*pj)) { - *pm = *pk; - ++pk; - }else{ - *pm = *pj; - ++pj; - } - } - for(; pk < pi; ++pm, ++pk) { - *pm = *pk; - } - }else{ - /* insertion sort */ - for(pi = pl + 1; pi <= pr; ++pi) { - vp = *pi; - for(pj = pi, pk = pi - 1;\ - pj > pl && @lessthan@(vp, *pk); --pj, --pk) { - *pj = *pk; - } - *pj = vp; - } + if (pr - pl > SMALL_MERGESORT) { + /* merge sort */ + pm = pl + ((pr - pl + 1)>>1); + @TYPE at _mergesort0(pl,pm-1,pw); + @TYPE at _mergesort0(pm,pr,pw); + for(pi = pw, pj = pl; pj < pm; ++pi, ++pj) { + *pi = *pj; } + for(pk = pw, pm = pl; pk < pi && pj <= pr; ++pm) { + if (@lessequal@(*pk,*pj)) { + *pm = *pk; + ++pk; + } + else { + *pm = *pj; + ++pj; + } + } + for(; pk < pi; ++pm, ++pk) { + *pm = *pk; + } + } + else { + /* insertion sort */ + for(pi = pl + 1; pi <= pr; ++pi) { + vp = *pi; + for(pj = pi, pk = pi - 1; pj > pl && @lessthan@(vp, *pk); --pj, --pk) { + *pj = *pk; + } + *pj = vp; + } + } } static int @TYPE at _mergesort(@type@ *start, intp num, void *unused) { - @type@ *pl, *pr, *pw; + @type@ *pl, *pr, *pw; - pl = start; pr = pl + num - 1; - pw = (@type@ *) PyDataMem_NEW(((1+num/2))*sizeof(@type@)); + pl = start; pr = pl + num - 1; + pw = (@type@ *) PyDataMem_NEW(((1+num/2))*sizeof(@type@)); - if (!pw) { - PyErr_NoMemory(); - return -1; - } + if (!pw) { + PyErr_NoMemory(); + return -1; + } - @TYPE at _mergesort0(pl, pr, pw); - PyDataMem_FREE(pw); - return 0; + @TYPE at _mergesort0(pl, pr, pw); + PyDataMem_FREE(pw); + + return 0; } static void @TYPE at _amergesort0(intp *pl, intp *pr, @type@ *v, intp *pw) { - @type@ vp; - intp vi, *pi, *pj, *pk, *pm; + @type@ vp; + intp vi, *pi, *pj, *pk, *pm; - if (pr - pl > SMALL_MERGESORT) { - /* merge sort */ - pm = pl + ((pr - pl + 1)>>1); - @TYPE at _amergesort0(pl,pm-1,v,pw); - @TYPE at _amergesort0(pm,pr,v,pw); - for(pi = pw, pj = pl; pj < pm; ++pi, ++pj) { - *pi = *pj; - } - for(pk = pw, pm = pl; pk < pi && pj <= pr; ++pm) { - if (@lessequal@(v[*pk],v[*pj])) { - *pm = *pk; - ++pk; - }else{ - *pm = *pj; - ++pj; - } - } - for(; pk < pi; ++pm, ++pk) { - *pm = *pk; - } - }else{ - /* insertion sort */ - for(pi = pl + 1; pi <= pr; ++pi) { - vi = *pi; - vp = v[vi]; - for(pj = pi, pk = pi - 1; \ - pj > pl && @lessthan@(vp, v[*pk]); --pj, --pk) { - *pj = *pk; - } - *pj = vi; - } + if (pr - pl > SMALL_MERGESORT) { + /* merge sort */ + pm = pl + ((pr - pl + 1)>>1); + @TYPE at _amergesort0(pl,pm-1,v,pw); + @TYPE at _amergesort0(pm,pr,v,pw); + for(pi = pw, pj = pl; pj < pm; ++pi, ++pj) { + *pi = *pj; } + for(pk = pw, pm = pl; pk < pi && pj <= pr; ++pm) { + if (@lessequal@(v[*pk],v[*pj])) { + *pm = *pk; + ++pk; + } + else { + *pm = *pj; + ++pj; + } + } + for(; pk < pi; ++pm, ++pk) { + *pm = *pk; + } + } + else { + /* insertion sort */ + for(pi = pl + 1; pi <= pr; ++pi) { + vi = *pi; + vp = v[vi]; + for(pj = pi, pk = pi - 1; pj > pl && @lessthan@(vp, v[*pk]); --pj, --pk) { + *pj = *pk; + } + *pj = vi; + } + } } static int @TYPE at _amergesort(@type@ *v, intp *tosort, intp num, void *unused) { - intp *pl, *pr, *pw; + intp *pl, *pr, *pw; - pl = tosort; pr = pl + num - 1; - pw = PyDimMem_NEW((1+num/2)); + pl = tosort; pr = pl + num - 1; + pw = PyDimMem_NEW((1+num/2)); - if (!pw) { - PyErr_NoMemory(); - return -1; - } + if (!pw) { + PyErr_NoMemory(); + return -1; + } - @TYPE at _amergesort0(pl, pr, v, pw); - PyDimMem_FREE(pw); - return 0; + @TYPE at _amergesort0(pl, pr, v, pw); + PyDimMem_FREE(pw); + + return 0; } /**end repeat**/ /**begin repeat -#TYPE=STRING,UNICODE# -#comp=strncmp,PyArray_CompareUCS4# +#TYPE=STRING, UNICODE# #type=char, PyArray_UCS4# -*/ +#lessthan=STRING_LT, UNICODE_LT# +#lessequal=STRING_LE, UNICODE_LE# +**/ static void @TYPE at _amergesort0(intp *pl, intp *pr, @type@ *v, intp *pw, int len) { - @type@ *vp; - intp vi, *pi, *pj, *pk, *pm; + @type@ *vp; + intp vi, *pi, *pj, *pk, *pm; - if (pr - pl > SMALL_MERGESORT) { - /* merge sort */ - pm = pl + ((pr - pl + 1)>>1); - @TYPE at _amergesort0(pl,pm-1,v,pw,len); - @TYPE at _amergesort0(pm,pr,v,pw,len); - for(pi = pw, pj = pl; pj < pm; ++pi, ++pj) { - *pi = *pj; - } - for(pk = pw, pm = pl; pk < pi && pj <= pr; ++pm) { - if (@comp@(v+(*pk)*len,v+(*pj)*len,len) <= 0) { - *pm = *pk; - ++pk; - }else{ - *pm = *pj; - ++pj; - } - } - for(; pk < pi; ++pm, ++pk) { - *pm = *pk; - } - }else{ - /* insertion sort */ - for(pi = pl + 1; pi <= pr; ++pi) { - vi = *pi; - vp = v + vi*len; - for(pj = pi, pk = pi - 1; \ - pj > pl && (@comp@(vp, v+(*pk)*len,len) < 0);\ - --pj, --pk) { - *pj = *pk; - } - *pj = vi; - } + if (pr - pl > SMALL_MERGESORT) { + /* merge sort */ + pm = pl + ((pr - pl + 1)>>1); + @TYPE at _amergesort0(pl,pm-1,v,pw,len); + @TYPE at _amergesort0(pm,pr,v,pw,len); + for(pi = pw, pj = pl; pj < pm;) { + *pi++ = *pj++; } + for(pk = pw, pm = pl; pk < pi && pj <= pr;) { + if (@lessequal@(v + (*pk)*len, v + (*pj)*len, len)) { + *pm++ = *pk++; + } else { + *pm++ = *pj++; + } + } + while(pk < pi) { + *pm++ = *pk++; + } + } else { + /* insertion sort */ + for(pi = pl + 1; pi <= pr; ++pi) { + vi = *pi; + vp = v + vi*len; + pj = pi; + pk = pi -1; + for(; pj > pl && @lessthan@(vp, v + (*pk)*len, len);) { + *pj-- = *pk--; + } + *pj = vi; + } + } } static int @@ -417,12 +434,13 @@ pw = PyDimMem_NEW((1+num/2)); if (!pw) { - PyErr_NoMemory(); - return -1; + PyErr_NoMemory(); + return -1; } @TYPE at _amergesort0(pl, pr, v, pw, chars); PyDimMem_FREE(pw); + return 0; } /**end repeat**/ From numpy-svn at scipy.org Fri Jul 6 11:05:15 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 6 Jul 2007 10:05:15 -0500 (CDT) Subject: [Numpy-svn] r3882 - trunk/numpy/distutils/fcompiler Message-ID: <20070706150515.100A439C0F1@new.scipy.org> Author: cookedm Date: 2007-07-06 10:05:09 -0500 (Fri, 06 Jul 2007) New Revision: 3882 Modified: trunk/numpy/distutils/fcompiler/__init__.py trunk/numpy/distutils/fcompiler/gnu.py trunk/numpy/distutils/fcompiler/intel.py Log: Add support for aliases for Fortran compilers. - 'g77' for gnu, 'gfortran' for gnu95, 'ifort' for intel Modified: trunk/numpy/distutils/fcompiler/__init__.py =================================================================== --- trunk/numpy/distutils/fcompiler/__init__.py 2007-07-05 07:00:57 UTC (rev 3881) +++ trunk/numpy/distutils/fcompiler/__init__.py 2007-07-06 15:05:09 UTC (rev 3882) @@ -149,6 +149,11 @@ } language_order = ['f90','f77'] + + # These will be set by the subclass + + compiler_type = None + compiler_aliases = () version_pattern = None possible_executables = [] @@ -163,6 +168,11 @@ 'ranlib' : None, } + # If compiler does not support compiling Fortran 90 then it can + # suggest using another compiler. For example, gnu would suggest + # gnu95 compiler type when there are F90 sources. + suggested_f90_compiler = None + compile_switch = "-c" object_switch = "-o " # Ending space matters! It will be stripped # but if it is missing then object_switch @@ -188,11 +198,6 @@ shared_lib_format = "%s%s" exe_extension = "" - # If compiler does not support compiling Fortran 90 then it can - # suggest using another compiler. For example, gnu would suggest - # gnu95 compiler type when there are F90 sources. - suggested_f90_compiler = None - _exe_cache = {} _executable_keys = ['version_cmd', 'compiler_f77', 'compiler_f90', @@ -688,17 +693,19 @@ ) fcompiler_class = None +fcompiler_aliases = None def load_all_fcompiler_classes(): """Cache all the FCompiler classes found in modules in the numpy.distutils.fcompiler package. """ from glob import glob - global fcompiler_class + global fcompiler_class, fcompiler_aliases if fcompiler_class is not None: return pys = os.path.join(os.path.dirname(__file__), '*.py') fcompiler_class = {} + fcompiler_aliases = {} for fname in glob(pys): module_name, ext = os.path.splitext(os.path.basename(fname)) module_name = 'numpy.distutils.fcompiler.' + module_name @@ -707,9 +714,10 @@ if hasattr(module, 'compilers'): for cname in module.compilers: klass = getattr(module, cname) - fcompiler_class[klass.compiler_type] = (klass.compiler_type, - klass, - klass.description) + desc = (klass.compiler_type, klass, klass.description) + fcompiler_class[klass.compiler_type] = desc + for alias in klass.compiler_aliases: + fcompiler_aliases[alias] = desc def _find_existing_fcompiler(compiler_types, osname=None, platform=None, @@ -785,9 +793,11 @@ plat = os.name if compiler is None: compiler = get_default_fcompiler(plat, requiref90=requiref90) - try: + if compiler in fcompiler_class: module_name, klass, long_description = fcompiler_class[compiler] - except KeyError: + elif compiler in fcompiler_aliases: + module_name, klass, long_description = fcompiler_aliases[compiler] + else: msg = "don't know how to compile Fortran code on platform '%s'" % plat if compiler is not None: msg = msg + " with '%s' compiler." % compiler Modified: trunk/numpy/distutils/fcompiler/gnu.py =================================================================== --- trunk/numpy/distutils/fcompiler/gnu.py 2007-07-05 07:00:57 UTC (rev 3881) +++ trunk/numpy/distutils/fcompiler/gnu.py 2007-07-06 15:05:09 UTC (rev 3882) @@ -12,6 +12,7 @@ class GnuFCompiler(FCompiler): compiler_type = 'gnu' + compiler_aliases = ('g77',) description = 'GNU Fortran 77 compiler' def gnu_version_match(self, version_string): @@ -270,6 +271,7 @@ class Gnu95FCompiler(GnuFCompiler): compiler_type = 'gnu95' + compiler_aliases = ('gfortran',) description = 'GNU Fortran 95 compiler' def version_match(self, version_string): Modified: trunk/numpy/distutils/fcompiler/intel.py =================================================================== --- trunk/numpy/distutils/fcompiler/intel.py 2007-07-05 07:00:57 UTC (rev 3881) +++ trunk/numpy/distutils/fcompiler/intel.py 2007-07-06 15:05:09 UTC (rev 3882) @@ -24,6 +24,7 @@ class IntelFCompiler(BaseIntelFCompiler): compiler_type = 'intel' + compiler_aliases = ('ifort',) description = 'Intel Fortran Compiler for 32-bit apps' version_match = intel_version_match('32-bit|IA-32') @@ -102,6 +103,7 @@ class IntelItaniumFCompiler(IntelFCompiler): compiler_type = 'intele' + compiler_aliases = () description = 'Intel Fortran Compiler for Itanium apps' version_match = intel_version_match('Itanium') @@ -125,6 +127,7 @@ class IntelEM64TFCompiler(IntelFCompiler): compiler_type = 'intelem' + compiler_aliases = () description = 'Intel Fortran Compiler for EM64T-based apps' version_match = intel_version_match('EM64T-based') From numpy-svn at scipy.org Fri Jul 6 15:42:50 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 6 Jul 2007 14:42:50 -0500 (CDT) Subject: [Numpy-svn] r3883 - trunk/numpy/core/src Message-ID: <20070706194250.F39DA39C035@new.scipy.org> Author: oliphant Date: 2007-07-06 14:42:46 -0500 (Fri, 06 Jul 2007) New Revision: 3883 Modified: trunk/numpy/core/src/ufuncobject.c Log: Remove un-necessary DECREF Modified: trunk/numpy/core/src/ufuncobject.c =================================================================== --- trunk/numpy/core/src/ufuncobject.c 2007-07-06 15:05:09 UTC (rev 3882) +++ trunk/numpy/core/src/ufuncobject.c 2007-07-06 19:42:46 UTC (rev 3883) @@ -902,7 +902,6 @@ ret = _find_matching_userloop(obj, arg_types, scalars, function, data, self->nargs, self->nin); - Py_DECREF(obj); return ret; } From numpy-svn at scipy.org Tue Jul 10 12:10:43 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 10 Jul 2007 11:10:43 -0500 (CDT) Subject: [Numpy-svn] r3884 - in trunk/numpy/lib: . tests Message-ID: <20070710161043.0D83B39C04E@new.scipy.org> Author: stefan Date: 2007-07-10 11:10:25 -0500 (Tue, 10 Jul 2007) New Revision: 3884 Modified: trunk/numpy/lib/shape_base.py trunk/numpy/lib/tests/test_shape_base.py Log: Tile empty arrays. Modified: trunk/numpy/lib/shape_base.py =================================================================== --- trunk/numpy/lib/shape_base.py 2007-07-06 19:42:46 UTC (rev 3883) +++ trunk/numpy/lib/shape_base.py 2007-07-10 16:10:25 UTC (rev 3884) @@ -620,7 +620,7 @@ d = len(tup) c = _nx.array(A,copy=False,subok=True,ndmin=d) shape = list(c.shape) - n = c.size + n = max(c.size,1) if (d < c.ndim): tup = (1,)*(c.ndim-d) + tup for i, nrep in enumerate(tup): @@ -629,5 +629,5 @@ dim_in = shape[i] dim_out = dim_in*nrep shape[i] = dim_out - n /= dim_in + n /= max(dim_in,1) return c.reshape(shape) Modified: trunk/numpy/lib/tests/test_shape_base.py =================================================================== --- trunk/numpy/lib/tests/test_shape_base.py 2007-07-06 19:42:46 UTC (rev 3883) +++ trunk/numpy/lib/tests/test_shape_base.py 2007-07-10 16:10:25 UTC (rev 3884) @@ -384,6 +384,11 @@ assert_equal(tile(b,(2,2)),[[1,2,1,2],[3,4,3,4], [1,2,1,2],[3,4,3,4]]) + def check_empty(self): + a = array([[[]]]) + d = tile(a,(3,2,5)).shape + assert_equal(d,(3,2,0)) + def check_kroncompare(self): import numpy.random as nr reps=[(2,),(1,2),(2,1),(2,2),(2,3,2),(3,2)] From numpy-svn at scipy.org Mon Jul 16 13:43:12 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 16 Jul 2007 12:43:12 -0500 (CDT) Subject: [Numpy-svn] r3885 - trunk/numpy/core Message-ID: <20070716174312.5913139C213@new.scipy.org> Author: stefan Date: 2007-07-16 12:42:56 -0500 (Mon, 16 Jul 2007) New Revision: 3885 Modified: trunk/numpy/core/fromnumeric.py Log: Clean up fromnumeric docstrings. Closes ticket #543. Modified: trunk/numpy/core/fromnumeric.py =================================================================== --- trunk/numpy/core/fromnumeric.py 2007-07-10 16:10:25 UTC (rev 3884) +++ trunk/numpy/core/fromnumeric.py 2007-07-16 17:42:56 UTC (rev 3885) @@ -71,7 +71,8 @@ - `subarray` : array :See also: - numpy.ndarray.take() is the equivalent method. + - numpy.ndarray.take() : equivalent method + """ try: take = a.take @@ -99,8 +100,9 @@ This will be a new view object if possible; otherwise, it will return a copy. - :See also: - numpy.ndarray.reshape() is the equivalent method. + :SeeAlso: + - numpy.ndarray.reshape() : Equivalent method. + """ try: reshape = a.reshape @@ -136,19 +138,21 @@ :Returns: - `merged_array` : array - :See also: - numpy.ndarray.choose() is the equivalent method. + :SeeAlso: + - numpy.ndarray.choose() : equivalent method - :Example: - >>> choices = [[0, 1, 2, 3], [10, 11, 12, 13], - ... [20, 21, 22, 23], [30, 31, 32, 33]] - >>> choose([2, 3, 1, 0], choices) - array([20, 31, 12, 3]) - >>> choose([2, 4, 1, 0], choices, mode='clip') - array([20, 31, 12, 3]) - >>> choose([2, 4, 1, 0], choices, mode='wrap') - array([20, 1, 12, 3]) + Examples + --------- + >>> choices = [[0, 1, 2, 3], [10, 11, 12, 13], + ... [20, 21, 22, 23], [30, 31, 32, 33]] + >>> choose([2, 3, 1, 0], choices) + array([20, 31, 12, 3]) + >>> choose([2, 4, 1, 0], choices, mode='clip') + array([20, 31, 12, 3]) + >>> choose([2, 4, 1, 0], choices, mode='wrap') + array([20, 1, 12, 3]) + """ try: choose = a.choose @@ -174,15 +178,17 @@ :Returns: - `repeated_array` : array - :See also: - numpy.ndarray.repeat() is the equivalent method. + :SeeAlso: + - numpy.ndarray.repeat() : equivalent method - :Example: - >>> repeat([0, 1, 2], 2) - array([0, 0, 1, 1, 2, 2]) - >>> repeat([0, 1, 2], [2, 3, 4]) - array([0, 0, 1, 1, 1, 2, 2, 2, 2]) + Examples + -------- + >>> repeat([0, 1, 2], 2) + array([0, 0, 1, 1, 2, 2]) + >>> repeat([0, 1, 2], [2, 3, 4]) + array([0, 0, 1, 1, 1, 2, 2, 2, 2]) + """ try: repeat = a.repeat @@ -192,22 +198,24 @@ def put (a, ind, v, mode='raise'): - """put(a, ind, v) results in a[n] = v[n] for all n in ind. If v is - shorter than mask it will be repeated as necessary. In particular v can - be a scalar or length 1 array. The routine put is the equivalent of the + """Set a[n] = v[n] for all n in ind. If v is shorter than mask it + will be repeated as necessary. In particular v can be a scalar or + length 1 array. The routine put is the equivalent of the following (although the loop is in C for speed): ind = array(indices, copy=False) v = array(values, copy=False).astype(a.dtype) for i in ind: a.flat[i] = v[i] + a must be a contiguous numpy array. + """ return a.put(ind, v, mode) def swapaxes(a, axis1, axis2): - """swapaxes(a, axis1, axis2) returns array a with axis1 and axis2 - interchanged. + """Return array a with axis1 and axis2 interchanged. + """ try: swapaxes = a.swapaxes @@ -217,9 +225,10 @@ def transpose(a, axes=None): - """transpose(a, axes=None) returns a view of the array with dimensions - permuted according to axes. If axes is None (default) returns array - with dimensions reversed. + """Return a view of the array with dimensions permuted according + to axes. If axes is None (default) returns array with dimensions + reversed. + """ try: transpose = a.transpose @@ -231,65 +240,57 @@ def sort(a, axis=-1, kind='quicksort', order=None): """Return copy of 'a' sorted along the given axis. - *Description* + :Description: Perform an inplace sort along the given axis using the algorithm specified by the kind keyword. - *Parameters*: - - a : array type + :Parameters: + a : array Array to be sorted. - axis : integer - Axis to be sorted along. None indicates that the flattened + Axis along which to sort. None indicates that the flattened array should be used. Default is -1. - kind : string Sorting algorithm to use. Possible values are 'quicksort', 'mergesort', or 'heapsort'. Default is 'quicksort'. - order : list type or None When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified. - *Returns*: + :Returns: + sorted_array : array of same type as a - sorted_array : type is unchanged. + :SeeAlso: + - argsort : Indirect sort. + - lexsort : Indirect stable sort on multiple keys. + - searchsorted : Find keys in sorted array. - *SeeAlso*: + Notes + ----- - argsort - Indirect sort - lexsort - Indirect stable sort on multiple keys - searchsorted - Find keys in sorted array + The various sorts are characterized by average speed, worst case + performance, need for work space, and whether they are stable. A + stable sort keeps items with the same key in the same relative + order. The three available algorithms have the following + properties: - *Notes* + +-----------+-------+-------------+------------+-------+ + | kind | speed | worst case | work space | stable| + +===========+=======+=============+============+=======+ + | quicksort | 1 | O(n^2) | 0 | no | + +-----------+-------+-------------+------------+-------+ + | mergesort | 2 | O(n*log(n)) | ~n/2 | yes | + +-----------+-------+-------------+------------+-------+ + | heapsort | 3 | O(n*log(n)) | 0 | no | + +-----------+-------+-------------+------------+-------+ - The various sorts are characterized by average speed, worst case - performance, need for work space, and whether they are stable. A - stable sort keeps items with the same key in the same relative - order. The three available algorithms have the following - properties: + All the sort algorithms make temporary copies of the data when + the sort is not along the last axis. Consequently, sorts along + the last axis are faster and use less space than sorts along + other axis. - +-----------+-------+-------------+------------+-------+ - | kind | speed | worst case | work space | stable| - +===========+=======+=============+============+=======+ - | quicksort | 1 | O(n^2) | 0 | no | - +-----------+-------+-------------+------------+-------+ - | mergesort | 2 | O(n*log(n)) | ~n/2 | yes | - +-----------+-------+-------------+------------+-------+ - | heapsort | 3 | O(n*log(n)) | 0 | no | - +-----------+-------+-------------+------------+-------+ - - All the sort algorithms make temporary copies of the data when - the sort is not along the last axis. Consequently, sorts along - the last axis are faster and use less space than sorts along - other axis. - """ if axis is None: a = asanyarray(a).flatten() @@ -303,66 +304,56 @@ def argsort(a, axis=-1, kind='quicksort', order=None): """Returns array of indices that index 'a' in sorted order. - *Description* - Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as a that index data along the given axis in sorted order. - *Parameters*: - - a : array type - Array containing values that the returned indices should - sort. - + :Parameters: + a : array + Values that the returned indices should sort. axis : integer Axis to be indirectly sorted. None indicates that the flattened array should be used. Default is -1. - kind : string Sorting algorithm to use. Possible values are 'quicksort', 'mergesort', or 'heapsort'. Default is 'quicksort'. - order : list type or None When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified. - *Returns*: - + :Returns: indices : integer array Array of indices that sort 'a' along the specified axis. - *SeeAlso*: + :SeeAlso: + - lexsort : Indirect stable sort with multiple keys. + - sort : Inplace sort. - lexsort - Indirect stable sort with multiple keys - sort - Inplace sort + Notes + ----- - *Notes* + The various sorts are characterized by average speed, worst case + performance, need for work space, and whether they are stable. A + stable sort keeps items with the same key in the same relative + order. The three available algorithms have the following + properties: - The various sorts are characterized by average speed, worst case - performance, need for work space, and whether they are stable. A - stable sort keeps items with the same key in the same relative - order. The three available algorithms have the following - properties: + +-----------+-------+-------------+------------+-------+ + | kind | speed | worst case | work space | stable| + +===========+=======+=============+============+=======+ + | quicksort | 1 | O(n^2) | 0 | no | + +-----------+-------+-------------+------------+-------+ + | mergesort | 2 | O(n*log(n)) | ~n/2 | yes | + +-----------+-------+-------------+------------+-------+ + | heapsort | 3 | O(n*log(n)) | 0 | no | + +-----------+-------+-------------+------------+-------+ - +-----------+-------+-------------+------------+-------+ - | kind | speed | worst case | work space | stable| - +===========+=======+=============+============+=======+ - | quicksort | 1 | O(n^2) | 0 | no | - +-----------+-------+-------------+------------+-------+ - | mergesort | 2 | O(n*log(n)) | ~n/2 | yes | - +-----------+-------+-------------+------------+-------+ - | heapsort | 3 | O(n*log(n)) | 0 | no | - +-----------+-------+-------------+------------+-------+ + All the sort algorithms make temporary copies of the data when + the sort is not along the last axis. Consequently, sorts along + the last axis are faster and use less space than sorts along + other axis. - All the sort algorithms make temporary copies of the data when - the sort is not along the last axis. Consequently, sorts along - the last axis are faster and use less space than sorts along - other axis. - """ try: argsort = a.argsort @@ -372,8 +363,9 @@ def argmax(a, axis=None): - """argmax(a,axis=None) returns the indices to the maximum value of the - 1-D arrays along the given axis. + """Return the indices to the maximum value of the 1-D arrays along + the given axis. + """ try: argmax = a.argmax @@ -383,8 +375,9 @@ def argmin(a, axis=None): - """argmin(a,axis=None) returns the indices to the minimum value of the - 1-D arrays along the given axis. + """Return the indices to the minimum value of the 1-D arrays along + the given axis. + """ try: argmin = a.argmin @@ -394,50 +387,48 @@ def searchsorted(a, v, side='left'): - """Returns indices where keys in v should be inserted to maintain order. + """Return indices where keys in v should be inserted to maintain + order. - *Description* + Find the indices into a sorted array such that if the + corresponding keys in v were inserted before the indices the + order of a would be preserved. If side='left', then the first + such index is returned. If side='right', then the last such index + is returned. If there is no such index because the key is out of + bounds, then the length of a is returned, i.e., the key would + need to be appended. The returned index array has the same shape + as v. - Find the indices into a sorted array such that if the - corresponding keys in v were inserted before the indices the - order of a would be preserved. If side='left', then the first - such index is returned. If side='right', then the last such index - is returned. If there is no such index because the key is out of - bounds, then the length of a is returned, i.e., the key would - need to be appended. The returned index array has the same shape - as v. - - *Parameters*: - - a : array - 1-d array sorted in ascending order. - + :Parameters: + a : 1-d array + Array sorted in ascending order. v : array or list type Array of keys to be searched for in a. - side : string Possible values are : 'left', 'right'. Default is 'left'. Return the first or last index where the key could be inserted. - *Returns*: - + :Returns: indices : integer array Array of insertion points with the same shape as v. - *SeeAlso*: + :SeeAlso: + - sort : Inplace sort. + - histogram : Produce histogram from 1-d data. - sort - Inplace sort - histogram - Produce histogram from 1-d data + Notes + ----- + The array a must be 1-d and is assumed to be sorted in ascending + order. Searchsorted uses binary search to find the required + insertion points. - *Notes* + Examples + -------- - The array a must be 1-d and is assumed to be sorted in ascending - order. Searchsorted uses binary search to find the required - insertion points. + >>> searchsorted([1,2,3,4,5],[6,4,0]) + array([5, 3, 0]) """ try: @@ -448,12 +439,14 @@ def resize(a, new_shape): - """resize(a,new_shape) returns a new array with the specified shape. - The original array's total size can be any size. It fills the new - array with repeated copies of a. + """Return a new array with the specified shape. - Note that a.resize(new_shape) will fill array with 0's beyond current - definition of a. + The original array's total size can be any size. The new array is + filled with repeated copies of a. + + Note that a.resize(new_shape) will fill the array with 0's beyond + current definition of a. + """ if isinstance(new_shape, (int, nt.integer)): @@ -480,7 +473,23 @@ def squeeze(a): - "Returns a with any ones from the shape of a removed" + """Remove single-dimensional entries from the shape of a. + + Examples + -------- + + >>> x = array([[[1,1,1],[2,2,2],[3,3,3]]]) + >>> x + array([[[1, 1, 1], + [2, 2, 2], + [3, 3, 3]]]) + >>> x.shape + (1, 3, 3) + >>> squeeze(x).shape + (3, 3) + + """ + try: squeeze = a.squeeze except AttributeError: @@ -489,89 +498,91 @@ def diagonal(a, offset=0, axis1=0, axis2=1): - """Return specified diagonals. Uses first two indices by default. + """Return specified diagonals. - *Description* - If a is 2-d, returns the diagonal of self with the given offset, - i.e., the collection of elements of the form a[i,i+offset]. If a is - n-d with n > 2, then the axes specified by axis1 and axis2 are used - to determine the 2-d subarray whose diagonal is returned. The shape - of the resulting array can be determined by removing axis1 and axis2 - and appending an index to the right equal to the size of the - resulting diagonals. + i.e., the collection of elements of the form a[i,i+offset]. If a + has more than two dimensions, then the axes specified by axis1 and + axis2 are used to determine the 2-d subarray whose diagonal is + returned. The shape of the resulting array can be determined by + removing axis1 and axis2 and appending an index to the right equal + to the size of the resulting diagonals. - *Parameters*: - + :Parameters: offset : integer Offset of the diagonal from the main diagonal. Can be both positive and negative. Defaults to main diagonal. - axis1 : integer Axis to be used as the first axis of the 2-d subarrays from which the diagonals should be taken. Defaults to first axis. - axis2 : integer Axis to be used as the second axis of the 2-d subarrays from which the diagonals should be taken. Defaults to second axis. - *Returns*: + :Returns: + array_of_diagonals : array of same type as a + If a is 2-d, a 1-d array containing the diagonal is + returned. If a has larger dimensions, then an array of + diagonals is returned. - array_of_diagonals : type of original array - If a is 2-d, then a 1-d array containing the diagonal is - returned. - If a is n-d, n > 2, then an array of diagonals is returned. + :SeeAlso: + - diag : Matlab workalike for 1-d and 2-d arrays. + - diagflat : Create diagonal arrays. + - trace : Sum along diagonals. - *SeeAlso*: + Examples + -------- - diag : - Matlab workalike for 1-d and 2-d arrays - diagflat : - creates diagonal arrays - trace : - sum along diagonals + >>> a = arange(4).reshape(2,2) + >>> a + array([[0, 1], + [2, 3]]) + >>> a.diagonal() + array([0, 3]) + >>> a.diagonal(1) + array([1]) - *Examples*: + >>> a = arange(8).reshape(2,2,2) + >>> a + array([[[0, 1], + [2, 3]], + [[4, 5], + [6, 7]]]) + >>> a.diagonal(0,-2,-1) + array([[0, 3], + [4, 7]]) - >>> a = arange(4).reshape(2,2) - >>> a - array([[0, 1], - [2, 3]]) - >>> a.diagonal() - array([0, 3]) - >>> a.diagonal(1) - array([1]) - - >>> a = arange(8).reshape(2,2,2) - >>> a - array([[[0, 1], - [2, 3]], - [[4, 5], - [6, 7]]]) - >>> a.diagonal(0,-2,-1) - array([[0, 3], - [4, 7]]) - """ return asarray(a).diagonal(offset, axis1, axis2) def trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None): - """trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals - (defined by the last two dimenions) of the array. + """Return the sum along diagonals of the array. + """ return asarray(a).trace(offset, axis1, axis2, dtype, out) def ravel(m,order='C'): - """ravel(m) returns a 1d array corresponding to all the elements of - its argument. The new array is a view of m if possible, otherwise it - is a copy. + """Return a 1d array with all the elements of m. The new array is + a view of m if possible, otherwise it is a copy. + + Examples + -------- + + >>> x = array([[1,2,3],[4,5,6]]) + >>> x + array([[1, 2, 3], + [4, 5, 6]]) + >>> ravel(x) + array([1, 2, 3, 4, 5, 6]) + """ a = asarray(m) return a.ravel(order) def nonzero(a): - """nonzero(a) returns the indices of the elements of a which are not zero + """Return the indices of the elements of a which are not zero. + """ try: nonzero = a.nonzero @@ -582,8 +593,16 @@ return res def shape(a): - """shape(a) returns the shape of a (as a function call which also - works on nested sequences). + """Return the shape of a. This function can also be called on + nested sequences, e.g. + + Examples + -------- + + >>> x = array([1,2,3]) + >>> shape((x,x,x)) + (3, 3) + """ try: result = a.shape @@ -592,9 +611,11 @@ return result def compress(condition, m, axis=None, out=None): - """compress(condition, x, axis=None) = those elements of x corresponding - to those elements of condition that are "true". condition must be the - same size as the given dimension of x.""" + """Return m where condition is true. + + Equivalent to m[condition]. + + """ try: compress = m.compress except AttributeError: @@ -602,9 +623,11 @@ return compress(condition, axis, out) def clip(m, m_min, m_max): - """clip(m, m_min, m_max) = every entry in m that is less than m_min is - replaced by m_min, and every entry greater than m_max is replaced by - m_max. + """Limit the values of m to [m_min, m_max]. Equivalent to + + m[m < m_min] = m_min + m[m > m_max] = m_max + """ try: clip = m.clip @@ -623,7 +646,9 @@ --------------------------------------------------- bool, int8, int16, int32 int32 - Examples: + Examples + -------- + >>> N.sum([0.5, 1.5]) 2.0 >>> N.sum([0.5, 1.5], dtype=N.int32) @@ -632,6 +657,7 @@ 6 >>> N.sum([[0, 1], [0, 5]], axis=1) array([1, 5]) + """ if isinstance(x, _gentype): res = _sum_(x) @@ -646,7 +672,9 @@ return sum(axis, dtype, out) def product (x, axis=None, dtype=None, out=None): - """Product of the array elements over the given axis.""" + """Product of the array elements over the given axis. + + """ try: prod = x.prod except AttributeError: @@ -654,7 +682,9 @@ return prod(axis, dtype, out) def sometrue (x, axis=None, out=None): - """Perform a logical_or over the given axis.""" + """Perform a logical_or over the given axis. + + """ try: any = x.any except AttributeError: @@ -662,7 +692,9 @@ return any(axis, out) def alltrue (x, axis=None, out=None): - """Perform a logical_and over the given axis.""" + """Perform a logical_and over the given axis. + + """ try: all = x.all except AttributeError: @@ -670,7 +702,8 @@ return all(axis, out) def any(x,axis=None, out=None): - """Return true if any elements of x are true: + """Return true if any elements of x are true. + """ try: any = x.any @@ -680,6 +713,7 @@ def all(x,axis=None, out=None): """Return true if all elements of x are true: + """ try: all = x.all @@ -688,7 +722,9 @@ return all(axis, out) def cumsum (x, axis=None, dtype=None, out=None): - """Sum the array over the given axis.""" + """Sum the array over the given axis. + + """ try: cumsum = x.cumsum except AttributeError: @@ -696,7 +732,9 @@ return cumsum(axis, dtype, out) def cumproduct (x, axis=None, dtype=None, out=None): - """Sum the array over the given axis.""" + """Return the cumulative product over the given axis. + + """ try: cumprod = x.cumprod except AttributeError: @@ -704,7 +742,8 @@ return cumprod(axis, dtype, out) def ptp(a, axis=None, out=None): - """Return maximum - minimum along the the given dimension + """Return maximum - minimum along the the given dimension. + """ try: ptp = a.ptp @@ -714,6 +753,7 @@ def amax(a, axis=None, out=None): """Return the maximum of 'a' along dimension axis. + """ try: amax = a.max @@ -733,6 +773,7 @@ def alen(a): """Return the length of a Python object interpreted as an array of at least 1 dimension. + """ try: return len(a) @@ -740,7 +781,8 @@ return len(array(a,ndmin=1)) def prod(a, axis=None, dtype=None, out=None): - """Return the product of the elements along the given axis + """Return the product of the elements along the given axis. + """ try: prod = a.prod @@ -749,7 +791,8 @@ return prod(axis, dtype, out) def cumprod(a, axis=None, dtype=None, out=None): - """Return the cumulative product of the elments along the given axis + """Return the cumulative product of the elements along the given axis. + """ try: cumprod = a.cumprod @@ -758,22 +801,29 @@ return cumprod(axis, dtype, out) def ndim(a): + """Return the number of dimensions of a. + + """ try: return a.ndim except AttributeError: return asarray(a).ndim def rank(a): - """Get the rank of sequence a (the number of dimensions, not a matrix rank) - The rank of a scalar is zero. + """Return the rank of sequence a (the number of dimensions, not + the matrix rank). The rank of a scalar is zero. + """ try: return a.ndim except AttributeError: return asarray(a).ndim -def size (a, axis=None): - "Get the number of elements in sequence a, or along a certain axis." +def size(a, axis=None): + """Return the number of elements in sequence a, or along a given axis. + + """ + if axis is None: try: return a.size @@ -786,27 +836,31 @@ return asarray(a).shape[axis] def round_(a, decimals=0, out=None): - """Returns reference to result. Copies a and rounds to 'decimals' places. + """Round a to the given number of decimals. - Keyword arguments: - decimals -- number of decimal places to round to (default 0). - out -- existing array to use for output (default copy of a). + The real and imaginary parts of complex numbers are rounded + separately. Nothing is done if the input is an integer array with + decimals >= 0. - Returns: - Reference to out, where None specifies a copy of the original - array a. + :Parameters: + decimals : integer + Number of decimal places to round to (default 0). When + 'decimals' is negative it specifies the number of + positions to the left of the decimal point. + out : array + Existing array to use for output (by default, make a + copy of a). - Round to the specified number of decimals. When 'decimals' is - negative it specifies the number of positions to the left of the - decimal point. The real and imaginary parts of complex numbers are - rounded separately. Nothing is done if the array is not of float - type and 'decimals' is greater than or equal to 0. + :Returns: + out : array + May be used to specify a different array to hold the + result rather than the default 'a'. If the type of the + array specified by 'out' differs from that of 'a', the + result is cast to the new type, otherwise the original + type is kept. Floats round to floats by default. - The keyword 'out' may be used to specify a different array to hold - the result rather than the default 'a'. If the type of the array - specified by 'out' differs from that of 'a', the result is cast to - the new type, otherwise the original type is kept. Floats round to - floats by default. + Notes + ----- Numpy rounds to even. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. Results may also be surprising due to the inexact @@ -828,46 +882,38 @@ def mean(a, axis=None, dtype=None, out=None): """Compute the mean along the specified axis. - *Description* + Returns the average of the array elements. The average is taken + over the flattened array by default, otherwise over the specified + axis. - Returns the average of the array elements. The average is taken - over the flattened array by default, otherwise over the specified - axis. - - *Parameters*: - + :Parameters: axis : integer Axis along which the means are computed. The default is to compute the standard deviation of the flattened array. - dtype : type Type to use in computing the means. For arrays of integer type the default is float32, for arrays of float types it is the same as the array type. - out : ndarray Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary. - *Returns*: - - mean : The return type varies, see above. + :Returns: + mean : array (see dtype parameter above) A new array holding the result is returned unless out is specified, in which case a reference to out is returned. - *SeeAlso*: + :SeeAlso: + - var : Variance + - std : Standard deviation - var - Variance - std - Standard deviation + Notes + ----- - *Notes* + The mean is the sum of the elements along the axis divided by the + number of elements. - The mean is the sum of the elements along the axis divided by the - number of elements. - """ try: mean = a.mean @@ -879,51 +925,43 @@ def std(a, axis=None, dtype=None, out=None): """Compute the standard deviation along the specified axis. - *Description* + Returns the standard deviation of the array elements, a measure + of the spread of a distribution. The standard deviation is + computed for the flattened array by default, otherwise over the + specified axis. - Returns the standard deviation of the array elements, a measure - of the spread of a distribution. The standard deviation is - computed for the flattened array by default, otherwise over the - specified axis. - - *Parameters*: - + :Parameters: axis : integer Axis along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array. - dtype : type Type to use in computing the standard deviation. For arrays of integer type the default is float32, for arrays of float types it is the same as the array type. - out : ndarray Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary. - *Returns*: - + :Returns: standard_deviation : The return type varies, see above. A new array holding the result is returned unless out is specified, in which case a reference to out is returned. - *SeeAlso*: + :SeeAlso: + - var : Variance + - mean : Average - var - Variance - mean - Average + Notes + ----- - *Notes* + The standard deviation is the square root of the average of the + squared deviations from the mean, i.e. var = sqrt(mean((x - + x.mean())**2)). The computed standard deviation is biased, i.e., + the mean is computed by dividing by the number of elements, N, + rather than by N-1. - The standard deviation is the square root of the average of the - squared deviations from the mean, i.e. var = sqrt(mean((x - - x.mean())**2)). The computed standard deviation is biased, i.e., - the mean is computed by dividing by the number of elements, N, - rather than by N-1. - """ try: std = a.std @@ -935,48 +973,40 @@ def var(a, axis=None, dtype=None, out=None): """Compute the variance along the specified axis. - *Description* + Returns the variance of the array elements, a measure of the + spread of a distribution. The variance is computed for the + flattened array by default, otherwise over the specified axis. - Returns the variance of the array elements, a measure of the - spread of a distribution. The variance is computed for the - flattened array by default, otherwise over the specified axis. - - *Parameters*: - + :Parameters: axis : integer Axis along which the variance is computed. The default is to compute the variance of the flattened array. - dtype : type Type to use in computing the variance. For arrays of integer type the default is float32, for arrays of float types it is the same as the array type. - out : ndarray Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary. - *Returns*: - - variance : depends, see above + :Returns: + variance : array (see dtype parameter above) A new array holding the result is returned unless out is specified, in which case a reference to out is returned. - *SeeAlso*: + :SeeAlso: + - std : Standard deviation + - mean : Average - std - Standard deviation - mean - Average + Notes + ----- - *Notes* + The variance is the average of the squared deviations from the + mean, i.e. var = mean((x - x.mean())**2). The computed variance + is biased, i.e., the mean is computed by dividing by the number + of elements, N, rather than by N-1. - The variance is the average of the squared deviations from the - mean, i.e. var = mean((x - x.mean())**2). The computed variance - is biased, i.e., the mean is computed by dividing by the number - of elements, N, rather than by N-1. - """ try: var = a.var From numpy-svn at scipy.org Tue Jul 17 08:32:06 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 17 Jul 2007 07:32:06 -0500 (CDT) Subject: [Numpy-svn] r3886 - trunk/numpy Message-ID: <20070717123206.6C02439C1CB@new.scipy.org> Author: stefan Date: 2007-07-17 07:31:52 -0500 (Tue, 17 Jul 2007) New Revision: 3886 Modified: trunk/numpy/add_newdocs.py Log: Fix documentation for 'where'. Modified: trunk/numpy/add_newdocs.py =================================================================== --- trunk/numpy/add_newdocs.py 2007-07-16 17:42:56 UTC (rev 3885) +++ trunk/numpy/add_newdocs.py 2007-07-17 12:31:52 UTC (rev 3886) @@ -343,11 +343,11 @@ The result is shaped like condition and has elements of x and y where condition is respectively true or false. If x or y are not given, - then it is equivalent to condition.nonzero(). + condition.nonzero() is returned. To group the indices by element, rather than dimension, use - transpose(where(condition, | x, y)) + transpose(where(condition)) instead. This always results in a 2d array, with a row of indices for each element that satisfies the condition. From numpy-svn at scipy.org Tue Jul 17 09:46:35 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 17 Jul 2007 08:46:35 -0500 (CDT) Subject: [Numpy-svn] r3887 - trunk/numpy/core/tests Message-ID: <20070717134635.6BB3E39C21B@new.scipy.org> Author: stefan Date: 2007-07-17 08:46:16 -0500 (Tue, 17 Jul 2007) New Revision: 3887 Modified: trunk/numpy/core/tests/test_regression.py Log: Regression test for ticket #396. Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2007-07-17 12:31:52 UTC (rev 3886) +++ trunk/numpy/core/tests/test_regression.py 2007-07-17 13:46:16 UTC (rev 3887) @@ -594,6 +594,11 @@ v = N.vectorize(p) assert_valid_refcount(v) + def check_poly1d_nan_roots(self, level=rlevel): + """Ticket #396""" + p = N.poly1d([N.nan,N.nan,1], r=0) + self.failUnlessRaises(N.linalg.LinAlgError,getattr,p,"r") + def check_refcount_vdot(self, level=rlevel): """Changeset #3443""" assert_valid_refcount(N.vdot) From numpy-svn at scipy.org Thu Jul 19 05:45:37 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 19 Jul 2007 04:45:37 -0500 (CDT) Subject: [Numpy-svn] r3888 - trunk/numpy/f2py/lib/parser Message-ID: <20070719094537.55D1739C22D@new.scipy.org> Author: pearu Date: 2007-07-19 04:45:27 -0500 (Thu, 19 Jul 2007) New Revision: 3888 Modified: trunk/numpy/f2py/lib/parser/doc.txt Log: updated fortran parser docs to rest Modified: trunk/numpy/f2py/lib/parser/doc.txt =================================================================== --- trunk/numpy/f2py/lib/parser/doc.txt 2007-07-17 13:46:16 UTC (rev 3887) +++ trunk/numpy/f2py/lib/parser/doc.txt 2007-07-19 09:45:27 UTC (rev 3888) @@ -6,16 +6,16 @@ Fortran parser package structure ================================ -numpy.f2py.lib.parser package contains the following files: +`numpy.f2py.lib.parser` package contains the following files: api.py ------ Public API for Fortran parser. -It exposes Statement classes, CHAR_BIT constant, and parse function. +It exposes `Statement` subclasses, `CHAR_BIT` constant, and a function `parse`. -Function parse(, ..) parses, analyzes and returns Statement +Function `parse(, ..)` parses, analyzes and returns a `Statement` tree of Fortran input. For example, :: @@ -63,14 +63,14 @@ readfortran.py -------------- -Tools for reading Fortran codes from file and string objects. +This file contains tools for reading Fortran codes from file and string objects. -To read Fortran code from a file, use FortranFileReader class. +To read Fortran code from a file, use `FortranFileReader` class. -FortranFileReader class is iterator over Fortran code lines -as is derived from FortranReaderBase class. -It automatically handles line continuations and comments as -well as detects if Fortran file is in free or fixed format. +`FortranFileReader` class is iterator over Fortran code lines +and is derived from `FortranReaderBase` class. +It automatically handles the line continuations and comments, as +well as it detects if Fortran file is in the free or fixed format. For example, @@ -88,31 +88,31 @@ >>> reader.next() Line('integer i,incx,incy,ix,iy,m,mp1,n',(9, 9),'') -FortranReaderBase.next() method may return Line, SyntaxErrorLine, Comment, MultiLine, -SyntaxErrorMultiLine instances. +Note that `FortranReaderBase.next()` method may return `Line`, `SyntaxErrorLine`, `Comment`, `MultiLine`, +`SyntaxErrorMultiLine` instances. -Line instance has the following attributes: +`Line` instance has the following attributes: - * .line - contains Fortran code line - * .span - a 2-tuple containing the span of line numbers containing + * `.line` - contains Fortran code line + * `.span` - a 2-tuple containing the span of line numbers containing Fortran code in the original Fortran file - * .label - the label of Fortran code line - * .reader - the FortranReaderBase class instance - * .strline - if not None then contains Fortran code line with parenthesis - content and string literal constants saved in .strlinemap dictionary. - * .is_f2py_directive - True if line started with f2py directive comment. + * `.label` - the label of Fortran code line + * `.reader` - the `FortranReaderBase` class instance + * `.strline` - if it is not `None` then it contains Fortran code line with parenthesis + content and string literal constants saved in the `.strlinemap` dictionary. + * `.is_f2py_directive` - `True` if line starts with the f2py directive comment. and the following methods: - * .get_line() - returns .strline (also evalutes it if None). Also - handles Hollerith contstants in fixed F77 mode. - * .isempty() - returns True if Fortran line contains no code. - * .copy(line=None, apply_map=False) - returns a Line instance - with given .span, .label, .reader information but line content - replaced with line (when not None) and applying .strlinemap - mapping (when apply_map is True). - * .apply_map(line) - apply .strlinemap mapping to line. - * .has_map() - returns True if .strlinemap mapping exists. + * `.get_line()` - returns `.strline` (also evalutes it if None). Also + handles Hollerith contstants in the fixed F77 mode. + * `.isempty()` - returns `True` if Fortran line contains no code. + * `.copy(line=None, apply_map=False)` - returns a `Line` instance + with given `.span`, `.label`, `.reader` information but the line content + replaced with `line` (when not `None`) and applying `.strlinemap` + mapping (when `apply_map` is `True`). + * `.apply_map(line)` - apply `.strlinemap` mapping to line content. + * `.has_map()` - returns `True` if `.strlinemap` mapping exists. For example, @@ -136,42 +136,42 @@ >>> item.copy('if(F2PY_EXPR_TUPLE_4)pause',True) Line('if(n.le.0)pause',(11, 11),'') -Comment instance has the following attributes: +`Comment` instance has the following attributes: - * .comment - comment string - * .span - a 2-tuple containing the span of line numbers containing + * `.comment` - a comment string + * `.span` - a 2-tuple containing the span of line numbers containing Fortran comment in the original Fortran file - * .reader - the FortranReaderBase class instance + * `.reader` - the `FortranReaderBase` class instance -and .isempty() method. +and `.isempty()` method. -MultiLine class represents multiline syntax in .pyf files:: +`MultiLine` class represents multiline syntax in the .pyf files:: '''''' -MultiLine instance has the following attributes: +`MultiLine` instance has the following attributes: - * .prefix - the content of - * .block - a list of lines - * .suffix - the content of - * .span - a 2-tuple containing the span of line numbers containing + * `.prefix` - the content of `` + * `.block` - a list of lines + * `.suffix` - the content of `` + * `.span` - a 2-tuple containing the span of line numbers containing multiline syntax in the original Fortran file - * .reader - the FortranReaderBase class instance + * `.reader` - the `FortranReaderBase` class instance -and .isempty() method. +and `.isempty()` method. -SyntaxErrorLine and SyntaxErrorMultiLine are like Line and MultiLine +`SyntaxErrorLine` and `SyntaxErrorMultiLine` are like `Line` and `MultiLine` classes, respectively, with a functionality of issuing an error -message to sys.stdout when constructing an instance of the corresponding +message to `sys.stdout` when constructing an instance of the corresponding class. -To read a Fortran code from a string, use FortranStringReader class:: +To read a Fortran code from a string, use `FortranStringReader` class:: reader = FortranStringReader(, , ) where the second and third arguments are used to specify the format -of the given content. When and are both -True, the content of a .pyf file is assumed. For example, +of the given `` content. When `` and `` are both +`True`, the content of a .pyf file is assumed. For example, :: @@ -191,31 +191,31 @@ >>> reader.next() Line('end',(5, 5),'') -FortranReaderBase has the following attributes: +`FortranReaderBase` has the following attributes: - * .source - a file-like object with .next() method to retrive + * `.source` - a file-like object with `.next()` method to retrive a source code line - * .source_lines - a list of read source lines - * .reader - a FortranReaderBase instance for reading files + * `.source_lines` - a list of read source lines + * `.reader` - a `FortranReaderBase` instance for reading files from INCLUDE statements. - * .include_dirs - a list of directories where INCLUDE files - are searched. Default is ['.']. + * `.include_dirs` - a list of directories where INCLUDE files + are searched. Default is `['.']`. and the following methods: - * .set_mode(isfree, isstrict) - set Fortran code format information - * .close_source() - called when .next() raises StopIteration exception. + * `.set_mode(isfree, isstrict)` - set Fortran code format information + * `.close_source()` - called when `.next()` raises `StopIteration` exception. parsefortran.py --------------- -Parse Fortran code from FortranReaderBase iterator. +This file contains code for parsing Fortran code from `FortranReaderBase` iterator. -FortranParser class holds the parser information while -iterating over items returned by FortranReaderBase iterator. -The parsing information, collected when calling .parse() method, -is saved in .block attribute as an instance -of BeginSource class defined in block_statements.py file. +`FortranParser` class holds the parser information while +iterating over items returned by `FortranReaderBase` iterator. +The parsing information, collected when calling `.parse()` method, +is saved in `.block` attribute as an instance +of `BeginSource` class defined in `block_statements.py` file. For example, @@ -233,133 +233,134 @@ block_statements.py, base_classes.py, typedecl_statements.py, statements.py --------------------------------------------------------------------------- -The model for representing Fortran code statements consists of a tree of Statement -classes defined in base_classes.py. There are two types of statements: one line +The model for representing Fortran code statements consists of a tree of `Statement` +classes defined in `base_classes.py`. There are two types of statements: one-line statements and block statements. Block statements consists of start and end statements, and content statements in between that can be of both types again. -Statement instance has the following attributes: +`Statement` instance has the following attributes: - * .parent - it is either parent block-type statement or FortranParser instance. - * .item - Line instance containing Fortran statement line information, see above. - * .isvalid - when False then processing this Statement instance will be skipped, - for example, when the content of .item does not match with - the Statement class. - * .ignore - when True then the Statement instance will be ignored. - * .modes - a list of Fortran format modes where the Statement instance is valid. + * `.parent` - it is either parent block-type statement or `FortranParser` instance. + * `.item` - a `Line` instance containing Fortran statement line information, see above. + * `.isvalid` - when `False` then processing this `Statement` instance will be skipped, + for example, when the content of `.item` does not match with + the `Statement` class. + * `.ignore` - when `True` then the `Statement` instance will be ignored. + * `.modes` - a list of Fortran format modes where the `Statement` instance is valid. and the following methods: - * .info(message), .warning(message), .error(message) - to spit messages to - sys.stderr stream. - * .get_variable(name) - get Variable instance by name that is defined in + * `.info(message)`, `.warning(message)`, `.error(message)` - to spit out messages to + `sys.stderr` stream. + * `.get_variable(name)` - get `Variable` instance by name that is defined in current namespace. If name is not defined, then the corresponding - Variable instance is created. - * .analyze() - calculate various information about the Statement, this information - is saved in .a attribute that is AttributeHolder instance. + `Variable` instance is created. + * `.analyze()` - calculate various information about the `Statement`, this information + is saved in `.a` attribute that is `AttributeHolder` instance. -All statement classes are derived from Statement class. Block statements are -derived from BeginStatement class and is assumed to end with EndStatement -instance in .content attribute list. BeginStatement and EndStatement instances +All statement classes are derived from the `Statement` class. Block statements are +derived from the `BeginStatement` class and is assumed to end with an `EndStatement` +instance in `.content` attribute list. `BeginStatement` and `EndStatement` instances have the following attributes: - * .name - name of the block, blocks without names use line label + * `.name` - name of the block, blocks without names use line label as the name. - * .blocktype - type of the block (derived from class name) - * .content - a list of Statement (or Line) instances. + * `.blocktype` - type of the block (derived from class name) + * `.content` - a list of `Statement` (or `Line`) instances. and the following methods: - * .__str__() - returns string representation of Fortran code. + * `.__str__()` - returns string representation of Fortran code. A number of statements may declare a variable that is used in other -statement expressions. Variables are represented via Variable class +statement expressions. Variables are represented via `Variable` class and its instances have the following attributes: - * .name - name of the variable - * .typedecl - type declaration - * .dimension - list of dimensions - * .bounds - list of bounds - * .length - length specs - * .attributes - list of attributes - * .bind - list of bind information - * .intent - list of intent information - * .check - list of check expressions - * .init - initial value of the variable - * .parent - statement instance declaring the variable - * .parents - list of statements that specify variable information + * `.name` - name of the variable + * `.typedecl` - type declaration + * `.dimension` - list of dimensions + * `.bounds` - list of bounds + * `.length` - length specs + * `.attributes` - list of attributes + * `.bind` - list of bind information + * `.intent` - list of intent information + * `.check` - list of check expressions + * `.init` - initial value of the variable + * `.parent` - statement instance declaring the variable + * `.parents` - list of statements that specify variable information and the following methods: - * .is_private() - * .is_public() - * .is_allocatable() - * .is_external() - * .is_intrinsic() - * .is_parameter() - * .is_optional() - * .is_required() + * `.is_private()` + * `.is_public()` + * `.is_allocatable()` + * `.is_external()` + * `.is_intrinsic()` + * `.is_parameter()` + * `.is_optional()` + * `.is_required()` -The following type declaration statements are defined in typedecl_statements.py: +The following type declaration statements are defined in `typedecl_statements.py`: - Integer, Real, DoublePrecision, Complex, DoubleComplex, Logical, - Character, Byte, Type, Class + `Integer`, `Real`, `DoublePrecision`, `Complex`, `DoubleComplex`, `Logical`, + `Character`, `Byte`, `Type`, `Class` and they have the following attributes: - * .selector - contains lenght and kind specs - * .entity_decls, .attrspec + * `.selector` - contains lenght and kind specs + * `.entity_decls`, `.attrspec` and methods: - * .tostr() - return string representation of Fortran type declaration - * .astypedecl() - pure type declaration instance, it has no .entity_decls - and .attrspec. - * .analyze() - processes .entity_decls and .attsspec attributes and adds - Variable instance to .parent.a.variables dictionary. + * `.tostr()` - return string representation of Fortran type declaration + * `.astypedecl()` - pure type declaration instance, it has no `.entity_decls` + and `.attrspec`. + * `.analyze()` - processes `.entity_decls` and `.attrspec` attributes and adds + `Variable` instance to `.parent.a.variables` dictionary. -The following block statements are defined in block_statements.py: +The following block statements are defined in `block_statements.py`: - BeginSource, Module, PythonModule, Program, BlockData, Interface, - Subroutine, Function, Select, Where, Forall, IfThen, If, Do, - Associate, TypeDecl (Type), Enum + `BeginSource`, `Module`, `PythonModule`, `Program`, `BlockData`, `Interface`, + `Subroutine`, `Function`, `Select`, `Where`, `Forall`, `IfThen`, `If`, `Do`, + `Associate`, `TypeDecl (Type)`, `Enum` Block statement classes may have different properties which are declared via deriving them from the following classes: - HasImplicitStmt, HasUseStmt, HasVariables, HasTypeDecls, - HasAttributes, HasModuleProcedures, ProgramBlock + `HasImplicitStmt`, `HasUseStmt`, `HasVariables`, `HasTypeDecls`, + `HasAttributes`, `HasModuleProcedures`, `ProgramBlock` -In summary, .a attribute may hold different information sets as follows: +In summary, the `.a` attribute may hold different information sets as follows: - * BeginSource - .module, .external_subprogram, .blockdata - * Module - .attributes, .implicit_rules, .use, .use_provides, .variables, - .type_decls, .module_subprogram, .module_data - * PythonModule - .implicit_rules, .use, .use_provides - * Program - .attributes, .implicit_rules, .use, .use_provides - * BlockData - .implicit_rules, .use, .use_provides, .variables - * Interface - .implicit_rules, .use, .use_provides, .module_procedures - * Function, Subroutine - .implicit_rules, .attributes, .use, .use_statements, - .variables, .type_decls, .internal_subprogram - * TypeDecl - .variables, .attributes + * `BeginSource` - `.module`, `.external_subprogram`, `.blockdata` + * `Module` - `.attributes`, `.implicit_rules`, `.use`, `.use_provides`, `.variables`, + `.type_decls`, `.module_subprogram`, `.module_data` + * `PythonModule` - `.implicit_rules`, `.use`, `.use_provides` + * `Program` - `.attributes`, `.implicit_rules`, `.use`, `.use_provides` + * `BlockData` - `.implicit_rules`, `.use`, `.use_provides`, `.variables` + * `Interface` - `.implicit_rules`, `.use`, `.use_provides`, `.module_procedures` + * `Function`, `Subroutine` - `.implicit_rules`, `.attributes`, `.use`, `.use_statements`, + `.variables`, `.type_decls`, `.internal_subprogram` + * `TypeDecl` - `.variables`, `.attributes` Block statements have the following methods: - * .get_classes() - returns a list of Statement classes that are valid + * `.get_classes()` - returns a list of `Statement` classes that are valid as a content of given block statement. The following one line statements are defined: - Implicit, TypeDeclarationStatement derivatives (see above), - Assignment, PointerAssignment, Assign, Call, Goto, ComputedGoto, - AssignedGoto, Continue, Return, Stop, Print, Read, Write, Flush, - Wait, Contains, Allocate, Deallocate, ModuleProcedure, Access, - Public, Private, Close, Cycle, Backspace, Endfile, Reeinf, Open, - Format, Save, Data, Nullify, Use, Exit, Parameter, Equivalence, - Dimension, Target, Pointer, Protected, Volatile, Value, - ArithmeticIf, Intrinsic, Inquire, Sequence, External, Namelist, - Common, Optional, Intent, Entry, Import, Forall, - SpecificBinding, GenericBinding, FinalBinding, Allocatable, - Asynchronous, Bind, Else, ElseIf, Case, Where, ElseWhere, - Enumerator, FortranName, Threadsafe, Depend, Check, - CallStatement, CallProtoArgument, Pause + `Implicit`, `TypeDeclarationStatement` derivatives (see above), + `Assignment`, `PointerAssignment`, `Assign`, `Call`, `Goto`, `ComputedGoto`, + `AssignedGoto`, `Continue`, `Return`, `Stop`, `Print`, `Read`, `Write`, `Flush`, + `Wait`, `Contains`, `Allocate`, `Deallocate`, `ModuleProcedure`, `Access`, + `Public`, `Private`, `Close`, `Cycle`, `Backspace`, `Endfile`, `Reeinf`, `Open`, + `Format`, `Save`, `Data`, `Nullify`, `Use`, `Exit`, `Parameter`, `Equivalence`, + `Dimension`, `Target`, `Pointer`, `Protected`, `Volatile`, `Value`, + `ArithmeticIf`, `Intrinsic`, `Inquire`, `Sequence`, `External`, `Namelist`, + `Common`, `Optional`, `Intent`, `Entry`, `Import`, `Forall`, + `SpecificBinding`, `GenericBinding`, `FinalBinding`, `Allocatable`, + `Asynchronous`, `Bind`, `Else`, `ElseIf`, `Case`, `Where`, `ElseWhere`, + `Enumerator`, `FortranName`, `Threadsafe`, `Depend`, `Check`, + `CallStatement`, `CallProtoArgument`, `Pause` + From numpy-svn at scipy.org Thu Jul 19 07:04:35 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 19 Jul 2007 06:04:35 -0500 (CDT) Subject: [Numpy-svn] r3889 - trunk/numpy/f2py/lib/parser Message-ID: <20070719110435.C4E9239C010@new.scipy.org> Author: pearu Date: 2007-07-19 06:04:25 -0500 (Thu, 19 Jul 2007) New Revision: 3889 Modified: trunk/numpy/f2py/lib/parser/doc.txt Log: update fortran parser docs. Modified: trunk/numpy/f2py/lib/parser/doc.txt =================================================================== --- trunk/numpy/f2py/lib/parser/doc.txt 2007-07-19 09:45:27 UTC (rev 3888) +++ trunk/numpy/f2py/lib/parser/doc.txt 2007-07-19 11:04:25 UTC (rev 3889) @@ -1,8 +1,27 @@ .. -*- rest -*- -Created: September 2006 -Author: Pearu Peterson +====================== +Fortran parser package +====================== +:Author: + Pearu Peterson +:Created: September 2006 + + +.. contents:: Table of Contents + +Overview +======== + +The Fortran parser package is a Python implementation +of Fortran 66/77/90/95/2003 language parser. The code +is under NumPy SVN tree: `numpy/f2py/lib/parser/`. +The Fortran language syntax rules are defined in `Fortran2003.py`, +the rules are taken from the following ISO/IEC 1539 working draft: +http://j3-fortran.org/doc/2003_Committee_Draft/04-007.pdf. + + Fortran parser package structure ================================ @@ -66,7 +85,6 @@ This file contains tools for reading Fortran codes from file and string objects. To read Fortran code from a file, use `FortranFileReader` class. - `FortranFileReader` class is iterator over Fortran code lines and is derived from `FortranReaderBase` class. It automatically handles the line continuations and comments, as From numpy-svn at scipy.org Thu Jul 19 07:13:03 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 19 Jul 2007 06:13:03 -0500 (CDT) Subject: [Numpy-svn] r3890 - trunk/numpy/f2py/lib/parser Message-ID: <20070719111303.D6DB839C178@new.scipy.org> Author: pearu Date: 2007-07-19 06:12:38 -0500 (Thu, 19 Jul 2007) New Revision: 3890 Modified: trunk/numpy/f2py/lib/parser/doc.txt Log: update fortran parser docs, 2 Modified: trunk/numpy/f2py/lib/parser/doc.txt =================================================================== --- trunk/numpy/f2py/lib/parser/doc.txt 2007-07-19 11:04:25 UTC (rev 3889) +++ trunk/numpy/f2py/lib/parser/doc.txt 2007-07-19 11:12:38 UTC (rev 3890) @@ -16,23 +16,25 @@ The Fortran parser package is a Python implementation of Fortran 66/77/90/95/2003 language parser. The code -is under NumPy SVN tree: `numpy/f2py/lib/parser/`. -The Fortran language syntax rules are defined in `Fortran2003.py`, +is under NumPy SVN tree: `numpy/f2py/lib/parser/`__. +The Fortran language syntax rules are defined in `Fortran2003.py`__, the rules are taken from the following ISO/IEC 1539 working draft: http://j3-fortran.org/doc/2003_Committee_Draft/04-007.pdf. +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/ +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/Fortran2003.py Fortran parser package structure ================================ `numpy.f2py.lib.parser` package contains the following files: -api.py ------- +api.py - public API for Fortran parser +-------------------------------------- -Public API for Fortran parser. +`This file`__ exposes `Statement` subclasses, `CHAR_BIT` constant, and a function `parse`. -It exposes `Statement` subclasses, `CHAR_BIT` constant, and a function `parse`. +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/api.py Function `parse(, ..)` parses, analyzes and returns a `Statement` tree of Fortran input. For example, @@ -82,8 +84,10 @@ readfortran.py -------------- -This file contains tools for reading Fortran codes from file and string objects. +`This file`__ contains tools for reading Fortran codes from file and string objects. +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/readfortran.py + To read Fortran code from a file, use `FortranFileReader` class. `FortranFileReader` class is iterator over Fortran code lines and is derived from `FortranReaderBase` class. @@ -227,8 +231,10 @@ parsefortran.py --------------- -This file contains code for parsing Fortran code from `FortranReaderBase` iterator. +`This file`__ contains code for parsing Fortran code from `FortranReaderBase` iterator. +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/parsefortran.py + `FortranParser` class holds the parser information while iterating over items returned by `FortranReaderBase` iterator. The parsing information, collected when calling `.parse()` method, @@ -248,9 +254,14 @@ PRINT *, "a=", a END SUBROUTINE foo -block_statements.py, base_classes.py, typedecl_statements.py, statements.py ---------------------------------------------------------------------------- +Files `block_statements.py`__, `base_classes.py`__, `typedecl_statements.py`__, `statements.py`__ +------------------------------------------------------------------------------------------------- +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/block_statements.py +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/base_classes.py +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/typedecl_statements.py +__ http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/f2py/lib/parser/statements.py + The model for representing Fortran code statements consists of a tree of `Statement` classes defined in `base_classes.py`. There are two types of statements: one-line statements and block statements. Block statements consists of start and end From numpy-svn at scipy.org Fri Jul 20 05:28:56 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 20 Jul 2007 04:28:56 -0500 (CDT) Subject: [Numpy-svn] r3891 - trunk/numpy/testing Message-ID: <20070720092856.E3E3939C12F@new.scipy.org> Author: pearu Date: 2007-07-20 04:28:37 -0500 (Fri, 20 Jul 2007) New Revision: 3891 Modified: trunk/numpy/testing/numpytest.py Log: Added a new option to NumpyTest.run command line: -s somestring will replace sys.argv\[1:\] with splitcmdline(somestring) Modified: trunk/numpy/testing/numpytest.py =================================================================== --- trunk/numpy/testing/numpytest.py 2007-07-19 11:12:38 UTC (rev 3890) +++ trunk/numpy/testing/numpytest.py 2007-07-20 09:28:37 UTC (rev 3891) @@ -16,6 +16,7 @@ DEBUG=0 from numpy.testing.utils import jiffies +from numpy.distutils.exec_command import splitcmdline get_frame = sys._getframe class IgnoreException(Exception): @@ -605,7 +606,7 @@ except ImportError: self.warn('Failed to import optparse module, ignoring.') return self.test() - usage = r'usage: %prog [-v ] [-l ]' + usage = r'usage: %prog [-v ] [-l ] [-s ""]' parser = OptionParser(usage) parser.add_option("-v", "--verbosity", action="store", @@ -617,7 +618,14 @@ dest="level", default=1, type='int') + parser.add_option("-s", "--sys-argv", + action="store", + dest="sys_argv", + default='', + type='string') (options, args) = parser.parse_args() + if options.sys_argv: + sys.argv[1:] = splitcmdline(options.sys_argv) self.test(options.level,options.verbosity) return From numpy-svn at scipy.org Fri Jul 20 07:29:43 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 20 Jul 2007 06:29:43 -0500 (CDT) Subject: [Numpy-svn] r3892 - trunk/numpy/distutils Message-ID: <20070720112943.BEDAA39C272@new.scipy.org> Author: pearu Date: 2007-07-20 06:28:43 -0500 (Fri, 20 Jul 2007) New Revision: 3892 Modified: trunk/numpy/distutils/system_info.py Log: Fixed LAPACK_SRC build for lapack-3.1.1. Modified: trunk/numpy/distutils/system_info.py =================================================================== --- trunk/numpy/distutils/system_info.py 2007-07-20 09:28:37 UTC (rev 3891) +++ trunk/numpy/distutils/system_info.py 2007-07-20 11:28:43 UTC (rev 3892) @@ -1030,9 +1030,12 @@ if not src_dir: #XXX: Get sources from netlib. May be ask first. return - # The following is extracted from LAPACK-3.0/SRC/Makefile + # The following is extracted from LAPACK-3.0/SRC/Makefile. + # Added missing names from lapack-lite-3.1.1/SRC/Makefile + # while keeping removed names for Lapack-3.0 compatibility. allaux=''' ilaenv ieeeck lsame lsamen xerbla + iparmq ''' # *.f laux = ''' bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1 @@ -1042,6 +1045,9 @@ lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1 lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf stebz stedc steqr sterf + + larra larrc larrd larr larrk larrj larrr laneg laisnan isnan + lazq3 lazq4 ''' # [s|d]*.f lasrc = ''' gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak @@ -1065,6 +1071,8 @@ tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs tzrqf tzrzf + + lacn2 lahr2 stemr laqr0 laqr1 laqr2 laqr3 laqr4 laqr5 ''' # [s|c|d|z]*.f sd_lasrc = ''' laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l @@ -1102,7 +1110,13 @@ + ['z%s.f'%f for f in (zlasrc).split()] \ + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()] sources = [os.path.join(src_dir,f) for f in sources] - #XXX: should we check here actual existence of source files? + # Lapack 3.1: + src_dir2 = os.path.join(src_dir,'..','INSTALL') + sources += [os.path.join(src_dir2,p+'lamch.f') for p in 'sdcz'] + # Should we check here actual existence of source files? + # Yes, the file listing is different between 3.0 and 3.1 + # versions. + sources = [f for f in sources if os.path.isfile(f)] info = {'sources':sources,'language':'f77'} self.set_info(**info) From numpy-svn at scipy.org Mon Jul 23 09:13:19 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 23 Jul 2007 08:13:19 -0500 (CDT) Subject: [Numpy-svn] r3893 - in trunk/numpy: core/tests oldnumeric Message-ID: <20070723131319.5C0E939C115@new.scipy.org> Author: stefan Date: 2007-07-23 08:12:55 -0500 (Mon, 23 Jul 2007) New Revision: 3893 Modified: trunk/numpy/core/tests/test_regression.py trunk/numpy/oldnumeric/random_array.py Log: Fix randint. Closes ticket #552. Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2007-07-20 11:28:43 UTC (rev 3892) +++ trunk/numpy/core/tests/test_regression.py 2007-07-23 13:12:55 UTC (rev 3893) @@ -697,6 +697,11 @@ x = N.array(['a']*32) assert_array_equal(x.argsort(kind='m'), N.arange(32)) + def check_numeric_random(self, level=rlevel): + """Ticket #552""" + from numpy.oldnumeric.random_array import randint + randint(0,50,[2,3]) + if __name__ == "__main__": NumpyTest().run() Modified: trunk/numpy/oldnumeric/random_array.py =================================================================== --- trunk/numpy/oldnumeric/random_array.py 2007-07-20 11:28:43 UTC (rev 3892) +++ trunk/numpy/oldnumeric/random_array.py 2007-07-23 13:12:55 UTC (rev 3893) @@ -12,8 +12,6 @@ import numpy.random.mtrand as mt import numpy as Numeric -from types import IntType - def seed(x=0, y=0): if (x == 0 or y == 0): mt.seed() @@ -42,16 +40,16 @@ def randint(minimum, maximum=None, shape=[]): """randint(min, max, shape=[]) = random integers >=min, < max If max not given, random integers >= 0, Author: stefan Date: 2007-07-24 02:33:28 -0500 (Tue, 24 Jul 2007) New Revision: 3894 Modified: trunk/numpy/core/tests/test_regression.py trunk/numpy/lib/polynomial.py Log: Fix polynomial comparison. Closes ticket #554. Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2007-07-23 13:12:55 UTC (rev 3893) +++ trunk/numpy/core/tests/test_regression.py 2007-07-24 07:33:28 UTC (rev 3894) @@ -702,6 +702,13 @@ from numpy.oldnumeric.random_array import randint randint(0,50,[2,3]) + def check_poly_eq(self, level=rlevel): + """Ticket #554""" + x = N.poly1d([1,2,3]) + y = N.poly1d([3,4]) + assert x != y + assert x == x + if __name__ == "__main__": NumpyTest().run() Modified: trunk/numpy/lib/polynomial.py =================================================================== --- trunk/numpy/lib/polynomial.py 2007-07-23 13:12:55 UTC (rev 3893) +++ trunk/numpy/lib/polynomial.py 2007-07-24 07:33:28 UTC (rev 3894) @@ -606,10 +606,10 @@ return polydiv(other, self) def __eq__(self, other): - return (self.coeffs == other.coeffs).all() + return NX.alltrue(self.coeffs == other.coeffs) def __ne__(self, other): - return (self.coeffs != other.coeffs).any() + return NX.any(self.coeffs != other.coeffs) def __setattr__(self, key, val): raise ValueError, "Attributes cannot be changed this way." From numpy-svn at scipy.org Tue Jul 24 03:46:33 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 24 Jul 2007 02:46:33 -0500 (CDT) Subject: [Numpy-svn] r3895 - in trunk/numpy: core/tests lib Message-ID: <20070724074633.29C7A39C035@new.scipy.org> Author: stefan Date: 2007-07-24 02:46:07 -0500 (Tue, 24 Jul 2007) New Revision: 3895 Modified: trunk/numpy/core/tests/test_regression.py trunk/numpy/lib/polynomial.py Log: Fix polygon division. Closes ticket #553. Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2007-07-24 07:33:28 UTC (rev 3894) +++ trunk/numpy/core/tests/test_regression.py 2007-07-24 07:46:07 UTC (rev 3895) @@ -702,6 +702,13 @@ from numpy.oldnumeric.random_array import randint randint(0,50,[2,3]) + def check_poly_div(self, level=rlevel): + """Ticket #553""" + u = N.poly1d([1,2,3]) + v = N.poly1d([1,2,3,4,5]) + q,r = N.polydiv(u,v) + assert_equal(q*v + r, u) + def check_poly_eq(self, level=rlevel): """Ticket #554""" x = N.poly1d([1,2,3]) Modified: trunk/numpy/lib/polynomial.py =================================================================== --- trunk/numpy/lib/polynomial.py 2007-07-24 07:33:28 UTC (rev 3894) +++ trunk/numpy/lib/polynomial.py 2007-07-24 07:46:07 UTC (rev 3895) @@ -400,7 +400,7 @@ m = len(u) - 1 n = len(v) - 1 scale = 1. / v[0] - q = NX.zeros((m-n+1,), float) + q = NX.zeros((max(m-n+1,1),), float) r = u.copy() for k in range(0, m-n+1): d = scale * r[k] From numpy-svn at scipy.org Tue Jul 24 08:09:05 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 24 Jul 2007 07:09:05 -0500 (CDT) Subject: [Numpy-svn] r3896 - in trunk/numpy/distutils: . fcompiler Message-ID: <20070724120905.B9C9D39C070@new.scipy.org> Author: pearu Date: 2007-07-24 07:08:46 -0500 (Tue, 24 Jul 2007) New Revision: 3896 Modified: trunk/numpy/distutils/exec_command.py trunk/numpy/distutils/fcompiler/compaq.py Log: Modified: trunk/numpy/distutils/exec_command.py =================================================================== --- trunk/numpy/distutils/exec_command.py 2007-07-24 07:46:07 UTC (rev 3895) +++ trunk/numpy/distutils/exec_command.py 2007-07-24 12:08:46 UTC (rev 3896) @@ -123,7 +123,7 @@ ############################################################ def find_executable(exe, path=None): - """Return full path of a executable. + """Return full path of a executable or None. Symbolic links are not followed. """ @@ -358,7 +358,6 @@ use_shell = os.name=='posix' if use_tee is None: use_tee = os.name=='posix' - using_command = 0 if use_shell: # We use shell (unless use_shell==0) so that wildcards can be @@ -380,7 +379,7 @@ spawn_command = os.spawnvpe else: spawn_command = os.spawnve - argv[0] = find_executable(argv[0]) + argv[0] = find_executable(argv[0]) or argv[0] if not os.path.isfile(argv[0]): log.warn('Executable %s does not exist' % (argv[0])) if os.name in ['nt','dos']: Modified: trunk/numpy/distutils/fcompiler/compaq.py =================================================================== --- trunk/numpy/distutils/fcompiler/compaq.py 2007-07-24 07:46:07 UTC (rev 3895) +++ trunk/numpy/distutils/fcompiler/compaq.py 2007-07-24 12:08:46 UTC (rev 3896) @@ -5,6 +5,7 @@ import sys from numpy.distutils.fcompiler import FCompiler +from distutils.errors import DistutilsPlatformError compilers = ['CompaqFCompiler'] if os.name != 'posix': @@ -69,12 +70,17 @@ ar_exe = 'lib.exe' fc_exe = 'DF' + if sys.platform=='win32': from distutils.msvccompiler import MSVCCompiler - m = MSVCCompiler() - m.initialize() - ar_exe = m.lib + try: + m = MSVCCompiler() + m.initialize() + ar_exe = m.lib + except DistutilsPlatformError, msg: + print 'Ignoring %s (one should fix me in fcompiler/compaq.py)' % (msg) + executables = { 'version_cmd' : ['', "/what"], 'compiler_f77' : [fc_exe, "/f77rtl","/fixed"], From numpy-svn at scipy.org Wed Jul 25 01:36:13 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 25 Jul 2007 00:36:13 -0500 (CDT) Subject: [Numpy-svn] r3897 - trunk/numpy/lib Message-ID: <20070725053613.E2A4639C0C8@new.scipy.org> Author: rkern Date: 2007-07-25 00:36:05 -0500 (Wed, 25 Jul 2007) New Revision: 3897 Modified: trunk/numpy/lib/twodim_base.py Log: Make sure we always return a value from eye(). It wasn't returning a value when dtype==bool. Modified: trunk/numpy/lib/twodim_base.py =================================================================== --- trunk/numpy/lib/twodim_base.py 2007-07-24 12:08:46 UTC (rev 3896) +++ trunk/numpy/lib/twodim_base.py 2007-07-25 05:36:05 UTC (rev 3897) @@ -47,7 +47,8 @@ if M is None: M = N m = equal(subtract.outer(arange(N), arange(M)),-k) if m.dtype != dtype: - return m.astype(dtype) + m = m.astype(dtype) + return m def diag(v, k=0): """ returns a copy of the the k-th diagonal if v is a 2-d array From numpy-svn at scipy.org Wed Jul 25 05:03:26 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 25 Jul 2007 04:03:26 -0500 (CDT) Subject: [Numpy-svn] r3898 - trunk/numpy/lib/tests Message-ID: <20070725090326.7011539C15C@new.scipy.org> Author: stefan Date: 2007-07-25 04:02:55 -0500 (Wed, 25 Jul 2007) New Revision: 3898 Modified: trunk/numpy/lib/tests/test_twodim_base.py Log: Add regression test for eye. Modified: trunk/numpy/lib/tests/test_twodim_base.py =================================================================== --- trunk/numpy/lib/tests/test_twodim_base.py 2007-07-25 05:36:05 UTC (rev 3897) +++ trunk/numpy/lib/tests/test_twodim_base.py 2007-07-25 09:02:55 UTC (rev 3898) @@ -27,6 +27,8 @@ [0,1,0,0], [0,0,1,0], [0,0,0,1]],'f')) + assert_equal(eye(3) == 1, eye(3,dtype=bool)) + def check_diag(self): assert_equal(eye(4,k=1),array([[0,1,0,0], [0,0,1,0], From numpy-svn at scipy.org Wed Jul 25 07:21:53 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 25 Jul 2007 06:21:53 -0500 (CDT) Subject: [Numpy-svn] r3899 - in trunk/numpy/distutils: . fcompiler Message-ID: <20070725112153.5A6D239C00F@new.scipy.org> Author: pearu Date: 2007-07-25 06:21:35 -0500 (Wed, 25 Jul 2007) New Revision: 3899 Modified: trunk/numpy/distutils/ccompiler.py trunk/numpy/distutils/fcompiler/__init__.py trunk/numpy/distutils/fcompiler/gnu.py Log: Don't use _nt_quote_args as exec_command should handle spaces in program path. This fixes building numpy/scipy on Windows using mingw32 g77 with full path=C:\Program Files\MinGW\g77.exe. Modified: trunk/numpy/distutils/ccompiler.py =================================================================== --- trunk/numpy/distutils/ccompiler.py 2007-07-25 09:02:55 UTC (rev 3898) +++ trunk/numpy/distutils/ccompiler.py 2007-07-25 11:21:35 UTC (rev 3899) @@ -11,7 +11,6 @@ from numpy.distutils import log from numpy.distutils.exec_command import exec_command from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32 -from distutils.spawn import _nt_quote_args # hack to set compiler optimizing options. Needs to integrated with something. import distutils.sysconfig @@ -32,8 +31,6 @@ if is_sequence(display): display = ' '.join(list(display)) log.info(display) - if is_sequence(cmd) and os.name == 'nt': - cmd = _nt_quote_args(list(cmd)) s,o = exec_command(cmd) if s: if is_sequence(cmd): @@ -264,7 +261,6 @@ return None if not version_cmd or not version_cmd[0]: return None - cmd = ' '.join(version_cmd) try: matcher = self.version_match except AttributeError: @@ -279,7 +275,7 @@ version = m.group('version') return version - status, output = exec_command(cmd,use_tee=0) + status, output = exec_command(version_cmd,use_tee=0) version = None if status in ok_status: Modified: trunk/numpy/distutils/fcompiler/__init__.py =================================================================== --- trunk/numpy/distutils/fcompiler/__init__.py 2007-07-25 09:02:55 UTC (rev 3898) +++ trunk/numpy/distutils/fcompiler/__init__.py 2007-07-25 11:21:35 UTC (rev 3899) @@ -30,7 +30,6 @@ from distutils.errors import DistutilsModuleError, \ DistutilsExecError, CompileError, LinkError, DistutilsPlatformError from distutils.util import split_quoted, strtobool -from distutils.spawn import _nt_quote_args from numpy.distutils.ccompiler import CCompiler, gen_lib_options from numpy.distutils import log @@ -569,8 +568,6 @@ log.info('using compile options from source: %r' \ % ' '.join(extra_flags)) - if os.name == 'nt': - compiler = _nt_quote_args(compiler) command = compiler + cc_args + extra_flags + s_args + o_args \ + extra_postargs @@ -642,8 +639,6 @@ linker = self.linker_exe[:] else: linker = self.linker_so[:] - if os.name == 'nt': - linker = _nt_quote_args(linker) command = linker + ld_args try: self.spawn(command) Modified: trunk/numpy/distutils/fcompiler/gnu.py =================================================================== --- trunk/numpy/distutils/fcompiler/gnu.py 2007-07-25 09:02:55 UTC (rev 3898) +++ trunk/numpy/distutils/fcompiler/gnu.py 2007-07-25 11:21:35 UTC (rev 3899) @@ -46,6 +46,7 @@ # GNU Fortran (GCC) 3.3.3 (Debian 20040401) # GNU Fortran 0.5.25 20010319 (prerelease) # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5) + # GNU Fortran (GCC) 3.4.2 (mingw-special) possible_executables = ['g77', 'f77'] executables = { @@ -325,6 +326,11 @@ compiler = GnuFCompiler() compiler.customize() print compiler.get_version() - compiler = Gnu95FCompiler() - compiler.customize() - print compiler.get_version() + raw_input('Press ENTER to continue...') + try: + compiler = Gnu95FCompiler() + compiler.customize() + print compiler.get_version() + except Exception, msg: + print msg + raw_input('Press ENTER to continue...') From numpy-svn at scipy.org Wed Jul 25 07:42:44 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 25 Jul 2007 06:42:44 -0500 (CDT) Subject: [Numpy-svn] r3900 - trunk/numpy/distutils Message-ID: <20070725114244.6D82339C00F@new.scipy.org> Author: pearu Date: 2007-07-25 06:42:39 -0500 (Wed, 25 Jul 2007) New Revision: 3900 Modified: trunk/numpy/distutils/ccompiler.py Log: Give a hint when getting "Too many open files" failure. Modified: trunk/numpy/distutils/ccompiler.py =================================================================== --- trunk/numpy/distutils/ccompiler.py 2007-07-25 11:21:35 UTC (rev 3899) +++ trunk/numpy/distutils/ccompiler.py 2007-07-25 11:42:39 UTC (rev 3900) @@ -36,8 +36,12 @@ if is_sequence(cmd): cmd = ' '.join(list(cmd)) print o + if re.search('Too many open files', o): + msg = '\nTry rerunning setup command until build succeeds.' + else: + msg = '' raise DistutilsExecError,\ - 'Command "%s" failed with exit status %d' % (cmd, s) + 'Command "%s" failed with exit status %d%s' % (cmd, s, msg) replace_method(CCompiler, 'spawn', CCompiler_spawn) From numpy-svn at scipy.org Wed Jul 25 17:47:37 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 25 Jul 2007 16:47:37 -0500 (CDT) Subject: [Numpy-svn] r3901 - in trunk/numpy/distutils: . command fcompiler Message-ID: <20070725214737.5817039C088@new.scipy.org> Author: pearu Date: 2007-07-25 16:47:16 -0500 (Wed, 25 Jul 2007) New Revision: 3901 Modified: trunk/numpy/distutils/command/build_clib.py trunk/numpy/distutils/command/build_ext.py trunk/numpy/distutils/command/config.py trunk/numpy/distutils/exec_command.py trunk/numpy/distutils/fcompiler/__init__.py trunk/numpy/distutils/fcompiler/gnu.py trunk/numpy/distutils/system_info.py Log: More fixes for building scipy with Mingw32 compilers. Modified: trunk/numpy/distutils/command/build_clib.py =================================================================== --- trunk/numpy/distutils/command/build_clib.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/command/build_clib.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -77,7 +77,8 @@ verbose=self.verbose, dry_run=self.dry_run, force=self.force, - requiref90='f90' in languages) + requiref90='f90' in languages, + c_compiler=self.compiler) if self.compiler is not None: self.fcompiler.customize(self.distribution) @@ -146,7 +147,8 @@ verbose=self.verbose, dry_run=self.dry_run, force=self.force, - requiref90=requiref90) + requiref90=requiref90, + c_compiler=self.compiler) if fcompiler is not None: dist = self.distribution base_config_fc = dist.get_option_dict('config_fc').copy() Modified: trunk/numpy/distutils/command/build_ext.py =================================================================== --- trunk/numpy/distutils/command/build_ext.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/command/build_ext.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -84,10 +84,10 @@ clibs = {} if build_clib is not None: for libname,build_info in build_clib.libraries or []: - if clibs.has_key(libname): + if clibs.has_key(libname) and clibs[libname]!=build_info: log.warn('library %r defined more than once,'\ - ' overwriting build_info %r with %r.' \ - % (libname, clibs[libname], build_info)) + ' overwriting build_info\n%s... \nwith\n%s...' \ + % (libname, `clibs[libname]`[:300], `build_info`[:300])) clibs[libname] = build_info # .. and distribution libraries: for libname,build_info in self.distribution.libraries or []: @@ -174,7 +174,8 @@ verbose=self.verbose, dry_run=self.dry_run, force=self.force, - requiref90=False) + requiref90=False, + c_compiler=self.compiler) fcompiler = self._f77_compiler if fcompiler: ctype = fcompiler.compiler_type @@ -196,7 +197,8 @@ verbose=self.verbose, dry_run=self.dry_run, force=self.force, - requiref90=True) + requiref90=True, + c_compiler = self.compiler) fcompiler = self._f90_compiler if fcompiler: ctype = fcompiler.compiler_type Modified: trunk/numpy/distutils/command/config.py =================================================================== --- trunk/numpy/distutils/command/config.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/command/config.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -27,7 +27,8 @@ from numpy.distutils.fcompiler import FCompiler, new_fcompiler if not isinstance(self.fcompiler, FCompiler): self.fcompiler = new_fcompiler(compiler=self.fcompiler, - dry_run=self.dry_run, force=1) + dry_run=self.dry_run, force=1, + c_compiler=self.compiler) if self.fcompiler is not None: self.fcompiler.customize(self.distribution) if self.fcompiler.get_version(): Modified: trunk/numpy/distutils/exec_command.py =================================================================== --- trunk/numpy/distutils/exec_command.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/exec_command.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -122,11 +122,16 @@ ############################################################ -def find_executable(exe, path=None): +def find_executable(exe, path=None, _cache={}): """Return full path of a executable or None. Symbolic links are not followed. """ + key = exe, path + try: + return _cache[key] + except KeyError: + pass log.debug('find_executable(%r)' % exe) orig_exe = exe @@ -160,6 +165,7 @@ f_ext = realpath(f_ext) if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK): log.good('Found executable %s' % f_ext) + _cache[key] = f_ext return f_ext log.warn('Could not locate executable %s' % orig_exe) Modified: trunk/numpy/distutils/fcompiler/__init__.py =================================================================== --- trunk/numpy/distutils/fcompiler/__init__.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/fcompiler/__init__.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -203,6 +203,10 @@ 'compiler_fix', 'linker_so', 'linker_exe', 'archiver', 'ranlib'] + # This will be set by new_fcompiler when called in + # command/{build_ext.py, build_clib.py, config.py} files. + c_compiler = None + def __init__(self, *args, **kw): CCompiler.__init__(self, *args, **kw) self.distutils_vars = self.distutils_vars.clone(self._environment_hook) @@ -599,6 +603,8 @@ def library_option(self, lib): return "-l" + lib def library_dir_option(self, dir): + if ' ' in dir and dir[0] not in '"\'': + return '-L"%s"' % (dir) return "-L" + dir def link(self, target_desc, objects, @@ -716,13 +722,15 @@ def _find_existing_fcompiler(compiler_types, osname=None, platform=None, - requiref90=False): + requiref90=False, + c_compiler=None): from numpy.distutils.core import get_distribution dist = get_distribution(always=True) for compiler_type in compiler_types: v = None try: - c = new_fcompiler(plat=platform, compiler=compiler_type) + c = new_fcompiler(plat=platform, compiler=compiler_type, + c_compiler=c_compiler) c.customize(dist) v = c.get_version() if requiref90 and c.compiler_f90 is None: @@ -732,7 +740,8 @@ log.warn('Trying %r compiler as suggested by %r ' 'compiler for f90 support.' % (compiler_type, new_compiler)) - c = new_fcompiler(plat=platform, compiler=new_compiler) + c = new_fcompiler(plat=platform, compiler=new_compiler, + c_compiler=c_compiler) c.customize(dist) v = c.get_version() if v is not None: @@ -763,7 +772,8 @@ matching_compiler_types.append('gnu') return matching_compiler_types -def get_default_fcompiler(osname=None, platform=None, requiref90=False): +def get_default_fcompiler(osname=None, platform=None, requiref90=False, + c_compiler=None): """Determine the default Fortran compiler to use for the given platform.""" matching_compiler_types = available_fcompilers_for_platform(osname, @@ -771,7 +781,8 @@ compiler_type = _find_existing_fcompiler(matching_compiler_types, osname=osname, platform=platform, - requiref90=requiref90) + requiref90=requiref90, + c_compiler=c_compiler) return compiler_type def new_fcompiler(plat=None, @@ -779,7 +790,8 @@ verbose=0, dry_run=0, force=0, - requiref90=False): + requiref90=False, + c_compiler = None): """Generate an instance of some FCompiler subclass for the supplied platform/compiler combination. """ @@ -787,7 +799,8 @@ if plat is None: plat = os.name if compiler is None: - compiler = get_default_fcompiler(plat, requiref90=requiref90) + compiler = get_default_fcompiler(plat, requiref90=requiref90, + c_compiler=c_compiler) if compiler in fcompiler_class: module_name, klass, long_description = fcompiler_class[compiler] elif compiler in fcompiler_aliases: @@ -802,6 +815,7 @@ return None compiler = klass(verbose=verbose, dry_run=dry_run, force=force) + compiler.c_compiler = c_compiler return compiler def show_fcompilers(dist=None): Modified: trunk/numpy/distutils/fcompiler/gnu.py =================================================================== --- trunk/numpy/distutils/fcompiler/gnu.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/fcompiler/gnu.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -151,7 +151,10 @@ if g2c is not None: opt.append(g2c) - if sys.platform == 'win32': + c_compiler = self.c_compiler + if sys.platform == 'win32' and c_compiler and \ + c_compiler.compiler_type=='msvc': + # the following code is not needed (read: breaks) when using MinGW # in case want to link F77 compiled code with MSVC opt.append('gcc') runtime_lib = msvc_runtime_library() Modified: trunk/numpy/distutils/system_info.py =================================================================== --- trunk/numpy/distutils/system_info.py 2007-07-25 11:42:39 UTC (rev 3900) +++ trunk/numpy/distutils/system_info.py 2007-07-25 21:47:16 UTC (rev 3901) @@ -416,7 +416,8 @@ if self.verbosity>0 and flag: for k,v in res.items(): v = str(v) - if k=='sources' and len(v)>200: v = v[:60]+' ...\n... '+v[-60:] + if k in ['sources','libraries'] and len(v)>270: + v = v[:120]+'...\n...\n...'+v[-120:] log.info(' %s = %s', k, v) log.info('') @@ -1394,6 +1395,7 @@ srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap + scabs1 ''' blas2 = ''' cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv @@ -1412,6 +1414,7 @@ sources = [os.path.join(src_dir,f+'.f') \ for f in (blas1+blas2+blas3).split()] #XXX: should we check here actual existence of source files? + sources = [f for f in sources if os.path.isfile(f)] info = {'sources':sources,'language':'f77'} self.set_info(**info) From numpy-svn at scipy.org Fri Jul 27 05:02:40 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 04:02:40 -0500 (CDT) Subject: [Numpy-svn] r3902 - in trunk/numpy/distutils: . fcompiler Message-ID: <20070727090240.2990139C087@new.scipy.org> Author: pearu Date: 2007-07-27 04:02:31 -0500 (Fri, 27 Jul 2007) New Revision: 3902 Modified: trunk/numpy/distutils/ccompiler.py trunk/numpy/distutils/fcompiler/__init__.py trunk/numpy/distutils/misc_util.py Log: Using own quote_args, trying to fix build failures with MSVC compiler. Modified: trunk/numpy/distutils/ccompiler.py =================================================================== --- trunk/numpy/distutils/ccompiler.py 2007-07-25 21:47:16 UTC (rev 3901) +++ trunk/numpy/distutils/ccompiler.py 2007-07-27 09:02:31 UTC (rev 3902) @@ -10,7 +10,7 @@ from numpy.distutils import log from numpy.distutils.exec_command import exec_command -from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32 +from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, quote_args # hack to set compiler optimizing options. Needs to integrated with something. import distutils.sysconfig @@ -367,9 +367,10 @@ ccompiler.new_compiler = new_compiler - _distutils_gen_lib_options = gen_lib_options def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries): + library_dirs = quote_args(library_dirs) + runtime_library_dirs = quote_args(runtime_library_dirs) r = _distutils_gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries) lib_opts = [] Modified: trunk/numpy/distutils/fcompiler/__init__.py =================================================================== --- trunk/numpy/distutils/fcompiler/__init__.py 2007-07-25 21:47:16 UTC (rev 3901) +++ trunk/numpy/distutils/fcompiler/__init__.py 2007-07-27 09:02:31 UTC (rev 3902) @@ -603,8 +603,6 @@ def library_option(self, lib): return "-l" + lib def library_dir_option(self, dir): - if ' ' in dir and dir[0] not in '"\'': - return '-L"%s"' % (dir) return "-L" + dir def link(self, target_desc, objects, Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2007-07-25 21:47:16 UTC (rev 3901) +++ trunk/numpy/distutils/misc_util.py 2007-07-27 09:02:31 UTC (rev 3902) @@ -21,8 +21,19 @@ 'get_dependencies', 'is_local_src_dir', 'get_ext_source_files', 'get_script_files', 'get_lib_source_files', 'get_data_files', 'dot_join', 'get_frame', 'minrelpath','njoin', - 'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language'] + 'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language', + 'quote_args'] +def quote_args(args): + # don't used _nt_quote_args as it does not check if + # args items already have quotes. + args = list(args) + for i in range(len(args)): + a = args[i] + if ' ' in a and a[0] not in '"\'': + args[i] = '"%s"' % (a) + return args + def allpath(name): "Convert a /-separated pathname to one using the OS's path separator." splitted = name.split('/') From numpy-svn at scipy.org Fri Jul 27 05:20:14 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 04:20:14 -0500 (CDT) Subject: [Numpy-svn] r3903 - trunk/numpy/distutils/fcompiler Message-ID: <20070727092014.5F88839C0A9@new.scipy.org> Author: pearu Date: 2007-07-27 04:20:08 -0500 (Fri, 27 Jul 2007) New Revision: 3903 Modified: trunk/numpy/distutils/fcompiler/compaq.py Log: Trying to fix Windows XP x86_64 MSVC build. Modified: trunk/numpy/distutils/fcompiler/compaq.py =================================================================== --- trunk/numpy/distutils/fcompiler/compaq.py 2007-07-27 09:02:31 UTC (rev 3902) +++ trunk/numpy/distutils/fcompiler/compaq.py 2007-07-27 09:20:08 UTC (rev 3903) @@ -79,7 +79,12 @@ m.initialize() ar_exe = m.lib except DistutilsPlatformError, msg: - print 'Ignoring %s (one should fix me in fcompiler/compaq.py)' % (msg) + print 'Ignoring "%s" (one should fix me in fcompiler/compaq.py)' % (msg) + except AttributeError, msg: + if '_MSVCCompiler__root' in str(msg): + print 'Ignoring "%s" (I think it is msvccompiler.py bug)' % (msg) + else: + raise executables = { 'version_cmd' : ['', "/what"], From numpy-svn at scipy.org Fri Jul 27 08:33:55 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 07:33:55 -0500 (CDT) Subject: [Numpy-svn] r3904 - trunk/numpy/f2py/lib Message-ID: <20070727123355.52AA939C016@new.scipy.org> Author: pearu Date: 2007-07-27 07:33:50 -0500 (Fri, 27 Jul 2007) New Revision: 3904 Added: trunk/numpy/f2py/lib/doc.txt Log: Added doc file for the g3 f2py library package. Added: trunk/numpy/f2py/lib/doc.txt =================================================================== --- trunk/numpy/f2py/lib/doc.txt 2007-07-27 09:20:08 UTC (rev 3903) +++ trunk/numpy/f2py/lib/doc.txt 2007-07-27 12:33:50 UTC (rev 3904) @@ -0,0 +1,60 @@ +.. -*- rest -*- + +======================= +G3 F2PY library package +======================= + +:Author: + Pearu Peterson +:Created: July 2007 + +.. contents:: Table of Contents + +Overview +======== + +The G3 F2PY library package contains tools to parse Fortran codes and +construct Python C/API extension modules for wrapping Fortran +programs. These tools are also suitable for implementing Fortran +program translators or wrappers to any other programming language. In +fact, wrapping Fortran programs to Python would be one example of +using these tools. + +Wrapping Fortran with Python +============================ + +There are two user interfaces to wrap Fortran programs with +Python: + + - the command line program `f2py` that scans Fortran files + given as command line arguments and builds extension modules + that can be used to call Fortran programs from Python. + The `f2py` program has four different ways of building + extension modules as specified with the following command + line flags: + + - `--g3-numpy` --- create extension modules with NumPy array + support using the new tools from `the 3rd generation of F2PY`__. + This is a work-in-progress feature. + + - `--2d-numpy` --- create extension modules with NumPy array + support using `the stable version of F2PY`__. This is default. + + - `--2d-numeric` --- create extension modules with Numeric + array support using the old version of f2py2e. The f2py2e + package must be downloaded and installed separately from + the `f2py2e homepage`__. + + - `--2d-numarray` --- create extension modules with Numarray + array support using the old version of f2py2e. + + See the output of `f2py` for more information. + +__ http://projects.scipy.org/scipy/numpy/wiki/G3F2PY/ +__ http://www.scipy.org/F2py/ +__ http://cens.ioc.ee/projects/f2py2e/ + + - the function `compile()` that scans its string input containing + Fortran code and returns a list of imported extension modules + that can be used to call Fortran programs from Python. + From numpy-svn at scipy.org Fri Jul 27 09:57:18 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 08:57:18 -0500 (CDT) Subject: [Numpy-svn] r3905 - trunk/numpy/f2py/lib Message-ID: <20070727135718.4A6F739C124@new.scipy.org> Author: pearu Date: 2007-07-27 08:57:12 -0500 (Fri, 27 Jul 2007) New Revision: 3905 Modified: trunk/numpy/f2py/lib/doc.txt Log: Doc update. Modified: trunk/numpy/f2py/lib/doc.txt =================================================================== --- trunk/numpy/f2py/lib/doc.txt 2007-07-27 12:33:50 UTC (rev 3904) +++ trunk/numpy/f2py/lib/doc.txt 2007-07-27 13:57:12 UTC (rev 3905) @@ -17,7 +17,7 @@ construct Python C/API extension modules for wrapping Fortran programs. These tools are also suitable for implementing Fortran program translators or wrappers to any other programming language. In -fact, wrapping Fortran programs to Python would be one example of +fact, wrapping Fortran programs to Python would be just one example of using these tools. Wrapping Fortran with Python @@ -48,6 +48,19 @@ - `--2d-numarray` --- create extension modules with Numarray array support using the old version of f2py2e. + Example:: + + $ cat hello.f90 + subroutine hello + print*, "Hello!" + end subroutine hello + $ f2py --g3-numpy -m foo -c hello.f90 --fcompiler=gnu95 + $ python + >>> import foo + >>> foo.hello() + Hello! + >>> + See the output of `f2py` for more information. __ http://projects.scipy.org/scipy/numpy/wiki/G3F2PY/ @@ -58,3 +71,16 @@ Fortran code and returns a list of imported extension modules that can be used to call Fortran programs from Python. + Example:: + + $ python + >>> from numpy.f2py.lib.api import compile + >>> code = 'subroutine hello\n print*, "Hello!"\nend' + >>> print code + subroutine hello + print*, "Hello!" + end + >>> foo, = compile(code, extra_args = ['--fcompiler=gnu95']) + >>> foo.hello() + Hello! + >>> From numpy-svn at scipy.org Fri Jul 27 10:36:51 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 09:36:51 -0500 (CDT) Subject: [Numpy-svn] r3906 - in trunk/numpy/core: src tests Message-ID: <20070727143651.60C0439C05A@new.scipy.org> Author: stefan Date: 2007-07-27 09:36:28 -0500 (Fri, 27 Jul 2007) New Revision: 3906 Modified: trunk/numpy/core/src/scalarmathmodule.c.src trunk/numpy/core/tests/test_scalarmath.py Log: Convert large integer scalars to long instead of to int [patch by Xavier]. Closes ticket #549. Modified: trunk/numpy/core/src/scalarmathmodule.c.src =================================================================== --- trunk/numpy/core/src/scalarmathmodule.c.src 2007-07-27 13:57:12 UTC (rev 3905) +++ trunk/numpy/core/src/scalarmathmodule.c.src 2007-07-27 14:36:28 UTC (rev 3906) @@ -805,13 +805,37 @@ /**end repeat**/ /**begin repeat - #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3# - #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*3# - #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*3# - #which=int*16,long*16,float*16# - #func=PyInt_FromLong*16,(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16# + #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble# + #Name=Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble# + #cmplx=,,,,,,,,,,,,,.real,.real,.real# + #sign=(signed,unsigned)*5,,,,,,# + #ctype=long*8,PY_LONG_LONG*2,double*6# + #realtyp=0*10,1*6# + #func=(PyLong_FromLong,PyLong_FromUnsignedLong)*4,PyLong_FromLongLong,PyLong_FromUnsignedLongLong,PyLong_FromDouble*6# **/ static PyObject * + at name@_int(PyObject *obj) +{ + @sign@ @ctype@ x= PyArrayScalar_VAL(obj, @Name@)@cmplx@; +#if @realtyp@ + double ix; + modf(x, &ix); + x = ix; +#endif + if(LONG_MIN < x && x < LONG_MAX) + return PyInt_FromLong(x); + return @func@(x); +} +/**end repeat**/ + +/**begin repeat + #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*2# + #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*2# + #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*2# + #which=long*16,float*16# + #func=(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16# +**/ +static PyObject * @name at _@which@(PyObject *obj) { return @func@((PyArrayScalar_VAL(obj, @Name@))@cmplx@); Modified: trunk/numpy/core/tests/test_scalarmath.py =================================================================== --- trunk/numpy/core/tests/test_scalarmath.py 2007-07-27 13:57:12 UTC (rev 3905) +++ trunk/numpy/core/tests/test_scalarmath.py 2007-07-27 14:36:28 UTC (rev 3906) @@ -51,5 +51,16 @@ b = a ** 4 assert b == 6765201, "error with %r: got %r" % (t,b) +class test_conversion(NumpyTestCase): + def test_int_from_long(self): + l = [1e6, 1e12, 1e18, -1e6, -1e12, -1e18] + li = [10**6, 10**12, 10**18, -10**6, -10**12, -10**18] + for T in [None,N.float64,N.int64]: + a = N.array(l,dtype=T) + assert_equal(map(int,a), li) + + a = N.array(l[:3],dtype=N.uint64) + assert_equal(map(int,a), li[:3]) + if __name__ == "__main__": NumpyTest().run() From numpy-svn at scipy.org Fri Jul 27 12:44:44 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 11:44:44 -0500 (CDT) Subject: [Numpy-svn] r3907 - trunk/numpy/f2py/lib Message-ID: <20070727164444.B9F8A39C04B@new.scipy.org> Author: pearu Date: 2007-07-27 11:44:39 -0500 (Fri, 27 Jul 2007) New Revision: 3907 Modified: trunk/numpy/f2py/lib/doc.txt Log: Doc update 2. Modified: trunk/numpy/f2py/lib/doc.txt =================================================================== --- trunk/numpy/f2py/lib/doc.txt 2007-07-27 14:36:28 UTC (rev 3906) +++ trunk/numpy/f2py/lib/doc.txt 2007-07-27 16:44:39 UTC (rev 3907) @@ -20,11 +20,10 @@ fact, wrapping Fortran programs to Python would be just one example of using these tools. -Wrapping Fortran with Python -============================ +Wrapping Fortran with Python - UI +================================= -There are two user interfaces to wrap Fortran programs with -Python: +There are two user interfaces to wrap Fortran programs with Python: - the command line program `f2py` that scans Fortran files given as command line arguments and builds extension modules @@ -84,3 +83,157 @@ >>> foo.hello() Hello! >>> + +Wrapping Fortran with Python - how it works? +============================================ + +The two users interfaces discussed above are implemented by functions +`main(sys_argv=None)` and `compile(source, jobname='untitled', +extra_args=[], source_ext=None, modulenames=None)` in file +`numpy/f2py/lib/main.py`. Both these functions call +`build_extension(sys_argv, sources_only=False)` function that reads +`sys_argv` list for files and options, constructs wrapper functions, +creates a `numpy.distutils` style `setup.py` file, and finally runs +it. + +`build_extension` options +------------------------- + +The following options are defined that can be used as command line +arguments to `f2py` or in `extra_args` list argument of the `compiler` +function: + + - `-m []` --- specify the name of a wrapper extension + module. Default is `untitled` or `unspecified` (if `` part + is not specified). + + - `--target-dir=` --- specify the directory path where + extension modules are saved. Default is the current working + directory. + + - `--build-dir=` --- specify the directory path where + temporary files are created during the build process. Default is + `_g2f2py` or temporary directory (when `` part is not + specified)). + + - `-I` --- specifies include directory path that is used for + finding Fortran 90 modules and when compiling sources. + + - `-D[=]`, `-U` --- defines or undefines CPP + macro used in compiling sources. See below for F2PY specific + macros. + + - `-L` --- specifies library directory path that is used in + linking extension modules. + + - `-l` --- specifies library that is used in linking extension + modules. + + - `.(o|a|so|dll|dylib|sl)` --- specifies extra object + files used in linking extension modules. + + - ``.pyf --- specifies signature file used for scanning + Fortran program signatures. + + - `.(f|f90|F90|F)` --- specifies Fortran source files used + for scanning Fortran program signatures (in case no signature + files are specified). These sources will be compiled and linked + with extension modules. + + - `.(c|cpp|C|CPP|c++)` --- specifies C/C++ source files + that will be compiled and linked with extension modules. Note that + if no signature file is specified then also C/C++ files are + scanned for Fortran program signatures. The Fortran program + signatures are assumed to be inside the C comment `/* f2py ... */` + block. + + - `--fcompiler=` --- specifies Fortran compiler to be + used in compiling/linking the sources. See also `--help-fcompiler` + option. + + - `--help-fcompiler` --- list Fortran compilers that are found in + the system, that are available or unavailable for the current + system. Then return without processing any other options. + + - `--compiler=` --- specifies C/C++ compiler to be + used in compiling/linking the sources. See also `--help-compiler` + option. + + - `--help-compiler` --- list C/C++ compilers that are available + for the current system. Then return without processing any other + options. + +Additional `f2py` command line options +-------------------------------------- + +Command line tool `f2py` uses the following additional command line +options: + + - `-c` --- specifies that F2PY should build extension + modules. Without this option F2PY just scans source files for + signatures and constructs extension module sources --- useful when + one needs to build extension modules manually (in Makefile, for + instance). See also `-h` option below. + + - `-h ` --- specifies the signature file name + where the results of scanning sources will be saved. With this + option F2PY just scans the sources but does not construct extension + modules sources --- useful when one needs to edit the signatures + of Fortran programs. If `` is `stdout` or `stderr` is + specified then the scanned signatures will be dumped to `stdout` + or `stderr` streams, respectively. + + - `--help-link [ ]...` --- list system resources as + defined in `numpy/distutils/system_info.py` and return. + + - `--parse` --- specifies that F2PY should just parce the + source files and dump the results to `stdout` stream. + Useful for debugging F2PY parser. + + +F2PY specific CPP macros +------------------------ + +F2PY may use the following CPP macros: + + - `-DF2PY_DEBUG_PYOBJ_TOFROM` --- show debug messages from + `pyobj_(to|from)_` functions. + + - `-DPREPEND_FORTRAN`, `-DNO_APPEND_FORTRAN`, `-DUPPERCASE_FORTRAN`, + `-DUNDERSCORE_G77` --- specify how Fortran compiler mangles Fortran + symbol names that need to be accessed from C extension modules. + Usually one never needs to specify these macros as supported + Fortran compilers should always mangle the names to be lower-cased + and with exactly one underscore after the name. + +Options for `compile` +--------------------- + +The `compile` function has the following options: + + - `source` --- a string containing Fortran code. To specify the + Fortran format of the `source` use the following header lines + in the `source` string: + + - `C -*- f77 -*-` --- the string contains Fortran 77 code + - `! -*- f90 -*-` --- the string contains Fortran 90 code in + free format. + - `! -*- fix -*-` --- the string contains Fortran 90 code in + fixed format. + - `! -*- pyf -*-` --- the string contains Fortran signatures. + + - `jobname='untitled'` --- a string specifing the name of an + extension module + + - `extra_args=[]` --- a list of `build_extension(..)` arguments, + see above. + + - `source_ext=None` --- a string specifying the extension (`.f` or + `.f90`) of the file where `source` will be saved for further + processing. Default extension will be determined from the `source` + string. + + - `modulenames=None` --- a list of module names that the build + process should create. `compile` function will try to import + these modules and return the corresponding module objects + as a list. From numpy-svn at scipy.org Fri Jul 27 16:48:52 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 15:48:52 -0500 (CDT) Subject: [Numpy-svn] r3908 - trunk/numpy/distutils Message-ID: <20070727204852.B9AC439C01F@new.scipy.org> Author: pearu Date: 2007-07-27 15:48:48 -0500 (Fri, 27 Jul 2007) New Revision: 3908 Modified: trunk/numpy/distutils/misc_util.py Log: Try to fix build on AMD64 with MSVC compiler. Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2007-07-27 16:44:39 UTC (rev 3907) +++ trunk/numpy/distutils/misc_util.py 2007-07-27 20:48:48 UTC (rev 3908) @@ -318,6 +318,20 @@ lib = None return lib +def msvc_on_amd64(): + if not (sys.platform=='win32' or os.name=='nt'): + return + from distutils.msvccompiler import get_build_architecture + if get_build_architecture() != 'AMD64': + return + if os.environ.has_key('DISTUTILS_USE_SDK'): + return + # try to avoid _MSVCCompiler__root attribute error + os.environ['DISTUTILS_USE_SDK']=1 + return + +msvc_on_amd64() + ######################### #XXX need support for .C that is also C++ From numpy-svn at scipy.org Fri Jul 27 17:12:39 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 16:12:39 -0500 (CDT) Subject: [Numpy-svn] r3909 - trunk/numpy/distutils Message-ID: <20070727211239.7450339C01F@new.scipy.org> Author: pearu Date: 2007-07-27 16:12:35 -0500 (Fri, 27 Jul 2007) New Revision: 3909 Modified: trunk/numpy/distutils/misc_util.py Log: Fix type error on setting os.environ item. Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2007-07-27 20:48:48 UTC (rev 3908) +++ trunk/numpy/distutils/misc_util.py 2007-07-27 21:12:35 UTC (rev 3909) @@ -327,7 +327,7 @@ if os.environ.has_key('DISTUTILS_USE_SDK'): return # try to avoid _MSVCCompiler__root attribute error - os.environ['DISTUTILS_USE_SDK']=1 + os.environ['DISTUTILS_USE_SDK']='1' return msvc_on_amd64() From numpy-svn at scipy.org Fri Jul 27 18:09:28 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 17:09:28 -0500 (CDT) Subject: [Numpy-svn] r3910 - trunk/numpy/distutils Message-ID: <20070727220928.3939D39C00C@new.scipy.org> Author: pearu Date: 2007-07-27 17:09:23 -0500 (Fri, 27 Jul 2007) New Revision: 3910 Modified: trunk/numpy/distutils/ccompiler.py trunk/numpy/distutils/misc_util.py Log: Added debug messages to see if quote_args are applied properly. Modified: trunk/numpy/distutils/ccompiler.py =================================================================== --- trunk/numpy/distutils/ccompiler.py 2007-07-27 21:12:35 UTC (rev 3909) +++ trunk/numpy/distutils/ccompiler.py 2007-07-27 22:09:23 UTC (rev 3910) @@ -371,6 +371,7 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries): library_dirs = quote_args(library_dirs) runtime_library_dirs = quote_args(runtime_library_dirs) + print 'gen_lib_options:',library_dirs, runtime_library_dirs r = _distutils_gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries) lib_opts = [] Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2007-07-27 21:12:35 UTC (rev 3909) +++ trunk/numpy/distutils/misc_util.py 2007-07-27 22:09:23 UTC (rev 3910) @@ -30,7 +30,9 @@ args = list(args) for i in range(len(args)): a = args[i] - if ' ' in a and a[0] not in '"\'': + if is_sequence(a): + args[i] = quote_args(a) + elif ' ' in a and a[0] not in '"\'': args[i] = '"%s"' % (a) return args @@ -327,6 +329,7 @@ if os.environ.has_key('DISTUTILS_USE_SDK'): return # try to avoid _MSVCCompiler__root attribute error + print 'Forcing DISTUTILS_USE_SDK=1' os.environ['DISTUTILS_USE_SDK']='1' return From numpy-svn at scipy.org Fri Jul 27 18:32:46 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 27 Jul 2007 17:32:46 -0500 (CDT) Subject: [Numpy-svn] r3911 - trunk/numpy/distutils Message-ID: <20070727223246.AB77D39C12E@new.scipy.org> Author: pearu Date: 2007-07-27 17:32:40 -0500 (Fri, 27 Jul 2007) New Revision: 3911 Modified: trunk/numpy/distutils/ccompiler.py trunk/numpy/distutils/misc_util.py Log: msvc_on_amd64 must be applied *after* importing ccompiler module, apply quote_args also to include_dirs. Modified: trunk/numpy/distutils/ccompiler.py =================================================================== --- trunk/numpy/distutils/ccompiler.py 2007-07-27 22:09:23 UTC (rev 3910) +++ trunk/numpy/distutils/ccompiler.py 2007-07-27 22:32:40 UTC (rev 3911) @@ -10,7 +10,7 @@ from numpy.distutils import log from numpy.distutils.exec_command import exec_command -from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, quote_args +from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, quote_args, msvc_on_amd64 # hack to set compiler optimizing options. Needs to integrated with something. import distutils.sysconfig @@ -383,6 +383,11 @@ return lib_opts ccompiler.gen_lib_options = gen_lib_options +_distutils_gen_preprocess_options = gen_preprocess_options +def gen_preprocess_options (macros, include_dirs): + include_dirs = quote_args(include_dirs) + return _distutils_gen_preprocess_options(macros, include_dirs) +ccompiler.gen_preprocess_options = gen_preprocess_options ##Fix distutils.util.split_quoted: import re,string @@ -440,3 +445,6 @@ return words ccompiler.split_quoted = split_quoted + +# define DISTUTILS_USE_SDK when necessary to workaround distutils/msvccompiler.py bug +msvc_on_amd64() Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2007-07-27 22:09:23 UTC (rev 3910) +++ trunk/numpy/distutils/misc_util.py 2007-07-27 22:32:40 UTC (rev 3911) @@ -333,8 +333,6 @@ os.environ['DISTUTILS_USE_SDK']='1' return -msvc_on_amd64() - ######################### #XXX need support for .C that is also C++ From numpy-svn at scipy.org Sat Jul 28 06:07:16 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:07:16 -0500 (CDT) Subject: [Numpy-svn] r3912 - trunk/numpy/core/src Message-ID: <20070728100716.76BB339C052@new.scipy.org> Author: pearu Date: 2007-07-28 05:07:12 -0500 (Sat, 28 Jul 2007) New Revision: 3912 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix inconsisted dll linkage warning, clean up. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-27 22:32:40 UTC (rev 3911) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:07:12 UTC (rev 3912) @@ -66,8 +66,13 @@ #undef sqrtf #endif float log1pf(float); +#if defined(_MSC_VER) +float __cdecl logf(float); +float __cdecl sqrtf(float); +#else float logf(float); float sqrtf(float); +#endif #ifdef acoshf #undef acoshf #endif From numpy-svn at scipy.org Sat Jul 28 06:07:51 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:07:51 -0500 (CDT) Subject: [Numpy-svn] r3913 - trunk/numpy/distutils Message-ID: <20070728100751.8069839C052@new.scipy.org> Author: pearu Date: 2007-07-28 05:07:47 -0500 (Sat, 28 Jul 2007) New Revision: 3913 Modified: trunk/numpy/distutils/ccompiler.py trunk/numpy/distutils/misc_util.py Log: remove debug messages. Modified: trunk/numpy/distutils/ccompiler.py =================================================================== --- trunk/numpy/distutils/ccompiler.py 2007-07-28 10:07:12 UTC (rev 3912) +++ trunk/numpy/distutils/ccompiler.py 2007-07-28 10:07:47 UTC (rev 3913) @@ -371,7 +371,6 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries): library_dirs = quote_args(library_dirs) runtime_library_dirs = quote_args(runtime_library_dirs) - print 'gen_lib_options:',library_dirs, runtime_library_dirs r = _distutils_gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries) lib_opts = [] Modified: trunk/numpy/distutils/misc_util.py =================================================================== --- trunk/numpy/distutils/misc_util.py 2007-07-28 10:07:12 UTC (rev 3912) +++ trunk/numpy/distutils/misc_util.py 2007-07-28 10:07:47 UTC (rev 3913) @@ -26,13 +26,11 @@ def quote_args(args): # don't used _nt_quote_args as it does not check if - # args items already have quotes. + # args items already have quotes or not. args = list(args) for i in range(len(args)): a = args[i] - if is_sequence(a): - args[i] = quote_args(a) - elif ' ' in a and a[0] not in '"\'': + if ' ' in a and a[0] not in '"\'': args[i] = '"%s"' % (a) return args From numpy-svn at scipy.org Sat Jul 28 06:16:37 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:16:37 -0500 (CDT) Subject: [Numpy-svn] r3914 - trunk/numpy/core/src Message-ID: <20070728101637.B172339C052@new.scipy.org> Author: pearu Date: 2007-07-28 05:16:34 -0500 (Sat, 28 Jul 2007) New Revision: 3914 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix inconsisted dll linkage warning, 2. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:07:47 UTC (rev 3913) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:16:34 UTC (rev 3914) @@ -66,7 +66,7 @@ #undef sqrtf #endif float log1pf(float); -#if defined(_MSC_VER) +#if defined(MS_WIN64) float __cdecl logf(float); float __cdecl sqrtf(float); #else From numpy-svn at scipy.org Sat Jul 28 06:19:04 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:19:04 -0500 (CDT) Subject: [Numpy-svn] r3915 - trunk/numpy/core/src Message-ID: <20070728101904.7D19939C052@new.scipy.org> Author: pearu Date: 2007-07-28 05:19:01 -0500 (Sat, 28 Jul 2007) New Revision: 3915 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix inconsisted dll linkage warning, 3. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:16:34 UTC (rev 3914) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:19:01 UTC (rev 3915) @@ -66,7 +66,7 @@ #undef sqrtf #endif float log1pf(float); -#if defined(MS_WIN64) +#if defined(_WIN64) float __cdecl logf(float); float __cdecl sqrtf(float); #else From numpy-svn at scipy.org Sat Jul 28 06:24:36 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:24:36 -0500 (CDT) Subject: [Numpy-svn] r3916 - in trunk/numpy/core: . src Message-ID: <20070728102436.AA22B39C076@new.scipy.org> Author: pearu Date: 2007-07-28 05:24:20 -0500 (Sat, 28 Jul 2007) New Revision: 3916 Modified: trunk/numpy/core/setup.py trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix inconsisted dll linkage warning, 4. Modified: trunk/numpy/core/setup.py =================================================================== --- trunk/numpy/core/setup.py 2007-07-28 10:19:01 UTC (rev 3915) +++ trunk/numpy/core/setup.py 2007-07-28 10:24:20 UTC (rev 3916) @@ -105,6 +105,9 @@ if sys.platform == 'win32': moredefs.append('NPY_NO_SIGNAL') + if os.environ.get('DISTUTILS_USE_SDK'): + moredefs.append('DISTUTILS_USE_SDK') + if sys.version[:3] < '2.4': if config_cmd.check_func('strtod', decl=False, headers=['stdlib.h']): Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:19:01 UTC (rev 3915) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:24:20 UTC (rev 3916) @@ -66,7 +66,7 @@ #undef sqrtf #endif float log1pf(float); -#if defined(_WIN64) +#if defined(DISTUTILS_USE_SDK) float __cdecl logf(float); float __cdecl sqrtf(float); #else From numpy-svn at scipy.org Sat Jul 28 06:28:47 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:28:47 -0500 (CDT) Subject: [Numpy-svn] r3917 - trunk/numpy/core Message-ID: <20070728102847.8FC4D39C052@new.scipy.org> Author: pearu Date: 2007-07-28 05:28:44 -0500 (Sat, 28 Jul 2007) New Revision: 3917 Modified: trunk/numpy/core/setup.py Log: Trying to fix inconsisted dll linkage warning, 5. Modified: trunk/numpy/core/setup.py =================================================================== --- trunk/numpy/core/setup.py 2007-07-28 10:24:20 UTC (rev 3916) +++ trunk/numpy/core/setup.py 2007-07-28 10:28:44 UTC (rev 3917) @@ -105,8 +105,10 @@ if sys.platform == 'win32': moredefs.append('NPY_NO_SIGNAL') - if os.environ.get('DISTUTILS_USE_SDK'): - moredefs.append('DISTUTILS_USE_SDK') + if sys.platform=='win32' or os.name=='nt': + from distutils.msvccompiler import get_build_architecture + if get_build_architecture() == 'AMD64': + moredefs.append('DISTUTILS_USE_SDK') if sys.version[:3] < '2.4': if config_cmd.check_func('strtod', decl=False, From numpy-svn at scipy.org Sat Jul 28 06:33:49 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 05:33:49 -0500 (CDT) Subject: [Numpy-svn] r3918 - in trunk/numpy/core: . src Message-ID: <20070728103349.86DEA39C052@new.scipy.org> Author: pearu Date: 2007-07-28 05:33:44 -0500 (Sat, 28 Jul 2007) New Revision: 3918 Modified: trunk/numpy/core/setup.py trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix inconsisted dll linkage warning, 6. Modified: trunk/numpy/core/setup.py =================================================================== --- trunk/numpy/core/setup.py 2007-07-28 10:28:44 UTC (rev 3917) +++ trunk/numpy/core/setup.py 2007-07-28 10:33:44 UTC (rev 3918) @@ -107,7 +107,9 @@ if sys.platform=='win32' or os.name=='nt': from distutils.msvccompiler import get_build_architecture - if get_build_architecture() == 'AMD64': + a = get_build_architecture() + print 'BUILD_ARCHITECTURE: %r, os.name=%r, sys.platform=%r' % (a, os.name, sys.platform) + if a == 'AMD64': moredefs.append('DISTUTILS_USE_SDK') if sys.version[:3] < '2.4': Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:28:44 UTC (rev 3917) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 10:33:44 UTC (rev 3918) @@ -66,7 +66,7 @@ #undef sqrtf #endif float log1pf(float); -#if defined(DISTUTILS_USE_SDK) +#ifdef DISTUTILS_USE_SDK float __cdecl logf(float); float __cdecl sqrtf(float); #else From numpy-svn at scipy.org Sat Jul 28 07:01:29 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 06:01:29 -0500 (CDT) Subject: [Numpy-svn] r3919 - trunk/numpy/core Message-ID: <20070728110129.3502839C052@new.scipy.org> Author: pearu Date: 2007-07-28 06:01:24 -0500 (Sat, 28 Jul 2007) New Revision: 3919 Modified: trunk/numpy/core/setup.py Log: Trying to fix inconsisted dll linkage warning, 7. Modified: trunk/numpy/core/setup.py =================================================================== --- trunk/numpy/core/setup.py 2007-07-28 10:33:44 UTC (rev 3918) +++ trunk/numpy/core/setup.py 2007-07-28 11:01:24 UTC (rev 3919) @@ -137,6 +137,12 @@ mathlibs.extend(value.split(',')) target_f.close() + print 'File:',target + target_f = open(target) + print target.read() + target_f.close() + print 'EOF' + ext.libraries.extend(mathlibs) incl_dir = os.path.dirname(target) From numpy-svn at scipy.org Sat Jul 28 07:16:30 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 06:16:30 -0500 (CDT) Subject: [Numpy-svn] r3920 - trunk/numpy/core Message-ID: <20070728111630.7E81239C052@new.scipy.org> Author: pearu Date: 2007-07-28 06:16:26 -0500 (Sat, 28 Jul 2007) New Revision: 3920 Modified: trunk/numpy/core/setup.py Log: Fix typo. Modified: trunk/numpy/core/setup.py =================================================================== --- trunk/numpy/core/setup.py 2007-07-28 11:01:24 UTC (rev 3919) +++ trunk/numpy/core/setup.py 2007-07-28 11:16:26 UTC (rev 3920) @@ -139,7 +139,7 @@ print 'File:',target target_f = open(target) - print target.read() + print target_f.read() target_f.close() print 'EOF' From numpy-svn at scipy.org Sat Jul 28 07:22:04 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 06:22:04 -0500 (CDT) Subject: [Numpy-svn] r3921 - trunk/numpy/core/src Message-ID: <20070728112204.4464639C052@new.scipy.org> Author: pearu Date: 2007-07-28 06:22:01 -0500 (Sat, 28 Jul 2007) New Revision: 3921 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix inconsisted dll linkage warning, 8: Dont understand why my changes have no effect, giving up for now. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 11:16:26 UTC (rev 3920) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 11:22:01 UTC (rev 3921) @@ -66,13 +66,8 @@ #undef sqrtf #endif float log1pf(float); -#ifdef DISTUTILS_USE_SDK -float __cdecl logf(float); -float __cdecl sqrtf(float); -#else float logf(float); float sqrtf(float); -#endif #ifdef acoshf #undef acoshf #endif From numpy-svn at scipy.org Sat Jul 28 08:02:56 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:02:56 -0500 (CDT) Subject: [Numpy-svn] r3922 - in trunk/numpy/core: . src Message-ID: <20070728120256.1AB1F39C01C@new.scipy.org> Author: pearu Date: 2007-07-28 07:02:52 -0500 (Sat, 28 Jul 2007) New Revision: 3922 Modified: trunk/numpy/core/setup.py trunk/numpy/core/src/umathmodule.c.src Log: Trying to use DL_IMPORT for logf, sqrtf. Modified: trunk/numpy/core/setup.py =================================================================== --- trunk/numpy/core/setup.py 2007-07-28 11:22:01 UTC (rev 3921) +++ trunk/numpy/core/setup.py 2007-07-28 12:02:52 UTC (rev 3922) @@ -126,6 +126,11 @@ if not nosmp: # default is to use WITH_THREAD target_f.write('#ifdef WITH_THREAD\n#define NPY_ALLOW_THREADS 1\n#else\n#define NPY_ALLOW_THREADS 0\n#endif\n') target_f.close() + print 'File:',target + target_f = open(target) + print target_f.read() + target_f.close() + print 'EOF' else: mathlibs = [] target_f = open(target) @@ -137,12 +142,6 @@ mathlibs.extend(value.split(',')) target_f.close() - print 'File:',target - target_f = open(target) - print target_f.read() - target_f.close() - print 'EOF' - ext.libraries.extend(mathlibs) incl_dir = os.path.dirname(target) Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 11:22:01 UTC (rev 3921) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:02:52 UTC (rev 3922) @@ -66,8 +66,8 @@ #undef sqrtf #endif float log1pf(float); -float logf(float); -float sqrtf(float); +DL_IMPORT(float) logf(float); +DL_IMPORT(float) sqrtf(float); #ifdef acoshf #undef acoshf #endif From numpy-svn at scipy.org Sat Jul 28 08:16:39 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:16:39 -0500 (CDT) Subject: [Numpy-svn] r3923 - trunk/numpy/core/src Message-ID: <20070728121639.8D7BE39C01C@new.scipy.org> Author: pearu Date: 2007-07-28 07:16:34 -0500 (Sat, 28 Jul 2007) New Revision: 3923 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Defining fabsf, hypotf, rintf when DISTUTILS_USE_SDK. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:02:52 UTC (rev 3922) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:16:34 UTC (rev 3923) @@ -21,6 +21,32 @@ #endif +#if defined(DISTUTILS_USE_SDK) +/* win32 on AMD64 build architecture */ +/* See also http://projects.scipy.org/scipy/numpy/ticket/164 */ +#ifndef HAVE_FABSF +#ifdef fabsf +#undef fabsf +#endif +static float fabsf(float x) +{ + return (float)fabs((double)(x)); +} +#endif +#ifndef HAVE_HYPOTF +static float hypotf(float x, float y) +{ + return (float)hypot((float)(x), (float)(y)); +} +#endif +#ifndef HAVE_RINTF +static float rintf(float x) +{ + return (float)rint((double) x); +} +#endif +#endif + #ifndef HAVE_INVERSE_HYPERBOLIC static double acosh(double x) { From numpy-svn at scipy.org Sat Jul 28 08:19:07 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:19:07 -0500 (CDT) Subject: [Numpy-svn] r3924 - trunk/numpy/core/src Message-ID: <20070728121907.5F51039C01C@new.scipy.org> Author: pearu Date: 2007-07-28 07:19:04 -0500 (Sat, 28 Jul 2007) New Revision: 3924 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Using DLL_IMPORT only when DISTUTILS_USE_SDK. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:16:34 UTC (rev 3923) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:19:04 UTC (rev 3924) @@ -92,8 +92,14 @@ #undef sqrtf #endif float log1pf(float); +#if defined(DISTUTILS_USE_SDK) DL_IMPORT(float) logf(float); DL_IMPORT(float) sqrtf(float); +#else +/* should these be extern?: */ +float logf(float); +float sqrtf(float); +#endif #ifdef acoshf #undef acoshf #endif From numpy-svn at scipy.org Sat Jul 28 08:24:55 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:24:55 -0500 (CDT) Subject: [Numpy-svn] r3925 - trunk/numpy/core/src Message-ID: <20070728122455.3347E39C0CA@new.scipy.org> Author: pearu Date: 2007-07-28 07:24:51 -0500 (Sat, 28 Jul 2007) New Revision: 3925 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Fix rint error and castings. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:19:04 UTC (rev 3924) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:24:51 UTC (rev 3925) @@ -36,13 +36,16 @@ #ifndef HAVE_HYPOTF static float hypotf(float x, float y) { - return (float)hypot((float)(x), (float)(y)); + return (float)hypot((double)(x), (double)(y)); } #endif #ifndef HAVE_RINTF +#ifndef HAVE_RINT +static double rint (double x); +#endif static float rintf(float x) { - return (float)rint((double) x); + return (float)rint((double)(x)); } #endif #endif From numpy-svn at scipy.org Sat Jul 28 08:29:07 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:29:07 -0500 (CDT) Subject: [Numpy-svn] r3926 - trunk/numpy/core/src Message-ID: <20070728122907.8CCD239C01C@new.scipy.org> Author: pearu Date: 2007-07-28 07:29:04 -0500 (Sat, 28 Jul 2007) New Revision: 3926 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix mingw32 build. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:24:51 UTC (rev 3925) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:29:04 UTC (rev 3926) @@ -95,7 +95,7 @@ #undef sqrtf #endif float log1pf(float); -#if defined(DISTUTILS_USE_SDK) +#ifdef DISTUTILS_USE_SDK DL_IMPORT(float) logf(float); DL_IMPORT(float) sqrtf(float); #else From numpy-svn at scipy.org Sat Jul 28 08:36:19 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:36:19 -0500 (CDT) Subject: [Numpy-svn] r3927 - trunk/numpy/core/src Message-ID: <20070728123619.668CD39C01C@new.scipy.org> Author: pearu Date: 2007-07-28 07:36:16 -0500 (Sat, 28 Jul 2007) New Revision: 3927 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix compiler wrarnings: conversion from 'double' to 'float' Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:29:04 UTC (rev 3926) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:36:16 UTC (rev 3927) @@ -1139,7 +1139,7 @@ } else { *((@otyp@ *)op)= \ - *((@typ@ *)i1) / (double)*((@typ@ *)i2); + (double)*((@typ@ *)i1) / (double)*((@typ@ *)i2); } } } From numpy-svn at scipy.org Sat Jul 28 08:41:43 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 07:41:43 -0500 (CDT) Subject: [Numpy-svn] r3928 - trunk/numpy/core/src Message-ID: <20070728124143.DBD5E39C01C@new.scipy.org> Author: pearu Date: 2007-07-28 07:41:40 -0500 (Sat, 28 Jul 2007) New Revision: 3928 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix compiler wrarnings, 2. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:36:16 UTC (rev 3927) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:41:40 UTC (rev 3928) @@ -1139,7 +1139,7 @@ } else { *((@otyp@ *)op)= \ - (double)*((@typ@ *)i1) / (double)*((@typ@ *)i2); + (@otyp@)((double)*((@typ@ *)i1) / (double)*((@typ@ *)i2)); } } } @@ -1381,8 +1381,8 @@ @btyp@ x, y; for(i=0; i Author: pearu Date: 2007-07-28 07:56:02 -0500 (Sat, 28 Jul 2007) New Revision: 3929 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix compiler wrarnings, 3. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:41:40 UTC (rev 3928) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:56:02 UTC (rev 3929) @@ -1615,7 +1615,7 @@ intp is1=steps[0],os=steps[1], n=dimensions[0]; char *i1=args[0], *op=args[1]; for(i=0; i Author: pearu Date: 2007-07-28 07:59:13 -0500 (Sat, 28 Jul 2007) New Revision: 3930 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix compiler wrarnings, 4. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:56:02 UTC (rev 3929) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:59:13 UTC (rev 3930) @@ -1607,6 +1607,7 @@ #TYPE=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE# #typ=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble# +#styp=byte, byte, short, short, int, int, long, long, longlong, longlong, float, double, longdouble# */ static void @TYPE at _negative(char **args, intp *dimensions, intp *steps, void *func) @@ -1615,7 +1616,7 @@ intp is1=steps[0],os=steps[1], n=dimensions[0]; char *i1=args[0], *op=args[1]; for(i=0; i Author: pearu Date: 2007-07-28 08:07:50 -0500 (Sat, 28 Jul 2007) New Revision: 3931 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix compiler wrarnings, 5. Defined frexpf when DISTUTILS_USE_SDK. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 12:59:13 UTC (rev 3930) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 13:07:50 UTC (rev 3931) @@ -48,7 +48,13 @@ return (float)rint((double)(x)); } #endif +#ifndef HAVE_FREXPF +static float frexpf(float x, int * i); +{ + return (float)frexp((double)(x), i); +} #endif +#endif #ifndef HAVE_INVERSE_HYPERBOLIC static double acosh(double x) @@ -1659,7 +1665,7 @@ @typ@ t1; for(i=0; i Author: pearu Date: 2007-07-28 08:13:33 -0500 (Sat, 28 Jul 2007) New Revision: 3932 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix compiler wrarnings, 5. Defined ldexpf when DISTUTILS_USE_SDK. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 13:07:50 UTC (rev 3931) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 13:13:33 UTC (rev 3932) @@ -54,7 +54,13 @@ return (float)frexp((double)(x), i); } #endif +#ifndef HAVE_LDEXPF +static float ldexpf(float x, int i); +{ + return (float)ldexp((double)(x), i); +} #endif +#endif #ifndef HAVE_INVERSE_HYPERBOLIC static double acosh(double x) From numpy-svn at scipy.org Sat Jul 28 09:16:16 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 08:16:16 -0500 (CDT) Subject: [Numpy-svn] r3933 - trunk/numpy/core/src Message-ID: <20070728131616.500AC39C0CA@new.scipy.org> Author: pearu Date: 2007-07-28 08:16:12 -0500 (Sat, 28 Jul 2007) New Revision: 3933 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Fixed typos. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 13:13:33 UTC (rev 3932) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 13:16:12 UTC (rev 3933) @@ -49,13 +49,13 @@ } #endif #ifndef HAVE_FREXPF -static float frexpf(float x, int * i); +static float frexpf(float x, int * i) { return (float)frexp((double)(x), i); } #endif #ifndef HAVE_LDEXPF -static float ldexpf(float x, int i); +static float ldexpf(float x, int i) { return (float)ldexp((double)(x), i); } From numpy-svn at scipy.org Sat Jul 28 09:28:23 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 08:28:23 -0500 (CDT) Subject: [Numpy-svn] r3934 - trunk/numpy/core/src Message-ID: <20070728132823.43A4139C05E@new.scipy.org> Author: pearu Date: 2007-07-28 08:28:18 -0500 (Sat, 28 Jul 2007) New Revision: 3934 Modified: trunk/numpy/core/src/ufuncobject.c Log: Fix more compiler warnings. Modified: trunk/numpy/core/src/ufuncobject.c =================================================================== --- trunk/numpy/core/src/ufuncobject.c 2007-07-28 13:16:12 UTC (rev 3933) +++ trunk/numpy/core/src/ufuncobject.c 2007-07-28 13:28:18 UTC (rev 3934) @@ -712,7 +712,7 @@ } } else if PyString_Check(type_tup) { - int slen; + Py_ssize_t slen; char *thestr; slen = PyString_GET_SIZE(type_tup); thestr = PyString_AS_STRING(type_tup); @@ -1110,11 +1110,12 @@ #undef _GETATTR_ -static int +static Py_ssize_t construct_arrays(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps, PyObject *typetup) { - int nargs, i; + Py_ssize_t nargs; + int i; int arg_types[NPY_MAXARGS]; PyArray_SCALARKIND scalars[NPY_MAXARGS]; PyArray_SCALARKIND maxarrkind, maxsckind, new; @@ -2953,7 +2954,8 @@ static void _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout) { - int nargs, i; + Py_ssize_t nargs; + int i; int np = 0; double priority, maxpriority; PyObject *with_wrap[NPY_MAXARGS], *wraps[NPY_MAXARGS]; From numpy-svn at scipy.org Sat Jul 28 15:04:51 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 14:04:51 -0500 (CDT) Subject: [Numpy-svn] r3935 - trunk/numpy/core/code_generators Message-ID: <20070728190451.8E9DD39C034@new.scipy.org> Author: pearu Date: 2007-07-28 14:04:45 -0500 (Sat, 28 Jul 2007) New Revision: 3935 Modified: trunk/numpy/core/code_generators/generate_umath.py Log: Initializing funcname_data inside InitOperators to fix compilation errors on Win32 AMD64 using SDK. Modified: trunk/numpy/core/code_generators/generate_umath.py =================================================================== --- trunk/numpy/core/code_generators/generate_umath.py 2007-07-28 13:28:18 UTC (rev 3934) +++ trunk/numpy/core/code_generators/generate_umath.py 2007-07-28 19:04:45 UTC (rev 3935) @@ -568,7 +568,11 @@ elif t.type == 'M': datalist.append('(void *)"%s"' % t.func_data) else: - datalist.append('(void *)%s' % t.func_data) + astr = '%s_data[%d] = (void *) %s;' % \ + (name, k, t.func_data) + code2list.append(astr) + datalist.append('(void *)NULL') + #datalist.append('(void *)%s' % t.func_data) sub += 1 else: datalist.append('(void *)NULL'); From numpy-svn at scipy.org Sat Jul 28 15:23:22 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 14:23:22 -0500 (CDT) Subject: [Numpy-svn] r3936 - trunk/numpy/core/src Message-ID: <20070728192322.3EC0439C034@new.scipy.org> Author: pearu Date: 2007-07-28 14:23:16 -0500 (Sat, 28 Jul 2007) New Revision: 3936 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix unknown symbol __imp_tanhf linking error. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 19:04:45 UTC (rev 3935) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 19:23:16 UTC (rev 3936) @@ -60,6 +60,7 @@ return (float)ldexp((double)(x), i); } #endif +DL_IMPORT(float) tanhf(float); #endif #ifndef HAVE_INVERSE_HYPERBOLIC From numpy-svn at scipy.org Sat Jul 28 15:44:14 2007 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 28 Jul 2007 14:44:14 -0500 (CDT) Subject: [Numpy-svn] r3937 - trunk/numpy/core/src Message-ID: <20070728194414.0538E39C034@new.scipy.org> Author: pearu Date: 2007-07-28 14:44:07 -0500 (Sat, 28 Jul 2007) New Revision: 3937 Modified: trunk/numpy/core/src/umathmodule.c.src Log: Trying to fix unknown symbol __imp_tanhf linking error, using nc_tanhf. Modified: trunk/numpy/core/src/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umathmodule.c.src 2007-07-28 19:23:16 UTC (rev 3936) +++ trunk/numpy/core/src/umathmodule.c.src 2007-07-28 19:44:07 UTC (rev 3937) @@ -60,7 +60,7 @@ return (float)ldexp((double)(x), i); } #endif -DL_IMPORT(float) tanhf(float); +#define tanhf nc_tanhf #endif #ifndef HAVE_INVERSE_HYPERBOLIC