Skip to content
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
#### Conduit
- Added `CONDUIT_VERSION_VALUE` macro that encodes the current Conduit version as an integer.
- Added a macro to make an integer a version number from major, minor, patch version numbers. Example: `CONDUIT_MAKE_VERSION_VALUE(0, 9, 6)`. This macro can be used to conditionally compile code that is valid for specific versions of Conduit.
- Added `set` methods to `DataAccessor` that take `DataArray`s and `DataAccessor`s.

#### Blueprint
- Finished `bent_multi_grid_amr` mesh by adding adjacency sets between spatially adjacent domains at the same level of refinement.
Expand Down
28 changes: 27 additions & 1 deletion src/docs/sphinx/tutorial_cpp_numeric.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ Alternately, we can use a DataAccessor to do the conversion as needed.
:start-after: BEGIN_EXAMPLE("numeric_data_accessor")
:end-before: END_EXAMPLE("numeric_data_accessor")
:language: cpp
:dedent: 4

.. literalinclude:: t_conduit_docs_tutorial_numeric_out.txt
:start-after: BEGIN_EXAMPLE("numeric_data_accessor")
Expand All @@ -152,6 +151,33 @@ array passed to it. The DataAccessor casts each value as needed on access, thus
incurring a small cost at each access. The DataAccessor is also safer and
simpler to use.

It is also possible to convert between DataAccessors and DataArrays using their
set methods. Below is an example of conversion from a DataArray to a DataAccessor.
It is possible to convert from a DataAccessor to a DataArray as well.

.. code-block:: c++

int64 i_vals[4] = {100,200,300,400};

Node n;
n["ints"].set(i_vals,
2, // # of elements
0, // offset in bytes
sizeof(int64)*2); // stride in bytes

int64_array vals_arr = n["ints"].value();
n["floats"].set(DataType::float64(2));
float64_accessor vals_acc = n["floats"].as_float64_accessor();
vals_acc.set(vals_arr);

std::cout << vals_acc[0] << std::endl;
std::cout << vals_acc[1] << std::endl;

::

100.0
300.0


C++11 Initializer Lists
-----------------------------------
Expand Down
281 changes: 281 additions & 0 deletions src/libs/conduit/conduit_data_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <limits>
#include <type_traits>

//-----------------------------------------------------------------------------
// -- conduit includes --
//-----------------------------------------------------------------------------
#include "conduit_data_array.hpp"

//-----------------------------------------------------------------------------
// -- begin conduit:: --
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -379,6 +384,282 @@ DataAccessor<T>::fill(T value)
}
}

//---------------------------------------------------------------------------//
//***************************************************************************//
// Set from DataAccessor
//***************************************************************************//
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
// Set from DataAccessor signed integers
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<int8> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<int16> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<int32> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<int64> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
// Set from DataAccessor unsigned integers
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<uint8> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<uint16> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<uint32> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<uint64> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
// Set from DataAccessor floating point
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<float32> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataAccessor<float64> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
//***************************************************************************//
// Set from DataArray
//***************************************************************************//
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
// Set from DataArray signed integers
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<int8> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<int16> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<int32> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<int64> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
// Set from DataArray unsigned integers
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<uint8> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<uint16> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<uint32> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<uint64> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
// Set from DataArray floating point
//---------------------------------------------------------------------------//

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<float32> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}

//---------------------------------------------------------------------------//
template <typename T>
void
DataAccessor<T>::set(const DataArray<float64> &values)
{
index_t num_elems = dtype().number_of_elements();
for(index_t i=0; i <num_elems; i++)
{
this->set(i, (T)values[i]);
}
}


//---------------------------------------------------------------------------//
template <typename T>
Expand Down
41 changes: 40 additions & 1 deletion src/libs/conduit/conduit_data_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
namespace conduit
{

//-----------------------------------------------------------------------------
// -- forward declarations required for conduit::DataAccessor --
//-----------------------------------------------------------------------------
template <typename T>
class DataArray;

//-----------------------------------------------------------------------------
// -- begin conduit::DataArray --
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -98,7 +104,40 @@ class CONDUIT_API DataAccessor
const DataType &dtype() const
{ return m_dtype;}


//-----------------------------------------------------------------------------
// Setters
//-----------------------------------------------------------------------------
/// signed integer arrays via DataArray
void set(const DataArray<int8> &values);
void set(const DataArray<int16> &values);
void set(const DataArray<int32> &values);
void set(const DataArray<int64> &values);

/// unsigned integer arrays via DataArray
void set(const DataArray<uint8> &values);
void set(const DataArray<uint16> &values);
void set(const DataArray<uint32> &values);
void set(const DataArray<uint64> &values);

/// floating point arrays via DataArray
void set(const DataArray<float32> &values);
void set(const DataArray<float64> &values);

/// signed integer arrays via DataAccessor
void set(const DataAccessor<int8> &values);
void set(const DataAccessor<int16> &values);
void set(const DataAccessor<int32> &values);
void set(const DataAccessor<int64> &values);

/// unsigned integer arrays via DataAccessor
void set(const DataAccessor<uint8> &values);
void set(const DataAccessor<uint16> &values);
void set(const DataAccessor<uint32> &values);
void set(const DataAccessor<uint64> &values);

/// floating point arrays via DataAccessor
void set(const DataAccessor<float32> &values);
void set(const DataAccessor<float64> &values);

//-----------------------------------------------------------------------------
// Transforms
Expand Down
Loading
Loading