Commit 88c84b19 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add macro to get the fixed dimention of a tensor. And add corresponding unit test, OK

parent ec8b2219
Pipeline #93583 passed with stages
in 4 minutes and 48 seconds
......@@ -14,5 +14,5 @@ add_subdirectory(TEST_TYPE)
add_subdirectory(TEST_TYPE_T)
add_subdirectory(TEST_TABLE_CONFIG)
add_subdirectory(TEST_TABLE_FIXED_SIZE)
add_subdirectory(TEST_TABLE_FIXED_SIZE_2)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
call_generator(test_table_config_fixed_size2_lib configTableFixedSize2.ph5)
add_executable(test_table_config_fixed_size2 main.cpp)
target_link_libraries(test_table_config_fixed_size2 test_table_config_fixed_size2_lib ${HDF5_CXX_LIBRARIES})
add_test(NAME TestTableConfigFixedSize2
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_table_config_fixed_size2
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
///Table of types
TableVertex{
///Event id
size_t eventId;
///Timestamp
double timestamp;
///Short value
Tensor(float, 3, 2) tabVertex;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "configTableFixedSize2.h"
///Test to write data
/** @param fileName : name of the file to be written
* @return true on success, false otherwise
*/
bool testWriteData(const std::string & fileName){
TableVertex table;
size_t nbRow(10lu);
table.resize(nbRow);
//Let's set some values in the Table
for(size_t i(0lu); i < nbRow; ++i){
table.setEventId(i, i);
table.setTimestamp(i, 2lu*i);
float * tabVertex = table.getTabVertex(i);
size_t nbVal(TABLEVERTEX_TABVERTEX_0*TABLEVERTEX_TABVERTEX_1);
for(size_t j(0lu); j < nbVal; ++j){
tabVertex[j] = i*(j + 1lu);
}
}
//Now let's open a file
H5::H5File file(fileName, H5F_ACC_TRUNC);
//And write our table directly in it
table.write(file);
//We can also explicitly cloase the file, otherwise it will do it automatically
file.close();
return true;
}
///Test to read data
/** @param fileName : name of the file to be read
* @return true on success, false otherwise
*/
bool testReadData(const std::string & fileName){
//First let's open a file in read only mode (better for concurencial access)
H5::H5File file(fileName, H5F_ACC_RDONLY);
//Let's create our table
TableVertex table;
//Add read the file
table.read(file);
//Now we can close the file and use the Table directly
file.close();
//Get the number of rows and number of columns
size_t nbRow = table.getNbRow();
bool b(true);
for(size_t i(0lu); i < nbRow; ++i){
b &= table.getEventId(i) == i;
b &= table.getTimestamp(i) == 2lu*i;
float * tabVertex = table.getTabVertex(i);
size_t nbVal(TABLEVERTEX_TABVERTEX_0*TABLEVERTEX_TABVERTEX_1);
for(size_t j(0lu); j < nbVal; ++j){
b &= tabVertex[j] == i*(j + 1lu);
}
}
return b;
}
int main(int argc, char** argv){
std::string fileName("configTable.h5");
if(!testWriteData(fileName)){
std::cerr << "Cannot write file '"<<fileName<<"'" << std::endl;
return -1;
}
if(!testReadData(fileName)){
std::cerr << "Cannot read file '"<<fileName<<"'" << std::endl;
return -1;
}
return 0;
}
This diff is collapsed.
......@@ -9,7 +9,7 @@
#include "Representation/representation.h"
bool ph5_backend(const PSource & source, const std::string & outputDir);
bool ph5_backend(const PVecSource & vecSource, const std::string & outputDir);
bool ph5_backend(PSource & source, const std::string & outputDir);
bool ph5_backend(PVecSource & vecSource, const std::string & outputDir);
#endif
......@@ -204,7 +204,7 @@ bool ConfigParser::parseDimention(PDimention & dim){
bool isNumber = isStrNumber(token);
dim.setIsValue(isNumber);
if(isNumber){
dim.setValue(atol(token.c_str()));
dim.setValue(token);
}else{
dim.setName(token);
}
......
......@@ -43,7 +43,7 @@ void PDimention::setName(const std::string & name){
///Sets the value of the PDimention
/** @param value : value of the PDimention
*/
void PDimention::setValue(const size_t & value){
void PDimention::setValue(const std::string & value){
p_value = value;
}
......@@ -71,14 +71,14 @@ std::string & PDimention::getName(){
///Gets the value of the PDimention
/** @return value of the PDimention
*/
const size_t & PDimention::getValue() const{
const std::string & PDimention::getValue() const{
return p_value;
}
///Gets the value of the PDimention
/** @return value of the PDimention
*/
size_t & PDimention::getValue(){
std::string & PDimention::getValue(){
return p_value;
}
......
......@@ -18,12 +18,12 @@ class PDimention{
virtual ~PDimention();
PDimention & operator = (const PDimention & other);
void setName(const std::string & name);
void setValue(const size_t & value);
void setValue(const std::string & value);
void setIsValue(bool isValue);
const std::string & getName() const;
std::string & getName();
const size_t & getValue() const;
size_t & getValue();
const std::string & getValue() const;
std::string & getValue();
bool getIsValue() const;
bool & getIsValue();
protected:
......@@ -32,7 +32,7 @@ class PDimention{
///Name of the variable associated to this dimention
std::string p_name;
///Fixed value of the dimention
size_t p_value;
std::string p_value;
///True if the Dimention is a fixed value
bool p_isValue;
};
......
......@@ -7,7 +7,7 @@ PDimention{
///Name of the variable associated to this dimention
std::string name;
///Fixed value of the dimention
size_t value;
std::string value;
///True if the Dimention is a fixed value
bool isValue;
}
......
......@@ -15,7 +15,7 @@
*/
std::string ph5_dimentionToStr(const PDimention & dim, const std::string & prefix){
if(dim.getIsValue()){
return convertToString(dim.getValue()) + "lu";
return dim.getValue();
}else{
return prefix + dim.getName();
}
......
......@@ -10,6 +10,7 @@
#include "PRepr.h"
typedef std::vector<std::string> PVecStr;
typedef std::vector<size_t> PVecSizet;
typedef std::vector<PDimention> PVecDim;
typedef std::vector<PAttribute> PVecAttribute;
typedef std::vector<PTable> PVecTable;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment