From juerg-tschirren at uiowa.edu Sun Jul 1 15:23:17 2001 From: juerg-tschirren at uiowa.edu (Juerg Tschirren) Date: Sun, 1 Jul 2001 14:23:17 -0500 (CDT) Subject: [Numpy-discussion] segfault in PyArray_FromDims Message-ID: I did some experimenting with the NumPy C API. I wrote two functions. One for processing a NumPy array in C++ and the other one for generating a NumPy array in C++. The processing function work perfectly fine. But in the array-generating function I get a segmentation fault whenever I call PyArray_FromDims. I used swig for generating the wrapper functions. The two src-files (numPyExt.i and numPyExt.cc): --- begin numPyExt.i ------------------------------------------------- %module numPyExt %{ #include #include #include %} %init %{ import_array(); %} %typemap(python,in) double * { PyArrayObject *py_arr; if(!PyArray_Check($source)) { PyErr_SetString(PyExc_TypeError, "Not a NumPy array"); return NULL; } if (PyArray_ObjectType($source,0) != PyArray_DOUBLE) { PyErr_SetString(PyExc_ValueError, "Array must be of type double"); return NULL; } py_arr = (PyArrayObject*) \ (PyArray_ContiguousFromObject($source, PyArray_DOUBLE, 1, 1)); if (py_arr->nd != 1) { PyErr_SetString(PyExc_TypeError, "Array must be 1D"); return NULL; } $target = (double*)(py_arr->data); } extern PyObject* createArray(); extern void processArray(double* pdInArray); --- end numPyExt.i --------------------------------------------------- --- begin numPyExt.cc ------------------------------------------------ #include #include #include //------ PyObject* createArray() { PyArrayObject* retArray; int iDimensions[3] = {10, 10, 10}; cout << "before PyArray_FromDims" << endl << flush; retArray = (PyArrayObject*)PyArray_FromDims(3, iDimensions, PyArray_INT); cout << "after PyArray_FromDims" << endl << flush; return PyArray_Return(retArray); } //------ void processArray(double* pdInArray) { cout << *pdInArray << " " << *(pdInArray+1) << " " << *(pdInArray+2) << endl; } --- end numPyExt.cc -------------------------------------------------- Compiled with: g++ -c -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -O2 numPyExt.cc swig -python -c++ numPyExt.i g++ -c -O2 numPyExt_wrap.c -DOS_LINUX -DHAVE_CONFIG_H -I. -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -I/usr/local/lib/python2.0/config g++ -W1,--heap,50000,--stack,100000 -O2 -shared numPyExt.o numPyExt_wrap.o -lstdc++ -o numPyExt.so The Python test code I am using: import Numeric, numPyExt vec = Numeric.array((1.23, 4.56, 7.89)) numPyExt.processArray(vec) # works fine a = numPyExt.createArray() # seg fault here print a I am using NumPy v20.0.0, Python 2.1, and gcc 2.95.2 on a Linux 2.2.16 sytem. Does anybody have an idea what's causing this problem? Juerg From cookedm at physics.mcmaster.ca Sun Jul 1 22:38:43 2001 From: cookedm at physics.mcmaster.ca (David M. Cooke) Date: 01 Jul 2001 22:38:43 -0400 Subject: [Numpy-discussion] segfault in PyArray_FromDims In-Reply-To: References: Message-ID: At some point, Juerg Tschirren wrote: > I did some experimenting with the NumPy C API. I wrote two functions. > One for processing a NumPy array in C++ and the other one for > generating a NumPy array in C++. The processing function work perfectly > fine. But in the array-generating function I get a segmentation fault > whenever I call PyArray_FromDims. I used swig for generating the wrapper > functions. > > The two src-files (numPyExt.i and numPyExt.cc): [code snipped] > Compiled with: > g++ -c -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -O2 numPyExt.cc > swig -python -c++ numPyExt.i > g++ -c -O2 numPyExt_wrap.c -DOS_LINUX -DHAVE_CONFIG_H -I. -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -I/usr/local/lib/python2.0/config > g++ -W1,--heap,50000,--stack,100000 -O2 -shared numPyExt.o numPyExt_wrap.o -lstdc++ -o numPyExt.so > This problem was discussed in April on this list, see http://www.geocrawler.com/mail/thread.php3?subject=%5BNumpy-discussion%5D+Numeric+on+OS+X+-+Anyone+get+it+to+work+%3F&list=1329 I banged my head against this for hours a few weeks ago until I found the above. The problem is that PyArray_FromDims (and all other PyArray_*) are not functions -- they're macros, defined like this: #define PyArray_FromDims \ (*(PyArray_FromDims_RET (*)PyArray_FromDims_PROTO) \ PyArray_API[PyArray_FromDims_NUM]) This means that all the PyArray_* functions are done through a lookup table PyArray_API, which is initialized by import_array(). By default, PyArray_API is defined in arrayobject.h as 'static void **PyArray_API', meaning that it is not accessible outside of the translation unit (i.e. file) that includes it. The relevant part of Numeric/arrayobject.h is this: #if defined(PY_ARRAY_UNIQUE_SYMBOL) #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL #endif /* C API address pointer */ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY) extern void **PyArray_API; #else #if defined(PY_ARRAY_UNIQUE_SYMBOL) void **PyArray_API; #else static void **PyArray_API; #endif #endif So, one way to get the behaviour you want is 1) in the file where import_array is called, #define PY_ARRAY_UNIQUE_SYMBOL to be something like Py_Array_API_myext. (Make it unique because it will be exported as part of the .so file.) before including Numeric/arrayobject.h 2) in the other files, #define NO_IMPORT_ARRAY before including Numeric/arrayobject.h Another way is to have your main file (say, main.c) call functions in the other files, passing the value of PyArray_API defined there, so that the other files can set theirs to that value. Hope this helps. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm at physics.mcmaster.ca From feiguin at magnet.fsu.edu Mon Jul 2 12:03:52 2001 From: feiguin at magnet.fsu.edu (Adrian Feiguin) Date: Mon, 2 Jul 2001 12:03:52 -0400 (EDT) Subject: [Numpy-discussion] gtkLeastSquares.py Message-ID: Hi everybody, I'm the author of SciGraphica (http://scigraphica.sourceforge.net), an application for scientific graphics and data analysis that uses Python and Numpy. Among other things, it features spreadheets that can contain Python data, like formulas. The Python stuff was mainly done by Conrad Steenberg, because I don't have much experience, specially embedding Python into C. However, I decided to get started this weekend because we needed badly a GUI for non-linear least squares fits. The result is gtkLeastSquares.py, which is attached below. It's going to be distributed with SG, but it works independently and needs gtk.py and Scientific. Basically it is a gtk GUI for Scientific.Functions.LeastSquares. I'm quite satisfied with the result, considering that I'm a newbie ;-) I'm writting because I'd like to have some feedback, and people interested in contributing. The code is still immature, and needs enhancements, like user defined functions and parameters (either editing the existing in the GUI, or adding new ones interactively). I still have to learn. It is very simple, and easy to use. You'll find the code below, with an example at the bottom of the file. I hope you like it. All comments, and suggestions are very welcome (as well as contributors ;-) Thank you, -------------- Cut here ---------------------- # # gtkLeastSquares.py : GUI for the module Scientific.Functions.LeastSquares # Implementation of the Levenberg-Marquardt algorithm for general # non-linear least-squares fits. # # Copyright (C) 2001 Adrian E. Feiguin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # from string import * from gtk import * from Numeric import * from Scientific.Functions.LeastSquares import * from Scientific.Functions.FirstDerivatives import * def fit_linear(parameters, values): a, b = parameters x = values return (a + b * x) def fit_cuadratic(parameters, values): a, b, c, x0 = parameters x = values return(a + b * (x - x0) + c * (x - x0)**2) return def fit_gauss(parameters, values): y0, x0, a, w = parameters x = values return(y0 + a * exp(-2*(x-x0)**2/w**2)) return def fit_lorentz(parameters, values): x0, y0, a, b = parameters x = values return(y0 + 2*a/pi * w / (4 * (x - x0)**2 + w**2)) return def fit_boltzman(parameters, values): x0, a1, a2, dx = parameters x = values return((a1 - a2)/(1 + exp((x - x0)/dx)) + a2) def fit_logistic(parameters, values): x0, a1, a2, p = parameters x = values return((a1 - a2)/(1 + (x/x0)**p) + a2) def fit_expdecay(parameters, values): x0, y0, a, t = parameters x = values return(y0 + a * exp(-(x - x0)/t)) def fit_expgrow(parameters, values): x0, y0, a, t = parameters x = values return(y0 + a * exp((x - x0)/t)) def fit_expassoc(parameters, values): y0, a1, t1, a2, t2 = parameters x = values return(y0 + a1 * (1 + exp(-x/t1)) + a2 * (1 + exp(-x/t2))) def fit_hyperbl(parameters, values): p1, p2 = parameters x = values return(p1 * x/ (p2 + x)) def fit_pulse(parameters, values): x0, y0, a, t1, t2 = parameters x = values return(y0 + a * (1 + exp(-(x - x0)/t1)) * exp(-(x - x0)/t2)) def fit_rational0(parameters, values): a, b, c = parameters x = values return((b + c*x)/(1 + a*x)) def fit_sine(parameters, values): x0, a, w = parameters x = values return(a * sin(pi*(x - x0)/w)) def fit_gaussamp(parameters, values): x0, y0, a, w = parameters x = values return(y0 + a * exp(-(x - x0)**2/(2*w**2))) def fit_allometric(parameters, values): a, b = parameters x = values return(a * x**b) fit_linear_dic = { "Doc" : "Linear Function", "Exp" : "y = a + b * x", "Par" : ("a", "b"), "NumPar" : 2, "IVar" : "x", "DVar" : "y", "Function" : fit_linear } fit_cuadratic_dic = { "Doc" : "Cuadratic Function", "Exp" : "y = a + b * (x - x0) + c * (x - x0)**2", "Par" : ("a", "b", "c", "x0"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_cuadratic } fit_gauss_dic = { "Doc" : "Amplitude version of Gaussian Function", "Exp" : "y = y0 + a * exp(-2*(x-x0)**2/w**2)", "Par" : ("x0", "y0", "a", "w"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_gauss } fit_lorentz_dic = { "Doc" : "Lorentzian Peak Function", "Exp" : "y = y0 + 2*a/pi * w / (4 * (x - x0)**2 + w**2)", "Par" : ("x0", "y0", "a", "w"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_lorentz } fit_boltzman_dic = { "Doc" : "Boltzman Function: sigmoidal curve", "Exp" : "y = (a1 - a2)/(1 + exp((x - x0)/dx)) + a2", "Par" : ("x0", "a1", "a2", "dx"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_boltzman } fit_logistic_dic = { "Doc" : "Logistic dose/response", "Exp" : "y = (a1 - a2)/(1 + (x/x0)**p) + a2", "Par" : ("x0", "a1", "a2", "p"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_logistic } fit_expdecay_dic = { "Doc" : "Exponential Decay", "Exp" : "y = y0 + a * exp(-(x - x0)/t)", "Par" : ("x0", "y0", "a", "t"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_expdecay } fit_expgrow_dic = { "Doc" : "Exponential Growth", "Exp" : "y = y0 + a * exp((x - x0)/t)", "Par" : ("x0", "y0", "a", "t"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_expgrow } fit_expassoc_dic = { "Doc" : "Exponential Associate", "Exp" : "y = y0 + a1 * (1 + exp(-x/t1)) + a2 * (1 + exp(-x/t2))", "Par" : ("y0", "a1", "t1", "a2", "t2"), "NumPar" : 5, "IVar" : "x", "DVar" : "y", "Function" : fit_expassoc } fit_hyperbl_dic = { "Doc" : "Hyperbola Function", "Exp" : "y = p1 * x/ (p2 + x)", "Par" : ("p1", "p2"), "NumPar" : 2, "IVar" : "x", "DVar" : "y", "Function" : fit_hyperbl } fit_pulse_dic = { "Doc" : "Pulse Function", "Exp" : "y = y0 + a * (1 + exp(-(x - x0)/t1)) * exp(-(x - x0)/t2)", "Par" : ("y0", "a", "t1", "t2"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_pulse } fit_rational0_dic = { "Doc" : "Rational Function , type 0", "Exp" : "y = (b + c*x)/(1 + a*x)", "Par" : ("a", "b", "c"), "NumPar" : 3, "IVar" : "x", "DVar" : "y", "Function" : fit_rational0 } fit_sine_dic = { "Doc" : "Sine Function", "Exp" : "y = a * sin(pi*(x - x0)/w)", "Par" : ("a", "x0", "w"), "NumPar" : 3, "IVar" : "x", "DVar" : "y", "Function" : fit_sine } fit_gaussamp_dic = { "Doc" : "Amplitude version of Gaussian Peak Function", "Exp" : "y = y0 + a * exp(-(x - x0)**2/(2*w**2))", "Par" : ("x0", "y0", "a", "w"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_gaussamp } fit_allometric_dic = { "Doc" : "Classical Freundlich Model", "Exp" : "y = a * x**b", "Par" : ("a", "b"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_allometric } functions = { "Linear" : fit_linear_dic, "Cuadratic" : fit_cuadratic_dic, "Gauss" : fit_gauss_dic, "Lorentz" : fit_lorentz_dic, "Boltzman" : fit_boltzman_dic, "Logistic" : fit_logistic_dic, "ExpDecay" : fit_expdecay_dic, "ExpGrow" : fit_expgrow_dic, "ExpAssoc" : fit_expassoc_dic, "Hyperbl" : fit_hyperbl_dic, "Pulse" : fit_pulse_dic, "Rational0" : fit_rational0_dic, "Sine" : fit_sine_dic, "GaussAmp" : fit_gaussamp_dic, "Allometric" : fit_allometric_dic } def fit(data): main_window = GtkWindow() main_window.set_title("Curve Fitting") main_window.set_border_width(5) main_window.connect("destroy", mainquit) main_window.connect("delete_event", mainquit) main_box = GtkVBox(FALSE, 5) main_window.add(main_box) main_frame = GtkFrame("Select Function") main_box.pack_start(main_frame) table = GtkTable(7, 4, FALSE) table.set_col_spacings(10) table.set_row_spacings(5) table.set_border_width(5) main_frame.add(table) swindow = GtkScrolledWindow() swindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) swindow.set_usize(120, 100) table.attach(swindow, 0, 1, 0, 6) clist = GtkCList(1) swindow.add(clist) table.attach(GtkVSeparator(), 1, 2, 0, 6) text = map(lambda i: str(i), range(20)) k = functions.keys() k.sort() for i in k: text[0] = i clist.append(text) label = GtkLabel("Exp:") label.set_alignment(1., .5) table.attach(label, 2, 3, 0, 1) fentry = GtkEntry() # fentry.set_editable(FALSE) table.attach(fentry, 3, 4, 0, 1) label = GtkLabel("Number of Param:") label.set_alignment(1., .5) table.attach(label, 2, 3, 1, 2) nspin = GtkSpinButton(GtkAdjustment(0, 0, 8, 1, 8, 0), 0, 0) nspin.set_editable(FALSE) nspin.set_state(STATE_INSENSITIVE) table.attach(nspin, 3, 4, 1, 2) label = GtkLabel("Param:") label.set_alignment(1., .5) table.attach(label, 2, 3, 2, 3) pentry = GtkEntry() pentry.set_editable(FALSE) pentry.set_state(STATE_INSENSITIVE) table.attach(pentry, 3, 4, 2, 3) label = GtkLabel("Independent Var:") label.set_alignment(1., .5) table.attach(label, 2, 3, 3, 4) iventry = GtkEntry() iventry.set_editable(FALSE) iventry.set_state(STATE_INSENSITIVE) table.attach(iventry, 3, 4, 3, 4) label = GtkLabel("Dependent Var:") label.set_alignment(1., .5) table.attach(label, 2, 3, 4, 5) dventry = GtkEntry() dventry.set_editable(FALSE) dventry.set_state(STATE_INSENSITIVE) table.attach(dventry, 3, 4, 4, 5) action_area = GtkHButtonBox() action_area.set_layout(BUTTONBOX_END) action_area.set_spacing(5) main_box.pack_start(action_area) fit_button = GtkButton("Fit") action_area.pack_start(fit_button) close_button = GtkButton("Close") action_area.pack_start(close_button) lframe = GtkFrame() lframe.set_shadow_type(SHADOW_IN) main_box.pack_start(lframe) explabel = GtkLabel("Choose a Fitting Function") lframe.add(explabel) # CALLBACK FUNCTIONS def select_function(_clist, row, col, event, functions = functions, label = explabel, fentry = fentry, pentry = pentry, nspin = nspin, iventry = iventry, dventry = dventry): k = _clist.get_text(row, col) f = functions[k] label.set_text(f["Doc"]) fentry.set_text(f["Exp"]) nspin.set_value(f["NumPar"]) iventry.set_text(f["IVar"]) dventry.set_text(f["DVar"]) s = "" for i in f["Par"]: s = s + i + ", " pentry.set_text(s[:len(s)-2]) def open_fit_dialog(_button, functions = functions, clist = clist, data = data): a = clist.__getattr__("selection") k = clist.get_text(a[0], 0) f = functions[k] param = (1, 1) fit_dialog(f, data) # CONNECT OBJECTS clist.connect("select_row", select_function) fit_button.connect("clicked", open_fit_dialog) close_button.connect("clicked", main_window.destroy) clist.select_row(0, 0) main_window.show_all() mainloop() def fit_dialog(f, data): main_window = GtkWindow() main_window.set_title("Fit") main_window.set_border_width(5) main_window.connect("destroy", mainquit) main_window.connect("delete_event", mainquit) table = GtkTable(len(f["Par"])+3, 2, FALSE) table.set_col_spacings(10) table.set_row_spacings(5) main_window.add(table) table.attach(GtkLabel("Variable"), 0, 1, 0, 1) table.attach(GtkLabel("Value"), 1, 2, 0, 1) table.attach(GtkHSeparator(), 0, 2, 1, 2) r = 2 entries = [] for i in f["Par"]: # check = GtkCheckButton(i+":") # table.attach(check, 0, 1, r, r+1) table.attach(GtkLabel(i+":"), 0, 1, r, r+1) entry = GtkEntry() entries = entries + [entry] entry.set_text("0.0") table.attach(entry, 1, 2, r, r+1) r = r + 1 table.attach(GtkHSeparator(), 0, 2, r, r + 1) r = r + 1 table.attach(GtkLabel("Chi_Sqr:"), 0, 1, r, r + 1) err_entry = GtkEntry() table.attach(err_entry, 1, 2, r, r + 1) r = r + 1 table.attach(GtkHSeparator(), 0, 2, r, r + 1) def run_fit(_button, f = f, data = data, entries = entries, err_entry = err_entry): n = 0 p = () for i in entries: s = entries[n].get_text() p = p + (atof(s),) n = n + 1 fit, error = leastSquaresFit(f["Function"], p, data) n = 0 for i in entries: entries[n].set_text(str(fit[n])) n = n + 1 err_entry.set_text(str(error)) # print "Fitted parameters: ", fit # print "Fit error: ", error return action_area = GtkHButtonBox() action_area.set_layout(BUTTONBOX_SPREAD) action_area.set_spacing(5) run_button = GtkButton("Run") close_button = GtkButton("Close") action_area.pack_start(run_button) action_area.pack_start(close_button) table.attach(action_area, 0, 2, r + 1, r + 2) # CONNECT OBJECTS run_button.connect("clicked", run_fit) close_button.connect("clicked", main_window.destroy) main_window.show_all() mainloop() # Test for linear fit: # # from gtkLeastSquares import * # data = [ (0., 0.), (1., 1.1), (2., 1.98), (3., 3.05) ] # fit(data) From feiguin at magnet.fsu.edu Mon Jul 2 17:43:23 2001 From: feiguin at magnet.fsu.edu (Adrian Feiguin) Date: Mon, 2 Jul 2001 17:43:23 -0400 (EDT) Subject: [Numpy-discussion] ANNOUNCE: SciGraphica-0.7.0 Message-ID: I'm pleased to announce the new release of Scigraphica with bugfixes and enhancements. Among other things, embedding images is now possible, as well as setting background images for the plots. Clipboard for plots: copy a plot, and paste it on a different plot window. Improved PostScript and WYSIWYG. It includes pysga.py, a Python module for interacting with plots and worksheets from terminal. New scheme for storing numerical data in worksheets. Examples are included. Scigraphica is a powerful tool for scientific graphics and data analysis. It pretends to be a clone of the popular commercial (and expensive) application "Microcal Origin". It fully supplies plotting features for 2D, 3D and polar charts. The aim is to obtain a fully-featured, cross-plattform, user-friendly, self-growing scientific application. It is free and open-source, released under the GPL license. Main features: -You can plot functions and manipulate data in worksheets. -You can open several worksheets and plots and work with them at the same time. -The plots are fully configurable using a control panel dialog. -The look and feel is completely WYSIWYG. -Publication quality PostScript output. -You can interact with the plots double-clicking, dragging and moving objects with the mouse. -Export/Import features in XML format. -You can insert Python expressions in the worksheets. -Terminal with command-line Python interface for interacting with plots and worksheets URL: http://scigraphica.sourceforge.net Enjoy! The SciGraphica Team.- ------------------------------------------------------------------------ TODO for sg-0.8.0: sg-0.8.0 will have a completely different structure, more modular, built ontop of reusable libraries. SGplot, SGworksheet, SGlayer, and SGdataset will be GtkWidgets and part of a shareable library, that could be used by other applications, and from Python. From jochen at unc.edu Tue Jul 3 10:14:24 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 03 Jul 2001 10:14:24 -0400 Subject: [Numpy-discussion] Numpy on Cygwin Message-ID: <86d77iyu9r.fsf@bock.chem.unc.edu> Dear All, I have had some problems with Cannot export _bss_end__: symbol not defined messages and friends again for the cvs Numerical Python package. Although the LAPACK-module uses the DL_EXPORT approach and works fine, the other packages apparently try the .def-approach (which I barely heard about); this packages do not build for me on latest Cygwin. (I have not tried it on older ones.) Putting DL_EXPORTs around all the init-functions fixes this for me: Index: Packages/FFT/Src/fftpackmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Packages/FFT/Src/fftpackmodule.c,v retrieving revision 1.1 diff -u -r1.1 fftpackmodule.c --- Packages/FFT/Src/fftpackmodule.c 2000/07/06 16:54:16 1.1 +++ Packages/FFT/Src/fftpackmodule.c 2001/07/03 14:06:48 @@ -238,7 +238,7 @@ "" ; -void +DL_EXPORT(void) initfftpack() { PyObject *m, *d; Index: Packages/RNG/Src/RNGmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Packages/RNG/Src/RNGmodule.c,v retrieving revision 1.1 diff -u -r1.1 RNGmodule.c --- Packages/RNG/Src/RNGmodule.c 2000/07/06 16:54:17 1.1 +++ Packages/RNG/Src/RNGmodule.c 2001/07/03 14:06:49 @@ -613,7 +613,7 @@ "Random number generator: independent random number streams." ; -void +DL_EXPORT(void) initRNG() { PyObject *m, *d; Index: Packages/kinds/Src/_kindsmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Packages/kinds/Src/_kindsmodule.c,v retrieving revision 1.1 diff -u -r1.1 _kindsmodule.c --- Packages/kinds/Src/_kindsmodule.c 2001/04/17 23:35:10 1.1 +++ Packages/kinds/Src/_kindsmodule.c 2001/07/03 14:06:49 @@ -10,7 +10,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void +DL_EXPORT(void) init_kinds() { PyObject *m, *d; Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From paul at pfdubois.com Mon Jul 9 13:57:50 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Mon, 9 Jul 2001 10:57:50 -0700 Subject: [Numpy-discussion] Cannot reply to some questions Message-ID: I receive a steady stream of questions sent to me about Numerical Python. Frequently, in their zeal to protect themselves from spam, the senders obscure their sending address. This causes my reply to bounce. I sometimes drop the ball and fail to reply promptly due to the volume of letters I receive, advancing senility, or because the question requires research and it goes onto my stack for too long. But before you conclude that I'm not answering you because of ineptitude, please be sure I *can* answer your mail with a simple reply. Thanks, Paul From paul at pfdubois.com Mon Jul 9 14:01:35 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Mon, 9 Jul 2001 11:01:35 -0700 Subject: [Numpy-discussion] MA : assignment to slices doesn't work like Numeric. In-Reply-To: <3B3BB29D.A932FF05@atd.ucar.edu> Message-ID: It is an advertised difference between MA and Numeric that index operations return copies, not references. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Joe Van Andel Sent: Thursday, June 28, 2001 3:42 PM To: numpy-discussion Subject: [Numpy-discussion] MA : assignment to slices doesn't work like Numeric. I retrieved the latest MA from CVS. I've noticed that assigning to a slice doesn't work the same as Numeric. Here's a simple test program: -------------------------------- from MA import * #from Numeric import * numBeams,numGates = (5,4) result = ones((numBeams, numGates),'f') * -327.68 print 'result = ', result t1 = ones((numGates,),'f') t2 = 2* ones((numGates,),'f') result[0] = t1 result[1][:] = t2 print 'result = ', result ----------------------------------------- Output using 'MA': result = [[-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,]] result = [[ 1. , 1. , 1. , 1. ,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,]] However, if I use Numeric, rather than MA, I get: result = [[-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68]] result = [[ 1. 1. 1. 1. ] [ 2. 2. 2. 2. ] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68]] So, a[x][:] = my_array doesn't seem to work using 'MA'. -- Joe VanAndel National Center for Atmospheric Research http://www.atd.ucar.edu/~vanandel/ Internet: vanandel at ucar.edu _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From nwagner at isd.uni-stuttgart.de Tue Jul 10 05:52:41 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Tue, 10 Jul 2001 11:52:41 +0200 Subject: [Numpy-discussion] Wishlist for Numpy Message-ID: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> Hi, Is there any wish-list of projects and feature requests for Numpy ? I would appreciate it, if Numpy could handle the following functions : 1. Fix eig to also be able to solve the generalized eigenvalue problem and polynomial eigenvalue problems 2. Support for matrix functions like logm, expm, sqrtm 3. Wavelet transform 4. Solver for ODE's and DAE's Nils Wagner From phrxy at csv.warwick.ac.uk Tue Jul 10 10:56:02 2001 From: phrxy at csv.warwick.ac.uk (John J. Lee) Date: Tue, 10 Jul 2001 15:56:02 +0100 (BST) Subject: [Numpy-discussion] Wishlist for Numpy In-Reply-To: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> Message-ID: On Tue, 10 Jul 2001, Nils Wagner wrote: [...] > I would appreciate it, if Numpy could handle the following functions : [...] > 2. Support for matrix functions like logm, expm, sqrtm [...] What do you mean by 'matrix functions'? John From hinsen at cnrs-orleans.fr Tue Jul 10 10:54:07 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Tue, 10 Jul 2001 16:54:07 +0200 Subject: [Numpy-discussion] Wishlist for Numpy In-Reply-To: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> (message from Nils Wagner on Tue, 10 Jul 2001 11:52:41 +0200) References: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> Message-ID: <200107101454.QAA08105@chinon.cnrs-orleans.fr> > I would appreciate it, if Numpy could handle the following functions : > > 1. Fix eig to also be able to solve the generalized eigenvalue problem > and polynomial eigenvalue problems That would be a relatively simple addition to LinearAlgebra, but would also require some additional routines from LAPACK. > 2. Support for matrix functions like logm, expm, sqrtm That can be done in Python code. > 3. Wavelet transform For efficiency, that should be done in C/Fortran. Are there any wavelet libraries out there? Anyway, this should become a separate package. > 4. Solver for ODE's and DAE's Given the variety of equations and solvers, this looks like a big project. Good Python integration is also not trivial. So that's not only a separate package, but even a major one. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From nwagner at isd.uni-stuttgart.de Tue Jul 10 10:13:53 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Tue, 10 Jul 2001 16:13:53 +0200 Subject: [Numpy-discussion] Wishlist for Numpy References: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> <200107101454.QAA08105@chinon.cnrs-orleans.fr> Message-ID: <3B4B0DA1.DD9575EC@isd.uni-stuttgart.de> Konrad Hinsen schrieb: > > I would appreciate it, if Numpy could handle the following functions : > > > > 1. Fix eig to also be able to solve the generalized eigenvalue problem > > and polynomial eigenvalue problems > > That would be a relatively simple addition to LinearAlgebra, but > would also require some additional routines from LAPACK. > > > 2. Support for matrix functions like logm, expm, sqrtm > > That can be done in Python code. > > > 3. Wavelet transform > > For efficiency, that should be done in C/Fortran. Are there any wavelet > libraries out there? Anyway, this should become a separate package. > > > 4. Solver for ODE's and DAE's > > Given the variety of equations and solvers, this looks like a big > project. Good Python integration is also not trivial. So that's not > only a separate package, but even a major one. > > Konrad. > -- > ------------------------------------------------------------------------------- > Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr > Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 > Rue Charles Sadron | Fax: +33-2.38.63.15.17 > 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ > France | Nederlands/Francais > ------------------------------------------------------------------------------- Is there any intention for inclusion of the missing functions in future releases of Numpy ? Nils. From hinsen at cnrs-orleans.fr Tue Jul 10 14:52:21 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Tue, 10 Jul 2001 20:52:21 +0200 Subject: [Numpy-discussion] Wishlist for Numpy In-Reply-To: <3B4B0DA1.DD9575EC@isd.uni-stuttgart.de> (message from Nils Wagner on Tue, 10 Jul 2001 16:13:53 +0200) References: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> <200107101454.QAA08105@chinon.cnrs-orleans.fr> <3B4B0DA1.DD9575EC@isd.uni-stuttgart.de> Message-ID: <200107101852.UAA08996@chinon.cnrs-orleans.fr> > Is there any intention for inclusion of the missing functions in > future releases of Numpy ? Usually code submissions are gratefully accepted. But I am not aware of anyone working on any of these topics at the moment. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From paul at pfdubois.com Tue Jul 10 16:01:19 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 10 Jul 2001 13:01:19 -0700 Subject: [Numpy-discussion] Release 20.1 Message-ID: Release 20.1 is available for your dining pleasure. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: changes.txt URL: From jochen at unc.edu Tue Jul 17 15:17:39 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 17 Jul 2001 15:17:39 -0400 Subject: [Numpy-discussion] Cygwin Message-ID: <8666crfjqk.fsf@bock.chem.unc.edu> Another little patch needed for NumPy as of today to compile on Cygwin: Index: Src/fastumathmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v retrieving revision 1.1 diff -u -r1.1 fastumathmodule.c --- Src/fastumathmodule.c 2001/07/16 23:19:23 1.1 +++ Src/fastumathmodule.c 2001/07/17 19:16:39 @@ -2123,7 +2123,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void initfastumath() { +DL_EXPORT(void) initfastumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From paul at pfdubois.com Tue Jul 17 15:53:52 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 17 Jul 2001 12:53:52 -0700 Subject: [Numpy-discussion] Cygwin In-Reply-To: <8666crfjqk.fsf@bock.chem.unc.edu> Message-ID: This file is no longer in the distribution. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Jochen K?pper Sent: Tuesday, July 17, 2001 12:18 PM To: Numpy Discussion Subject: [Numpy-discussion] Cygwin Another little patch needed for NumPy as of today to compile on Cygwin: Index: Src/fastumathmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v retrieving revision 1.1 diff -u -r1.1 fastumathmodule.c --- Src/fastumathmodule.c 2001/07/16 23:19:23 1.1 +++ Src/fastumathmodule.c 2001/07/17 19:16:39 @@ -2123,7 +2123,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void initfastumath() { +DL_EXPORT(void) initfastumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From jochen at unc.edu Tue Jul 17 16:30:53 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 17 Jul 2001 16:30:53 -0400 Subject: [Numpy-discussion] Cygwin In-Reply-To: References: Message-ID: <86zoa3e1s2.fsf@bock.chem.unc.edu> >>>>> Paul F Dubois wrote on Tue, 17 Jul 2001 12:53:52 -0700: Paul> This file is no longer in the distribution. Uhm, what am I doing wrong? cvs up && cvs stat -v Src/fastumathmodule.c =================================================================== File: fastumathmodule.c Status: Locally Modified Working revision: 1.1 Repository revision: 1.1 /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v Sticky Tag: (none) Sticky Date: (none) Sticky Options: (none) Existing Tags: No Tags Exist Paul> -----Original Message----- Paul> Another little patch needed for NumPy as of today to compile on Paul> Cygwin: Paul> Index: Src/fastumathmodule.c Paul> =================================================================== Paul> RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v Greetings, Jochen -- University of North Carolina phone: 919-962-4403 Department of Chemistry phone: 919-962-1579 Venable Hall CB#3290 fax: 919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From nwagner at isd.uni-stuttgart.de Wed Jul 18 07:10:05 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 18 Jul 2001 13:10:05 +0200 Subject: [Numpy-discussion] Kronecker product Message-ID: <3B556E8D.D485CB98@isd.uni-stuttgart.de> Hi, I would appreciate it, if Numpy could handle the Kronecker-product of two matrices X, Y. kron(X,Y) is the Kronecker tensor product of X and Y. The result is a large matrix formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. Nils From paul at pfdubois.com Wed Jul 18 10:40:41 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Wed, 18 Jul 2001 07:40:41 -0700 Subject: [Numpy-discussion] Kronecker product In-Reply-To: <3B556E8D.D485CB98@isd.uni-stuttgart.de> Message-ID: Using the outer product you get a matrix that has the right size and contents but it is m*n by p*q Was that a misprint in your post? >>> x array([1, 2, 3, 4, 5, 6]) >>> x.shape=(3,2) >>> y = 10*transpose(x) >>> y array([[10, 30, 50], [20, 40, 60]]) >>> z = outerproduct(x.flat, y.flat) >>> z array([[ 10, 30, 50, 20, 40, 60], [ 20, 60, 100, 40, 80, 120], [ 30, 90, 150, 60, 120, 180], [ 40, 120, 200, 80, 160, 240], [ 50, 150, 250, 100, 200, 300], [ 60, 180, 300, 120, 240, 360]]) >>> -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Nils Wagner Sent: Wednesday, July 18, 2001 4:10 AM To: numpy-discussion at lists.sourceforge.net Subject: [Numpy-discussion] Kronecker product Hi, I would appreciate it, if Numpy could handle the Kronecker-product of two matrices X, Y. kron(X,Y) is the Kronecker tensor product of X and Y. The result is a large matrix formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. Nils _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From nwagner at isd.uni-stuttgart.de Wed Jul 18 09:55:55 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 18 Jul 2001 15:55:55 +0200 Subject: [Numpy-discussion] Kronecker product References: Message-ID: <3B55956B.B01DDC19@isd.uni-stuttgart.de> "Paul F. Dubois" schrieb: > Using the outer product you get a matrix that has the right size and > contents but it is m*n by p*q > Was that a misprint in your post? > >>> x > array([1, 2, 3, 4, 5, 6]) > >>> x.shape=(3,2) > >>> y = 10*transpose(x) > >>> y > array([[10, 30, 50], > [20, 40, 60]]) > >>> z = outerproduct(x.flat, y.flat) > >>> z > array([[ 10, 30, 50, 20, 40, 60], > [ 20, 60, 100, 40, 80, 120], > [ 30, 90, 150, 60, 120, 180], > [ 40, 120, 200, 80, 160, 240], > [ 50, 150, 250, 100, 200, 300], > [ 60, 180, 300, 120, 240, 360]]) > >>> > > -----Original Message----- > From: numpy-discussion-admin at lists.sourceforge.net > [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Nils > Wagner > Sent: Wednesday, July 18, 2001 4:10 AM > To: numpy-discussion at lists.sourceforge.net > Subject: [Numpy-discussion] Kronecker product > > Hi, > > I would appreciate it, if Numpy could handle the Kronecker-product of > two matrices X, Y. > > kron(X,Y) is the Kronecker tensor product of X and Y. > The result is a large matrix formed by taking all possible products > between the elements of X and those of Y. If X is m-by-n > and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. > > Nils > > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > http://lists.sourceforge.net/lists/listinfo/numpy-discussion >>> a > array([[1, 2], > [3, 4]]) > >>> b > array([[11, 12], > [13, 14]]) > >>> outerproduct(a,b) > array([[11, 12, 13, 14], > [22, 24, 26, 28], > [33, 36, 39, 42], > [44, 48, 52, 56]]) The Kronecker product applied to A,B is kron(A,B) = array([[11,12,22,24], [13,14,26,28], [33,36,44,48], [39,42,52,56]]) How can I rearrange the result of outerproduct to the result of Kronecker product with numpy ? Cheers, Nils From cgw at alum.mit.edu Wed Jul 18 11:07:07 2001 From: cgw at alum.mit.edu (Charles G Waldman) Date: Wed, 18 Jul 2001 10:07:07 -0500 Subject: [Numpy-discussion] Kronecker product In-Reply-To: <3B5580B1.186F375B@isd.uni-stuttgart.de> References: <3B556E8D.D485CB98@isd.uni-stuttgart.de> <15189.35598.403100.520462@sirius.net.home> <3B5580B1.186F375B@isd.uni-stuttgart.de> Message-ID: <15189.42523.133794.26662@transamoeba.dyndns.org> Nils Wagner writes: > > How can I rearrange the result of outerproduct to the result of > Kronecker product with numpy ? > def kron(a,b): o = outerproduct(a,b) o.shape = a.shape + b.shape return concatenate(concatenate(o, axis=1), axis=1) From hinsen at cnrs-orleans.fr Wed Jul 18 11:20:20 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Wed, 18 Jul 2001 17:20:20 +0200 Subject: [Numpy-discussion] Kronecker product In-Reply-To: <3B556E8D.D485CB98@isd.uni-stuttgart.de> (message from Nils Wagner on Wed, 18 Jul 2001 13:10:05 +0200) References: <3B556E8D.D485CB98@isd.uni-stuttgart.de> Message-ID: <200107181520.RAA05268@chinon.cnrs-orleans.fr> > I would appreciate it, if Numpy could handle the Kronecker-product of > two matrices X, Y. > > kron(X,Y) is the Kronecker tensor product of X and Y. import Numeric def kron(x, y): return Numeric.multiply.outer(x, y) > The result is a large matrix formed by taking all possible products > between the elements of X and those of Y. If X is m-by-n > and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. OK, there's one difference: the function shown about returns an array of shape (m, n, p, q). If the input arrays are always 2D, the following will do what you need: import Numeric def kron(x, y): z = Numeric.transpose(Numeric.multiply.outer(x, y), [0, 2, 1, 3]) z.shape = (z.shape[0]*z.shape[1], z.shape[2]*z.shape[3]) return z Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From bowman at acsu.buffalo.edu Wed Jul 18 18:34:10 2001 From: bowman at acsu.buffalo.edu (Charles L. Bowman, Ph.D.) Date: Wed, 18 Jul 2001 18:34:10 -0400 Subject: [Numpy-discussion] Re: Problem running Numeric-20.1 installer on NT4,SP3 Message-ID: <3B560EE2.19655A2E@acsu.buffalo.edu> Hello, I have python2.1.1c1 in I:\python21. It's up and running OK. I downloaded Numeric-20.1.0.win32-py2.1.exe, placed it in I:\python21, opened up a DOS window and ran the installer. The desktop flickered *very* briefly. Import Numeric returns "No module named Numeric". I cannot find any files named numeric.py. Does the installer assume python2.1 is in C:\python21? If so, how can I pass the correct drive information to the installer? Thanks for your help. Charles Bowman From nwagner at isd.uni-stuttgart.de Thu Jul 19 03:16:42 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Thu, 19 Jul 2001 09:16:42 +0200 Subject: [Numpy-discussion] Kronecker product References: <3B556E8D.D485CB98@isd.uni-stuttgart.de> <15189.35598.403100.520462@sirius.net.home> <3B5580B1.186F375B@isd.uni-stuttgart.de> <15189.42523.133794.26662@transamoeba.dyndns.org> Message-ID: <3B56895A.E653095C@isd.uni-stuttgart.de> Charles G Waldman schrieb: > Nils Wagner writes: > > > > How can I rearrange the result of outerproduct to the result of > > Kronecker product with numpy ? > > > > def kron(a,b): > o = outerproduct(a,b) > o.shape = a.shape + b.shape > return concatenate(concatenate(o, axis=1), axis=1) What is the difference between kron(z,eye) and kron(yt,eye) ? Nils -------------- next part -------------- from Numeric import * def kron(a,b): o = outerproduct(a,b) o.shape = a.shape + b.shape return concatenate(concatenate(o, axis=1), axis=1) y = array(([5,6,7],[8,9,10])) print 'y' print print y print z = array(([5,8],[6,9],[7,10])) print 'z' print print z print yt = transpose(y) print 'yt' print print yt print eye = identity(2) a = kron(y,eye) print print 'kron(y,eye)' print print a print b = kron(z,eye) print print 'kron(z,eye)' print print b print c = kron(yt,eye) print print c print From chrishbarker at home.net Thu Jul 19 20:28:14 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 19 Jul 2001 17:28:14 -0700 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? References: Message-ID: <3B577B1E.EC592447@home.net> Hi all, I am using a 2-d array to store values that will be an index into a list. It is huge, sot to samve space I have used a type Int16. Now when I pull a value outl it is of type array, so it can not be used to index a sequence. The strange thing is that it works if the array is of rank 1. Some tests: >>> from Numeric import * >>> >>> l = range(10) # a test list >>> a = arange(10) # an array if Ints >>> print type(a[3]) #So this is an Int >>> print l[a[3]] 3 # and it can be used as an index. >>> a.shape = (2,5) #reshape it to be rank-2 >>> print type(a[1,3]) # still and Int >>> print l[a[1,3]] 8 # and still usable as an index. # now change the type >>> a = a.astype(Int16) >>> a.shape = (10,) >>> print type(a[3]) #it's an Int >>> a.shape = (2,5) # now change the shape to rank-2 >>> print type(a[1,3]) #!!!!!!!#### # Now a single item is of type 'array' >>> print l[a[1,3]] Traceback (most recent call last): File "", line 1, in ? TypeError: sequence index must be integer # and it can not be used as an index! I can work around this with an explicite type cast with int(), but it seems like wierd behaviour to me. I am accesing a single item, it is typcaste as an Int when the item is pulled out of a rank-1 array, but it is a rank-0 array when pulled from a rank > 1 array. Any ideas what causes this? Is there a good reson for htis, or is it a bug? -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From viennet at lipn.univ-paris13.fr Fri Jul 20 03:11:31 2001 From: viennet at lipn.univ-paris13.fr (Emmanuel Viennet) Date: Fri, 20 Jul 2001 09:11:31 +0200 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? References: <3B577B1E.EC592447@home.net> Message-ID: <3B57D9A3.C5D396F@lipn.univ-paris13.fr> Feature, I think. a[1,3] is a rank-0 array, with typecode Int16. There is no other way to handle a Int16 scalar in Python (Int16 is not a python type). This solution allows to correctly propagate the types in array arithmetic, without unwanted upcasts. Emmanuel Chris Barker wrote: > # now change the type > >>> a = a.astype(Int16) > >>> a.shape = (10,) > >>> print type(a[3]) > > #it's an Int > > >>> a.shape = (2,5) > # now change the shape to rank-2 > > >>> print type(a[1,3]) > > >>> print a[0,0].typecode() 's' # == Int16 >>> a[0,0].shape () # rank-0 array From hinsen at cnrs-orleans.fr Fri Jul 20 08:28:35 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Fri, 20 Jul 2001 14:28:35 +0200 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? In-Reply-To: <3B57D9A3.C5D396F@lipn.univ-paris13.fr> (message from Emmanuel Viennet on Fri, 20 Jul 2001 09:11:31 +0200) References: <3B577B1E.EC592447@home.net> <3B57D9A3.C5D396F@lipn.univ-paris13.fr> Message-ID: <200107201228.OAA07664@chinon.cnrs-orleans.fr> > Feature, I think. Right, but a relatively recent one. In the first NumPy releases, the result was a scalar Integer object. There are good arguments for both variants. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From Peter.Bienstman at rug.ac.be Fri Jul 20 11:03:59 2001 From: Peter.Bienstman at rug.ac.be (Peter Bienstman) Date: Fri, 20 Jul 2001 17:03:59 +0200 Subject: [Numpy-discussion] suggested doc improvement: C API, fortran arrays Message-ID: <003b01c1112d$346fb0a0$0454c19d@intec.rug.ac.be> Hi, In chapter 14 of the docs (Writing a C extension to NumPy), the last section (a less simple example) deals with mixing Fortran and C code. Wouldn't it be useful to mention the topic of different storage orders there, and to reflect this in the code by swapping some stride parameters? Could avoid a lot of frustration... Peter ------------------------------------- Peter Bienstman Department of Information Technology INTEC/IMEC - Ghent University St.-Pietersnieuwstraat 41 B-9000 Gent - Belgium E-mail: Peter.Bienstman at rug.ac.be Tel: +32 9 264 3445 Fax: +32 9 264 3593 ------------------------------------- From chrishbarker at home.net Fri Jul 20 14:48:22 2001 From: chrishbarker at home.net (Chris Barker) Date: Fri, 20 Jul 2001 11:48:22 -0700 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? References: <3B577B1E.EC592447@home.net> <3B57D9A3.C5D396F@lipn.univ-paris13.fr> <200107201228.OAA07664@chinon.cnrs-orleans.fr> Message-ID: <3B587CF6.E5CD54F8@home.net> Konrad Hinsen wrote: > > > Feature, I think. > > Right, but a relatively recent one. In the first NumPy releases, the > result was a scalar Integer object. There are good arguments for both > variants. OK. I see that there are trade-offs either way, and I certainly see the benefit of keeping the precision consistent(even though it would be easier in this case to have th upcast). I do think it's a bug, however, to have the upcast when pulling a single value out of a 1-d array, but not when pulling it out of a higher rank array: >>> a = array(((1,2,3),(4,5,6)),Int16) >>> type(a[1,1]) >>> a.shape = (6,) >>> type(a[2]) >>> This seems totally inconsistant. Note that this same effect occurs for arrays of type Float16 (and probably others) By the way, would it be at all possible for Python to accept an array of rank 0 as an index? How big a change would that be? -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From jochen at unc.edu Fri Jul 20 16:05:21 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 Jul 2001 16:05:21 -0400 Subject: [Numpy-discussion] Cygwin In-Reply-To: References: Message-ID: <8666cnqsce.fsf@bock.chem.unc.edu> >>>>> Paul F Dubois wrote on Tue, 17 Jul 2001 12:53:52 -0700: [patch to Src/fastumathmodule.c] Paul> This file is no longer in the distribution. So why was it changed today? > cvs log Src/fastumathmodule.c ,---- | RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v | Working file: Src/fastumathmodule.c | head: 1.2 | branch: | locks: strict | access list: | symbolic names: | keyword substitution: kv | total revisions: 2; selected revisions: 2 | description: | ---------------------------- | revision 1.2 | date: 2001/07/20 03:24:33; author: teoliphant; state: Exp; lines: +18 -0 | Added inverse hyperbolic functions. | ---------------------------- | revision 1.1 | date: 2001/07/16 23:19:23; author: teoliphant; state: Exp; | Added fastumathmodule which doesn't emit exceptions. | ============================================================================= `---- To get that straight: I am looking at the Repository "Numerical" at :pserver:anonymous at cvs.numpy.sourceforge.net:/cvsroot/numpy I hope that is the correct module for an uptodate version of NumPy. If so, I would suggest the following patch to have it link successfully on Cygwin: Index: Src/fastumathmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v retrieving revision 1.2 diff -u -r1.2 fastumathmodule.c --- Src/fastumathmodule.c 2001/07/20 03:24:33 1.2 +++ Src/fastumathmodule.c 2001/07/20 20:01:33 @@ -2141,7 +2141,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void initfastumath() { +DL_EXPORT(void) initfastumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ Thanks, Jochen -- University of North Carolina phone: 919-962-4403 Department of Chemistry phone: 919-962-1579 Venable Hall CB#3290 fax: 919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From romberg at fsl.noaa.gov Fri Jul 20 18:02:20 2001 From: romberg at fsl.noaa.gov (Mike Romberg) Date: Fri, 20 Jul 2001 16:02:20 -0600 (MDT) Subject: [Numpy-discussion] 20.1.0 undefined symbol: PyArray_API Message-ID: <15192.43628.309241.850260@smaug.fsl.noaa.gov> I have written a python module in C which is implemented as a loadable shared library. My module uses Numeric array objects and includes arrayobject.h. With Numeric-19 this used to work fine. Now my module will not load because the symbol PyArray_API is not found. I located this fellow in the arrayobject header file: /* C API address pointer */ #if defined(NO_IMPORT) || defined(NO_IMPORT_UFUNC) extern void **PyUFunc_API; #else #if defined(PY_UFUNC_UNIQUE_SYMBOL) void **PyUFunc_API; #else static void **PyUFunc_API; #endif So, it seems (at first glance) that this symbol is either static or extern based on the NO_IMPORT macro. My question is, can I just define NO_IMPORT before including arrayobject.h or does Numeric python need to be rebuilt so that this symbol gets exported? Thanks, Mike Romberg (romberg at fsl.noaa.gov) From vanroose at ruca.ua.ac.be Tue Jul 24 07:04:33 2001 From: vanroose at ruca.ua.ac.be (Wim Vanroose) Date: Tue, 24 Jul 2001 13:04:33 +0200 (METDST) Subject: [Numpy-discussion] Troubles with arrays Message-ID: Dear Numerical Python Users, I have a small program that produces array's that I want to import in Python. The code is organised in three files. 1) arraytest.h, 2) arraytest.c 3) testmodule.c. and the code is shown below. The function myTest() produces the array and is called from the test module. However, the program does not work! it crashes. In my opinion, I do not have yet enough insight in Numerical Python. Is there an essential part that I do not understand. Remarkable is that the pure Python equivalent of the program does not crash. Any ideas? Wim Vanroose ///////////////////////// //file: arraytest.h ////////////////////// #include "Python.h" #include "arrayobject.h" PyObject *myTest(void); ////////////////////// // file: arraytest.c //////////////////// #include "arraytest.h" PyObject * myTest(void ){ PyArrayObject *result; double *datainput; int dimensions[1]; int M=10; int MM; dimensions[0]=M; result = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); datainput =(double *)result->data; for(MM=0;MM < M ; MM++){ datainput[MM] = MM*0.1; } return PyArray_Return(result); } //////////////////// //file: test.c CRASHES!!!! //////////////// #include "arraytest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); import_array(); d = PyModule_GetDict(m); } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The Python Equivalent: DOES NOT CRASH %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ///////////// // file: simpletest.h ///////////////// #include "simpletest.h" PyObject * myTest(void); //////////////////// // file: test.c ////////////////////// #include "simpletest.h" PyObject * myTest(void ){ return Py_BuildValue("i",123); } //////////////// //file: test.c ////////////////// #include "simpletest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); d = PyModule_GetDict(m); } From nils.wagner at freenet.de Tue Jul 24 14:58:05 2001 From: nils.wagner at freenet.de (nils.wagner at freenet.de) Date: Tue, 24 Jul 2001 20:58:05 +0200 Subject: [Numpy-discussion] largest matrix element Message-ID: <200107241858.UAA26240@www6.emo.freenet-rz.de> Given a complex Matrix A(m,n) How can I get the absolute value of the largest matrix element very efficiently ? Nils Die sch?nen Seiten des Urlaubs bei Libri.de: Sonnige B?cher portofrei bestellen: http://www.libri.de/content/urlaub.html From cgw at alum.mit.edu Tue Jul 24 15:18:28 2001 From: cgw at alum.mit.edu (Charles G Waldman) Date: Tue, 24 Jul 2001 14:18:28 -0500 Subject: [Numpy-discussion] largest matrix element In-Reply-To: <200107241858.UAA26240@www6.emo.freenet-rz.de> References: <200107241858.UAA26240@www6.emo.freenet-rz.de> Message-ID: <15197.51716.109153.805370@nyx.dyndns.org> nils.wagner at freenet.de writes: > Given a complex Matrix A(m,n) > How can I get the absolute value of the largest matrix element > very efficiently ? How about sqrt(max((asarray(A)*conjugate(asarray(A))).real)) ? From ransom at cfa.harvard.edu Tue Jul 24 15:24:50 2001 From: ransom at cfa.harvard.edu (Scott Ransom) Date: Tue, 24 Jul 2001 15:24:50 -0400 Subject: [Numpy-discussion] largest matrix element References: <200107241858.UAA26240@www6.emo.freenet-rz.de> <15197.51716.109153.805370@nyx.dyndns.org> Message-ID: <3B5DCB82.5ABB343A@cfa.harvard.edu> Charles G Waldman wrote: > > nils.wagner at freenet.de writes: > > Given a complex Matrix A(m,n) > > How can I get the absolute value of the largest matrix element > > very efficiently ? > > How about > > sqrt(max((asarray(A)*conjugate(asarray(A))).real)) I if you want the global maximum you need a ravel in there: sqrt(max(ravel((asarray(a)*conjugate(asarray(a))).real))) Scott -- Scott M. Ransom Address: Harvard-Smithsonian CfA Phone: (617) 496-7908 60 Garden St. MS 10 email: ransom at cfa.harvard.edu Cambridge, MA 02138 GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989 From tim.hochberg at ieee.org Tue Jul 24 15:50:34 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Tue, 24 Jul 2001 12:50:34 -0700 Subject: [Numpy-discussion] largest matrix element References: <200107241858.UAA26240@www6.emo.freenet-rz.de> <15197.51716.109153.805370@nyx.dyndns.org> <3B5DCB82.5ABB343A@cfa.harvard.edu> <093c01c11477$8093acf0$87740918@cx781526b> <3B5DCE14.676B5A23@cfa.harvard.edu> Message-ID: <098c01c1147c$29ebbd20$87740918@cx781526b> Hi Scott, et al. First off I goofed -- that last reply should have gone to the list as a whole. Second, mere seconds after I pushed send I realized one problem with it: 'flat' only works for contiguous arrays. Its probably safer to use ravel after all, unless it's known that the array is contiguous. On the other hand, it would be slightly more efficient to ravel the matrix after taking its absolute value since ravel potentially allocates a new array and an array of Floats is going to be half the size of an array of Complexes. But then we know the resulting array is going to be contiguous. So after rewriting and erasing the thing a few times I end up with: max(abs(a).flat) Which is almost the same as my first one, except that the flat has been moved and now it should work when the array starts out noncontiguous. -tim > Hi Tim, > > Looks good to me! ;) > > Scott > > Tim Hochberg wrote: > > > > ----- Original Message ----- > > From: "Scott Ransom" > > Cc: ; > > Sent: Tuesday, July 24, 2001 12:24 PM > > Subject: Re: [Numpy-discussion] largest matrix element > > > > > Charles G Waldman wrote: > > > > > > > > nils.wagner at freenet.de writes: > > > > > Given a complex Matrix A(m,n) > > > > > How can I get the absolute value of the largest matrix element > > > > > very efficiently ? > > > > > > > > How about > > > > > > > > sqrt(max((asarray(A)*conjugate(asarray(A))).real)) > > > > > > I if you want the global maximum you need a ravel in there: > > > > > > sqrt(max(ravel((asarray(a)*conjugate(asarray(a))).real))) > > > > I must be missing something. What's wrong with: > > > > max(abs(a.flat)) ? > > > > -tim > > -- > Scott M. Ransom Address: Harvard-Smithsonian CfA > Phone: (617) 496-7908 60 Garden St. MS 10 > email: ransom at cfa.harvard.edu Cambridge, MA 02138 > GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989 From nwagner at isd.uni-stuttgart.de Wed Jul 25 04:15:26 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 25 Jul 2001 10:15:26 +0200 Subject: [Numpy-discussion] A question on vector and matrix norms Message-ID: <3B5E801E.97B18C01@isd.uni-stuttgart.de> Hi, I'm interested in efficient implementations of various vector and matrix norms. Please can anyone give me some short examples regarding the following norms for vectors : 1. Frobenius norm 2. L_1 norm is sum of absolute values 3. L_2 norm 4. L_\infty or maximum norm 5. p-norm and matrices: matrix spectral norm or matrix 2-norm Frobenius norm ||A||_F p-norms ||A||_p Thanks in advance. Nils From nwagner at isd.uni-stuttgart.de Wed Jul 25 04:39:36 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 25 Jul 2001 10:39:36 +0200 Subject: [Numpy-discussion] Matrix exponential Message-ID: <3B5E85C8.1817CB30@isd.uni-stuttgart.de> Hi, Has anyone written some functions concerning the matrix exponential expm(A) ? I am looking for demos illustrating the use of Pad? approximation, Taylor series approximation, and eigenvalues and eigenvectors, respectively, to compute the matrix exponential. Thanks in advance. Nils Reference : SIAM Review, Vol. 20 (1979) pp.801-836 Moler, van Loan "Nineteen dubious ways to compute the exponential of a matrix" From nwagner at isd.uni-stuttgart.de Thu Jul 26 10:56:12 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Thu, 26 Jul 2001 16:56:12 +0200 Subject: [Numpy-discussion] vec-operator Message-ID: <3B602F8C.9043A7EF@isd.uni-stuttgart.de> Hi, A matrix operation is that of stacking the columns of a matrix one under the other to form a single column. This operation is called "vec" or "cs" (c)olumn (s)tring Example A is a m * n matrix vec(A) = reshape(transpose(A),(m*n,1)) How can I copy the result of vec(A) into the i-th column of another matrix called B ? Thanks in advance. Nils From tim.hochberg at ieee.org Thu Jul 26 12:35:27 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 26 Jul 2001 09:35:27 -0700 Subject: [Numpy-discussion] vec-operator References: <3B602F8C.9043A7EF@isd.uni-stuttgart.de> Message-ID: <132901c115f0$fa76ab60$87740918@cx781526b> From: "Nils Wagner" > A matrix operation is that of stacking the columns of a > matrix one under the other to form a single column. > This operation is called "vec" or "cs" (c)olumn (s)tring > > Example > > A is a m * n matrix > > vec(A) = reshape(transpose(A),(m*n,1)) I assume you mean: def vec(A): reshape(transpose(A), (m*n,1)) First off, the following is a bit simpler and means you don't have to carray m and n around def vec(A): reshape(transpose(A), (-1,1)) > How can I copy the result of vec(A) into the i-th column of another > matrix called B ? B = zeros([m*n, p]) B[:,i:i+1] = vec(A) However, I don't think this is what you really want. I suspect you'd be happier with: B[:,i] = ravel(A) Ravel turns A into an m*n length vector [shape (m*n,)] instead of m*n by 1 array [shape (m*n,1)]. If all you want to do is insert it into B, this is going to be more useful. -tim From chrishbarker at home.net Thu Jul 26 14:46:06 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 26 Jul 2001 11:46:06 -0700 Subject: [Numpy-discussion] round, floor and ceil ? References: <00101808405300.01041@penguin.visionpro.com> Message-ID: <3B60656E.D068BEBB@home.net> Hi all, I was surprised to find that the functions: round, floor, and ceil are not included as ufuncs in NumPy. Have I just missed them? Where can I find them if they do exist? If they don't is there a reason for it, or has just no one gotten around to writing them? If the latter, can someone give me some pointers as to how I would go about writting them myself. It certainly seems as though it would be easy if modeled after the other unary ufuncs, but I'm a little unsure from the source where I would put it all. thanks, -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From kern at caltech.edu Thu Jul 26 14:41:13 2001 From: kern at caltech.edu (Robert Kern) Date: Thu, 26 Jul 2001 11:41:13 -0700 Subject: [Numpy-discussion] round, floor and ceil ? In-Reply-To: <3B60656E.D068BEBB@home.net> References: <00101808405300.01041@penguin.visionpro.com> <3B60656E.D068BEBB@home.net> Message-ID: <20010726114113.A1116@myrddin.caltech.edu> On Thu, Jul 26, 2001 at 11:46:06AM -0700, Chris Barker wrote: > Hi all, > > I was surprised to find that the functions: > > round, floor, and ceil are not included as ufuncs in NumPy. > > Have I just missed them? Where can I find them if they do exist? Python 2.0.1 (#0, Jul 3 2001, 12:36:30) [GCC 2.95.4 20010629 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import Numeric >>> print Numeric.__version__ 20.1.0 >>> Numeric.floor >>> Numeric.ceil >>> Numeric.around The last one isn't a ufunc, but it's composed of them. I would guess that it's a function so that it can match Python's rounding behavior. -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From chrishbarker at home.net Thu Jul 26 15:53:16 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 26 Jul 2001 12:53:16 -0700 Subject: [Numpy-discussion] round, floor and ceil ? References: <00101808405300.01041@penguin.visionpro.com> <3B60656E.D068BEBB@home.net> <20010726114113.A1116@myrddin.caltech.edu> Message-ID: <3B60752C.5F85EBDD@home.net> Robert Kern wrote: > >>> Numeric.floor > > >>> Numeric.ceil > > >>> Numeric.around > DOH! I had just been looking for round, but Ithought I had checked for ceil and floor as wel, but I guess not. sorry for the stupid question. I can point out that none of these is in the doc. Paul, is there any way any of us can contribute to the doc?? > The last one isn't a ufunc, but it's composed of them. ] It seems to act like one: >>> floor([3.3,3.5,3.6]) array([ 3., 3., 3.]) probably because it is composed of them. > a function so that it can match Python's rounding behavior. It does seem to match Python's native round, which makes me wonder why it can't be called "round", since it will behave the same for regulat python number types. NOt a big deal, of course. -thanks, Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From tim.hochberg at ieee.org Thu Jul 26 16:35:13 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 26 Jul 2001 13:35:13 -0700 Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) Message-ID: <149101c11612$795bdb50$87740918@cx781526b> "Curtis Jensen" wrote in message news:3B6076D4.68B6840C at bioeng.ucsd.edu... > the documenation for the "transpose" function for the "Numeric" module > seems to be incoorect, or at least missleading. The correct place for this is probably the numpy-discussion list, so I'm cc'ing it there. Perhaps the Paul Dubois will see it and have some ideas for clearing of the docs. > It says that transpose is suppose to return a "new" array. In fact it > does not. It returns a pointer to the same array, only with transposed > indicies. It's been a while since I looked at the NumPy docs, so I don't recall what conventions they use here. However, transpose does return a new array, it just points to the same data as the original. If a=transpose(b), "a is b" is false and "a.shape == b.shape" is false, so clearly they are different objects (i.e., different arrays). You know most of this, as you demonstrate down below, I just wanted to make the point that there is a difference between a new array and new data. Note that nearly every operation that can return a reference rather than a copy does so. Even slicing, if b=a[3:5], then 'b' holds a reference to the same data as 'a'. Some functions go so far to return a reference when they can, but otherwise copy. See ravel for example -- it copies the data if its argument is not contiguous, otherwise it uses a reference. Now _that_ can be confusing! Useful though. -tim > consider the example: > > Python 1.5.2 (#4, Sep 5 2000, 10:29:12) [C] on irix646 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> from Numeric import * > >>> foo = zeros([5,10]) > >>> bar = transpose( foo ) > >>> foo > array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) > >>> bar > array([[0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0]]) > >>> foo[0,2] = 1 > >>> foo > array([[0, 0, 1, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) > >>> bar > array([[0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [1, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0]]) > >>> > > > if bar was truely a new array, then changes to foo would not affect > bar. In the example above, it does. This way actualy works better for > my purposes, however, the documentation is missleading. > > -- > Curtis Jensen > cjensen at bioeng.ucsd.edu > http://www-bioeng.ucsd.edu/~cjensen/ > FAX (425) 740-1451 From Aureli.Soria_Frisch at ipk.fhg.de Fri Jul 27 13:14:04 2001 From: Aureli.Soria_Frisch at ipk.fhg.de (Aureli Soria Frisch) Date: Fri, 27 Jul 2001 19:14:04 +0200 Subject: [Numpy-discussion] Bug in RandomArray.multivariate_normal? In-Reply-To: <3B60656E.D068BEBB@home.net> References: <00101808405300.01041@penguin.visionpro.com> Message-ID: Hi, Folllowing could be a bug: >Traceback (most recent call last): > File "", line 1, in ? > File "macintosh hd:compiler:python >2.0:extensions:numerical:lib:packages:RandomArray.py", line 120, in >multivariate_normal > final_shape.append(mean.shape[0]) >AttributeError: 'tuple' object has no attribute 'append' should be: final_shape=final_shape+(mean.shape[0],) or am I missing something? Thanks ################################# Aureli Soria Frisch Fraunhofer IPK Dept. Pattern Recognition post: Pascalstr. 8-9, 10587 Berlin, Germany e-mail:aureli at ipk.fhg.de fon: +49 30 39006-150 fax: +49 30 3917517 ################################# From paul at pfdubois.com Fri Jul 27 15:03:12 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Fri, 27 Jul 2001 12:03:12 -0700 Subject: [Numpy-discussion] Troubles with arrays In-Reply-To: Message-ID: I don't know if someone helped you with this while I was on travel, but in case they didn't: I'm pretty sure your problem is that myTest is not in the same file as the import_array; when it tries to access the Numeric C API, it will be dereferencing zero. For extensions that are not in one file, a special techniques is required. Recently an improvement was added to make this easier. I believe you should add this to your header file, above the include of arrayobject.h: #define PY_ARRAY_UNIQUE_SYMBOL xxxx where xxxx is any name you choose that won't conflict with your other stuff. I hope that if I have this wrong somebody will correct me. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Wim Vanroose Sent: Tuesday, July 24, 2001 4:05 AM To: numpy-discussion at lists.sourceforge.net Subject: [Numpy-discussion] Troubles with arrays Dear Numerical Python Users, I have a small program that produces array's that I want to import in Python. The code is organised in three files. 1) arraytest.h, 2) arraytest.c 3) testmodule.c. and the code is shown below. The function myTest() produces the array and is called from the test module. However, the program does not work! it crashes. In my opinion, I do not have yet enough insight in Numerical Python. Is there an essential part that I do not understand. Remarkable is that the pure Python equivalent of the program does not crash. Any ideas? Wim Vanroose ///////////////////////// //file: arraytest.h ////////////////////// #include "Python.h" #include "arrayobject.h" PyObject *myTest(void); ////////////////////// // file: arraytest.c //////////////////// #include "arraytest.h" PyObject * myTest(void ){ PyArrayObject *result; double *datainput; int dimensions[1]; int M=10; int MM; dimensions[0]=M; result = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); datainput =(double *)result->data; for(MM=0;MM < M ; MM++){ datainput[MM] = MM*0.1; } return PyArray_Return(result); } //////////////////// //file: test.c CRASHES!!!! //////////////// #include "arraytest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); import_array(); d = PyModule_GetDict(m); } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The Python Equivalent: DOES NOT CRASH %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ///////////// // file: simpletest.h ///////////////// #include "simpletest.h" PyObject * myTest(void); //////////////////// // file: test.c ////////////////////// #include "simpletest.h" PyObject * myTest(void ){ return Py_BuildValue("i",123); } //////////////// //file: test.c ////////////////// #include "simpletest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); d = PyModule_GetDict(m); } _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From oliphant.travis at ieee.org Fri Jul 27 09:55:04 2001 From: oliphant.travis at ieee.org (Travis Oliphant) Date: Fri, 27 Jul 2001 13:55:04 +0000 Subject: [Numpy-discussion] Troubles with arrays In-Reply-To: References: Message-ID: <01072713550400.14723@travis> On Fri, 27 Jul 2001, Paul F. Dubois wrote: > I don't know if someone helped you with this while I was on travel, but in > case they didn't: > I tested his code on my machine and found that by placing an import_array() statement in the subroutine which uses the C-API seems to work. > I'm pretty sure your problem is that myTest is not in the same file as the > import_array; when it tries to access the Numeric C API, it will be > dereferencing zero. For extensions that are not in one file, a special > techniques is required. Recently an improvement was added to make this > easier. I believe you should add this to your header file, above the > include of arrayobject.h: > > #define PY_ARRAY_UNIQUE_SYMBOL xxxx > > where xxxx is any name you choose that won't conflict with your other > stuff. > From paul at pfdubois.com Fri Jul 27 19:13:30 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Fri, 27 Jul 2001 16:13:30 -0700 Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) In-Reply-To: <149101c11612$795bdb50$87740918@cx781526b> Message-ID: I will try to put a note in the transpose section if there isn't one there already. As noted, there are numerous reference-instead-of-a-copy returns in Numeric which reflect the speed rather than safety orientation of the original designer. Many complaints of this nature are a complaint about that choice, which made a package that was harder to understand and more difficult to use safely but which is about as fast as possible. I didn't like some of these choices but then again I didn't do the work. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Tim Hochberg Sent: Thursday, July 26, 2001 1:35 PM To: numpy-discussion at lists.sourceforge.net Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) "Curtis Jensen" wrote in message news:3B6076D4.68B6840C at bioeng.ucsd.edu... > the documenation for the "transpose" function for the "Numeric" module > seems to be incoorect, or at least missleading. The correct place for this is probably the numpy-discussion list, so I'm cc'ing it there. Perhaps the Paul Dubois will see it and have some ideas for clearing of the docs. From tim.hochberg at ieee.org Fri Jul 27 19:48:22 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Fri, 27 Jul 2001 16:48:22 -0700 Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) References: Message-ID: <1cf601c116f6$9f2962a0$87740918@cx781526b> From: "Paul F. Dubois" > I will try to put a note in the transpose section if there isn't one there > already. As noted, there are numerous reference-instead-of-a-copy returns in > Numeric which reflect the speed rather than safety orientation of the > original designer. Many complaints of this nature are a complaint about that > choice, which made a package that was harder to understand and more > difficult to use safely but which is about as fast as possible. I didn't > like some of these choices but then again I didn't do the work. Hmmm.... I tend to think that the reference semantics were the right choice, at least for the lower level C implementation, since it's relatively easy to build copy semantics on top of reference semantics, but not vice versa (except, perhaps for slicing). Even now it would be pretty easy to build a pure python ncNumeric[1], where copy was the default. One could even make transpose do something sensible: import ncNumeric as ncn # C is a contiguous array # N is a noncontiguous array # Both of these would return a transposed copy ncn.transpose(C) ncn.transpose(N) # This returns a transposed reference ncn.transpose(C, copy=0) # And this raises an exception. ncn.transpose(N, copy=0) That'd be kinda cool. -tim [1] nc for nonconfusing. I thought about using 'safe', but Numeric is unlikely to ever be remotely safe.... From vanroose at ruca.ua.ac.be Mon Jul 30 03:42:38 2001 From: vanroose at ruca.ua.ac.be (Vanroose Wim) Date: Mon, 30 Jul 2001 09:42:38 +0200 Subject: [Numpy-discussion] Troubles with arrays, proposal for Solution Message-ID: <3B650FEE.50304@ruca.ua.ac.be> Dear Numerical Python Users, It is now clear to me, after the comments of Travis Oliphant, Paul Dubois and Phil Austin, that in EVERY C-file that uses NumPy extensions, the "import_array" statement must be present. However, after some try-outs with parts my code, it seems not a good idea to allow a diffusion of the "import_array" statement and "PyArrayObject" throughout the "C" code. The code becomes unclear by the mixing of Python concepts and C concepts. Therefore it is, in my opinion, a good rule to limit the use of NumPy to the interface between python and "C" code; i.e. the function where the python parameters are read and the PyArrayObject is created. Do more experienced NumPy users agree??? The code below illustrates the limited use of NumPy parts. Wim Vanroose ///////////////////////// //file: arraytest.h ////////////////////// #include "Python.h" #include "arrayobject.h" double *myTest(void); ////////////////////// // file: arraytest.c //////////////////// #include "arraytest.h" double * myTest(void ){ double *result; ... return result; } //////////////////// //file: test.c //////////////// #include "arraytest.h" static PyObject *function(PyObject *self, PyObject *args){ ... int dimensions[2]; dimensions[0] = N; dimensions[1] = N; PyArrayObject *result ; result = (PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_DOUBLE); double *data; data = myTest(); memcpy(result->data,data,N*N*sizeof(double)); return PyArray_Return(result); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); import_array(); d = PyModule_GetDict(m); } From phil at geog.ubc.ca Mon Jul 30 18:29:20 2001 From: phil at geog.ubc.ca (Phil Austin) Date: Mon, 30 Jul 2001 15:29:20 -0700 (PDT) Subject: [Numpy-discussion] Troubles with arrays, proposal for Solution Message-ID: <15205.57280.42626.794650@curlew.geog.ubc.ca> Vanroose Wim writes: > Dear Numerical Python Users, > > It is now clear to me, after the comments of Travis Oliphant, > Paul Dubois and Phil Austin, that in EVERY C-file that uses NumPy > extensions, the "import_array" statement must be present. Actually, what I was trying to say (in a message that didn't make it to the list) is the opposite -- import_array must be present in only one file. So below I would do something like: (my additions marked by PA>) > > ///////////////////////// > //file: arraytest.h > ////////////////////// > > #include "Python.h" PA> #define PY_ARRAY_UNIQUE_SYMBOL paArray > #include "arrayobject.h" > > double *myTest(void); > > ////////////////////// > // file: arraytest.c > //////////////////// > PA> #define NO_IMPORT_ARRAY > #include "arraytest.h" > > double * myTest(void ){ > double *result; > ... > > return result; > } > > //////////////////// > //file: test.c > //////////////// > #include "arraytest.h" > > static PyObject *function(PyObject *self, PyObject *args){ > > ... > int dimensions[2]; > > dimensions[0] = N; > dimensions[1] = N; > > PyArrayObject *result ; > result = (PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_DOUBLE); > > double *data; > data = myTest(); > memcpy(result->data,data,N*N*sizeof(double)); > return PyArray_Return(result); > } > > static PyMethodDef testMethods[] = { > {"test",function,1}, > {NULL,NULL} > }; > > extern "C" { > void inittest(){ > PyObject *m,*d; > m = Py_InitModule("test", testMethods); > import_array(); > d = PyModule_GetDict(m); > } > You should see the following when you run /lib/cpp -E on these files: in arraytest.c #define NO_IMPORT_ARRAY #include "arraytest.h" will produce a line like: extern void **paArray; but in test.c #include "arraytest.h" will produce: void **paArray; and import_array(); will expand to { PyObject *numpy = PyImport_ImportModule("_numpy"); if (numpy != 0) { PyObject *module_dict = PyModule_GetDict(numpy); PyObject *c_api_object = PyDict_GetItemString(module_dict, "_ARRAY_API"); if (((c_api_object)->ob_type == &PyCObject_Type)) { paArray = (void **)PyCObject_AsVoidPtr(c_api_object); } } }; The result is that there is a single global function pointer array called paArray that has its space reserved in test.c, and is referenced externally in arraytest.c. This allows you to use any numeric api call in either file. If you compile the module to, say, test.so on unix you should see something like this when you do a nm -D: ~phil% nm -D test.so | grep paArray 000a3d00 B paArray i.e. one instance of paArray in the data segment of the so file. Scanning the output of /lib/cpp -E output is a good way to get a feel for this (on unix anyway). Regards, Phil From paul at pfdubois.com Tue Jul 31 11:18:23 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 31 Jul 2001 08:18:23 -0700 Subject: [Numpy-discussion] RE: [Numpy-developers] Error behavior. (2) In-Reply-To: Message-ID: I understand why some people might want the behavior (return with inf or NaN etc in arrays rather than get an exception). Let's ask some basic questions. Having done such an operation, how do I tell if I have any errant values in the result? For example, what can I compare x[i] to, in order to know if it is invalid? We have had several requests for full support of IEEE but nobody knows how to do it portably, as far as I know. I resist bringing back fastumath because I wonder if it really would work portably, I don't know the answers to the simpleest questions like the above, and if it would I know that it made people reluctant to fix bugs or add new functions because they would have to do it twice. Adding a new function already requires something like five different places to fix. Using optional package MA, a user *can* achieve the goal you desire. For example, if x and y are numpy arrays, and I want to divide them without possibility of error, I can do: z = MA.masked_array(x) / MA.masked_array(y) if MA.getmask(z) is not None: print "Your operation failed in one or more components" The masked_array constructor does not copy its argument. (MAs mix with Numerics and scalars, so one of the masked_array calls above could be omitted.) >From a Windows session: >>> print x/y [ 1.#INF0000e+000, 2.00000000e+000, 1.50000000e+000, 1.33333333e+000,] >>> print MA.masked_array(x)/y [-- ,2.0 ,1.5 ,1.33333333333 ,] >>> >>> print MA.sqrt(y-2.) [-- ,-- ,0.0 ,1.0 ,] I realize this isn't exactly what you had in mind, and it is more expensive than just letting it rip, but it is reliable and portable. With the infs and Nans, I'm not sure what you can do with the answer other than print it. It does place the burden on the programmer to distinguish cases where he wants to survive a divide by zero from those where he does not, but in my mind that is a good thing. Paul From paul at pfdubois.com Tue Jul 31 11:22:53 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 31 Jul 2001 08:22:53 -0700 Subject: [Numpy-discussion] RE: [Numpy-developers] Error behavior. In-Reply-To: Message-ID: Numpys, This is Travis' original message to the developers list, discussing his ideas for dealing with floating point errors. When I answered him a minute ago I inadvertently posted to this list instead. But, it is a good idea to have everyone's thoughts. I only ask that you keep the noise down and not have this degenerate into the numerous IEEE discussions we have had before. Paul P.S. I still am looking for help on solving the Numeric bug on Alphas. -----Original Message----- From: numpy-developers-admin at lists.sourceforge.net [mailto:numpy-developers-admin at lists.sourceforge.net]On Behalf Of Travis Oliphant Sent: Monday, July 23, 2001 12:46 PM To: numpy-developers at lists.sourceforge.net Subject: [Numpy-developers] Error behavior. Many have noticed that with one of the newer Python releases, domain and range errors on one of the computations in an element-by-element umath function now always raise Python errors. It used to be that one could say: >>> x = arange(1,10) >>> y = arange(0,9) >>> print x/y and get an output with reasonable values in positions 1..9 of the output array but get an inf in the first position (how inf printed was platform specific). Many, including me, prefer returning an array with some undefined entries rather than raising an error and ruining the rest of the perfectly valid computations. Proposed solutions: 1) Make a new module (bring back the old fastumathmodule), which does not set the "check" flag when the ufunc is created so that error are not raised --- quick and fast fix. 2) Use the warnings framework so that rather than raise a Python error, a warning is issued. This allows the user to do what they want with the warning (from raise an error to ignore it). --- this feels like a better solution. Please let me know your position on this, so we can take action if warranted. Sincerely, Travis Oliphant _______________________________________________ Numpy-developers mailing list Numpy-developers at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-developers From paul at pfdubois.com Tue Jul 31 19:36:47 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 31 Jul 2001 16:36:47 -0700 Subject: [Numpy-discussion] Help: need info on Fortran/C mixing on Windows Message-ID: Any fellow nummies and Pythonistas out there with experience using Digital Fortran on Windows? I'm trying to get Pyfort to work with Visual Fortran / Visual C++ on Windows. I am not usually a Windows developer so I do not know how to do things like look at an object file to see what names are in it (as I could do with nm on Unix). I have discovered that by including c$DEC ATTRIBUTES C:: foo in my Fortran, where foo is the name of my Fortran function, that my missing external for foo disappears. This is not really ok as I want to be able to link to unmodified Fortran files that have simply been compiled into a foostuff.lib file. I need information such as: How to get the names to match up, or what name to generate in my C to correspond to the Fortran; Which library to load with: I've tried dfor.lib and dformd.lib, in the context of running a python extension link through distutils, and both complain vociferously about library conflicts. If this was my working life I could afford to put in the time to figure all this out, but this is pro bono publico and I would appreciate your tolerance of my asking for help. Even just your Makefile or setup.py from a successful project of this type would be a big help. Thanks, Paul Dubois From juerg-tschirren at uiowa.edu Sun Jul 1 15:23:17 2001 From: juerg-tschirren at uiowa.edu (Juerg Tschirren) Date: Sun, 1 Jul 2001 14:23:17 -0500 (CDT) Subject: [Numpy-discussion] segfault in PyArray_FromDims Message-ID: I did some experimenting with the NumPy C API. I wrote two functions. One for processing a NumPy array in C++ and the other one for generating a NumPy array in C++. The processing function work perfectly fine. But in the array-generating function I get a segmentation fault whenever I call PyArray_FromDims. I used swig for generating the wrapper functions. The two src-files (numPyExt.i and numPyExt.cc): --- begin numPyExt.i ------------------------------------------------- %module numPyExt %{ #include #include #include %} %init %{ import_array(); %} %typemap(python,in) double * { PyArrayObject *py_arr; if(!PyArray_Check($source)) { PyErr_SetString(PyExc_TypeError, "Not a NumPy array"); return NULL; } if (PyArray_ObjectType($source,0) != PyArray_DOUBLE) { PyErr_SetString(PyExc_ValueError, "Array must be of type double"); return NULL; } py_arr = (PyArrayObject*) \ (PyArray_ContiguousFromObject($source, PyArray_DOUBLE, 1, 1)); if (py_arr->nd != 1) { PyErr_SetString(PyExc_TypeError, "Array must be 1D"); return NULL; } $target = (double*)(py_arr->data); } extern PyObject* createArray(); extern void processArray(double* pdInArray); --- end numPyExt.i --------------------------------------------------- --- begin numPyExt.cc ------------------------------------------------ #include #include #include //------ PyObject* createArray() { PyArrayObject* retArray; int iDimensions[3] = {10, 10, 10}; cout << "before PyArray_FromDims" << endl << flush; retArray = (PyArrayObject*)PyArray_FromDims(3, iDimensions, PyArray_INT); cout << "after PyArray_FromDims" << endl << flush; return PyArray_Return(retArray); } //------ void processArray(double* pdInArray) { cout << *pdInArray << " " << *(pdInArray+1) << " " << *(pdInArray+2) << endl; } --- end numPyExt.cc -------------------------------------------------- Compiled with: g++ -c -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -O2 numPyExt.cc swig -python -c++ numPyExt.i g++ -c -O2 numPyExt_wrap.c -DOS_LINUX -DHAVE_CONFIG_H -I. -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -I/usr/local/lib/python2.0/config g++ -W1,--heap,50000,--stack,100000 -O2 -shared numPyExt.o numPyExt_wrap.o -lstdc++ -o numPyExt.so The Python test code I am using: import Numeric, numPyExt vec = Numeric.array((1.23, 4.56, 7.89)) numPyExt.processArray(vec) # works fine a = numPyExt.createArray() # seg fault here print a I am using NumPy v20.0.0, Python 2.1, and gcc 2.95.2 on a Linux 2.2.16 sytem. Does anybody have an idea what's causing this problem? Juerg From cookedm at physics.mcmaster.ca Sun Jul 1 22:38:43 2001 From: cookedm at physics.mcmaster.ca (David M. Cooke) Date: 01 Jul 2001 22:38:43 -0400 Subject: [Numpy-discussion] segfault in PyArray_FromDims In-Reply-To: References: Message-ID: At some point, Juerg Tschirren wrote: > I did some experimenting with the NumPy C API. I wrote two functions. > One for processing a NumPy array in C++ and the other one for > generating a NumPy array in C++. The processing function work perfectly > fine. But in the array-generating function I get a segmentation fault > whenever I call PyArray_FromDims. I used swig for generating the wrapper > functions. > > The two src-files (numPyExt.i and numPyExt.cc): [code snipped] > Compiled with: > g++ -c -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -O2 numPyExt.cc > swig -python -c++ numPyExt.i > g++ -c -O2 numPyExt_wrap.c -DOS_LINUX -DHAVE_CONFIG_H -I. -I/usr/local/include/python2.0 -I/usr/local/lib/python2.0/site-packages -I/usr/local/lib/python2.0/config > g++ -W1,--heap,50000,--stack,100000 -O2 -shared numPyExt.o numPyExt_wrap.o -lstdc++ -o numPyExt.so > This problem was discussed in April on this list, see http://www.geocrawler.com/mail/thread.php3?subject=%5BNumpy-discussion%5D+Numeric+on+OS+X+-+Anyone+get+it+to+work+%3F&list=1329 I banged my head against this for hours a few weeks ago until I found the above. The problem is that PyArray_FromDims (and all other PyArray_*) are not functions -- they're macros, defined like this: #define PyArray_FromDims \ (*(PyArray_FromDims_RET (*)PyArray_FromDims_PROTO) \ PyArray_API[PyArray_FromDims_NUM]) This means that all the PyArray_* functions are done through a lookup table PyArray_API, which is initialized by import_array(). By default, PyArray_API is defined in arrayobject.h as 'static void **PyArray_API', meaning that it is not accessible outside of the translation unit (i.e. file) that includes it. The relevant part of Numeric/arrayobject.h is this: #if defined(PY_ARRAY_UNIQUE_SYMBOL) #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL #endif /* C API address pointer */ #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY) extern void **PyArray_API; #else #if defined(PY_ARRAY_UNIQUE_SYMBOL) void **PyArray_API; #else static void **PyArray_API; #endif #endif So, one way to get the behaviour you want is 1) in the file where import_array is called, #define PY_ARRAY_UNIQUE_SYMBOL to be something like Py_Array_API_myext. (Make it unique because it will be exported as part of the .so file.) before including Numeric/arrayobject.h 2) in the other files, #define NO_IMPORT_ARRAY before including Numeric/arrayobject.h Another way is to have your main file (say, main.c) call functions in the other files, passing the value of PyArray_API defined there, so that the other files can set theirs to that value. Hope this helps. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm at physics.mcmaster.ca From feiguin at magnet.fsu.edu Mon Jul 2 12:03:52 2001 From: feiguin at magnet.fsu.edu (Adrian Feiguin) Date: Mon, 2 Jul 2001 12:03:52 -0400 (EDT) Subject: [Numpy-discussion] gtkLeastSquares.py Message-ID: Hi everybody, I'm the author of SciGraphica (http://scigraphica.sourceforge.net), an application for scientific graphics and data analysis that uses Python and Numpy. Among other things, it features spreadheets that can contain Python data, like formulas. The Python stuff was mainly done by Conrad Steenberg, because I don't have much experience, specially embedding Python into C. However, I decided to get started this weekend because we needed badly a GUI for non-linear least squares fits. The result is gtkLeastSquares.py, which is attached below. It's going to be distributed with SG, but it works independently and needs gtk.py and Scientific. Basically it is a gtk GUI for Scientific.Functions.LeastSquares. I'm quite satisfied with the result, considering that I'm a newbie ;-) I'm writting because I'd like to have some feedback, and people interested in contributing. The code is still immature, and needs enhancements, like user defined functions and parameters (either editing the existing in the GUI, or adding new ones interactively). I still have to learn. It is very simple, and easy to use. You'll find the code below, with an example at the bottom of the file. I hope you like it. All comments, and suggestions are very welcome (as well as contributors ;-) Thank you, -------------- Cut here ---------------------- # # gtkLeastSquares.py : GUI for the module Scientific.Functions.LeastSquares # Implementation of the Levenberg-Marquardt algorithm for general # non-linear least-squares fits. # # Copyright (C) 2001 Adrian E. Feiguin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # from string import * from gtk import * from Numeric import * from Scientific.Functions.LeastSquares import * from Scientific.Functions.FirstDerivatives import * def fit_linear(parameters, values): a, b = parameters x = values return (a + b * x) def fit_cuadratic(parameters, values): a, b, c, x0 = parameters x = values return(a + b * (x - x0) + c * (x - x0)**2) return def fit_gauss(parameters, values): y0, x0, a, w = parameters x = values return(y0 + a * exp(-2*(x-x0)**2/w**2)) return def fit_lorentz(parameters, values): x0, y0, a, b = parameters x = values return(y0 + 2*a/pi * w / (4 * (x - x0)**2 + w**2)) return def fit_boltzman(parameters, values): x0, a1, a2, dx = parameters x = values return((a1 - a2)/(1 + exp((x - x0)/dx)) + a2) def fit_logistic(parameters, values): x0, a1, a2, p = parameters x = values return((a1 - a2)/(1 + (x/x0)**p) + a2) def fit_expdecay(parameters, values): x0, y0, a, t = parameters x = values return(y0 + a * exp(-(x - x0)/t)) def fit_expgrow(parameters, values): x0, y0, a, t = parameters x = values return(y0 + a * exp((x - x0)/t)) def fit_expassoc(parameters, values): y0, a1, t1, a2, t2 = parameters x = values return(y0 + a1 * (1 + exp(-x/t1)) + a2 * (1 + exp(-x/t2))) def fit_hyperbl(parameters, values): p1, p2 = parameters x = values return(p1 * x/ (p2 + x)) def fit_pulse(parameters, values): x0, y0, a, t1, t2 = parameters x = values return(y0 + a * (1 + exp(-(x - x0)/t1)) * exp(-(x - x0)/t2)) def fit_rational0(parameters, values): a, b, c = parameters x = values return((b + c*x)/(1 + a*x)) def fit_sine(parameters, values): x0, a, w = parameters x = values return(a * sin(pi*(x - x0)/w)) def fit_gaussamp(parameters, values): x0, y0, a, w = parameters x = values return(y0 + a * exp(-(x - x0)**2/(2*w**2))) def fit_allometric(parameters, values): a, b = parameters x = values return(a * x**b) fit_linear_dic = { "Doc" : "Linear Function", "Exp" : "y = a + b * x", "Par" : ("a", "b"), "NumPar" : 2, "IVar" : "x", "DVar" : "y", "Function" : fit_linear } fit_cuadratic_dic = { "Doc" : "Cuadratic Function", "Exp" : "y = a + b * (x - x0) + c * (x - x0)**2", "Par" : ("a", "b", "c", "x0"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_cuadratic } fit_gauss_dic = { "Doc" : "Amplitude version of Gaussian Function", "Exp" : "y = y0 + a * exp(-2*(x-x0)**2/w**2)", "Par" : ("x0", "y0", "a", "w"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_gauss } fit_lorentz_dic = { "Doc" : "Lorentzian Peak Function", "Exp" : "y = y0 + 2*a/pi * w / (4 * (x - x0)**2 + w**2)", "Par" : ("x0", "y0", "a", "w"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_lorentz } fit_boltzman_dic = { "Doc" : "Boltzman Function: sigmoidal curve", "Exp" : "y = (a1 - a2)/(1 + exp((x - x0)/dx)) + a2", "Par" : ("x0", "a1", "a2", "dx"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_boltzman } fit_logistic_dic = { "Doc" : "Logistic dose/response", "Exp" : "y = (a1 - a2)/(1 + (x/x0)**p) + a2", "Par" : ("x0", "a1", "a2", "p"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_logistic } fit_expdecay_dic = { "Doc" : "Exponential Decay", "Exp" : "y = y0 + a * exp(-(x - x0)/t)", "Par" : ("x0", "y0", "a", "t"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_expdecay } fit_expgrow_dic = { "Doc" : "Exponential Growth", "Exp" : "y = y0 + a * exp((x - x0)/t)", "Par" : ("x0", "y0", "a", "t"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_expgrow } fit_expassoc_dic = { "Doc" : "Exponential Associate", "Exp" : "y = y0 + a1 * (1 + exp(-x/t1)) + a2 * (1 + exp(-x/t2))", "Par" : ("y0", "a1", "t1", "a2", "t2"), "NumPar" : 5, "IVar" : "x", "DVar" : "y", "Function" : fit_expassoc } fit_hyperbl_dic = { "Doc" : "Hyperbola Function", "Exp" : "y = p1 * x/ (p2 + x)", "Par" : ("p1", "p2"), "NumPar" : 2, "IVar" : "x", "DVar" : "y", "Function" : fit_hyperbl } fit_pulse_dic = { "Doc" : "Pulse Function", "Exp" : "y = y0 + a * (1 + exp(-(x - x0)/t1)) * exp(-(x - x0)/t2)", "Par" : ("y0", "a", "t1", "t2"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_pulse } fit_rational0_dic = { "Doc" : "Rational Function , type 0", "Exp" : "y = (b + c*x)/(1 + a*x)", "Par" : ("a", "b", "c"), "NumPar" : 3, "IVar" : "x", "DVar" : "y", "Function" : fit_rational0 } fit_sine_dic = { "Doc" : "Sine Function", "Exp" : "y = a * sin(pi*(x - x0)/w)", "Par" : ("a", "x0", "w"), "NumPar" : 3, "IVar" : "x", "DVar" : "y", "Function" : fit_sine } fit_gaussamp_dic = { "Doc" : "Amplitude version of Gaussian Peak Function", "Exp" : "y = y0 + a * exp(-(x - x0)**2/(2*w**2))", "Par" : ("x0", "y0", "a", "w"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_gaussamp } fit_allometric_dic = { "Doc" : "Classical Freundlich Model", "Exp" : "y = a * x**b", "Par" : ("a", "b"), "NumPar" : 4, "IVar" : "x", "DVar" : "y", "Function" : fit_allometric } functions = { "Linear" : fit_linear_dic, "Cuadratic" : fit_cuadratic_dic, "Gauss" : fit_gauss_dic, "Lorentz" : fit_lorentz_dic, "Boltzman" : fit_boltzman_dic, "Logistic" : fit_logistic_dic, "ExpDecay" : fit_expdecay_dic, "ExpGrow" : fit_expgrow_dic, "ExpAssoc" : fit_expassoc_dic, "Hyperbl" : fit_hyperbl_dic, "Pulse" : fit_pulse_dic, "Rational0" : fit_rational0_dic, "Sine" : fit_sine_dic, "GaussAmp" : fit_gaussamp_dic, "Allometric" : fit_allometric_dic } def fit(data): main_window = GtkWindow() main_window.set_title("Curve Fitting") main_window.set_border_width(5) main_window.connect("destroy", mainquit) main_window.connect("delete_event", mainquit) main_box = GtkVBox(FALSE, 5) main_window.add(main_box) main_frame = GtkFrame("Select Function") main_box.pack_start(main_frame) table = GtkTable(7, 4, FALSE) table.set_col_spacings(10) table.set_row_spacings(5) table.set_border_width(5) main_frame.add(table) swindow = GtkScrolledWindow() swindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) swindow.set_usize(120, 100) table.attach(swindow, 0, 1, 0, 6) clist = GtkCList(1) swindow.add(clist) table.attach(GtkVSeparator(), 1, 2, 0, 6) text = map(lambda i: str(i), range(20)) k = functions.keys() k.sort() for i in k: text[0] = i clist.append(text) label = GtkLabel("Exp:") label.set_alignment(1., .5) table.attach(label, 2, 3, 0, 1) fentry = GtkEntry() # fentry.set_editable(FALSE) table.attach(fentry, 3, 4, 0, 1) label = GtkLabel("Number of Param:") label.set_alignment(1., .5) table.attach(label, 2, 3, 1, 2) nspin = GtkSpinButton(GtkAdjustment(0, 0, 8, 1, 8, 0), 0, 0) nspin.set_editable(FALSE) nspin.set_state(STATE_INSENSITIVE) table.attach(nspin, 3, 4, 1, 2) label = GtkLabel("Param:") label.set_alignment(1., .5) table.attach(label, 2, 3, 2, 3) pentry = GtkEntry() pentry.set_editable(FALSE) pentry.set_state(STATE_INSENSITIVE) table.attach(pentry, 3, 4, 2, 3) label = GtkLabel("Independent Var:") label.set_alignment(1., .5) table.attach(label, 2, 3, 3, 4) iventry = GtkEntry() iventry.set_editable(FALSE) iventry.set_state(STATE_INSENSITIVE) table.attach(iventry, 3, 4, 3, 4) label = GtkLabel("Dependent Var:") label.set_alignment(1., .5) table.attach(label, 2, 3, 4, 5) dventry = GtkEntry() dventry.set_editable(FALSE) dventry.set_state(STATE_INSENSITIVE) table.attach(dventry, 3, 4, 4, 5) action_area = GtkHButtonBox() action_area.set_layout(BUTTONBOX_END) action_area.set_spacing(5) main_box.pack_start(action_area) fit_button = GtkButton("Fit") action_area.pack_start(fit_button) close_button = GtkButton("Close") action_area.pack_start(close_button) lframe = GtkFrame() lframe.set_shadow_type(SHADOW_IN) main_box.pack_start(lframe) explabel = GtkLabel("Choose a Fitting Function") lframe.add(explabel) # CALLBACK FUNCTIONS def select_function(_clist, row, col, event, functions = functions, label = explabel, fentry = fentry, pentry = pentry, nspin = nspin, iventry = iventry, dventry = dventry): k = _clist.get_text(row, col) f = functions[k] label.set_text(f["Doc"]) fentry.set_text(f["Exp"]) nspin.set_value(f["NumPar"]) iventry.set_text(f["IVar"]) dventry.set_text(f["DVar"]) s = "" for i in f["Par"]: s = s + i + ", " pentry.set_text(s[:len(s)-2]) def open_fit_dialog(_button, functions = functions, clist = clist, data = data): a = clist.__getattr__("selection") k = clist.get_text(a[0], 0) f = functions[k] param = (1, 1) fit_dialog(f, data) # CONNECT OBJECTS clist.connect("select_row", select_function) fit_button.connect("clicked", open_fit_dialog) close_button.connect("clicked", main_window.destroy) clist.select_row(0, 0) main_window.show_all() mainloop() def fit_dialog(f, data): main_window = GtkWindow() main_window.set_title("Fit") main_window.set_border_width(5) main_window.connect("destroy", mainquit) main_window.connect("delete_event", mainquit) table = GtkTable(len(f["Par"])+3, 2, FALSE) table.set_col_spacings(10) table.set_row_spacings(5) main_window.add(table) table.attach(GtkLabel("Variable"), 0, 1, 0, 1) table.attach(GtkLabel("Value"), 1, 2, 0, 1) table.attach(GtkHSeparator(), 0, 2, 1, 2) r = 2 entries = [] for i in f["Par"]: # check = GtkCheckButton(i+":") # table.attach(check, 0, 1, r, r+1) table.attach(GtkLabel(i+":"), 0, 1, r, r+1) entry = GtkEntry() entries = entries + [entry] entry.set_text("0.0") table.attach(entry, 1, 2, r, r+1) r = r + 1 table.attach(GtkHSeparator(), 0, 2, r, r + 1) r = r + 1 table.attach(GtkLabel("Chi_Sqr:"), 0, 1, r, r + 1) err_entry = GtkEntry() table.attach(err_entry, 1, 2, r, r + 1) r = r + 1 table.attach(GtkHSeparator(), 0, 2, r, r + 1) def run_fit(_button, f = f, data = data, entries = entries, err_entry = err_entry): n = 0 p = () for i in entries: s = entries[n].get_text() p = p + (atof(s),) n = n + 1 fit, error = leastSquaresFit(f["Function"], p, data) n = 0 for i in entries: entries[n].set_text(str(fit[n])) n = n + 1 err_entry.set_text(str(error)) # print "Fitted parameters: ", fit # print "Fit error: ", error return action_area = GtkHButtonBox() action_area.set_layout(BUTTONBOX_SPREAD) action_area.set_spacing(5) run_button = GtkButton("Run") close_button = GtkButton("Close") action_area.pack_start(run_button) action_area.pack_start(close_button) table.attach(action_area, 0, 2, r + 1, r + 2) # CONNECT OBJECTS run_button.connect("clicked", run_fit) close_button.connect("clicked", main_window.destroy) main_window.show_all() mainloop() # Test for linear fit: # # from gtkLeastSquares import * # data = [ (0., 0.), (1., 1.1), (2., 1.98), (3., 3.05) ] # fit(data) From feiguin at magnet.fsu.edu Mon Jul 2 17:43:23 2001 From: feiguin at magnet.fsu.edu (Adrian Feiguin) Date: Mon, 2 Jul 2001 17:43:23 -0400 (EDT) Subject: [Numpy-discussion] ANNOUNCE: SciGraphica-0.7.0 Message-ID: I'm pleased to announce the new release of Scigraphica with bugfixes and enhancements. Among other things, embedding images is now possible, as well as setting background images for the plots. Clipboard for plots: copy a plot, and paste it on a different plot window. Improved PostScript and WYSIWYG. It includes pysga.py, a Python module for interacting with plots and worksheets from terminal. New scheme for storing numerical data in worksheets. Examples are included. Scigraphica is a powerful tool for scientific graphics and data analysis. It pretends to be a clone of the popular commercial (and expensive) application "Microcal Origin". It fully supplies plotting features for 2D, 3D and polar charts. The aim is to obtain a fully-featured, cross-plattform, user-friendly, self-growing scientific application. It is free and open-source, released under the GPL license. Main features: -You can plot functions and manipulate data in worksheets. -You can open several worksheets and plots and work with them at the same time. -The plots are fully configurable using a control panel dialog. -The look and feel is completely WYSIWYG. -Publication quality PostScript output. -You can interact with the plots double-clicking, dragging and moving objects with the mouse. -Export/Import features in XML format. -You can insert Python expressions in the worksheets. -Terminal with command-line Python interface for interacting with plots and worksheets URL: http://scigraphica.sourceforge.net Enjoy! The SciGraphica Team.- ------------------------------------------------------------------------ TODO for sg-0.8.0: sg-0.8.0 will have a completely different structure, more modular, built ontop of reusable libraries. SGplot, SGworksheet, SGlayer, and SGdataset will be GtkWidgets and part of a shareable library, that could be used by other applications, and from Python. From jochen at unc.edu Tue Jul 3 10:14:24 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 03 Jul 2001 10:14:24 -0400 Subject: [Numpy-discussion] Numpy on Cygwin Message-ID: <86d77iyu9r.fsf@bock.chem.unc.edu> Dear All, I have had some problems with Cannot export _bss_end__: symbol not defined messages and friends again for the cvs Numerical Python package. Although the LAPACK-module uses the DL_EXPORT approach and works fine, the other packages apparently try the .def-approach (which I barely heard about); this packages do not build for me on latest Cygwin. (I have not tried it on older ones.) Putting DL_EXPORTs around all the init-functions fixes this for me: Index: Packages/FFT/Src/fftpackmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Packages/FFT/Src/fftpackmodule.c,v retrieving revision 1.1 diff -u -r1.1 fftpackmodule.c --- Packages/FFT/Src/fftpackmodule.c 2000/07/06 16:54:16 1.1 +++ Packages/FFT/Src/fftpackmodule.c 2001/07/03 14:06:48 @@ -238,7 +238,7 @@ "" ; -void +DL_EXPORT(void) initfftpack() { PyObject *m, *d; Index: Packages/RNG/Src/RNGmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Packages/RNG/Src/RNGmodule.c,v retrieving revision 1.1 diff -u -r1.1 RNGmodule.c --- Packages/RNG/Src/RNGmodule.c 2000/07/06 16:54:17 1.1 +++ Packages/RNG/Src/RNGmodule.c 2001/07/03 14:06:49 @@ -613,7 +613,7 @@ "Random number generator: independent random number streams." ; -void +DL_EXPORT(void) initRNG() { PyObject *m, *d; Index: Packages/kinds/Src/_kindsmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Packages/kinds/Src/_kindsmodule.c,v retrieving revision 1.1 diff -u -r1.1 _kindsmodule.c --- Packages/kinds/Src/_kindsmodule.c 2001/04/17 23:35:10 1.1 +++ Packages/kinds/Src/_kindsmodule.c 2001/07/03 14:06:49 @@ -10,7 +10,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void +DL_EXPORT(void) init_kinds() { PyObject *m, *d; Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From paul at pfdubois.com Mon Jul 9 13:57:50 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Mon, 9 Jul 2001 10:57:50 -0700 Subject: [Numpy-discussion] Cannot reply to some questions Message-ID: I receive a steady stream of questions sent to me about Numerical Python. Frequently, in their zeal to protect themselves from spam, the senders obscure their sending address. This causes my reply to bounce. I sometimes drop the ball and fail to reply promptly due to the volume of letters I receive, advancing senility, or because the question requires research and it goes onto my stack for too long. But before you conclude that I'm not answering you because of ineptitude, please be sure I *can* answer your mail with a simple reply. Thanks, Paul From paul at pfdubois.com Mon Jul 9 14:01:35 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Mon, 9 Jul 2001 11:01:35 -0700 Subject: [Numpy-discussion] MA : assignment to slices doesn't work like Numeric. In-Reply-To: <3B3BB29D.A932FF05@atd.ucar.edu> Message-ID: It is an advertised difference between MA and Numeric that index operations return copies, not references. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Joe Van Andel Sent: Thursday, June 28, 2001 3:42 PM To: numpy-discussion Subject: [Numpy-discussion] MA : assignment to slices doesn't work like Numeric. I retrieved the latest MA from CVS. I've noticed that assigning to a slice doesn't work the same as Numeric. Here's a simple test program: -------------------------------- from MA import * #from Numeric import * numBeams,numGates = (5,4) result = ones((numBeams, numGates),'f') * -327.68 print 'result = ', result t1 = ones((numGates,),'f') t2 = 2* ones((numGates,),'f') result[0] = t1 result[1][:] = t2 print 'result = ', result ----------------------------------------- Output using 'MA': result = [[-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,]] result = [[ 1. , 1. , 1. , 1. ,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,] [-327.68,-327.68,-327.68,-327.68,]] However, if I use Numeric, rather than MA, I get: result = [[-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68]] result = [[ 1. 1. 1. 1. ] [ 2. 2. 2. 2. ] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68] [-327.68 -327.68 -327.68 -327.68]] So, a[x][:] = my_array doesn't seem to work using 'MA'. -- Joe VanAndel National Center for Atmospheric Research http://www.atd.ucar.edu/~vanandel/ Internet: vanandel at ucar.edu _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From nwagner at isd.uni-stuttgart.de Tue Jul 10 05:52:41 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Tue, 10 Jul 2001 11:52:41 +0200 Subject: [Numpy-discussion] Wishlist for Numpy Message-ID: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> Hi, Is there any wish-list of projects and feature requests for Numpy ? I would appreciate it, if Numpy could handle the following functions : 1. Fix eig to also be able to solve the generalized eigenvalue problem and polynomial eigenvalue problems 2. Support for matrix functions like logm, expm, sqrtm 3. Wavelet transform 4. Solver for ODE's and DAE's Nils Wagner From phrxy at csv.warwick.ac.uk Tue Jul 10 10:56:02 2001 From: phrxy at csv.warwick.ac.uk (John J. Lee) Date: Tue, 10 Jul 2001 15:56:02 +0100 (BST) Subject: [Numpy-discussion] Wishlist for Numpy In-Reply-To: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> Message-ID: On Tue, 10 Jul 2001, Nils Wagner wrote: [...] > I would appreciate it, if Numpy could handle the following functions : [...] > 2. Support for matrix functions like logm, expm, sqrtm [...] What do you mean by 'matrix functions'? John From hinsen at cnrs-orleans.fr Tue Jul 10 10:54:07 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Tue, 10 Jul 2001 16:54:07 +0200 Subject: [Numpy-discussion] Wishlist for Numpy In-Reply-To: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> (message from Nils Wagner on Tue, 10 Jul 2001 11:52:41 +0200) References: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> Message-ID: <200107101454.QAA08105@chinon.cnrs-orleans.fr> > I would appreciate it, if Numpy could handle the following functions : > > 1. Fix eig to also be able to solve the generalized eigenvalue problem > and polynomial eigenvalue problems That would be a relatively simple addition to LinearAlgebra, but would also require some additional routines from LAPACK. > 2. Support for matrix functions like logm, expm, sqrtm That can be done in Python code. > 3. Wavelet transform For efficiency, that should be done in C/Fortran. Are there any wavelet libraries out there? Anyway, this should become a separate package. > 4. Solver for ODE's and DAE's Given the variety of equations and solvers, this looks like a big project. Good Python integration is also not trivial. So that's not only a separate package, but even a major one. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From nwagner at isd.uni-stuttgart.de Tue Jul 10 10:13:53 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Tue, 10 Jul 2001 16:13:53 +0200 Subject: [Numpy-discussion] Wishlist for Numpy References: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> <200107101454.QAA08105@chinon.cnrs-orleans.fr> Message-ID: <3B4B0DA1.DD9575EC@isd.uni-stuttgart.de> Konrad Hinsen schrieb: > > I would appreciate it, if Numpy could handle the following functions : > > > > 1. Fix eig to also be able to solve the generalized eigenvalue problem > > and polynomial eigenvalue problems > > That would be a relatively simple addition to LinearAlgebra, but > would also require some additional routines from LAPACK. > > > 2. Support for matrix functions like logm, expm, sqrtm > > That can be done in Python code. > > > 3. Wavelet transform > > For efficiency, that should be done in C/Fortran. Are there any wavelet > libraries out there? Anyway, this should become a separate package. > > > 4. Solver for ODE's and DAE's > > Given the variety of equations and solvers, this looks like a big > project. Good Python integration is also not trivial. So that's not > only a separate package, but even a major one. > > Konrad. > -- > ------------------------------------------------------------------------------- > Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr > Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 > Rue Charles Sadron | Fax: +33-2.38.63.15.17 > 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ > France | Nederlands/Francais > ------------------------------------------------------------------------------- Is there any intention for inclusion of the missing functions in future releases of Numpy ? Nils. From hinsen at cnrs-orleans.fr Tue Jul 10 14:52:21 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Tue, 10 Jul 2001 20:52:21 +0200 Subject: [Numpy-discussion] Wishlist for Numpy In-Reply-To: <3B4B0DA1.DD9575EC@isd.uni-stuttgart.de> (message from Nils Wagner on Tue, 10 Jul 2001 16:13:53 +0200) References: <3B4AD069.2EEEE7BC@isd.uni-stuttgart.de> <200107101454.QAA08105@chinon.cnrs-orleans.fr> <3B4B0DA1.DD9575EC@isd.uni-stuttgart.de> Message-ID: <200107101852.UAA08996@chinon.cnrs-orleans.fr> > Is there any intention for inclusion of the missing functions in > future releases of Numpy ? Usually code submissions are gratefully accepted. But I am not aware of anyone working on any of these topics at the moment. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From paul at pfdubois.com Tue Jul 10 16:01:19 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 10 Jul 2001 13:01:19 -0700 Subject: [Numpy-discussion] Release 20.1 Message-ID: Release 20.1 is available for your dining pleasure. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: changes.txt URL: From jochen at unc.edu Tue Jul 17 15:17:39 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 17 Jul 2001 15:17:39 -0400 Subject: [Numpy-discussion] Cygwin Message-ID: <8666crfjqk.fsf@bock.chem.unc.edu> Another little patch needed for NumPy as of today to compile on Cygwin: Index: Src/fastumathmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v retrieving revision 1.1 diff -u -r1.1 fastumathmodule.c --- Src/fastumathmodule.c 2001/07/16 23:19:23 1.1 +++ Src/fastumathmodule.c 2001/07/17 19:16:39 @@ -2123,7 +2123,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void initfastumath() { +DL_EXPORT(void) initfastumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From paul at pfdubois.com Tue Jul 17 15:53:52 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 17 Jul 2001 12:53:52 -0700 Subject: [Numpy-discussion] Cygwin In-Reply-To: <8666crfjqk.fsf@bock.chem.unc.edu> Message-ID: This file is no longer in the distribution. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Jochen K?pper Sent: Tuesday, July 17, 2001 12:18 PM To: Numpy Discussion Subject: [Numpy-discussion] Cygwin Another little patch needed for NumPy as of today to compile on Cygwin: Index: Src/fastumathmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v retrieving revision 1.1 diff -u -r1.1 fastumathmodule.c --- Src/fastumathmodule.c 2001/07/16 23:19:23 1.1 +++ Src/fastumathmodule.c 2001/07/17 19:16:39 @@ -2123,7 +2123,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void initfastumath() { +DL_EXPORT(void) initfastumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From jochen at unc.edu Tue Jul 17 16:30:53 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 17 Jul 2001 16:30:53 -0400 Subject: [Numpy-discussion] Cygwin In-Reply-To: References: Message-ID: <86zoa3e1s2.fsf@bock.chem.unc.edu> >>>>> Paul F Dubois wrote on Tue, 17 Jul 2001 12:53:52 -0700: Paul> This file is no longer in the distribution. Uhm, what am I doing wrong? cvs up && cvs stat -v Src/fastumathmodule.c =================================================================== File: fastumathmodule.c Status: Locally Modified Working revision: 1.1 Repository revision: 1.1 /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v Sticky Tag: (none) Sticky Date: (none) Sticky Options: (none) Existing Tags: No Tags Exist Paul> -----Original Message----- Paul> Another little patch needed for NumPy as of today to compile on Paul> Cygwin: Paul> Index: Src/fastumathmodule.c Paul> =================================================================== Paul> RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v Greetings, Jochen -- University of North Carolina phone: 919-962-4403 Department of Chemistry phone: 919-962-1579 Venable Hall CB#3290 fax: 919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From nwagner at isd.uni-stuttgart.de Wed Jul 18 07:10:05 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 18 Jul 2001 13:10:05 +0200 Subject: [Numpy-discussion] Kronecker product Message-ID: <3B556E8D.D485CB98@isd.uni-stuttgart.de> Hi, I would appreciate it, if Numpy could handle the Kronecker-product of two matrices X, Y. kron(X,Y) is the Kronecker tensor product of X and Y. The result is a large matrix formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. Nils From paul at pfdubois.com Wed Jul 18 10:40:41 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Wed, 18 Jul 2001 07:40:41 -0700 Subject: [Numpy-discussion] Kronecker product In-Reply-To: <3B556E8D.D485CB98@isd.uni-stuttgart.de> Message-ID: Using the outer product you get a matrix that has the right size and contents but it is m*n by p*q Was that a misprint in your post? >>> x array([1, 2, 3, 4, 5, 6]) >>> x.shape=(3,2) >>> y = 10*transpose(x) >>> y array([[10, 30, 50], [20, 40, 60]]) >>> z = outerproduct(x.flat, y.flat) >>> z array([[ 10, 30, 50, 20, 40, 60], [ 20, 60, 100, 40, 80, 120], [ 30, 90, 150, 60, 120, 180], [ 40, 120, 200, 80, 160, 240], [ 50, 150, 250, 100, 200, 300], [ 60, 180, 300, 120, 240, 360]]) >>> -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Nils Wagner Sent: Wednesday, July 18, 2001 4:10 AM To: numpy-discussion at lists.sourceforge.net Subject: [Numpy-discussion] Kronecker product Hi, I would appreciate it, if Numpy could handle the Kronecker-product of two matrices X, Y. kron(X,Y) is the Kronecker tensor product of X and Y. The result is a large matrix formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. Nils _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From nwagner at isd.uni-stuttgart.de Wed Jul 18 09:55:55 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 18 Jul 2001 15:55:55 +0200 Subject: [Numpy-discussion] Kronecker product References: Message-ID: <3B55956B.B01DDC19@isd.uni-stuttgart.de> "Paul F. Dubois" schrieb: > Using the outer product you get a matrix that has the right size and > contents but it is m*n by p*q > Was that a misprint in your post? > >>> x > array([1, 2, 3, 4, 5, 6]) > >>> x.shape=(3,2) > >>> y = 10*transpose(x) > >>> y > array([[10, 30, 50], > [20, 40, 60]]) > >>> z = outerproduct(x.flat, y.flat) > >>> z > array([[ 10, 30, 50, 20, 40, 60], > [ 20, 60, 100, 40, 80, 120], > [ 30, 90, 150, 60, 120, 180], > [ 40, 120, 200, 80, 160, 240], > [ 50, 150, 250, 100, 200, 300], > [ 60, 180, 300, 120, 240, 360]]) > >>> > > -----Original Message----- > From: numpy-discussion-admin at lists.sourceforge.net > [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Nils > Wagner > Sent: Wednesday, July 18, 2001 4:10 AM > To: numpy-discussion at lists.sourceforge.net > Subject: [Numpy-discussion] Kronecker product > > Hi, > > I would appreciate it, if Numpy could handle the Kronecker-product of > two matrices X, Y. > > kron(X,Y) is the Kronecker tensor product of X and Y. > The result is a large matrix formed by taking all possible products > between the elements of X and those of Y. If X is m-by-n > and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. > > Nils > > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > http://lists.sourceforge.net/lists/listinfo/numpy-discussion >>> a > array([[1, 2], > [3, 4]]) > >>> b > array([[11, 12], > [13, 14]]) > >>> outerproduct(a,b) > array([[11, 12, 13, 14], > [22, 24, 26, 28], > [33, 36, 39, 42], > [44, 48, 52, 56]]) The Kronecker product applied to A,B is kron(A,B) = array([[11,12,22,24], [13,14,26,28], [33,36,44,48], [39,42,52,56]]) How can I rearrange the result of outerproduct to the result of Kronecker product with numpy ? Cheers, Nils From cgw at alum.mit.edu Wed Jul 18 11:07:07 2001 From: cgw at alum.mit.edu (Charles G Waldman) Date: Wed, 18 Jul 2001 10:07:07 -0500 Subject: [Numpy-discussion] Kronecker product In-Reply-To: <3B5580B1.186F375B@isd.uni-stuttgart.de> References: <3B556E8D.D485CB98@isd.uni-stuttgart.de> <15189.35598.403100.520462@sirius.net.home> <3B5580B1.186F375B@isd.uni-stuttgart.de> Message-ID: <15189.42523.133794.26662@transamoeba.dyndns.org> Nils Wagner writes: > > How can I rearrange the result of outerproduct to the result of > Kronecker product with numpy ? > def kron(a,b): o = outerproduct(a,b) o.shape = a.shape + b.shape return concatenate(concatenate(o, axis=1), axis=1) From hinsen at cnrs-orleans.fr Wed Jul 18 11:20:20 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Wed, 18 Jul 2001 17:20:20 +0200 Subject: [Numpy-discussion] Kronecker product In-Reply-To: <3B556E8D.D485CB98@isd.uni-stuttgart.de> (message from Nils Wagner on Wed, 18 Jul 2001 13:10:05 +0200) References: <3B556E8D.D485CB98@isd.uni-stuttgart.de> Message-ID: <200107181520.RAA05268@chinon.cnrs-orleans.fr> > I would appreciate it, if Numpy could handle the Kronecker-product of > two matrices X, Y. > > kron(X,Y) is the Kronecker tensor product of X and Y. import Numeric def kron(x, y): return Numeric.multiply.outer(x, y) > The result is a large matrix formed by taking all possible products > between the elements of X and those of Y. If X is m-by-n > and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. OK, there's one difference: the function shown about returns an array of shape (m, n, p, q). If the input arrays are always 2D, the following will do what you need: import Numeric def kron(x, y): z = Numeric.transpose(Numeric.multiply.outer(x, y), [0, 2, 1, 3]) z.shape = (z.shape[0]*z.shape[1], z.shape[2]*z.shape[3]) return z Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From bowman at acsu.buffalo.edu Wed Jul 18 18:34:10 2001 From: bowman at acsu.buffalo.edu (Charles L. Bowman, Ph.D.) Date: Wed, 18 Jul 2001 18:34:10 -0400 Subject: [Numpy-discussion] Re: Problem running Numeric-20.1 installer on NT4,SP3 Message-ID: <3B560EE2.19655A2E@acsu.buffalo.edu> Hello, I have python2.1.1c1 in I:\python21. It's up and running OK. I downloaded Numeric-20.1.0.win32-py2.1.exe, placed it in I:\python21, opened up a DOS window and ran the installer. The desktop flickered *very* briefly. Import Numeric returns "No module named Numeric". I cannot find any files named numeric.py. Does the installer assume python2.1 is in C:\python21? If so, how can I pass the correct drive information to the installer? Thanks for your help. Charles Bowman From nwagner at isd.uni-stuttgart.de Thu Jul 19 03:16:42 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Thu, 19 Jul 2001 09:16:42 +0200 Subject: [Numpy-discussion] Kronecker product References: <3B556E8D.D485CB98@isd.uni-stuttgart.de> <15189.35598.403100.520462@sirius.net.home> <3B5580B1.186F375B@isd.uni-stuttgart.de> <15189.42523.133794.26662@transamoeba.dyndns.org> Message-ID: <3B56895A.E653095C@isd.uni-stuttgart.de> Charles G Waldman schrieb: > Nils Wagner writes: > > > > How can I rearrange the result of outerproduct to the result of > > Kronecker product with numpy ? > > > > def kron(a,b): > o = outerproduct(a,b) > o.shape = a.shape + b.shape > return concatenate(concatenate(o, axis=1), axis=1) What is the difference between kron(z,eye) and kron(yt,eye) ? Nils -------------- next part -------------- from Numeric import * def kron(a,b): o = outerproduct(a,b) o.shape = a.shape + b.shape return concatenate(concatenate(o, axis=1), axis=1) y = array(([5,6,7],[8,9,10])) print 'y' print print y print z = array(([5,8],[6,9],[7,10])) print 'z' print print z print yt = transpose(y) print 'yt' print print yt print eye = identity(2) a = kron(y,eye) print print 'kron(y,eye)' print print a print b = kron(z,eye) print print 'kron(z,eye)' print print b print c = kron(yt,eye) print print c print From chrishbarker at home.net Thu Jul 19 20:28:14 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 19 Jul 2001 17:28:14 -0700 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? References: Message-ID: <3B577B1E.EC592447@home.net> Hi all, I am using a 2-d array to store values that will be an index into a list. It is huge, sot to samve space I have used a type Int16. Now when I pull a value outl it is of type array, so it can not be used to index a sequence. The strange thing is that it works if the array is of rank 1. Some tests: >>> from Numeric import * >>> >>> l = range(10) # a test list >>> a = arange(10) # an array if Ints >>> print type(a[3]) #So this is an Int >>> print l[a[3]] 3 # and it can be used as an index. >>> a.shape = (2,5) #reshape it to be rank-2 >>> print type(a[1,3]) # still and Int >>> print l[a[1,3]] 8 # and still usable as an index. # now change the type >>> a = a.astype(Int16) >>> a.shape = (10,) >>> print type(a[3]) #it's an Int >>> a.shape = (2,5) # now change the shape to rank-2 >>> print type(a[1,3]) #!!!!!!!#### # Now a single item is of type 'array' >>> print l[a[1,3]] Traceback (most recent call last): File "", line 1, in ? TypeError: sequence index must be integer # and it can not be used as an index! I can work around this with an explicite type cast with int(), but it seems like wierd behaviour to me. I am accesing a single item, it is typcaste as an Int when the item is pulled out of a rank-1 array, but it is a rank-0 array when pulled from a rank > 1 array. Any ideas what causes this? Is there a good reson for htis, or is it a bug? -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From viennet at lipn.univ-paris13.fr Fri Jul 20 03:11:31 2001 From: viennet at lipn.univ-paris13.fr (Emmanuel Viennet) Date: Fri, 20 Jul 2001 09:11:31 +0200 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? References: <3B577B1E.EC592447@home.net> Message-ID: <3B57D9A3.C5D396F@lipn.univ-paris13.fr> Feature, I think. a[1,3] is a rank-0 array, with typecode Int16. There is no other way to handle a Int16 scalar in Python (Int16 is not a python type). This solution allows to correctly propagate the types in array arithmetic, without unwanted upcasts. Emmanuel Chris Barker wrote: > # now change the type > >>> a = a.astype(Int16) > >>> a.shape = (10,) > >>> print type(a[3]) > > #it's an Int > > >>> a.shape = (2,5) > # now change the shape to rank-2 > > >>> print type(a[1,3]) > > >>> print a[0,0].typecode() 's' # == Int16 >>> a[0,0].shape () # rank-0 array From hinsen at cnrs-orleans.fr Fri Jul 20 08:28:35 2001 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Fri, 20 Jul 2001 14:28:35 +0200 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? In-Reply-To: <3B57D9A3.C5D396F@lipn.univ-paris13.fr> (message from Emmanuel Viennet on Fri, 20 Jul 2001 09:11:31 +0200) References: <3B577B1E.EC592447@home.net> <3B57D9A3.C5D396F@lipn.univ-paris13.fr> Message-ID: <200107201228.OAA07664@chinon.cnrs-orleans.fr> > Feature, I think. Right, but a relatively recent one. In the first NumPy releases, the result was a scalar Integer object. There are good arguments for both variants. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From Peter.Bienstman at rug.ac.be Fri Jul 20 11:03:59 2001 From: Peter.Bienstman at rug.ac.be (Peter Bienstman) Date: Fri, 20 Jul 2001 17:03:59 +0200 Subject: [Numpy-discussion] suggested doc improvement: C API, fortran arrays Message-ID: <003b01c1112d$346fb0a0$0454c19d@intec.rug.ac.be> Hi, In chapter 14 of the docs (Writing a C extension to NumPy), the last section (a less simple example) deals with mixing Fortran and C code. Wouldn't it be useful to mention the topic of different storage orders there, and to reflect this in the code by swapping some stride parameters? Could avoid a lot of frustration... Peter ------------------------------------- Peter Bienstman Department of Information Technology INTEC/IMEC - Ghent University St.-Pietersnieuwstraat 41 B-9000 Gent - Belgium E-mail: Peter.Bienstman at rug.ac.be Tel: +32 9 264 3445 Fax: +32 9 264 3593 ------------------------------------- From chrishbarker at home.net Fri Jul 20 14:48:22 2001 From: chrishbarker at home.net (Chris Barker) Date: Fri, 20 Jul 2001 11:48:22 -0700 Subject: [Numpy-discussion] typecasting of single values form an array: Bug or feature? References: <3B577B1E.EC592447@home.net> <3B57D9A3.C5D396F@lipn.univ-paris13.fr> <200107201228.OAA07664@chinon.cnrs-orleans.fr> Message-ID: <3B587CF6.E5CD54F8@home.net> Konrad Hinsen wrote: > > > Feature, I think. > > Right, but a relatively recent one. In the first NumPy releases, the > result was a scalar Integer object. There are good arguments for both > variants. OK. I see that there are trade-offs either way, and I certainly see the benefit of keeping the precision consistent(even though it would be easier in this case to have th upcast). I do think it's a bug, however, to have the upcast when pulling a single value out of a 1-d array, but not when pulling it out of a higher rank array: >>> a = array(((1,2,3),(4,5,6)),Int16) >>> type(a[1,1]) >>> a.shape = (6,) >>> type(a[2]) >>> This seems totally inconsistant. Note that this same effect occurs for arrays of type Float16 (and probably others) By the way, would it be at all possible for Python to accept an array of rank 0 as an index? How big a change would that be? -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From jochen at unc.edu Fri Jul 20 16:05:21 2001 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 Jul 2001 16:05:21 -0400 Subject: [Numpy-discussion] Cygwin In-Reply-To: References: Message-ID: <8666cnqsce.fsf@bock.chem.unc.edu> >>>>> Paul F Dubois wrote on Tue, 17 Jul 2001 12:53:52 -0700: [patch to Src/fastumathmodule.c] Paul> This file is no longer in the distribution. So why was it changed today? > cvs log Src/fastumathmodule.c ,---- | RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v | Working file: Src/fastumathmodule.c | head: 1.2 | branch: | locks: strict | access list: | symbolic names: | keyword substitution: kv | total revisions: 2; selected revisions: 2 | description: | ---------------------------- | revision 1.2 | date: 2001/07/20 03:24:33; author: teoliphant; state: Exp; lines: +18 -0 | Added inverse hyperbolic functions. | ---------------------------- | revision 1.1 | date: 2001/07/16 23:19:23; author: teoliphant; state: Exp; | Added fastumathmodule which doesn't emit exceptions. | ============================================================================= `---- To get that straight: I am looking at the Repository "Numerical" at :pserver:anonymous at cvs.numpy.sourceforge.net:/cvsroot/numpy I hope that is the correct module for an uptodate version of NumPy. If so, I would suggest the following patch to have it link successfully on Cygwin: Index: Src/fastumathmodule.c =================================================================== RCS file: /cvsroot/numpy/Numerical/Src/fastumathmodule.c,v retrieving revision 1.2 diff -u -r1.2 fastumathmodule.c --- Src/fastumathmodule.c 2001/07/20 03:24:33 1.2 +++ Src/fastumathmodule.c 2001/07/20 20:01:33 @@ -2141,7 +2141,7 @@ {NULL, NULL, 0} /* sentinel */ }; -void initfastumath() { +DL_EXPORT(void) initfastumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ Thanks, Jochen -- University of North Carolina phone: 919-962-4403 Department of Chemistry phone: 919-962-1579 Venable Hall CB#3290 fax: 919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From romberg at fsl.noaa.gov Fri Jul 20 18:02:20 2001 From: romberg at fsl.noaa.gov (Mike Romberg) Date: Fri, 20 Jul 2001 16:02:20 -0600 (MDT) Subject: [Numpy-discussion] 20.1.0 undefined symbol: PyArray_API Message-ID: <15192.43628.309241.850260@smaug.fsl.noaa.gov> I have written a python module in C which is implemented as a loadable shared library. My module uses Numeric array objects and includes arrayobject.h. With Numeric-19 this used to work fine. Now my module will not load because the symbol PyArray_API is not found. I located this fellow in the arrayobject header file: /* C API address pointer */ #if defined(NO_IMPORT) || defined(NO_IMPORT_UFUNC) extern void **PyUFunc_API; #else #if defined(PY_UFUNC_UNIQUE_SYMBOL) void **PyUFunc_API; #else static void **PyUFunc_API; #endif So, it seems (at first glance) that this symbol is either static or extern based on the NO_IMPORT macro. My question is, can I just define NO_IMPORT before including arrayobject.h or does Numeric python need to be rebuilt so that this symbol gets exported? Thanks, Mike Romberg (romberg at fsl.noaa.gov) From vanroose at ruca.ua.ac.be Tue Jul 24 07:04:33 2001 From: vanroose at ruca.ua.ac.be (Wim Vanroose) Date: Tue, 24 Jul 2001 13:04:33 +0200 (METDST) Subject: [Numpy-discussion] Troubles with arrays Message-ID: Dear Numerical Python Users, I have a small program that produces array's that I want to import in Python. The code is organised in three files. 1) arraytest.h, 2) arraytest.c 3) testmodule.c. and the code is shown below. The function myTest() produces the array and is called from the test module. However, the program does not work! it crashes. In my opinion, I do not have yet enough insight in Numerical Python. Is there an essential part that I do not understand. Remarkable is that the pure Python equivalent of the program does not crash. Any ideas? Wim Vanroose ///////////////////////// //file: arraytest.h ////////////////////// #include "Python.h" #include "arrayobject.h" PyObject *myTest(void); ////////////////////// // file: arraytest.c //////////////////// #include "arraytest.h" PyObject * myTest(void ){ PyArrayObject *result; double *datainput; int dimensions[1]; int M=10; int MM; dimensions[0]=M; result = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); datainput =(double *)result->data; for(MM=0;MM < M ; MM++){ datainput[MM] = MM*0.1; } return PyArray_Return(result); } //////////////////// //file: test.c CRASHES!!!! //////////////// #include "arraytest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); import_array(); d = PyModule_GetDict(m); } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The Python Equivalent: DOES NOT CRASH %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ///////////// // file: simpletest.h ///////////////// #include "simpletest.h" PyObject * myTest(void); //////////////////// // file: test.c ////////////////////// #include "simpletest.h" PyObject * myTest(void ){ return Py_BuildValue("i",123); } //////////////// //file: test.c ////////////////// #include "simpletest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); d = PyModule_GetDict(m); } From nils.wagner at freenet.de Tue Jul 24 14:58:05 2001 From: nils.wagner at freenet.de (nils.wagner at freenet.de) Date: Tue, 24 Jul 2001 20:58:05 +0200 Subject: [Numpy-discussion] largest matrix element Message-ID: <200107241858.UAA26240@www6.emo.freenet-rz.de> Given a complex Matrix A(m,n) How can I get the absolute value of the largest matrix element very efficiently ? Nils Die sch?nen Seiten des Urlaubs bei Libri.de: Sonnige B?cher portofrei bestellen: http://www.libri.de/content/urlaub.html From cgw at alum.mit.edu Tue Jul 24 15:18:28 2001 From: cgw at alum.mit.edu (Charles G Waldman) Date: Tue, 24 Jul 2001 14:18:28 -0500 Subject: [Numpy-discussion] largest matrix element In-Reply-To: <200107241858.UAA26240@www6.emo.freenet-rz.de> References: <200107241858.UAA26240@www6.emo.freenet-rz.de> Message-ID: <15197.51716.109153.805370@nyx.dyndns.org> nils.wagner at freenet.de writes: > Given a complex Matrix A(m,n) > How can I get the absolute value of the largest matrix element > very efficiently ? How about sqrt(max((asarray(A)*conjugate(asarray(A))).real)) ? From ransom at cfa.harvard.edu Tue Jul 24 15:24:50 2001 From: ransom at cfa.harvard.edu (Scott Ransom) Date: Tue, 24 Jul 2001 15:24:50 -0400 Subject: [Numpy-discussion] largest matrix element References: <200107241858.UAA26240@www6.emo.freenet-rz.de> <15197.51716.109153.805370@nyx.dyndns.org> Message-ID: <3B5DCB82.5ABB343A@cfa.harvard.edu> Charles G Waldman wrote: > > nils.wagner at freenet.de writes: > > Given a complex Matrix A(m,n) > > How can I get the absolute value of the largest matrix element > > very efficiently ? > > How about > > sqrt(max((asarray(A)*conjugate(asarray(A))).real)) I if you want the global maximum you need a ravel in there: sqrt(max(ravel((asarray(a)*conjugate(asarray(a))).real))) Scott -- Scott M. Ransom Address: Harvard-Smithsonian CfA Phone: (617) 496-7908 60 Garden St. MS 10 email: ransom at cfa.harvard.edu Cambridge, MA 02138 GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989 From tim.hochberg at ieee.org Tue Jul 24 15:50:34 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Tue, 24 Jul 2001 12:50:34 -0700 Subject: [Numpy-discussion] largest matrix element References: <200107241858.UAA26240@www6.emo.freenet-rz.de> <15197.51716.109153.805370@nyx.dyndns.org> <3B5DCB82.5ABB343A@cfa.harvard.edu> <093c01c11477$8093acf0$87740918@cx781526b> <3B5DCE14.676B5A23@cfa.harvard.edu> Message-ID: <098c01c1147c$29ebbd20$87740918@cx781526b> Hi Scott, et al. First off I goofed -- that last reply should have gone to the list as a whole. Second, mere seconds after I pushed send I realized one problem with it: 'flat' only works for contiguous arrays. Its probably safer to use ravel after all, unless it's known that the array is contiguous. On the other hand, it would be slightly more efficient to ravel the matrix after taking its absolute value since ravel potentially allocates a new array and an array of Floats is going to be half the size of an array of Complexes. But then we know the resulting array is going to be contiguous. So after rewriting and erasing the thing a few times I end up with: max(abs(a).flat) Which is almost the same as my first one, except that the flat has been moved and now it should work when the array starts out noncontiguous. -tim > Hi Tim, > > Looks good to me! ;) > > Scott > > Tim Hochberg wrote: > > > > ----- Original Message ----- > > From: "Scott Ransom" > > Cc: ; > > Sent: Tuesday, July 24, 2001 12:24 PM > > Subject: Re: [Numpy-discussion] largest matrix element > > > > > Charles G Waldman wrote: > > > > > > > > nils.wagner at freenet.de writes: > > > > > Given a complex Matrix A(m,n) > > > > > How can I get the absolute value of the largest matrix element > > > > > very efficiently ? > > > > > > > > How about > > > > > > > > sqrt(max((asarray(A)*conjugate(asarray(A))).real)) > > > > > > I if you want the global maximum you need a ravel in there: > > > > > > sqrt(max(ravel((asarray(a)*conjugate(asarray(a))).real))) > > > > I must be missing something. What's wrong with: > > > > max(abs(a.flat)) ? > > > > -tim > > -- > Scott M. Ransom Address: Harvard-Smithsonian CfA > Phone: (617) 496-7908 60 Garden St. MS 10 > email: ransom at cfa.harvard.edu Cambridge, MA 02138 > GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989 From nwagner at isd.uni-stuttgart.de Wed Jul 25 04:15:26 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 25 Jul 2001 10:15:26 +0200 Subject: [Numpy-discussion] A question on vector and matrix norms Message-ID: <3B5E801E.97B18C01@isd.uni-stuttgart.de> Hi, I'm interested in efficient implementations of various vector and matrix norms. Please can anyone give me some short examples regarding the following norms for vectors : 1. Frobenius norm 2. L_1 norm is sum of absolute values 3. L_2 norm 4. L_\infty or maximum norm 5. p-norm and matrices: matrix spectral norm or matrix 2-norm Frobenius norm ||A||_F p-norms ||A||_p Thanks in advance. Nils From nwagner at isd.uni-stuttgart.de Wed Jul 25 04:39:36 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Wed, 25 Jul 2001 10:39:36 +0200 Subject: [Numpy-discussion] Matrix exponential Message-ID: <3B5E85C8.1817CB30@isd.uni-stuttgart.de> Hi, Has anyone written some functions concerning the matrix exponential expm(A) ? I am looking for demos illustrating the use of Pad? approximation, Taylor series approximation, and eigenvalues and eigenvectors, respectively, to compute the matrix exponential. Thanks in advance. Nils Reference : SIAM Review, Vol. 20 (1979) pp.801-836 Moler, van Loan "Nineteen dubious ways to compute the exponential of a matrix" From nwagner at isd.uni-stuttgart.de Thu Jul 26 10:56:12 2001 From: nwagner at isd.uni-stuttgart.de (Nils Wagner) Date: Thu, 26 Jul 2001 16:56:12 +0200 Subject: [Numpy-discussion] vec-operator Message-ID: <3B602F8C.9043A7EF@isd.uni-stuttgart.de> Hi, A matrix operation is that of stacking the columns of a matrix one under the other to form a single column. This operation is called "vec" or "cs" (c)olumn (s)tring Example A is a m * n matrix vec(A) = reshape(transpose(A),(m*n,1)) How can I copy the result of vec(A) into the i-th column of another matrix called B ? Thanks in advance. Nils From tim.hochberg at ieee.org Thu Jul 26 12:35:27 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 26 Jul 2001 09:35:27 -0700 Subject: [Numpy-discussion] vec-operator References: <3B602F8C.9043A7EF@isd.uni-stuttgart.de> Message-ID: <132901c115f0$fa76ab60$87740918@cx781526b> From: "Nils Wagner" > A matrix operation is that of stacking the columns of a > matrix one under the other to form a single column. > This operation is called "vec" or "cs" (c)olumn (s)tring > > Example > > A is a m * n matrix > > vec(A) = reshape(transpose(A),(m*n,1)) I assume you mean: def vec(A): reshape(transpose(A), (m*n,1)) First off, the following is a bit simpler and means you don't have to carray m and n around def vec(A): reshape(transpose(A), (-1,1)) > How can I copy the result of vec(A) into the i-th column of another > matrix called B ? B = zeros([m*n, p]) B[:,i:i+1] = vec(A) However, I don't think this is what you really want. I suspect you'd be happier with: B[:,i] = ravel(A) Ravel turns A into an m*n length vector [shape (m*n,)] instead of m*n by 1 array [shape (m*n,1)]. If all you want to do is insert it into B, this is going to be more useful. -tim From chrishbarker at home.net Thu Jul 26 14:46:06 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 26 Jul 2001 11:46:06 -0700 Subject: [Numpy-discussion] round, floor and ceil ? References: <00101808405300.01041@penguin.visionpro.com> Message-ID: <3B60656E.D068BEBB@home.net> Hi all, I was surprised to find that the functions: round, floor, and ceil are not included as ufuncs in NumPy. Have I just missed them? Where can I find them if they do exist? If they don't is there a reason for it, or has just no one gotten around to writing them? If the latter, can someone give me some pointers as to how I would go about writting them myself. It certainly seems as though it would be easy if modeled after the other unary ufuncs, but I'm a little unsure from the source where I would put it all. thanks, -Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From kern at caltech.edu Thu Jul 26 14:41:13 2001 From: kern at caltech.edu (Robert Kern) Date: Thu, 26 Jul 2001 11:41:13 -0700 Subject: [Numpy-discussion] round, floor and ceil ? In-Reply-To: <3B60656E.D068BEBB@home.net> References: <00101808405300.01041@penguin.visionpro.com> <3B60656E.D068BEBB@home.net> Message-ID: <20010726114113.A1116@myrddin.caltech.edu> On Thu, Jul 26, 2001 at 11:46:06AM -0700, Chris Barker wrote: > Hi all, > > I was surprised to find that the functions: > > round, floor, and ceil are not included as ufuncs in NumPy. > > Have I just missed them? Where can I find them if they do exist? Python 2.0.1 (#0, Jul 3 2001, 12:36:30) [GCC 2.95.4 20010629 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import Numeric >>> print Numeric.__version__ 20.1.0 >>> Numeric.floor >>> Numeric.ceil >>> Numeric.around The last one isn't a ufunc, but it's composed of them. I would guess that it's a function so that it can match Python's rounding behavior. -- Robert Kern kern at caltech.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From chrishbarker at home.net Thu Jul 26 15:53:16 2001 From: chrishbarker at home.net (Chris Barker) Date: Thu, 26 Jul 2001 12:53:16 -0700 Subject: [Numpy-discussion] round, floor and ceil ? References: <00101808405300.01041@penguin.visionpro.com> <3B60656E.D068BEBB@home.net> <20010726114113.A1116@myrddin.caltech.edu> Message-ID: <3B60752C.5F85EBDD@home.net> Robert Kern wrote: > >>> Numeric.floor > > >>> Numeric.ceil > > >>> Numeric.around > DOH! I had just been looking for round, but Ithought I had checked for ceil and floor as wel, but I guess not. sorry for the stupid question. I can point out that none of these is in the doc. Paul, is there any way any of us can contribute to the doc?? > The last one isn't a ufunc, but it's composed of them. ] It seems to act like one: >>> floor([3.3,3.5,3.6]) array([ 3., 3., 3.]) probably because it is composed of them. > a function so that it can match Python's rounding behavior. It does seem to match Python's native round, which makes me wonder why it can't be called "round", since it will behave the same for regulat python number types. NOt a big deal, of course. -thanks, Chris -- Christopher Barker, Ph.D. ChrisHBarker at home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------ From tim.hochberg at ieee.org Thu Jul 26 16:35:13 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 26 Jul 2001 13:35:13 -0700 Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) Message-ID: <149101c11612$795bdb50$87740918@cx781526b> "Curtis Jensen" wrote in message news:3B6076D4.68B6840C at bioeng.ucsd.edu... > the documenation for the "transpose" function for the "Numeric" module > seems to be incoorect, or at least missleading. The correct place for this is probably the numpy-discussion list, so I'm cc'ing it there. Perhaps the Paul Dubois will see it and have some ideas for clearing of the docs. > It says that transpose is suppose to return a "new" array. In fact it > does not. It returns a pointer to the same array, only with transposed > indicies. It's been a while since I looked at the NumPy docs, so I don't recall what conventions they use here. However, transpose does return a new array, it just points to the same data as the original. If a=transpose(b), "a is b" is false and "a.shape == b.shape" is false, so clearly they are different objects (i.e., different arrays). You know most of this, as you demonstrate down below, I just wanted to make the point that there is a difference between a new array and new data. Note that nearly every operation that can return a reference rather than a copy does so. Even slicing, if b=a[3:5], then 'b' holds a reference to the same data as 'a'. Some functions go so far to return a reference when they can, but otherwise copy. See ravel for example -- it copies the data if its argument is not contiguous, otherwise it uses a reference. Now _that_ can be confusing! Useful though. -tim > consider the example: > > Python 1.5.2 (#4, Sep 5 2000, 10:29:12) [C] on irix646 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> from Numeric import * > >>> foo = zeros([5,10]) > >>> bar = transpose( foo ) > >>> foo > array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) > >>> bar > array([[0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0]]) > >>> foo[0,2] = 1 > >>> foo > array([[0, 0, 1, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) > >>> bar > array([[0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [1, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0], > [0, 0, 0, 0, 0]]) > >>> > > > if bar was truely a new array, then changes to foo would not affect > bar. In the example above, it does. This way actualy works better for > my purposes, however, the documentation is missleading. > > -- > Curtis Jensen > cjensen at bioeng.ucsd.edu > http://www-bioeng.ucsd.edu/~cjensen/ > FAX (425) 740-1451 From Aureli.Soria_Frisch at ipk.fhg.de Fri Jul 27 13:14:04 2001 From: Aureli.Soria_Frisch at ipk.fhg.de (Aureli Soria Frisch) Date: Fri, 27 Jul 2001 19:14:04 +0200 Subject: [Numpy-discussion] Bug in RandomArray.multivariate_normal? In-Reply-To: <3B60656E.D068BEBB@home.net> References: <00101808405300.01041@penguin.visionpro.com> Message-ID: Hi, Folllowing could be a bug: >Traceback (most recent call last): > File "", line 1, in ? > File "macintosh hd:compiler:python >2.0:extensions:numerical:lib:packages:RandomArray.py", line 120, in >multivariate_normal > final_shape.append(mean.shape[0]) >AttributeError: 'tuple' object has no attribute 'append' should be: final_shape=final_shape+(mean.shape[0],) or am I missing something? Thanks ################################# Aureli Soria Frisch Fraunhofer IPK Dept. Pattern Recognition post: Pascalstr. 8-9, 10587 Berlin, Germany e-mail:aureli at ipk.fhg.de fon: +49 30 39006-150 fax: +49 30 3917517 ################################# From paul at pfdubois.com Fri Jul 27 15:03:12 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Fri, 27 Jul 2001 12:03:12 -0700 Subject: [Numpy-discussion] Troubles with arrays In-Reply-To: Message-ID: I don't know if someone helped you with this while I was on travel, but in case they didn't: I'm pretty sure your problem is that myTest is not in the same file as the import_array; when it tries to access the Numeric C API, it will be dereferencing zero. For extensions that are not in one file, a special techniques is required. Recently an improvement was added to make this easier. I believe you should add this to your header file, above the include of arrayobject.h: #define PY_ARRAY_UNIQUE_SYMBOL xxxx where xxxx is any name you choose that won't conflict with your other stuff. I hope that if I have this wrong somebody will correct me. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Wim Vanroose Sent: Tuesday, July 24, 2001 4:05 AM To: numpy-discussion at lists.sourceforge.net Subject: [Numpy-discussion] Troubles with arrays Dear Numerical Python Users, I have a small program that produces array's that I want to import in Python. The code is organised in three files. 1) arraytest.h, 2) arraytest.c 3) testmodule.c. and the code is shown below. The function myTest() produces the array and is called from the test module. However, the program does not work! it crashes. In my opinion, I do not have yet enough insight in Numerical Python. Is there an essential part that I do not understand. Remarkable is that the pure Python equivalent of the program does not crash. Any ideas? Wim Vanroose ///////////////////////// //file: arraytest.h ////////////////////// #include "Python.h" #include "arrayobject.h" PyObject *myTest(void); ////////////////////// // file: arraytest.c //////////////////// #include "arraytest.h" PyObject * myTest(void ){ PyArrayObject *result; double *datainput; int dimensions[1]; int M=10; int MM; dimensions[0]=M; result = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE); datainput =(double *)result->data; for(MM=0;MM < M ; MM++){ datainput[MM] = MM*0.1; } return PyArray_Return(result); } //////////////////// //file: test.c CRASHES!!!! //////////////// #include "arraytest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); import_array(); d = PyModule_GetDict(m); } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The Python Equivalent: DOES NOT CRASH %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ///////////// // file: simpletest.h ///////////////// #include "simpletest.h" PyObject * myTest(void); //////////////////// // file: test.c ////////////////////// #include "simpletest.h" PyObject * myTest(void ){ return Py_BuildValue("i",123); } //////////////// //file: test.c ////////////////// #include "simpletest.h" static PyObject *function(PyObject *self, PyObject *args){ return myTest(); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); d = PyModule_GetDict(m); } _______________________________________________ Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion From oliphant.travis at ieee.org Fri Jul 27 09:55:04 2001 From: oliphant.travis at ieee.org (Travis Oliphant) Date: Fri, 27 Jul 2001 13:55:04 +0000 Subject: [Numpy-discussion] Troubles with arrays In-Reply-To: References: Message-ID: <01072713550400.14723@travis> On Fri, 27 Jul 2001, Paul F. Dubois wrote: > I don't know if someone helped you with this while I was on travel, but in > case they didn't: > I tested his code on my machine and found that by placing an import_array() statement in the subroutine which uses the C-API seems to work. > I'm pretty sure your problem is that myTest is not in the same file as the > import_array; when it tries to access the Numeric C API, it will be > dereferencing zero. For extensions that are not in one file, a special > techniques is required. Recently an improvement was added to make this > easier. I believe you should add this to your header file, above the > include of arrayobject.h: > > #define PY_ARRAY_UNIQUE_SYMBOL xxxx > > where xxxx is any name you choose that won't conflict with your other > stuff. > From paul at pfdubois.com Fri Jul 27 19:13:30 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Fri, 27 Jul 2001 16:13:30 -0700 Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) In-Reply-To: <149101c11612$795bdb50$87740918@cx781526b> Message-ID: I will try to put a note in the transpose section if there isn't one there already. As noted, there are numerous reference-instead-of-a-copy returns in Numeric which reflect the speed rather than safety orientation of the original designer. Many complaints of this nature are a complaint about that choice, which made a package that was harder to understand and more difficult to use safely but which is about as fast as possible. I didn't like some of these choices but then again I didn't do the work. -----Original Message----- From: numpy-discussion-admin at lists.sourceforge.net [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Tim Hochberg Sent: Thursday, July 26, 2001 1:35 PM To: numpy-discussion at lists.sourceforge.net Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) "Curtis Jensen" wrote in message news:3B6076D4.68B6840C at bioeng.ucsd.edu... > the documenation for the "transpose" function for the "Numeric" module > seems to be incoorect, or at least missleading. The correct place for this is probably the numpy-discussion list, so I'm cc'ing it there. Perhaps the Paul Dubois will see it and have some ideas for clearing of the docs. From tim.hochberg at ieee.org Fri Jul 27 19:48:22 2001 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Fri, 27 Jul 2001 16:48:22 -0700 Subject: [Numpy-discussion] Re: Numeric.transpose (incorrect documentation) References: Message-ID: <1cf601c116f6$9f2962a0$87740918@cx781526b> From: "Paul F. Dubois" > I will try to put a note in the transpose section if there isn't one there > already. As noted, there are numerous reference-instead-of-a-copy returns in > Numeric which reflect the speed rather than safety orientation of the > original designer. Many complaints of this nature are a complaint about that > choice, which made a package that was harder to understand and more > difficult to use safely but which is about as fast as possible. I didn't > like some of these choices but then again I didn't do the work. Hmmm.... I tend to think that the reference semantics were the right choice, at least for the lower level C implementation, since it's relatively easy to build copy semantics on top of reference semantics, but not vice versa (except, perhaps for slicing). Even now it would be pretty easy to build a pure python ncNumeric[1], where copy was the default. One could even make transpose do something sensible: import ncNumeric as ncn # C is a contiguous array # N is a noncontiguous array # Both of these would return a transposed copy ncn.transpose(C) ncn.transpose(N) # This returns a transposed reference ncn.transpose(C, copy=0) # And this raises an exception. ncn.transpose(N, copy=0) That'd be kinda cool. -tim [1] nc for nonconfusing. I thought about using 'safe', but Numeric is unlikely to ever be remotely safe.... From vanroose at ruca.ua.ac.be Mon Jul 30 03:42:38 2001 From: vanroose at ruca.ua.ac.be (Vanroose Wim) Date: Mon, 30 Jul 2001 09:42:38 +0200 Subject: [Numpy-discussion] Troubles with arrays, proposal for Solution Message-ID: <3B650FEE.50304@ruca.ua.ac.be> Dear Numerical Python Users, It is now clear to me, after the comments of Travis Oliphant, Paul Dubois and Phil Austin, that in EVERY C-file that uses NumPy extensions, the "import_array" statement must be present. However, after some try-outs with parts my code, it seems not a good idea to allow a diffusion of the "import_array" statement and "PyArrayObject" throughout the "C" code. The code becomes unclear by the mixing of Python concepts and C concepts. Therefore it is, in my opinion, a good rule to limit the use of NumPy to the interface between python and "C" code; i.e. the function where the python parameters are read and the PyArrayObject is created. Do more experienced NumPy users agree??? The code below illustrates the limited use of NumPy parts. Wim Vanroose ///////////////////////// //file: arraytest.h ////////////////////// #include "Python.h" #include "arrayobject.h" double *myTest(void); ////////////////////// // file: arraytest.c //////////////////// #include "arraytest.h" double * myTest(void ){ double *result; ... return result; } //////////////////// //file: test.c //////////////// #include "arraytest.h" static PyObject *function(PyObject *self, PyObject *args){ ... int dimensions[2]; dimensions[0] = N; dimensions[1] = N; PyArrayObject *result ; result = (PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_DOUBLE); double *data; data = myTest(); memcpy(result->data,data,N*N*sizeof(double)); return PyArray_Return(result); } static PyMethodDef testMethods[] = { {"test",function,1}, {NULL,NULL} }; extern "C" { void inittest(){ PyObject *m,*d; m = Py_InitModule("test", testMethods); import_array(); d = PyModule_GetDict(m); } From phil at geog.ubc.ca Mon Jul 30 18:29:20 2001 From: phil at geog.ubc.ca (Phil Austin) Date: Mon, 30 Jul 2001 15:29:20 -0700 (PDT) Subject: [Numpy-discussion] Troubles with arrays, proposal for Solution Message-ID: <15205.57280.42626.794650@curlew.geog.ubc.ca> Vanroose Wim writes: > Dear Numerical Python Users, > > It is now clear to me, after the comments of Travis Oliphant, > Paul Dubois and Phil Austin, that in EVERY C-file that uses NumPy > extensions, the "import_array" statement must be present. Actually, what I was trying to say (in a message that didn't make it to the list) is the opposite -- import_array must be present in only one file. So below I would do something like: (my additions marked by PA>) > > ///////////////////////// > //file: arraytest.h > ////////////////////// > > #include "Python.h" PA> #define PY_ARRAY_UNIQUE_SYMBOL paArray > #include "arrayobject.h" > > double *myTest(void); > > ////////////////////// > // file: arraytest.c > //////////////////// > PA> #define NO_IMPORT_ARRAY > #include "arraytest.h" > > double * myTest(void ){ > double *result; > ... > > return result; > } > > //////////////////// > //file: test.c > //////////////// > #include "arraytest.h" > > static PyObject *function(PyObject *self, PyObject *args){ > > ... > int dimensions[2]; > > dimensions[0] = N; > dimensions[1] = N; > > PyArrayObject *result ; > result = (PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_DOUBLE); > > double *data; > data = myTest(); > memcpy(result->data,data,N*N*sizeof(double)); > return PyArray_Return(result); > } > > static PyMethodDef testMethods[] = { > {"test",function,1}, > {NULL,NULL} > }; > > extern "C" { > void inittest(){ > PyObject *m,*d; > m = Py_InitModule("test", testMethods); > import_array(); > d = PyModule_GetDict(m); > } > You should see the following when you run /lib/cpp -E on these files: in arraytest.c #define NO_IMPORT_ARRAY #include "arraytest.h" will produce a line like: extern void **paArray; but in test.c #include "arraytest.h" will produce: void **paArray; and import_array(); will expand to { PyObject *numpy = PyImport_ImportModule("_numpy"); if (numpy != 0) { PyObject *module_dict = PyModule_GetDict(numpy); PyObject *c_api_object = PyDict_GetItemString(module_dict, "_ARRAY_API"); if (((c_api_object)->ob_type == &PyCObject_Type)) { paArray = (void **)PyCObject_AsVoidPtr(c_api_object); } } }; The result is that there is a single global function pointer array called paArray that has its space reserved in test.c, and is referenced externally in arraytest.c. This allows you to use any numeric api call in either file. If you compile the module to, say, test.so on unix you should see something like this when you do a nm -D: ~phil% nm -D test.so | grep paArray 000a3d00 B paArray i.e. one instance of paArray in the data segment of the so file. Scanning the output of /lib/cpp -E output is a good way to get a feel for this (on unix anyway). Regards, Phil From paul at pfdubois.com Tue Jul 31 11:18:23 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 31 Jul 2001 08:18:23 -0700 Subject: [Numpy-discussion] RE: [Numpy-developers] Error behavior. (2) In-Reply-To: Message-ID: I understand why some people might want the behavior (return with inf or NaN etc in arrays rather than get an exception). Let's ask some basic questions. Having done such an operation, how do I tell if I have any errant values in the result? For example, what can I compare x[i] to, in order to know if it is invalid? We have had several requests for full support of IEEE but nobody knows how to do it portably, as far as I know. I resist bringing back fastumath because I wonder if it really would work portably, I don't know the answers to the simpleest questions like the above, and if it would I know that it made people reluctant to fix bugs or add new functions because they would have to do it twice. Adding a new function already requires something like five different places to fix. Using optional package MA, a user *can* achieve the goal you desire. For example, if x and y are numpy arrays, and I want to divide them without possibility of error, I can do: z = MA.masked_array(x) / MA.masked_array(y) if MA.getmask(z) is not None: print "Your operation failed in one or more components" The masked_array constructor does not copy its argument. (MAs mix with Numerics and scalars, so one of the masked_array calls above could be omitted.) >From a Windows session: >>> print x/y [ 1.#INF0000e+000, 2.00000000e+000, 1.50000000e+000, 1.33333333e+000,] >>> print MA.masked_array(x)/y [-- ,2.0 ,1.5 ,1.33333333333 ,] >>> >>> print MA.sqrt(y-2.) [-- ,-- ,0.0 ,1.0 ,] I realize this isn't exactly what you had in mind, and it is more expensive than just letting it rip, but it is reliable and portable. With the infs and Nans, I'm not sure what you can do with the answer other than print it. It does place the burden on the programmer to distinguish cases where he wants to survive a divide by zero from those where he does not, but in my mind that is a good thing. Paul From paul at pfdubois.com Tue Jul 31 11:22:53 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 31 Jul 2001 08:22:53 -0700 Subject: [Numpy-discussion] RE: [Numpy-developers] Error behavior. In-Reply-To: Message-ID: Numpys, This is Travis' original message to the developers list, discussing his ideas for dealing with floating point errors. When I answered him a minute ago I inadvertently posted to this list instead. But, it is a good idea to have everyone's thoughts. I only ask that you keep the noise down and not have this degenerate into the numerous IEEE discussions we have had before. Paul P.S. I still am looking for help on solving the Numeric bug on Alphas. -----Original Message----- From: numpy-developers-admin at lists.sourceforge.net [mailto:numpy-developers-admin at lists.sourceforge.net]On Behalf Of Travis Oliphant Sent: Monday, July 23, 2001 12:46 PM To: numpy-developers at lists.sourceforge.net Subject: [Numpy-developers] Error behavior. Many have noticed that with one of the newer Python releases, domain and range errors on one of the computations in an element-by-element umath function now always raise Python errors. It used to be that one could say: >>> x = arange(1,10) >>> y = arange(0,9) >>> print x/y and get an output with reasonable values in positions 1..9 of the output array but get an inf in the first position (how inf printed was platform specific). Many, including me, prefer returning an array with some undefined entries rather than raising an error and ruining the rest of the perfectly valid computations. Proposed solutions: 1) Make a new module (bring back the old fastumathmodule), which does not set the "check" flag when the ufunc is created so that error are not raised --- quick and fast fix. 2) Use the warnings framework so that rather than raise a Python error, a warning is issued. This allows the user to do what they want with the warning (from raise an error to ignore it). --- this feels like a better solution. Please let me know your position on this, so we can take action if warranted. Sincerely, Travis Oliphant _______________________________________________ Numpy-developers mailing list Numpy-developers at lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-developers From paul at pfdubois.com Tue Jul 31 19:36:47 2001 From: paul at pfdubois.com (Paul F. Dubois) Date: Tue, 31 Jul 2001 16:36:47 -0700 Subject: [Numpy-discussion] Help: need info on Fortran/C mixing on Windows Message-ID: Any fellow nummies and Pythonistas out there with experience using Digital Fortran on Windows? I'm trying to get Pyfort to work with Visual Fortran / Visual C++ on Windows. I am not usually a Windows developer so I do not know how to do things like look at an object file to see what names are in it (as I could do with nm on Unix). I have discovered that by including c$DEC ATTRIBUTES C:: foo in my Fortran, where foo is the name of my Fortran function, that my missing external for foo disappears. This is not really ok as I want to be able to link to unmodified Fortran files that have simply been compiled into a foostuff.lib file. I need information such as: How to get the names to match up, or what name to generate in my C to correspond to the Fortran; Which library to load with: I've tried dfor.lib and dformd.lib, in the context of running a python extension link through distutils, and both complain vociferously about library conflicts. If this was my working life I could afford to put in the time to figure all this out, but this is pro bono publico and I would appreciate your tolerance of my asking for help. Even just your Makefile or setup.py from a successful project of this type would be a big help. Thanks, Paul Dubois