problem face with plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

problem face with plugin

Ang BeePeng
I've wrote a simple plugin to perform Gaussian elimination on matrix. Before compiling it, I test it with the simulator,
MyPlugin doPrimitive: 'primGauss'.

The answer returned correctly. But after I compile it into an external plugin, the plugin return different answer, wrong answer. Can anyone tell me what are the possible mistakes I've make, where should I look into to correct this.

Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: problem face with plugin

askoh
Administrator
Please show us your code. Aik-Siong Koh

Ang Beepeng wrote
I've wrote a simple plugin to perform Gaussian elimination on matrix. Before compiling it, I test it with the simulator,
MyPlugin doPrimitive: 'primGauss'.

The answer returned correctly. But after I compile it into an external plugin, the plugin return different answer, wrong answer. Can anyone tell me what are the possible mistakes I've make, where should I look into to correct this.

Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: problem face with plugin

Ang BeePeng
primSolveGauss":bVector :xVector"
        "primitive performs gaussian elimination"
        | mat1 bVec xVec result |

        self export: true.
        self inline: false.
       
        self var: #mat1 type:'float *'.
        self var: #bVec type:'float *'.
        self var: #xVec type:'float *'.
       
        xVec := self loadArgumentVector: (result := interpreterProxy stackObjectValue: 0).
        bVec := self loadArgumentVector: (interpreterProxy stackObjectValue: 1).
        mat1 := self loadArgumentMatrix: (interpreterProxy stackObjectValue: 2).
                       
        self solveGauss: mat1 with: bVec into: xVec.
               
        interpreterProxy pop:3 thenPush: result.



solveGauss: mat1 with: bVec into: xVec
        "perform gaussian elimination"
        | ratio temp a13 a12 a11|
       
        self var: #mat1 type:'const float *'.
        self var: #bVec type:'const float *'.
        self var: #xVec type:'float *'.
       
        self var: #a11 type:'double '.
        self var: #a12 type:'double '.
        self var: #a13 type:'double '.
       
        ratio := ((mat1 at: 3) / (mat1 at: 0)).
                mat1 at: 3 put: ((mat1 at: 3) - ((mat1 at: 0) * ratio)).
  mat1 at: 4 put: ((mat1 at: 4) - ((mat1 at: 1) * ratio)).
                mat1 at: 5 put: ((mat1 at: 5) - ((mat1 at: 2) * ratio)).
               
        bVec at: 1 put: ((bVec at: 1) - (ratio * (bVec at: 0))).
       
        ratio := ((mat1 at: 6) / (mat1 at: 0)).
                mat1 at: 6 put: ((mat1 at: 6) - ((mat1 at: 0) * ratio)).
  mat1 at: 7 put: ((mat1 at: 7) - ((mat1 at: 1) * ratio)).
                mat1 at: 8 put: ((mat1 at: 8) - ((mat1 at: 2) * ratio)).
        bVec at: 2 put: ((bVec at: 2) - (ratio * (bVec at: 0))).
       
        ratio := ((mat1 at: 7) / (mat1 at: 4)).
                mat1 at: 7 put: ((mat1 at: 7) - ((mat1 at: 4) * ratio)).
  mat1 at: 8 put: ((mat1 at: 8) - ((mat1 at: 5) * ratio)).
        bVec at: 2 put: ((bVec at: 2) - (ratio * (bVec at: 1))).
       

        "Back substitution"
        a13 := (bVec at: 2) / (mat1 at: 8).
       
        temp := bVec at: 1.
        temp := temp - ((mat1 at: 5) * a13).
        a12 := temp / (mat1 at: 4).
       
        temp := bVec at: 0.
        temp := temp - ((mat1 at: 2) * a13).
        temp := temp - ((mat1 at: 1) * a12).
        a11 := (temp / (mat1 at: 0)).
       
        xVec at:0 put: (self cCoerce: a11 to: 'float').
        xVec at:1 put: (self cCoerce: a12 to: 'float').
        xVec at:2 put: (self cCoerce: a13 to: 'float').


About the coding, I'm trying to perform the gauss elimination row by row, before coding it in loop. It takes in a 3x3 matrix along with two 3x1 vectors.



askoh wrote
Please show us your code. Aik-Siong Koh

Ang Beepeng wrote
I've wrote a simple plugin to perform Gaussian elimination on matrix. Before compiling it, I test it with the simulator,
MyPlugin doPrimitive: 'primGauss'.

