libmsnumpress
Numerical compression schemes for proteomics mass spectrometry data
Loading...
Searching...
No Matches
Functions | Variables
MSNumpressTest.cpp File Reference
#include "MSNumpress.hpp"
#include <assert.h>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <stdio.h>
Include dependency graph for MSNumpressTest.cpp:

Go to the source code of this file.

Functions

void encodeLinear1 ()
 
void encodeLinear ()
 
void decodeLinearNice ()
 
void decodeLinearNiceLowFP ()
 
void decodeLinearWierd ()
 
void decodeLinearWierd_llong_overflow ()
 
void decodeLinearWierd_int_overflow ()
 
void decodeLinearWierd_int_underflow ()
 
void decodeLinearCorrupt1 ()
 
void decodeLinearCorrupt2 ()
 
void optimalLinearFixedPoint ()
 
void optimalLinearFixedPointMass ()
 
void encodeDecodeLinearStraight ()
 
void encodeDecodeSafeStraight ()
 
void encodeDecodeSafe ()
 
void encodeDecodeLinear ()
 
void encodeDecodeLinear5 ()
 
void encodeDecodePic ()
 
void encodeDecodePic5 ()
 
void optimalSlofFixedPoint ()
 
void encodeDecodeSlof ()
 
void encodeDecodeSlof5 ()
 
void testErroneousDecodePic ()
 
int main (int argc, const char *argv[])
 

Variables

double ENC_TWO_BYTE_FIXED_POINT = 3000.0
 

Function Documentation

◆ decodeLinearCorrupt1()

void decodeLinearCorrupt1 ( )

Definition at line 279 of file MSNumpressTest.cpp.

279 {
280 unsigned char encoded[20];
281 double decoded[4];
282
283 try {
284 ms::numpress::MSNumpress::decodeLinear(&encoded[0], 11, &decoded[0]);
285 cout << "- fail decodeLinearCorrupt1: didn't throw exception for corrupt input " << endl << endl;
286 assert(0 == 1);
287 } catch (const char *err) {
288
289 }
290
291 try {
292 ms::numpress::MSNumpress::decodeLinear(&encoded[0], 14, &decoded[0]);
293 cout << "- fail decodeLinearCorrupt1: didn't throw exception for corrupt input " << endl << endl;
294 assert(0 == 1);
295 } catch (const char *err) {
296
297 }
298
299 cout << "+ pass decodeLinearCorrupt 1 " << endl << endl;
300}
size_t decodeLinear(const unsigned char *data, const size_t dataSize, double *result)

References ms::numpress::MSNumpress::decodeLinear().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeLinearCorrupt2()

void decodeLinearCorrupt2 ( )

Definition at line 303 of file MSNumpressTest.cpp.

303 {
304
305 double mzs[4];
306
307 mzs[0] = 100.0;
308 mzs[1] = 200.0;
309 mzs[2] = 300.00005;
310 mzs[3] = 0.00010;
311
312 size_t nMzs = 4;
313 unsigned char encoded[28];
314 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], nMzs);
315 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], fixedPoint);
316
317 double decoded[4];
318 try {
319 ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes-1, &decoded[0]);
320 cout << "- fail decodeLinearCorrupt2: didn't throw exception for corrupt input " << endl << endl;
321 assert(0 == 1);
322 } catch (const char *err) {
323
324 }
325
326 cout << "+ pass decodeLinearCorrupt 2 " << endl << endl;
327}
double optimalLinearFixedPoint(const double *data, size_t dataSize)
size_t encodeLinear(const double *data, size_t dataSize, unsigned char *result, double fixedPoint)

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeLinearNice()

void decodeLinearNice ( )

Definition at line 86 of file MSNumpressTest.cpp.

86 {
87
88 double mzs[4];
89
90 mzs[0] = 100.0;
91 mzs[1] = 200.0;
92 mzs[2] = 300.00005;
93 mzs[3] = 400.00010;
94
95 size_t nMzs = 4;
96 unsigned char encoded[28];
97 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], nMzs);
98 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], fixedPoint);
99
100 double decoded[4];
101 size_t numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
102 assert(4 == numDecoded);
103 assert(abs(100.0 - decoded[0]) < 0.000005);
104 assert(abs(200.0 - decoded[1]) < 0.000005);
105 assert(abs(300.00005 - decoded[2]) < 0.000005);
106 assert(abs(400.00010 - decoded[3]) < 0.000005);
107
108 cout << "+ pass decodeLinearNice " << endl << endl;
109}

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeLinearNiceLowFP()

void decodeLinearNiceLowFP ( )

Definition at line 111 of file MSNumpressTest.cpp.

111 {
112
113 double mzs[7];
114
115 mzs[0] = 100.0;
116 mzs[1] = 200.0;
117 mzs[2] = 300.00005;
118 mzs[3] = 400.00010;
119 mzs[4] = 450.00010;
120 mzs[5] = 455.00010;
121 mzs[6] = 700.00010;
122
123 size_t nMzs = 7;
124 unsigned char encoded[33]; // max length is 33 bytes
125
126 // check for fixed points
127 {
128 double fixedPoint;
129 fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, 0.1);
130 assert( abs(5 - fixedPoint) < 0.000005);
131
132 fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, 1e-3);
133 assert( abs(500 - fixedPoint) < 0.000005);
134
135 fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, 1e-5);
136 assert( abs(50000 - fixedPoint) < 0.000005);
137
138 fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, 1e-7);
139 assert( abs(5000000 - fixedPoint) < 0.000005);
140
141 // cannot fulfill accuracy of 1e-8
142 fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, 1e-8);
143 assert( abs(-1 - fixedPoint) < 0.000005);
144 }
145
146 {
147 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, 0.001);
148 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], fixedPoint);
149
150 double decoded[7];
151 size_t numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
152 assert(25 == encodedBytes);
153 assert(7 == numDecoded);
154
155 assert(abs(100.0 - decoded[0]) < 0.001);
156 assert(abs(200.0 - decoded[1]) < 0.001);
157 assert(abs(300.00005 - decoded[2]) < 0.001);
158 assert(abs(400.00010 - decoded[3]) < 0.001);
159 }
160
161 double mz_err[5];
162 double encodedLength[5];
163
164 // for higher accuracy, we get longer encoded lengths
165 mz_err[0] = 0.1; encodedLength[0] = 22;
166 mz_err[1] = 1e-3; encodedLength[1] = 25;
167 mz_err[2] = 1e-5; encodedLength[2] = 29;
168 mz_err[3] = 1e-6; encodedLength[3] = 30;
169 mz_err[4] = 1e-7; encodedLength[4] = 31;
170
171 for (int k = 0; k < 4; k++)
172 {
173 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPointMass(&mzs[0], nMzs, mz_err[k]);
174 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], fixedPoint);
175
176 double decoded[7];
177 size_t numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
178 assert( encodedLength[k] == encodedBytes);
179 assert(7 == numDecoded);
180 assert(abs(100.0 - decoded[0]) < mz_err[k]);
181 assert(abs(200.0 - decoded[1]) < mz_err[k]);
182 assert(abs(300.00005 - decoded[2]) < mz_err[k]);
183 assert(abs(400.00010 - decoded[3]) < mz_err[k]);
184 assert(abs(450.00010 - decoded[4]) < mz_err[k]);
185 assert(abs(455.00010 - decoded[5]) < mz_err[k]);
186 assert(abs(700.00010 - decoded[6]) < mz_err[k]);
187 }
188
189 cout << "+ pass decodeLinearNiceFP " << endl << endl;
190}
double optimalLinearFixedPointMass(const double *data, size_t dataSize, double mass_acc)

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPointMass().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeLinearWierd()

void decodeLinearWierd ( )

Definition at line 192 of file MSNumpressTest.cpp.

192 {
193 double mzs[4];
194
195 mzs[0] = 100.0;
196 mzs[1] = 200.0;
197 mzs[2] = 300.00005;
198 mzs[3] = 0.00010;
199
200 size_t nMzs = 4;
201 unsigned char encoded[28];
202 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], nMzs);
203 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], fixedPoint);
204
205 double decoded[4];
206 size_t numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
207 assert(4 == numDecoded);
208 assert(abs(100.0 - decoded[0]) < 0.000005);
209 assert(abs(200.0 - decoded[1]) < 0.000005);
210 assert(abs(300.00005 - decoded[2]) < 0.000005);
211 assert(abs(0.00010 - decoded[3]) < 0.000005);
212
213 cout << "+ pass decodeLinearWierd " << endl << endl;
214}

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeLinearWierd_int_overflow()

void decodeLinearWierd_int_overflow ( )

Definition at line 237 of file MSNumpressTest.cpp.

237 {
238 double mzs[4];
239
240 mzs[0] = 100.0;
241 mzs[1] = 200.0;
242 mzs[2] = 30000000.00005;
243 mzs[3] = 0.00006;
244
245 size_t nMzs = 4;
246 unsigned char encoded[28];
247
248 try {
249 ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], 1000000000);
250 cout << "- fail test decodeLinearWierd_int_overflow: didn't throw exception for corrupt input " << endl << endl;
251 assert(0 == 1);
252 } catch (const char *err) {
253 assert( std::string(err) == std::string("[MSNumpress::encodeLinear] Cannot encode a number that exceeds the bounds of [-INT_MAX, INT_MAX]."));
254 }
255 cout << "+ pass decodeLinearWierd3 " << endl << endl;
256}

References ms::numpress::MSNumpress::encodeLinear().

Here is the call graph for this function:

◆ decodeLinearWierd_int_underflow()

void decodeLinearWierd_int_underflow ( )

Definition at line 258 of file MSNumpressTest.cpp.

258 {
259 double mzs[4];
260
261 mzs[0] = 30000000.00005;
262 mzs[1] = 60000000.00005;
263 mzs[2] = 30000000.00005;
264 mzs[3] = 0.00006;
265
266 size_t nMzs = 4;
267 unsigned char encoded[28];
268
269 try {
270 ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], 1000000000);
271 cout << "- fail test decodeLinearWierd_int_underflow: didn't throw exception for corrupt input " << endl << endl;
272 assert(0 == 1);
273 } catch (const char *err) {
274 assert( std::string(err) == std::string("[MSNumpress::encodeLinear] Cannot encode a number that exceeds the bounds of [-INT_MAX, INT_MAX]."));
275 }
276 cout << "+ pass decodeLinearWierd3 " << endl << endl;
277}

References ms::numpress::MSNumpress::encodeLinear().

Here is the call graph for this function:

◆ decodeLinearWierd_llong_overflow()

void decodeLinearWierd_llong_overflow ( )

Definition at line 216 of file MSNumpressTest.cpp.

216 {
217 double mzs[4];
218
219 mzs[0] = 100.0;
220 mzs[1] = 200.0;
221 mzs[2] = 30000000.00005;
222 mzs[3] = 0.000010;
223
224 size_t nMzs = 4;
225 unsigned char encoded[28];
226
227 try {
228 ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], 1000000000000);
229 cout << "- fail test decodeLinearWierd_llong_overflow: didn't throw exception for corrupt input " << endl << endl;
230 assert(0 == 1);
231 } catch (const char *err) {
232 assert( std::string(err) == std::string("[MSNumpress::encodeLinear] Next number overflows LLONG_MAX."));
233 }
234 cout << "+ pass decodeLinearWierd_llong_overflow " << endl << endl;
235}

References ms::numpress::MSNumpress::encodeLinear().

Here is the call graph for this function:

◆ encodeDecodeLinear()

void encodeDecodeLinear ( )

Definition at line 475 of file MSNumpressTest.cpp.

475 {
476 srand(123459);
477
478 size_t n = 1000;
479 double mzs[1000];
480 mzs[0] = 300 + rand() / double(RAND_MAX);
481 for (size_t i=1; i<n; i++)
482 mzs[i] = mzs[i-1] + rand() / double(RAND_MAX);
483
484 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], n);
485
486 unsigned char encoded[5000];
487 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], n, &encoded[0], fixedPoint);
488
489 double decoded[1000];
490 size_t numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
491
492 assert(n == numDecoded);
493
494 double m = 0;
495 double error;
496 double mLim = 0.000005;
497
498 for (size_t i=0; i<n; i++) {
499 error = abs(mzs[i] - decoded[i]);
500 m = max(m, error);
501 if (error >= mLim) {
502 cout << "error " << error << " above limit " << mLim << endl;
503 assert(error < mLim);
504 }
505 }
506 cout << "+ size compressed: " << encodedBytes / double(n*8) * 100 << "% " << endl;
507 cout << "+ max error: " << m << " limit: " << mLim << endl;
508 cout << "+ pass encodeDecodeLinear " << endl << endl;
509}

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodeLinear5()

void encodeDecodeLinear5 ( )

Definition at line 513 of file MSNumpressTest.cpp.

513 {
514 srand(123662);
515
516 size_t n = 1000;
517 double mzs[1000];
518 mzs[0] = 100 + (rand() % 1000) / 1000.0;
519 for (size_t i=1; i<n; i++)
520 mzs[i] = mzs[i-1] + (rand() % 1000) / 1000.0;
521
522 size_t encodedBytes;
523 size_t numDecoded;
524 unsigned char encoded[5000];
525 double firstDecoded[1000];
526 double decoded[1000];
527
528 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], n);
529
530 encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], n, &encoded[0], fixedPoint);
531 numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
532
533 for (size_t i=0; i<n; i++)
534 firstDecoded[i] = decoded[i];
535
536 for (size_t i=0; i<5; i++) {
537 encodedBytes = ms::numpress::MSNumpress::encodeLinear(&decoded[0], n, &encoded[0], fixedPoint);
538 numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
539 }
540
541 double afterFixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&decoded[0], n);
542
543 assert(fixedPoint == afterFixedPoint);
544 assert(n == numDecoded);
545
546 for (size_t i=0; i<n; i++)
547 if (firstDecoded[i] != decoded[i]) {
548 cout << endl << firstDecoded[i] << " " << decoded[i] << endl;
549 assert(firstDecoded[i] == decoded[i]);
550 }
551
552 cout << "+ pass encodeDecodeLinear5 " << endl << endl;
553}

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodeLinearStraight()

void encodeDecodeLinearStraight ( )

Definition at line 370 of file MSNumpressTest.cpp.

370 {
371 size_t n = 15;
372 double mzs[15];
373 for (size_t i=0; i<n; i++)
374 mzs[i] = i;
375
376 double fixedPoint = ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], n);
377
378 unsigned char encoded[75];
379 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], n, &encoded[0], fixedPoint);
380
381 double decoded[15];
382 size_t numDecoded = ms::numpress::MSNumpress::decodeLinear(&encoded[0], encodedBytes, &decoded[0]);
383
384 assert(n == numDecoded);
385
386 double m = 0;
387 double error;
388 double mLim = 0.000005;
389
390 for (size_t i=0; i<n; i++) {
391 error = abs(mzs[i] - decoded[i]);
392 m = max(m, error);
393 if (error >= mLim) {
394 cout << "error " << error << " above limit " << mLim << endl;
395 assert(error < mLim);
396 }
397 }
398 cout << "+ size compressed: " << encodedBytes / double(n*8) * 100 << "% " << endl;
399 cout << "+ max error: " << m << " limit: " << mLim << endl;
400 cout << "+ pass encodeDecodeLinearStraight " << endl << endl;
401}

References ms::numpress::MSNumpress::decodeLinear(), ms::numpress::MSNumpress::encodeLinear(), and ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodePic()

void encodeDecodePic ( )

Definition at line 557 of file MSNumpressTest.cpp.

557 {
558 srand(123459);
559
560 size_t n = 1000;
561 double ics[1000];
562 for (size_t i=0; i<n; i++)
563 ics[i] = rand() % 1000000;
564
565 unsigned char encoded[5000];
566 size_t encodedBytes = ms::numpress::MSNumpress::encodePic(&ics[0], n, &encoded[0]);
567
568 double decoded[1000];
569 size_t numDecoded = ms::numpress::MSNumpress::decodePic(&encoded[0], encodedBytes, &decoded[0]);
570
571 assert(n == numDecoded);
572
573 for (size_t i=0; i<n; i++)
574 assert(abs(ics[i] - decoded[i]) < 0.5);
575
576 cout << "+ pass encodeDecodePic " << endl << endl;
577}
size_t encodePic(const double *data, size_t dataSize, unsigned char *result)
size_t decodePic(const unsigned char *data, const size_t dataSize, double *result)

References ms::numpress::MSNumpress::decodePic(), and ms::numpress::MSNumpress::encodePic().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodePic5()

void encodeDecodePic5 ( )

Definition at line 581 of file MSNumpressTest.cpp.

581 {
582 srand(123459);
583
584 size_t n = 1000;
585 double ics[1000];
586 for (size_t i=0; i<n; i++)
587 ics[i] = rand() % 1000000;
588
589 ics[1] = 0.0;
590 ics[2] = 0.0001;
591 ics[3] = 0.0002;
592
593 size_t encodedBytes;
594 size_t numDecoded;
595 unsigned char encoded[5000];
596 double firstDecoded[1000];
597 double decoded[1000];
598
599 encodedBytes = ms::numpress::MSNumpress::encodePic(&ics[0], n, &encoded[0]);
600 numDecoded = ms::numpress::MSNumpress::decodePic(&encoded[0], encodedBytes, &decoded[0]);
601
602 for (size_t i=0; i<n; i++)
603 firstDecoded[i] = decoded[i];
604
605 for (size_t i=0; i<5; i++) {
606 encodedBytes = ms::numpress::MSNumpress::encodePic(&decoded[0], n, &encoded[0]);
607 numDecoded = ms::numpress::MSNumpress::decodePic(&encoded[0], encodedBytes, &decoded[0]);
608 }
609
610 assert(n == numDecoded);
611
612 for (size_t i=0; i<n; i++)
613 if (firstDecoded[i] != decoded[i]) {
614 cout << endl << firstDecoded[i] << " " << decoded[i] << endl;
615 assert(firstDecoded[i] == decoded[i]);
616 }
617
618 cout << "+ pass encodeDecodePic5 " << endl << endl;
619}

References ms::numpress::MSNumpress::decodePic(), and ms::numpress::MSNumpress::encodePic().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodeSafe()

void encodeDecodeSafe ( )

Definition at line 443 of file MSNumpressTest.cpp.

443 {
444 srand(123459);
445
446 double error;
447 double eLim = 1.0e-300;
448 size_t n = 1000;
449 double mzs[1000];
450 mzs[0] = 300 + rand() / double(RAND_MAX);
451 for (size_t i=1; i<n; i++)
452 mzs[i] = mzs[i-1] + rand() / double(RAND_MAX);
453
454 unsigned char encoded[8000];
455 size_t encodedBytes = ms::numpress::MSNumpress::encodeSafe(&mzs[0], n, &encoded[0]);
456
457 assert(encodedBytes == n*8);
458
459 double decoded[1000];
460 size_t numDecoded = ms::numpress::MSNumpress::decodeSafe(&encoded[0], encodedBytes, &decoded[0]);
461
462 assert(numDecoded == n);
463 for (size_t i=0; i<n; i++) {
464 error = abs(mzs[i] - decoded[i]);
465 if (error >= eLim) {
466 cout << "error " << error << " is non-zero ( >= " << eLim << " )" << endl;
467 assert(error == 0);
468 }
469 }
470 cout << "+ pass encodeDecodeSafe " << endl << endl;
471}
size_t encodeSafe(const double *data, const size_t dataSize, unsigned char *result)
size_t decodeSafe(const unsigned char *data, const size_t dataSize, double *result)

References ms::numpress::MSNumpress::decodeSafe(), and ms::numpress::MSNumpress::encodeSafe().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodeSafeStraight()

void encodeDecodeSafeStraight ( )

Definition at line 405 of file MSNumpressTest.cpp.

405 {
406 double error;
407 double eLim = 1.0e-300;
408 size_t n = 15;
409 double mzs[15];
410 for (size_t i=0; i<n; i++)
411 mzs[i] = i+1;
412
413 unsigned char encoded[8000];
414 size_t encodedBytes = ms::numpress::MSNumpress::encodeSafe(&mzs[0], n, &encoded[0]);
415
416 /*
417 printf("\n");
418 assert(encodedBytes == n*8);
419 for (size_t i=0; i<n; i++) {
420 for (size_t j=0; j<8; j++) {
421 printf("%x ", encoded[i*8 + j]);
422 }
423 printf("\n");
424 }
425 */
426
427 double decoded[1000];
428 size_t numDecoded = ms::numpress::MSNumpress::decodeSafe(&encoded[0], encodedBytes, &decoded[0]);
429
430 assert(numDecoded == n);
431 for (size_t i=0; i<n; i++) {
432 error = abs(mzs[i] - decoded[i]);
433 if (error >= eLim) {
434 cout << "error " << error << " is non-zero ( >= " << eLim << " )" << endl;
435 assert(error == 0);
436 }
437 }
438 cout << "+ pass encodeDecodeSafeStraight " << endl << endl;
439}

References ms::numpress::MSNumpress::decodeSafe(), and ms::numpress::MSNumpress::encodeSafe().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodeSlof()

void encodeDecodeSlof ( )

Definition at line 638 of file MSNumpressTest.cpp.

638 {
639 srand(123459);
640
641 size_t n = 1000;
642 double ics[1000];
643 for (size_t i=0; i<n; i++)
644 ics[i] = rand() % 1000000;
645
646 ics[1] = 0.0;
647 ics[2] = 0.0001;
648 ics[3] = 0.0002;
649
650 double fixedPoint = ms::numpress::MSNumpress::optimalSlofFixedPoint(&ics[0], n);
651
652 unsigned char encoded[5000];
653 size_t encodedBytes = ms::numpress::MSNumpress::encodeSlof(&ics[0], n, &encoded[0], fixedPoint);
654
655 double decoded[1000];
656 size_t numDecoded = ms::numpress::MSNumpress::decodeSlof(&encoded[0], encodedBytes, &decoded[0]);
657
658 assert(n == numDecoded);
659
660 double m = 0;
661 double rm = 0;
662 double mLim = 0.0005;
663 double rmLim = 0.0005;
664 double error;
665
666 for (size_t i=0; i<n; i++)
667 if (ics[i] < 1.0) {
668 error = abs(ics[i] - decoded[i]);
669 m = max(m, error);
670 if (error >= mLim) {
671 cout << endl << ics[i] << " " << decoded[i] << endl;
672 assert(error < mLim);
673 }
674 } else {
675 error = abs((ics[i] - decoded[i]) / ((ics[i] + decoded[i])/2));
676 rm = max(rm, error);
677 if (error >= rmLim) {
678 cout << endl << ics[i] << " " << decoded[i] << endl;
679 assert(error < rmLim);
680 }
681 }
682 cout << "+ max error: " << m << " limit: " << mLim << endl;
683 cout << "+ max rel error: " << rm << " limit: " << rmLim << endl;
684 cout << "+ pass encodeDecodeSlof " << endl << endl;
685}
double optimalSlofFixedPoint(const double *data, size_t dataSize)
size_t decodeSlof(const unsigned char *data, const size_t dataSize, double *result)
size_t encodeSlof(const double *data, size_t dataSize, unsigned char *result, double fixedPoint)

References ms::numpress::MSNumpress::decodeSlof(), ms::numpress::MSNumpress::encodeSlof(), and ms::numpress::MSNumpress::optimalSlofFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeDecodeSlof5()

void encodeDecodeSlof5 ( )

Definition at line 689 of file MSNumpressTest.cpp.

