Skip to content

Commit

Permalink
Updates (#47)
Browse files Browse the repository at this point in the history
* int -> long types in c files

* Stop track of general.h

* All numbers are float types in geodetic2UTMFloat()

* Bump to 0.3.5

---------

Co-authored-by: Daniel Stoops <[email protected]>
  • Loading branch information
Stoops-ML and Daniel Stoops authored Nov 6, 2024
1 parent d2c9b65 commit c5e4fce
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 209 deletions.
24 changes: 12 additions & 12 deletions include/distances.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ Calculate the Haversine distance between two points in double precision.
range [rad, rad, m]
@param float *rrmEnd array of size nx3 of start point azimuth, elevation, range
[rad, rad, m]
@param size_t nPoints Number of target points
@param long nPoints Number of target points
@param double mRadiusSphere Radius of sphere in metres
@param float *mRadiusSphere array of size nx3 of distance between start and end
points
*/
void HaversineDouble(const double* rrmStart,
const double* rrmEnd,
int nPoints,
long nPoints,
int isArraysSizeEqual,
double mRadiusSphere,
double* mDistance)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
int iPointEnd = iPoint * NCOORDSIN3D;
int iPointStart = iPointEnd * isArraysSizeEqual;
long iPointEnd = iPoint * NCOORDSIN3D;
long iPointStart = iPointEnd * isArraysSizeEqual;
mDistance[iPoint] = 2.0 * mRadiusSphere * asin(sqrt((1.0 - cos(rrmEnd[iPointEnd] - rrmStart[iPointStart]) + cos(rrmStart[iPointStart]) * cos(rrmEnd[iPointEnd]) * (1.0 - cos(rrmEnd[iPointEnd + 1] - rrmStart[iPointStart + 1]))) / 2.0));
}
}
Expand All @@ -41,23 +41,23 @@ Calculate the Haversine distance between two points in float precision.
range [rad, rad, m]
@param float *rrmEnd array of size nx3 of start point azimuth, elevation, range
[rad, rad, m]
@param size_t nPoints Number of target points
@param long nPoints Number of target points
@param double mRadiusSphere Radius of sphere in metres
@param float *mRadiusSphere array of size nx3 of distance between start and end
points
*/
void HaversineFloat(const float* rrmStart,
const float* rrmEnd,
int nPoints,
long nPoints,
int isArraysSizeEqual,
float mRadiusSphere,
float* mDistance)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
int iPointEnd = iPoint * NCOORDSIN3D;
int iPointStart = iPointEnd * isArraysSizeEqual;
long iPointEnd = iPoint * NCOORDSIN3D;
long iPointStart = iPointEnd * isArraysSizeEqual;
mDistance[iPoint] = (float)(2.0) * mRadiusSphere * asinf(sqrtf(((float)(1.0) - cosf(rrmEnd[iPointEnd] - rrmStart[iPointStart]) + cosf(rrmStart[iPointStart]) * cosf(rrmEnd[iPointEnd]) * ((float)(1.0) - cosf(rrmEnd[iPointEnd + 1] - rrmStart[iPointStart + 1]))) / (float)(2.0)));
}
}
Expand Down Expand Up @@ -144,11 +144,11 @@ HaversineWrapper(PyObject* self, PyObject* args)
switch (PyArray_TYPE(result_array)) {
case NPY_DOUBLE:
HaversineDouble(
(double*)PyArray_DATA(inArrayStart), (double*)PyArray_DATA(inArrayEnd), (int)nPoints, isArraysSizeEqual, mRadiusSphere, (double*)PyArray_DATA(result_array));
(double*)PyArray_DATA(inArrayStart), (double*)PyArray_DATA(inArrayEnd), (long)nPoints, isArraysSizeEqual, mRadiusSphere, (double*)PyArray_DATA(result_array));
break;
case NPY_FLOAT:
HaversineFloat(
(float*)PyArray_DATA(inArrayStart), (float*)PyArray_DATA(inArrayEnd), (int)nPoints, isArraysSizeEqual, (float)(mRadiusSphere), (float*)PyArray_DATA(result_array));
(float*)PyArray_DATA(inArrayStart), (float*)PyArray_DATA(inArrayEnd), (long)nPoints, isArraysSizeEqual, (float)(mRadiusSphere), (float*)PyArray_DATA(result_array));
break;
default:
PyErr_SetString(PyExc_ValueError,
Expand Down
Empty file removed include/general.h
Empty file.
64 changes: 32 additions & 32 deletions include/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Calculate the angular difference between two numbers of double precision.
smallestAngle is false.
@param double *AngleEnd array of size n angles. This is the end angle if
smallestAngle is false.
@param int nAngles Number of angles in array
@param long nAngles Number of angles in array
@param int smallestAngle Whether to calculate the angular difference between
the start and end angles or the smallest angle.
@param double Difference Angular difference
Expand All @@ -38,7 +38,7 @@ Calculate the angular difference between two numbers of float precision.
false.
@param float AngleEnd angle. This is the end angle if smallestAngle is false.
@param float MaxValue angle.
@param int nAngles Number of angles in array
@param long nAngles Number of angles in array
@param int smallestAngle Whether to calculate the angular difference between
the start and end angles or the smallest angle.
@param float Difference Angular difference
Expand All @@ -63,18 +63,18 @@ Calculate the angular difference between two numbers of float precision.
smallestAngle is false.
@param float *AngleEnd array of size n angles. This is the end angle if
smallestAngle is false.
@param int nAngles Number of angles in array
@param long nAngles Number of angles in array
@param int smallestAngle Whether to calculate the angular difference between
the start and end angles or the smallest angle.
@param float Difference Angular difference */
void AngularDifferencesFloat(const float* AngleStart,
const float* AngleEnd,
const float MaxValue,
int nAngles,
long nAngles,
int smallestAngle,
float* Difference)
{
int i;
long i;
#pragma omp parallel for if (nAngles > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (i = 0; i < nAngles; ++i) {
Difference[i] = fmodf(fabsf(AngleStart[i] - AngleEnd[i]), MaxValue);
Expand All @@ -92,18 +92,18 @@ Calculate the angular difference between two numbers of float precision.
smallestAngle is false.
@param double *AngleEnd array of size n angles. This is the end angle if
smallestAngle is false.
@param int nAngles Number of angles in array
@param long nAngles Number of angles in array
@param int smallestAngle Whether to calculate the angular difference between
the start and end angles or the smallest angle.
@param double Difference Angular difference */
void AngularDifferencesDouble(const double* AngleStart,
const double* AngleEnd,
const double MaxValue,
int nAngles,
long nAngles,
int smallestAngle,
double* Difference)
{
int i;
long i;
#pragma omp parallel for if (nAngles > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (i = 0; i < nAngles; ++i) {
Difference[i] = fmod(fabs(AngleStart[i] - AngleEnd[i]), MaxValue);
Expand All @@ -118,18 +118,18 @@ void AngularDifferencesDouble(const double* AngleStart,
Convert a point from X, X, m to Y, Y, m in double precision
@param double *ddmPoint array of size nx3
@param int nPoints Number of angles in array
@param long nPoints Number of angles in array
@param double *rrmPoint array of size nx3
*/
void XXM2YYMDouble(const double* rrmPoint,
int nPoints,
long nPoints,
const double transform,
double* ddmPoint)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
int i = iPoint * NCOORDSIN3D;
long i = iPoint * NCOORDSIN3D;
ddmPoint[i + 0] = rrmPoint[i + 0] * transform;
ddmPoint[i + 1] = rrmPoint[i + 1] * transform;
ddmPoint[i + 2] = rrmPoint[i + 2];
Expand All @@ -140,18 +140,18 @@ void XXM2YYMDouble(const double* rrmPoint,
Convert a point from X, X, m to Y, Y, m in float precision
@param float *ddmPoint array of size nx3
@param int nPoints Number of angles in array
@param long nPoints Number of angles in array
@param float *rrmPoint array of size nx3
*/
void XXM2YYMFloat(const float* rrmPoint,
int nPoints,
long nPoints,
const float transform,
float* ddmPoint)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
int i = iPoint * NCOORDSIN3D;
long i = iPoint * NCOORDSIN3D;
ddmPoint[i + 0] = rrmPoint[i + 0] * transform;
ddmPoint[i + 1] = rrmPoint[i + 1] * transform;
ddmPoint[i + 2] = rrmPoint[i + 2];
Expand All @@ -164,10 +164,10 @@ Wrap a point between two numbers
void WrapsFloat3(const float* val,
const float* maxVal,
const float* minVal,
int nPoints,
long nPoints,
float* boundedVal)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmodf(val[iPoint] - minVal[iPoint], maxVal[iPoint] - minVal[iPoint]) + minVal[iPoint];
Expand All @@ -182,10 +182,10 @@ Wrap a point between two numbers
void WrapsDouble3(const double* val,
const double* maxVal,
const double* minVal,
int nPoints,
long nPoints,
double* boundedVal)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmod(val[iPoint] - minVal[iPoint], maxVal[iPoint] - minVal[iPoint]) + minVal[iPoint];
Expand All @@ -200,10 +200,10 @@ Wrap a point between two numbers
void WrapsFloat1(const float* val,
const float maxVal,
const float minVal,
int nPoints,
long nPoints,
float* boundedVal)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmodf(val[iPoint] - minVal, maxVal - minVal) + minVal;
Expand All @@ -218,10 +218,10 @@ Wrap a point between two numbers
void WrapsDouble1(const double* val,
const double maxVal,
const double minVal,
int nPoints,
long nPoints,
double* boundedVal)
{
int iPoint;
long iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmod(val[iPoint] - minVal, maxVal - minVal) + minVal;
Expand Down Expand Up @@ -304,7 +304,7 @@ WrapWrapper(PyObject* self, PyObject* args)
return NULL;
}

int nPoints = (int)PyArray_SIZE(val);
long nPoints = (int)PyArray_SIZE(val);
double minVal, maxVal;
if (PyLong_Check(arg2))
minVal = PyLong_AsDouble(arg2);
Expand Down Expand Up @@ -367,11 +367,11 @@ WrapWrapper(PyObject* self, PyObject* args)
return NULL;
}

int nPoints = (int)PyArray_SIZE(val);
long nPoints = (int)PyArray_SIZE(val);
if (PyArray_TYPE(val) == NPY_DOUBLE) {
double* maxVals = (double*)PyArray_DATA(maxVal);
double* minVals = (double*)PyArray_DATA(minVal);
for (npy_intp i = 0; i < nPoints; i++) {
for (long i = 0; i < nPoints; i++) {
if (minVals[i] > maxVals[i]) {
PyErr_SetString(PyExc_ValueError, "All maximum values must be larger than all minimum values.");
return NULL;
Expand All @@ -381,7 +381,7 @@ WrapWrapper(PyObject* self, PyObject* args)
} else if (PyArray_TYPE(val) == NPY_FLOAT) {
float* maxVals = (float*)PyArray_DATA(maxVal);
float* minVals = (float*)PyArray_DATA(minVal);
for (npy_intp i = 0; i < nPoints; i++) {
for (long i = 0; i < nPoints; i++) {
if (minVals[i] > maxVals[i]) {
PyErr_SetString(PyExc_ValueError, "All maximum values must be larger than all minimum values.");
return NULL;
Expand Down Expand Up @@ -447,7 +447,7 @@ RadAngularDifferenceWrapper(PyObject* self, PyObject* args)
return NULL;
}

int nPoints = (int)PyArray_SIZE(radAngleStart);
long nPoints = (int)PyArray_SIZE(radAngleStart);
if (PyArray_TYPE(radAngleEnd) == NPY_DOUBLE) {
AngularDifferencesDouble((double*)PyArray_DATA(radAngleStart), (double*)PyArray_DATA(radAngleEnd), 2.0 * PI, nPoints, smallestAngle, (double*)PyArray_DATA(result_array));
} else if (PyArray_TYPE(radAngleEnd) == NPY_FLOAT) {
Expand Down Expand Up @@ -548,7 +548,7 @@ DegAngularDifferenceWrapper(PyObject* self, PyObject* args)
return NULL;
}

int nPoints = (int)PyArray_SIZE(degAngleStart);
long nPoints = (int)PyArray_SIZE(degAngleStart);
if (PyArray_TYPE(degAngleEnd) == NPY_DOUBLE) {
AngularDifferencesDouble((double*)PyArray_DATA(degAngleStart), (double*)PyArray_DATA(degAngleEnd), DEGCIRCLE, nPoints, smallestAngle, (double*)PyArray_DATA(result_array));
} else if (PyArray_TYPE(degAngleEnd) == NPY_FLOAT) {
Expand Down Expand Up @@ -643,7 +643,7 @@ RRM2DDMWrapper(PyObject* self, PyObject* args)
return NULL;
}

int nPoints = (int)PyArray_SIZE(in_array) / NCOORDSIN3D;
long nPoints = (int)PyArray_SIZE(in_array) / NCOORDSIN3D;
if (PyArray_TYPE(result_array) == NPY_DOUBLE) {
XXM2YYMDouble(
(double*)PyArray_DATA(in_array), nPoints, 180.0 / PI, (double*)PyArray_DATA(result_array));
Expand Down Expand Up @@ -699,7 +699,7 @@ DDM2RRMWrapper(PyObject* self, PyObject* args)
PyErr_SetString(PyExc_ValueError, "Could not create output array.");
return NULL;
}
int nPoints = (int)PyArray_SIZE(in_array) / NCOORDSIN3D;
long nPoints = (int)PyArray_SIZE(in_array) / NCOORDSIN3D;
if (PyArray_TYPE(result_array) == NPY_DOUBLE) {
XXM2YYMDouble(
(double*)PyArray_DATA(in_array), nPoints, PI / 180.0, (double*)PyArray_DATA(result_array));
Expand Down
Loading

0 comments on commit c5e4fce

Please sign in to comment.