Example #1
0
template<class TV> void SparseMatrix::
multiply_helper(RawArray<const TV> x,RawArray<TV> result) const
{
    const int rows = this->rows();
    GEODE_ASSERT(columns()<=x.size() && rows<=result.size());
    RawArray<const int> offsets = J.offsets;
    RawArray<const int> J_flat = J.flat;
    RawArray<const T> A_flat = A.flat;
    for(int i=0;i<rows;i++){
        int end=offsets[i+1];TV sum=TV();
        for(int index=offsets[i];index<end;index++) sum+=A_flat[index]*x[J_flat[index]];
        result[i]=sum;}
    result.slice(rows,result.size()).zero();
}
Example #2
0
static void spatial_sort(RawArray<Perturbed2> X, const int leaf_size, Random& random) {
  const int n = X.size();
  if (n<=leaf_size)
    return;

  // We determine the subdivision axis using inexact computation, which is okay since neither the result nor
  // the asymptotic worst case complexity depends upon any properties of the spatial_sort whatsoever.
  const Box<EV> box = bounding_box(X.project<EV,&Perturbed2::value_>());
  const int axis = box.sizes().argmax();

  // We use exact arithmetic to perform the partition, which is important in case many points are coincident
  const int mid = axis==0 ? spatial_partition<0>(X,random)
                          : spatial_partition<1>(X,random);

  // Recursely sort both halves
  spatial_sort(X.slice(0,mid),leaf_size,random);
  spatial_sort(X.slice(mid,n),leaf_size,random);
}
Example #3
0
static inline RawArray<mp_limb_t> sqrt_helper(RawArray<mp_limb_t> result, RawArray<const mp_limb_t> x) {
  const auto s = result.slice(0,(1+x.size())/2);
  mpn_sqrtrem(s.data(),0,x.data(),x.size());
  return trim(s);
}