473,769 Members | 6,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Numeric C extension: bug or error ?

Hi,

I don't understand this strange behaviour:

I compile this code :

#include <Python.h>
#include"Numeri c/arrayobject.h"

static PyObject *
return_vector(P yObject *self, PyObject *args)
{
PyObject *input1;
PyArrayObject *vector;

if (!PyArg_ParseTu ple(args, "O", &input1))
return NULL;

vector = (PyArrayObject
*)PyArray_Conti guousFromObject (input1,PyArray _DOUBLE, 1, 1);

if (vector == NULL)
return NULL;

return PyArray_Return( vector);

}

/* registration table */
static struct PyMethodDef testMethods[] = {
{"return_vector ", return_vector, 1}, /* method name, C
funcptr, always-tuple */
{NULL, NULL} /* end of table marker */
};

/* module initializer */
void inittest() /* called on first import */
{ /* name matters if loaded
dynamically */
(void) Py_InitModule(" test",testMetho ds); /* mod name, table ptr */
import_array(); /* indispensable pour utiliser les arrays */
}

Very simple: this module takes a Numeric array (vector) as argument and
send this array back to python...

If I compile it under macOSX, the result in python is:
import test
from Numeric import *
v=array([1.0,2.0,3.0,4.0],Float)
v array([ 1., 2., 3., 4.]) test.return_vec tor(v) array([ 1., 2., 3., 4.])

but in linux the result is:
import test
from Numeric import *
v=array([1.0,2.0,3.0,4.0],Float)
v array([ 1., 2., 3., 4.]) test.return_vec tor(v) array([ 1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j])

Strange !!! the result is a complex array.
The C vector is really complex because if I try to use it in the C module,
the result is...incomplete .
For example, if I try to multiply each item of the vector array by a
scalar ( pi for example) in a loop, I get this result in python:

import test
from Numeric import *
v=array([1.0,2.0,3.0,4.0],Float)
test.return_vec tor(v)

array([ 3.14159265+0.j, 0.+0.j, 6.28318531+0.j, 0.+0.j])

It's the result of pi* 1.0, 0.0, 2.0, 0.0 ( the four first elements of the
internal representation of the complex array ([ 1.+0.j, 2.+0.j, 3.+0.j,
4.+0.j]).

Anyone any idea where I'm going wrong?
Thank you for any help.

Philippe
Jul 18 '05 #1
1 1740
At some point, ve************* *@wanadoo.fr (Philippe Grosse) wrote:
Hi,

I don't understand this strange behaviour:

I compile this code : [code clipped; it looks good]
.... /* registration table */
static struct PyMethodDef testMethods[] = {
{"return_vector ", return_vector, 1}, /* method name, C
funcptr, always-tuple */
{NULL, NULL} /* end of table marker */
};
Instead of the magic constant "1", use METH_VARARGS.

.... Very simple: this module takes a Numeric array (vector) as argument and
send this array back to python...

If I compile it under macOSX, the result in python is:
import test
from Numeric import *
v=array([1.0,2.0,3.0,4.0],Float)
v array([ 1., 2., 3., 4.]) test.return_vec tor(v) array([ 1., 2., 3., 4.])

but in linux the result is:
import test
from Numeric import *
v=array([1.0,2.0,3.0,4.0],Float)
v array([ 1., 2., 3., 4.]) test.return_vec tor(v)

array([ 1.+0.j, 2.+0.j, 3.+0.j, 4.+0.j])


This isn't what I get; I get the same result under linux as you get
from Mac OS X. Have you checked that the copies of the code are the
same?

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)phy sics(dot)mcmast er(dot)ca
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1036
by: Unixtrekkor | last post by:
I am unable to successfully compile Numeric 23-3.3. I running python 2.3.4. Running python setup.py install yields the following error: running install running build running build_py running build_ext building 'lapack_lite -I ./Include Src/lapack_litemodule.c' extension creating /Include Src creating /Include Src/lapack_litemodule
7
3009
by: Jive | last post by:
Here's my sitch: I use gnuplot.py at work, platform Win32. I want to upgrade to Python 2.4. Gnuplot.py uses extension module Numeric. Numeric is now "unsupported." The documentation says "If you are new to Numerical Python, please use Numarray.". It's not that easy, dangit. The download page for numpy does not contain a 2.4 version of Numeric, and I suspect they do not intend to release one, because there IS a 2.4 version of...
0
1528
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade woes: Numeric, gnuplot, and Python 2.4 Date: 2004-12-11 18:45:10 PST > Here's my sitch: > > I use gnuplot.py at work, platform Win32. > I want to upgrade to Python 2.4.
4
2504
by: Chris Weisiger | last post by:
I'm trying to install numeric on my MacOS X box using Darwin, with the eventual goal of satisfying all of PyGame's dependencies so I can finally start working on my semester project. I would be using MacPython, except that I can't seem to get its Package Manager to work. Anyway, when I try to install numeric, I get the following error: chriswei% sudo ./setup.py install Password: running install running build
5
3399
by: Jeffry van de Vuurst | last post by:
Hi, I'm working on an xml schema and I'm running into some problems relating substitutionGroups and extensions. This xsd validates fine: There are three elements and three complex types and every element has the type of some complexType. <?xml version="1.0" encoding="UTF-8"?>
0
2146
by: robert | last post by:
Hi all, I'm having a hard time resolving a namespace issue in my wsdl. Here's an element that explains my question, with the full wsdl below: <definitions name="MaragatoService" targetNamespace="http://swaMaragatoNS" xmlns:tns="http://swaMaragatoNS" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
2
2278
by: goetzie | last post by:
I am using Python 2.4.1 and Numeric 23.8 and running on Windows XP. I am passing a Numeric array of strings (objects) to a C Extension module using the following python code: import Numeric import TestDLL # my C Extension Module a = Numeric.array(, 'O' ) print 'a =', a print 'type a =', type(a)
11
2580
by: ZMY | last post by:
Dear all, I am a real newbie for both python and QNX, but I am still trying to compile Numeric-24.2 under QNX4.25 with python 2.2. I got following error message: $ sudo python setup.py install Password: running install
2
1274
by: Arthur Dent | last post by:
Hi all... I'm playing around experimenting with Extensions and R&D'ing what's new. There's a procedure I would like to add to numbers, and I was wondering, is there any "base" number type, that I could put an extension on, as opposed to manually adding it to all the numeric types... decimal, double, single, long, short, etc... ?? Cheers!
0
9587
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.