The change for rpy2 fixes for my very own mistake.
What I had missing was obvious (well, once I found it... it kept me
wondering a little while):
 a call to R_PreserveObject() to protect a newly created R "SEXP" (and this
when RPy vectors are created out of python sequences).

rpy2 and rpy differ a fair bit from each other (a very significant
proportion of design, and therefore of the code, changed), and the fix
cannot be applied to rpy as it is.

The mechanism used to protect anonymous R objects (i.e., no symbol in
R) exposed to Python is "similar", with a list containing the
references to be protected.
But the implementation differs may be because rpy's implementation
came first, before something similar appeared in R's C API. rpy uses
its own implementation while rpy2 uses the one shipped with R.

I had a quick look at rpy's code again: check around calls to
"seq_to_R" in rpy's rpymodule.c to see if a similar problem is
happening there.
(I can't promise that this is the case).


L.



2008/7/21 laurent oget <[EMAIL PROTECTED]>:
> That is good to hear. If I have a look at the change you made on rpy2, do
> you think there is any hope i will be able to patch rpy1? I do not know much
> about rpy yet, but if you think that is do-able this would give me a good
> pretext to learn.
>
> Laurent
>
> 2008/7/21 Laurent Gautier <[EMAIL PROTECTED]>:
>>
>> I fixed a problem with rpy2 (the fix is in SVN)
>> It does seem to fit happily a lot of linear models without problems now.
>>
>> For the moment rpy-1.x, calling R's gc() is the only known workaround, I
>> think.
>>
>>
>> ##---
>>
>>
>> #
>> # brutal and naive strategy for model selection:
>> #   fit all possible two-variable models
>> #
>> # The purpose is of this is code to try reproducing
>> # an elusive bug when iteratively fitting a lot of models.
>> #
>> # Here, we are iterating nvariable * (nvariables-1) times.
>> #
>>
>> import rpy2.robjects as ro
>> import array
>> import random
>>
>> # build pool of variables
>> nvariables = 75
>> variables = {}
>> for v_i in range(nvariables):
>>    a_i = array.array('f', [random.random() for i in xrange(1000)])
>>    rv_i = ro.RVector(a_i)
>>    variables['v%i' %v_i] = rv_i
>>
>> # create a dummy response variable
>> y = variables['v1'].r + variables['v2']
>>
>>
>> # fit all pairwise combinations
>> dataframe = ro.r['data.frame']
>> lm = ro.r['lm']
>>
>> res = []
>> for v1_i in range(nvariables):
>>    for v2_i in xrange(v1_i+1):
>>        subvarnames = ['v%i' %x for x in [v1_i, v2_i]]
>>        subvar = dict([(x, variables[x]) for x in subvarnames])
>>        subvar['y'] = y
>>        dataf = dataframe(**subvar)
>>        fit = lm('y ~ %s + %s' %(subvarnames[0], subvarnames[1]),
>>                 data=dataf)
>>        sumfit = ro.r.summary(fit)
>>        rsq = sumfit.r['adj.r.squared'][0][0]
>>
>>        res.append((v1_i, v2_i, rsq))
>>
>> ## check R2 == 1 for the pair (v1, v2)
>> [x for x in res if x[2] == 1]
>>
>>
>>
>>
>> L.
>>
>>
>>
>>
>>
>>
>> 2008/7/18 Laurent Gautier <[EMAIL PROTECTED]>:
>> > 2008/7/18 Laurent Gautier <[EMAIL PROTECTED]>:
>> >> 2008/7/17 laurent oget <[EMAIL PROTECTED]>:
>> >>>
>> >>>
>> >>> 2008/7/17 Laurent Gautier <[EMAIL PROTECTED]>:
>> >>>>
>> >
>> >> It might not really be a race condition, but more an overzealous
>> >> garbage collection.
>> >> R does not have reference counting, and objects without an associated
>> >> symbol/name
>> >> in the R space can be flagged as "protected" from garbage collection.
>> >> The removal of
>> >> the protection is recursive, I think,
>> >
>> > Just a work of caution: I I might not be thinking right. After
>> > checking R's source, I am
>> > not sure that contained elements in a "preserved" container are
>> > recursively unprotected.
>> > There is more that I do not know about R's memory management than I
>> > thought...
>> >
>
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to