689 {
690 srand(123459);
691
692 size_t n = 1000;
693 double ics[1000];
694 for (size_t i=0; i<n; i++)
695 ics[i] = rand() % 1000000;
696
697 ics[1] = 0.0;
698 ics[2] = 0.0001;
699 ics[3] = 0.0002;
700
701 double fixedPoint = ms::numpress::MSNumpress::optimalSlofFixedPoint(&ics[0], n);
702
703 size_t encodedBytes;
704 size_t numDecoded;
705 unsigned char encoded[5000];
706 double firstDecoded[1000];
707 double decoded[1000];
708
709 encodedBytes = ms::numpress::MSNumpress::encodeSlof(&ics[0], n, &encoded[0], fixedPoint);
710 numDecoded = ms::numpress::MSNumpress::decodeSlof(&encoded[0], encodedBytes, &decoded[0]);
711
712 for (size_t i=0; i<n; i++)
713 firstDecoded[i] = decoded[i];
714
715 for (size_t i=0; i<5; i++) {
716 encodedBytes = ms::numpress::MSNumpress::encodeSlof(&decoded[0], n, &encoded[0], fixedPoint);
717 numDecoded = ms::numpress::MSNumpress::decodeSlof(&encoded[0], encodedBytes, &decoded[0]);
718 }
719
720 double afterFixedPoint = ms::numpress::MSNumpress::optimalSlofFixedPoint(&decoded[0], n);
721
722 assert(n == numDecoded);
723 assert(fixedPoint == afterFixedPoint);
724
725 for (size_t i=0; i<n; i++)
726 if (firstDecoded[i] != decoded[i]) {
727 cout << endl << firstDecoded[i] << " " << decoded[i] << endl;
728 assert(firstDecoded[i] == decoded[i]);
729 }
730
731 cout << "+ pass encodeDecodeSlof5 " << endl << endl;
732}

References ms::numpress::MSNumpress::decodeSlof(), ms::numpress::MSNumpress::encodeSlof(), and ms::numpress::MSNumpress::optimalSlofFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeLinear()

void encodeLinear ( )

Definition at line 63 of file MSNumpressTest.cpp.

63 {
64 double mzs[4];
65
66 mzs[0] = 100.0;
67 mzs[1] = 200.0;
68 mzs[2] = 300.00005;
69 mzs[3] = 400.00010;
70
71 size_t nMzs = 4;
72 unsigned char encoded[20];
73 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], 100000.0);
74
75 assert(18 == encodedBytes);
76 assert(0x80 == encoded[8]);
77 assert(0x96 == encoded[9]);
78 assert(0x98 == encoded[10]);
79 assert(0x00 == encoded[11]);
80 assert(0x75 == encoded[16]);
81 assert(0x80 == encoded[17]);
82
83 cout << "+ pass encodeLinear " << endl << endl;
84}

References ms::numpress::MSNumpress::encodeLinear().

