Skip to content

Commit

Permalink
[ProgressBar] Replace all SG_SGPROGRESS with new progress().
Browse files Browse the repository at this point in the history
  • Loading branch information
geektoni committed Jun 6, 2017
1 parent 0de3c9c commit 92f5009
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
6 changes: 4 additions & 2 deletions examples/undocumented/libshogun/classifier_latent_svm.cpp
Expand Up @@ -3,6 +3,7 @@
#include <shogun/latent/LatentSVM.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/base/init.h>
#include <shogun/base/progress.h>
#include <shogun/lib/common.h>
#include <shogun/io/SGIO.h>
#include <shogun/mathematics/Math.h>
Expand Down Expand Up @@ -113,6 +114,7 @@ static void read_dataset(char* fname, CLatentFeatures*& feats, CLatentLabels*& l
feats = new CLatentFeatures(num_examples);
SG_REF(feats);

auto pb=progress(range(num_examples));
CMath::init_random();
for (int i = 0; (!feof(fd)) && (i < num_examples); ++i)
{
Expand Down Expand Up @@ -150,7 +152,7 @@ static void read_dataset(char* fname, CLatentFeatures*& feats, CLatentLabels*& l
CBoundingBox* bb = new CBoundingBox(x,y);
labels->add_latent_label(bb);

SG_SPROGRESS(i, 0, num_examples);
pb.print_progress();
CHOGFeatures* hog = new CHOGFeatures(width, height);
hog->hog = SG_CALLOC(float64_t**, hog->width);
for (int j = 0; j < width; ++j)
Expand All @@ -176,7 +178,7 @@ static void read_dataset(char* fname, CLatentFeatures*& feats, CLatentLabels*& l

labels->set_labels(ys);

SG_SDONE();
pb.complete();
}

int main(int argc, char** argv)
Expand Down
6 changes: 4 additions & 2 deletions src/shogun/lib/external/shogun_libsvm.cpp
Expand Up @@ -42,6 +42,7 @@
#include <shogun/lib/Signal.h>
#include <shogun/lib/common.h>
#include <shogun/mathematics/Math.h>
#include <shogun/base/progress.h>

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -432,6 +433,7 @@ void Solver::Solve(
CSignal::clear_cancel();
CTime start_time;
{
auto pb= progress(range(l));
G = SG_MALLOC(float64_t, l);
G_bar = SG_MALLOC(float64_t, l);
int32_t i;
Expand All @@ -455,9 +457,9 @@ void Solver::Solve(
for(j=0;j<l;j++)
G_bar[j] += get_C(i) * Q_i[j];
}
SG_SPROGRESS(i, 0, l)
pb.print_progress();
}
SG_SDONE()
pb.complete();
}

// optimization step
Expand Down
29 changes: 10 additions & 19 deletions src/shogun/machine/KernelMachine.cpp
Expand Up @@ -13,13 +13,16 @@
#include <shogun/lib/Signal.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/io/SGIO.h>
#include <shogun/base/progress.h>

#include <shogun/kernel/Kernel.h>
#include <shogun/kernel/CustomKernel.h>
#include <shogun/labels/Labels.h>


#ifdef HAVE_OPENMP
#include <omp.h>

#endif

using namespace shogun;
Expand Down Expand Up @@ -337,6 +340,7 @@ SGVector<float64_t> CKernelMachine::apply_get_outputs(CFeatures* data)
}
else
{
auto pb = progress(range(num_vectors));
int32_t num_threads;
int64_t step;
#pragma omp parallel shared(num_threads, step)
Expand All @@ -355,7 +359,6 @@ SGVector<float64_t> CKernelMachine::apply_get_outputs(CFeatures* data)
step = num_vectors;
int32_t thread_num = 0;
#endif
bool verbose = (thread_num == 0);
int32_t start = thread_num * step;
int32_t end = (thread_num == num_threads)
? num_vectors
Expand All @@ -368,13 +371,8 @@ SGVector<float64_t> CKernelMachine::apply_get_outputs(CFeatures* data)
vec < end && !CSignal::cancel_computations(); vec++)
#endif
{
if (verbose)
{
int32_t vectors_num = end - start;
int32_t v = vec - start;
if ((v % (vectors_num / 100 + 1)) == 0)
SG_SPROGRESS(v, 0.0, vectors_num - 1)
}
pb.print_progress();

ASSERT(kernel)
if (kernel->has_property(KP_LINADD) &&
(kernel->get_is_initialized()))
Expand All @@ -393,14 +391,13 @@ SGVector<float64_t> CKernelMachine::apply_get_outputs(CFeatures* data)
}
}
}
pb.complete();
}

#ifndef WIN32
if ( CSignal::cancel_computations() )
SG_INFO("prematurely stopped. \n")
else
#endif
SG_DONE()
}

SG_DEBUG("leaving %s::apply_get_outputs(%s at %p)\n",
Expand Down Expand Up @@ -507,6 +504,7 @@ SGVector<float64_t> CKernelMachine::apply_locked_get_output(
io->disable_progress();

/* custom kernel never has batch evaluation property so dont do this here */
auto pb = progress(range(0, num_inds));
int32_t num_threads;
int64_t step;
#pragma omp parallel shared(num_threads, step)
Expand All @@ -524,7 +522,6 @@ SGVector<float64_t> CKernelMachine::apply_locked_get_output(
step = num_inds;
int32_t thread_num = 0;
#endif
bool verbose = (thread_num == 0);
int32_t start = thread_num * step;
int32_t end =
(thread_num == num_threads) ? num_inds : (thread_num + 1) * step;
Expand All @@ -535,13 +532,7 @@ SGVector<float64_t> CKernelMachine::apply_locked_get_output(
vec++)
#endif
{
if (verbose)
{
int32_t vectors_num = end - start;
int32_t v = vec - start;
if ((v % (vectors_num / 100 + 1)) == 0)
SG_SPROGRESS(v, 0.0, vectors_num - 1)
}
pb.print_progress();
index_t index = indices[vec];
ASSERT(kernel)
if (kernel->has_property(KP_LINADD) &&
Expand All @@ -561,13 +552,13 @@ SGVector<float64_t> CKernelMachine::apply_locked_get_output(
}
}
}
pb.complete();

#ifndef WIN32
if ( CSignal::cancel_computations() )
SG_INFO("prematurely stopped.\n")
else
#endif
SG_DONE()

return output;
}
Expand Down

0 comments on commit 92f5009

Please sign in to comment.