Hello, I am Dhruv, majoring in Mathematics & Computing from Indian Institute of Technology, Guwahati. After doing a bit of research over the project ideas, I found the idea of further developing boost.ublas library interesting and have started writing the programming competency code. Here is the link to the code I've written yet: https://github.com/chiggum/boost.ublas/blob/master/gaussian_elimination.hpp. Though the code is not yet complete, but a naive version of algorithm is implemented and is integrated into ublas. To me, the code seems to be running properly. I need a little help for proceeding further. 1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library. To be specific, the gaussian elimination doesn't work on singular matrices. So, I would like to set the errno and display appropriate message to the user whenever a singular matrix is given as an input. 2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library. Sorry, I haven't yet gone through most of the code in boost library. Any further helpful links/resources are welcomed. Thanks & Best regards, Dhruv https://github.com/chiggum P.S. Sorry for reposting the mail. I am still waiting for a reply.
Hey Dhruv I am an applicant myself, I think I can give you a few ideas regarding your queries.
1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library.
Go through the library source code thoroughly. Use a code dependency graph generator to browse code easily. (Easiest way is to run doxygen over the ublas directory). That will make going through the code real fast.
2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library.
Not sure about the format, but the tests should cover as many cases as
possible.
Best wishes
Ganesh Prasad
On 10 March 2015 at 15:03, Dhruv Kohli
Hello,
I am Dhruv, majoring in Mathematics & Computing from Indian Institute of Technology, Guwahati. After doing a bit of research over the project ideas, I found the idea of further developing boost.ublas library interesting and have started writing the programming competency code. Here is the link to the code I've written yet: https://github.com/chiggum/boost.ublas/blob/master/gaussian_elimination.hpp . Though the code is not yet complete, but a naive version of algorithm is implemented and is integrated into ublas. To me, the code seems to be running properly.
I need a little help for proceeding further. 1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library. To be specific, the gaussian elimination doesn't work on singular matrices. So, I would like to set the errno and display appropriate message to the user whenever a singular matrix is given as an input.
2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library. Sorry, I haven't yet gone through most of the code in boost library.
Any further helpful links/resources are welcomed.
Thanks & Best regards, Dhruv https://github.com/chiggum
P.S. Sorry for reposting the mail. I am still waiting for a reply.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
If you have a license of MATLAB, you can use the gallery function to
generate some very good test matrices.
*Rajaditya Mukherjee *
*3rd Year Graduate Student*
Dept. of Computer Science and Engineering
The Ohio State University
Columbus, Ohio
Tel :- +1-(614)-271-4439
email :- rajaditya.mukherjee@gmail.com
Hey Dhruv I am an applicant myself, I think I can give you a few ideas regarding your queries.
1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library.
Go through the library source code thoroughly. Use a code dependency graph generator to browse code easily. (Easiest way is to run doxygen over the ublas directory). That will make going through the code real fast.
2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library.
Not sure about the format, but the tests should cover as many cases as possible.
Best wishes Ganesh Prasad
On 10 March 2015 at 15:03, Dhruv Kohli
wrote: Hello,
I am Dhruv, majoring in Mathematics & Computing from Indian Institute of Technology, Guwahati. After doing a bit of research over the project ideas, I found the idea of further developing boost.ublas library interesting and have started writing the programming competency code. Here is the link to the code I've written yet:
https://github.com/chiggum/boost.ublas/blob/master/gaussian_elimination.hpp
. Though the code is not yet complete, but a naive version of algorithm is implemented and is integrated into ublas. To me, the code seems to be running properly.
I need a little help for proceeding further. 1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library. To be specific, the gaussian elimination doesn't work on singular matrices. So, I would like to set the errno and display appropriate message to the user whenever a singular matrix is given as an input.
2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library. Sorry, I haven't yet gone through most of the code in boost library.
Any further helpful links/resources are welcomed.
Thanks & Best regards, Dhruv https://github.com/chiggum
P.S. Sorry for reposting the mail. I am still waiting for a reply.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thanks a lot guys for replying. Using doxygen and the information at ublas wiki, I was able to understand the error handling and test case format. I have written the required competency code which is here: https://github.com/chiggum/boost.ublas/blob/master/gaussian_elimination.hpp Also, a preliminary framework of test code is implemented here: https://github.com/chiggum/boost.ublas/tree/master/test Finally, I will be going to write a proposal now and will soon draft it for a review by the mentor. Dhruv
Thanks a lot guys for replying. Using doxygen and the information at ublas wiki, I was able to understand the error handling and test case format.
Hi guys, it seems I will have dozens of great students already working as a community. Google please give me a slots for each of them ! Hi Dhruv, thanks for your contribution. I will review it quickly too. It's about time to write your proposal too. The sooner the better. Best, David
Hi guys, About the error handling issue. I was just giving some feedback on Rajaditya's proposal draft and his code, and noticed the use of the BOOST_UBLAS_CHECK macro for reporting the singularity of the matrix involved. And now I see that Dhruv has also adopted this. I have a big problem with this approach, and I'd like to get that issue cleared up before anyone gets too involved into developing code for numerical methods in uBlas. The BOOST_UBLAS_CHECK macro is essentially behaves as an assert() macro, in the sense that it is only enabled on debug builds, and kind of crashes the program if the condition fails. Where it differs from assert() is that when exceptions are not disabled (globally, or only for ublas) it will throw an exception instead, and otherwise it will call std::abort(). Now, as a replacement for assert(), it has some pros and some cons, but that's not what I want to discuss. For the purposes of this discussion, this macro is equivalent to assert(). The main problem I have is with using this to report a singularity or similar conditions (like bad numeric conditioning, or numeric rank-deficiency). The problem really is that such conditions are *not* bugs, i.e., they are not things that should ever crash a program, even during debugging. Such conditions occur all the time, and not by mistake nor due to a bug. To me, it is *completely unacceptable* to have a behaviour like calling std::abort() on such a condition. Here is a very common real life example. Let's say I have some non-linear system of equations that I'm trying to do something with (e.g., run an optimization on, compute some control gain matrices, or just solve it). Typically, that will involve computing a Jacobian matrix for that system of equations, and inverting it or, equivalently, solving a linear system with it. However, there is a very real possibility that at some specific points of linearization, the Jacobian matrix will be singular (numerically-speaking), which doesn't mean that I want my overall program to crash or my algorithm to stop, because in most cases, if I detect this singularity, I can cope with it somehow (e.g., pseudo-invert it, transpose it, add matrix damping to it, etc...). I have written code like this more often that I can count. I consider it to be a part of the contract of any matrix numerical method to *gracefully* report a singularity condition or similar conditions so that an alternative method can be used instead. Code that simply crashes under those circumstances is completely worthless, nobody is going to want to use that. When I do a search for the other uses of the BOOST_UBLAS_CHECK macro, I find that pretty much everywhere that it is used, it is used as one would properly use assert(), that is, to report problems like out-of-bounds indices or mismatching matrix sizes and things like that. This is fine because all of these things can only really be the result of a bug (wrong bounds on a for-loop, wrong dimensions of matrices, etc...). And these are the only situations in which this macro should ever be used, it should be considered as a substitute for assert(), nothing more. For reporting singularities or similar conditions, there are really only two options, either throw an exception or return an error code, but only one of those two must be used consistently throughout uBlas. I personally prefer to work with exceptions, but I know that in this application domain it can be a very hard sell (especially with people wanting to use this in embedded systems). So, that really only leaves us with error-codes. That's what I would recommend. As the maintainer, David, you get to make that call. But this needs to be cleared up at some point before anyone of these guys starts working on their GSoC project(s), if accepted, of course. Cheers, Mikael. -- Sven Mikael Persson, M.Sc.(Tech.) PhD Candidate and Vanier CGS Scholar, Department of Mechanical Engineering, McGill University,
For reporting singularities or similar conditions, there are really only two options, either throw an exception or return an error code, but only one of those two must be used consistently throughout uBlas. I personally prefer to work with exceptions, but I know that in this application domain it can be a very hard sell (especially with people wanting to use this in embedded systems). So, that really only leaves us with error-codes. That's what I would recommend.
I think you're pointing to a complex problem. Indeed, assertions are usually not a good idea and your use case is typical and quite common in fact. ___[For the potential GSOC students]___ Should we use exceptions or return codes ? Again, as you pointed, exceptions are great, with almost no overhead except when there is an ... exception. And most of the time, the execution time is hard to predict. Which is far from being a good idea in a real-time system. I can't really say who the ublas users are, because there are a lot in all sort of applications. Now, think about these 2 cases: - you implement a multiplication algorithm for 2 matrices: you want your algorithm to return the result and to be embedable into another expression, that is you want to be able to write C = A + (B*C). So it's important that the return value is the result itself. Your only option to report an error is to throw an exception. But it's hard to have a problem with a multiplication (hard but not impossible), - you implement a decomposition algorithm, and as a result you want 2 matrices (for example). You know that even for simple cases, you're going to run a good and long algorithm. And have 2 values (i.e. 2 matrices) in return. So it wouldn't be a bad idea to pass 2 empty matrices by reference where to store the result (it's just an example, your design may vary), and return a code which says if things went wrong or not. It could be a boolean value, an enum, or anything that is quickly interpretable. And you really don't want to include your decomposition algorithm into a bigger expression. You can simply decompose your complex calculations and have one line dedicated to the use of this decomposition algorithm. Therefore, I think a return code is a better idea.
Should we use exceptions or return codes ?
I agree with all that you've said on this. It's very true that one of the nice benefits of exceptions is that they allow you to retain the nice functional / expression syntax, that is, instead of having to do each operation on its own line, grabbing the error-code and checking it. For the purposes of operator overloads, I'm not really sure what kind of error could come out of those except for mismatching dimensions. I think that mismatching dimensions are the types of errors for which assert() exists, or similarly, the current check macro. I think that if there are certain multiplications that lead to NaN / INF values, I think that those can just remain like that, as it matches the behaviour of scalar operations. So, I think that the current error reporting strategy for the matrix / vector operator overloads is perfectly acceptable (i.e., catch mismatching dimensions with an assert(), leave the rest unchecked, as it is with scalar operators). I think that if people want to have checked operations (to prevent NaN / INF, or overflow / underflow problems), then they can use a library similar to Boost.Safe-Numerics for the value-types in the matrix-vector classes from uBlas. For the decomposition algorithms or solutions for inversion / eigen / Riccati / etc., I agree that there's no point in trying to retain too much of the "functional" style, as many of them are algorithms that have multiple (and optional) outputs, and can often be done in-place. Generally, that does mean that most outputs would be in the form of by-reference parameters (either as pure output parameters, or as input-output for in-place algorithms), which leaves the return-value free to be an error-code of some kind. And this is why I see this as a viable solution. However, after thinking about this more, I think that the best option might be to use a strategy similar to Boost.Asio. The idea there is to provide two overloads, one that takes an error-code by reference (which would be set to an error code value if an error occurred), and one that does not have the parameter (and throws an exception if an error occurs). The exception-throwing version simply wraps a call to the error-code version, and throws if the error-code is non-zero. And the beauty of that is that this overload can be disabled when compiling without exceptions (-fno-exceptions option) as per the BOOST_NO_EXCEPTIONS macro. This would allow those who prefer exceptions (like me) to use exceptions by simply not providing the error-code parameter. And anyone who disables exceptions is forced to collect the error-code for each algorithm called, and thus, is less likely to ignore those error conditions. It seems to me like it's really the best of both worlds, and it seems to work very well for Boost.Asio. The archetype for the implementation would be something like this: void some_algorithm(/* params */, system::error_code& err) { // primary implementation of some-algorithm here.. if( error occurred ) { err.assign(/* something */); return; }; }; #ifndef BOOST_NO_EXCEPTIONS void some_algorithm(/* params */) { system::error_code err; some_algorithm(/* forward params */, err); if(err) throw something(err); }; #endif There are a few other ways to achieve something similar to this. Boost.Asio does something slightly different (i.e., my version removes the exception-throwing version completely, while Boost.Asio retains it, but triggers an error later at link-time, which I don't really like). There are a number of trade-offs involved here. And, of course, you might have noticed that this does introduce the run-time overhead associated with using error-codes even when using the exception-throwing version, that's a bit annoying (as usually, using exceptions doesn't have this run-time overhead that error-codes have), but I think it's an acceptable trade-off here, as it's the only way to support disabling exceptions. What say you? Cheers, Mikael. -- Sven Mikael Persson, M.Sc.(Tech.) PhD Candidate and Vanier CGS Scholar, Department of Mechanical Engineering, McGill University,
On 15 Mar 2015 at 16:59, Mikael Persson wrote:
Should we use exceptions or return codes ?
I agree with all that you've said on this. It's very true that one of the nice benefits of exceptions is that they allow you to retain the nice functional / expression syntax, that is, instead of having to do each operation on its own line, grabbing the error-code and checking it.
The lightweight non-allocating future
overhead that error-codes have), but I think it's an acceptable trade-off here, as it's the only way to support disabling exceptions.
What say you?
apart from the fact it requires implementing a wrapper, which is not a big deal, it looks like a good solution. We loose the functional aspect because of passing the error code variable by reference, but we're not supposed to be that "functional" on error codes either. Sounds good to me.
If you don't have one, I think that OCTAVE maybe a good alternative for MATLAB 2015-03-10 21:18 GMT+08:00 Rajaditya Mukherjee < rajaditya.mukherjee@gmail.com>:
If you have a license of MATLAB, you can use the gallery function to generate some very good test matrices.
*Rajaditya Mukherjee * *3rd Year Graduate Student* Dept. of Computer Science and Engineering The Ohio State University Columbus, Ohio Tel :- +1-(614)-271-4439 email :- rajaditya.mukherjee@gmail.com
, raj@rajaditya.com On Tue, Mar 10, 2015 at 8:18 AM, Ganesh Prasad
wrote: Hey Dhruv I am an applicant myself, I think I can give you a few ideas regarding your queries.
1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library.
Go through the library source code thoroughly. Use a code dependency graph generator to browse code easily. (Easiest way is to run doxygen over the ublas directory). That will make going through the code real fast.
2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library.
Not sure about the format, but the tests should cover as many cases as possible.
Best wishes Ganesh Prasad
On 10 March 2015 at 15:03, Dhruv Kohli
wrote: Hello,
I am Dhruv, majoring in Mathematics & Computing from Indian Institute of Technology, Guwahati. After doing a bit of research over the project ideas, I found the idea of further developing boost.ublas library interesting and have started writing the programming competency code. Here is the link to the code I've written yet:
. Though the code is not yet complete, but a naive version of algorithm is implemented and is integrated into ublas. To me, the code seems to be running properly.
I need a little help for proceeding further. 1. Can someone please direct me to some code snippet that shows how the error handling code is written in boost library. To be specific, the gaussian elimination doesn't work on singular matrices. So, I would
https://github.com/chiggum/boost.ublas/blob/master/gaussian_elimination.hpp like
to
set the errno and display appropriate message to the user whenever a singular matrix is given as an input.
2. What sort of test code is required? Do we need to have a test case with hard-coded output to be checked against the results obtained when the test case is passed to the algo. Or there's some other predefined format for testing codes in boost library. Sorry, I haven't yet gone through most of the code in boost library.
Any further helpful links/resources are welcomed.
Thanks & Best regards, Dhruv https://github.com/chiggum
P.S. Sorry for reposting the mail. I am still waiting for a reply.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- with kind regards ------------------------------------------------------------------ Yan Ni, undergraduate of Department of Computer Science, School of Electronic Engineering & Computer Science, Peking University
participants (7)
-
David Bellot
-
Dhruv Kohli
-
Ganesh Prasad
-
Mikael Persson
-
Niall Douglas
-
Rajaditya Mukherjee
-
Yan Ni