[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: SWIG typemap for ta-lib
From: "BENI" <rajib.chakrabarti () googlemail ! com>
Date: 2007-03-14 10:50:21
Message-ID: 1173869153.219214.34010 () l77g2000hsb ! googlegroups ! com
[Download RAW message or body]
Thanks for your lead.
It is lot clear now ... how to go about it.
Still I am fuzzy on a couple of things.
Could you pl guide....
>
> in ruby use it as
> closePrice = Array.new(<your data>)
> data_inp = closePrice[0..399]
> data_arr = ModuleExp::TA_MA( data_inp, 30, ModuleExp::TA_MAType_SMA)
So are you suggesting that i need not pass startIdx,endIdx in the
input. But these values I understand is required .. this is to
sometimes specify a range on which to run the function .
What I am confused about is ...ModuleExp::TA_MAType_SMA... is this a
constant that you are suggesting to pass along?
>
> In .i file you should define
> %typemap(in)(int startIdx,
> int endIdx,
> const double inReal[]
> )
> {
>
> Check_Type($input, T_ARRAY);
>
> /* Get the length of the array */
> int size = RARRAY($input)->len;
> int i;
> $3 = (unsigned char*) malloc(size * sizeof(double));
> $2 = size;
> $1 = 0;
>
> // copy the ruby array in the new allocated buffer
> /* Get the first element in memory */
> VALUE *ptr = RARRAY($input)->ptr;
> for (i=0; i < size; i++, ptr++)
> {
> /* Convert Ruby Object Fixnum to unsigned char */
> $1[i]= (double)?????(*ptr); // here i don't remember the macro
> to convert something like FIX2INT for float
> }
here I used $1[i]= NUM2DBL(*ptr);
is that OK?
> }
>
> %typemap(in)(int optInMAType,
> int *outBegIdx,
> int *outNbElement,
> double outReal[]
> )
> {
> int out_beg_ix = 0;
> int out_n_ele = 0;
> double arr_res[400];
Here I need to dimensionise the arr_res to the size of the input
array instead of 400. So i need to get the size variable in the
previous typemap declaration. But how can i use the size variable
here... it was a local variable only.
>
> $1 = NUM2INT(optInMAType);
> $2 = &out_beg_ix;
> $3 = &out_n_ele;
> &4 = arr_res;
>
> }
>
> %typemap(freearg) (int startIdx,
> int endIdx,
> const double inReal[],
> int optInTimePeriod,
> int optInMAType,
> int *outBegIdx,
> int *outNbElement,
> double outReal[]) {
> free((double *) $1);
> }
>
> %typemap(out)TA_RetCode TA_MA( int startIdx,
> int endIdx,
> const double inReal[],
> int optInTimePeriod,
> int optInMAType,
> int *outBegIdx,
> int *outNbElement,
> double outReal[])
I did not get this one clearly.... TA_Retcode is the output type.
Can't i get it in ruby?Only thing that i am getting back here is the
outReal[] array i think.
> {
>
> int iStartIx = *arg6;
> int iLen = iStartIx + *arg7;
>
> VALUE arr = rb_ary_new2(iLen);
>
> for ( int i = iStartIx; i < iLen; i++ )
> rb_ary_push(arr, INT2FIX((*arg8)[i]));
> $result = arr;
the *arg8 contains floating point number so will INT2FIX work?
> }
>
>
> it is not tested but this give you the idea how to make the i file.
>
> Regards
Thanks again ..
Regards
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic