Macaulay2 Engine
Loading...
Searching...
No Matches

◆ safeDenseToSparse()

template<typename RingType>
template<typename LockType>
void ConcreteVectorArithmetic< RingType >::safeDenseToSparse ( ElementArray & dense,
ElementArray & sparse,
Range< int > & comps,
int first,
int last,
MemoryBlock & monomialSpace,
LockType & lock ) const
inline

Definition at line 320 of file VectorArithmetic.hpp.

327 {
328 auto& dvec = * elementArray(dense);
329
330 int len = 0;
331
332 // first can be -1 if the row is zero. in this case, we should
333 // not be accessing dense[i] for i negative.
334 for (int i = first; i >= 0 and i <= last; i++)
335 if (not mRing->is_zero(dvec[i])) len++;
336
337 comps = monomialSpace.safeAllocateArray<int,LockType>(len,lock);
340 auto& svec = * elementArray(sparse);
341
342 int next = 0;
343 for (int i = first; i >= 0 and i <= last; i++)
344 if (not mRing->is_zero(dvec[i]))
345 {
346 mRing->set(svec[next],dvec[i]);
347 comps[next] = i;
348 ++next;
349 mRing->set_zero(dvec[i]);
350 }
351 }
void deallocateElementArray(ElementArray &coeffs) const
ElementArrayContainer * elementArray(const ElementArray &f) const
ElementArray allocateElementArray() const

References allocateElementArray(), deallocateElementArray(), dvec(), elementArray(), mRing, and MemoryBlock::safeAllocateArray().

Referenced by denseToSparse().