C API: how to replace python number object in place?

2009-05-14 Thread Stephen Vavasis
If x is a C variable of type PyObject*, and I happen to know already that 
the object is of a numeric type, say int, is there a way to change the 
value of x in place to a different number?  In the C/API documentation I 
found routines to increment or decrement it in place, but I didn't find a 
routine to simply replace its value by a different value.  (I suppose I 
could change it to the new value via an increment or decrement, but this 
is ugly as well as being susceptible to overflow problems and roundoff 
errors in the case of floats.)

Thanks,
Steve Vavasis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C API: how to replace python number object in place?

2009-05-14 Thread Stephen Vavasis
In my previous posting, I inquired how to change a python numeric object 
in place.  Several people responded that this is not possible.  Perhaps I 
should explain the larger problem that I am trying to solve, and then the 
solution will become apparent.  I have a C routine R that invokes a Python 
routine S repeatedly.  This Python routine S takes three arguments, two 
floats and an integer.  I have read the documentation explaining how R can 
use the C API to construct an argument list for invoking S.  The issue 
that baffles me is that, as far as I can tell, each time R invokes S 
again, it needs to deallocate and reallocate the three arguments.  It 
would seem be much more efficient if R could create the argument list once 
and then modify the values inside of it for each subsequent invocation of 
S.

-- Steve Vavasis


In article ,
Scott David Daniels   wrote:

>If you do figurte out how to do what you want, you will put us in the
>old FORTRAN trap:  People can write code that changes the value of a
>constant.
>The code:
> month = 12 # make it december
> inches_per_foot = 12
> make_previous(month)
> print ('Month is now: %s, inches_per_foot = %s' % (
>month, inches_per_foot))
>might print:
> Month is now: 11, inches_per_foot = 11
>
>--Scott David Daniels
>scott.dani...@acm.org


-- 
http://mail.python.org/mailman/listinfo/python-list


array of 64-bit ints?

2008-05-23 Thread Stephen Vavasis
Is it possible to have an array of 64-bit-ints using the standard Python 
array module?  On my 64-bit architecture (AMD64, MSVC), both "int" and 
"long int" are 32 bit integers.  To declare 64-bit ints, one needs either 
"long long int" or "size_t".  However, according to the Python array 
documentation, arrays of "size_t" or "long long int" are not available.

Thanks,
Steve Vavasis, [EMAIL PROTECTED]


--
http://mail.python.org/mailman/listinfo/python-list