giacomomonari@email.it wrote:
> On 30 Ago, 23:13, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
>> Right, but as you've found out, they don't need to be called :-)
>>
>> Now, what's lls? Is it by any chance empty? If not, and it's valid
>> (from the 'DataAnalysis' point of view), then you need to keep
>> digging in, find what in the constructor of 'DataAnalysis' makes the
>> program crash (yes, I understand that sometimes you can't go without
>> some steps, but you need to know how your 'lls' is used, what's done
>> to the iterators, etc.) Be fully aware of how your data are handled,
>> even if by somebody else's library.
>>
>> V
>
> lls isn't empty.
> I created the header "dataAnalysis.h", if you want I can enrtirely
> post it (and btw, how you hid part of your posts?
I am not versed in the problem domain as well as you (most people
here probably aren't), I don't have the source data you have (and
even if you share those, I am not sure I'd have the time to delve
into the details of your algorithm. *You* on the other hand hold
all the cards, you know what your program /should/ do, step after
step, so you're the best person to continue debugging it.
> It would be very
> useful if I'll post all the code ;))
No, it would not. Next after that you're going to post the source
data, so we can also run your program, and not just look at it.
And there are probably other pieces that you will either forget or
they are not allowed to be copied...
> I suspect that the bad part of my code could be like this:
>
> template <typename Itr, typename TYPE>
> TYPE DataAnalysis<Itr,TYPE>::ComputeVariance()
> {
> const TYPE initValue = (TYPE) (0.0);
> Itr averageConstFirst = dataLast++;
> std::fill_n(averageConstFirst,(dataLast - dataFirst), average);
> TYPE tmp = std::inner_product(dataFirst, dataLast, averageConstFirst,
> initValue, std::plus<TYPE>(), SquaredDifference<TYPE>()) ;
> tmp /= (TYPE) (dataLast - dataFirst - 1);
> return tmp;
> }
What's so bad about it?
> these (there are other similar) are functions of my code directely
> called from the constructor...
Well, if it's your constructor that's failing, try pulling it apart
and call those functions separately... You need to make sure that
the pieces from which you assemble your object are actually valid to
begin with. Are they? You don't have to answer, just figure it out
for yourself.
> I needed to use inner_product beetween the data vector and a vector of
> the same size that values "average" in every components.
Have those vectors been allocated (resized) to the proper length, or
are you using 'back_inserter'?
> So I used these strange lines:
> Itr averageConstFirst = dataLast++;
> std::fill_n(averageConstFirst,(dataLast - dataFirst), average);
> in order to create that all-average-vector and not write on data
> vector (all using iterators)...
OK. Does 'fill_n' insert or does it assign? Does your vector (to
which 'dataLast' and 'dataFirst' are iterators) have enough room in
it to contain your averages (in case 'fill_n' actually assigns and
doesn't insert)? If you have access to the vector, resize it right
before 'fill_n' to twice its current size, and see what happens.
> But this doesn't seem a very elegant solution and could be the spring
> of the problems... What do you think? Should I post the entire code?
<shrug> Post it if you must. Keep in mind that everybody in this
newsgroup also has other things to do in their lives than fix your
code, no offense intended. Besides, if you fix it yourself you not
only will have more pride in your work, you'll also learn more than
if somebody else does it.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask