IsoSpecPy 2.3.0.dev11__cp313-cp313-win_arm64.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,204 @@
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 <iostream>
20
+ #include <vector>
21
+ #include <cstring>
22
+ #include <algorithm>
23
+ #include "isoMath.h"
24
+ #include "pod_vector.h"
25
+
26
+ namespace IsoSpec
27
+ {
28
+
29
+ inline double combinedSum(
30
+ const int* conf, const std::vector<double>** valuesContainer, int dimNumber
31
+ ){
32
+ double res = 0.0;
33
+ for(int i = 0; i < dimNumber; i++)
34
+ res += (*(valuesContainer[i]))[conf[i]];
35
+ return res;
36
+ }
37
+
38
+ inline double combinedSum(
39
+ const int* conf, const pod_vector<double>** valuesContainer, int dimNumber
40
+ ){
41
+ double res = 0.0;
42
+ for(int i = 0; i < dimNumber; i++)
43
+ res += (*(valuesContainer[i]))[conf[i]];
44
+ return res;
45
+ }
46
+
47
+ inline int* getConf(void* conf)
48
+ {
49
+ return reinterpret_cast<int*>(
50
+ reinterpret_cast<char*>(conf) + sizeof(double)
51
+ );
52
+ }
53
+
54
+ inline double getLProb(void* conf)
55
+ {
56
+ double ret = *reinterpret_cast<double*>(conf);
57
+ return ret;
58
+ }
59
+
60
+
61
+ inline double unnormalized_logProb(const int* conf, const double* logProbs, int dim)
62
+ {
63
+ double res = 0.0;
64
+
65
+ for(int i = 0; i < dim; i++)
66
+ res += minuslogFactorial(conf[i]) + conf[i] * logProbs[i];
67
+
68
+ return res;
69
+ }
70
+
71
+ inline double calc_mass(const int* conf, const double* masses, int dim)
72
+ {
73
+ double res = 0.0;
74
+
75
+ for(int i = 0; i < dim; i++)
76
+ {
77
+ res += conf[i] * masses[i];
78
+ }
79
+
80
+ return res;
81
+ }
82
+
83
+
84
+
85
+ template<typename T> void printArray(const T* array, size_t size, const char* prefix = "")
86
+ {
87
+ if (strlen(prefix) > 0)
88
+ std::cout << prefix << " ";
89
+ for (size_t i = 0; i < size; i++)
90
+ std::cout << array[i] << " ";
91
+ std::cout << std::endl;
92
+ }
93
+
94
+ template<typename T> void printVector(const std::vector<T>& vec)
95
+ {
96
+ printArray<T>(vec.data(), vec.size());
97
+ }
98
+
99
+ template<typename T> void printVector(const pod_vector<T>& vec)
100
+ {
101
+ printArray<T>(vec.data(), vec.size());
102
+ }
103
+
104
+ template<typename T> void printOffsets(const T** array, size_t size, const T* offset, const char* prefix = "")
105
+ {
106
+ if (strlen(prefix) > 0)
107
+ std::cout << prefix << " ";
108
+ for (size_t i = 0; i < size; i++)
109
+ std::cout << array[i] - offset << " ";
110
+ std::cout << std::endl;
111
+ }
112
+
113
+ template<typename T> void printNestedArray(const T** array, const int* shape, size_t size)
114
+ {
115
+ for (size_t i = 0; i < size; i++)
116
+ printArray(array[i], shape[i]);
117
+ std::cout << std::endl;
118
+ }
119
+
120
+ //! Quickly select the n'th positional statistic, including the weights.
121
+ void* quickselect(const void** array, size_t n, size_t start, size_t end);
122
+
123
+
124
+ template <typename T> inline static T* array_copy(const T* A, size_t size)
125
+ {
126
+ T* ret = new T[size];
127
+ memcpy(ret, A, size*sizeof(T));
128
+ return ret;
129
+ }
130
+
131
+ template <typename T> static T* array_copy_nptr(const T* A, size_t size)
132
+ {
133
+ if(A == nullptr)
134
+ return nullptr;
135
+ return array_copy(A, size);
136
+ }
137
+
138
+ template<typename T> void dealloc_table(T* tbl, int dim)
139
+ {
140
+ for(int i = 0; i < dim; i++)
141
+ {
142
+ delete tbl[i];
143
+ }
144
+ delete[] tbl;
145
+ }
146
+
147
+ template<typename T> void realloc_append(T** array, T what, size_t old_array_size)
148
+ {
149
+ T* newT = new T[old_array_size+1];
150
+ memcpy(newT, *array, old_array_size*sizeof(T));
151
+ newT[old_array_size] = what;
152
+ delete[] *array;
153
+ *array = newT;
154
+ }
155
+
156
+ template<typename T> size_t* get_order(T* order_array, size_t N)
157
+ {
158
+ size_t* arr = new size_t[N];
159
+ for(size_t ii = 0; ii < N; ii++)
160
+ arr[ii] = ii;
161
+
162
+ std::sort(arr, arr + N, [&](size_t i, size_t j) { return order_array[i] < order_array[j]; });
163
+
164
+ return arr;
165
+ }
166
+
167
+ template<typename T> size_t* get_inverse_order(T* order_array, size_t N)
168
+ {
169
+ size_t* arr = new size_t[N];
170
+ for(size_t ii = 0; ii < N; ii++)
171
+ arr[ii] = ii;
172
+
173
+ std::sort(arr, arr + N, [&](size_t i, size_t j) { return order_array[i] > order_array[j]; });
174
+
175
+ return arr;
176
+ }
177
+
178
+ template<typename TA, typename TB> void impose_order(size_t* O, size_t N, TA* A, TB* B)
179
+ {
180
+ for(size_t ii = 0; ii < N; ii++)
181
+ {
182
+ if(ii != O[ii])
183
+ {
184
+ size_t curr_ii = ii;
185
+ TA ta = A[ii];
186
+ TB tb = B[ii];
187
+ size_t next_ii = O[ii];
188
+ while(next_ii != ii)
189
+ {
190
+ A[curr_ii] = A[next_ii];
191
+ B[curr_ii] = B[next_ii];
192
+ O[curr_ii] = curr_ii;
193
+ curr_ii = next_ii;
194
+ next_ii = O[next_ii];
195
+ }
196
+ A[curr_ii] = ta;
197
+ B[curr_ii] = tb;
198
+ O[curr_ii] = curr_ii;
199
+ }
200
+ }
201
+ }
202
+
203
+
204
+ } // namespace IsoSpec
@@ -0,0 +1,67 @@
1
+ /*
2
+ * NOLINT(legal/copyright) - the original authors did not slap a (C) notice in here,
3
+ * for whatever reason, and I'm in no position to do that for them.
4
+ *
5
+ * sys/mman.h
6
+ * mman-win32
7
+ *
8
+ * This file has been included as a part of IsoSpec project, under a MIT licence. It
9
+ * comes from the repository:
10
+ *
11
+ * https://github.com/witwall/mman-win32
12
+ *
13
+ * which itself is a mirror of:
14
+ *
15
+ * https://code.google.com/archive/p/mman-win32/
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
21
+ #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
22
+ #endif
23
+
24
+ /* All the headers include this file. */
25
+ #ifndef _MSC_VER
26
+ #include <_mingw.h>
27
+ #endif
28
+
29
+ /* Determine offset type */
30
+ #include <stdint.h>
31
+ #if defined(_WIN64)
32
+ typedef int64_t OffsetType;
33
+ #else
34
+ typedef uint32_t OffsetType;
35
+ #endif
36
+
37
+ #include <sys/types.h>
38
+
39
+
40
+ #define PROT_NONE 0
41
+ #define PROT_READ 1
42
+ #define PROT_WRITE 2
43
+ #define PROT_EXEC 4
44
+
45
+ #define MAP_FILE 0
46
+ #define MAP_SHARED 1
47
+ #define MAP_PRIVATE 2
48
+ #define MAP_TYPE 0xf
49
+ #define MAP_FIXED 0x10
50
+ #define MAP_ANONYMOUS 0x20
51
+ #define MAP_ANON MAP_ANONYMOUS
52
+
53
+ #define MAP_FAILED ((void *)-1)
54
+
55
+ /* Flags for msync. */
56
+ #define MS_ASYNC 1
57
+ #define MS_SYNC 2
58
+ #define MS_INVALIDATE 4
59
+
60
+ void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType off);
61
+ int munmap(void *addr, size_t len);
62
+ int _mprotect(void *addr, size_t len, int prot);
63
+ int msync(void *addr, size_t len, int flags);
64
+ int mlock(const void *addr, size_t len);
65
+ int munlock(const void *addr, size_t len);
66
+
67
+
@@ -0,0 +1,150 @@
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 <string.h>
20
+ #include "platform.h"
21
+ #include "conf.h"
22
+ #include "isoMath.h"
23
+ #include "misc.h"
24
+
25
+ namespace IsoSpec
26
+ {
27
+
28
+ class KeyHasher
29
+ {
30
+ private:
31
+ int dim;
32
+
33
+ public:
34
+ explicit KeyHasher(int dim);
35
+
36
+ inline std::size_t operator()(const int* conf) const noexcept
37
+ {
38
+ std::size_t seed = conf[0];
39
+ for(int i = 1; i < dim; ++i )
40
+ {
41
+ constexpr_if(sizeof(std::size_t) == 8)
42
+ seed = seed << 6;
43
+ else // Assuming 32 bit arch. If not, well, there will be
44
+ // more hash collisions but it still should run OK
45
+ seed = seed << 3;
46
+ seed ^= conf[i];
47
+ }
48
+ return seed;
49
+ };
50
+ };
51
+
52
+
53
+ class ConfEqual
54
+ {
55
+ private:
56
+ int size;
57
+
58
+ public:
59
+ explicit ConfEqual(int dim);
60
+
61
+ inline bool operator()(const int* conf1, const int* conf2) const
62
+ {
63
+ // The memcmp() function returns zero if the two strings are identical, oth-
64
+ // erwise returns the difference between the first two differing bytes
65
+ // (treated as unsigned char values, so that `\200' is greater than `\0',
66
+ // for example). Zero-length strings are always identical. This behavior
67
+ // is not required by C and portable code should only depend on the sign of
68
+ // the returned value.
69
+ // sacred man of memcmp.
70
+ return memcmp(conf1, conf2, size) == 0;
71
+ }
72
+ };
73
+
74
+
75
+ class ConfOrder
76
+ {
77
+ // configurations comparator
78
+ public:
79
+ inline bool operator()(void* conf1, void* conf2) const
80
+ {
81
+ return *reinterpret_cast<double*>(conf1) < *reinterpret_cast<double*>(conf2);
82
+ };
83
+ };
84
+
85
+
86
+
87
+ class ConfOrderMarginal
88
+ {
89
+ // configurations comparator
90
+ const double* logProbs;
91
+ int dim;
92
+ public:
93
+ ConfOrderMarginal(const double* logProbs, int dim);
94
+
95
+ inline bool operator()(const Conf conf1, const Conf conf2)
96
+ {
97
+ // Return true if conf1 is less probable than conf2.
98
+ return unnormalized_logProb(conf1, logProbs, dim) < unnormalized_logProb(conf2, logProbs, dim);
99
+ };
100
+ };
101
+
102
+ class ConfOrderMarginalDescending
103
+ {
104
+ // configurations comparator
105
+ const double* logProbs;
106
+ int dim;
107
+ public:
108
+ ConfOrderMarginalDescending(const double* logProbs, int dim);
109
+
110
+ inline bool operator()(const Conf conf1, const Conf conf2)
111
+ {
112
+ // Return true if conf1 is less probable than conf2.
113
+ return unnormalized_logProb(conf1, logProbs, dim) > unnormalized_logProb(conf2, logProbs, dim);
114
+ };
115
+ };
116
+
117
+ template<typename T> class ReverseOrder
118
+ {
119
+ public:
120
+ inline ReverseOrder() {}
121
+ inline bool operator()(const T a, const T b) const { return a > b; }
122
+ };
123
+
124
+ template<typename T> class TableOrder
125
+ {
126
+ const T* tbl;
127
+ public:
128
+ inline explicit TableOrder(const T* _tbl) : tbl(_tbl) {}
129
+ inline bool operator()(size_t i, size_t j) { return tbl[i] < tbl[j]; }
130
+ };
131
+
132
+ } // namespace IsoSpec
133
+
134
+ #include "marginalTrek++.h"
135
+
136
+ class PrecalculatedMarginal; // In case marginalTrek++.h us including us, and can't be included again...
137
+
138
+ namespace IsoSpec
139
+ {
140
+
141
+ template<typename T> class OrderMarginalsBySizeDecresing
142
+ {
143
+ T const* const* const MT;
144
+ public:
145
+ explicit OrderMarginalsBySizeDecresing(T const* const * const MT_) : MT(MT_) {};
146
+ inline bool operator()(size_t m1, size_t m2) { return MT[m1]->get_no_confs() > MT[m2]->get_no_confs(); }
147
+ };
148
+
149
+
150
+ } // namespace IsoSpec
@@ -0,0 +1,111 @@
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 "platform_incl.h"
20
+
21
+ #if defined(__unix__) || defined(__unix) || \
22
+ (defined(__APPLE__) && defined(__MACH__))
23
+ #define ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY true
24
+ #define ISOSPEC_TEST_WE_ARE_ON_WINDOWS false /* CYGWIN doesn't really count as Windows for our purposes, we'll be using UNIX API anyway */
25
+ #define ISOSPEC_TEST_GOT_SYSTEM_MMAN true
26
+ #define ISOSPEC_TEST_GOT_MMAN true
27
+ #elif defined(__MINGW32__) || defined(_WIN32)
28
+ #define ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY false
29
+ #define ISOSPEC_TEST_WE_ARE_ON_WINDOWS true
30
+ #define ISOSPEC_TEST_GOT_SYSTEM_MMAN false
31
+ #define ISOSPEC_TEST_GOT_MMAN true
32
+ #else
33
+ #define ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY false /* Well, probably... */
34
+ #define ISOSPEC_TEST_WE_ARE_ON_WINDOWS false
35
+ #define ISOSPEC_TEST_GOT_SYSTEM_MMAN false
36
+ #define ISOSPEC_TEST_GOT_MMAN false
37
+ #endif
38
+
39
+ #if !defined(ISOSPEC_WE_ARE_ON_UNIX_YAY)
40
+ #define ISOSPEC_WE_ARE_ON_UNIX_YAY ISOSPEC_TEST_WE_ARE_ON_UNIX_YAY
41
+ #endif
42
+
43
+ #if !defined(ISOSPEC_WE_ARE_ON_WINDOWS)
44
+ #define ISOSPEC_WE_ARE_ON_WINDOWS ISOSPEC_TEST_WE_ARE_ON_WINDOWS
45
+ #endif
46
+
47
+ #if !defined(ISOSPEC_GOT_SYSTEM_MMAN)
48
+ #define ISOSPEC_GOT_SYSTEM_MMAN ISOSPEC_TEST_GOT_SYSTEM_MMAN
49
+ #endif
50
+
51
+ #if !defined(ISOSPEC_GOT_MMAN)
52
+ #define ISOSPEC_GOT_MMAN ISOSPEC_TEST_GOT_MMAN
53
+ #endif
54
+
55
+
56
+ // Note: __GNUC__ is defined by clang and gcc
57
+ #ifdef __GNUC__
58
+ #define ISOSPEC_IMPOSSIBLE(condition) if(condition) __builtin_unreachable();
59
+ #define ISOSPEC_LIKELY(condition) __builtin_expect(static_cast<bool>(condition), 1)
60
+ #define ISOSPEC_UNLIKELY(condition) __builtin_expect(static_cast<bool>(condition), 0)
61
+ // For aggressive inlining
62
+ #define ISOSPEC_FORCE_INLINE __attribute__ ((always_inline)) inline
63
+ #elif defined _MSC_VER
64
+ #define ISOSPEC_IMPOSSIBLE(condition) __assume(!(condition));
65
+ #define ISOSPEC_LIKELY(condition) condition
66
+ #define ISOSPEC_UNLIKELY(condition) condition
67
+ #define ISOSPEC_FORCE_INLINE __forceinline
68
+ #else
69
+ #define ISOSPEC_IMPOSSIBLE(condition)
70
+ #define ISOSPEC_LIKELY(condition) condition
71
+ #define ISOSPEC_UNLIKELY(condition) condition
72
+ #define ISOSPEC_FORCE_INLINE inline
73
+ #endif
74
+
75
+ #ifdef ISOSPEC_DEBUG
76
+ #undef ISOSPEC_IMPOSSIBLE
77
+ #include <cassert>
78
+ #define ISOSPEC_IMPOSSIBLE(condition) assert(!(condition));
79
+ #endif /* ISOSPEC_DEBUG */
80
+
81
+
82
+ #if ISOSPEC_GOT_MMAN
83
+ #if ISOSPEC_GOT_SYSTEM_MMAN
84
+ #include <sys/mman.h>
85
+ #else
86
+ #include "mman.h"
87
+ #endif
88
+ #else
89
+ #include <stdlib.h> /* malloc, free, rand */
90
+ #endif
91
+
92
+
93
+ #if defined(OPENMS_DLLAPI) /* IsoSpec is being built as a part of OpenMS: use their visibility macros */
94
+ #define ISOSPEC_EXPORT_SYMBOL OPENMS_DLLAPI
95
+ #else /* it's a can of worms we don't yet want to open ourselves though... */
96
+ #define ISOSPEC_EXPORT_SYMBOL
97
+ #endif
98
+
99
+ #if defined(_WIN32) || defined(_WIN64)
100
+ #define ISOSPEC_C_API __declspec(dllexport)
101
+ #else
102
+ #define ISOSPEC_C_API
103
+ #endif
104
+
105
+ #if !defined(__cpp_if_constexpr)
106
+ #define constexpr_if if
107
+ #define ISOSPEC_MAYBE_UNUSED
108
+ #else
109
+ #define constexpr_if if constexpr
110
+ #define ISOSPEC_MAYBE_UNUSED [[maybe_unused]]
111
+ #endif
@@ -0,0 +1,33 @@
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
+ #if !defined(ISOSPEC_BUILDING_R)
20
+ #define ISOSPEC_BUILDING_R false
21
+ #endif
22
+
23
+ #if !defined(ISOSPEC_BUILDING_CPP)
24
+ #define ISOSPEC_BUILDING_CPP true
25
+ #endif
26
+
27
+ #if !defined(ISOSPEC_BUILDING_PYTHON)
28
+ #define ISOSPEC_BUILDING_PYTHON false
29
+ #endif
30
+
31
+ #if !defined(ISOSPEC_BUILDING_OPENMS)
32
+ #define ISOSPEC_BUILDING_OPENMS false
33
+ #endif