IsoSpecPy 2.4.0__cp315-cp315-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,401 @@
1
+ /*!
2
+ Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
3
+
4
+ This file is part of IsoSpec.
5
+
6
+ IsoSpec is free software: you can redistribute it and/or modify
7
+ it under the terms of the Simplified ("2-clause") BSD licence.
8
+
9
+ IsoSpec is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+
13
+ You should have received a copy of the Simplified BSD Licence
14
+ along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <type_traits>
20
+ #include <cstdlib>
21
+ #include <cstddef>
22
+ #include <utility>
23
+ #include <new>
24
+ #include <algorithm>
25
+ #include "platform.h"
26
+ #include "conf.h"
27
+
28
+
29
+
30
+ template<typename T> class unsafe_pod_vector;
31
+
32
+ template<typename T> class pod_vector
33
+ {
34
+ T* backend_past_end;
35
+ T* first_free;
36
+ T* store;
37
+
38
+ public:
39
+ explicit pod_vector(size_t initial_size = 16)
40
+ {
41
+ #if !ISOSPEC_BUILDING_R
42
+ static_assert(std::is_trivially_copyable<T>::value, "Cannot use a pod_vector with a non-Plain Old Data type.");
43
+ #endif
44
+
45
+ store = reinterpret_cast<T*>(malloc(sizeof(T) * initial_size));
46
+ if(store == NULL)
47
+ throw std::bad_alloc();
48
+ first_free = store;
49
+ backend_past_end = store + initial_size;
50
+ }
51
+
52
+ pod_vector(const pod_vector<T>& other) = delete;
53
+ pod_vector& operator=(const pod_vector<T>& other) = delete;
54
+ pod_vector& operator=(pod_vector<T>&& other)
55
+ {
56
+ free(store);
57
+ backend_past_end = other.backend_past_end;
58
+ first_free = other.first_free;
59
+ store = other.store;
60
+ other.backend_past_end = other.first_free = other.store = NULL;
61
+ return *this;
62
+ }
63
+
64
+ pod_vector(pod_vector<T>&& other)
65
+ {
66
+ backend_past_end = other.backend_past_end;
67
+ first_free = other.first_free;
68
+ store = other.store;
69
+ other.backend_past_end = other.first_free = other.store = NULL;
70
+ }
71
+
72
+ ~pod_vector() { free(store); backend_past_end = first_free = store = NULL; }
73
+
74
+ explicit pod_vector(unsafe_pod_vector<T>&& other)
75
+ {
76
+ backend_past_end = other.backend_past_end;
77
+ first_free = other.first_free;
78
+ store = other.store;
79
+ other.backend_past_end = other.first_free = other.store = NULL;
80
+ }
81
+
82
+ void fast_reserve(size_t n)
83
+ {
84
+ ISOSPEC_IMPOSSIBLE(n < static_cast<size_t>(backend_past_end - store));
85
+ const std::ptrdiff_t store_used_size = first_free - store;
86
+ T* new_store = reinterpret_cast<T*>(realloc(store, n * sizeof(T)));
87
+ if(new_store == NULL)
88
+ throw std::bad_alloc();
89
+ first_free = new_store + store_used_size;
90
+ backend_past_end = new_store + n;
91
+ store = new_store;
92
+ }
93
+
94
+ void reserve(size_t n)
95
+ {
96
+ if (n > static_cast<size_t>(backend_past_end - store))
97
+ fast_reserve(n);
98
+ }
99
+
100
+ void resize(size_t new_size)
101
+ {
102
+ ISOSPEC_IMPOSSIBLE(static_cast<std::ptrdiff_t>(new_size) < first_free - store);
103
+ size_t cap = capacity();
104
+ if(cap < new_size)
105
+ {
106
+ cap = (std::max<size_t>)(4, cap);
107
+ do {
108
+ cap = cap * 2;
109
+ } while(cap < new_size);
110
+ fast_reserve(cap);
111
+ }
112
+ first_free = store + new_size;
113
+ }
114
+
115
+ void resize_and_wipe(size_t new_size)
116
+ {
117
+ size_t old_size = size();
118
+ ISOSPEC_IMPOSSIBLE(new_size <= old_size);
119
+ resize(new_size);
120
+ memset(store+old_size, 0, (new_size-old_size) * sizeof(T));
121
+ }
122
+
123
+ ISOSPEC_FORCE_INLINE void nocheck_push_back(const T& val) noexcept
124
+ {
125
+ ISOSPEC_IMPOSSIBLE(first_free >= backend_past_end);
126
+ *first_free = val;
127
+ first_free++;
128
+ }
129
+
130
+ ISOSPEC_FORCE_INLINE void push_back(const T& val)
131
+ {
132
+ if(first_free >= backend_past_end)
133
+ fast_reserve((std::max<std::ptrdiff_t>)(4, (backend_past_end-store)) * 2);
134
+ *first_free = val;
135
+ first_free++;
136
+ }
137
+
138
+ ISOSPEC_FORCE_INLINE T& operator[](size_t n) noexcept
139
+ {
140
+ ISOSPEC_IMPOSSIBLE(store + n >= first_free);
141
+ return store[n];
142
+ }
143
+
144
+ ISOSPEC_FORCE_INLINE const T& operator[](size_t n) const noexcept
145
+ {
146
+ ISOSPEC_IMPOSSIBLE(store + n >= first_free);
147
+ return store[n];
148
+ }
149
+
150
+ ISOSPEC_FORCE_INLINE size_t size() const noexcept
151
+ {
152
+ return first_free - store;
153
+ }
154
+
155
+ ISOSPEC_FORCE_INLINE size_t capacity() const noexcept
156
+ {
157
+ return backend_past_end - store;
158
+ }
159
+
160
+ ISOSPEC_FORCE_INLINE T* data() noexcept
161
+ {
162
+ return store;
163
+ }
164
+
165
+ ISOSPEC_FORCE_INLINE const T* data() const noexcept
166
+ {
167
+ return store;
168
+ }
169
+
170
+ ISOSPEC_FORCE_INLINE bool empty() const noexcept
171
+ {
172
+ return first_free == store;
173
+ }
174
+
175
+ ISOSPEC_FORCE_INLINE const T& back() const noexcept
176
+ {
177
+ ISOSPEC_IMPOSSIBLE(first_free > backend_past_end);
178
+ return *(first_free-1);
179
+ }
180
+
181
+ ISOSPEC_FORCE_INLINE void pop_back() noexcept
182
+ {
183
+ // Unlike std::vector we do not ever shrink backend storage unless explicitly requested.
184
+ ISOSPEC_IMPOSSIBLE(first_free == store);
185
+ first_free--;
186
+ }
187
+
188
+ void swap(pod_vector<T>& other) noexcept
189
+ {
190
+ std::swap(backend_past_end, other.backend_past_end);
191
+ std::swap(first_free, other.first_free);
192
+ std::swap(store, other.store);
193
+ }
194
+
195
+ typedef T* iterator;
196
+ typedef const T* const_iterator;
197
+ typedef T value_type;
198
+ typedef size_t size_type;
199
+ typedef T& reference;
200
+ typedef const T& const_reference;
201
+
202
+ iterator begin() noexcept { return store; };
203
+ const_iterator begin() const noexcept { return store; }
204
+ const_iterator cbegin() const noexcept { return store; }
205
+ iterator end() noexcept { return first_free; }
206
+ const_iterator end() const noexcept { return first_free; }
207
+ const_iterator cend() const noexcept { return first_free; }
208
+
209
+ ISOSPEC_FORCE_INLINE const T& front() const noexcept
210
+ {
211
+ ISOSPEC_IMPOSSIBLE(store == first_free);
212
+ return *store;
213
+ }
214
+
215
+ void clear()
216
+ {
217
+ free(store);
218
+ first_free = store = backend_past_end = NULL;
219
+ }
220
+
221
+ friend class unsafe_pod_vector<T>;
222
+ };
223
+
224
+
225
+ template<typename T> class unsafe_pod_vector
226
+ {
227
+
228
+ T* backend_past_end;
229
+ T* first_free;
230
+ T* store;
231
+
232
+ public:
233
+ unsafe_pod_vector() = default;
234
+
235
+ void init() {
236
+ #if !ISOSPEC_BUILDING_R
237
+ static_assert(std::is_trivially_copyable<T>::value, "Cannot use a pod_vector with a non-Plain Old Data type.");
238
+ static_assert(std::is_trivially_copyable<unsafe_pod_vector<T> >::value, "Cannot use a pod_vector with a non-Plain Old Data type.");
239
+ #endif
240
+ memset(this, 0, sizeof(*this));
241
+ }
242
+
243
+ void init(size_t initial_size)
244
+ {
245
+ #if !ISOSPEC_BUILDING_R
246
+ static_assert(std::is_trivially_copyable<T>::value, "Cannot use a pod_vector with a non-Plain Old Data type.");
247
+ static_assert(std::is_trivially_copyable<unsafe_pod_vector<T> >::value, "Cannot use a pod_vector with a non-Plain Old Data type.");
248
+ #endif
249
+ store = reinterpret_cast<T*>(malloc(sizeof(T) * initial_size));
250
+ if(store == NULL)
251
+ throw std::bad_alloc();
252
+ first_free = store;
253
+ backend_past_end = store + initial_size;
254
+ }
255
+
256
+ unsafe_pod_vector(const pod_vector<T>& other) = delete; // NOLINT(runtime/explicit) - seriously? Deleted constructors have to be marked explicit?
257
+ unsafe_pod_vector& operator=(const pod_vector<T>& other) = delete;
258
+ //unsafe_pod_vector(unsafe_pod_vector<T>&& other) = default;
259
+
260
+ ~unsafe_pod_vector() = default;
261
+
262
+ void fast_reserve(size_t n)
263
+ {
264
+ ISOSPEC_IMPOSSIBLE(n < static_cast<size_t>(backend_past_end - store));
265
+ T* new_store = reinterpret_cast<T*>(realloc(store, n * sizeof(T)));
266
+ if(new_store == NULL)
267
+ throw std::bad_alloc();
268
+ first_free = new_store + (first_free - store);
269
+ backend_past_end = new_store + n;
270
+ store = new_store;
271
+ }
272
+
273
+ void reserve(size_t n)
274
+ {
275
+ if (n > static_cast<size_t>(backend_past_end - store))
276
+ fast_reserve(n);
277
+ }
278
+
279
+ void resize(size_t new_size)
280
+ {
281
+ ISOSPEC_IMPOSSIBLE(static_cast<std::ptrdiff_t>(new_size) < first_free - store);
282
+ size_t cap = capacity();
283
+ if(cap < new_size)
284
+ {
285
+ cap = (std::max<size_t>)(4, cap);
286
+ do {
287
+ cap = cap * 2;
288
+ } while(cap < new_size);
289
+ fast_reserve(cap);
290
+ }
291
+ first_free = store + new_size;
292
+ }
293
+
294
+ void resize_and_wipe(size_t new_size)
295
+ {
296
+ size_t old_size = size();
297
+ ISOSPEC_IMPOSSIBLE(new_size <= old_size);
298
+ resize(new_size);
299
+ memset(store+old_size, 0, (new_size-old_size) * sizeof(T));
300
+ }
301
+
302
+ ISOSPEC_FORCE_INLINE void nocheck_push_back(const T& val) noexcept
303
+ {
304
+ ISOSPEC_IMPOSSIBLE(first_free >= backend_past_end);
305
+ *first_free = val;
306
+ first_free++;
307
+ }
308
+
309
+ ISOSPEC_FORCE_INLINE void push_back(const T& val)
310
+ {
311
+ if(first_free >= backend_past_end)
312
+ fast_reserve((std::max<std::ptrdiff_t>)(4, (backend_past_end-store)) * 2);
313
+ *first_free = val;
314
+ first_free++;
315
+ }
316
+
317
+ ISOSPEC_FORCE_INLINE T& operator[](size_t n) noexcept
318
+ {
319
+ ISOSPEC_IMPOSSIBLE(store + n >= first_free);
320
+ return store[n];
321
+ }
322
+
323
+ ISOSPEC_FORCE_INLINE const T& operator[](size_t n) const noexcept
324
+ {
325
+ ISOSPEC_IMPOSSIBLE(store + n >= first_free);
326
+ return store[n];
327
+ }
328
+
329
+ ISOSPEC_FORCE_INLINE size_t size() const noexcept
330
+ {
331
+ return first_free - store;
332
+ }
333
+
334
+ ISOSPEC_FORCE_INLINE size_t capacity() const noexcept
335
+ {
336
+ return backend_past_end - store;
337
+ }
338
+
339
+ ISOSPEC_FORCE_INLINE T* data() noexcept
340
+ {
341
+ return store;
342
+ }
343
+
344
+ ISOSPEC_FORCE_INLINE const T* data() const noexcept
345
+ {
346
+ return store;
347
+ }
348
+
349
+ ISOSPEC_FORCE_INLINE bool empty() const noexcept
350
+ {
351
+ return first_free == store;
352
+ }
353
+
354
+ ISOSPEC_FORCE_INLINE const T& back() const noexcept
355
+ {
356
+ ISOSPEC_IMPOSSIBLE(first_free > backend_past_end);
357
+ return *(first_free-1);
358
+ }
359
+
360
+ ISOSPEC_FORCE_INLINE void pop_back() noexcept
361
+ {
362
+ // Unlike std::vector we do not ever shrink backend storage unless explicitly requested.
363
+ ISOSPEC_IMPOSSIBLE(first_free == store);
364
+ first_free--;
365
+ }
366
+
367
+ void swap(unsafe_pod_vector<T>& other) noexcept
368
+ {
369
+ std::swap(backend_past_end, other.backend_past_end);
370
+ std::swap(first_free, other.first_free);
371
+ std::swap(store, other.store);
372
+ }
373
+
374
+ typedef T* iterator;
375
+ typedef const T* const_iterator;
376
+ typedef T value_type;
377
+ typedef size_t size_type;
378
+ typedef T& reference;
379
+ typedef const T& const_reference;
380
+
381
+ iterator begin() noexcept { return store; };
382
+ const_iterator begin() const noexcept { return store; }
383
+ const_iterator cbegin() const noexcept { return store; }
384
+ iterator end() noexcept { return first_free; }
385
+ const_iterator end() const noexcept { return first_free; }
386
+ const_iterator cend() const noexcept { return first_free; }
387
+
388
+ ISOSPEC_FORCE_INLINE const T& front() const noexcept
389
+ {
390
+ ISOSPEC_IMPOSSIBLE(store == first_free);
391
+ return *store;
392
+ }
393
+
394
+ void clear()
395
+ {
396
+ free(store);
397
+ first_free = store = backend_past_end = NULL;
398
+ }
399
+
400
+ friend class pod_vector<T>;
401
+ };
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
3
+ *
4
+ * This file is part of IsoSpec.
5
+ *
6
+ * IsoSpec is free software: you can redistribute it and/or modify
7
+ * it under the terms of the Simplified ("2-clause") BSD licence.
8
+ *
9
+ * IsoSpec is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ *
13
+ * You should have received a copy of the Simplified BSD Licence
14
+ * along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <cmath>
20
+ #include <vector>
21
+ #include <utility>
22
+
23
+ namespace IsoSpec
24
+ {
25
+
26
+ class SSummator
27
+ {
28
+ // Shewchuk algorithm
29
+ std::vector<double> partials;
30
+ int maxpart;
31
+ public:
32
+ inline SSummator()
33
+ { maxpart = 0; }
34
+
35
+ inline SSummator(const SSummator& other) :
36
+ partials(other.partials),
37
+ maxpart(other.maxpart) {}
38
+
39
+ inline void add(double x)
40
+ {
41
+ unsigned int i = 0;
42
+ for(int pidx = 0; pidx < maxpart; pidx++)
43
+ {
44
+ double y = partials[pidx];
45
+ if(std::abs(x) < std::abs(y))
46
+ std::swap(x, y);
47
+ double hi = x+y;
48
+ double lo = y-(hi-x);
49
+ if(lo != 0.0)
50
+ {
51
+ partials[i] = lo;
52
+ i += 1;
53
+ }
54
+ x = hi;
55
+ }
56
+ while(partials.size() <= i)
57
+ partials.push_back(0.0);
58
+ partials[i] = x;
59
+ maxpart = i+1;
60
+ }
61
+ inline double get()
62
+ {
63
+ double ret = 0.0;
64
+ for(int i = 0; i < maxpart; i++)
65
+ ret += partials[i];
66
+ return ret;
67
+ }
68
+ };
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+ class Summator{
77
+ // Kahan algorithm
78
+ double sum;
79
+ double c;
80
+
81
+ public:
82
+ inline Summator()
83
+ { sum = 0.0; c = 0.0;}
84
+
85
+ inline void add(double what)
86
+ {
87
+ double y = what - c;
88
+ double t = sum + y;
89
+ c = (t - sum) - y;
90
+ sum = t;
91
+ }
92
+
93
+ inline double get()
94
+ {
95
+ return sum;
96
+ }
97
+ };
98
+
99
+ class TSummator
100
+ {
101
+ // Trivial algorithm, for testing only
102
+ double sum;
103
+ public:
104
+ inline TSummator()
105
+ { sum = 0.0; }
106
+
107
+ inline void add(double what)
108
+ {
109
+ sum += what;
110
+ }
111
+ inline double get()
112
+ {
113
+ return sum;
114
+ }
115
+ };
116
+
117
+
118
+ } // namespace IsoSpec