Not sure how it got that format but here is a second go:

The vector is a list of double.

std::vector Update_A9(const double &T)

{

double T_1(1.0/T);

std::vector res;

for(int i=0; i = 5; ++i)

{

double dum = std::exp(-3.0 * ei_*T_1);

res.push_back(nyi_ * (1.0 - 0.12*dum));

}

return res;

}

Also how do I tell the f# compiler to use eigther double or decimal?

Thanks Torben

By on 10/4/2009 4:13 AM ()

I would try something like

1
2
3
4
5
6
7
8
let Update_A9 (T:double) =
    let T_1 = 1.0 / T
    let len = 5
    Array.map
        ( fun i -> 
            let dum = exp ( -3.0 * ei_ * T_1 )
            nyi_ * (1.0 - 0.12*dum)
        ) [| 0 .. len |]

I'm not sure what ei_ or nyi_ are. I assume that they are defined earlier. Is the purpose to call this function from F# or C++. If the former, I would replace Array.map with List.map. If the latter check that Array is a valid map of c++ Vector.

Hope that helps
Joe

By on 10/4/2009 10:48 AM ()

Hi Joe,

Thanks for your response. ei_ and nyi_ are vectors of double in c++.

The code is to be called from c#. It is part of a study to find what I should do with a huge engineering c++ library that I have. Port it to C#, F# or stay in c++.

Torben

By on 10/4/2009 2:11 PM ()

The code is to be called from c#. It is part of a study to find what I should do with a huge engineering c++ library that I have. Port it to C#, F# or stay in c++.

Torben

Unless you have a valid reason I suggest you do not re-write this from scratch, just write a binding API that you can call in C#/F#.

Use C++/CLI to write your binding layer.

By on 10/6/2009 5:14 AM ()

Hi Torben,

Hmmm, I am a little concerned, on two counts.

Firstly, your original code is out dated c++, vector should be something like

1
vector<double>

i.e. vector is a generic container and should identify the type of the contents.

Secondly, rewriting any significant sized project in another language is not to be undertaken lightly. For example, now that you say ei_ and nyi_ are vectors, is the * operator being overloaded?

Whilst it might be a fun project to convert the existing code to F#, have you got tests for it and proper documentation? I am a total newbie wrt inter-operation between c#/c++, but you should check because c# uses managed code and c++ generally uses unmanaged code. I would urge some research in inter-language calling. I do not doubt it can be done, but you need to establish the framework.

Joe

By on 10/4/2009 5:20 PM ()

Hi Joe,

Thanks for your feedback.

The vectors are of the correct type (using std). The editor for this newsgroup does not seem to like c++ code and to parse it :)

Currently the c++ code has a c# frontend so clr is a option but for a range of reasons the c++ code needs rewriting so I want to spend a few months looking into what is the best direction to take.

Torben

By on 10/5/2009 6:32 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper