示例#1
0
nd::arrfunc dynd::lift_arrfunc(const nd::arrfunc &child_af)
{
  nd::array af = nd::empty(lift_proto(child_af.get_type()));
  arrfunc_type_data *out_af =
      reinterpret_cast<arrfunc_type_data *>(af.get_readwrite_originptr());
  out_af->free_func = &delete_lifted_expr_arrfunc_data;
  *out_af->get_data_as<const array_preamble *>() =
      nd::array(child_af).release();
  out_af->instantiate = &instantiate_lifted_expr_arrfunc_data;
  out_af->resolve_dst_type = &resolve_lifted_dst_type;
  af.flag_as_immutable();
  return af;
}
示例#2
0
nd::arrfunc dynd::make_rolling_arrfunc(const nd::arrfunc &window_op,
                                       intptr_t window_size)
{
  // Validate the input arrfunc
  if (window_op.is_null()) {
    throw invalid_argument("make_rolling_arrfunc() 'window_op' cannot be null");
  }
  const arrfunc_type *window_af_tp = window_op.get_type();
  if (window_af_tp->get_npos() != 1) {
    stringstream ss;
    ss << "To make a rolling window arrfunc, an operation with one "
          "argument is required, got " << window_af_tp;
    throw invalid_argument(ss.str());
  }
  const ndt::type &window_src_tp = window_af_tp->get_arg_type(0);
  if (window_src_tp.get_ndim() < 1) {
    stringstream ss;
    ss << "To make a rolling window arrfunc, an operation with which "
          "accepts a dimension is required, got " << window_af_tp;
    throw invalid_argument(ss.str());
  }

  nd::string rolldimname("RollDim");
  ndt::type roll_src_tp = ndt::make_typevar_dim(
      rolldimname, window_src_tp.get_type_at_dimension(NULL, 1));
  ndt::type roll_dst_tp =
      ndt::make_typevar_dim(rolldimname, window_af_tp->get_return_type());

  nd::array af = nd::empty(ndt::make_funcproto(roll_src_tp, roll_dst_tp));
  arrfunc_type_data *out_af =
      reinterpret_cast<arrfunc_type_data *>(af.get_readwrite_originptr());

  // Create the data for the arrfunc
  rolling_arrfunc_data *data = new rolling_arrfunc_data;
  *out_af->get_data_as<rolling_arrfunc_data *>() = data;
  out_af->free = &free_rolling_arrfunc_data;
  out_af->resolve_dst_type = &resolve_rolling_dst_type;
  out_af->instantiate = &instantiate_strided;
  data->window_size = window_size;
  data->window_op = window_op;
  af.flag_as_immutable();
  return af;
}
示例#3
0
nd::arrfunc nd::functional::rolling(const nd::arrfunc &window_op,
                                    intptr_t window_size)
{
  // Validate the input arrfunc
  if (window_op.is_null()) {
    throw invalid_argument("make_rolling_arrfunc() 'window_op' cannot be null");
  }
  const ndt::arrfunc_type *window_af_tp = window_op.get_type();
  if (window_af_tp->get_npos() != 1) {
    stringstream ss;
    ss << "To make a rolling window arrfunc, an operation with one "
          "argument is required, got " << window_af_tp;
    throw invalid_argument(ss.str());
  }
  const ndt::type &window_src_tp = window_af_tp->get_pos_type(0);
  if (window_src_tp.get_ndim() < 1) {
    stringstream ss;
    ss << "To make a rolling window arrfunc, an operation with which "
          "accepts a dimension is required, got " << window_af_tp;
    throw invalid_argument(ss.str());
  }

  nd::string rolldimname("RollDim");
  ndt::type roll_src_tp = ndt::make_typevar_dim(
      rolldimname, window_src_tp.get_type_at_dimension(NULL, 1));
  ndt::type roll_dst_tp =
      ndt::make_typevar_dim(rolldimname, window_af_tp->get_return_type());

  // Create the data for the arrfunc
  std::shared_ptr<rolling_arrfunc_data> data(new rolling_arrfunc_data);
  data->window_size = window_size;
  data->window_op = window_op;

  return arrfunc::make<rolling_ck>(
      ndt::make_arrfunc(ndt::make_tuple(roll_src_tp), roll_dst_tp), data, 0);
}