Commit 6c56e5d1 authored by kulvait's avatar kulvait

DenFileInfo statistics extension

parent b6e6ec70
...@@ -35,13 +35,19 @@ namespace io { ...@@ -35,13 +35,19 @@ namespace io {
template <typename T> template <typename T>
T getMinVal() const; T getMinVal() const;
template <typename T> template <typename T>
T getl2Square() const; double getl2Square() const;
template <typename T>
double getMean() const;
template <typename T>
double getVariance() const;
private: private:
std::string fileName; std::string fileName;
//Extended format means that the file has header 0,0,0 followed by the four dimensions so that the offset is 18 bytes and dimensions are stored in 6..9, 10..13 and 14..17 bytes as uint32_t // Extended format means that the file has header 0,0,0 followed by the four dimensions so
bool extended = false; // that the offset is 18 bytes and dimensions are stored in 6..9, 10..13 and 14..17 bytes as
uint64_t offset = 6; // uint32_t
bool extended = false;
uint64_t offset = 6;
}; };
template <typename T> template <typename T>
...@@ -207,7 +213,7 @@ namespace io { ...@@ -207,7 +213,7 @@ namespace io {
* @return |x|_2^2 * @return |x|_2^2
*/ */
template <typename T> template <typename T>
T DenFileInfo::getl2Square() const double DenFileInfo::getl2Square() const
{ {
DenSupportedType dataType = getDataType(); DenSupportedType dataType = getDataType();
uint64_t dim_x = dimx(); uint64_t dim_x = dimx();
...@@ -275,5 +281,60 @@ namespace io { ...@@ -275,5 +281,60 @@ namespace io {
} }
} }
template <typename T>
double DenFileInfo::getMean() const
{
DenSupportedType dataType = getDataType();
uint64_t dim_x = dimx();
uint64_t dim_y = dimy();
uint64_t dim_z = dimz();
uint64_t totalSize = dim_x * dim_y * dim_z;
uint64_t currentPosition;
uint32_t elementSize = elementByteSize();
double sum = 0.0;
double val;
uint8_t* buffer = new uint8_t[dim_x * dim_y * elementByteSize()];
for(uint64_t z = 0; z != dim_z; z++)
{
currentPosition = offset + z * dim_x * dim_y * elementSize;
io::readBytesFrom(fileName, currentPosition, buffer, dim_x * dim_y * elementSize);
for(uint64_t pos = 0; pos != dim_y * dim_x; pos++)
{
val = (double)util::getNextElement<T>(&buffer[pos * elementSize], dataType);
sum += val;
}
}
delete[] buffer;
return T(sum / totalSize);
}
template <typename T>
double DenFileInfo::getVariance() const
{
DenSupportedType dataType = getDataType();
uint32_t elementSize = elementByteSize();
uint64_t dim_x = dimx();
uint64_t dim_y = dimy();
uint64_t dim_z = dimz();
uint64_t totalSize = dim_x * dim_y * dim_z;
uint64_t currentPosition;
double sum = 0.0;
double val;
double mean = (double)getMean<T>();
uint8_t* buffer = new uint8_t[dim_x * dim_y * elementByteSize()];
for(uint64_t z = 0; z != dim_z; z++)
{
currentPosition = offset + z * dim_x * dim_y * elementSize;
io::readBytesFrom(fileName, currentPosition, buffer, dim_x * dim_y * 2);
for(uint64_t pos = 0; pos != dim_y * dim_x; pos++)
{
val = (double)util::getNextElement<T>(&buffer[pos * elementSize], dataType);
sum += (val - mean) * (val - mean);
}
}
delete[] buffer;
return T(sum / totalSize);
}
} // namespace io } // namespace io
} // namespace CTL } // namespace CTL
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