31 using namespace shogun;
191 REQUIRE(idx_a >= 0 && idx_b >= 0,
"In CDistance::distance(int32_t,int32_t), idx_a and "
192 "idx_b must be positive, %d and %d given instead\n", idx_a, idx_b)
201 if (idx_a>=num_vectors)
202 idx_a=2*num_vectors-1-idx_a;
204 if (idx_b>=num_vectors)
205 idx_b=2*num_vectors-1-idx_b;
208 REQUIRE(idx_a < lhs->get_num_vectors() && idx_b < rhs->get_num_vectors(),
209 "In CDistance::distance(int32_t,int32_t), idx_a and idx_b must be less than "
210 "the number of vectors, but %d >= %d or %d >= %d\n",
231 SG_INFO(
"precomputing distance matrix (%ix%i)\n", num_left, num_right)
233 ASSERT(num_left==num_right)
235 int32_t num=num_left;
240 for (int32_t i=0; i<num; i++)
243 for (int32_t j=0; j<=i; j++)
251 void CDistance::init()
261 "Feature vectors to occur on left hand side.");
263 "Feature vectors to occur on right hand side.");
269 int32_t i_start=params->
start;
270 int32_t i_end=params->
end;
279 int64_t total=total_start;
281 for (int32_t i=i_start; i<i_end; i++)
288 for (int32_t j=j_start; j<n; j++)
293 if (symmetric && i!=j)
300 if (symmetric && i!=j)
326 int64_t total_num = int64_t(m)*n;
329 bool symmetric= (
lhs &&
lhs==
rhs && m==n);
333 result=SG_MALLOC(T, total_num);
335 int32_t num_threads=
parallel->get_num_threads();
349 get_distance_matrix_helper<T>((
void*) ¶ms);
353 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
355 int64_t step= total_num/num_threads;
360 for (t=0; t<num_threads; t++)
363 params[t].
result = result;
373 int code=pthread_create(&threads[t], NULL,
374 CDistance::get_distance_matrix_helper<T>, (
void*)¶ms[t]);
378 SG_WARNING(
"Thread creation failed (thread %d of %d) "
379 "with error:'%s'\n",t, num_threads, strerror(code));
386 params[t].
result = result;
395 get_distance_matrix_helper<T>(¶ms[t]);
397 for (t=0; t<num_threads; t++)
399 if (pthread_join(threads[t], NULL) != 0)
400 SG_WARNING(
"pthread_join of thread %d/%d failed\n", t, num_threads)
409 return
SGMatrix<T>(result,m,n,true);