本文整理汇总了C++中arma::Col::memptr方法的典型用法代码示例。如果您正苦于以下问题:C++ Col::memptr方法的具体用法?C++ Col::memptr怎么用?C++ Col::memptr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::Col
的用法示例。
在下文中一共展示了Col::memptr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SortPointSet
size_t CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::
SortPointSet(arma::Col<size_t>& indices,
arma::vec& distances,
const size_t childFarSetSize,
const size_t childUsedSetSize,
const size_t farSetSize)
{
// We'll use low-level memcpy calls ourselves, just to ensure it's done
// quickly and the way we want it to be. Unfortunately this takes up more
// memory than one-element swaps, but there's not a great way around that.
const size_t bufferSize = std::min(farSetSize, childUsedSetSize);
const size_t bigCopySize = std::max(farSetSize, childUsedSetSize);
// Sanity check: there is no need to sort if the buffer size is going to be
// zero.
if (bufferSize == 0)
return (childFarSetSize + farSetSize);
size_t* indicesBuffer = new size_t[bufferSize];
ElemType* distancesBuffer = new ElemType[bufferSize];
// The start of the memory region to copy to the buffer.
const size_t bufferFromLocation = ((bufferSize == farSetSize) ?
(childFarSetSize + childUsedSetSize) : childFarSetSize);
// The start of the memory region to move directly to the new place.
const size_t directFromLocation = ((bufferSize == farSetSize) ?
childFarSetSize : (childFarSetSize + childUsedSetSize));
// The destination to copy the buffer back to.
const size_t bufferToLocation = ((bufferSize == farSetSize) ?
childFarSetSize : (childFarSetSize + farSetSize));
// The destination of the directly moved memory region.
const size_t directToLocation = ((bufferSize == farSetSize) ?
(childFarSetSize + farSetSize) : childFarSetSize);
// Copy the smaller piece to the buffer.
memcpy(indicesBuffer, indices.memptr() + bufferFromLocation,
sizeof(size_t) * bufferSize);
memcpy(distancesBuffer, distances.memptr() + bufferFromLocation,
sizeof(ElemType) * bufferSize);
// Now move the other memory.
memmove(indices.memptr() + directToLocation,
indices.memptr() + directFromLocation, sizeof(size_t) * bigCopySize);
memmove(distances.memptr() + directToLocation,
distances.memptr() + directFromLocation, sizeof(ElemType) * bigCopySize);
// Now copy the temporary memory to the right place.
memcpy(indices.memptr() + bufferToLocation, indicesBuffer,
sizeof(size_t) * bufferSize);
memcpy(distances.memptr() + bufferToLocation, distancesBuffer,
sizeof(ElemType) * bufferSize);
delete[] indicesBuffer;
delete[] distancesBuffer;
// This returns the complete size of the far set.
return (childFarSetSize + farSetSize);
}
示例2: TrilinosVector
Teuchos::RCP<Thyra::DefaultSpmdVector<ValueType> >
wrapInTrilinosVector(arma::Col<ValueType>& col)
{
size_t size = col.n_rows;
Teuchos::ArrayRCP<ValueType> trilinosArray =
Teuchos::arcp(col.memptr(), 0 /* lowerOffset */,
size, false /* doesn't own memory */);
typedef Thyra::DefaultSpmdVector<ValueType> TrilinosVector;
return Teuchos::RCP<TrilinosVector>(new TrilinosVector(
Thyra::defaultSpmdVectorSpace<ValueType>(size),
trilinosArray, 1 /* stride */));
}