Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > "bad argument type for built-in operation"

Reply
Thread Tools

"bad argument type for built-in operation"

 
 
Gilles Arnaud
Guest
Posts: n/a
 
      01-24-2005
Hello,

I've got a nasty bug and no idea to deal with :

here is the method :
<method>
def denormer(self, var) :
" denorme un vecteur d'entree "
try:
#a = map(self.decerner, self.param, var)
#a = [self.decerner(x, y) for x, y in map(None,
self.param, var)]
a = []
print 'in', None, self.param, var, len(self.param),
len(var), str(self.decerner)
#return map(undoc, self.param, var)
print map(None, var)
print map(None, self.param)
#print zip(var, var)
#print zip(self.param, self.param)
#print map(lambda x, y: (x,y), self.param, var)
#print zip(self.param, var)
b = []
print '$',
ii = range(len(var))
print ii, '$',
for i in ii :
print '%',
b.append((self.param[i], var[i]))
print b, '/',
print '$',
print b
for x,y in b :
print x, y
z = undoc(x, y)
print z
a.append(z)
except TypeError, c :
print 'E', str(self.decerner), self.param, var
print 'E2', str(c)
raise
return a
</method>
in fact the method was initially reduce to
<method>
return map(self.decerner, self.param, var)
</method>
all the commented line produced the same exception raised

this method unnormalize an input vector (var)

and the trace
<trace>
in None [(-2.0, 2.0), (-2.0, 2.0)] [0.1385039192456847,
0.87787941093093491] 2 2 <function undo at 0x81ff94c>
[0.1385039192456847, 0.87787941093093491]
[(-2.0, 2.0), (-2.0, 2.0)]
$ [0, 1] $ % [((-2.0, 2.0), 0.1385039192456847)] / % [((-2.0,
2.0), 0.1385039192456847), ((-2.0, 2.0), 0.87787941093093491)] / $
[((-2.0, 2.0), 0.1385039192456847), ((-2.0, 2.0),
0.87787941093093491)]
(-2.0, 2.0) 0.138503919246
% 0.277007838491
(-2.0, 2.0) 0.877879410931
% 1.75575882186
in None [(-2.0, 2.0), (-2.0, 2.0)] [0.38111874838950943,
0.74880175070169164] 2
2 <function undo at 0x81ff94c>
[0.38111874838950943, 0.74880175070169164]
[(-2.0, 2.0), (-2.0, 2.0)]
$ [0, 1] $ % [((-2.0, 2.0), 0.38111874838950943)] / % [((-2.0,
2.0), 0.38111874838950943), ((-2.0, 2.0), 0.74880175070169164)] /
E <function undo at 0x81ff94c>
[(-2.0, 2.0), (-2.0, 2.0)] [0.38111874838950943, 0.74880175070169164]
E2 bad argument type for built-in operation

[...]
</trace>

the first call of the methode succeed
all following call failed.

I've got different scenario which call this low level methode,
many succeed, some failed this way.

what's happened ?
If someone got an idea ?
what can raise this exception ?

My program is written partially in python and partially in C.
the top level is in python which call a C optimisation routine
which use a callback (PyObject_CallMethod) to evaluate the cost in
python again.
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      01-24-2005

Gilles Arnaud wrote:
> Hello,
>
> I've got a nasty bug and no idea to deal with :
>
> here is the method :


Big snip. The Python code is unlikely to be your problem.

> and the trace
> <trace>
> in None [(-2.0, 2.0), (-2.0, 2.0)] [0.1385039192456847,
> 0.87787941093093491] 2 2 <function undo at 0x81ff94c>
> [0.1385039192456847, 0.87787941093093491]


That's a very mangled trace!

> the first call of the methode succeed
> all following call failed.


So the first call is leaving a bomb behind.

>
> I've got different scenario which call this low level methode,
> many succeed, some failed this way.
>
> what's happened ?
> If someone got an idea ?
> what can raise this exception ?


At this stage, without the benefit of look-ahead, one could only blame
gamma rays or pointy-eared aliens

>
> My program is written partially in python and partially in C.
> the top level is in python which call a C optimisation routine
> which use a callback (PyObject_CallMethod) to evaluate the cost in
> python again.


Aha! *Now* you tell us. *You* have "denormalised" the stack. Read your
C code carefully. Use a debugger, or put some "printf()" in it. With
PyObject_CallMethod, do the format descriptors and the arguments match?
Are you testing the returned value for NULL and acting accordingly? Is
the called-from-C Python method ever executed? Try putting a print
statement (that shows the args) at the top. More generally, are you
testing the returned value from each and every C API call? Are you
testing for the correct error value (some return NULL, some -1, ...)?
Are you doing the right thing on error?

A catalogue of the different ways of messing things up using C would
take forever to write. If you can't find your problem, post the code,
either on the newsgroup or as a web page.

Hope this helps,
John

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’ Seebs C Programming 9 09-17-2009 07:36 PM
compiler error: argument of type "VALUE *" is incompatible with parameter of type "VALUE" me2faster@excite.com Ruby 1 05-05-2005 11:23 PM
Function pointers, variable argument functions calling other variable-argument functions (sort of) S?ren Gammelmark C Programming 1 01-07-2005 09:41 PM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM
defaulting argument to previous argument Bhushit Joshipura C++ 5 12-30-2003 03:21 PM



Advertisments