This example show how to use Array in FasTensor to access data.
#include <iostream>
#include <stdarg.h>
#include <vector>
#include <stdlib.h>
using namespace std;
int main(
int argc,
char *argv[])
{
Array<float> *A = new Array<float>("EP_HDF5:./test-data/testf-16x16-array.h5:/testg/testd");
std::cout << "Read diagonal cells, via (...) operator: \n";
for (int i = 0; i < 16; i++)
{
std::cout << A->operator()(i, i) << " , ";
}
std::cout << " \n\n";
std::cout << "Read diagonal cells, via GetValue() method: \n";
for (int i = 0; i < 16; i++)
{
std::cout << A->GetValue(i, i) << " , ";
}
std::cout << " \n\n";
for (int i = 0; i < 16; i++)
{
A->SetValue(0.001, i, i);
}
std::cout << "Read diagonal cells, after SetValue(0.001, ...) method: \n";
for (int i = 0; i < 16; i++)
{
std::cout << A->GetValue(i, i) << " , ";
}
std::cout << " \n\n";
std::vector<unsigned long long> start = {0, 0};
std::vector<unsigned long long> end = {5, 5};
std::vector<float> datav(6 * 6);
A->ReadEndpoint(start, end, static_cast<void *>(datav.data()));
std::cout << "Read vector of cells [0,0]-[5,5], via ReadEndpoint() method: \n";
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
std::cout << datav[i * 6 + j] << ", ";
}
std::cout << " \n";
}
std::cout << " \n";
for (int i = 0; i < 6 * 6; i++)
{
datav[i] = datav[i] - 1.1;
}
A->WriteEndpoint(start, end, static_cast<void *>(datav.data()));
std::vector<float> datav_updated(6 * 6);
A->ReadEndpoint(start, end, static_cast<void *>(datav_updated.data()));
std::cout << "Read vector of cells [0,0]-[5,5], after WriteEndpoint() /w each cell - 1.1: \n";
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
std::cout << datav_updated[i * 6 + j] << ", ";
}
std::cout << " \n";
}
std::cout << " \n\n";
delete A;
return 0;
}
#define AU_Init(argc, argv)
Definition: ft.h:112
#define AU_Finalize()
Definition: ft.h:113
int main(int argc, char *argv[])
Definition: ft_example_array.cpp:100
Definition: ft_array.h:113