-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
143 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include <vector> | ||
|
||
#include "nifty/xtensor/xtensor.hxx" | ||
|
||
|
||
namespace nifty{ | ||
namespace tools{ | ||
|
||
|
||
template<class ARRAY> | ||
void computeRLE(xt::xexpression<ARRAY> & dataExp, std::vector<int> & counts){ | ||
typedef typename ARRAY::value_type DataType; | ||
auto & data = dataExp.derived_cast(); | ||
|
||
auto val = data[0]; | ||
if(val == 1) { | ||
counts.push_back(0); | ||
} | ||
|
||
int count = 0; | ||
for(const auto & m : data) { | ||
if(val == m) { | ||
++count; | ||
} else { | ||
val = m; | ||
counts.push_back(count); | ||
count = 1; | ||
} | ||
} | ||
counts.push_back(count); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <pybind11/numpy.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include <typeinfo> // to debug atm | ||
|
||
#include "xtensor-python/pyarray.hpp" | ||
#include "nifty/tools/rle.hxx" | ||
|
||
namespace py = pybind11; | ||
|
||
|
||
|
||
namespace nifty{ | ||
namespace tools{ | ||
|
||
template<class T> | ||
void exportComputeRLET(py::module & toolsModule) { | ||
|
||
toolsModule.def("computeRLE", | ||
[](xt::pyarray<T> & dataIn){ | ||
|
||
std::vector<int> counts; | ||
{ | ||
py::gil_scoped_release allowThreads; | ||
tools::computeRLE(dataIn, counts); | ||
} | ||
return counts; | ||
}); | ||
} | ||
|
||
|
||
void exportComputeRLE(py::module & toolsModule) { | ||
exportComputeRLET<bool>(toolsModule); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters