Skip to content

Commit

Permalink
Merge 5a1c967 into b3d1ba0
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Feb 1, 2021
2 parents b3d1ba0 + 5a1c967 commit a0eeeaa
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
- Added support for using C++11 initializer lists to set Node and DataArray values from numeric arrays. See C++ tutorial docs (https://llnl-conduit.readthedocs.io/en/latest/tutorial_cpp_numeric.html#c-11-initializer-lists) for more details.
- Added a Node::describe() method. This method creates a new node that mirrors the current Node, however each leaf is replaced by summary stats and a truncated display of the values. For use cases with large leaves, printing the describe() output Node is much more helpful for debugging and understanding vs wall of text from other to_string() methods.
- Added conduit::utils::format methods. These methods use fmt to format strings that include fmt style patterns. The formatting arguments are passed as a conduit::Node tree. The `args` case allows named arguments (args passed as object) or ordered args (args passed as list). The `maps` case also supports named or ordered args and works in conjunction with a `map_index`. The `map_index` is used to fetch a value from an array, or list of strings, which is then passed to fmt. The `maps` style of indexed indirection supports generating path strings for non-trivial domain partition mappings in Blueprint. This functionality is also available in Python, via the `conduit.utils.format` method.
- Added DataArray::fill method, which set all elements of a DataArray to a given value.


#### Relay
Expand Down
127 changes: 127 additions & 0 deletions src/libs/conduit/conduit_data_array.cpp
Expand Up @@ -1066,6 +1066,133 @@ DataArray<T>::set(const std::initializer_list<double> &values)
//---------------------------------------------------------------------------//



//-----------------------------------------------------------------------------
// fill
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
/// signed integer fill
//-----------------------------------------------------------------------------

//---------------------------------------------------------------------------//
template <typename T>
void
DataArray<T>::fill(int8 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(int16 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(int32 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(int64 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
/// unsigned integer fill
//-----------------------------------------------------------------------------

//---------------------------------------------------------------------------//
template <typename T>
void
DataArray<T>::fill(uint8 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(uint16 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(uint32 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(uint64 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
/// floating point fill
//-----------------------------------------------------------------------------

//---------------------------------------------------------------------------//
template <typename T>
void
DataArray<T>::fill(float32 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//-----------------------------------------------------------------------------
template <typename T>
void
DataArray<T>::fill(float64 value)
{
for(index_t i=0;i < m_dtype.number_of_elements(); i++)
{
this->element(i) = (T)value;
}
}

//---------------------------------------------------------------------------//
// assign operator overloads for initializer_list
//---------------------------------------------------------------------------//
Expand Down
19 changes: 19 additions & 0 deletions src/libs/conduit/conduit_data_array.hpp
Expand Up @@ -296,6 +296,25 @@ class CONDUIT_API DataArray
void set(const DataArray<float32> &values);
void set(const DataArray<float64> &values);

//-----------------------------------------------------------------------------
// fill
//-----------------------------------------------------------------------------
/// signed integer fill
void fill(int8 value);
void fill(int16 value);
void fill(int32 value);
void fill(int64 value);

/// unsigned integer fill
void fill(uint8 value);
void fill(uint16 value);
void fill(uint32 value);
void fill(uint64 value);

/// floating point fill
void fill(float32 value);
void fill(float64 value);

//-----------------------------------------------------------------------------
// Transforms
//-----------------------------------------------------------------------------
Expand Down
102 changes: 102 additions & 0 deletions src/tests/conduit/t_conduit_array.cpp
Expand Up @@ -604,6 +604,105 @@ TEST(conduit_array, print_bells_and_whistles)
std::cout << std::endl;
}

//-----------------------------------------------------------------------------
TEST(conduit_array, fill)
{
int num_ele = 5;

std::vector<int8> v_int8(num_ele,-8);
std::vector<int16> v_int16(num_ele,-16);
std::vector<int32> v_int32(num_ele,-32);
std::vector<int64> v_int64(num_ele,-64);

std::vector<uint8> v_uint8(num_ele,8);
std::vector<uint16> v_uint16(num_ele,16);
std::vector<uint32> v_uint32(num_ele,32);
std::vector<uint64> v_uint64(num_ele,64);

std::vector<float32> v_float32(num_ele,32.0);
std::vector<float64> v_float64(num_ele,64.0);

Node n;
n["v_int8"].set(v_int8);
n["v_int16"].set(v_int16);
n["v_int32"].set(v_int32);
n["v_int64"].set(v_int64);

n["v_uint8"].set(v_uint8);
n["v_uint16"].set(v_uint16);
n["v_uint32"].set(v_uint32);
n["v_uint64"].set(v_uint64);

n["v_float32"].set(v_float32);
n["v_float64"].set(v_float64);

n.print();

int8_array va_int8 = n["v_int8"].value();
int16_array va_int16 = n["v_int16"].value();
int32_array va_int32 = n["v_int32"].value();
int64_array va_int64 = n["v_int64"].value();

uint8_array va_uint8 = n["v_uint8"].value();
uint16_array va_uint16 = n["v_uint16"].value();
uint32_array va_uint32 = n["v_uint32"].value();
uint64_array va_uint64 = n["v_uint64"].value();

float32_array va_float32 = n["v_float32"].value();
float64_array va_float64 = n["v_float64"].value();

for(size_t i=0;i<num_ele; i++)
{
EXPECT_NE(va_int8[i],-1);
EXPECT_NE(va_int16[i],-1);
EXPECT_NE(va_int32[i],-1);
EXPECT_NE(va_int64[i],-1);

EXPECT_NE(va_uint8[i],1);
EXPECT_NE(va_uint16[i],1);
EXPECT_NE(va_uint32[i],1);
EXPECT_NE(va_uint64[i],1);

EXPECT_NE(va_float32[i],1.0);
EXPECT_NE(va_float64[i],1.0);
}


// not all combos of src to dest, but all combos of src.
va_int8.fill((int8) -1);
va_int16.fill((int16) -1);
va_int32.fill((int32) -1);
va_int64.fill((int32) -1);

va_uint8.fill((uint8) 1);
va_uint16.fill((uint16) 1);
va_uint32.fill((uint32) 1);
va_uint64.fill((uint32) 1);

va_float32.fill((int32) 1.0);
va_float64.fill((int32) 1.0);

n.print();

for(size_t i=0;i<num_ele; i++)
{
EXPECT_EQ(va_int8[i],-1);
EXPECT_EQ(va_int16[i],-1);
EXPECT_EQ(va_int32[i],-1);
EXPECT_EQ(va_int64[i],-1);

EXPECT_EQ(va_uint8[i],1);
EXPECT_EQ(va_uint16[i],1);
EXPECT_EQ(va_uint32[i],1);
EXPECT_EQ(va_uint64[i],1);

EXPECT_EQ(va_float32[i],1.0);
EXPECT_EQ(va_float64[i],1.0);
}

}



//-----------------------------------------------------------------------------
#ifdef CONDUIT_USE_CXX11
Expand Down Expand Up @@ -1322,3 +1421,6 @@ TEST(conduit_array, cxx_11_init_lists)
//-----------------------------------------------------------------------------





0 comments on commit a0eeeaa

Please sign in to comment.