103 REQUIRE(l,
"Left hand side features must be set!\n");
104 REQUIRE(r,
"Right hand side features must be set!\n");
107 "Right hand side of features (%s) must be of same type with left hand side features (%s)\n",
113 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
119 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
125 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
208 REQUIRE(idx_a >= 0 && idx_b >= 0,
"In CDistance::distance(int32_t,int32_t), idx_a and "
209 "idx_b must be positive, %d and %d given instead\n", idx_a, idx_b)
218 if (idx_a>=num_vectors)
219 idx_a=2*num_vectors-1-idx_a;
221 if (idx_b>=num_vectors)
222 idx_b=2*num_vectors-1-idx_b;
225 REQUIRE(idx_a < lhs->get_num_vectors() && idx_b < rhs->get_num_vectors(),
226 "In CDistance::distance(int32_t,int32_t), idx_a and idx_b must be less than "
227 "the number of vectors, but %d >= %d or %d >= %d\n",
248 SG_INFO(
"precomputing distance matrix (%ix%i)\n", num_left, num_right)
250 ASSERT(num_left==num_right)
252 int32_t num=num_left;
257 for (int32_t i=0; i<num; i++)
260 for (int32_t j=0; j<=i; j++)
268 void CDistance::init()
278 "Feature vectors to occur on left hand side.");
280 "Feature vectors to occur on right hand side.");
286 int32_t i_start=params->
start;
287 int32_t i_end=params->
end;
296 int64_t total=total_start;
298 for (int32_t i=i_start; i<i_end; i++)
305 for (int32_t j=j_start; j<n; j++)
310 if (symmetric && i!=j)
317 if (symmetric && i!=j)
343 int64_t total_num = int64_t(m)*n;
346 bool symmetric= (
lhs &&
lhs==
rhs && m==n);
348 SG_DEBUG(
"returning distance matrix of size %dx%d\n", m, n)
350 result=SG_MALLOC(T, total_num);
366 get_distance_matrix_helper<T>((
void*) ¶ms);
370 pthread_t* threads = SG_MALLOC(pthread_t, num_threads-1);
372 int64_t step= total_num/num_threads;
377 for (t=0; t<num_threads; t++)
380 params[t].
result = result;
390 int code=pthread_create(&threads[t], NULL,
391 CDistance::get_distance_matrix_helper<T>, (
void*)¶ms[t]);
395 SG_WARNING(
"Thread creation failed (thread %d of %d) "
396 "with error:'%s'\n",t, num_threads, strerror(code));
403 params[t].
result = result;
412 get_distance_matrix_helper<T>(¶ms[t]);
414 for (t=0; t<num_threads; t++)
416 if (pthread_join(threads[t], NULL) != 0)
417 SG_WARNING(
"pthread_join of thread %d/%d failed\n", t, num_threads)
432 template void* CDistance::get_distance_matrix_helper<float64_t>(
void* p);
433 template void* CDistance::get_distance_matrix_helper<float32_t>(
void* p);
virtual const char * get_name() const =0
virtual bool support_compatible_class() const
void do_precompute_matrix()
matrix precomputation
virtual bool has_features()
Class Distance, a base class for all the distances used in the Shogun toolbox.
virtual bool get_feature_class_compatibility(EFeatureClass rhs) const
int32_t get_num_threads() const
virtual int32_t get_num_vec_lhs()
virtual CFeatures * replace_lhs(CFeatures *lhs)
virtual void remove_lhs()
takes all necessary steps if the lhs is removed from distance matrix
virtual int32_t get_num_vectors() const =0
virtual bool check_compatibility(CFeatures *l, CFeatures *r)
void add(bool *param, const char *name, const char *description="")
Class SGObject is the base class of all shogun objects.
#define SG_OBJ_PROGRESS(o,...)
virtual void remove_lhs_and_rhs()
A File access base class.
virtual EFeatureClass get_feature_class() const =0
virtual int32_t get_num_vec_rhs()
static bool cancel_computations()
virtual CFeatures * replace_rhs(CFeatures *rhs)
int32_t compute_row_start(int64_t offs, int32_t n, bool symmetric)
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
all of classes and functions are contained in the shogun namespace
CFeatures * lhs
feature vectors to occur on the left hand side
The class Features is the base class of all feature objects.
CFeatures * rhs
feature vectors to occur on the right hand side
SGMatrix< float64_t > get_distance_matrix()
float32_t * precomputed_matrix
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from distance matrix
static void * get_distance_matrix_helper(void *p)
virtual float64_t compute(int32_t idx_a, int32_t idx_b)=0
virtual EFeatureType get_feature_type() const =0