2020-12-13

这是我的项目老师布置给我的代码优化题目,但对于一个初学c语言不到三个月的小白来说着实有点困难,所以求大佬帮助。
int ScaC_DSPF_sp_sort_singular_values(const int Nrows, const int Ncols, double *U, double *V, double *singular_values)
{
int i, j, row, max_index;
double temp;

// 用选择法实现奇异值从大到小排序, U的列和V的行也跟着改变顺序.
for (i = 0; i < Ncols - 1; i++)
{
	max_index = i;
	for (j = i + 1; j < Ncols; j++)
	{
		if (singular_values[j] > singular_values[max_index])
		{
			max_index = j;
		}
	}
	if (max_index != i)
	{
		temp = singular_values[i];
		singular_values[i] = singular_values[max_index];
		singular_values[max_index] = temp;

#ifndef ENABLE_REDUCED_FORM_CN
for (row = 0; row < Nrows; row++)
{ // 交换列
temp = U[max_index + row * Nrows];
U[max_index + row * Nrows] = U[i + row * Nrows];
U[i + row * Nrows] = temp;
}
#else
for (row = 0; row < Nrows; row++)
{
temp = U[max_index + row * Ncols];
U[max_index + row * Ncols] = U[i + row * Ncols];
U[i + row * Ncols] = temp;
}
#endif
for (row = 0; row < Ncols; row++)
{ // 交换列
temp = V[max_index + row * Ncols];
V[max_index + row * Ncols] = V[i + row * Ncols];
V[i + row * Ncols] = temp;
}
}
}

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值