Skip to content

Commit 4f5287b

Browse files
authored
Merge pull request #1500 from LLNL/feature/gunney/move-numeric-array-to-core
Move `primal::NumericArray` to core
2 parents 95c0a46 + 5b9be47 commit 4f5287b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+134
-156
lines changed

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ to use Open Cascade's file I/O capabilities in support of Quest applications.
3737
of `loadExternalData` in `sidre::IOManager` and `sidre::Group`.
3838

3939
### Changed
40+
- `primal::NumericArray` has been moved to `core`. The header is `core/NumericArray.hpp`.
4041
- `quest::Shaper` and `quest::IntersectionShaper` constructors require a runtime policy.
4142
Changing the policy after construction is no longer supported.
4243
- Importing Conduit array data into `sidre::View` now allocates destination

src/axom/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ set(core_headers
6464
Map.hpp
6565
MapCollection.hpp
6666
FlatMap.hpp
67+
NumericArray.hpp
6768
NumericLimits.hpp
6869
Path.hpp
6970
RangeAdapter.hpp

src/axom/primal/geometry/NumericArray.hpp src/axom/core/NumericArray.hpp

+12-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "axom/core/Macros.hpp"
1010
#include "axom/core/utilities/Utilities.hpp"
11-
#include "axom/slic/interface/slic.hpp"
11+
#include <cassert>
1212

1313
// C/C++ includes
1414
#include <algorithm>
@@ -18,8 +18,6 @@
1818

1919
namespace axom
2020
{
21-
namespace primal
22-
{
2321
// Forward declare the templated classes and operator functions
2422
template <typename T, int SIZE>
2523
class NumericArray;
@@ -381,16 +379,16 @@ class NumericArray // NOLINT
381379

382380
private:
383381
AXOM_HOST_DEVICE
384-
void verifyIndex(int AXOM_DEBUG_PARAM(idx)) const
382+
void verifyIndex(int idx) const
385383
{
386-
SLIC_ASSERT(idx >= 0 && idx < SIZE);
384+
AXOM_UNUSED_VAR(idx);
385+
assert(idx >= 0 && idx < SIZE);
387386
}
388387

389388
protected:
390389
T m_components[SIZE]; /// The encapsulated array
391390
};
392391

393-
} // namespace primal
394392
} // namespace axom
395393

396394
//------------------------------------------------------------------------------
@@ -399,14 +397,12 @@ class NumericArray // NOLINT
399397

