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

Move primal::NumericArray to core #1500

Merged
merged 7 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ to use Open Cascade's file I/O capabilities in support of Quest applications.
of `loadExternalData` in `sidre::IOManager` and `sidre::Group`.

### Changed
- `primal::NumericArray` has been moved to `core`. The header is `core/NumericArray.hpp`.
- `quest::Shaper` and `quest::IntersectionShaper` constructors require a runtime policy.
Changing the policy after construction is no longer supported.
- Importing Conduit array data into `sidre::View` now allocates destination
Expand Down
1 change: 1 addition & 0 deletions src/axom/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(core_headers
Map.hpp
MapCollection.hpp
FlatMap.hpp
NumericArray.hpp
NumericLimits.hpp
Path.hpp
RangeAdapter.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "axom/core/Macros.hpp"
#include "axom/core/utilities/Utilities.hpp"
#include "axom/slic/interface/slic.hpp"
#include <cassert>

// C/C++ includes
#include <algorithm>
Expand All @@ -18,8 +18,6 @@

namespace axom
{
namespace primal
{
// Forward declare the templated classes and operator functions
template <typename T, int SIZE>
class NumericArray;
Expand Down Expand Up @@ -381,16 +379,16 @@ class NumericArray // NOLINT

private:
AXOM_HOST_DEVICE
void verifyIndex(int AXOM_DEBUG_PARAM(idx)) const
void verifyIndex(int idx) const
{
SLIC_ASSERT(idx >= 0 && idx < SIZE);
AXOM_UNUSED_VAR(idx);
assert(idx >= 0 && idx < SIZE);
}

protected:
T m_components[SIZE]; /// The encapsulated array
};

} // namespace primal
} // namespace axom

//------------------------------------------------------------------------------
Expand All @@ -399,14 +397,12 @@ class NumericArray // NOLINT

namespace axom
{
namespace primal
{
//------------------------------------------------------------------------------
template <typename T, int SIZE>
AXOM_HOST_DEVICE NumericArray<T, SIZE>::NumericArray(T val, int sz)
{
// NOTE (KW): This should be a static assert in the class
SLIC_ASSERT(SIZE >= 1);
assert(SIZE >= 1);

// Fill first nvals coordinates with val ( 0 <= nvals <= SIZE )
const int nvals = axom::utilities::clampVal(sz, 0, SIZE);
Expand All @@ -426,7 +422,7 @@ AXOM_HOST_DEVICE NumericArray<T, SIZE>::NumericArray(T val, int sz)
template <typename T, int SIZE>
AXOM_HOST_DEVICE NumericArray<T, SIZE>::NumericArray(const T* vals, int sz)
{
SLIC_ASSERT(SIZE >= 1);
assert(SIZE >= 1);

const int nvals = axom::utilities::clampVal(sz, 0, SIZE);

Expand Down Expand Up @@ -477,7 +473,7 @@ AXOM_HOST_DEVICE inline T* NumericArray<T, SIZE>::data()
template <typename T, int SIZE>
AXOM_HOST_DEVICE void NumericArray<T, SIZE>::to_array(T* arr) const
{
SLIC_ASSERT(arr != nullptr);
assert(arr != nullptr);
for(int dim = 0; dim < SIZE; ++dim)
{
arr[dim] = m_components[dim];
Expand Down Expand Up @@ -520,7 +516,7 @@ template <typename T, int SIZE>
AXOM_HOST_DEVICE inline NumericArray<T, SIZE>& NumericArray<T, SIZE>::operator/=(
double scalar)
{
SLIC_ASSERT(scalar != 0.);
assert(scalar != 0.);
return operator*=(1. / scalar);
}

Expand All @@ -544,7 +540,7 @@ AXOM_HOST_DEVICE inline NumericArray<T, SIZE>& NumericArray<T, SIZE>::operator/=
{
for(int i = 0; i < SIZE; ++i)
{
SLIC_ASSERT(v[i] != 0.);
assert(v[i] != 0.);
m_components[i] /= v[i];
}

Expand Down Expand Up @@ -582,7 +578,7 @@ template <typename T, int SIZE>
inline NumericArray<T, SIZE>& NumericArray<T, SIZE>::clamp(const T& lowerVal,
const T& upperVal)
{
SLIC_ASSERT(lowerVal <= upperVal);
assert(lowerVal <= upperVal);

for(int i = 0; i < SIZE; ++i)
{
Expand Down Expand Up @@ -834,13 +830,11 @@ AXOM_HOST_DEVICE inline NumericArray<T, SIZE> abs(const NumericArray<T, SIZE>& a
return result;
}

} // namespace primal
} // namespace axom

/// Overload to format a primal::NumericArray using fmt
/// Overload to format a axom::NumericArray using fmt
template <typename T, int NDIMS>
struct axom::fmt::formatter<axom::primal::NumericArray<T, NDIMS>>
: ostream_formatter
struct axom::fmt::formatter<axom::NumericArray<T, NDIMS>> : ostream_formatter
{ };

#endif // AXOM_PRIMAL_NUMERIC_ARRAY_HPP_
3 changes: 3 additions & 0 deletions src/axom/core/docs/sphinx/core_utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ filesystem example snippet.
:end-before: _timer_end
:language: C++

Axom provides the NumericArray class, which implements arithmetic
operations on numerical tuples.

There are several other utility functions. Some are numerical functions such as
variations on ``clamp`` (ensure a variable is restricted to a given range) and
``swap`` (exchange the values of two variables). There are also functions for
Expand Down
1 change: 1 addition & 0 deletions src/axom/core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(core_serial_tests
core_map.hpp
core_flatmap.hpp
core_memory_management.hpp
core_numeric_array.hpp
core_numeric_limits.hpp
core_Path.hpp
core_stack_array.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
//
// SPDX-License-Identifier: (BSD-3-Clause)

#include "axom/core.hpp"
#include "axom/slic.hpp"
#include "axom/primal.hpp"
#include "axom/core/NumericArray.hpp"
#include "axom/core/execution/execution_space.hpp"
#include "axom/core/execution/for_all.hpp"
#include "axom/core/memory_management.hpp"

#include "gtest/gtest.h"

namespace primal = axom::primal;

//------------------------------------------------------------------------------
template <typename ExecSpace>
void check_numeric_array_policy()
{
constexpr int DIM = 3;
using NumericArrayType = primal::NumericArray<double, DIM>;
using NumericArrayType = axom::NumericArray<double, DIM>;

double* coords =
axom::allocate<double>(DIM, axom::execution_space<ExecSpace>::allocatorID());
Expand All @@ -41,7 +40,7 @@ TEST(primal_numeric_array, constructors)
{
constexpr int DIM = 5;
using CoordType = double;
using QArray = primal::NumericArray<CoordType, DIM>;
using QArray = axom::NumericArray<CoordType, DIM>;

QArray arr1;
EXPECT_EQ(QArray::size(), DIM);
Expand Down Expand Up @@ -82,19 +81,19 @@ TEST(primal_numeric_array, constructors)
EXPECT_EQ(arrHalfVec[i], expVal);
}

primal::NumericArray<int, 3> fromInitializerListRightSize = {10, 20, 30};
axom::NumericArray<int, 3> fromInitializerListRightSize = {10, 20, 30};
for(int i = 0; i < 3; ++i)
{
EXPECT_EQ(10 * (i + 1), fromInitializerListRightSize[i]);
}

primal::NumericArray<int, 3> fromInitializerListTooLong = {10, 20, 30, 40};
axom::NumericArray<int, 3> fromInitializerListTooLong = {10, 20, 30, 40};
for(int i = 0; i < 3; ++i)
{
EXPECT_EQ(10 * (i + 1), fromInitializerListTooLong[i]);
}

primal::NumericArray<int, 5> fromInitializerListTooShort = {10, 20};
axom::NumericArray<int, 5> fromInitializerListTooShort = {10, 20};
for(int i = 0; i < 2; ++i)
{
EXPECT_EQ(10 * (i + 1), fromInitializerListTooShort[i]);
Expand All @@ -104,7 +103,7 @@ TEST(primal_numeric_array, constructors)
EXPECT_EQ(0, fromInitializerListTooShort[i]);
}

primal::NumericArray<int, 3> fromInitializerNoEqualsSign {10, 20, 30};
axom::NumericArray<int, 3> fromInitializerNoEqualsSign {10, 20, 30};
for(int i = 0; i < 3; ++i)
{
EXPECT_EQ(10 * (i + 1), fromInitializerNoEqualsSign[i]);
Expand All @@ -116,7 +115,7 @@ TEST(primal_numeric_array, num_array_to_array)
{
constexpr int DIM = 5;
using CoordType = double;
using QArray = primal::NumericArray<CoordType, DIM>;
using QArray = axom::NumericArray<CoordType, DIM>;

// Compare array initialized from arbitrary array
CoordType valsArr[DIM] = {12., 23., 34., 45., 56.432};
Expand All @@ -142,7 +141,7 @@ TEST(primal_numeric_array, component_wise_arithmetic)
{
constexpr int DIM = 3;
using CoordType = double;
using QArray = primal::NumericArray<CoordType, DIM>;
using QArray = axom::NumericArray<CoordType, DIM>;

CoordType ca1[] = {3, 0, 1.2};
CoordType ca2[] = {0, 4, 1.2};
Expand Down Expand Up @@ -191,7 +190,7 @@ TEST(primal_numeric_array, component_min_max)
{
constexpr int DIM = 3;
using CoordType = int;
using QArray = primal::NumericArray<CoordType, DIM>;
using QArray = axom::NumericArray<CoordType, DIM>;

QArray incArr {1, 2, 3};
QArray decArr {3, 2, 1};
Expand Down Expand Up @@ -221,7 +220,7 @@ TEST(primal_numeric_array, component_sum)
{
constexpr int DIM = 3;
using CoordType = int;
using QArray = primal::NumericArray<CoordType, DIM>;
using QArray = axom::NumericArray<CoordType, DIM>;

QArray incArr {1, 2, 3};
QArray decArr {3, 2, 1};
Expand All @@ -241,7 +240,7 @@ TEST(primal_numeric_array, clamping)
{
constexpr int DIM = 3;
using CoordType = int;
using QArray = primal::NumericArray<CoordType, DIM>;
using QArray = axom::NumericArray<CoordType, DIM>;

CoordType seq[] = {15, 4, 2};
CoordType seqClampUp7[] = {7, 4, 2};
Expand Down Expand Up @@ -274,9 +273,9 @@ TEST(primal_numeric_array, clamping)

#ifdef AXOM_DEBUG
// NOTE: AXOM_DEBUG is disabled in release mode, so this test will only fail
// in
// debug mode
SLIC_INFO("Checking that clamping with ill-formed range throws an assert.");
// in debug mode
std::cout << "Checking that clamping with ill-formed range throws an assert."
<< std::endl;

::testing::FLAGS_gtest_death_test_style = "threadsafe";
EXPECT_DEATH_IF_SUPPORTED(QArray(seq).clamp(7, 3), "");
Expand Down Expand Up @@ -314,18 +313,3 @@ AXOM_CUDA_TEST(primal_numeric_array, numeric_array_check_policies)
check_numeric_array_policy<hip_exec>();
#endif
}

//----------------------------------------------------------------------
//----------------------------------------------------------------------

int main(int argc, char* argv[])
{
int result = 0;

::testing::InitGoogleTest(&argc, argv);
axom::slic::SimpleLogger logger;

result = RUN_ALL_TESTS();

return result;
}
2 changes: 1 addition & 1 deletion src/axom/multimat/multimat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ bool MultiMat::isValid(bool verboseOutput) const
}
for(unsigned int i = 0; i < volfrac_sum.size(); ++i)
{
if(abs(volfrac_sum[i] - 1.0) > 10e-9)
if(std::abs(volfrac_sum[i] - 1.0) > 10e-9)
{
errStr << "\n\t*Volfrac does not sum to 1.0 in cell " << i;
bValid = false;
Expand Down
1 change: 0 additions & 1 deletion src/axom/primal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ set( primal_headers
geometry/KnotVector.hpp
geometry/OrientedBoundingBox.hpp
geometry/OrientationResult.hpp
geometry/NumericArray.hpp
geometry/NURBSCurve.hpp
geometry/NURBSPatch.hpp
geometry/Plane.hpp
Expand Down
2 changes: 0 additions & 2 deletions src/axom/primal/docs/sphinx/primitive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Primal includes the following primitives:

.. note:: Primitives in Axom use a right-handed coordinate system.

Primal also provides the NumericArray class, which implements arithmetic
operations on numerical tuples and supports Primal's Point and Vector classes.
Classes in Primal are templated on coordinate type (double, float, etc.) and
dimension. The primitives do not inherit from a common base class. This was a
design choice in favor of simplicity and performance. Geometric primitives can
Expand Down
1 change: 0 additions & 1 deletion src/axom/primal/geometry/BezierCurve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "axom/core.hpp"
#include "axom/slic.hpp"

#include "axom/primal/geometry/NumericArray.hpp"
#include "axom/primal/geometry/Point.hpp"
#include "axom/primal/geometry/Vector.hpp"
#include "axom/primal/geometry/Segment.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/axom/primal/geometry/BezierPatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "axom/core.hpp"
#include "axom/slic.hpp"

#include "axom/primal/geometry/NumericArray.hpp"
#include "axom/primal/geometry/Point.hpp"
#include "axom/primal/geometry/Vector.hpp"
#include "axom/primal/geometry/Segment.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/axom/primal/geometry/CurvedPolygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include "axom/slic.hpp"

#include "axom/core/NumericArray.hpp"
#include "axom/primal/geometry/Point.hpp"
#include "axom/primal/geometry/Vector.hpp"
#include "axom/primal/geometry/NumericArray.hpp"
#include "axom/primal/geometry/BezierCurve.hpp"
#include "axom/primal/geometry/BoundingBox.hpp"

Expand Down Expand Up @@ -50,7 +50,7 @@ class CurvedPolygon
public:
using PointType = Point<T, NDIMS>;
using VectorType = Vector<T, NDIMS>;
using NumArrayType = NumericArray<T, NDIMS>;
using NumArrayType = axom::NumericArray<T, NDIMS>;
using BezierCurveType = BezierCurve<T, NDIMS>;
using BoundingBoxType = typename BezierCurveType::BoundingBoxType;

Expand Down
3 changes: 2 additions & 1 deletion src/axom/primal/geometry/Hexahedron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "axom/core/StackArray.hpp"

#include "axom/core/NumericArray.hpp"
#include "axom/primal/geometry/Point.hpp"
#include "axom/primal/geometry/Tetrahedron.hpp"
#include "axom/primal/geometry/Vector.hpp"
Expand Down Expand Up @@ -59,7 +60,7 @@ class Hexahedron
using PointType = Point<T, NDIMS>;
using VectorType = Vector<T, NDIMS>;
using TetrahedronType = Tetrahedron<T, NDIMS>;
using NumArrayType = NumericArray<T, NDIMS>;
using NumArrayType = axom::NumericArray<T, NDIMS>;

enum
{
Expand Down
2 changes: 1 addition & 1 deletion src/axom/primal/geometry/NURBSPatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "axom/core.hpp"
#include "axom/slic.hpp"

#include "axom/primal/geometry/NumericArray.hpp"
#include "axom/core/NumericArray.hpp"
#include "axom/primal/geometry/Point.hpp"
#include "axom/primal/geometry/Vector.hpp"
#include "axom/primal/geometry/Segment.hpp"
Expand Down
Loading