text.cc (7504:ad631c296c9b) | text.cc (7505:7772a8bf76ee) |
---|---|
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 292 unchanged lines hidden (view full) --- 301struct DistPrint 302{ 303 string name; 304 string desc; 305 Flags flags; 306 bool descriptions; 307 int precision; 308 | 1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 292 unchanged lines hidden (view full) --- 301struct DistPrint 302{ 303 string name; 304 string desc; 305 Flags flags; 306 bool descriptions; 307 int precision; 308 |
309 Counter min; 310 Counter max; 311 Counter bucket_size; 312 size_type size; 313 DistType type; 314 | |
315 const DistData &data; 316 317 DistPrint(const Text *text, const DistInfo &info); 318 DistPrint(const Text *text, const VectorDistInfo &info, int i); | 309 const DistData &data; 310 311 DistPrint(const Text *text, const DistInfo &info); 312 DistPrint(const Text *text, const VectorDistInfo &info, int i); |
319 void init(const Text *text, const Info &info, const DistParams *params); | 313 void init(const Text *text, const Info &info); |
320 void operator()(ostream &stream) const; 321}; 322 323DistPrint::DistPrint(const Text *text, const DistInfo &info) 324 : data(info.data) 325{ | 314 void operator()(ostream &stream) const; 315}; 316 317DistPrint::DistPrint(const Text *text, const DistInfo &info) 318 : data(info.data) 319{ |
326 init(text, info, safe_cast<const DistParams *>(info.storageParams)); | 320 init(text, info); |
327} 328 329DistPrint::DistPrint(const Text *text, const VectorDistInfo &info, int i) 330 : data(info.data[i]) 331{ | 321} 322 323DistPrint::DistPrint(const Text *text, const VectorDistInfo &info, int i) 324 : data(info.data[i]) 325{ |
332 init(text, info, safe_cast<const DistParams *>(info.storageParams)); | 326 init(text, info); |
333 334 name = info.name + "_" + 335 (info.subnames[i].empty() ? (to_string(i)) : info.subnames[i]); 336 337 if (!info.subdescs[i].empty()) 338 desc = info.subdescs[i]; 339} 340 341void | 327 328 name = info.name + "_" + 329 (info.subnames[i].empty() ? (to_string(i)) : info.subnames[i]); 330 331 if (!info.subdescs[i].empty()) 332 desc = info.subdescs[i]; 333} 334 335void |
342DistPrint::init(const Text *text, const Info &info, const DistParams *params) | 336DistPrint::init(const Text *text, const Info &info) |
343{ 344 name = info.name; 345 desc = info.desc; 346 flags = info.flags; 347 precision = info.precision; 348 descriptions = text->descriptions; | 337{ 338 name = info.name; 339 desc = info.desc; 340 flags = info.flags; 341 precision = info.precision; 342 descriptions = text->descriptions; |
349 350 type = params->type; 351 switch (type) { 352 case Dist: 353 min = params->min; 354 max = params->max; 355 bucket_size = params->bucket_size; 356 size = params->buckets; 357 break; 358 case Deviation: 359 break; 360 default: 361 panic("unknown distribution type"); 362 } | |
363} 364 365void 366DistPrint::operator()(ostream &stream) const 367{ 368 string base = name + "::"; 369 370 ScalarPrint print; --- 15 unchanged lines hidden (view full) --- 386 Result stdev = NAN; 387 if (data.samples) 388 stdev = sqrt((data.samples * data.squares - data.sum * data.sum) / 389 (data.samples * (data.samples - 1.0))); 390 print.name = base + "stdev"; 391 print.value = stdev; 392 print(stream); 393 | 343} 344 345void 346DistPrint::operator()(ostream &stream) const 347{ 348 string base = name + "::"; 349 350 ScalarPrint print; --- 15 unchanged lines hidden (view full) --- 366 Result stdev = NAN; 367 if (data.samples) 368 stdev = sqrt((data.samples * data.squares - data.sum * data.sum) / 369 (data.samples * (data.samples - 1.0))); 370 print.name = base + "stdev"; 371 print.value = stdev; 372 print(stream); 373 |
394 if (type == Deviation) | 374 if (data.type == Deviation) |
395 return; 396 | 375 return; 376 |
397 assert(size == data.cvec.size()); | 377 size_t size = data.cvec.size(); |
398 399 Result total = 0.0; 400 if (data.underflow != NAN) 401 total += data.underflow; 402 for (off_type i = 0; i < size; ++i) 403 total += data.cvec[i]; 404 if (data.overflow != NAN) 405 total += data.overflow; --- 8 unchanged lines hidden (view full) --- 414 print.update(data.underflow, total); 415 print(stream); 416 } 417 418 for (off_type i = 0; i < size; ++i) { 419 stringstream namestr; 420 namestr << base; 421 | 378 379 Result total = 0.0; 380 if (data.underflow != NAN) 381 total += data.underflow; 382 for (off_type i = 0; i < size; ++i) 383 total += data.cvec[i]; 384 if (data.overflow != NAN) 385 total += data.overflow; --- 8 unchanged lines hidden (view full) --- 394 print.update(data.underflow, total); 395 print(stream); 396 } 397 398 for (off_type i = 0; i < size; ++i) { 399 stringstream namestr; 400 namestr << base; 401 |
422 Counter low = i * bucket_size + min; 423 Counter high = ::min(low + bucket_size - 1.0, max); | 402 Counter low = i * data.bucket_size + data.min; 403 Counter high = ::min(low + data.bucket_size - 1.0, data.max); |
424 namestr << low; 425 if (low < high) 426 namestr << "-" << high; 427 428 print.name = namestr.str(); 429 print.update(data.cvec[i], total); 430 print(stream); 431 } --- 186 unchanged lines hidden --- | 404 namestr << low; 405 if (low < high) 406 namestr << "-" << high; 407 408 print.name = namestr.str(); 409 print.update(data.cvec[i], total); 410 print(stream); 411 } --- 186 unchanged lines hidden --- |