IsoSpecPy 2.5.0__py3-none-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.
- IsoSpecPy/Advanced.py +32 -0
- IsoSpecPy/Distributions.py +93 -0
- IsoSpecPy/Formulas.py +71 -0
- IsoSpecPy/IsoSpec++/aligned_ptr.h +638 -0
- IsoSpecPy/IsoSpec++/allocator.h +69 -0
- IsoSpecPy/IsoSpec++/btrd.h +206 -0
- IsoSpecPy/IsoSpec++/composition.h +126 -0
- IsoSpecPy/IsoSpec++/conf.h +38 -0
- IsoSpecPy/IsoSpec++/cwrapper.h +271 -0
- IsoSpecPy/IsoSpec++/dirtyAllocator.h +58 -0
- IsoSpecPy/IsoSpec++/element_lookup.h +36 -0
- IsoSpecPy/IsoSpec++/element_tables.h +50 -0
- IsoSpecPy/IsoSpec++/fasta.h +70 -0
- IsoSpecPy/IsoSpec++/fasta_mods.h +70 -0
- IsoSpecPy/IsoSpec++/fixedEnvelopes.h +418 -0
- IsoSpecPy/IsoSpec++/isa_kernel_impl.h +192 -0
- IsoSpecPy/IsoSpec++/isa_kernels.h +172 -0
- IsoSpecPy/IsoSpec++/isoMath.h +121 -0
- IsoSpecPy/IsoSpec++/isoSpec++.h +801 -0
- IsoSpecPy/IsoSpec++/iso_simd.h +48 -0
- IsoSpecPy/IsoSpec++/marginalTrek++.h +614 -0
- IsoSpecPy/IsoSpec++/misc.h +229 -0
- IsoSpecPy/IsoSpec++/mman.h +67 -0
- IsoSpecPy/IsoSpec++/operators.h +150 -0
- IsoSpecPy/IsoSpec++/platform.h +180 -0
- IsoSpecPy/IsoSpec++/platform_incl.h +33 -0
- IsoSpecPy/IsoSpec++/pod_vector.h +400 -0
- IsoSpecPy/IsoSpec++/summator.h +118 -0
- IsoSpecPy/IsoSpec++/unimod.h +80 -0
- IsoSpecPy/IsoSpec++/unimod_support.h +2169 -0
- IsoSpecPy/IsoSpec++/unimod_table_data.h +1027 -0
- IsoSpecPy/IsoSpecPy.py +1088 -0
- IsoSpecPy/IsoSpecPyOld.py +290 -0
- IsoSpecPy/PeriodicTbl.py +51 -0
- IsoSpecPy/__init__.py +19 -0
- IsoSpecPy/__main__.py +25 -0
- IsoSpecPy/approximations.py +122 -0
- IsoSpecPy/confs_passthrough.py +16 -0
- IsoSpecPy/isoFFI.py +290 -0
- bin/IsoSpecCppPy.dll +0 -0
- isospecpy-2.5.0.dist-info/METADATA +220 -0
- isospecpy-2.5.0.dist-info/RECORD +45 -0
- isospecpy-2.5.0.dist-info/WHEEL +5 -0
- isospecpy-2.5.0.dist-info/licenses/LICENCE +35 -0
- lib/IsoSpecCppPy.lib +0 -0
|
@@ -0,0 +1,229 @@
|
|
|
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(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() is declared with __attribute__((nonnull)), so a zero-length copy
|
|
128
|
+
// from a null source is undefined behaviour even though it moves no bytes.
|
|
129
|
+
// A zero-dimensional Iso (e.g. setupIso(0, NULL, ...)) reaches exactly that.
|
|
130
|
+
if(size > 0)
|
|
131
|
+
memcpy(ret, A, size*sizeof(T));
|
|
132
|
+
return ret;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
template <typename T> inline static T* array_copy_malloc(const T* A, size_t size)
|
|
136
|
+
{
|
|
137
|
+
T* ret = reinterpret_cast<T*>(malloc(size * sizeof(T)));
|
|
138
|
+
if(ret == nullptr)
|
|
139
|
+
throw std::bad_alloc();
|
|
140
|
+
memcpy(ret, A, size*sizeof(T));
|
|
141
|
+
return ret;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
template <typename T> static T* array_copy_nptr(const T* A, size_t size)
|
|
146
|
+
{
|
|
147
|
+
if(A == nullptr)
|
|
148
|
+
return nullptr;
|
|
149
|
+
return array_copy(A, size);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
template <typename T> static T* array_copy_nptr_malloc(const T* A, size_t size)
|
|
153
|
+
{
|
|
154
|
+
if(A == nullptr)
|
|
155
|
+
return nullptr;
|
|
156
|
+
return array_copy_malloc(A, size);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
template<typename T> void dealloc_table(T* tbl, int dim)
|
|
161
|
+
{
|
|
162
|
+
for(int i = 0; i < dim; i++)
|
|
163
|
+
{
|
|
164
|
+
delete tbl[i];
|
|
165
|
+
}
|
|
166
|
+
delete[] tbl;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
template<typename T> void realloc_append(T** array, T what, size_t old_array_size)
|
|
170
|
+
{
|
|
171
|
+
T* newT = new T[old_array_size+1];
|
|
172
|
+
// *array may be nullptr when old_array_size == 0 (a default-constructed
|
|
173
|
+
// Iso), and memcpy from a null pointer is undefined even for zero bytes.
|
|
174
|
+
if(old_array_size > 0)
|
|
175
|
+
memcpy(newT, *array, old_array_size*sizeof(T));
|
|
176
|
+
newT[old_array_size] = what;
|
|
177
|
+
delete[] *array;
|
|
178
|
+
*array = newT;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
template<typename T> size_t* get_order(T* order_array, size_t N)
|
|
182
|
+
{
|
|
183
|
+
size_t* arr = new size_t[N];
|
|
184
|
+
for(size_t ii = 0; ii < N; ii++)
|
|
185
|
+
arr[ii] = ii;
|
|
186
|
+
|
|
187
|
+
std::sort(arr, arr + N, [&](size_t i, size_t j) { return order_array[i] < order_array[j]; });
|
|
188
|
+
|
|
189
|
+
return arr;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
template<typename T> size_t* get_inverse_order(T* order_array, size_t N)
|
|
193
|
+
{
|
|
194
|
+
size_t* arr = new size_t[N];
|
|
195
|
+
for(size_t ii = 0; ii < N; ii++)
|
|
196
|
+
arr[ii] = ii;
|
|
197
|
+
|
|
198
|
+
std::sort(arr, arr + N, [&](size_t i, size_t j) { return order_array[i] > order_array[j]; });
|
|
199
|
+
|
|
200
|
+
return arr;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
template<typename TA, typename TB> void impose_order(size_t* O, size_t N, TA* A, TB* B)
|
|
204
|
+
{
|
|
205
|
+
for(size_t ii = 0; ii < N; ii++)
|
|
206
|
+
{
|
|
207
|
+
if(ii != O[ii])
|
|
208
|
+
{
|
|
209
|
+
size_t curr_ii = ii;
|
|
210
|
+
TA ta = A[ii];
|
|
211
|
+
TB tb = B[ii];
|
|
212
|
+
size_t next_ii = O[ii];
|
|
213
|
+
while(next_ii != ii)
|
|
214
|
+
{
|
|
215
|
+
A[curr_ii] = A[next_ii];
|
|
216
|
+
B[curr_ii] = B[next_ii];
|
|
217
|
+
O[curr_ii] = curr_ii;
|
|
218
|
+
curr_ii = next_ii;
|
|
219
|
+
next_ii = O[next_ii];
|
|
220
|
+
}
|
|
221
|
+
A[curr_ii] = ta;
|
|
222
|
+
B[curr_ii] = tb;
|
|
223
|
+
O[curr_ii] = curr_ii;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
} // 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,180 @@
|
|
|
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)) && !defined(MXE)
|
|
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
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/* Is this an x86 target, i.e. one where several instruction-set levels exist to
|
|
115
|
+
choose between at run time? Everywhere else there is nothing to dispatch on:
|
|
116
|
+
on AArch64, NEON is architecturally guaranteed and is what the baseline
|
|
117
|
+
kernels already compile to. */
|
|
118
|
+
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
|
|
119
|
+
#define ISOSPEC_ISA_BUILD_X86 1
|
|
120
|
+
#else
|
|
121
|
+
#define ISOSPEC_ISA_BUILD_X86 0
|
|
122
|
+
#endif
|
|
123
|
+
|
|
124
|
+
/* Build several instruction-set levels of the batched kernels into the binary
|
|
125
|
+
and pick one at run time? Off by default, so a plain `c++ unity-build.cpp`
|
|
126
|
+
(and the R package, which compiles its own sources under CRAN's flags) keeps
|
|
127
|
+
the single-level behaviour; the Makefile, the CMake builds and the Python
|
|
128
|
+
wheel all turn it on. Turning it on requires the isa_kernels_*.cpp files to
|
|
129
|
+
be compiled and linked in -- see isa_kernels.h. */
|
|
130
|
+
#if !defined(ISOSPEC_ISA_DISPATCH)
|
|
131
|
+
#define ISOSPEC_ISA_DISPATCH 0
|
|
132
|
+
#endif
|
|
133
|
+
|
|
134
|
+
// C++-only from here on: cwrapper.h includes this header, and that one must
|
|
135
|
+
// stay includable from a C translation unit (it is the C ABI's header).
|
|
136
|
+
#ifdef __cplusplus
|
|
137
|
+
|
|
138
|
+
#include <cstddef> // std::size_t, used below whether or not SIMD is available
|
|
139
|
+
|
|
140
|
+
#ifdef __has_include
|
|
141
|
+
// Deliberately NOT preferring <simd>: the standardized std::simd (P1928,
|
|
142
|
+
// landing piecemeal in libstdc++/libc++) does not expose the experimental
|
|
143
|
+
// TS's native_simd alias, so __has_include(<simd>) can be true while the
|
|
144
|
+
// header provides none of the API this codebase uses. GCC 16's <simd> is
|
|
145
|
+
// exactly this case (compiles under -std=c++2c, not under our -std=c++20)
|
|
146
|
+
// and silently broke the macOS build when given priority here. Revisit
|
|
147
|
+
// once std::simd's actual shipped API is verified against our usage.
|
|
148
|
+
//
|
|
149
|
+
// Also exclude libc++ (_LIBCPP_VERSION) explicitly: on Apple Clang,
|
|
150
|
+
// __has_include(<experimental/simd>) is true -- the header exists -- but
|
|
151
|
+
// it doesn't define std::experimental::native_simd, so the include below
|
|
152
|
+
// compiles yet fails at the alias/constexpr lines just past it. Measured
|
|
153
|
+
// on spot (Apple clang 21 / macOS 26): the same TU builds fine with
|
|
154
|
+
// Homebrew g++-16 (real libstdc++), so this is specifically a libc++
|
|
155
|
+
// limitation, not a general Apple/arm64 one -- use Homebrew GCC there
|
|
156
|
+
// instead if the SIMD path matters.
|
|
157
|
+
#if __has_include(<experimental/simd>) && !defined(_LIBCPP_VERSION)
|
|
158
|
+
#define ISOSPEC_HAS_SIMD 1
|
|
159
|
+
#include <experimental/simd>
|
|
160
|
+
namespace simd_ns = std::experimental;
|
|
161
|
+
using simd_double = simd_ns::native_simd<double>;
|
|
162
|
+
#endif
|
|
163
|
+
#endif
|
|
164
|
+
|
|
165
|
+
#if !defined(ISOSPEC_HAS_SIMD)
|
|
166
|
+
#define ISOSPEC_HAS_SIMD 0
|
|
167
|
+
#endif
|
|
168
|
+
|
|
169
|
+
// Alignment for the double arrays the batched kernels read and write.
|
|
170
|
+
//
|
|
171
|
+
// Deliberately a constant, and not alignof(native_simd<double>): with runtime
|
|
172
|
+
// ISA dispatch the kernel that ends up running is chosen from the CPU, not from
|
|
173
|
+
// the -march this translation unit saw, so the layout has to satisfy the widest
|
|
174
|
+
// kernel that could be selected -- 64 bytes, for AVX-512's 8 doubles. Anything
|
|
175
|
+
// derived from the ambient -march would under-align the arrays for a wider
|
|
176
|
+
// kernel. (It is also a cache line on every target we build for, which the
|
|
177
|
+
// arrays want anyway.)
|
|
178
|
+
constexpr std::size_t DOUBLE_SIMD_ALIGNMENT = 64;
|
|
179
|
+
|
|
180
|
+
#endif /* __cplusplus */
|
|
@@ -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
|