The answer returned correctly. But after I compile it into an external plugin, the plugin return different answer, wrong answer. Can anyone tell me what are the possible mistakes I've make, where should I look into to correct this.

Thanks.

Ang Beepeng
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: problem face with plugin

Yoshiki Ohshima-2
In reply to this post by askoh
At Mon, 6 Oct 2008 07:53:40 -0700 (PDT),
askoh wrote:
>
> Please show us your code. Aik-Siong Koh

  I second that.

  If it is not possible for some reason, one of the likely senario is
that type declaration for some variables may be missing.

-- Yoshiki

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: problem face with plugin

Andreas.Raab
In reply to this post by Ang BeePeng
Ang Beepeng wrote:
> xVec := self loadArgumentVector: (result := interpreterProxy
> stackObjectValue: 0).

This may be the problem. I'm not sure if the CCodeGen can deal with the
nested assignment properly. Try rewriting this as:

        result := interpreterProxy stackObjectValue: 0.
        xVec := self loadArgumentVector: result.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: problem face with plugin

Ang BeePeng
I've try as suggested, but the plugin still giving wrong answer. Meantime, I tried to change all data type into double, turn up the VM crashed. What are the possible errors, and why the VM crashed when I change data representation into double?

Any help will be very much appreciated. Thanks

Ang Beepeng


Andreas Raab wrote
Ang Beepeng wrote:
> xVec := self loadArgumentVector: (result := interpreterProxy
> stackObjectValue: 0).

This may be the problem. I'm not sure if the CCodeGen can deal with the
nested assignment properly. Try rewriting this as:

        result := interpreterProxy stackObjectValue: 0.
        xVec := self loadArgumentVector: result.

Cheers,
   - Andreas
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: problem face with plugin

Yoshiki Ohshima-2
> I've try as suggested, but the plugin still giving wrong answer. Meantime, I
> tried to change all data type into double, turn up the VM crashed. What are
> the possible errors, and why the VM crashed when I change data
> representation into double?
>
> Any help will be very much appreciated. Thanks

  What are bVector and xVector?  What class(es) are they?  If they are
FloatArrays changing the types to double is not a right thing.
What does loadArgumentVector: do?

  Ah, but the problem seems that you are missing the type declaration
of ratio and temp in solveGauss:with:into:.  Upon the assignments to
them in C, the values will be truncated.

-- Yoshiki



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: problem face with plugin

Bert Freudenberg
Am 09.10.2008 um 00:45 schrieb Yoshiki Ohshima:

>> I've try as suggested, but the plugin still giving wrong answer.  
>> Meantime, I
>> tried to change all data type into double, turn up the VM crashed.  
>> What are
>> the possible errors, and why the VM crashed when I change data
>> representation into double?
>>
>> Any help will be very much appreciated. Thanks
>
>  What are bVector and xVector?  What class(es) are they?  If they are
> FloatArrays changing the types to double is not a right thing.
> What does loadArgumentVector: do?
>
>  Ah, but the problem seems that you are missing the type declaration
> of ratio and temp in solveGauss:with:into:.  Upon the assignments to
> them in C, the values will be truncated.
>

The thing to keep in mind is that Slang is simply C written in  
Smalltalkish syntax. This is rather confusing at first, so take a good  
look at the generated C code and try to make sense of it. You do have  
to ensure all your type declarations make sense to the C compiler,  
etc. There is no magic about this, it's straight-forward C.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: problem face with plugin

Ang BeePeng
In reply to this post by Yoshiki Ohshima-2
bVector class subclassed MatrixTransform2x3, which have the same superclass as the matrix class. loadArgumentVector: is to load the vectors into C stack as array.

Thank you so much. The problem is with ratio and temp, after I've declared them as c variable, the plugin returns correct answer.

Ang Beepeng



Yoshiki Ohshima-2 wrote
> I've try as suggested, but the plugin still giving wrong answer. Meantime, I
> tried to change all data type into double, turn up the VM crashed. What are
> the possible errors, and why the VM crashed when I change data
> representation into double?
>
> Any help will be very much appreciated. Thanks

  What are bVector and xVector?  What class(es) are they?  If they are
FloatArrays changing the types to double is not a right thing.
What does loadArgumentVector: do?

  Ah, but the problem seems that you are missing the type declaration
of ratio and temp in solveGauss:with:into:.  Upon the assignments to
them in C, the values will be truncated.

-- Yoshiki