Пример #1
0
groupby_type::groupby_type(const ndt::type& data_values_tp,
                const ndt::type& by_values_tp)
    : base_expr_type(groupby_type_id, expr_kind,
                    sizeof(groupby_type_data), sizeof(void *), type_flag_none,
                    0, 1 + data_values_tp.get_ndim())
{
    m_groups_type = by_values_tp.at_single(0).value_type();
    if (m_groups_type.get_type_id() != categorical_type_id) {
        stringstream ss;
        ss << "to construct a groupby type, the by type, " << by_values_tp.at_single(0);
        ss << ", must have a categorical value type";
        throw runtime_error(ss.str());
    }
    if (data_values_tp.get_ndim() < 1) {
        throw runtime_error("to construct a groupby type, its values type must have at least one array dimension");
    }
    if (by_values_tp.get_ndim() < 1) {
        throw runtime_error("to construct a groupby type, its values type must have at least one array dimension");
    }
    m_operand_type = ndt::make_cstruct(ndt::make_pointer(data_values_tp), "data",
                    ndt::make_pointer(by_values_tp), "by");
    m_members.arrmeta_size = m_operand_type.get_arrmeta_size();
    const categorical_type *cd = m_groups_type.extended<categorical_type>();
    m_value_type = ndt::make_cfixed_dim(cd->get_category_count(),
                    ndt::make_var_dim(data_values_tp.at_single(0)));
    m_members.flags = inherited_flags(m_value_type.get_flags(), m_operand_type.get_flags());
}
Пример #2
0
 /**
  * Given some metadata for the groupby type, return metadata
  * for a single element of the data_values array.
  */
 const char *get_data_value_metadata(const char *metadata) const {
     // First at_single gets us to the pointer<array<data_value>> type
     ndt::type d = m_operand_type.at_single(0, &metadata);
     // Second at_single gets us to the data_value type
     d.at_single(0, &metadata);
     return metadata;
 }
Пример #3
0
 /**
  * Given some metadata for the groupby type, returns the
  * metadata for the pointer type that points at the by
  * values.
  *
  * \param metadata  An instance of groupby type metadata.
  *
  * \returns  The pointer<by_values_type> metadata within the
  *           groupby metadata.
  */
 pointer_type_metadata *get_by_values_pointer_metadata(char *metadata) const {
     m_operand_type.at_single(1, const_cast<const char **>(&metadata));
     return reinterpret_cast<pointer_type_metadata *>(metadata);
 }
Пример #4
0
 /**
  * Given some arrmeta for the groupby type, returns the
  * arrmeta for the pointer type that points at the data
  * values.
  *
  * \param arrmeta  An instance of groupby type arrmeta.
  *
  * \returns  The pointer<data_values_type> arrmeta within the
  *           groupby arrmeta.
  */
 pointer_type_arrmeta *get_data_values_pointer_arrmeta(char *arrmeta) const {
     m_operand_type.at_single(0, const_cast<const char **>(&arrmeta));
     return reinterpret_cast<pointer_type_arrmeta *>(arrmeta);
 }