Referenced by ms::numpress::MSNumpress::encodeLinear(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodeLinear1()

void encodeLinear1 ( )

Definition at line 44 of file MSNumpressTest.cpp.

44 {
45
46 double mzs[1];
47
48 mzs[0] = 100.0;
49
50 size_t nMzs = 1;
51 unsigned char encoded[12];
52 size_t encodedBytes = ms::numpress::MSNumpress::encodeLinear(&mzs[0], nMzs, &encoded[0], 100000.0);
53
54 assert(12 == encodedBytes);
55 assert(0x80 == encoded[8]);
56 assert(0x96 == encoded[9]);
57 assert(0x98 == encoded[10]);
58 assert(0x00 == encoded[11]);
59
60 cout << "+ pass encodeLinear1 " << endl << endl;
61}

References ms::numpress::MSNumpress::encodeLinear().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 762 of file MSNumpressTest.cpp.

762 {
766 encodeLinear();
783
784 cout << "=== all tests succeeded! ===" << endl;
785 return 0;
786}
void encodeDecodeLinearStraight()
void encodeDecodeSafe()
void decodeLinearNice()
void encodeDecodeSlof()
void encodeDecodeSlof5()
void encodeLinear()
void decodeLinearCorrupt1()
void testErroneousDecodePic()
void optimalLinearFixedPointMass()
void encodeDecodeLinear5()
void encodeDecodePic()
void encodeDecodeLinear()
void optimalSlofFixedPoint()
void decodeLinearWierd()
void encodeDecodePic5()
void decodeLinearCorrupt2()
void encodeLinear1()
void optimalLinearFixedPoint()
void decodeLinearNiceLowFP()
void encodeDecodeSafeStraight()

References decodeLinearCorrupt1(), decodeLinearCorrupt2(), decodeLinearNice(), decodeLinearNiceLowFP(), decodeLinearWierd(), encodeDecodeLinear(), encodeDecodeLinear5(), encodeDecodeLinearStraight(), encodeDecodePic(), encodeDecodePic5(), encodeDecodeSafe(), encodeDecodeSafeStraight(), encodeDecodeSlof(), encodeDecodeSlof5(), encodeLinear(), encodeLinear1(), optimalLinearFixedPoint(), optimalLinearFixedPointMass(), optimalSlofFixedPoint(), and testErroneousDecodePic().

Here is the call graph for this function:

◆ optimalLinearFixedPoint()

void optimalLinearFixedPoint ( )

Definition at line 331 of file MSNumpressTest.cpp.

331 {
332 srand(123459);
333
334 size_t n = 1000;
335 double mzs[1000];
336 mzs[0] = 300 + (rand() % 1000) / 1000.0;
337 for (size_t i=1; i<n; i++)
338 mzs[i] = mzs[i-1] + (rand() % 1000) / 1000.0;
339
340 cout << "+ max val: " << mzs[n-1] << endl;
341 cout << "+ optimal linear fp: " << ms::numpress::MSNumpress::optimalLinearFixedPoint(&mzs[0], n) << endl;
342 cout << "+ pass optimalLinearFixedPoint " << endl << endl;
343}

References ms::numpress::MSNumpress::optimalLinearFixedPoint().

Referenced by main(), and ms::numpress::MSNumpress::optimalLinearFixedPointMass().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ optimalLinearFixedPointMass()

void optimalLinearFixedPointMass ( )

Definition at line 346 of file MSNumpressTest.cpp.

346 {
347 srand(123459);
348
349 size_t n = 1000;
350 double mzs[1000];
351 mzs[0] = 300 + (rand() % 1000) / 1000.0;
352 for (size_t i=1; i<n; i++)
353 mzs[i] = mzs[i-1] + (rand() % 1000) / 1000.0;
354
355 double fixedP;
356
358 assert(abs(5.0 - fixedP) < 0.000005);
359
361 assert(abs(50.0 - fixedP) < 0.000005);
362
364 assert(abs(500.0 - fixedP) < 0.000005);
365
366 cout << "+ optimal linear fp: " << fixedP << endl;
367 cout << "+ pass optimalLinearFixedPointMass " << endl << endl;
368}

References ms::numpress::MSNumpress::optimalLinearFixedPointMass().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ optimalSlofFixedPoint()

void optimalSlofFixedPoint ( )

Definition at line 623 of file MSNumpressTest.cpp.

623 {
624
625 srand(123459);
626
627 size_t n = 1000;
628 double ics[1000];
629 for (size_t i=0; i<n; i++)
630 ics[i] = rand() % 1000000;
631
632 cout << "+ optimal slof fp: " << ms::numpress::MSNumpress::optimalSlofFixedPoint(&ics[0], n) << endl;
633 cout << "+ pass optimalSlofFixedPoint " << endl << endl;
634}

References ms::numpress::MSNumpress::optimalSlofFixedPoint().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testErroneousDecodePic()

void testErroneousDecodePic ( )

Definition at line 736 of file MSNumpressTest.cpp.

736 {
737 std::vector<double> result;
738
739 // set data to [ 100, 102, 140, 92, 33, 80, 145 ]; // Base64 is "ZGaMXCFQkQ=="
740 std::vector<unsigned char> data;
741 data.resize(32);
742 data[0] = 100;
743 data[1] = 102;
744 data[2] = 140;
745 data[3] = 92;
746 data[4] = 33;
747 data[5] = 80;
748 data[6] = 145;
749
750 try {
752 cout << "- fail testErroneousDecodePic: didn't throw exception for corrupt input " << endl << endl;
753 assert(0 == 1);
754 } catch (const char *err) {
755
756 }
757
758 cout << "+ pass testErroneousDecodePic " << endl << endl;
759}

References ms::numpress::MSNumpress::decodePic().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ENC_TWO_BYTE_FIXED_POINT

double ENC_TWO_BYTE_FIXED_POINT = 3000.0

Definition at line 40 of file MSNumpressTest.cpp.