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


C++ SparseVector::cbegin方法代码示例

本文整理汇总了C++中SparseVector::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseVector::cbegin方法的具体用法?C++ SparseVector::cbegin怎么用?C++ SparseVector::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SparseVector的用法示例。


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

示例1: incompleteLDLTDecomposition

	void InLDLTPreconditioner::incompleteLDLTDecomposition(const BlockedSymSpMatrix& mat){
		int columnCount = mat.getNumColumns();
		MemoryPool<InvMatRowListNode, std::alignment_of<InvMatRowListNode>::value> nodePool(columnCount);
		InvMatRowListNode *listPerRow = new InvMatRowListNode[columnCount];
		std::vector<InvMatRowListNode *> *invRowNodes = new std::vector<InvMatRowListNode *>[columnCount];

		//work space
		FastSparseVector vec(columnCount);
		FastSparseVector lowerColumn(columnCount);
		SparseVector invColumn;
		invColumn.Reserve(32);

		constexpr int preAlloced = 32;
		for (int i = 0; i < columnCount; i++) {
			InvMatRowListNode *node = nodePool.Alloc();
			node->row = i;  node->col = i; node->value = 1.0;
			listPerRow[i].prev = node;
			listPerRow[i].next = node;
			node->prev = &listPerRow[i];
			node->next = &listPerRow[i];

			invRowNodes[i].reserve(std::min(i + 1, preAlloced));
			invRowNodes[i].push_back(node);
		}

		int count = 0;
		pcol.push_back(0);
		for (int i = 0; i < columnCount - 1; i++){
			for (auto node : invRowNodes[i]) {
				invColumn.emplaceBack(node->row, node->value);
				node->prev->next = node->next;
			    node->next->prev = node->prev;
				nodePool.Dealloc(node);
			}
			invRowNodes[i].clear();
			invRowNodes[i].shrink_to_fit();

			SpMSV(mat, matFullIndices, invColumn, vec);
			Scalar diag =  vec * invColumn;
			Scalar inv = Scalar(1.0) / diag;
			invDiagonal[i] = inv;

			for (auto iter = vec.cbegin(); iter != vec.cend(); ++iter) {
				int index = *iter.indexIterator;
				Scalar value = *iter.valueIterator;
				if (value != 0) {
					InvMatRowListNode *node = listPerRow[index].next;
					InvMatRowListNode *end = &listPerRow[index];
					while (node != end) {
						lowerColumn.Add(node->col, value * node->value);
						node = node->next;
					}
				}
			}

			for (auto iter = lowerColumn.cbegin(); iter != lowerColumn.cend(); ++iter) {
				int j = *iter.indexIterator;
				Scalar lower = (*iter.valueIterator) * inv;
				if (fabs(lower) > ldltEpsilon){
					values.push_back(lower);
					rows.push_back(j);
					++count;
				}
			}
			pcol.push_back(count);

			vec.Clear();
			for (auto iter = lowerColumn.cbegin(); iter != lowerColumn.cend(); ++iter) {
				int j = *iter.indexIterator;
				Scalar factor = *iter.valueIterator;
				if (factor != 0) {
					factor *= inv;
					//copy invRowNodes[j] and clean node
					for (auto node : invRowNodes[j]) {
						vec.emplaceBack(node->row, node->value);
						node->prev->next = node->next;
						node->next->prev = node->prev;
						nodePool.Dealloc(node);
					}
					invRowNodes[j].clear();

					for (auto iter = invColumn.cbegin(); iter != invColumn.cend(); ++iter)
						vec.Add(*(iter.indexIterator), -factor * (*(iter.valueIterator)));

					//drop invRowNodes[j]
					for (auto iter = vec.cbegin(); iter != vec.cend(); ++iter) {
						int index = *iter.indexIterator;
						Scalar val = *iter.valueIterator;
						if (fabs(val) > sainvEpsilon) {
							//insert to linked list
							InvMatRowListNode *node = nodePool.Alloc();
							node->row = index; node->col = j; node->value = val;

							node->next = listPerRow[index].next;
							node->prev = &listPerRow[index];
							listPerRow[index].next->prev = node;
							listPerRow[index].next = node;
							invRowNodes[j].push_back(node);
						}
					}
//.........这里部分代码省略.........
开发者ID:OpenDeformerDev,项目名称:OpenDeformer,代码行数:101,代码来源:inLDLTPreconditioner.cpp


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