Hello Wim,
Thank you for your advise. I am using ROOT 5.20.00, OS X 10.5 (Intel) and Python 2.5.1.
foo[1,2] = 2.
runs as you suggested. It look much better than setter method. I will use it for now. But it did not work for the following class (actual one has other methods.)
template<typename T> class THealAlm : public TObject {
private:
std::vector<std::complex<T> > fAlm;
public:
std::complex<T>& operator()(Int_t l, Int_t m); const std::complex<T>& operator()(Int_t l, Int_t m) const; };
>>> import ROOT
>>> ROOT.gSystem.Load("libRootHealPix")
0
>>> a = ROOT.THealAlm("double")(2, 2)
>>> a[0,0] = ROOT.complex("double")(0,0)
TClass::TClass:0: RuntimeWarning: no dictionary for class
complex<double> is available
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: none of the 2 overloaded methods succeeded. Full details:
no __setitem__ handler for return type (complex<double>&)
no __setitem__ handler for return type (const complex<double>&)
After I got this error, I added
#pragma link C++ class std::complex<Float_t>; #pragma link C++ class std::complex<Double_t>;
in my LinkDef.h. But I got another error message.
>>> a[0,0] = ROOT.std.complex("double")(0,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: complex<double>::complex<double>() =>
takes at most 0 arguments (2 given)
>>> a[0,0] = ROOT.std.complex("double")() ##### <=== no argument!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: none of the 2 overloaded methods succeeded. Full details:
no __setitem__ handler for return type (complex<double>&)
no __setitem__ handler for return type (const complex<double>&)
Where should I change? It may not be PyROOT problem but LinkDef.h problem...
Regards,
OKUMURA, Akira oxon_at_ceres.phys.s.u-tokyo.ac.jp
Department of Physics, The University of Tokyo
7-3-1 Hongo, Bunkyo-ku, Tokyo 113-0033
TEL/FAX +81 3-5841-4173/4059
Skype : okumura.akira
On 2008/06/26, at 17:25, <WLavrijsen_at_lbl.gov> <WLavrijsen_at_lbl.gov> wrote:
> Akira,
>
>>>>> foo = Foo() # constructor is not written in the above example...
>>>>> a = foo(1, 2) # OK
>>>>> foo(1, 2) += 10. # NG
>> SyntaxError: can't assign to function call
>
> which version of ROOT are you using? If I try the above (with a little
> modification to actually allocate an array to assign to :) ), then I
> get:
>
> SyntaxError: illegal expression for augmented assignment
>
> Which might be fixable, but I'm not quite sure how. Note that this
> was done
> for pure assignment (i.e. '=' instead of '+=') for operator(int,int):
>
>>>> foo(1, 2) = 2.
> Are you trying to assign a value to a reference return, for example
> to the
> result of a call to "double& SMatrix<>::operator()(int,int)"? If so,
> then
> please use operator[] instead, as in e.g. "mymatrix[i,j] = somevalue".
>
> File "<stdin>", line 1
> SyntaxError: can't assign to function call
>>>> foo[1, 2] = 2.
>>>> print foo(1, 2)
> 2.0
>>>>
>
> Thus, as for:
>
>> Is there any way to make python assign to foo(1, 2)? Other setter/
>> getter
>> methods will work if I add them. But I prefer simple script which
>> is easy to
>> read instead of using a setter.
>
> assuming you're running the same version of ROOT as I am, please use:
>
>>>> foo[1, 2] = foo(1, 2) + 10.
>
> Which I'll agree doesn't look very elegant, but has been the best I
> can come
> up with, the language limitation being what it is.
>
> Best regards,
> Wim
> --
> Wim.Lavrijsen_at_cern.ch -- WLavrijsen_at_lbl.gov -- www.lavrijsen.net
>
> "Your day will be somewhat dictated by authority." --fortune
> cookie
>
Received on Sat Jun 28 2008 - 00:46:44 CEST
This archive was generated by hypermail 2.2.0 : Sat Jun 28 2008 - 05:50:08 CEST