Skip to content
Snippets Groups Projects
Commit 70d727f6 authored by sgegito's avatar sgegito
Browse files

git ignore updated

parent ed093534
No related branches found
No related tags found
No related merge requests found
Showing
with 3 additions and 1357 deletions
......@@ -2,8 +2,8 @@
*.o
*.x
*.pgm
*.a
*.b
*.c
*.aa
*.bb
*.cc
*.lines
opti
File deleted
File deleted
from matplotlib import pyplot as plt
from load_vec import load_vector
X = load_vector("../X.vec")
Y = load_vector("../Y.vec")
type_of_data = 'curve'
if type_of_data == 'curve':
plt.plot(X, Y, label="my curve")
else:
plt.scatter(X, Y, marker='x', label="my points")
plt.title("My data")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend(loc="upper right")
plt.show()
import numpy as np
from typing import Tuple
METADATA_SIZE = 6
def _parse_metadata(metadata: bytes) -> Tuple[type, int]:
"""
Parse the metadata for a vec file.
Parameters:
metadata (bytes): The metadata bytes
Returns:
(type, int): The type and the number of component of the vector
"""
little_endian = bool(metadata[0])
endianness = 'little' if little_endian else 'big'
size_of_components = int(metadata[1])
# For now we only consider two types
datatype = np.float64 if size_of_components == 8 else np.float
# Recover our 32 bit integer specifying the endianness
nb_components = int.from_bytes(metadata[2:], endianness)
return datatype, nb_components
def load_vector(filename: str) -> np.ndarray:
"""
Load a vector from a file.
Parameters:
filename (str): The name of the file containing the vector
Returns:
np.ndarray: The vector
"""
file = open(filename, 'rb')
# Read our metadata struct
metadata = file.read(METADATA_SIZE)
datatype, nb_components = _parse_metadata(metadata)
array = np.fromfile(file, dtype=datatype, count=nb_components)
file.close()
return array
0.625312 0.199250
0.297644 0.166352
0.380443 0.204745
0.495471 0.328579
0.489868 0.360706
0.766303 0.199380
0.603302 0.315161
0.782253 0.249109
0.445699 0.140730
0.052343 0.361297
0.385709 0.137151
0.773697 0.143313
0.826224 0.275096
0.894353 0.390373
0.884780 0.161504
0.891529 0.261537
0.571429 0.139631
0.817748 0.405355
0.600421 0.182332
0.718521 0.113532
0.177033 0.219781
0.431436 0.330153
0.196126 0.130294
0.268435 0.276379
0.423757 0.176609
0.568649 0.346265
0.528504 0.188686
0.981378 0.213941
0.902255 0.383917
0.250932 0.323966
0.086669 0.101445
0.297126 0.283142
0.331635 0.103677
0.609969 0.389056
0.428092 0.179383
0.022346 0.252665
0.813314 0.239118
0.385459 0.071044
0.667471 0.299018
0.651265 0.110707
0.974672 0.168690
0.900693 0.259659
0.562260 0.370169
0.857904 0.244776
0.757802 0.121546
0.251549 0.343140
0.251298 0.244530
0.502570 0.267671
0.663549 0.118384
0.514989 0.104487
0.441030 0.249601
0.696767 0.167202
0.991116 0.123561
0.263783 0.281749
0.736120 0.389272
0.749815 0.321826
0.134963 0.273047
0.213967 0.292304
0.532579 0.098718
0.161738 0.154254
0.180708 0.196107
0.134854 0.200207
0.961962 0.307267
0.014938 0.259115
0.749963 0.261544
0.717153 0.147036
0.067262 0.191025
0.445337 0.090150
0.496145 0.309434
0.716965 0.160784
0.624168 0.234627
0.943057 0.346954
0.117288 0.107727
0.456354 0.287827
0.228896 0.266623
0.940248 0.230314
0.031379 0.076412
0.841608 0.420291
0.712526 0.368671
0.618852 0.232948
0.386473 0.179946
0.653482 0.231646
0.749925 0.117840
0.512113 0.155829
0.807938 0.163966
0.478335 0.216265
0.695857 0.222842
0.191237 0.329884
0.578416 0.292763
0.463012 0.340619
0.265683 0.196729
0.216915 0.159054
0.478362 0.091739
0.290402 0.127091
0.915069 0.395690
0.653376 0.180910
0.245260 0.163642
0.755276 0.416878
0.405676 0.157970
0.241255 0.132374
0.496466 0.312939
0.645721 0.144147
0.140982 0.335477
0.005468 0.289969
0.484549 0.228680
0.526710 0.324564
0.871740 0.338458
0.047293 0.168821
0.802147 0.199902
0.540990 0.314225
0.246950 0.126224
0.018757 0.214859
0.501224 0.331309
0.487395 0.374953
0.041423 0.294730
0.120514 0.234833
0.448241 0.326238
0.730213 0.280388
0.603193 0.323282
0.308621 0.093560
0.204161 0.337882
0.837975 0.114309
0.578955 0.372013
0.426004 0.196822
0.222963 0.382647
0.098317 0.211139
0.161359 0.096467
0.962123 0.315661
0.891108 0.241326
0.569483 0.387326
0.178169 0.288226
0.470420 0.280664
0.456233 0.138076
0.215633 0.079783
0.936315 0.268347
0.147169 0.103605
0.359585 0.395071
0.216377 0.372855
0.870411 0.304648
0.319641 0.095951
0.609374 0.217663
0.563288 0.333104
0.535033 0.250012
0.433317 0.212177
0.974930 0.096331
0.358672 0.117680
0.692798 0.358599
0.779509 0.135957
0.029726 0.383015
0.208457 0.381653
0.519396 0.192687
0.106516 0.347877
0.340769 0.173443
0.817520 0.158447
0.965275 0.140667
0.304556 0.255672
0.555119 0.365093
0.345382 0.096078
0.393255 0.327827
0.516293 0.196729
0.781499 0.378028
0.521284 0.232333
0.704058 0.183025
0.623328 0.323589
0.295935 0.340982
0.699824 0.354340
0.187411 0.327438
0.694312 0.258366
0.129234 0.226554
0.739361 0.115910
0.648993 0.094831
0.669157 0.149170
0.911760 0.097297
0.294264 0.165314
0.793238 0.357107
0.673200 0.272900
0.685522 0.146724
0.049035 0.182062
0.495278 0.297141
0.123364 0.319407
0.504148 0.347830
0.606544 0.308731
0.629528 0.179569
0.219740 0.313086
0.812688 0.407529
0.853271 0.243615
0.003018 0.224198
0.665792 0.385901
0.536967 0.394984
0.219794 0.170237
0.770613 0.383530
0.904943 0.244177
0.087479 0.371988
0.845715 0.283621
0.626341 0.402161
0.373970 0.110857
0.792268 0.413714
0.822048 0.228864
0.281371 0.076970
0.180558 0.089691
0.000889 0.061232
0.555739 0.077143
0.556257 0.149709
0.918685 0.123848
0.181587 0.104545
0.423430 0.387068
0.031474 0.160840
0.408335 0.108615
0.282352 0.147770
0.701710 0.385548
0.223130 0.085550
0.039181 0.056875
0.056194 0.339612
0.437194 0.182832
0.903017 0.297960
0.431623 0.371352
0.651581 0.409433
0.907812 0.161546
0.208893 0.335159
0.301063 0.194120
0.964977 0.336431
0.342681 0.398051
0.052867 0.302719
0.115403 0.167038
0.005067 0.322522
0.243911 0.137359
0.892793 0.185930
0.243595 0.377607
0.144322 0.283577
0.286552 0.079062
0.298540 0.303233
0.951245 0.410999
0.705537 0.369182
0.157959 0.362093
0.685555 0.234905
0.304911 0.280983
0.183515 0.274340
0.646983 0.158892
0.398608 0.322639
0.571601 0.211139
0.579499 0.348787
0.631872 0.236823
0.098605 0.346337
0.421279 0.150544
0.556254 0.311808
0.290267 0.348387
0.426005 0.150292
0.804915 0.131313
0.100569 0.375564
0.045972 0.314100
0.421897 0.186558
0.436656 0.272090
0.998474 0.124376
0.841795 0.221547
0.846025 0.227182
0.800757 0.229113
0.228908 0.204803
0.897816 0.200971
0.308096 0.170653
0.570441 0.364644
0.026925 0.338073
0.719145 0.234441
0.102220 0.229370
0.584472 0.144778
0.486935 0.282779
0.988914 0.398994
0.981326 0.237553
0.514244 0.400505
0.509209 0.192350
0.376883 0.185908
0.769434 0.145024
0.780759 0.419120
0.610270 0.304577
0.325856 0.371238
0.997671 0.395224
0.782716 0.094629
0.757005 0.252517
0.477526 0.358601
0.025920 0.071789
0.062015 0.223759
0.692442 0.099195
0.421687 0.294176
0.476499 0.384121
0.653569 0.408974
0.291970 0.073686
0.340943 0.086288
0.208092 0.100190
0.059746 0.325489
0.800278 0.215783
0.736727 0.350268
0.281899 0.236213
0.822545 0.101257
0.021303 0.150932
0.898131 0.107556
0.362070 0.386854
0.560078 0.094214
0.011075 0.377686
0.728280 0.246415
0.917696 0.220010
0.473282 0.141883
0.412300 0.340557
0.271070 0.269358
0.935927 0.203850
0.438754 0.315785
0.716419 0.141831
0.534155 0.407607
0.694925 0.201234
0.037223 0.290393
0.656771 0.392339
0.763451 0.091812
0.895499 0.199535
0.073353 0.355528
0.305295 0.331368
0.394148 0.142633
0.183481 0.347617
0.432657 0.268692
0.681654 0.316291
0.216173 0.265860
0.034543 0.269835
0.353787 0.316740
0.830410 0.384636
0.749280 0.259982
0.244641 0.323495
0.241562 0.361655
0.721856 0.085262
0.920254 0.298632
0.328543 0.396444
0.523930 0.285636
0.795239 0.393040
0.856828 0.416128
0.785507 0.183055
0.574501 0.232437
0.993212 0.359808
0.084743 0.063119
0.445602 0.216879
0.778717 0.178247
0.326472 0.241144
0.801346 0.277670
0.314501 0.078889
0.472526 0.084078
0.047922 0.183077
0.653713 0.205900
0.386387 0.127154
0.010302 0.110937
0.095719 0.343423
0.160346 0.351137
0.156615 0.302170
0.348387 0.116110
0.525521 0.218808
0.177582 0.381907
0.871660 0.409346
0.247135 0.127487
0.484298 0.088668
0.769244 0.352068
0.091389 0.134768
0.835155 0.135314
0.634550 0.242474
0.515776 0.080956
0.666510 0.256368
0.202563 0.313441
0.393208 0.189228
0.643456 0.263207
0.097756 0.385089
0.699650 0.290314
0.424973 0.362151
0.594400 0.176522
0.833532 0.369312
0.494763 0.178940
0.890015 0.179438
0.116628 0.382490
0.505777 0.390771
0.120716 0.102322
0.440651 0.282636
0.161264 0.093158
0.162570 0.178774
0.869391 0.275733
0.726736 0.254767
0.105600 0.329671
0.504689 0.341876
0.447769 0.380691
0.682481 0.095810
0.226294 0.232476
0.883702 0.331494
0.833843 0.346721
0.985065 0.412694
0.755122 0.248757
0.902254 0.383953
0.631170 0.193662
0.512330 0.337961
0.450066 0.295878
0.156262 0.163690
0.230677 0.355009
0.832303 0.200836
0.707490 0.195251
0.141526 0.108270
0.266655 0.337024
0.197427 0.223441
0.340021 0.092820
0.214006 0.117853
0.854847 0.156152
0.124335 0.259038
0.689913 0.090964
0.485807 0.179606
0.369494 0.399865
0.113517 0.328397
0.673038 0.171240
0.139017 0.357638
0.152777 0.380815
0.239991 0.347866
0.308313 0.191470
0.015525 0.242294
0.205525 0.130486
0.067916 0.234931
0.294081 0.157608
0.719410 0.133119
0.480993 0.353602
0.758896 0.142288
0.870335 0.172086
0.491989 0.152810
0.242841 0.263079
0.059389 0.357978
0.875285 0.156884
0.819593 0.097505
0.169727 0.077694
0.888329 0.250704
0.441102 0.371777
0.053008 0.267929
0.116806 0.095672
0.192172 0.195842
0.402847 0.372569
0.559814 0.370644
0.755327 0.191389
0.054746 0.261022
0.563414 0.258444
0.865490 0.359043
0.152242 0.365310
0.722134 0.092780
0.123286 0.236242
0.055590 0.150178
0.601312 0.392607
0.771053 0.100024
0.847772 0.364152
0.689040 0.403586
0.944985 0.387738
0.375464 0.183375
0.792793 0.398660
0.231672 0.243429
0.253988 0.157236
0.173781 0.330489
0.833154 0.101874
0.623657 0.407475
0.964150 0.210158
0.012923 0.079662
0.887519 0.114157
0.380448 0.230607
0.012431 0.100994
0.531246 0.361433
0.975561 0.168856
0.824782 0.395241
0.101498 0.121398
0.268378 0.360532
0.135524 0.222920
0.442411 0.200391
0.786468 0.292002
0.206915 0.266108
0.655463 0.357351
0.605017 0.284678
0.176364 0.264122
0.707049 0.104194
0.686454 0.111105
0.552715 0.308662
0.238998 0.089051
0.559089 0.147517
0.304247 0.192065
0.135105 0.191465
0.584117 0.211659
0.300035 0.303792
0.903532 0.339549
0.109154 0.285006
0.358638 0.172002
0.309621 0.069059
0.146640 0.361635
0.633715 0.187147
0.532580 0.188349
0.386887 0.140975
0.428261 0.383094
0.917919 0.315157
0.023562 0.210016
0.881818 0.200323
0.860879 0.095718
0.733553 0.232468
0.420406 0.080724
0.164637 0.165575
0.776035 0.177382
0.013938 0.095456
0.589860 0.185286
0.148775 0.302355
0.238198 0.321857
0.059504 0.309616
0.123254 0.204461
0.989812 0.279930
0.385993 0.370499
0.218774 0.196639
0.384739 0.101394
0.737364 0.166187
0.117516 0.212369
0.690614 0.261441
0.504506 0.358534
0.861861 0.183636
0.129042 0.347868
0.415214 0.308919
0.199359 0.247211
0.455402 0.217013
0.346479 0.237714
0.208336 0.216211
0.961297 0.160811
0.021248 0.166669
0.105878 0.134861
0.756845 0.248762
0.340615 0.230541
0.736234 0.236972
0.965126 0.237223
0.996053 0.252927
0.282099 0.349046
0.750173 0.221959
0.733714 0.139273
0.130043 0.367005
0.729377 0.279090
0.370631 0.092490
0.100351 0.247585
0.545589 0.095917
0.777114 0.275114
0.408937 0.363323
0.806859 0.142817
0.373609 0.116502
0.659991 0.117319
0.605605 0.286540
0.536692 0.275505
0.094750 0.327265
0.459573 0.352996
0.229931 0.125070
0.010311 0.170387
0.126361 0.302372
0.945419 0.259684
0.815544 0.103218
0.075958 0.173836
0.107417 0.339283
0.927970 0.265325
0.736065 0.329197
0.682137 0.118296
0.882304 0.205119
0.219518 0.222792
0.967246 0.347109
0.089568 0.074758
0.575000 0.259787
0.906920 0.360535
0.742429 0.390294
0.164905 0.347204
0.656919 0.117336
0.365781 0.224467
0.156094 0.204443
0.833597 0.176641
0.294812 0.317524
0.779865 0.096589
0.496397 0.227073
0.140552 0.182705
0.804130 0.207452
0.866610 0.347469
0.116279 0.374065
0.833372 0.319220
0.505319 0.320253
0.496210 0.155646
0.657523 0.300961
0.116537 0.160165
0.771440 0.246677
0.786905 0.395803
0.924057 0.299858
0.191044 0.131783
0.382069 0.391375
0.249746 0.354387
0.432911 0.200210
0.257166 0.140925
0.750368 0.126180
0.008417 0.339189
0.079954 0.334241
0.557926 0.271034
0.582081 0.095115
0.833021 0.168645
0.715252 0.399802
0.554046 0.237992
0.431876 0.183713
0.414224 0.187883
0.961453 0.296525
0.574803 0.191238
0.576177 0.351644
0.221987 0.063300
0.214847 0.219655
0.246130 0.383135
0.602928 0.162891
0.831861 0.316350
0.096336 0.184338
0.268155 0.288564
0.443923 0.104350
0.918022 0.145801
0.050735 0.209637
0.645866 0.240916
0.813019 0.107874
0.838545 0.347192
0.665359 0.218738
0.117993 0.135931
0.237897 0.174339
0.250624 0.212521
0.819132 0.253714
0.417958 0.210100
0.751301 0.168238
0.104943 0.337356
0.639607 0.204120
0.526055 0.102299
0.474275 0.220066
0.242705 0.236241
0.916144 0.388845
0.007622 0.293324
0.948662 0.376228
0.503634 0.278084
0.259516 0.269230
0.855557 0.255633
0.961607 0.130170
0.950157 0.354488
0.602935 0.200748
0.202800 0.177454
0.617935 0.181323
0.201873 0.145179
0.680841 0.324320
0.341071 0.117531
0.172004 0.252531
0.680127 0.111027
0.472347 0.301200
0.817311 0.228380
0.533916 0.181805
0.035030 0.316026
0.942573 0.390750
0.290845 0.364876
0.996767 0.176750
0.684919 0.281768
0.609117 0.374237
0.953938 0.170102
0.195461 0.110970
0.484593 0.364623
0.883739 0.366364
0.031418 0.069961
0.409440 0.306197
0.143892 0.350556
0.399294 0.388943
0.302796 0.375110
0.282149 0.175686
0.726642 0.158721
0.228412 0.066399
0.128902 0.130987
0.258488 0.333247
0.824881 0.377599
0.701539 0.342250
0.094656 0.353330
0.934631 0.286600
0.773303 0.358781
0.404912 0.337045
0.874113 0.362145
0.516266 0.080001
0.696139 0.387578
0.979209 0.428575
0.848770 0.176631
0.336759 0.257429
0.486080 0.260981
0.592897 0.282568
0.790350 0.370581
0.428802 0.274996
0.718989 0.126904
0.394051 0.339513
0.027343 0.160750
0.392893 0.335126
0.147052 0.322710
0.605367 0.085211
0.612157 0.119017
0.039170 0.154507
0.037193 0.057776
0.307229 0.359568
0.279736 0.277628
0.461374 0.326711
0.209160 0.077762
0.380798 0.400849
0.905656 0.362032
0.614741 0.286809
0.939942 0.096696
0.438290 0.392790
0.337474 0.342719
0.767931 0.247249
0.628988 0.203691
0.505690 0.153888
0.494931 0.254624
0.549440 0.252922
0.563239 0.361747
0.418087 0.350411
0.500658 0.366425
0.608792 0.314922
0.933732 0.423339
0.709328 0.362802
0.799190 0.195222
0.464034 0.317940
0.332861 0.366218
0.706418 0.306316
0.733506 0.242251
0.154861 0.177970
0.847646 0.309643
0.603639 0.192268
0.205412 0.110523
0.874702 0.346938
0.009748 0.147965
0.611626 0.248583
0.172250 0.131423
0.220224 0.095516
0.210008 0.369562
0.945371 0.097085
0.253620 0.198215
0.748331 0.280320
0.311729 0.216040
0.256817 0.076974
0.929098 0.230485
0.407729 0.327851
0.072229 0.057073
0.119322 0.148028
0.164446 0.388927
0.046292 0.110138
0.286814 0.282601
0.684600 0.234874
0.878336 0.392499
0.565047 0.105723
0.834375 0.258980
0.097543 0.083797
0.919823 0.374785
0.674477 0.158564
0.300624 0.374370
0.276787 0.139401
0.342971 0.294087
0.006466 0.188616
0.695885 0.124309
0.692842 0.369014
0.119813 0.301882
0.034525 0.187067
0.397051 0.308146
0.865690 0.182097
0.623948 0.222602
0.363732 0.219657
0.941155 0.247580
0.546317 0.362394
0.307150 0.137842
0.092531 0.256822
0.152088 0.180116
0.837495 0.254005
0.053835 0.333746
0.910260 0.342287
0.969749 0.296189
0.610051 0.108229
0.342235 0.280739
0.496188 0.319491
0.363700 0.187508
0.014674 0.379815
0.792615 0.213027
0.445970 0.315310
0.839681 0.419850
0.594750 0.126605
0.213081 0.288948
0.754605 0.206842
0.056599 0.249921
0.860228 0.126857
0.436061 0.327087
0.860153 0.225313
0.373589 0.224078
0.495372 0.311632
0.114779 0.385789
0.455109 0.230639
0.353438 0.222997
0.466127 0.120345
0.848189 0.393517
0.879825 0.320251
0.904384 0.250298
0.834702 0.128011
0.161854 0.253901
0.482634 0.145248
0.181406 0.172665
0.328886 0.271080
0.113350 0.118215
0.023277 0.213313
0.659243 0.253553
0.202762 0.317381
0.510209 0.293007
0.252502 0.349577
0.127655 0.295412
0.009701 0.375648
0.630725 0.375848
0.663715 0.259248
0.364100 0.233039
0.652575 0.255677
0.087723 0.099077
0.744408 0.174352
0.478072 0.096649
0.886595 0.288417
0.262333 0.365443
0.078360 0.360762
0.428521 0.163613
0.695599 0.395276
0.938993 0.409754
0.802378 0.109563
0.666729 0.351712
0.042492 0.151048
0.701605 0.318048
0.832564 0.110657
0.204623 0.221173
0.591660 0.174965
0.620349 0.190878
0.561474 0.108915
0.409361 0.218368
0.689842 0.305995
0.357941 0.322681
0.593271 0.339746
0.049324 0.148505
0.725192 0.413186
0.236970 0.236826
0.054966 0.353712
0.339649 0.098246
0.201154 0.073050
0.803664 0.098647
0.106958 0.057666
0.518857 0.306993
0.300631 0.110341
0.034685 0.338901
0.237625 0.209015
0.310174 0.373540
0.115741 0.278019
0.695669 0.318706
0.454577 0.319453
0.997882 0.156391
0.733311 0.162409
0.707339 0.345673
0.138551 0.072040
0.885734 0.204471
0.088240 0.283830
0.373422 0.132402
0.697684 0.379889
0.893817 0.424385
0.031484 0.360884
0.860421 0.179758
0.372548 0.124160
0.196576 0.221848
0.838710 0.386458
0.197300 0.156881
0.637239 0.144704
0.473056 0.195500
0.430034 0.130108
0.158828 0.246852
0.227381 0.075376
0.908289 0.197496
0.733960 0.178059
0.510821 0.217627
0.173990 0.192910
0.429960 0.138464
0.333139 0.162250
0.474583 0.307284
0.460977 0.295140
0.193976 0.158859
0.563404 0.206624
0.592973 0.144459
0.586459 0.099284
0.571194 0.082060
0.246423 0.304751
0.585077 0.235144
0.774584 0.250506
0.789426 0.256258
0.775078 0.186156
0.940189 0.410133
0.704884 0.206182
0.154542 0.069798
0.660531 0.290438
0.743711 0.125113
0.300284 0.376486
0.421194 0.357460
0.328964 0.069984
0.064332 0.358056
0.080196 0.265497
0.931915 0.202264
0.365547 0.239299
0.800423 0.133967
0.010359 0.247014
0.648675 0.341989
0.890096 0.287728
0.734506 0.282508
0.959013 0.391004
0.633003 0.285960
0.518173 0.199660
0.741051 0.357305
0.314401 0.118663
0.682144 0.296193
0.176411 0.306970
0.558787 0.161519
0.382002 0.231303
0.583226 0.326306
0.007694 0.178156
0.887680 0.097345
0.973498 0.274116
0.803491 0.375264
0.125220 0.235088
0.458574 0.099386
0.427045 0.100363
0.703776 0.397820
0.468292 0.220037
0.763675 0.346440
0.607072 0.226842
0.426058 0.330952
0.192295 0.387167
0.040090 0.243217
0.475548 0.279872
0.321846 0.226010
0.006965 0.120081
0.501296 0.400122
0.745882 0.186307
0.844058 0.379659
0.842784 0.190110
0.955334 0.184426
0.394210 0.288009
0.215048 0.347447
0.103938 0.381004
0.645195 0.317018
0.424542 0.093471
0.494493 0.278596
0.056099 0.230726
0.191134 0.236047
0.157899 0.228274
0.014888 0.105563
0.722506 0.255682
0.145327 0.212823
0.820971 0.418010
0.339490 0.287004
0.292017 0.161812
0.933584 0.322211
0.953935 0.143962
0.548729 0.094805
0.127354 0.120497
0.768882 0.269750
0.265178 0.150077
0.168733 0.164878
0.797958 0.207097
0.852923 0.408324
0.872846 0.379905
0.120721 0.253997
0.383995 0.156511
0.063740 0.121210
0.255433 0.196241
0.868721 0.272926
0.698054 0.349915
0.233678 0.278145
0.950937 0.355080
0.709861 0.109128
0.976331 0.255044
0.630187 0.159817
0.742119 0.350843
0.562786 0.256195
0.158787 0.195892
0.495933 0.083595
0.283520 0.268693
0.626985 0.301670
0.882702 0.321337
0.872482 0.136663
0.093955 0.301365
0.685585 0.345902
0.543507 0.381691
0.443997 0.235443
0.701670 0.133935
0.572736 0.302634
0.632601 0.147068
0.919510 0.217719
0.001844 0.210766
0.914797 0.146136
0.898006 0.228719
0.192264 0.119392
0.027384 0.324275
0.849041 0.392886
0.509974 0.314214
0.048221 0.253474
0.462725 0.316104
0.395939 0.070463
0.653070 0.360360
0.500677 0.191519
0.993794 0.120748
0.032740 0.260240
0.276336 0.380223
0.001116 0.142693
0.434547 0.375491
0.438810 0.181237
0.326642 0.275511
0.514079 0.191906
0.450323 0.191963
0.264113 0.382335
*.vec
.vscode
__pycache__
example
*.o
\ No newline at end of file
#include <stdio.h>
#include <math.h>
#include "vector.h"
/** @brief
* An exemple of mathematical function
* in 1 dimension.
*
* @param x A double variable.
* @return f(x) = 2.0*sin(x) - 3.0*cos(x)
*/
double my_function(double x)
{
return 2.0 * sin(x) - 3.0 * cos(x);
}
int main()
{
// Create a vector X = [0,1,2...99]
double_vector_t *X = iota(100);
// Create a vector Y = my_function(x)
double_vector_t *Y = apply_function(X, my_function);
// Export our vectors into files
export_vector("../X.vec", X);
export_vector("../Y.vec", Y);
// Free our vectors
destroy_vector(&Y);
destroy_vector(&X);
}
\ No newline at end of file
CC=gcc -std=gnu11 -Wall -Wextra -g -fsanitize=leak -fsanitize=undefined
LIBS=-lm
example: vector.o vector.h main.c
$(CC) $^ $(LIBS) -o $@
vector.o: vector.c vector.h
$(CC) -c $< -o $@
clean:
rm -f *.vec *.o example
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "vector.h"
/** @brief
* Compute the endianness used by
* the architecture.
*
* @return 1 if little-endian, 0 if big-endian
*/
uint8_t get_endianness()
{
uint32_t endianness = 0x01020304;
// Return the endianness by accessing the first byte in memory
// which should be 1 if big-endian and 4 if little-endian
return *((uint8_t *)(&endianness)) == 4;
}
/** @brief
* Create a vector of a given dimension.
*
* @param N The number of dimensions.
* @return A dynamically allocated vector
*/
double_vector_t *init_vector(uint32_t N)
{
double_vector_t *vec = malloc(sizeof(double_vector_t));
vec->components = malloc(N * sizeof(double));
vec->N = N;
if (vec == NULL)
{
perror("Can't allocate memory");
exit(EXIT_FAILURE);
}
return vec;
}
/** @brief
* Create a vector of a given dimension,
* with values from 0 to N excluded.
*
* @param N The number of dimensions.
* @return A dynamically allocated vector : [0,1..N-1]
*/
double_vector_t *iota(uint32_t N)
{
double_vector_t *vec = init_vector(N);
for (uint32_t i = 0; i < N; i++)
{
vec->components[i] = i;
}
return vec;
}
/** @brief
* Apply a 1d function element-wise
* to a given vector, and return the
* result in a new vector.
*
* @param vec The argument vector
* @param f The 1d function to apply
* @return A dynamically allocated vector : f(X)
*/
double_vector_t *apply_function(double_vector_t *vec, double_function_t f)
{
double_vector_t *res = init_vector(vec->N);
for (uint32_t i = 0; i < vec->N; i++)
{
res->components[i] = f(vec->components[i]);
}
return res;
}
/** @brief
* Export a vector into a file.
*
* @param filename The name of the output file
* @param vec The vector to export
*/
void export_vector(const char *filename, double_vector_t *vec)
{
FILE *output = fopen(filename, "w");
vector_metadata_t metadata;
metadata.endianness = get_endianness();
metadata.size_of_a_component = sizeof(double);
metadata.number_of_component = vec->N;
fwrite(&metadata, sizeof(vector_metadata_t), 1, output);
fwrite(vec->components,
metadata.size_of_a_component,
metadata.number_of_component,
output);
fclose(output);
}
/** @brief
* Free a vector.
*
* @param vec A double pointer on a vector
*/
void destroy_vector(double_vector_t **vec)
{
free((*vec)->components);
free(*vec);
*vec = NULL;
}
\ No newline at end of file
#include <stdint.h>
typedef struct double_vector
{
uint32_t N; // The dimmension of the vector
double *components;
} double_vector_t;
// Function pointer, example : double f(double x);
typedef double (*double_function_t)(double);
/*
* The attribute "packed" tells the compiler,
* that the struct should be stored in memory
* without padding. It's highly recommended,
* if we want to serialize the structure.
* (for example to store it in a file)
*/
typedef struct vector_metadata
{
uint8_t endianness; // 1 = little, 0 = big
uint8_t size_of_a_component; // in bytes
uint32_t number_of_component;
} __attribute__((packed)) vector_metadata_t;
/** @brief
* Create a vector of a given dimension.
*
* @param N The number of dimensions.
* @return A dynamically allocated vector
*/
double_vector_t *init_vector(uint32_t N);
/** @brief
* Create a vector of a given dimension,
* with values from 0 to N excluded.
*
* @param N The number of dimensions.
* @return A dynamically allocated vector : [0,1..N-1]
*/
double_vector_t *iota(uint32_t N);
/** @brief
* Apply a 1d function element-wise
* to a given vector, and return the
* result in a new vector.
*
* @param vec The argument vector
* @param f The 1d function to apply
* @return A dynamically allocated vector : f(X)
*/
double_vector_t *apply_function(double_vector_t *vec, double_function_t f);
/** @brief
* Export a vector into a file.
*
* @param filename The name of the output file
* @param vec The vector to export
*/
void export_vector(const char *filename, double_vector_t *vec);
/** @brief
* Free a vector.
*
* @param vec A double pointer on a vector
*/
void destroy_vector(double_vector_t **vec);
\ No newline at end of file
from matplotlib import pyplot as plt
from load_vec import load_vector
X = load_vector("../X.vec")
Y = load_vector("../Y.vec")
type_of_data = 'curve'
if type_of_data == 'curve':
plt.plot(X, Y, label="my curve")
else:
plt.scatter(X, Y, marker='x', label="my points")
plt.title("My data")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend(loc="upper right")
plt.show()
import numpy as np
from typing import Tuple
METADATA_SIZE = 6
def _parse_metadata(metadata: bytes) -> Tuple[type, int]:
"""
Parse the metadata for a vec file.
Parameters:
metadata (bytes): The metadata bytes
Returns:
(type, int): The type and the number of component of the vector
"""
little_endian = bool(metadata[0])
endianness = 'little' if little_endian else 'big'
size_of_components = int(metadata[1])
# For now we only consider two types
datatype = np.float64 if size_of_components == 8 else np.float
# Recover our 32 bit integer specifying the endianness
nb_components = int.from_bytes(metadata[2:], endianness)
return datatype, nb_components
def load_vector(filename: str) -> np.ndarray:
"""
Load a vector from a file.
Parameters:
filename (str): The name of the file containing the vector
Returns:
np.ndarray: The vector
"""
file = open(filename, 'rb')
# Read our metadata struct
metadata = file.read(METADATA_SIZE)
datatype, nb_components = _parse_metadata(metadata)
array = np.fromfile(file, dtype=datatype, count=nb_components)
file.close()
return array
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment