Skip to content

Commit

Permalink
fix: remove Long64_t from common header-only (#2084)
Browse files Browse the repository at this point in the history
* fix: remove Long64_t from common header-only; enable boolean type test

* fix: try int64 as a default

* fix: support long long

* fix: better error message

* fix: address Jim's comments

* Make type decisions based on fixed-size types exclusively.

Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
  • Loading branch information
ianna and jpivarski committed Jan 12, 2023
1 parent 97d813a commit 12a3101
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 117 deletions.
165 changes: 50 additions & 115 deletions header-only/awkward/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,136 +11,71 @@
#include <utility>
#include <stdexcept>
#include <stdint.h>
#include <typeinfo>


namespace awkward {

/// @brief Returns the name of a primitive type as a string.
template <typename T>
const std::string
type_to_name() {
std::cout << "Type " << typeid(T).name() << " is not recognized." << std::endl;
return typeid(T).name();
if (std::is_integral_v<T>) {
if (std::is_signed_v<T>) {
if (sizeof(T) == 1) {
return "int8";
}
else if (sizeof(T) == 2) {
return "int16";
}
else if (sizeof(T) == 4) {
return "int32";
}
else if (sizeof(T) == 8) {
return "int64";
}
}
else {
if (sizeof(T) == 1) {
return "uint8";
}
else if (sizeof(T) == 2) {
return "uint16";
}
else if (sizeof(T) == 4) {
return "uint32";
}
else if (sizeof(T) == 8) {
return "uint64";
}
}
}
else if (std::is_same_v<T, float>) {
return "float32";
}
else if (std::is_same_v<T, double>) {
return "float64";
}
else if (std::is_same_v<T, std::complex<float>>) {
return "complex64";
}
else if (std::is_same_v<T, std::complex<double>>) {
return "complex128";
}

// std::is_integral_v<T> and sizeof(T) not in (1, 2, 4, 8) can get here.
// Don't connect this line with the above as an 'else' clause.
return std::string("unsupported primitive type: ") + typeid(T).name();
}

/// @brief Returns `bool` string when the primitive type
/// is boolean.
template <>
const std::string
type_to_name<bool>() {
// This takes precedence over the unspecialized template, and therefore any
// 8-bit data that is not named bool will be mapped to "int8" or "uint8".
return "bool";
}

/// @brief Returns `int8` string when the primitive type
/// is an 8-bit signed integer.
template <>
const std::string
type_to_name<int8_t>() {
return "int8";
}

/// @brief Returns `int16` string when the primitive type
/// is a 16-bit signed integer.
template <>
const std::string
type_to_name<int16_t>() {
return "int16";
}

/// @brief Returns `int32` string when the primitive type
/// is a 32-bit signed integer.
template <>
const std::string
type_to_name<int32_t>() {
return "int32";
}

/// @brief Returns `int64` string when the primitive type
/// is a 64-bit signed integer.
template <>
const std::string
type_to_name<int64_t>() {
return "int64";
}

/// @brief Returns `int64` string when the primitive type
/// is a 64-bit signed integer.
template <>
const std::string
type_to_name<Long64_t>() {
return "int64";
}

/// @brief Returns `uint8` string when the primitive type
/// is an 8-bit unsigned integer.
template <>
const std::string
type_to_name<uint8_t>() {
return "uint8";
}

/// @brief Returns `uint16` string when the primitive type
/// is a 16-bit unsigned integer.
template <>
const std::string
type_to_name<uint16_t>() {
return "uint16";
}

/// @brief Returns `uint32` string when the primitive type
/// is a 32-bit unsigned integer.
template <>
const std::string
type_to_name<uint32_t>() {
return "uint32";
}

/// @brief Returns `uint64` string when the primitive type
/// is a 64-bit unsigned integer.
template <>
const std::string
type_to_name<uint64_t>() {
return "uint64";
}

/// @brief Returns `float32` string when the primitive type
/// is a floating point.
template <>
const std::string
type_to_name<float>() {
return "float32";
}

/// @brief Returns `float32` string when the primitive type
/// is a double floating point.
template <>
const std::string
type_to_name<double>() {
return "float64";
}

/// @brief Returns `char` string when the primitive type
/// is a character.
template <>
const std::string
type_to_name<char>() {
return "char";
}

/// @brief Returns `complex64` string when the primitive type is a
/// complex number with float32 real and float32 imaginary parts.
template <>
const std::string
type_to_name<std::complex<float>>() {
return "complex64";
}

/// @brief Returns `complex128` string when the primitive type is a
/// complex number with float64 real and float64 imaginary parts.
template <>
const std::string
type_to_name<std::complex<double>>() {
return "complex128";
}

/// @brief Returns `char` string when the primitive type
/// is a character.
Expand Down
3 changes: 1 addition & 2 deletions tests/test_1473_from_rdataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_to_from_data_frame_large():
assert len(ak_array_in) == len(ak_array_out)


@pytest.mark.skip(reason="FIXME: arrays of boolean are not supported yet")
def test_data_frame_boolean():
ak_array_in = ak.Array([True, False, True, True, True])

Expand All @@ -58,7 +57,7 @@ def test_data_frame_boolean():
data_frame,
columns=("x",),
)
assert ak_array_in.to_list() == ak_array_out.to_list()
assert ak_array_in.to_list() == ak_array_out.x.to_list()


def test_data_frame_integers():
Expand Down

0 comments on commit 12a3101

Please sign in to comment.