void Metadata::setInputSpatialLocations()

in sparseconvnet/SCN/Metadata/Metadata.cpp [101:147]


void Metadata<dimension>::setInputSpatialLocations(
    /*float*/ at::Tensor &features,
    /*long*/ at::Tensor &locations,
    /*float*/ at::Tensor &vecs, bool overwrite) {
  /* assert(locations.ndimension() == 2 and "locations must be 2
   * dimensional!"); */
  /* assert(vecs.ndimension() == 2 and "vecs must be 2 dimensional!"); */
  /* assert(locations.size(0) == vecs.size(0) and */
  /*        "Location.size(0) and vecs.size(0) must be equal!"); */
  /* assert((locations.size(1) == dimension or */
  /*         locations.size(1) == 1 + dimension) and */
  /*        "locations.size(0) must be either dimension or dimension+1"); */
  Point<dimension> p;
  Int &nActive = *inputNActive;
  auto nPlanes = vecs.size(1);
  long *l = locations.data_ptr<long>();
  float *v = vecs.data_ptr<float>();

  if (locations.size(1) == dimension) {
    // add points to current sample
    assert(inputSG);
    SparseGridMap<dimension> &mp = inputSG->mp;
    for (Int idx = 0; idx < locations.size(0); ++idx) {
      for (Int d = 0; d < dimension; ++d)
        p[d] = *l++;
      addPointToSparseGridMapAndFeatures<dimension>(mp, p, nActive, nPlanes,
                                                    features, v, overwrite);
      v += nPlanes;
    }
  }
  if (locations.size(1) == dimension + 1) {
    // add new samples to batch as necessary
    auto &SGs = *inputSGs;
    for (Int idx = 0; idx < locations.size(0); ++idx) {
      for (Int d = 0; d < dimension; ++d)
        p[d] = *l++;
      Int batch = *l++;
      if (batch >= (Int)SGs.size()) {
        SGs.resize(batch + 1);
      }
      SparseGridMap<dimension> &mp = SGs[batch].mp;
      addPointToSparseGridMapAndFeatures<dimension>(mp, p, nActive, nPlanes,
                                                    features, v, overwrite);
      v += nPlanes;
    }
  }
}