Convert Functions ...

S

shapper

Hello,

I am converting a few Matlab functions to C#.
Each function has 2 to 8 inputs being 1 or 2 an array with 1xN
dimension.
All functions return 1 or 2 arrays.

What would be the best way, in terms of performance and usability, to
create these functions?

I see the following options:

1. Make each function a class with properties that are inputs.
Then a method Run that makes the calculation.
I am not sure if it is "to much" to create a class for each
function.

2. Create a class MatlabFunctions and inside have static methods for
each function with the inputs.

Which one would be the best way to implement it?

The calculation inside the functions differ a lot.
Some are quite simple ... others are a little bit more complex.
And some functions rely on other functions to for their own
calculations.

And are there better options than 1 and 2?

Thank You,
Miguel
 
A

Arne Vajhøj

shapper said:
I am converting a few Matlab functions to C#.
Each function has 2 to 8 inputs being 1 or 2 an array with 1xN
dimension.
All functions return 1 or 2 arrays.

What would be the best way, in terms of performance and usability, to
create these functions?

I see the following options:

1. Make each function a class with properties that are inputs.
Then a method Run that makes the calculation.
I am not sure if it is "to much" to create a class for each
function.

2. Create a class MatlabFunctions and inside have static methods for
each function with the inputs.

Which one would be the best way to implement it?

The calculation inside the functions differ a lot.
Some are quite simple ... others are a little bit more complex.
And some functions rely on other functions to for their own
calculations.

#2 would be the standard for simple calculation.

The more complex the calculations and especially if
multiple algorithms to implement the calculation exists
the more attractive #1 becomes.

Arne
 
P

Pavel Minaev

I am converting a few Matlab functions to C#.
Each function has 2 to 8 inputs being 1 or 2 an array with 1xN
dimension.
All functions return 1 or 2 arrays.

What would be the best way, in terms of performance and usability, to
create these functions?

I see the following options:

1. Make each function a class with properties that are inputs.
    Then a method Run that makes the calculation.
    I am not sure if it is "to much" to create a class for each
function.

It doesn't make much sense, anyway. Why a class when it doesn't model
any entity or concept in any useful way?
2. Create a class MatlabFunctions and inside have static methods for
each function with the inputs.

That's the most straightforward way, and I don't see any downsides.
 
R

Ratnesh Maurya

Hello,

I am converting a few Matlab functions to C#.
Each function has 2 to 8 inputs being 1 or 2 an array with 1xN
dimension.
All functions return 1 or 2 arrays.

What would be the best way, in terms of performance and usability, to
create these functions?

I see the following options:

1. Make each function a class with properties that are inputs.
    Then a method Run that makes the calculation.
    I am not sure if it is "to much" to create a class for each
function.

2. Create a class MatlabFunctions and inside have static methods for
each function with the inputs.

Which one would be the best way to implement it?

The calculation inside the functions differ a lot.
Some are quite simple ... others are a little bit more complex.
And some functions rely on other functions to for their own
calculations.

And are there better options than 1 and 2?

Thank You,
Miguel

Hi Miguel,

I will go for #2, I would like #1 only if you are keeping some data or
result in the class which can be reused later in the same class.

Cheers,
-Ratnesh
S7 Software
 
R

Ratnesh Maurya

Hello,

I am converting a few Matlab functions to C#.
Each function has 2 to 8 inputs being 1 or 2 an array with 1xN
dimension.
All functions return 1 or 2 arrays.

What would be the best way, in terms of performance and usability, to
create these functions?

I see the following options:

1. Make each function a class with properties that are inputs.
    Then a method Run that makes the calculation.
    I am not sure if it is "to much" to create a class for each
function.

2. Create a class MatlabFunctions and inside have static methods for
each function with the inputs.

Which one would be the best way to implement it?

The calculation inside the functions differ a lot.
Some are quite simple ... others are a little bit more complex.
And some functions rely on other functions to for their own
calculations.

And are there better options than 1 and 2?

Thank You,
Miguel

Hi Miguel,

I will go for #2, I would like #1 only if you are keeping some data or
result in the class which can be reused later in the same class.

Cheers,
-Ratnesh
S7 Software
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top