Skip to content

Commit c72899f

Browse files
tests
1 parent ccf2efc commit c72899f

2 files changed

Lines changed: 129 additions & 7 deletions

File tree

src/libs/conduit/conduit_data_accessor.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
namespace conduit
2828
{
2929

30+
//-----------------------------------------------------------------------------
31+
// -- begin conduit::detail --
32+
//-----------------------------------------------------------------------------
3033
namespace detail
3134
{
3235

36+
//-----------------------------------------------------------------------------
3337
template <typename T>
3438
void
35-
set_value_helper(const DataAccessor<T> &accessor,
36-
index_t idx,
37-
T value)
39+
set_value_helper(const DataAccessor<T> &accessor, index_t idx, T value)
3840
{
3941
switch(accessor.dtype().id())
4042
{
@@ -74,12 +76,13 @@ set_value_helper(const DataAccessor<T> &accessor,
7476
}
7577
}
7678

77-
template <typename T, typename Values>
79+
//-----------------------------------------------------------------------------
80+
template <typename T, typename U>
7881
void
79-
set_values_helper(const DataAccessor<T> &accessor,
80-
const Values &values,
81-
index_t num_elements)
82+
set_values_helper(const DataAccessor<T> &accessor, const U &values, index_t num_elements)
8283
{
84+
// Preserve DataAccessor semantics by converting source values through the
85+
// accessor's logical type T before converting to the destination dtype.
8386
switch(accessor.dtype().id())
8487
{
8588
case DataType::INT8_ID:
@@ -158,6 +161,9 @@ set_values_helper(const DataAccessor<T> &accessor,
158161
}
159162
}
160163
}
164+
//-----------------------------------------------------------------------------
165+
// -- end conduit::detail --
166+
//-----------------------------------------------------------------------------
161167

162168
//-----------------------------------------------------------------------------
163169
//

src/tests/conduit/t_conduit_data_accessor.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,122 @@ TEST(conduit_data_accessor, to_string)
288288
EXPECT_EQ(res,"[0, 0, 0, ..., 0, 0]");
289289
}
290290

291+
//-----------------------------------------------------------------------------
292+
TEST(conduit_data_accessor, set_using_ptrs)
293+
{
294+
//in this case we are using std vectors to init data conveniently
295+
// we are actually testing the pointer set cases
296+
// we test std vector set cases directly in "set_using_std_vectors"
297+
std::vector<int8> v_int8(10,-8);
298+
std::vector<int16> v_int16(10,-16);
299+
std::vector<int32> v_int32(10,-32);
300+
std::vector<int64> v_int64(10,-64);
301+
302+
std::vector<uint8> v_uint8(10,8);
303+
std::vector<uint16> v_uint16(10,16);
304+
std::vector<uint32> v_uint32(10,32);
305+
std::vector<uint64> v_uint64(10,64);
306+
307+
std::vector<float32> v_float32(10,32.0);
308+
std::vector<float64> v_float64(10,64.0);
309+
310+
311+
312+
Node n;
313+
314+
// int8_array
315+
n["vint8"].set(DataType::int8(10));
316+
n["vint8"].as_int8_accessor().set(&v_int8[0],10);
317+
int8 *n_int8_ptr = n["vint8"].value();
318+
for(size_t i=0;i<10;i++)
319+
{
320+
EXPECT_EQ(n_int8_ptr[i],v_int8[i]);
321+
}
322+
323+
// int16_array
324+
n["vint16"].set(DataType::int16(10));
325+
n["vint16"].as_int16_accessor().set(&v_int16[0],10);
326+
int16 *n_int16_ptr = n["vint16"].value();
327+
for(size_t i=0;i<10;i++)
328+
{
329+
EXPECT_EQ(n_int16_ptr[i],v_int16[i]);
330+
}
331+
332+
// int32_array
333+
n["vint32"].set(DataType::int32(10));
334+
n["vint32"].as_int32_accessor().set(&v_int32[0],10);
335+
int32 *n_int32_ptr = n["vint32"].value();
336+
for(size_t i=0;i<10;i++)
337+
{
338+
EXPECT_EQ(n_int32_ptr[i],v_int32[i]);
339+
}
340+
341+
// int64_array
342+
n["vint64"].set(DataType::int64(10));
343+
n["vint64"].as_int64_accessor().set(&v_int64[0],10);
344+
int64 *n_int64_ptr = n["vint64"].value();
345+
for(size_t i=0;i<10;i++)
346+
{
347+
EXPECT_EQ(n_int64_ptr[i],v_int64[i]);
348+
}
349+
350+
// uint8_array
351+
n["vuint8"].set(DataType::uint8(10));
352+
n["vuint8"].as_uint8_accessor().set(&v_uint8[0],10);
353+
uint8 *n_uint8_ptr = n["vuint8"].value();
354+
for(size_t i=0;i<10;i++)
355+
{
356+
EXPECT_EQ(n_uint8_ptr[i],v_uint8[i]);
357+
}
358+
359+
// uint16_array
360+
n["vuint16"].set(DataType::uint16(10));
361+
n["vuint16"].as_uint16_accessor().set(&v_uint16[0],10);
362+
uint16 *n_uint16_ptr = n["vuint16"].value();
363+
for(size_t i=0;i<10;i++)
364+
{
365+
EXPECT_EQ(n_uint16_ptr[i],v_uint16[i]);
366+
}
367+
368+
// uint32_array
369+
n["vuint32"].set(DataType::uint32(10));
370+
n["vuint32"].as_uint32_accessor().set(&v_uint32[0],10);
371+
uint32 *n_uint32_ptr = n["vuint32"].value();
372+
for(size_t i=0;i<10;i++)
373+
{
374+
EXPECT_EQ(n_uint32_ptr[i],v_uint32[i]);
375+
}
376+
377+
// uint64_array
378+
n["vuint64"].set(DataType::uint64(10));
379+
n["vuint64"].as_uint64_accessor().set(&v_uint64[0],10);
380+
uint64 *n_uint64_ptr = n["vuint64"].value();
381+
for(size_t i=0;i<10;i++)
382+
{
383+
EXPECT_EQ(n_uint64_ptr[i],v_uint64[i]);
384+
}
385+
386+
387+
// float32_array
388+
n["vfloat32"].set(DataType::float32(10));
389+
n["vfloat32"].as_float32_accessor().set(&v_float32[0],10);
390+
float32 *n_float32_ptr = n["vfloat32"].value();
391+
for(size_t i=0;i<10;i++)
392+
{
393+
EXPECT_EQ(n_float32_ptr[i],v_float32[i]);
394+
}
395+
396+
// float64_array
397+
n["vfloat64"].set(DataType::float64(10));
398+
n["vfloat64"].as_float64_accessor().set(&v_float64[0],10);
399+
float64 *n_float64_ptr = n["vfloat64"].value();
400+
for(size_t i=0;i<10;i++)
401+
{
402+
EXPECT_EQ(n_float64_ptr[i],v_float64[i]);
403+
}
404+
405+
}
406+
291407

292408
//-----------------------------------------------------------------------------
293409
TEST(conduit_data_accessor, set_using_data_array)

0 commit comments

Comments
 (0)