Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arrays): Make Numeric_Array support LONGLONG and ULONGLONG #112

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bundles/arrays/_arrays/pythonarray.cpp
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@ bool array_from_python(PyObject *array, int dim, Numeric_Array *na, bool allow_d
dtype = (sizeof(int) == sizeof(long) ? Numeric_Array::Int : Numeric_Array::Long_Int); break;
case NPY_ULONG:
dtype = (sizeof(int) == sizeof(long) ? Numeric_Array::Unsigned_Int : Numeric_Array::Unsigned_Long_Int); break;
case NPY_LONGLONG: dtype = Numeric_Array::Long_Long_Int; break;
case NPY_ULONGLONG: dtype = Numeric_Array::Unsigned_Long_Long_Int; break;
case NPY_FLOAT: dtype = Numeric_Array::Float; break;
case NPY_DOUBLE: dtype = Numeric_Array::Double; break;
default:
@@ -1315,6 +1317,12 @@ static int parse_int_nm(PyObject *arg, int64_t m, void *iarray, bool allow_copy)
vi.set(Reference_Counted_Array::Array<long int>(v));
v = Numeric_Array(Numeric_Array::Int, vi);
}
if (v.value_type() == Numeric_Array::Long_Long_Int && allow_copy)
{
IArray vi = IArray(v.dimension(), v.sizes());
vi.set(Reference_Counted_Array::Array<long long int>(v));
v = Numeric_Array(Numeric_Array::Int, vi);
}
if (v.value_type() != Numeric_Array::Int)
{
PyErr_Format(PyExc_TypeError, "array type must be int or long int, got %s",
4 changes: 4 additions & 0 deletions src/bundles/arrays/_arrays/rcarray.cpp
Original file line number Diff line number Diff line change
@@ -322,6 +322,8 @@ int Numeric_Array::size_of_type(Value_Type t)
case Unsigned_Int: return sizeof(unsigned int);
case Long_Int: return sizeof(long int);
case Unsigned_Long_Int: return sizeof(unsigned long int);
case Long_Long_Int: return sizeof(long long int);
case Unsigned_Long_Long_Int: return sizeof(unsigned long long int);
case Float: return sizeof(float);
case Double: return sizeof(double);
};
@@ -465,6 +467,8 @@ const char *Numeric_Array::value_type_name(Value_Type type)
case Unsigned_Int: return "unsigned int";
case Long_Int: return "long int";
case Unsigned_Long_Int: return "unsigned long int";
case Long_Long_Int: return "long long int";
case Unsigned_Long_Long_Int: return "unsigned long long int";
case Float: return "float";
case Double: return "double";
}
4 changes: 3 additions & 1 deletion src/bundles/arrays/_arrays/rcarray.h
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ class ARRAYS_IMEX Numeric_Array : public Untyped_Array
public:
enum Value_Type { Char, Signed_Char, Unsigned_Char,
Short_Int, Unsigned_Short_Int, Int, Unsigned_Int,
Long_Int, Unsigned_Long_Int, Float, Double };
Long_Int, Unsigned_Long_Int, Float, Double, Long_Long_Int, Unsigned_Long_Long_Int };
static int size_of_type(Value_Type t);
static const char *value_type_name(Value_Type type);

@@ -228,7 +228,9 @@ class ARRAYS_IMEX Numeric_Array : public Untyped_Array
case RCANA::Int: f<int> args; break; \
case RCANA::Unsigned_Int: f<unsigned int> args; break; \
case RCANA::Long_Int: f<long> args; break; \
case RCANA::Long_Long_Int: f<long long> args; break; \
case RCANA::Unsigned_Long_Int: f<unsigned long> args; break; \
case RCANA::Unsigned_Long_Long_Int: f<unsigned long long> args; break; \
case RCANA::Float: f<float> args; break; \
case RCANA::Double: f<double> args; break; \
}