82 #ifndef ARRAY_UDF_UTILITY_H
83 #define ARRAY_UDF_UTILITY_H
86 #include <type_traits>
89 #include <sys/types.h>
105 #if __cplusplus > 201402L
109 #define V2VOIDP(vv) static_cast<void *>(vv.data())
162 std::string
ExtractPath(
const std::string &fullPath);
164 template <
typename T>
169 std::cout <<
"Rank " <<
ft_rank <<
", " << name <<
": ";
173 std::cout << std::endl;
179 for (
int i = 0; i < 4; i++)
181 std::cout << v[i] <<
",";
183 std::cout <<
" ... ";
184 for (
int i = n - 4; i < n - 1; i++)
186 std::cout << v[i] <<
",";
188 std::cout << v[n - 1];
192 for (
int i = 0; i < n - 1; i++)
194 std::cout << v[i] <<
",";
196 std::cout << v[n - 1];
198 std::cout << std::endl;
201 template <
typename T>
202 inline void PrintVV(std::string name, std::vector<std::vector<T>> v)
206 std::cout <<
"Rank " <<
ft_rank <<
", " << name <<
": ";
210 std::cout << std::endl;
216 for (
int i = 0; i < 4; i++)
220 std::cout <<
" ... \n";
221 for (
int i = n - 4; i < n; i++)
228 for (
int i = 0; i < n - 1; i++)
233 std::cout << std::endl;
236 template <
typename T>
240 std::cout <<
"Rank " <<
ft_rank <<
", " << name <<
": "
241 <<
": " << v << std::endl;
244 template <
typename T>
248 std::cout <<
"Rank " <<
ft_rank <<
", " << name << std::endl;
258 inline unsigned long long RowMajorOrder(std::vector<unsigned long long> dsize, std::vector<unsigned long long> coordinate)
260 unsigned long long offset = coordinate[0];
261 int n = dsize.size();
262 for (
int i = 1; i < n; i++)
264 offset = offset * dsize[i] + coordinate[i];
276 inline std::vector<unsigned long long>
RowMajorOrderReverse(
unsigned long long offset, std::vector<unsigned long long> dsize)
278 int n = dsize.size();
279 std::vector<unsigned long long> original_coordinate;
280 original_coordinate.resize(n);
282 for (
unsigned long long i = n - 1; i >= 1; i--)
284 original_coordinate[i] = offset % dsize[i];
285 offset = offset / dsize[i];
288 original_coordinate[0] = offset;
290 return original_coordinate;
302 template <
class T1,
class T2>
305 assert(attribute_vector.size() == virtual_array_vector.size());
306 size_t n = attribute_vector.size();
307 for (
size_t i = 0; i < n; i++)
309 T1 attribute_vector_value = attribute_vector[i];
311 cista::for_each_field(virtual_array_vector[i], [&m_index, attribute_index, attribute_vector_value, union_index](
auto &&m) {
312 if (m_index == attribute_index)
318 m = std::get<AU_SHORT>(attribute_vector_value);
323 m = std::get<AU_INT>(attribute_vector_value);
328 m = std::get<AU_LONG>(attribute_vector_value);
333 m = std::get<AU_LONG_LONG>(attribute_vector_value);
338 m = std::get<AU_USHORT>(attribute_vector_value);
343 m = std::get<AU_UINT>(attribute_vector_value);
348 m = std::get<AU_ULONG>(attribute_vector_value);
353 m = std::get<AU_ULLONG>(attribute_vector_value);
358 m = std::get<AU_FLOAT>(attribute_vector_value);
363 m = std::get<AU_DOUBLE>(attribute_vector_value);
367 std::cout <<
"Unsupported datatype in " << __FILE__ <<
" : " << __LINE__ << std::endl;
368 std::flush(std::cout);
369 std::exit(EXIT_FAILURE);
379 inline void InsertAttribute2VirtualArrayVector<AuEndpointDataTypeUnion, std::complex<double>>(
const std::vector<AuEndpointDataTypeUnion> &attribute_vector,
AuEndpointDataType union_index, std::vector<std::complex<double>> &virtual_array_vector,
int attribute_index)
381 AU_EXIT(
"std::complex does not work with cista::for_each_field now");
384 #define ExtractAttributeFromVirtualArrayVector_HELPER(ELEMENT_TYPE) \
386 ELEMENT_TYPE *attribute_data_typed = (ELEMENT_TYPE *)attribute_data_void_pointer; \
387 for (size_t i = 0; i < n; i++) \
390 ELEMENT_TYPE temp_attribute_value; \
391 cista::for_each_field(virtual_array_vector[i], [&m_index, attribute_index, &temp_attribute_value](auto &&m) { \
392 if (m_index == attribute_index) \
394 temp_attribute_value = m; \
398 attribute_data_typed[i] = temp_attribute_value; \
406 size_t n = virtual_array_vector.size();
407 void *attribute_data_void_pointer = malloc(n * element_type_size);
409 switch (element_type)
462 std::cout <<
"Unsupported datatype in " << __FILE__ <<
" : " << __LINE__ << std::endl;
463 std::flush(std::cout);
464 std::exit(EXIT_FAILURE);
466 return attribute_data_void_pointer;
470 inline void *ExtractAttributeFromVirtualArrayVector<std::complex<double>>(std::vector<std::complex<double>> &virtual_array_vector,
int attribute_index,
AuEndpointDataType element_type,
int element_type_size)
472 AU_EXIT(
"std::complex<double> does work with cista::to_tuple<");
481 template <
typename T>
484 std::ostringstream vts;
485 vts << std::setprecision(17);
489 std::copy(vec.begin(), std::prev(vec.end(), 1),
490 std::ostream_iterator<T>(vts,
","));
498 template <
typename T>
501 std::stringstream ss(str);
505 vec_new.push_back(i);
506 if (ss.peek() ==
',')
AuEndpointType
Definition: ft_type.h:95
AuEndpointDataType
Definition: ft_type.h:118
@ AU_LONG
Definition: ft_type.h:122
@ AU_ULLONG
Definition: ft_type.h:127
@ AU_DOUBLE
Definition: ft_type.h:129
@ AU_FLOAT
Definition: ft_type.h:128
@ AU_INT
Definition: ft_type.h:121
@ AU_ULONG
Definition: ft_type.h:126
@ AU_USHORT
Definition: ft_type.h:124
@ AU_LONG_LONG
Definition: ft_type.h:123
@ AU_SHORT
Definition: ft_type.h:120
@ AU_UINT
Definition: ft_type.h:125
std::string ExtractPath(const std::string &fullPath)
Definition: ft_utility.cpp:127
void PrintVV(std::string name, std::vector< std::vector< T >> v)
Definition: ft_utility.h:202
int ft_rank
Definition: ft.cpp:86
void * ExtractAttributeFromVirtualArrayVector(std::vector< T2 > &virtual_array_vector, int attribute_index, AuEndpointDataType element_type, int element_type_size)
Definition: ft_utility.h:403
std::string Vector2String(const std::vector< T > &vec)
Definition: ft_utility.h:482
void PrintVector(std::string name, std::vector< T > v)
Definition: ft_utility.h:165
std::vector< unsigned long long > RowMajorOrderReverse(unsigned long long offset, std::vector< unsigned long long > dsize)
convert linearized coordinate to multidimensional one
Definition: ft_utility.h:276
unsigned long long RowMajorOrder(std::vector< unsigned long long > dsize, std::vector< unsigned long long > coordinate)
convert coordinate to linearized one
Definition: ft_utility.h:258
std::vector< std::string > GetDirFileList(std::string dir_str_p)
Get file list of a direction.
Definition: ft_utility.cpp:133
std::string ExtractFileName(const std::string &fullPath)
Definition: ft_utility.cpp:121
void InsertAttribute2VirtualArrayVector(const std::vector< T1 > &attribute_vector, AuEndpointDataType union_index, std::vector< T2 > &virtual_array_vector, int attribute_index)
Definition: ft_utility.h:303
int ExtractEndpointTypeInfo(std::string endpoint_type_info, AuEndpointType &endpoint_type, std::string &endpoint_info)
Split endpoint_type_info string to type and information.
Definition: ft_utility.cpp:100
std::string realpathEx(std::string path)
expand the path to full directory https://www.dreamincode.net/forums/topic/218601-realpath-and-tilde/
Definition: ft_utility.cpp:83
void PrintString(std::string name)
Definition: ft_utility.h:245
#define ExtractAttributeFromVirtualArrayVector_HELPER(ELEMENT_TYPE)
Definition: ft_utility.h:384
void String2Vector(const std::string &str, std::vector< T > &vec_new)
Definition: ft_utility.h:499
void PrintScalar(std::string name, T v)
Definition: ft_utility.h:237
int file_exist(const char *filename)
Check wether the file exists.
Definition: ft_utility.cpp:115
#define AU_EXIT(info)
Definition: ft_utility_macro.h:147