Thread: Matrices library is now!!!

  1. #16
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    How do you populate your matrix?

    It seems you can only set its dimensions, which, in terms of utility, wouldn't do much for a lot of people.

    Also, if I went about looking for a matrix library so I wouldn't have to wrack my brains trying to create one, I'd at least expect functions for deriving:
    (1) a determinant
    (2) an eigenvector
    (3) a transpose
    (4) an upper triangle
    (5) a lower triangle
    (6) an E matrix
    (7) addition
    (8) subtraction

  2. #17
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    Quote Originally Posted by ChaosEngine View Post
    First, well done on releasing your first project. next some constructive criticism:

    • first you absolutely must include some more info in your header file. At the very least, you should put author, date, revision, copyright and warranty disclaimer. Theoretically I could use this code and if it didn't work, I could sue you. (it's not very likely but you should protect yourself). I'd recommend the boost licence, but there are others. to use it you just need to add
      Code:
      // Copyright Hussain Hani 2007.
      // Distributed under the Boost Software License, Version 1.0. (See
      // http://www.boost.org/LICENSE_1_0.txt)
    • why is matrix restricted to floats? you could make the library a template and then users could have matrices of doubles/ints/complex numbers/whatever.
    • what happens if I create a Matrix and use it without calling build? will it fail? if so, wouldn't it make more sense to require rows and columns as arguements to the constructor?
    • how does print() work? the normal c++ convention would be to make an overloaded '<<' operator. that would work with printing and with files (and any other stream)
    • if you're overloading the +, - and * ops it's customary to overload +=, -= and *= too. In fact you should overload those first and then op+ is simply
      Code:
      Matrix operator+(const Matrix& rhs)
      {
          Matrix result(*this);
          result += rhs;
          return result;
      }
    • const correctness - print(), getr(), getc() and about() should be const. op+, - and * should return const Matrix. this prevents accidental mistakes like (m1 * m2 = m3), which is legal but useless in your code.


    That's a few points from reading the header. If you want to post the source, I'll have a look at that too. Finally, wrt to boost, they won't accept a closed source library, so you'll have to provide the source. Plus I don't think the library is up to boosts standards yet.

    Sorry if that's a bit harsh. Please take the criticism in the spirit in which it's intended, which is to help you improve the library. It's a good first attempt, but it needs work.
    Answering your first question about the constructor that has to have arguments. I dont agree. When you just simply creat a matrice, the dimensions are zero and the pointers are null, and I tried to stick to original C++ library, like for example the vector
    it's much cleaner to say :
    Code:
    Matrix matrix;
    //than 
    Matrix matrix(2,1);
    
    //and 
    vector<int> intvec;
    //than 
    vector<int> intvec(2,4);
    Although you could inter some arguments in vector class.

    for you question about "why didnt I overload the << operator to show the result instead of print() function)". The answer is that I wanted to keep the library in its OO boundries. I didnt want it to use the C++ built-int that hides it's and actual function. For example, I wanted it to look like this :
    Code:
    matrix.print();
    so the user will know that he is dealing with library while using the dot operator.
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  3. #18
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Hussain Hani View Post
    for you question about "why didnt I overload the << operator to show the result instead of print() function)". The answer is that I wanted to keep the library in its OO boundries. I didnt want it to use the C++ built-int that hides it's and actual function. For example, I wanted it to look like this :
    Code:
    matrix.print();
    so the user will know that he is dealing with library while using the dot operator.
    Kinda reminds me of these, plus or minus a few FAQs:
    http://parashift.com/c++-faq-lite/in....html#faq-15.8
    http://parashift.com/c++-faq-lite/in....html#faq-15.9
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #19
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    one popular one is GPL
    I rarely see the GPL used for projects such as this, if ever. Libraries more commonly use the LGPL, whereas applications use the GPL.

    Congrats on your library. More constructive (I hope) criticism.
    • about() - This function has no parameters and returns no data. How does one go about getting info about the library if it does neither? Does it merely print it to stdout? If it does, I'd recommend not to - as an application developer I want to have control over how and what data gets outputted. Also, about() is a member function of Matrix, meaning I have to declare and allocate memory to a Martix just to get info on the library. You might want about to be static, since it has (as far as I can tell) no need to read/write any data in the class.
    • Is there any way in gcc/MinGW to use .lib files? Otherwise, I can't test the library. (I'm thinking that g++ doesn't like MSVC's name mangling, but I could be way off here...) (And yes, I tried "g++ -o test.exe test.cpp matrix.lib" - undef'd references to Matrix::*)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #20
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Is there any way in gcc/MinGW to use .lib files? Otherwise, I can't test the library. (I'm thinking that g++ doesn't like MSVC's name mangling, but I could be way off here...) (And yes, I tried "g++ -o test.exe test.cpp matrix.lib" - undef'd references to Matrix::*)
    I don't think so. You would have to recompile the source anyway or wait for Hani to release an a file. While looking for the answer I was directed to some GNU stuff. My hunch was something with -I and -L: According to the manual -L dir only expands the search path for -l by dir. And the only thing -lfoo does is look for libfoo.a which is useless here. I don't think there's another way to do it.

  6. #21
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Hussain Hani View Post
    Answering your first question about the constructor that has to have arguments. I dont agree. When you just simply creat a matrice, the dimensions are zero and the pointers are null, and I tried to stick to original C++ library, like for example the vector
    it's much cleaner to say :
    Code:
    Matrix matrix;
    //than 
    Matrix matrix(2,1);
    
    //and 
    vector<int> intvec;
    //than 
    vector<int> intvec(2,4);
    Although you could inter some arguments in vector class.
    Actually you didn't answer my question. I asked you what happens if I don't call build? does your library check for the null pointers? will it throw an exception? crash?

    as for vector,
    • vector is in a usable state when default constructed. you can perform push_back, reserve, resize, etc. Also a vectors purpose is to be a dynamically resizeable array. it grows as you need it. a matrix is a fixed size.
    • vector has a "size constructor"

    In general, it is bad design for a class that is default constructable to be in an invalid state after construction.

    Quote Originally Posted by Hussain Hani View Post
    for you question about "why didnt I overload the << operator to show the result instead of print() function)". The answer is that I wanted to keep the library in its OO boundries. I didnt want it to use the C++ built-int that hides it's and actual function. For example, I wanted it to look like this :
    Code:
    matrix.print();
    so the user will know that he is dealing with library while using the dot operator.
    sorry, that's just wrong. read the links Dave posted (esp the second one)
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 09:20 AM