Skip to content

Commit bc55f9a

Browse files
committed
Use 64bit int to avoid potential integer overflow
1 parent f7a3bef commit bc55f9a

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

src/DualViewPlugin.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,10 @@ void DualViewPlugin::updateLineConnections()
748748
}
749749

750750
// define lines - assume embedding A is dimension embedding, embedding B is observation embedding
751-
const size_t numDimensions = _embeddingSourceDatasetB->getNumDimensions(); // Assume the number of points in A is the same as the number of dimensions in B
752-
const size_t numDimensionsFull = _embeddingSourceDatasetB->getNumDimensions(); // FIXME: is this needed??
753-
const size_t numPoints = _embeddingSourceDatasetB->getNumPoints(); // num of points in source dataset B
754-
const size_t numPointsLocal = _embeddingDatasetB->getNumPoints(); // num of points in the embedding B
751+
const int64_t numDimensions = _embeddingSourceDatasetB->getNumDimensions(); // Assume the number of points in A is the same as the number of dimensions in B
752+
const int64_t numDimensionsFull = _embeddingSourceDatasetB->getNumDimensions(); // FIXME: is this needed??
753+
const int64_t numPoints = _embeddingSourceDatasetB->getNumPoints(); // num of points in source dataset B
754+
const int64_t numPointsLocal = _embeddingDatasetB->getNumPoints(); // num of points in the embedding B
755755

756756
std::vector<std::uint32_t> localGlobalIndicesB;
757757
_embeddingSourceDatasetB->getGlobalIndices(localGlobalIndicesB);
@@ -760,10 +760,10 @@ void DualViewPlugin::updateLineConnections()
760760

761761
// Iterate over each row and column in the subset to generate lines
762762
auto start2 = std::chrono::high_resolution_clock::now();
763-
for (size_t cellLocalIndex = 0; cellLocalIndex < numPointsLocal; cellLocalIndex++) {
764-
for (size_t dimIdx = 0; dimIdx < numDimensions; dimIdx++) {
763+
for (int64_t cellLocalIndex = 0; cellLocalIndex < numPointsLocal; cellLocalIndex++) {
764+
for (int64_t dimIdx = 0; dimIdx < numDimensions; dimIdx++) {
765765

766-
size_t cellGlobalIdx = static_cast<size_t>(localGlobalIndicesB[cellLocalIndex]);
766+
int64_t cellGlobalIdx = static_cast<int64_t>(localGlobalIndicesB[cellLocalIndex]);
767767
float expression = _embeddingSourceDatasetB->getValueAt(cellGlobalIdx * numDimensionsFull + dimIdx);
768768

769769
//if (expression != columnMins[dimLocalIdx]) { // only draw lines for cells whose expression are not at the minimum
@@ -1425,15 +1425,15 @@ void DualViewPlugin::updateEmbeddingASize()
14251425
// _embeddingSourceDatasetB->getGlobalIndices(localGlobalIndicesB);
14261426
//
14271427
// std::vector<float> selectedMeanExpression(numPointsA, 0.0f);
1428-
// int selectedNumPointsB = selection->indices.size();
1429-
// int numDimensionsB = _embeddingSourceDatasetB->getNumDimensions();
1428+
// int64_t selectedNumPointsB = selection->indices.size();
1429+
// int64_t numDimensionsB = _embeddingSourceDatasetB->getNumDimensions();
14301430
//
1431-
// for (int i = 0; i < selectedNumPointsB; i++)
1431+
// for (int64_t i = 0; i < selectedNumPointsB; i++)
14321432
// {
1433-
// int globalIndex = selection->indices[i];
1433+
// int64_t globalIndex = selection->indices[i];
14341434
// //qDebug() << "globalIndex" << globalIndex;
14351435
//
1436-
// for (int j = 0; j < numPointsA; j++)
1436+
// for (int64_t j = 0; j < numPointsA; j++)
14371437
// {
14381438
// selectedMeanExpression[j] += _embeddingSourceDatasetB->getValueAt(globalIndex * numDimensionsB + j);
14391439
// }
@@ -1933,11 +1933,11 @@ void DualViewPlugin::computeTopCellForEachGene()
19331933
// for this cluster, compute the avg expression for each gene
19341934
std::vector<float> avgExpressionForEachGene(numGene, 0.0f);
19351935
int count = 0;
1936-
for (const size_t& index : cluster.getIndices()) // index is the global index of the cell in embedding B
1936+
for (const int64_t& index : cluster.getIndices()) // index is the global index of the cell in embedding B
19371937
{
19381938

1939-
size_t offset = index * numGene;
1940-
for (size_t i = 0; i < numGene; i++)
1939+
int64_t offset = index * numGene;
1940+
for (int64_t i = 0; i < numGene; i++)
19411941
{
19421942
avgExpressionForEachGene[i] += fullDatasetB->getValueAt(offset + i);
19431943
}
@@ -1996,16 +1996,16 @@ void DualViewPlugin::computeTopCellForEachGene()
19961996

19971997
// Extract gene expression for this cell from fullDatasetB using global indices
19981998
//std::vector<float> geneExpression(numGene, 0.0f);
1999-
//for (int i = 0; i < numGene; i++)
1999+
//for (int64_t i = 0; i < numGene; i++)
20002000
//{
20012001
// // and getValueAt(row * numGene + col) retrieves the value:
20022002
// geneExpression[i] = fullDatasetB->getValueAt((globalCellIndex * numGene) + i);
20032003
//}
20042004

20052005
//qDebug() << "extracted from fullDataA geneExpression.size() = " << geneExpression.size();
20062006

2007-
size_t offset = globalCellIndex * numGene;
2008-
for (size_t i = 0; i < numGene; i++)
2007+
int64_t offset = globalCellIndex * numGene;
2008+
for (int64_t i = 0; i < numGene; i++)
20092009
{
20102010
//avgExpressionForEachGene[i] += geneExpression[i];
20112011
avgExpressionForEachGene[i] += fullDatasetB->getValueAt(offset + i);

0 commit comments

Comments
 (0)