Skip to content

Commit

Permalink
Make get_column_extents an independent file away from context_common
Browse files Browse the repository at this point in the history
  • Loading branch information
sc1f committed Mar 6, 2019
1 parent b58e2c1 commit 23bd8cb
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ set (SOURCE_FILES
src/cpp/context_zero.cpp
src/cpp/custom_column.cpp
src/cpp/data_slice.cpp
src/cpp/date.cpp
src/cpp/data.cpp
src/cpp/date.cpp
src/cpp/dense_nodes.cpp
Expand All @@ -296,6 +295,7 @@ set (SOURCE_FILES
src/cpp/extract_aggregate.cpp
src/cpp/filter.cpp
src/cpp/flat_traversal.cpp
src/cpp/get_data_extents.cpp
src/cpp/gnode.cpp
src/cpp/gnode_state.cpp
src/cpp/histogram.cpp
Expand Down
8 changes: 5 additions & 3 deletions cpp/perspective/src/cpp/context_grouped_pkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

#include <perspective/first.h>
#include <perspective/context_common.h>
#include <perspective/get_data_extents.h>
#include <perspective/context_grouped_pkey.h>
#include <perspective/extract_aggregate.h>
#include <perspective/filter.h>
Expand Down Expand Up @@ -113,11 +113,13 @@ t_ctx_grouped_pkey::get_data(
t_index start_row, t_index end_row, t_index start_col, t_index end_col) const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
auto ext = sanitize_get_data_extents(*this, start_row, end_row, start_col, end_col);
t_uindex ctx_nrows = get_row_count();
t_uindex ncols = get_column_count();
auto ext
= sanitize_get_data_extents(ctx_nrows, ncols, start_row, end_row, start_col, end_col);

t_index nrows = ext.m_erow - ext.m_srow;
t_index stride = ext.m_ecol - ext.m_scol;
t_uindex ncols = get_column_count();
std::vector<t_tscalar> values(nrows * stride);
std::vector<t_tscalar> tmpvalues(nrows * ncols);

Expand Down
8 changes: 5 additions & 3 deletions cpp/perspective/src/cpp/context_one.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <perspective/first.h>
#include <perspective/sort_specification.h>
#include <perspective/context_common.h>
#include <perspective/get_data_extents.h>
#include <perspective/context_one.h>
#include <perspective/extract_aggregate.h>
#include <perspective/filter.h>
Expand Down Expand Up @@ -103,12 +103,14 @@ std::vector<t_tscalar>
t_ctx1::get_data(t_index start_row, t_index end_row, t_index start_col, t_index end_col) const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
auto ext = sanitize_get_data_extents(*this, start_row, end_row, start_col, end_col);
t_uindex ctx_nrows = get_row_count();
t_uindex ncols = get_column_count();
auto ext
= sanitize_get_data_extents(ctx_nrows, ncols, start_row, end_row, start_col, end_col);

t_index nrows = ext.m_erow - ext.m_srow;
t_index stride = ext.m_ecol - ext.m_scol;

t_uindex ncols = get_column_count();
std::vector<t_tscalar> tmpvalues(nrows * ncols);
std::vector<t_tscalar> values(nrows * stride);

Expand Down
12 changes: 9 additions & 3 deletions cpp/perspective/src/cpp/context_two.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

#include <perspective/first.h>
#include <perspective/context_common.h>
#include <perspective/get_data_extents.h>
#include <perspective/context_two.h>
#include <perspective/extract_aggregate.h>
#include <perspective/sparse_tree.h>
Expand Down Expand Up @@ -194,7 +194,10 @@ t_ctx2::get_ctraversal_indices() const {

std::vector<t_tscalar>
t_ctx2::get_data(t_index start_row, t_index end_row, t_index start_col, t_index end_col) const {
auto ext = sanitize_get_data_extents(*this, start_row, end_row, start_col, end_col);
t_uindex ctx_nrows = get_row_count();
t_uindex ctx_ncols = get_column_count();
auto ext = sanitize_get_data_extents(
ctx_nrows, ctx_ncols, start_row, end_row, start_col, end_col);

std::vector<std::pair<t_uindex, t_uindex>> cells;
for (t_index ridx = ext.m_srow; ridx < ext.m_erow; ++ridx) {
Expand Down Expand Up @@ -615,7 +618,10 @@ t_ctx2::get_step_delta(t_index bidx, t_index eidx) {
rval.columns_changed = true;
std::vector<t_cellupd>& updvec = rval.cells;

auto ext = sanitize_get_data_extents(*this, start_row, end_row, start_col, end_col);
t_uindex ctx_nrows = get_row_count();
t_uindex ctx_ncols = get_column_count();
auto ext = sanitize_get_data_extents(
ctx_nrows, ctx_ncols, start_row, end_row, start_col, end_col);

std::vector<std::pair<t_uindex, t_uindex>> cells;

Expand Down
8 changes: 5 additions & 3 deletions cpp/perspective/src/cpp/context_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <perspective/first.h>
#include <perspective/context_base.h>
#include <perspective/context_common.h>
#include <perspective/get_data_extents.h>
#include <perspective/context_zero.h>
#include <perspective/flat_traversal.h>
#include <perspective/sym_table.h>
Expand Down Expand Up @@ -98,8 +98,10 @@ t_ctx0::get_column_count() const {

std::vector<t_tscalar>
t_ctx0::get_data(t_index start_row, t_index end_row, t_index start_col, t_index end_col) const {

auto ext = sanitize_get_data_extents(*this, start_row, end_row, start_col, end_col);
t_uindex ctx_nrows = get_row_count();
t_uindex ctx_ncols = get_column_count();
auto ext = sanitize_get_data_extents(
ctx_nrows, ctx_ncols, start_row, end_row, start_col, end_col);

t_index nrows = ext.m_erow - ext.m_srow;
t_index stride = ext.m_ecol - ext.m_scol;
Expand Down
42 changes: 37 additions & 5 deletions cpp/perspective/src/cpp/data_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@
namespace perspective {

template <typename CTX_T>
t_data_slice<CTX_T>::t_data_slice(std::shared_ptr<CTX_T> ctx,
t_data_slice<CTX_T>::t_data_slice(std::shared_ptr<CTX_T> ctx, t_uindex start_row,
t_uindex end_row, t_uindex start_col, t_uindex end_col,
std::shared_ptr<std::vector<t_tscalar>> slice,
std::shared_ptr<std::vector<std::string>> column_names)
: m_ctx(ctx)
, m_start_row(start_row)
, m_end_row(end_row)
, m_start_col(start_col)
, m_end_col(end_col)
, m_slice(slice)
, m_column_names(column_names) {}

template <typename CTX_T>
t_data_slice<CTX_T>::t_data_slice(std::shared_ptr<CTX_T> ctx,
t_data_slice<CTX_T>::t_data_slice(std::shared_ptr<CTX_T> ctx, t_uindex start_row,
t_uindex end_row, t_uindex start_col, t_uindex end_col,
std::shared_ptr<std::vector<t_tscalar>> slice,
std::shared_ptr<std::vector<std::string>> column_names,
std::shared_ptr<std::vector<t_uindex>> column_indices)
: m_ctx(ctx)
, m_start_row(start_row)
, m_end_row(end_row)
, m_start_col(start_col)
, m_end_col(end_col)
, m_slice(slice)
, m_column_names(column_names)
, m_column_indices(column_indices) {}
Expand All @@ -45,28 +55,40 @@ t_data_slice<CTX_T>::~t_data_slice() {}
*/
template <>
t_tscalar
t_data_slice<t_ctx0>::get(t_uindex ridx, t_uindex col) {
t_data_slice<t_ctx0>::get(t_uindex ridx, t_uindex col) const {
t_tscalar rv;
rv.clear();
return rv;
}

template <>
t_tscalar
t_data_slice<t_ctx1>::get(t_uindex ridx, t_uindex cidx) {
t_data_slice<t_ctx1>::get(t_uindex ridx, t_uindex cidx) const {
t_tscalar rv;
rv.clear();
return rv;
}

template <>
t_tscalar
t_data_slice<t_ctx2>::get(t_uindex ridx, t_uindex cidx) {
t_data_slice<t_ctx2>::get(t_uindex ridx, t_uindex cidx) const {
t_tscalar rv;
rv.clear();
return rv;
}

template <>
std::vector<t_tscalar>
t_data_slice<t_ctx0>::get_row_path(t_uindex idx) const {
return std::vector<t_tscalar>();
}

template <typename CTX_T>
std::vector<t_tscalar>
t_data_slice<CTX_T>::get_row_path(t_uindex idx) const {
return m_ctx->unity_get_row_path(idx);
}

// Getters
template <typename CTX_T>
std::shared_ptr<CTX_T>
Expand Down Expand Up @@ -105,6 +127,16 @@ t_data_slice<t_ctx0>::is_column_only() const {
return false;
}

template <typename CTX_T>
t_get_data_extents
t_data_slice<CTX_T>::get_data_extents() const {
auto nrows = m_ctx->get_row_count();
auto ncols = m_ctx->get_column_count();
t_get_data_extents ext = sanitize_get_data_extents(
nrows, ncols, m_start_row, m_end_row, m_start_col, m_end_col);
return ext;
}

// Explicitly instantiate data slice for each context
template class t_data_slice<t_ctx0>;
template class t_data_slice<t_ctx1>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,15 @@
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

#pragma once

#include <perspective/first.h>
#include <perspective/raw_types.h>
#include <perspective/get_data_extents.h>

namespace perspective {

struct t_get_data_extents {
t_index m_srow;
t_index m_erow;
t_index m_scol;
t_index m_ecol;
};

template <typename CONTEXT_T>
t_get_data_extents
sanitize_get_data_extents(const CONTEXT_T& ctx, t_index start_row, t_index end_row,
sanitize_get_data_extents(t_index nrows, t_index ncols, t_index start_row, t_index end_row,
t_index start_col, t_index end_col) {
t_index ncols = ctx.get_column_count();

start_row = std::min(start_row, ctx.get_row_count());
end_row = std::min(end_row, ctx.get_row_count());
start_row = std::min(start_row, nrows);
end_row = std::min(end_row, nrows);

start_row = std::max(t_index(0), start_row);
end_row = std::max(t_index(0), end_row);
Expand Down
6 changes: 4 additions & 2 deletions cpp/perspective/src/cpp/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ View<CTX_T>::get_data(std::uint32_t start_row, std::uint32_t end_row, std::uint3
auto slice_ptr = std::make_shared<std::vector<t_tscalar>>(
m_ctx->get_data(start_row, end_row, start_col, end_col));
auto names_ptr = std::make_shared<std::vector<std::string>>(_column_names());
auto data_slice = t_data_slice<CTX_T>(m_ctx, slice_ptr, names_ptr);
auto data_slice = t_data_slice<CTX_T>(
m_ctx, start_row, end_row, start_col, end_col, slice_ptr, names_ptr);
return data_slice;
}

Expand Down Expand Up @@ -336,7 +337,8 @@ View<t_ctx2>::get_data(std::uint32_t start_row, std::uint32_t end_row, std::uint
auto slice_ptr = std::make_shared<std::vector<t_tscalar>>(slice);
auto names_ptr = std::make_shared<std::vector<std::string>>(column_names);
auto indices_ptr = std::make_shared<std::vector<t_uindex>>(column_indices);
auto data_slice = t_data_slice<t_ctx2>(m_ctx, slice_ptr, names_ptr, indices_ptr);
auto data_slice = t_data_slice<t_ctx2>(
m_ctx, start_row, end_row, start_col, end_col, slice_ptr, names_ptr, indices_ptr);
return data_slice;
}

Expand Down
16 changes: 13 additions & 3 deletions cpp/perspective/src/include/perspective/data_slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <perspective/base.h>
#include <perspective/raw_types.h>
#include <perspective/scalar.h>
#include <perspective/get_data_extents.h>
#include <perspective/context_zero.h>
#include <perspective/context_one.h>
#include <perspective/context_two.h>
Expand All @@ -34,10 +35,12 @@ namespace perspective {
template <typename CTX_T>
class PERSPECTIVE_EXPORT t_data_slice {
public:
t_data_slice(std::shared_ptr<CTX_T> ctx, std::shared_ptr<std::vector<t_tscalar>> slice,
t_data_slice(std::shared_ptr<CTX_T> ctx, t_uindex start_row, t_uindex end_row,
t_uindex start_col, t_uindex end_col, std::shared_ptr<std::vector<t_tscalar>> slice,
std::shared_ptr<std::vector<std::string>> column_names);

t_data_slice(std::shared_ptr<CTX_T> ctx, std::shared_ptr<std::vector<t_tscalar>> slice,
t_data_slice(std::shared_ptr<CTX_T> ctx, t_uindex start_row, t_uindex end_row,
t_uindex start_col, t_uindex end_col, std::shared_ptr<std::vector<t_tscalar>> slice,
std::shared_ptr<std::vector<std::string>> column_names,
std::shared_ptr<std::vector<t_uindex>> column_indices);

Expand All @@ -53,16 +56,23 @@ class PERSPECTIVE_EXPORT t_data_slice {
* @return t_tscalar a valid scalar containing the underlying data, or a new
* t_tscalar initialized with an invalid flag.
*/
t_tscalar get(t_uindex ridx, t_uindex cidx);
t_tscalar get(t_uindex ridx, t_uindex cidx) const;

std::vector<t_tscalar> get_row_path(t_uindex idx) const;

std::shared_ptr<CTX_T> get_context() const;
std::shared_ptr<std::vector<t_tscalar>> get_slice() const;
std::shared_ptr<std::vector<std::string>> get_column_names() const;
std::shared_ptr<std::vector<t_uindex>> get_column_indices() const;
t_get_data_extents get_data_extents() const;
bool is_column_only() const;

private:
std::shared_ptr<CTX_T> m_ctx;
t_uindex m_start_row;
t_uindex m_end_row;
t_uindex m_start_col;
t_uindex m_end_col;
std::shared_ptr<std::vector<t_tscalar>> m_slice;
std::shared_ptr<std::vector<std::string>> m_column_names;
std::shared_ptr<std::vector<t_uindex>> m_column_indices;
Expand Down
26 changes: 26 additions & 0 deletions cpp/perspective/src/include/perspective/get_data_extents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

#pragma once

#include <perspective/first.h>
#include <perspective/raw_types.h>

namespace perspective {

struct t_get_data_extents {
t_index m_srow;
t_index m_erow;
t_index m_scol;
t_index m_ecol;
};

t_get_data_extents sanitize_get_data_extents(t_index nrows, t_index ncols, t_index start_row,
t_index end_row, t_index start_col, t_index end_col);
} // namespace perspective
1 change: 0 additions & 1 deletion packages/perspective/bench/js/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function transpose(json) {
async function run() {
// Allow users to set a limit on version lookbacks
let psp_urls = URLS;
console.log(`limit: ${LIMIT}`);
if (LIMIT !== -1) {
let limit_num = Number(args[LIMIT + 1]);
if (!isNaN(limit_num) && limit_num > 0 && limit_num <= psp_urls.length) {
Expand Down

0 comments on commit 23bd8cb

Please sign in to comment.