clvcooke / MatrixMath

A from scratch implementation of basic matrix manipulation and operations in C++
0 stars 2 forks source link

Failure Value/Garbage matrix for failed matrix operation #11

Open clvcooke opened 9 years ago

clvcooke commented 9 years ago

We often encounter situations when doing certain operations is illegal, and we want to make sure that we don't try anything that isn't mathematically possibly. So far we have been doing a good job of checking if the operation is valid before doing it, but we don't yet have a unified approach to what to do under that failure condition. Should we return a zero by zero matrix, the identity matrix, or throw an exception(out of the bounds of GENE 121) or just fill the users screen with millions of randomly changing numbers?

RowanFerrabee commented 9 years ago

EXCEPTIONS!

clvcooke commented 9 years ago

I can agree with exceptions, simple implementation and very attention grabbing

sazisurv commented 9 years ago

Sorry guys. Was a bit busy. If we are trying to stay within the scope of gene 121, then i suggest we stick to returning zero. What I would do if it were java is to use a TryCatch failure, which works roughly the same as an Exception. Its a lot cleaner.

On Fri, Dec 5, 2014 at 5:35 PM, Colin Langdon Vernon Cooke < notifications@github.com> wrote:

I can agree with exceptions, simple implementation and very attention grabbing

— Reply to this email directly or view it on GitHub https://github.com/clvc/MatrixMath/issues/11#issuecomment-65871827.

neilparikh commented 9 years ago

How about returning NULL?

ericye16 commented 9 years ago

NULL only works for pointers (I think?). @sazisurv try/catches and exceptions are the same mechanism.

RowanFerrabee commented 9 years ago

We could define our "NULL_Matrix" as being a 0x0 matrix such that elements = NULL and just operate with that as our illegal operator return value since 0x0 matrices are never really used.

I also think using a 1x1 matrix containing elements[0][0] = numeric_limits::infinity could be helpful since a) it's obvious and easy to catch and b) matrices containing infinite elements are scarcely used and c) in the case that the error is not caught, operations with infinity tend to also yield infinity which works since infinity is already our garbage value.

ericye16 commented 9 years ago

Maybe a 1x1 with NaN?