Esempio n. 1
0
void write_supertensor_index(const string& name, const vector<Ref<const supertensor_reader_t>>& readers) {
  // Check consistency
  GEODE_ASSERT(readers.size());
  const uint32_t slice = readers[0]->header.stones;
  const auto sections = descendent_sections(section_t(),slice).at(slice);
  GEODE_ASSERT(sections->slice==int(slice));
  Hashtable<section_t,Ref<const supertensor_reader_t>> section_reader;
  for (const auto reader : readers) {
    GEODE_ASSERT(int(reader->header.filter)==filter);
    section_reader.set(reader->header.section,reader);
  }
  for (const auto section : sections->sections)
    GEODE_ASSERT(section_reader.contains(section));

  // Write index
  FILE* file = fopen(name.c_str(),"wb");
  if (!file)
    throw IOError(format("write_supertensor_index: can't open '%s' for writing",name));
  fwrite("pentago index      \n",1,20,file);
  fwrite(&slice,sizeof(uint32_t),1,file);
  GEODE_ASSERT(ftell(file)==24);
  for (const auto section : sections->sections) {
    const auto reader = section_reader.get(section);
    Array<compact_blob_t> blobs(reader->offset.flat.size(),uninit);
    for (const int i : range(blobs.size())) {
      const uint64_t offset = reader->offset.flat[i];
      blobs[i].set_offset(offset);
      blobs[i].size = reader->compressed_size_.flat[i];
    }
    fwrite(blobs.data(),sizeof(compact_blob_t),blobs.size(),file);
  }
  const auto index = new_<supertensor_index_t>(sections);
  GEODE_ASSERT(uint64_t(ftell(file))==index->section_offset.back());
  fclose(file);
}
Esempio n. 2
0
	reader::section_t reader::profile::section(function_id id)
	{
		for (auto&& f: ref.items())
		{
			for (auto&& s: f.items())
			{
				if (s.id() == id)
					return section_t(s);
			}
		}
		throw bad_section(id);
	}
Esempio n. 3
0
supertensor_index_t::supertensor_index_t(const sections_t& sections)
  : sections(ref(sections))
  , section_offset(make_offsets(sections)) {
  // Make sure we have a complete slice
  GEODE_ASSERT(descendent_sections(section_t(),sections.slice).at(sections.slice)->sections==sections.sections);
}
Esempio n. 4
0
	reader::section_t reader::function_t::section(const std::string& name, function_id id)
	{
		return section_t(add_section(ref, name, id));
	}