当前位置: 首页>>代码示例>>C++>>正文


C++ NV_MAT_V函数代码示例

本文整理汇总了C++中NV_MAT_V函数的典型用法代码示例。如果您正苦于以下问题:C++ NV_MAT_V函数的具体用法?C++ NV_MAT_V怎么用?C++ NV_MAT_V使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NV_MAT_V函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: nv_vector_copy

void
nv_vector_copy(nv_matrix_t *dest, int dm, const nv_matrix_t *src, int sm)
{
	NV_ASSERT(dest->n >= src->n);

	memmove(&NV_MAT_V(dest, dm, 0), &NV_MAT_V(src, sm, 0), src->step * sizeof(float));
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:7,代码来源:nv_core_matrix.c

示例2: nv_vector_fill

void 
nv_vector_fill(nv_matrix_t *mat, int m, float v)
{
	if (mat->n < 64) {
		int i;
		for (i = 0; i < mat->n; ++i) {
			NV_MAT_V(mat, m, i) = v;
		}
	} else {
		int j, k;
		float *p = &NV_MAT_V(mat, m, 0);
		p[0] = v;
		k = 1;
		j = 1;
		while (k * 2 < mat->n) {
			memmove(&p[j], &p[0], k * sizeof(float));
			j += k;
			k *= 2;
		}
		if (k > 1) {
			k /= 2;
		}
		while (j < mat->n) {
			if (j + k <= mat->n) {
				memmove(&p[j], &p[0], k * sizeof(float));
				j += k;
			} else {
				if (k > 1) {
					k /= 2;
				}
			}
		}
	}
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:34,代码来源:nv_core_matrix.c

示例3: nv_contrast

void 
nv_contrast(nv_matrix_t *dest, int dch,
			const nv_matrix_t *src, int sch,
			float angle)// 0.0f-90.0f
{
	int i, j;
	float deg_scale = NV_PI / 180.0f;
	nv_matrix_t *conv = nv_matrix_alloc(256, 1);

	NV_ASSERT(dest->m == src->m);
	NV_ASSERT(dch <= dest->n);
	NV_ASSERT(sch <= src->n);

	for (i = 0; i < conv->n; ++i) {
		NV_MAT_V(conv, 0, i) = tanf(angle * deg_scale) * ((float)i - 127.0f) + 127.0f;
		if (NV_MAT_V(conv, 0, i) > 255.0f) {
			NV_MAT_V(conv, 0, i) = 255.0f;
		}
		if (NV_MAT_V(conv, 0, i) < 0.0f) {
			NV_MAT_V(conv, 0, i) = 0.0f;
		}
	}
	for (j = 0; j < src->m; ++j) {
		NV_ASSERT(NV_MAT_V(src, j, sch) < 256.0f);
		NV_ASSERT(NV_MAT_V(src, j, sch) > 0.0f);

		NV_MAT_V(dest, j, dch) = NV_MAT_V(conv, 0, (int)NV_MAT_V(src, j, sch));
	}
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:29,代码来源:nv_ip_gray.c

示例4: conv_image2vec

static nv_matrix_t *
conv_image2vec(const nv_bgseg_t *bg,
			   const nv_matrix_t *image)
{
	nv_matrix_t *vec;
	nv_matrix_t *smooth;
	nv_matrix_t *resize = NULL, *gray = NULL;
	int i;
	float scale = (float)bg->size / (float)NV_MAX(image->rows, image->cols);

	if (scale != 1.0f) {
		resize = nv_matrix3d_alloc(image->n,
								   NV_ROUND_INT(image->rows * scale),
								   NV_ROUND_INT(image->cols * scale));
		nv_resize(resize, image);
		image = resize;
	}
	if (image->n != 1) {
		gray = nv_matrix3d_alloc(1, image->rows, image->cols);
		nv_gray(gray, image);
		image = gray;
	}
	vec = nv_matrix_alloc(image->rows * image->cols, 1);
	smooth = nv_matrix_clone(image);
	nv_gaussian5x5(smooth, 0, image, 0);

	for (i = 0; i < image->m; ++i) {
		NV_MAT_V(vec, 0, i) = NV_MAT_V(smooth, i, 0);
	}
	nv_matrix_free(&smooth);
	nv_matrix_free(&gray);
	nv_matrix_free(&resize);
	
	return vec;
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:35,代码来源:nv_ip_bgseg.c

示例5: nv_mahalanobis

// Mahalanobis distance
float nv_mahalanobis(const nv_cov_t *cov, const nv_matrix_t *x, int xm)
{
	int n;
	nv_matrix_t *y = nv_matrix_alloc(x->n, 1);
	nv_matrix_t *x2 = nv_matrix_alloc(x->n, 1);
	float distance;
	float delta2 = 0.0f;

	nv_matrix_zero(y);
	nv_matrix_zero(x2);
	for (n = 0; n < x2->n; ++n) {
		NV_MAT_V(x2, 0, n) = NV_MAT_V(x, xm, n) - NV_MAT_V(cov->u, 0, n);
	}
	nv_gemv(y, 0, NV_MAT_TR, cov->eigen_vec, x2, xm);
	for (n = 0; n < x->n; ++n) {
		float ev = NV_MAT_V(cov->eigen_val, n, 0);
		float xv = NV_MAT_V(y, 0, n);
		delta2 += (xv * xv) / ev;
	}

	distance = sqrtf(delta2);
	nv_matrix_free(&x2);
	nv_matrix_free(&y);

	return distance;
}
开发者ID:inlmouse,项目名称:lbpcascade_animeface.Net,代码行数:27,代码来源:nv_distance.c

示例6: nv_contrast_sigmoid

void nv_contrast_sigmoid(nv_matrix_t *dest, int dch,
						 const nv_matrix_t *src, int sch,
						 float gain) // 0.1f-1.0f
{
	int i, j;
	nv_matrix_t *conv = nv_matrix_alloc(256, 1);
	float max_v = -FLT_MAX;
	float min_v = FLT_MAX;

	NV_ASSERT(dest->m == src->m);
	NV_ASSERT(dch <= dest->n);
	NV_ASSERT(sch <= src->n);

	for (j = 0; j < src->m; ++j) {
		if (max_v < NV_MAT_V(src, j, sch)) {
			max_v = NV_MAT_V(src, j, sch);
		}
		if (min_v > NV_MAT_V(src, j, sch)) {
			min_v = NV_MAT_V(src, j, sch);
		}
	}

	for (i = 0; i < conv->n; ++i) {
		float x = 255.0f * ((float)i - min_v) / max_v;
		NV_MAT_V(conv, 0, i) = 255.0f * (1.0f / (1.0f + expf(-gain * (x - 128.0f) * 0.078125f)));
	}
	for (j = 0; j < src->m; ++j) {
		NV_ASSERT(NV_MAT_V(src, j, sch) < 256.0f);
		NV_ASSERT(NV_MAT_V(src, j, sch) > 0.0f);
		NV_MAT_V(dest, j, dch) = NV_MAT_V(conv, 0, (int)NV_MAT_V(src, j, sch));
	}
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:32,代码来源:nv_ip_gray.c

示例7: nv_mlp_regression

/* 回帰 */
void nv_mlp_regression(const nv_mlp_t *mlp, 
					   const nv_matrix_t *x, int xm, nv_matrix_t *out, int om)
{
	int m;
	float y;
	nv_matrix_t *input_y = nv_matrix_alloc(mlp->input_w->m, 1);
	nv_matrix_t *hidden_y = nv_matrix_alloc(mlp->hidden_w->m, 1);

#ifdef _OPENMP
#pragma omp parallel for private(y)
#endif
	for (m = 0; m < mlp->input_w->m; ++m) {
		y = NV_MAT_V(mlp->input_bias, m, 0)  * NV_MLP_BIAS;
		y += nv_vector_dot(x, xm, mlp->input_w, m);
		NV_MAT_V(input_y, 0, m) = nv_mlp_sigmoid(y);
	}

	for (m = 0; m < mlp->hidden_w->m; ++m) {
		y = NV_MAT_V(mlp->hidden_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(input_y, 0, mlp->hidden_w, m);
		NV_MAT_V(hidden_y, 0, m) = y;
	}

	nv_vector_copy(out, om, hidden_y, 0);

	nv_matrix_free(&input_y);
	nv_matrix_free(&hidden_y);
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:29,代码来源:nv_ml_mlp.c

示例8: nv_vector_dot

float 
nv_vector_dot(const nv_matrix_t *vec1, int m1,
			  const nv_matrix_t *vec2, int m2)
{
	NV_ASSERT(vec1->n == vec2->n);
	
#if NV_ENABLE_AVX
	{
		NV_ALIGNED(float, mm[8], 32);
		__m256 x, u;
		int n;
		int pk_lp = (vec1->n & 0xfffffff8);
		float dp = 0.0f;
		
		u = _mm256_setzero_ps();
		for (n = 0; n < pk_lp; n += 8) {
			x = _mm256_load_ps(&NV_MAT_V(vec2, m2, n));
			u = _mm256_add_ps(u, _mm256_mul_ps(x, *(__m256 *)&NV_MAT_V(vec1, m1, n)));
		}
		_mm256_store_ps(mm, u);
		dp = mm[0] + mm[1] + mm[2] + mm[3] + mm[4] + mm[5] + mm[6] + mm[7];
		for (n = pk_lp; n < vec1->n; ++n) {
			dp += NV_MAT_V(vec1, m1, n) * NV_MAT_V(vec2, m2, n);
		}
		
		return dp;
	}
#elif NV_ENABLE_SSE2
	{
		NV_ALIGNED(float, mm[4], 16);
		__m128 x, u;
		int n;
		int pk_lp = (vec1->n & 0xfffffffc);
		float dp = 0.0f;

		u = _mm_setzero_ps();
		for (n = 0; n < pk_lp; n += 4) {
			x = _mm_load_ps(&NV_MAT_V(vec2, m2, n));
			u = _mm_add_ps(u,
				_mm_mul_ps(x, *(__m128 *)&NV_MAT_V(vec1, m1, n)));
		}
		_mm_store_ps(mm, u);
		dp = mm[0] + mm[1] + mm[2] + mm[3];
		for (n = pk_lp; n < vec1->n; ++n) {
			dp += NV_MAT_V(vec1, m1, n) * NV_MAT_V(vec2, m2, n);
		}
  
		return dp;
	}
#else
	{
		int n;
		float dp = 0.0f;
		for (n = 0; n < vec1->n; ++n) {
			dp += NV_MAT_V(vec1, m1, n) * NV_MAT_V(vec2, m2, n);
		}
		return dp;
	}
#endif
}
开发者ID:nagadomi,项目名称:nv-debian,代码行数:60,代码来源:nv_num_vector.c

示例9: nv_mlp_predict_vector

void
nv_mlp_predict_vector(const nv_mlp_t *mlp,
					  nv_matrix_t *p, int p_j,
					  const nv_matrix_t *x, int x_j)
{
	int m;
	float y;
	nv_matrix_t *input_y = nv_matrix_alloc(mlp->hidden, 1);
	nv_matrix_t *hidden_y = nv_matrix_alloc(mlp->output, 1);
	float dropout_scale = 1.0f - mlp->dropout;
	float noise_scale = 1.0f - mlp->noise;
	
#ifdef _OPENMP
#pragma omp parallel for private(y)
#endif
	for (m = 0; m < mlp->hidden; ++m) {
		y = NV_MAT_V(mlp->input_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(x, x_j, mlp->input_w, m) * noise_scale;
		NV_MAT_V(input_y, 0, m) = nv_mlp_sigmoid(y) * dropout_scale;
	}
	for (m = 0; m < mlp->output; ++m) {
		y = NV_MAT_V(mlp->hidden_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(input_y, 0, mlp->hidden_w, m);
		NV_MAT_V(hidden_y, 0, m) = nv_mlp_sigmoid(y);
	}
	nv_mlp_softmax(p, p_j, hidden_y, 0);

	nv_matrix_free(&input_y);
	nv_matrix_free(&hidden_y);
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:30,代码来源:nv_ml_mlp.c

示例10: nv_mlp_predict

float nv_mlp_predict(const nv_mlp_t *mlp,
					 const nv_matrix_t *x, int xm, int cls)
{
	int m;
	float y;
	nv_matrix_t *input_y = nv_matrix_alloc(mlp->input_w->m, 1);
	nv_matrix_t *hidden_y = nv_matrix_alloc(mlp->output, 1);
	nv_matrix_t *output_y = nv_matrix_alloc(mlp->output, 1);
	float p;
	double dropout_scale = 1.0 - mlp->dropout;
	float noise_scale = 1.0f - mlp->noise;
	
#ifdef _OPENMP
#pragma omp parallel for private(y)
#endif
	for (m = 0; m < mlp->hidden; ++m) {
		y = NV_MAT_V(mlp->input_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(x, xm, mlp->input_w, m) * noise_scale;
		NV_MAT_V(input_y, 0, m) = nv_mlp_sigmoid(y) * dropout_scale;
	}

	for (m = 0; m < mlp->output; ++m) {
		y = NV_MAT_V(mlp->hidden_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(input_y, 0, mlp->hidden_w, m);
		NV_MAT_V(hidden_y, 0, m) = nv_mlp_sigmoid(y);
	}
	nv_mlp_softmax(output_y, 0, hidden_y, 0);
	p = NV_MAT_V(output_y, 0, cls);

	nv_matrix_free(&input_y);
	nv_matrix_free(&hidden_y);
	nv_matrix_free(&output_y);

	return p;
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:35,代码来源:nv_ml_mlp.c

示例11: nv_mlp_predict_label

int nv_mlp_predict_label(const nv_mlp_t *mlp, const nv_matrix_t *x, int xm)
{
	int m;
	int label = -1;
	float max_output = -FLT_MAX;
	nv_matrix_t *input_y = nv_matrix_alloc(mlp->input_w->m, 1);
	float dropout_scale = 1.0f - mlp->dropout;
	float noise_scale = 1.0f - mlp->noise;

#ifdef _OPENMP
#pragma omp parallel for
#endif
	for (m = 0; m < mlp->hidden; ++m) {
		float y = NV_MAT_V(mlp->input_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(x, xm, mlp->input_w, m) * noise_scale;
		NV_MAT_V(input_y, 0, m) = nv_mlp_sigmoid(y) * dropout_scale;
	}
	for (m = 0; m < mlp->output; ++m) {
		float y = NV_MAT_V(mlp->hidden_bias, m, 0) * NV_MLP_BIAS;
		y += nv_vector_dot(input_y, 0, mlp->hidden_w, m);
		if (max_output < y) {
			label = m;
			max_output = y;
		}
	}
	nv_matrix_free(&input_y);

	return label;
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:29,代码来源:nv_ml_mlp.c

示例12: nv_gaussian_predict

/* この関数は次元が高いと確率が小さくなりすぎて数値計算できないので
 * 次元が高い場合は, この関数値の対数であるnv_gaussian_log_predictを使うこと.
 */
float 
nv_gaussian_predict(const nv_cov_t *cov, const nv_matrix_t *x, int xm)
{
	int n;
	nv_matrix_t *y = nv_matrix_alloc(x->n, 2);
	float p = 1.0f;
	float d = (float)x->n;
	float delta2 = 0.0f;
	float lambda = 1.0f;

	nv_vector_sub(y, 0, x, xm, cov->u, 0);
	nv_matrix_mulv(y, 1, cov->eigen_vec, NV_MAT_TR, y, 0);
	for (n = 0; n < x->n; ++n) {
		float ev = NV_MAT_V(cov->eigen_val, n, 0);
		float xv = NV_MAT_V(y, 1, n);
		if (ev > 0.0f) {
			delta2 += (xv * xv) / ev;
			lambda *= sqrtf(ev);
		}
	}
	p = (1.0f / powf(2.0f * NV_PI, d / 2.0f)) * (1.0f / lambda) * expf(-0.5f * delta2);

	nv_matrix_free(&y);

	return p;
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:29,代码来源:nv_ml_gaussian.c

示例13: nv_matrix_sort

void
nv_matrix_sort(nv_matrix_t *mat, int sort_column_n, nv_sort_dir_e dir)
{
	nv_matrix_t *sort_data = nv_matrix_alloc(2, mat->m);
	nv_matrix_t *tmp = nv_matrix_alloc(mat->n, mat->m);
	int m;

	for (m = 0; m < mat->m; ++m) {
		NV_MAT_V(sort_data, m, 0) = NV_MAT_V(mat, m, sort_column_n);
		NV_MAT_V(sort_data, m, 1) = (float)m;
	}
	if (dir == NV_SORT_DIR_ASC) {
		qsort(sort_data->v, sort_data->m,
			sort_data->step * sizeof(float), nv_column_cmp_asc);
	} else {
		qsort(sort_data->v, sort_data->m,
			sort_data->step * sizeof(float), nv_column_cmp_desc);
	}
	for (m = 0; m < mat->m; ++m) {
		nv_vector_copy(tmp, m, mat, (int)NV_MAT_V(sort_data, m, 1));
	}
	nv_matrix_copy(mat, 0, tmp, 0, mat->m);

	nv_matrix_free(&sort_data);
	nv_matrix_free(&tmp);
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:26,代码来源:nv_core_matrix.c

示例14: nv_integral_tilted

/*
 * 45°回転したIntegral Image
 */
void 
nv_integral_tilted(nv_matrix_t *integral,
				   const nv_matrix_t *img, int channel)
{
	int row, col, scol, srow;
	int erow = img->rows + 1;
	int ecol = img->cols + 1;
	nv_matrix_t *prev_tilted = nv_matrix_alloc(img->cols + 1, 1);

	NV_ASSERT(
		integral->rows - 1 == img->rows 
		&& integral->cols - 1 == img->cols
	);

	nv_matrix_zero(prev_tilted);
	nv_matrix_zero(integral);

	for (scol = img->cols; scol > 0; --scol) {
		float tilted_sum = 0.0f;
		for (row = 1, col = scol; row < erow && col < ecol; ++row, ++col) {
			float tilted_val = NV_MAT3D_V(img, row - 1, col - 1, channel);
			if (col + 1 == ecol) {
				NV_MAT3D_V(integral, row, col, 0) = 
					NV_MAT3D_V(integral, row - 1, col, 0)
					+ tilted_sum + tilted_val;
			} else {
				NV_MAT3D_V(integral, row, col, 0) = 
					NV_MAT3D_V(integral, row - 1, col + 1, 0) 
					+ NV_MAT_V(prev_tilted, 0, col)
					+ tilted_sum + tilted_val;
			}
			tilted_sum += tilted_val;
			NV_MAT_V(prev_tilted, 0, col) = tilted_sum;
		}
	}
	for (srow = 2; srow < erow; ++srow) {
		float tilted_sum = 0.0f;
		for (row = srow, col = 1; row < erow && col < ecol; ++row, ++col) {
			float tilted_val = NV_MAT3D_V(img, row - 1, col - 1, channel);
			if (col + 1 == ecol) {
				NV_MAT3D_V(integral, row, col, 0) = 
					NV_MAT3D_V(integral, row - 1, col, 0)
					+ tilted_sum + tilted_val;
			} else {
				NV_MAT3D_V(integral, row, col, 0) = 
					NV_MAT3D_V(integral, row - 1, col + 1, 0) 
					+ NV_MAT_V(prev_tilted, 0, col)
					+ tilted_sum + tilted_val;
			}
			tilted_sum += tilted_val;
			NV_MAT_V(prev_tilted, 0, col) = tilted_sum;
		}
	}

	nv_matrix_free(&prev_tilted);
}
开发者ID:andrew950468,项目名称:otama_api,代码行数:59,代码来源:nv_ip_integral.c

示例15: nv_color_bgr2euclidean_scalar

void nv_color_bgr2euclidean_scalar(nv_matrix_t *ec, int ec_m, const nv_matrix_t *bgr, int bgr_m)
{
	assert(ec->n == bgr->n && ec->n == 3);
	NV_MAT_V(ec, ec_m, 0) = floorf((NV_MAT_V(bgr, bgr_m, NV_CH_R) + NV_MAT_V(bgr, bgr_m, NV_CH_G) + NV_MAT_V(bgr, bgr_m, NV_CH_B)) / 3.0f);
	NV_MAT_V(ec, ec_m, 1) = floorf((NV_MAT_V(bgr, bgr_m, NV_CH_R) + (255.0f - NV_MAT_V(bgr, bgr_m, NV_CH_B))) / 2.0f);
	NV_MAT_V(ec, ec_m, 2) = floorf((NV_MAT_V(bgr, bgr_m, NV_CH_R) + 2.0f * (255.0f - NV_MAT_V(bgr, bgr_m, NV_CH_G)) + NV_MAT_V(bgr, bgr_m, NV_CH_B)) / 4.0f);
}
开发者ID:nya3jp,项目名称:python-animeface,代码行数:7,代码来源:nv_euclidean_color.c


注:本文中的NV_MAT_V函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。