400398
namespace axom
401399
{
402-
namespace primal
403-
{
404400
//------------------------------------------------------------------------------
405401
template <typename T, int SIZE>
406402
AXOM_HOST_DEVICE NumericArray<T, SIZE>::NumericArray(T val, int sz)
407403
{
408404
// NOTE (KW): This should be a static assert in the class
409-
SLIC_ASSERT(SIZE >= 1);
405+
assert(SIZE >= 1);
410406

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

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

@@ -477,7 +473,7 @@ AXOM_HOST_DEVICE inline T* NumericArray<T, SIZE>::data()
477473
template <typename T, int SIZE>
478474
AXOM_HOST_DEVICE void NumericArray<T, SIZE>::to_array(T* arr) const
479475
{
480-
SLIC_ASSERT(arr != nullptr);
476+
assert(arr != nullptr);
481477
for(int dim = 0; dim < SIZE; ++dim)
482478
{
483479
arr[dim] = m_components[dim];
@@ -520,7 +516,7 @@ template <typename T, int SIZE>
520516
AXOM_HOST_DEVICE inline NumericArray<T, SIZE>& NumericArray<T, SIZE>::operator/=(
521517
double scalar)
522518
{
523-
SLIC_ASSERT(scalar != 0.);
519+
assert(scalar != 0.);
524520
return operator*=(1. / scalar);
525521
}
526522

@@ -544,7 +540,7 @@ AXOM_HOST_DEVICE inline NumericArray<T, SIZE>& NumericArray<T, SIZE>::operator/=
544540
{
545541
for(int i = 0; i < SIZE; ++i)
546542
{
547-
SLIC_ASSERT(v[i] != 0.);
543+
assert(v[i] != 0.);
548544
m_components[i] /= v[i];
549545
}
550546

@@ -582,7 +578,7 @@ template <typename T, int SIZE>
582578
inline NumericArray<T, SIZE>& NumericArray<T, SIZE>::clamp(const T& lowerVal,
583579
const T& upperVal)
584580
{
585-
SLIC_ASSERT(lowerVal <= upperVal);
581+
assert(lowerVal <= upperVal);
586582

587583
for(int i = 0; i < SIZE; ++i)
588584
{
@@ -834,13 +830,11 @@ AXOM_HOST_DEVICE inline NumericArray<T, SIZE> abs(const NumericArray<T, SIZE>& a
834830
return result;
835831
}
836832

837-
} // namespace primal
838833
} // namespace axom
839834

840-
/// Overload to format a primal::NumericArray using fmt
835+
/// Overload to format a axom::NumericArray using fmt
841836
template <typename T, int NDIMS>
842-
struct axom::fmt::formatter<axom::primal::NumericArray<T, NDIMS>>
843-
: ostream_formatter
837+
struct axom::fmt::formatter<axom::NumericArray<T, NDIMS>> : ostream_formatter
844838
{ };
845839

846840
#endif // AXOM_PRIMAL_NUMERIC_ARRAY_HPP_

src/axom/core/docs/sphinx/core_utilities.rst

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ filesystem example snippet.
3636
:end-before: _timer_end
3737
:language: C++
3838

39+
Axom provides the NumericArray class, which implements arithmetic
40+
operations on numerical tuples.
41+
3942
There are several other utility functions. Some are numerical functions such as
4043
variations on ``clamp`` (ensure a variable is restricted to a given range) and
4144
``swap`` (exchange the values of two variables). There are also functions for

src/axom/core/tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(core_serial_tests
2626
core_map.hpp
2727
core_flatmap.hpp
2828
core_memory_management.hpp
29+
core_numeric_array.hpp
2930
core_numeric_limits.hpp
3031
core_Path.hpp
3132
core_stack_array.hpp

src/axom/primal/tests/primal_numeric_array.cpp src/axom/core/tests/core_numeric_array.hpp

+18-34
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
//
44
// SPDX-License-Identifier: (BSD-3-Clause)
55

6-
#include "axom/core.hpp"
7-
#include "axom/slic.hpp"
8-
#include "axom/primal.hpp"
6+
#include "axom/core/NumericArray.hpp"
7+
#include "axom/core/execution/execution_space.hpp"
8+
#include "axom/core/execution/for_all.hpp"
9+
#include "axom/core/memory_management.hpp"
910

1011
#include "gtest/gtest.h"
1112

12-
namespace primal = axom::primal;
13-
1413
//------------------------------------------------------------------------------
1514
template <typename ExecSpace>
1615
void check_numeric_array_policy()
1716
{
1817
constexpr int DIM = 3;
19-
using NumericArrayType = primal::NumericArray<double, DIM>;
18+
using NumericArrayType = axom::NumericArray<double, DIM>;
2019

2120
double* coords =
2221
axom::allocate<double>(DIM, axom::execution_space<ExecSpace>::allocatorID());
@@ -41,7 +40,7 @@ TEST(primal_numeric_array, constructors)
4140
{
4241
constexpr int DIM = 5;
4342
using CoordType = double;
44-
using QArray = primal::NumericArray<CoordType, DIM>;
43+
using QArray = axom::NumericArray<CoordType, DIM>;
4544

4645
QArray arr1;
4746
EXPECT_EQ(QArray::size(), DIM);
@@ -82,19 +81,19 @@ TEST(primal_numeric_array, constructors)
8281
EXPECT_EQ(arrHalfVec[i], expVal);
8382
}
8483

85-
primal::NumericArray<int, 3> fromInitializerListRightSize = {10, 20, 30};
84+
axom::NumericArray<int, 3> fromInitializerListRightSize = {10, 20, 30};
8685
for(int i = 0; i < 3; ++i)
8786
{
8887
EXPECT_EQ(10 * (i + 1), fromInitializerListRightSize[i]);
8988
}
9089

91-
primal::NumericArray<int, 3> fromInitializerListTooLong = {10, 20, 30, 40};
90+
axom::NumericArray<int, 3> fromInitializerListTooLong = {10, 20, 30, 40};
9291
for(int i = 0; i < 3; ++i)
9392
{
9493
EXPECT_EQ(10 * (i + 1), fromInitializerListTooLong[i]);
9594
}
9695

97-
primal::NumericArray<int, 5> fromInitializerListTooShort = {10, 20};
96+
axom::NumericArray<int, 5> fromInitializerListTooShort = {10, 20};
9897
for(int i = 0; i < 2; ++i)
9998
{
10099
EXPECT_EQ(10 * (i + 1), fromInitializerListTooShort[i]);
@@ -104,7 +103,7 @@ TEST(primal_numeric_array, constructors)
104103
EXPECT_EQ(0, fromInitializerListTooShort[i]);
105104
}
106105

107-
primal::NumericArray<int, 3> fromInitializerNoEqualsSign {10, 20, 30};
106+
axom::NumericArray<int, 3> fromInitializerNoEqualsSign {10, 20, 30};
108107
for(int i = 0; i < 3; ++i)
109108
{
110109
EXPECT_EQ(10 * (i + 1), fromInitializerNoEqualsSign[i]);
@@ -116,7 +115,7 @@ TEST(primal_numeric_array, num_array_to_array)
116115
{
117116
constexpr int DIM = 5;
118117
using CoordType = double;
119-
using QArray = primal::NumericArray<CoordType, DIM>;
118+
using QArray = axom::NumericArray<CoordType, DIM>;
120119

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

147146
CoordType ca1[] = {3, 0, 1.2};
148147
CoordType ca2[] = {0, 4, 1.2};
@@ -191,7 +190,7 @@ TEST(primal_numeric_array, component_min_max)
191190
{
192191
constexpr int DIM = 3;
193192
using CoordType = int;
194-
using QArray = primal::NumericArray<CoordType, DIM>;
193+
using QArray = axom::NumericArray<CoordType, DIM>;
195194

196195
QArray incArr {1, 2, 3};
197196
QArray decArr {3, 2, 1};
@@ -221,7 +220,7 @@ TEST(primal_numeric_array, component_sum)
221220
{
222221
constexpr int DIM = 3;
223222
using CoordType = int;
224-
using QArray = primal::NumericArray<CoordType, DIM>;
223+
using QArray = axom::NumericArray<CoordType, DIM>;
225224

226225
QArray incArr {1, 2, 3};
227226
QArray decArr {3, 2, 1};
@@ -241,7 +240,7 @@ TEST(primal_numeric_array, clamping)
241240
{
242241
constexpr int DIM = 3;
243242
using CoordType = int;
244-
using QArray = primal::NumericArray<CoordType, DIM>;
243+
using QArray = axom::NumericArray<CoordType, DIM>;
245244

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

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

281280
::testing::FLAGS_gtest_death_test_style = "threadsafe";
282281
EXPECT_DEATH_IF_SUPPORTED(QArray(seq).clamp(7, 3), "");
@@ -314,18 +313,3 @@ AXOM_CUDA_TEST(primal_numeric_array, numeric_array_check_policies)
314313
check_numeric_array_policy<hip_exec>();
315314
#endif
316315
}
317-
318-
//----------------------------------------------------------------------
319-
//----------------------------------------------------------------------
320-
321-
int main(int argc, char* argv[])
322-
{
323-
int result = 0;
324-
325-
::testing::InitGoogleTest(&argc, argv);
326-
axom::slic::SimpleLogger logger;
327-
328-
result = RUN_ALL_TESTS();
329-
330-
return result;
331-
}

src/axom/multimat/multimat.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ bool MultiMat::isValid(bool verboseOutput) const
19361936
}
19371937
for(unsigned int i = 0; i < volfrac_sum.size(); ++i)
19381938
{
1939-
if(abs(volfrac_sum[i] - 1.0) > 10e-9)
1939+
if(std::abs(volfrac_sum[i] - 1.0) > 10e-9)
19401940
{
19411941
errStr << "\n\t*Volfrac does not sum to 1.0 in cell " << i;
19421942
bValid = false;

src/axom/primal/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ set( primal_headers
2828
geometry/KnotVector.hpp
2929
geometry/OrientedBoundingBox.hpp
3030
geometry/OrientationResult.hpp
31-
geometry/NumericArray.hpp
3231
geometry/NURBSCurve.hpp
3332
geometry/NURBSPatch.hpp
3433
geometry/Plane.hpp

src/axom/primal/docs/sphinx/primitive.rst

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Primal includes the following primitives:
1515

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

18-
Primal also provides the NumericArray class, which implements arithmetic
19-
operations on numerical tuples and supports Primal's Point and Vector classes.
2018
Classes in Primal are templated on coordinate type (double, float, etc.) and
2119
dimension. The primitives do not inherit from a common base class. This was a
2220
design choice in favor of simplicity and performance. Geometric primitives can

src/axom/primal/geometry/BezierCurve.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "axom/core.hpp"
1616
#include "axom/slic.hpp"
1717

18-
#include "axom/primal/geometry/NumericArray.hpp"
1918
#include "axom/primal/geometry/Point.hpp"
2019
#include "axom/primal/geometry/Vector.hpp"
2120
#include "axom/primal/geometry/Segment.hpp"

src/axom/primal/geometry/BezierPatch.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "axom/core.hpp"
1616
#include "axom/slic.hpp"
1717

18-
#include "axom/primal/geometry/NumericArray.hpp"
1918
#include "axom/primal/geometry/Point.hpp"
2019
#include "axom/primal/geometry/Vector.hpp"
2120
#include "axom/primal/geometry/Segment.hpp"

src/axom/primal/geometry/CurvedPolygon.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#include "axom/slic.hpp"
1616

17+
#include "axom/core/NumericArray.hpp"
1718
#include "axom/primal/geometry/Point.hpp"
1819
#include "axom/primal/geometry/Vector.hpp"
19-
#include "axom/primal/geometry/NumericArray.hpp"
2020
#include "axom/primal/geometry/BezierCurve.hpp"
2121
#include "axom/primal/geometry/BoundingBox.hpp"
2222

@@ -50,7 +50,7 @@ class CurvedPolygon
5050
public:
5151
using PointType = Point<T, NDIMS>;
5252
using VectorType = Vector<T, NDIMS>;
53-
using NumArrayType = NumericArray<T, NDIMS>;
53+
using NumArrayType = axom::NumericArray<T, NDIMS>;
5454
using BezierCurveType = BezierCurve<T, NDIMS>;
5555
using BoundingBoxType = typename BezierCurveType::BoundingBoxType;
5656

src/axom/primal/geometry/Hexahedron.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "axom/core/StackArray.hpp"
1010

11+
#include "axom/core/NumericArray.hpp"
1112
#include "axom/primal/geometry/Point.hpp"
1213
#include "axom/primal/geometry/Tetrahedron.hpp"
1314
#include "axom/primal/geometry/Vector.hpp"
@@ -59,7 +60,7 @@ class Hexahedron
5960
using PointType = Point<T, NDIMS>;
6061
using VectorType = Vector<T, NDIMS>;
6162
using TetrahedronType = Tetrahedron<T, NDIMS>;
62-
using NumArrayType = NumericArray<T, NDIMS>;
63+
using NumArrayType = axom::NumericArray<T, NDIMS>;
6364

6465
enum
6566
{

src/axom/primal/geometry/NURBSPatch.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "axom/core.hpp"
1616
#include "axom/slic.hpp"
1717

18-
#include "axom/primal/geometry/NumericArray.hpp"
18+
#include "axom/core/NumericArray.hpp"
1919
#include "axom/primal/geometry/Point.hpp"
2020
#include "axom/primal/geometry/Vector.hpp"
2121
#include "axom/primal/geometry/Segment.hpp"

0 commit comments

Comments
 (0)