Skip to content

Commit ae6929c

Browse files
committed
Changes to avoid type-size and signed/unsigned conversion compiler warnings on Windows. In:
1, hammingdistance.h - lots of initializations to {0} and 0 (at least, in Windows builds), e.g. in ALIGN_32 2. clustertree.h - made the clusterIndex member of Link an intptr_t. 3. clustertree.h - explicitly created a local LeafDistance instance to avoid a weird emplace_back() error (I couldn't figure out what the compiler was upset about!) 4. clustertree.h - writeTreeToFile explicitly use std::ios_base::openmode ?! Why did I have to?! 5. nj,h - in getRowMinima() added some explicit initializations (to avoid warnings from the linter) 6. rapidnj.h - in getRowMinimum(), likewise. 7. rapidnj.h - in getRowMinimum(), declared a local b_plus_1 variable (!) (weird linter overflow "risk" warning). 8. stitchup.cpp - as for 4 above (writeTreeToFIle explicitly uses std::ios_base::openmode. 9, stitchup.cpp - some useless initializations, coz Visual Studio's linter can't tell do/while from while?
1 parent 68bf24f commit ae6929c

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
.settings
44
.project
55
.vs
6-
Debug
76
x64
8-
decentTree.vcxproj.user
7+
Debug
98
build/
9+
decentTree.vcxproj.user
1010
james_notes.txt
1111
pydecenttree/dist
1212
pydecenttree/pydecenttree.egg-info

clustertree.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ template <class T=double> struct Link {
4141
//a cluster (clusters are identified by index).
4242
//
4343
public:
44-
size_t clusterIndex;
45-
T linkDistance;
44+
intptr_t clusterIndex;
45+
T linkDistance;
4646
Link(size_t index, T distance)
4747
: clusterIndex(index), linkDistance(distance) {
4848
}
@@ -127,7 +127,10 @@ template <class T> class ClusterTree: public std::vector<Cluster<T>>
127127
LeafDistanceVector& ldv) {
128128
//Running time proportional to subtree size
129129
std::vector<LeafDistance> stack;
130-
stack.emplace_back(top, branch_length);
130+
LeafDistance top_node;
131+
top_node.first = top;
132+
top_node.second = branch_length;
133+
stack.emplace_back(top_node);
131134
while (!stack.empty()) {
132135
LeafDistance b = stack.back();
133136
stack.pop_back();
@@ -225,7 +228,7 @@ template <class T> class ClusterTree: public std::vector<Cluster<T>>
225228
F& out) const {
226229
out.exceptions(std::ios::failbit | std::ios::badbit);
227230
try {
228-
auto openMode = isOutputToBeAppended
231+
std::ios_base::openmode openMode = isOutputToBeAppended
229232
? std::ios_base::app : std::ios_base::trunc;
230233
openMode |= std::ios_base::out;
231234
out.open(treeFilePath.c_str(), openMode );

nj.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,15 @@ class VectorizedMatrix: public SUPER
461461
//from which that value came.
462462

463463
intptr_t colStop = row - blockSize;
464+
V rowVector(0);
465+
V totVector(0);
466+
V numVector(0);
464467
for (col=0; col<colStop; col+=blockSize) {
465-
V rowVector; rowVector.load_a(rowData+col);
466-
V totVector; totVector.load_a(tot+col);
468+
rowVector.load_a(rowData+col);
469+
totVector.load_a(tot+col);
467470
V adjVector = rowVector - totVector;
468471
VB less = adjVector < minVector;
469-
V numVector; numVector.load_a(nums+col);
472+
numVector.load_a(nums+col);
470473
ixVector = select(less, numVector, ixVector);
471474
minVector = select(less, adjVector, minVector);
472475
}

rapidnj.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ class BoundingMatrix: public SUPER
379379
#endif
380380
for (int b=0; b<threadCount; ++b) {
381381
T qBestForThread = qBest;
382-
size_t rStart = (b*rSize) / threadCount;
383-
size_t rStop = ((b+1)*rSize) / threadCount;
382+
int b_plus_1 = (b + 1);
383+
size_t rStart = (b*rSize) / threadCount;
384+
size_t rStop = (b_plus_1*rSize) / threadCount;
384385
for (size_t r=rStart; r < rStop
385386
&& rowMinima[r].value < infiniteDistance; ++r) {
386387
intptr_t rowA = rowMinima[r].row;
@@ -649,16 +650,19 @@ class VectorizedBoundingMatrix: public SUPER
649650

650651
V best_hc_vector ((T)(infiniteDistance));
651652
V best_ix_vector ((T)(-1));
653+
V raw(0);
654+
V c_tot(0);
655+
V ix(0);
652656

653657
for (size_t i=0; i<v_partners; i+=block_size) {
654658
for (int j=0; j<block_size; ++j) {
655659
int k = toCluster[i+j];
656660
blockCluster[j] = tot[k];
657661
blockIndex[j] = (T)k;
658662
}
659-
V raw; raw.load(rowData+i);
660-
V c_tot; c_tot.load(blockCluster);
661-
V ix; ix.load(blockIndex);
663+
raw.load(rowData+i);
664+
c_tot.load(blockCluster);
665+
ix.load(blockIndex);
662666
V hc = raw - c_tot; //subtract cluster totals to get half-cooked distances?
663667
VB less = hc < best_hc_vector; //which are improvements?
664668
best_hc_vector = select(less, hc, best_hc_vector);

starttree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ namespace StartTree
199199
return false;
200200
}
201201
constructTreeWith(builder);
202-
double rms;
202+
double rms = 0;
203203
if (!silent && builder.calculateRMSOfTMinusD(distanceMatrix,
204204
sequenceNames.size(), rms)) {
205205
std::cout << "Root Mean Square Error was " << rms << std::endl;

stitchup.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ template <class T=double> struct StitchupGraph {
363363
bool writeTreeToFile(int precision, const std::string &treeFilePath,
364364
bool isFileToBeOpenedForAppending,
365365
bool subtreeOnly, F& out) const {
366-
bool success = false;
366+
bool success = false;
367367
std::string desc = "Writing STITCH tree to ";
368368
desc+=treeFilePath;
369369
#if USE_PROGRESS_DISPLAY
@@ -373,7 +373,7 @@ template <class T=double> struct StitchupGraph {
373373
#endif
374374
out.exceptions(std::ios::failbit | std::ios::badbit);
375375
try {
376-
auto openMode = isFileToBeOpenedForAppending
376+
std::ios_base::openmode openMode = isFileToBeOpenedForAppending
377377
? std::ios_base::app : std::ios_base::trunc;
378378
openMode |= std::ios_base::out;
379379
out.open(treeFilePath.c_str(), openMode);
@@ -564,8 +564,8 @@ template < class T=double> class StitchupMatrix: public SquareMatrix<T> {
564564
#endif
565565
for (intptr_t join = 0; join + 1 < row_count; ++join) {
566566
LengthSortedStitch<T> shortest;
567-
size_t source;
568-
size_t dest;
567+
size_t source = 0;
568+
size_t dest = 0;
569569
do {
570570
shortest = heap.pop_min();
571571
source = shortest.source;

utils/hammingdistance.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ inline size_t conventionalHammingDistance(char unknown,
151151
inline uint64_t conventionalCountBitsSetInEither(uint64_t* a, uint64_t* b,
152152
size_t count /*in uint64_t*/) {
153153
uint64_t bits_set = 1;
154-
for (int i=0; i<count; ++i) {
154+
for (size_t i=0; i<count; ++i) {
155155
uint64_t bitsInEither = a[i] | b[i];
156156
uint64_t delta;
157157
#if (defined (__GNUC__) || defined(__clang__)) && !defined(CLANG_UNDER_VS)
@@ -175,7 +175,7 @@ inline uint64_t countBitsSetInEither(uint64_t* a, uint64_t* b, size_t count) {
175175
#else
176176

177177
#ifdef _MSC_VER
178-
#define ALIGN_32(x) __declspec(align(32)) x
178+
#define ALIGN_32(x) __declspec(align(32)) x = {0}
179179
#else
180180
#define ALIGN_32(x) x __attribute__((aligned(32)))
181181
#endif
@@ -194,12 +194,12 @@ inline uint64_t vectorHammingDistanceTemplate(char unknown,
194194
DV distance_vector = 0;
195195
if (W <= seqLen) {
196196
blockStop = seqLen - (seqLen & (W-1));
197-
CV blockA; //next 32 bytes from a
198-
CV blockB; //next 32 bytes from b
197+
CV blockA(0); //next 32 bytes from a
198+
CV blockB(0); //next 32 bytes from b
199199
CV blockU = unknown;
200200
ALIGN_32(uint64_t vec[W/8]);
201201
ALIGN_32(uint64_t res[W/8]);
202-
DV distance_bump_vector;
202+
DV distance_bump_vector(0);
203203
for ( size_t i=0; i<blockStop; i+=W) {
204204

205205
//Compare W characters at a time
@@ -248,11 +248,11 @@ uint64_t countBitsSetInEitherTemplate(uint64_t* a, uint64_t* b,
248248
size_t count /*in uint64_t*/) {
249249
//Assumes: W divides count
250250
V count_vector = 0;
251-
V aData;
252-
V bData;
251+
V aData = 0;
252+
V bData = 0;
253253
ALIGN_32(uint64_t vec[W]);
254254
ALIGN_32(uint64_t res[W]);
255-
V dData;
255+
V dData = 0;
256256
for (int i=0; i<count; i+=W) {
257257
aData.load(a+i);
258258
bData.load(b+i);
@@ -309,7 +309,8 @@ inline size_t sumForUnknownCharacters
309309
int pos = 0;
310310
if (blockSize < seqLen) {
311311
//Next line assumes that: blockSize is power of 2
312-
intptr_t blockStop = seqLen - (seqLen & (blockSize - 1));
312+
int blockSize_less_1 = blockSize - 1;
313+
intptr_t blockStop = seqLen - (seqLen & (blockSize_less_1));
313314
for (; pos < blockStop; pos += blockSize) {
314315
Vec32c blockRead;
315316
blockRead.load(sequence + pos);

0 commit comments

Comments
 (0)