bool ndt::categorical_kind_type::match(
    const char *DYND_UNUSED(arrmeta), const type &candidate_tp,
    const char *DYND_UNUSED(candidate_arrmeta),
    std::map<std::string, type> &DYND_UNUSED(tp_vars)) const
{
  return candidate_tp.get_type_id() == categorical_type_id;
}
Example #2
0
void sequence::clear_vector (type &vectorobject)
{
	for(size_t i = 0; i < vectorobject.size(); i++)
	{
		delete vectorobject[i];
	}
}
Example #3
0
bool ndt::time_type::is_lossless_assignment(const type &dst_tp,
                                            const type &src_tp) const
{
  if (dst_tp.extended() == this) {
    if (src_tp.extended() == this) {
      return true;
    } else if (src_tp.get_type_id() == time_type_id) {
      // There is only one possibility for the time type (TODO: timezones!)
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}
		std::string FractalTexture::gmpNumToString(type num, int base) {
			std::string s;
#ifdef ROE_FRACTAL_USE_GMP
			long exp;
#ifdef ROE_FRACTAL_GMP_USE_C
			s = mpf_get_str(nullptr, &exp, base, 0, num);
#else
			s = num.get_str(exp, base, 0);
#endif
			std::string sign = "";
			if(s.length() == 0) {s="00"; ++exp;}
			if(s[0] == '-') {sign = "-"; s = s.substr(1);}
			while (exp <= 0) {
				s = "0"+s;
				++exp;
			}
			while (exp >= (long)s.length()) {
				s += "0";
			}
			s.insert(exp, ".");//*/
			s = sign + s;
#else
			s = util::toString((double)num);
#endif
			return s;
		}
 static void fill(type& v, std::size_t num_of_elems, T const& val) {
     for (std::size_t elem = 0; elem < num_of_elems; ++elem) {
         typename vecvec<T, level - 1>::type child;
         vecvec<T, level - 1>::fill(child, num_of_elems, val);
         v.push_back(child);
     }
 }
Example #6
0
size_t ndt::tuple_type::make_comparison_kernel(
    void *ckb, intptr_t ckb_offset, const type &src0_tp,
    const char *src0_arrmeta, const type &src1_tp, const char *src1_arrmeta,
    comparison_type_t comptype, const eval::eval_context *ectx) const
{
  if (this == src0_tp.extended()) {
    if (*this == *src1_tp.extended()) {
      return make_tuple_comparison_kernel(
          ckb, ckb_offset, src0_tp, src0_arrmeta, src1_arrmeta, comptype, ectx);
    } else if (src1_tp.get_kind() == tuple_kind) {
      // TODO
    }
  }

  throw not_comparable_error(src0_tp, src1_tp, comptype);
}
Example #7
0
dependencies extract_dependencies(const types_by_name &known_types, const type &for_type)
{
	assert(!for_type.is_empty());

	auto interfaces = extract_interfaces(for_type);
	auto setters = extract_setters(known_types, for_type);
	for (auto &&setter : setters)
	{
		auto parameter_type = setter.parameter_type();
		if (parameter_type == for_type)
			throw exception::dependency_on_self{};
		if (std::find(std::begin(interfaces), std::end(interfaces), parameter_type) != std::end(interfaces))
			throw exception::dependency_on_supertype{};
		auto parameter_interfaces = extract_interfaces(parameter_type);
		if (std::find(std::begin(parameter_interfaces), std::end(parameter_interfaces), for_type) != std::end(parameter_interfaces))
			throw exception::dependency_on_subtype{};
	}

	auto result = std::vector<dependency>{};
	std::transform(std::begin(setters), std::end(setters), std::back_inserter(result),
		[](const setter_method &setter){ return dependency{setter}; }
	);

	return dependencies{result};
}
Example #8
0
bool ndt::fixed_dim_type::match(const char *arrmeta, const type &candidate_tp,
                                const char *candidate_arrmeta,
                                std::map<std::string, type> &tp_vars) const
{
  switch (candidate_tp.get_type_id()) {
  case fixed_dim_type_id:
    // TODO XXX If the arrmeta is not NULL, the strides should be checked too
    return get_fixed_dim_size() ==
               candidate_tp.extended<fixed_dim_type>()->get_fixed_dim_size() &&
           m_element_tp.match(
               (arrmeta == NULL) ? arrmeta
                                 : (arrmeta + sizeof(fixed_dim_type_arrmeta)),
               candidate_tp.extended<fixed_dim_type>()->m_element_tp,
               (candidate_arrmeta == NULL)
                   ? candidate_arrmeta
                   : (candidate_arrmeta + sizeof(fixed_dim_type_arrmeta)),
               tp_vars);
  case c_contiguous_type_id:
    return is_c_contiguous(arrmeta) &&
           match(arrmeta,
                 candidate_tp.extended<c_contiguous_type>()->get_child_type(),
                 candidate_arrmeta, tp_vars);
  default:
    return false;
  }
}
Example #9
0
bool
eq_algo::operator()(const type& a, const type& b) const
{
  assert(a.get_kind() == b.get_kind());
  switch (a.get_kind()) {
    case void_type_kind:
      return eq_void_type(cast<void_type>(a), cast<void_type>(b));
    case ref_type_kind:
      return eq_ref_type(cast<ref_type>(a), cast<ref_type>(b));
    case fn_type_kind:
      return eq_fn_type(cast<fn_type>(a), cast<fn_type>(b));
    default:
      break;
  }
  assert(false && "not a common type");
}
Example #10
0
 expression const_cast_(
   const std::shared_ptr< llvm::LLVMContext > &context,
   const std::shared_ptr< ir_builder_t > &ir_builder,
   const type cast_to,
   const expression &value
 ) {
   if(
     type_traits::is_reference( value.type() ) ||
     type_traits::is_pointer( value.type() )
   ) {
     if(
       value.type().which() == cast_to.which()
     ) return remove_const_cast( context, ir_builder, cast_to, value );
     else if(
       type_traits::is_reference( value.type() ) &&
       type_traits::is_pointer( cast_to )
     ) {
       const auto dereferenced = remove_reference( context, ir_builder, value );
       return const_cast_( context, ir_builder, cast_to, dereferenced );
     }
     else if(
       type_traits::is_rvalue_reference( value.type() ) &&
       type_traits::is_lvalue_reference( cast_to )
     ) return reference_cast( context, ir_builder, cast_to, value );
   }
   throw exceptions::invalid_cast();
 }
Example #11
0
bool ndt::callable_type::match(const char *arrmeta, const type &candidate_tp,
                               const char *candidate_arrmeta,
                               std::map<nd::string, type> &tp_vars) const
{
  if (candidate_tp.get_type_id() != callable_type_id) {
    return false;
  }

  // First match the return type
  if (!m_return_type.match(
          arrmeta, candidate_tp.extended<callable_type>()->m_return_type,
          candidate_arrmeta, tp_vars)) {
    return false;
  }

  // Next match all the positional parameters
  if (!m_pos_tuple.match(arrmeta,
                         candidate_tp.extended<callable_type>()->m_pos_tuple,
                         candidate_arrmeta, tp_vars)) {
    return false;
  }

  // Finally match all the keyword parameters
  if (!m_kwd_struct.match(
          arrmeta, candidate_tp.extended<callable_type>()->get_kwd_struct(),
          candidate_arrmeta, tp_vars)) {
    return false;
  }

  return true;
}
Example #12
0
bool ndt::fixed_string_kind_type::match(
    const char *DYND_UNUSED(arrmeta), const type &candidate_tp,
    const char *DYND_UNUSED(candidate_arrmeta),
    std::map<nd::string, type> &DYND_UNUSED(tp_vars)) const
{
  return candidate_tp.get_type_id() == fixed_string_type_id;
}
Example #13
0
bool ndt::fixed_bytes_type::is_lossless_assignment(const type &dst_tp,
                                                   const type &src_tp) const
{
  if (dst_tp.extended() == this) {
    if (src_tp.extended() == this) {
      return true;
    } else if (src_tp.get_type_id() == fixed_bytes_type_id) {
      const fixed_bytes_type *src_fs =
          static_cast<const fixed_bytes_type *>(src_tp.extended());
      return get_data_size() == src_fs->get_data_size();
    } else {
      return false;
    }
  } else {
    return false;
  }
}
Example #14
0
bool ndt::kind_sym_type::match(
    const char *DYND_UNUSED(arrmeta), const type &candidate_tp,
    const char *DYND_UNUSED(candidate_arrmeta),
    std::map<nd::string, type> &DYND_UNUSED(tp_vars)) const
{
  // Matches against the 'kind' of the candidate type
  return candidate_tp.get_kind() == m_kind;
}
Example #15
0
bool ndt::scalar_kind_type::match(
    const char *DYND_UNUSED(arrmeta), const type &candidate_tp,
    const char *DYND_UNUSED(candidate_arrmeta),
    std::map<std::string, type> &DYND_UNUSED(tp_vars)) const
{
  // Match against any scalar
  return candidate_tp.is_scalar();
}
Example #16
0
bool ndt::pointer_type::is_lossless_assignment(const type &dst_tp, const type &src_tp) const
{
    if (dst_tp.extended() == this) {
        return ::is_lossless_assignment(m_target_tp, src_tp);
    } else {
        return ::is_lossless_assignment(dst_tp, m_target_tp);
    }
}
Example #17
0
 virtual bool operator==(const type & t) const override
 {
     if (!t.is_array())
         return false;
     const auto & a = static_cast<const array_type &>(t);
     return size == a.size &&
             element == a.element;
 }
Example #18
0
bool ndt::option_type::match(const type &candidate_tp, std::map<std::string, type> &tp_vars) const
{
  if (candidate_tp.get_id() != option_id) {
    return false;
  }

  return m_value_tp.match(candidate_tp.extended<option_type>()->m_value_tp, tp_vars);
}
Example #19
0
intptr_t ndt::bytes_type::make_assignment_kernel(void *ckb, intptr_t ckb_offset, const type &dst_tp,
        const char *dst_arrmeta, const type &src_tp, const char *src_arrmeta,
        kernel_request_t kernreq, const eval::eval_context *ectx) const
{
    if (this == dst_tp.extended()) {
        switch (src_tp.get_type_id()) {
        case bytes_type_id: {
            return make_blockref_bytes_assignment_kernel(ckb, ckb_offset, get_data_alignment(), dst_arrmeta,
                    src_tp.get_data_alignment(), src_arrmeta, kernreq, ectx);
        }
        case fixed_bytes_type_id: {
            return make_fixed_bytes_to_blockref_bytes_assignment_kernel(ckb, ckb_offset, get_data_alignment(), dst_arrmeta,
                    src_tp.get_data_size(), src_tp.get_data_alignment(),
                    kernreq, ectx);
        }
        default: {
            if (!src_tp.is_builtin()) {
                src_tp.extended()->make_assignment_kernel(ckb, ckb_offset, dst_tp, dst_arrmeta, src_tp, src_arrmeta, kernreq,
                        ectx);
            }
            break;
        }
        }
    }

    stringstream ss;
    ss << "Cannot assign from " << src_tp << " to " << dst_tp;
    throw runtime_error(ss.str());
}
Example #20
0
intptr_t ndt::callable_type::make_assignment_kernel(void *ckb, intptr_t ckb_offset, const type &dst_tp,
                                                    const char *dst_arrmeta, const type &src_tp,
                                                    const char *DYND_UNUSED(src_arrmeta), kernel_request_t kernreq,
                                                    const eval::eval_context *ectx) const
{
  if (this == dst_tp.extended()) {
  } else {
    if (dst_tp.get_kind() == string_kind) {
      // Assignment to strings
      return make_callable_to_string_assignment_kernel(ckb, ckb_offset, dst_tp, dst_arrmeta, src_tp, kernreq, ectx);
    }
  }

  // Nothing can be assigned to/from callable
  stringstream ss;
  ss << "Cannot assign from " << src_tp << " to " << dst_tp;
  throw dynd::type_error(ss.str());
}
Example #21
0
size_t ndt::time_type::make_comparison_kernel(
    void *ckb, intptr_t ckb_offset, const type &src0_tp,
    const char *src0_arrmeta, const type &src1_tp, const char *src1_arrmeta,
    comparison_type_t comptype, const eval::eval_context *ectx) const
{
  if (this == src0_tp.extended()) {
    if (*this == *src1_tp.extended()) {
      return make_builtin_type_comparison_kernel(ckb, ckb_offset, int64_type_id,
                                                 int64_type_id, comptype);
    } else if (!src1_tp.is_builtin()) {
      return src1_tp.extended()->make_comparison_kernel(
          ckb, ckb_offset, src0_tp, src0_arrmeta, src1_tp, src1_arrmeta,
          comptype, ectx);
    }
  }

  throw not_comparable_error(src0_tp, src1_tp, comptype);
}
Example #22
0
bool ndt::option_type::is_lossless_assignment(const type &dst_tp,
                                              const type &src_tp) const
{
  if (dst_tp.extended() == this) {
    return ::is_lossless_assignment(m_value_tp, src_tp);
  } else {
    return ::is_lossless_assignment(dst_tp, m_value_tp);
  }
}
Example #23
0
bool ndt::base_memory_type::is_lossless_assignment(const type &dst_tp, const type &src_tp) const
{
  // Default to calling with the storage types
  if (dst_tp.extended() == this) {
    return ::is_lossless_assignment(m_element_tp, src_tp);
  } else {
    return ::is_lossless_assignment(dst_tp, m_element_tp);
  }
}
Example #24
0
bool ndt::int_kind_sym_type::match(
    const char *DYND_UNUSED(arrmeta), const type &candidate_tp,
    const char *DYND_UNUSED(candidate_arrmeta),
    std::map<nd::string, type> &DYND_UNUSED(tp_vars)) const
{
  // Matches against the 'kind' of the candidate type
  type_kind_t kind = candidate_tp.get_kind();
  return kind == uint_kind || kind == sint_kind;
}
Example #25
0
std::vector<action_method> extract_actions(const std::string &action_tag, const type &for_type)
{
	assert(!for_type.is_empty());

	auto result = std::vector<action_method>{};

	auto meta_object = for_type.meta_object();
	auto method_count = meta_object->methodCount();
	for (decltype(method_count) i = 0; i < method_count; i++)
	{
		auto probably_action = meta_object->method(i);
		auto method_tag = std::string{probably_action.tag()};
		if (action_tag == method_tag)
			result.emplace_back(make_action_method(probably_action));
	}

	return result;
}
bool ndt::fixed_dim_kind_type::match(const char *arrmeta, const type &candidate_tp, const char *candidate_arrmeta,
                                     std::map<std::string, type> &tp_vars) const
{
  switch (candidate_tp.get_type_id()) {
  case fixed_dim_type_id:
    if (candidate_tp.get_kind() == kind_kind) {
      return m_element_tp.match(arrmeta, candidate_tp.extended<fixed_dim_kind_type>()->get_element_type(),
                                candidate_arrmeta, tp_vars);
    } else {
      return m_element_tp.match(arrmeta, candidate_tp.extended<fixed_dim_type>()->get_element_type(),
                                DYND_INC_IF_NOT_NULL(candidate_arrmeta, sizeof(fixed_dim_type_arrmeta)), tp_vars);
    }
  case any_kind_type_id:
    return true;
  default:
    return false;
  }
}
Example #27
0
size_t ndt::string_type::make_comparison_kernel(void *ckb, intptr_t ckb_offset, const type &src0_dt,
                                                const char *src0_arrmeta, const type &src1_dt, const char *src1_arrmeta,
                                                comparison_type_t comptype, const eval::eval_context *ectx) const
{
  if (this == src0_dt.extended()) {
    if (*this == *src1_dt.extended()) {
      return make_string_comparison_kernel(ckb, ckb_offset, string_encoding_utf_8, comptype, ectx);
    } else if (src1_dt.get_kind() == string_kind) {
      return make_general_string_comparison_kernel(ckb, ckb_offset, src0_dt, src0_arrmeta, src1_dt, src1_arrmeta,
                                                   comptype, ectx);
    } else if (!src1_dt.is_builtin()) {
      return src1_dt.extended()->make_comparison_kernel(ckb, ckb_offset, src0_dt, src0_arrmeta, src1_dt, src1_arrmeta,
                                                        comptype, ectx);
    }
  }

  throw not_comparable_error(src0_dt, src1_dt, comptype);
}
intptr_t ndt::fixed_dim_type::make_assignment_kernel(void *ckb, intptr_t ckb_offset, const type &dst_tp,
                                                     const char *dst_arrmeta, const type &src_tp,
                                                     const char *src_arrmeta, kernel_request_t kernreq,
                                                     const eval::eval_context *ectx) const
{
  if (this == dst_tp.extended()) {
    const fixed_dim_type_arrmeta *dst_md = reinterpret_cast<const fixed_dim_type_arrmeta *>(dst_arrmeta);
    intptr_t src_size, src_stride;
    type src_el_tp;
    const char *src_el_arrmeta;

    if (src_tp.get_ndim() < dst_tp.get_ndim()) {
      src_stride = 0;
      nd::functional::elwise_ck<fixed_dim_type_id, fixed_dim_type_id, 1>::make(
          ckb, kernreq, ckb_offset, get_fixed_dim_size(), dst_md->stride, &src_stride);

      return ::make_assignment_kernel(ckb, ckb_offset, m_element_tp, dst_arrmeta + sizeof(fixed_dim_type_arrmeta),
                                      src_tp, src_arrmeta, kernel_request_strided, ectx);
    } else if (src_tp.get_as_strided(src_arrmeta, &src_size, &src_stride, &src_el_tp, &src_el_arrmeta)) {
      nd::functional::elwise_ck<fixed_dim_type_id, fixed_dim_type_id, 1>::make(
          ckb, kernreq, ckb_offset, get_fixed_dim_size(), dst_md->stride, &src_stride);

      // Check for a broadcasting error
      if (src_size != 1 && get_fixed_dim_size() != src_size) {
        throw broadcast_error(dst_tp, dst_arrmeta, src_tp, src_arrmeta);
      }

      return ::make_assignment_kernel(ckb, ckb_offset, m_element_tp, dst_arrmeta + sizeof(fixed_dim_type_arrmeta),
                                      src_el_tp, src_el_arrmeta, kernel_request_strided, ectx);
    } else if (!src_tp.is_builtin()) {
      // Give the src type a chance to make a kernel
      return src_tp.extended()->make_assignment_kernel(ckb, ckb_offset, dst_tp, dst_arrmeta, src_tp, src_arrmeta,
                                                       kernreq, ectx);
    } else {
      stringstream ss;
      ss << "Cannot assign from " << src_tp << " to " << dst_tp;
      throw dynd::type_error(ss.str());
    }
  } else if (dst_tp.get_kind() == string_kind) {
    return make_any_to_string_assignment_kernel(ckb, ckb_offset, dst_tp, dst_arrmeta, src_tp, src_arrmeta, kernreq,
                                                ectx);
  } else if (dst_tp.get_ndim() < src_tp.get_ndim()) {
    throw broadcast_error(dst_tp, dst_arrmeta, src_tp, src_arrmeta);
  } else {
    stringstream ss;
    ss << "Cannot assign from " << src_tp << " to " << dst_tp;
    throw dynd::type_error(ss.str());
  }
}
Example #29
0
    static std::vector<type> permute(const type& nums)
    {
        if (nums.empty()) {
            return std::vector<type> {{}};
        }

        std::vector<type> result;
        for (type::size_type i = 0; i != nums.size(); ++i) {
            type rest;
            std::copy(nums.begin(), nums.begin() + i, std::back_inserter(rest));
            std::copy(nums.begin() + i + 1, nums.end(), std::back_inserter(rest));
            auto sub = permute(rest);
            for (auto& x : sub) {
                x.push_back(nums[i]);
                result.push_back(x);
            }
        }
        return result;
    }
Example #30
0
bool ndt::groupby_type::is_lossless_assignment(const type &dst_tp,
                                               const type &src_tp) const
{
  // Treat this type as the value type for whether assignment is always lossless
  if (src_tp.extended() == this) {
    return ::dynd::is_lossless_assignment(dst_tp, m_value_type);
  } else {
    return ::dynd::is_lossless_assignment(m_value_type, src_tp);
  }
}