Jörgen Tegnér | 25 Jul 08:34

Troubles getting reverse assignment right

Hi list,

I have troubles with reverse assignment and would appreciate some
advice.

class GENERAL_VECTOR[E_->NUMERIC]
	inherit ARRAY[E_]

class REAL_VECTOR_32
	inherit GENERAL_VECTOR[REAL_32]

class REAL_VECTOR_64
	inherit GENERAL_VECTOR[REAL_64]

In GENERAL_VECTOR I want to find out the correct type of E_, REAL_32 or
REAL_64, to call the correct function with the correct live type. One
unelegant solution that kind of works:

anchor:E_
...
inspect Current.anchor.generating_type
	when "REAL_32" then
		debug io.put_string("REAL_32 version of axpy%N") end
		f_saxpy($n,$alpha,p1,$ldx,p2,$ldy)
	when "REAL_64" then
		debug io.put_string("REAL_64 version of axpy%N") end
		f_daxpy($n,$alpha,p1,$ldx,p2,$ldy)
	end

Above code works and gives the correct results.
(Continue reading)

Frederic Merizen | 28 Jul 13:54
Favicon
Gravatar

Re: Troubles getting reverse assignment right

Hi,

> So I would like to avoid the unelegant solution above.
> Adding dummy variables or type REFERENCE[E_] and REFERENCE[REAL_32] and
> trying reverse assignment gives typically the following error:
>
> ...
> ranchor: REFERENCE[E_]
> dummy_32:REFERENCE[REAL_32]
> ...
>
> if ranchor ?:= dummy_32 then
> 	...

You got you reverse assignment reversed !

ranchor: REFERENCE[E_]
dummy_32:REFERENCE[REAL_32]
...
if dummy_32 ?:= ranchor then

I didn't test the snippet above so it might not work either, but it's not
as hopeless as the other way round

Cheers
--

-- 
Frederic Merizen
If our behavior is strict, we do not need fun!

(Continue reading)

Philippe Ribet | 11 Aug 07:47

Re: Troubles getting reverse assignment right

Jörgen Tegnér wrote:

>Hi list,
>
>I have troubles with reverse assignment and would appreciate some
>advice.
>
>class GENERAL_VECTOR[E_->NUMERIC]
>	inherit ARRAY[E_]
>
>class REAL_VECTOR_32
>	inherit GENERAL_VECTOR[REAL_32]
>
>class REAL_VECTOR_64
>	inherit GENERAL_VECTOR[REAL_64]
>
>In GENERAL_VECTOR I want to find out the correct type of E_, REAL_32 or
>REAL_64, to call the correct function with the correct live type. One
>unelegant solution that kind of works:
>
>anchor:E_
>...
>inspect Current.anchor.generating_type
>	when "REAL_32" then
>		debug io.put_string("REAL_32 version of axpy%N") end
>		f_saxpy($n,$alpha,p1,$ldx,p2,$ldy)
>	when "REAL_64" then
>		debug io.put_string("REAL_64 version of axpy%N") end
>		f_daxpy($n,$alpha,p1,$ldx,p2,$ldy)
>	end
(Continue reading)

Paolo Redaelli | 11 Aug 11:36
Favicon

Re: Troubles getting reverse assignment right


> Jörgen Tegnér wrote:
>
>> Hi list,
>>
>> I have troubles with reverse assignment and would appreciate some
>> advice.
>>
>> class GENERAL_VECTOR[E_->NUMERIC]
>>     inherit ARRAY[E_]
>>
>> class REAL_VECTOR_32
>>     inherit GENERAL_VECTOR[REAL_32]
>>
>> class REAL_VECTOR_64
>>     inherit GENERAL_VECTOR[REAL_64]
>>
>> In GENERAL_VECTOR I want to find out the correct type of E_, REAL_32 or
>> REAL_64, to call the correct function with the correct live type. One
>> unelegant solution that kind of works:
>>
>> anchor:E_
>> ...
>> inspect Current.anchor.generating_type
>>     when "REAL_32" then
>>         debug io.put_string("REAL_32 version of axpy%N") end
>>         f_saxpy($n,$alpha,p1,$ldx,p2,$ldy)
>>     when "REAL_64" then
>>         debug io.put_string("REAL_64 version of axpy%N") end
>>         f_daxpy($n,$alpha,p1,$ldx,p2,$ldy)
(Continue reading)

Jörgen Tegnér | 17 Aug 22:44

Re: Troubles getting reverse assignment right

On Mon, 2008-08-11 at 11:36 +0200, Paolo Redaelli wrote:
> > Jörgen Tegnér wrote:
> >
> >> Hi list,
> >>
> >> I have troubles with reverse assignment and would appreciate some

> Mhmmm... this smells to be as BLAS - Basic Linear Algebra Subprograms...
> Am I right?

Yep! BLAS, LAPACK and some QUADPACK experiments.

> We have been trying to address a problem almost identical to yours in
> Eiffel Wrapper Libraries Collection, wrapping the GNU Scientific Library
> which does actually include BLAS.
> You could read more about it at
> https://gna.org/projects/eiffel-libraries more specifically looking at
> GSL_VECTOR_GENERAL, GSL_VECTOR_REAL_32 and GSL_VECTOR_REAL_64 at
> http://svn.gna.org/viewcvs/eiffel-libraries/trunk/eiffel-gsl/library/ .
> I don't see why you need to use such a non-object-oriented technique.

Coming from a Fortran 77 background so I'm learning by doing (mistakes).

> As far as I can understand you need to invoke different (Fortran/C)
> functions depending on the generic type of the vector. At EWLC we solved
> the problem this way:

> feature {} -- External calls
>     gsl_blas_sdot(x, y, res: POINTER): INTEGER_32 is
>         external "plug_in"
(Continue reading)

Jörgen Tegnér | 17 Aug 22:26

Re: Troubles getting reverse assignment right

On Mon, 2008-08-11 at 07:47 +0200, Philippe Ribet wrote:
> Jörgen Tegnér wrote:
> 
> >Hi list,
> >
> >I have troubles with reverse assignment and would appreciate some
> >advice.
> >
> >class GENERAL_VECTOR[E_->NUMERIC]
> >	inherit ARRAY[E_]
> >
> >class REAL_VECTOR_32
> >	inherit GENERAL_VECTOR[REAL_32]
> >
> >class REAL_VECTOR_64
> >	inherit GENERAL_VECTOR[REAL_64]
> >
> >In GENERAL_VECTOR I want to find out the correct type of E_, REAL_32 or
> >REAL_64, to call the correct function with the correct live type. One
> >unelegant solution that kind of works:
> >
> >anchor:E_
> >...
> >inspect Current.anchor.generating_type
> >	when "REAL_32" then
> >		debug io.put_string("REAL_32 version of axpy%N") end
> >		f_saxpy($n,$alpha,p1,$ldx,p2,$ldy)
> >	when "REAL_64" then
> >		debug io.put_string("REAL_64 version of axpy%N") end
> >		f_daxpy($n,$alpha,p1,$ldx,p2,$ldy)
(Continue reading)


Gmane