Overload comma , operator to init the array

Started by
16 comments, last by Misery 11 years, 8 months ago
Seriously now, why are you needing to frequently initialise matrices with lists of constants?

Would it not be clearer to have stuff like:


Matrix identityMatrix();
Matrix rotationZMatrix(float angle);


and just do whatever is easiest to implement inside these relatively few functions?

Be far more clear reading code that uses named methods to construct matrices than wading through code containing any of the above, no matter how the detail of the initialisation syntax happens to be expressed.
Advertisement
@Aardvajik:
Hello,
I am a scientist in CFD. I was asked to create a "friendly" library for scientific computations. I know, there are many of those, but none of them fulfills all of these criteria at once:
- includes matrix classes, sparse matrix classes, graphs, FEM meshes, solvers (I know, I know, Dune does for example) under one common interface
- is intuitive for people using Scilab, Matlab, Octave, Mathematica etc (this is why I aim to create such syntax)
- has easy to use installer on both Windows and Linux
- is portable between Windows/Linux and Intel C++, VS C++ and GCC on those platforms
- is written in compiled language, so it is much faster than scientific script languages, and avoids copying of arrays (what is common in Scilab for example)
- to use: include only one header and done, no needed fortran to C and C to C++ etc compilations, using Linux to windows cross compilers and so on

And to give You straight answer: Engineers and scientists very often use Mathematica, Matlab and silimar things.
And quite often we begin to learn programming using these (btw great) packages. And these script languages are oriented for using matrices, the same way as it is in engineering practice. We are used to init matrices "by hand". However, as one develops oneself tries to count more and more complicated things. And at some moment those scientific packages seem too slow, even to use them at super computers (on our HPC Task server, if Your computations are not finished in a week, they are canceled).

So what I am trying to do is to create intuitive library, which can be easily installed and used by non-proffesional programmers (like myself).So they could easily count much larger cases than before.

I am guessing that You are a pro programmer. So Your viewpoint to this matter is quite different than someones who is just trying to do different job, but needs to create program to count anything. For You it is not a problem to choose a language, dependently to what You need to achieve. You need a good parsing - take Python, You need fast numerical algorithms - take C++ or Fortran. Need administrative scripts: take PowerShell or Perl...
But we - non-profesionals - don't look at those matters this way. Our job demands from us bit different things, and we are not (unfortunately) paid for spending time on learing new programming language.

You would be surprised how little most just-programming-users enigneers know about programming. smile.png
Fair enough :)

@Aardvajik:
Hello,
I am a scientist in CFD. I was asked to create a "friendly" library for scientific computations. I know, there are many of those, but none of them fulfills all of these criteria at once:
- includes matrix classes, sparse matrix classes, graphs, FEM meshes, solvers (I know, I know, Dune does for example) under one common interface
- is intuitive for people using Scilab, Matlab, Octave, Mathematica etc (this is why I aim to create such syntax)
- has easy to use installer on both Windows and Linux
- is portable between Windows/Linux and Intel C++, VS C++ and GCC on those platforms
- is written in compiled language, so it is much faster than scientific script languages, and avoids copying of arrays (what is common in Scilab for example)
- to use: include only one header and done, no needed fortran to C and C to C++ etc compilations, using Linux to windows cross compilers and so on


Hey, have you considered looking into Eigen, http://eigen.tuxfamily.org/dox-devel/ ?
I think that it fulfills most of your requirements, other than some of the first one and the last one (I think, I usually just include what I need, but this one is trivial to solve if you prepare a header that would include everything -- not that I think it's a good practice, btw) -- but relatively speaking, since writing from the scratch seems to be your alternative anyway, wouldn't it be faster to build on Eigen as a foundation (and if you contribute your addons to an open-source project you'll get other benefits, like more eyes to catch more bugs, etc.),
@Matt-D:
Thank You for this suggestion. The lib seems quite interesting. I'm sure I will take a look at sources of Eigen, especially iterative solvers - that's what I was missing. But still this is matrix only package (and few more classes: plynomial for example) and I need to have a basic engineering lib that contains a bit more.
Maybe I should add a few more words of explanation:

I decided to create my own library that will be similar in usage to Scilab and/or Mathematica. So in general it will be some kind of code-compiled matrix operator. I am not trying to do everything from scratch, because probably my life wouldn't be long enough to make a good quality lib (creating a good sparse solver or mesh generator are another branches of sciences themselves). I am trying to make a reasonably fast and convenient common, homogenous interface to few well known and portable libraries. And this interface is my main job at the moment.
I will integrate (or already have integrated some of those libs/programs):
-CBLAS and CLAPCK,
-CGAL, GMSH, provide GiD mesh generator interface,
-Umfpack, SuperLU for sparse matrices.
-Intel MKL and AMD MKL support
And some more... maybe Boost.units? Time will show. For now I needed a realistic goal to achieve. In future I plan to integrate VTK and make python bindings.
I will add many of functions written by myself "copying" the functionality known from Scilab and Mathematica. Interpolation, differentation, integration and so on...
And if this lib become successful among my friends at work, and my students I will be happy to make it open-source (in the meaning that it will be well documented for developers and users, and tested and ready to download), as most of those libs are GPL licensed.

And why I will not use Eigen as a foundation? First if all: it is too late now to change the abosule basis. Second I want to have as much control over this project as possible. Third: I love programming and it gives me much fun.

Regards
OK, fair enough :-)
Engineers and scientists very often use Mathematica, Matlab and silimar things.
And quite often we begin to learn programming using these (btw great) packages. And these script languages are oriented for using matrices, the same way as it is in engineering practice. We are used to init matrices "by hand". However, as one develops oneself tries to count more and more complicated things. And at some moment those scientific packages seem too slow, even to use them at super computers (on our HPC Task server, if Your computations are not finished in a week, they are canceled).


But at this point -- when something like MatLab becomes too slow -- I think a better approach than switching to an entirely new language with an entirely new library, etc., is to stick with the original engineering environment but write extensions to it in C++ using the API exposed by its developer. In the case of MatLab MathWorks gives you the whole MEX interface and, I think, even has a MEX Compiler built into Matlab, so what you can do is profile your Matlab computations and re-write the slow parts in C++ interfacing via MEX. Anyway, that's what we did at my last job and it worked pretty well.

Not sure if Mathematica has something like this, but I'd actually be pretty surprised if it didn't
@jwezorek:
That's true, but when taking into concern Matlab or Mathematica the cost of those is very high. Especially Mathworks strategy is painful: You have to pay about $470 for each component. For deployment tool, for compiler... Why not use free tools? Or just make a GPL code that will work on most compilers.
And still those Mathematica and Matlab libraries are distributed as dll's (or so). How would anybody move such application to different platform. Let's say to platform with Itanium processors?

Matlab and Mathematica are really great tools, but it is for a reason why I decided tf rsuch solution.
smile.png

This topic is closed to new replies.

Advertisement