Skip to content

Commit

Permalink
Refactored Consolidator towards addressing #93
Browse files Browse the repository at this point in the history
  • Loading branch information
stavrospapadopoulos committed Feb 21, 2020
1 parent abb7dbd commit e000f49
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 532 deletions.
5 changes: 2 additions & 3 deletions test/src/unit-capi-consolidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ bool ConsolidationFx::is_array(const std::string& array_name) {
TEST_CASE_METHOD(
ConsolidationFx,
"C API: Test consolidation, dense",
"[capi], [consolidation], [dense-consolidation]") {
"[capi][consolidation][dense-consolidation]") {
remove_dense_array();
create_dense_array();

Expand Down Expand Up @@ -2933,8 +2933,7 @@ TEST_CASE_METHOD(
TEST_CASE_METHOD(
ConsolidationFx,
"C API: Test advanced consolidation #1",
"[capi], [consolidation], [consolidation-adv], "
"[consolidation-adv-1]") {
"[capi][consolidation][adv-1]") {
remove_dense_vector();
create_dense_vector();
write_dense_vector_4_fragments();
Expand Down
78 changes: 78 additions & 0 deletions tiledb/sm/array_schema/dimension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Dimension::Dimension() {
type_ = Datatype::INT32;
set_compute_mbr_func();
set_crop_range_func();
set_domain_range_func();
set_expand_range_func();
set_expand_range_v_func();
set_expand_to_tile_func();
Expand All @@ -71,6 +72,7 @@ Dimension::Dimension(const std::string& name, Datatype type)
tile_extent_ = nullptr;
set_compute_mbr_func();
set_crop_range_func();
set_domain_range_func();
set_expand_range_func();
set_expand_range_v_func();
set_expand_to_tile_func();
Expand Down Expand Up @@ -218,6 +220,7 @@ Status Dimension::deserialize(ConstBuffer* buff, Datatype type) {

set_compute_mbr_func();
set_crop_range_func();
set_domain_range_func();
set_expand_range_func();
set_expand_range_v_func();
set_expand_to_tile_func();
Expand Down Expand Up @@ -302,9 +305,31 @@ void Dimension::crop_range(Range* range) const {
crop_range_func_(this, range);
}

template <class T>
uint64_t Dimension::domain_range(const Range& range) {
assert(!range.empty());

if (&typeid(T) == &typeid(float) || &typeid(T) == &typeid(double))
return 0;

auto r = (const T*)range.data();
uint64_t ret = r[1] - r[0];
if (ret == std::numeric_limits<uint64_t>::max()) // overflow
return 0;
++ret;

return ret;
}

uint64_t Dimension::domain_range(const Range& range) const {
assert(domain_range_func_ != nullptr);
return domain_range_func_(range);
}

template <class T>
void Dimension::expand_range_v(const void* v, Range* r) {
assert(v != nullptr);
assert(r != nullptr);
assert(!r->empty());
auto rt = (const T*)r->data();
auto vt = (const T*)v;
Expand Down Expand Up @@ -870,6 +895,59 @@ void Dimension::set_crop_range_func() {
}
}

void Dimension::set_domain_range_func() {
switch (type_) {
case Datatype::INT32:
domain_range_func_ = domain_range<int32_t>;
break;
case Datatype::INT64:
domain_range_func_ = domain_range<int64_t>;
break;
case Datatype::INT8:
domain_range_func_ = domain_range<int8_t>;
break;
case Datatype::UINT8:
domain_range_func_ = domain_range<uint8_t>;
break;
case Datatype::INT16:
domain_range_func_ = domain_range<int16_t>;
break;
case Datatype::UINT16:
domain_range_func_ = domain_range<uint16_t>;
break;
case Datatype::UINT32:
domain_range_func_ = domain_range<uint32_t>;
break;
case Datatype::UINT64:
domain_range_func_ = domain_range<uint64_t>;
break;
case Datatype::FLOAT32:
domain_range_func_ = domain_range<float>;
break;
case Datatype::FLOAT64:
domain_range_func_ = domain_range<double>;
break;
case Datatype::DATETIME_YEAR:
case Datatype::DATETIME_MONTH:
case Datatype::DATETIME_WEEK:
case Datatype::DATETIME_DAY:
case Datatype::DATETIME_HR:
case Datatype::DATETIME_MIN:
case Datatype::DATETIME_SEC:
case Datatype::DATETIME_MS:
case Datatype::DATETIME_US:
case Datatype::DATETIME_NS:
case Datatype::DATETIME_PS:
case Datatype::DATETIME_FS:
case Datatype::DATETIME_AS:
domain_range_func_ = domain_range<int64_t>;
break;
default:
domain_range_func_ = nullptr;
break;
}
}

void Dimension::set_compute_mbr_func() {
switch (type_) {
case Datatype::INT32:
Expand Down
24 changes: 24 additions & 0 deletions tiledb/sm/array_schema/dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ class Dimension {
template <class T>
static void crop_range(const Dimension* dim, Range* range);

/**
* Returns the domain range (high - low + 1) of the input
* 1D range. It returns 0 in case the dimension datatype
* is not integer or if there is an overflow.
*/
uint64_t domain_range(const Range& range) const;

/**
* Returns the domain range (high - low + 1) of the input
* 1D range. It returns 0 in case the dimension datatype
* is not integer or if there is an overflow.
*/
template <class T>
static uint64_t domain_range(const Range& range);

/** Expand 1D range `r` using value `v`. */
void expand_range_v(const void* v, Range* r) const;

Expand Down Expand Up @@ -297,6 +312,12 @@ class Dimension {
*/
std::function<void(const Dimension* dim, Range*)> crop_range_func_;

/**
* Stores the appropriate templated crop_range() function based on the
* dimension datatype.
*/
std::function<uint64_t(const Range&)> domain_range_func_;

/**
* Stores the appropriate templated expand_range() function based on the
* dimension datatype.
Expand Down Expand Up @@ -439,6 +460,9 @@ class Dimension {
/** Sets the templated crop_range() function. */
void set_crop_range_func();

/** Sets the templated domain_range() function. */
void set_domain_range_func();

/** Sets the templated expand_range() function. */
void set_expand_range_func();

Expand Down
64 changes: 18 additions & 46 deletions tiledb/sm/array_schema/domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,52 +619,6 @@ void Domain::expand_to_tiles(NDRange* ndrange) const {
dimensions_[d]->expand_to_tile(&(*ndrange)[d]);
}

void Domain::expand_domain(void* domain) const {
switch (type_) {
case Datatype::INT32:
expand_domain<int>(static_cast<int*>(domain));
break;
case Datatype::INT64:
expand_domain<int64_t>(static_cast<int64_t*>(domain));
break;
case Datatype::INT8:
expand_domain<int8_t>(static_cast<int8_t*>(domain));
break;
case Datatype::UINT8:
expand_domain<uint8_t>(static_cast<uint8_t*>(domain));
break;
case Datatype::INT16:
expand_domain<int16_t>(static_cast<int16_t*>(domain));
break;
case Datatype::UINT16:
expand_domain<uint16_t>(static_cast<uint16_t*>(domain));
break;
case Datatype::UINT32:
expand_domain<uint32_t>(static_cast<uint32_t*>(domain));
break;
case Datatype::UINT64:
expand_domain<uint64_t>(static_cast<uint64_t*>(domain));
break;
case Datatype::DATETIME_YEAR:
case Datatype::DATETIME_MONTH:
case Datatype::DATETIME_WEEK:
case Datatype::DATETIME_DAY:
case Datatype::DATETIME_HR:
case Datatype::DATETIME_MIN:
case Datatype::DATETIME_SEC:
case Datatype::DATETIME_MS:
case Datatype::DATETIME_US:
case Datatype::DATETIME_NS:
case Datatype::DATETIME_PS:
case Datatype::DATETIME_FS:
case Datatype::DATETIME_AS:
expand_domain<int64_t>(static_cast<int64_t*>(domain));
break;
default: // Non-applicable to non-integer domains
break;
}
}

template <class T>
void Domain::get_tile_coords(const T* coords, T* tile_coords) const {
auto domain = (T*)domain_;
Expand Down Expand Up @@ -931,6 +885,24 @@ uint64_t Domain::tile_num(const NDRange& ndrange) const {
return ret;
}

uint64_t Domain::cell_num(const NDRange& ndrange) const {
assert(!ndrange.empty());

uint64_t cell_num = 1, range, prod;
for (unsigned d = 0; d < dim_num_; ++d) {
range = dimensions_[d]->domain_range(ndrange[d]);
if (range == 0) // Real dimension domain or overflow
return 0;

prod = range * cell_num;
if (prod / range != cell_num) // Overflow
return 0;
cell_num = prod;
}

return cell_num;
}

bool Domain::covered(const NDRange& r1, const NDRange& r2) const {
assert(r1.size() == dim_num_);
assert(r2.size() == dim_num_);
Expand Down
59 changes: 8 additions & 51 deletions tiledb/sm/array_schema/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,57 +311,6 @@ class Domain {
*/
void expand_to_tiles(NDRange* ndrange) const;

/**
* Expands the input domain such that it coincides with the boundaries of
* the array's regular tiles (i.e., it maps it on the regular tile grid).
* If the array has no regular tile grid, the function does not do anything.
*
* @param domain The domain to be expanded.
* @return void
*/
void expand_domain(void* domain) const;

/**
* Expands the input domain such that it coincides with the boundaries of
* the array's regular tiles (i.e., it maps it on the regular tile grid).
* If the array has no regular tile grid, the function does not do anything.
*
* @tparam The domain type.
* @param domain The domain to be expanded.
* @return void
*/
template <
class T,
typename std::enable_if<std::is_integral<T>::value, T>::type* = nullptr>
void expand_domain(T* domain) const {
// Applicable only to regular tiles
if (tile_extents_ == nullptr)
return;

auto tile_extents = static_cast<const T*>(tile_extents_);
auto array_domain = static_cast<const T*>(domain_);

for (unsigned int i = 0; i < dim_num_; ++i) {
// This will always make the first bound coincide with a tile
domain[2 * i] = ((domain[2 * i] - array_domain[2 * i]) / tile_extents[i] *
tile_extents[i]) +
array_domain[2 * i];

domain[2 * i + 1] =
((domain[2 * i + 1] - array_domain[2 * i]) / tile_extents[i] + 1) *
tile_extents[i] -
1 + array_domain[2 * i];
}
}

/** No-op for float/double domains. */
template <
class T,
typename std::enable_if<!std::is_integral<T>::value, T>::type* = nullptr>
void expand_domain(T* domain) const {
(void)domain;
}

/**
* Returns the position of the input coordinates inside its corresponding
* tile, based on the array cell order. Applicable only to **dense** arrays.
Expand Down Expand Up @@ -589,6 +538,14 @@ class Domain {
*/
uint64_t tile_num(const NDRange& ndrange) const;

/**
* Returns the number of cells in the input range.
* If there is an overflow, then the function returns 0.
* If at least one dimension had a non-integer domain, the
* functuon returns 0.
*/
uint64_t cell_num(const NDRange& ndrange) const;

/** Returns true if r1 is fully covered by r2. */
bool covered(const NDRange& r1, const NDRange& r2) const;

Expand Down
Loading

0 comments on commit e000f49

Please sign in to comment.