[shark] 46/58: slow loop replaced with fast alternative - thanks for Phil Marek
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Mar 16 10:05:33 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository shark.
commit 6e44e22b407c19cdd708c36c7409eac1d2e749cf
Author: Tobias Glasmachers <tobias.glasmachers at ini.rub.de>
Date: Tue Feb 16 15:28:23 2016 +0100
slow loop replaced with fast alternative - thanks for Phil Marek
---
include/shark/Algorithms/QP/QpBoxLinear.h | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/include/shark/Algorithms/QP/QpBoxLinear.h b/include/shark/Algorithms/QP/QpBoxLinear.h
index 0f72e4a..0202ddd 100644
--- a/include/shark/Algorithms/QP/QpBoxLinear.h
+++ b/include/shark/Algorithms/QP/QpBoxLinear.h
@@ -345,7 +345,7 @@ public:
for (std::size_t i=0; i<batch.size(); i++)
{
CompressedRealVector x_i = shark::get(batch, i).input;
- if (x_i.nnz() == 0) continue;
+ // if (x_i.nnz() == 0) continue;
unsigned int y_i = shark::get(batch, i).label;
y[j] = 2.0 * y_i - 1.0;
@@ -364,15 +364,19 @@ public:
j++;
}
}
- for (std::size_t i=0, j=0, k=0; i<x.size(); i++)
+ for (std::size_t b=0, j=0, k=0; b<dataset.numberOfBatches(); b++)
{
- CompressedRealVector x_i = dataset.element(i).input;
- if (x_i.nnz() == 0) continue;
+ DatasetType::const_batch_reference batch = dataset.batch(b);
+ for (std::size_t i=0; i<batch.size(); i++)
+ {
+ CompressedRealVector x_i = shark::get(batch, i).input;
+ // if (x_i.nnz() == 0) continue;
- x[j] = &storage[k];
- for (; storage[k].index != (std::size_t)-1; k++);
- k++;
- j++;
+ x[j] = &storage[k]; // cannot be done in the first loop because of vector reallocation
+ for (; storage[k].index != (std::size_t)-1; k++);
+ k++;
+ j++;
+ }
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/shark.git
More information about the debian-science-commits
mailing list