Re: Returning matrices with errors
Status: Pre-Alpha
Brought to you by:
cassioneri
From: Questions r. to t. u. of KeyValue.
<key...@li...> - 2011-03-03 01:24:52
|
Hi, Unfortunately, you can't put a #NULL in just one matrix entry but this is planned to be possible in the future. For the time being I suggest the approach given in the code below. In there, I'm supposing that nRows, nCols are known (size_t's) and your core library implements a function double calc(i, j) which computes the (i,j)-th entry of the matrix. keyvalue::value::Matrix m(nRows, nCols); for (size_t i = 0; i < nRows; ++i) { for (size_t j = 0; j < nCols; ++j) { try { m(i, j) = calc(i, j); } catch (...) { m(i, j) = something_that_indicates_an_error; } } } For something_that_indicates_an_error I have two suggestions: 1) An obviously invalid value: For instance, if your matrix is supposed to contain only positive numbers, then something_that_indicates_an_error could be 0.0, -1.0, std::numeric_limits<double>::quiet_NaN() or std::numeric_limits<double>::infinity(). Unfortunately, for the last two approaches, Excel shows 2.6965E+308 and 1.7977E+308, resp. 2) A string error message: Recall that keyvalue::value::Matrix entries are of type keyvalue::value::Variant and, therefore, they can hold the same types as Variants do. In particular they can be strings. Then, you can set something_that_indicates_an_error to "" (an empty string) or "Error" or, "#NULL", if you wish to fake an Excel error. A remark on the second suggestion. A keyvalue::value::Variant can also hold a type keyvalue::value::Nothing which indicates no data. My first idea was letting something_that_indicates_an_error to be this type but, unfortunately, I just realized that Excel considers it as 0.0. This is not a good thing and I'm going to change this behaviour. I was wondering to allow keyvalue::value::Variant to hold some type indicating an error that, latter, Excel would convert to #NULL. I thought, for instance to allow this type to be keyvalue::RuntimeError. Any suggestion? Cheers, Cassio. On Wed, Mar 2, 2011 at 9:32 AM, Questions relating to the use of KeyValue. <key...@li...> wrote: > Hi, > > I have a processor which computes and returns a keyvalue::value::Matrix to > Excel. > > Often, some (but not all) entries of this matrix cannot be computed and my > core library throws an exception. > > In that case the matrix appers in Excel filled with #NULLs. > > I would like to catch the exception for any failing entry and resume the > computations to have the right numbers whenever possible. How can I put a > #NULL in the failing entries to indicate the failure to the spreadsheet > user? > > Thanks a lot for your help! > > _______________________________________________ > KeyValue-users mailing list > Key...@li... > https://lists.sourceforge.net/lists/listinfo/keyvalue-users > > |