Skip to content

Commit

Permalink
Merge 5c28860 into 0b6a8c8
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrewe committed Aug 22, 2018
2 parents 0b6a8c8 + 5c28860 commit 684670e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 18 deletions.
4 changes: 3 additions & 1 deletion include/nix/DataView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class NIXAPI DataView : public DataSet {
virtual NDSize dataExtent() const;
virtual DataType dataType() const;

Dimension getDimension(ndsize_t idx) const;

protected:
void ioRead(DataType dtype,
void *data,
Expand All @@ -53,4 +55,4 @@ class NIXAPI DataView : public DataSet {

} // nix::

#endif // DATA_VIEW_HPP
#endif // DATA_VIEW_HPP
9 changes: 9 additions & 0 deletions include/nix/MultiTag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ class NIXAPI MultiTag : public base::EntityWithSources<base::IMultiTag> {
return backend()->positions();
}

/**
* @brief Returns the number of tagged positions.
*
* @return The number of positions tagging the referenced data.
*/
ndsize_t positionCount() const {
return positions().dataExtent()[0];
}

/**
* @brief Setter for the positions of the tag.
*
Expand Down
32 changes: 24 additions & 8 deletions include/nix/util/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <unordered_set>
#include <string>
#include <iostream>
#include <boost/regex.hpp>
namespace nix {
namespace util {

Expand Down Expand Up @@ -89,16 +90,23 @@ struct IdsFilter : public Filter<T> {
template<typename T>
struct TypeFilter : public Filter<T> {

const std::string type;
boost::regex expression;


TypeFilter(const std::string &str)
: type(str)
TypeFilter(const std::string &str) {
std::string temp = "^" + str + "$";
expression = boost::regex(temp);
}


TypeFilter(const boost::regex &expr)
: expression(expr)
{}


virtual bool operator()(const T &e) {
return e.type() == type;
boost::smatch matches;
return boost::regex_search(e.type(), matches, expression);
}

};
Expand All @@ -107,16 +115,23 @@ struct TypeFilter : public Filter<T> {
template<typename T>
struct NameFilter : public Filter<T> {

const std::string name;
boost::regex expression;


NameFilter(const std::string &str)
: name(str)
NameFilter(const std::string &str) {
std::string temp = "^" + str + "$";
expression = boost::regex(temp);
}


NameFilter(const boost::regex &expr)
: expression(expr)
{}


virtual bool operator()(const T &e) {
return e.name() == name;
boost::smatch matches;
return boost::regex_search(e.name(), matches, expression);
}

};
Expand All @@ -141,6 +156,7 @@ struct MetadataFilter : public Filter<T> {
}

}

};


Expand Down
11 changes: 10 additions & 1 deletion src/DataView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ NDSize DataView::dataExtent() const {
return count;
}


Dimension DataView::getDimension(ndsize_t idx) const {
if (idx <=0 || idx > this->array.dimensionCount()) {
throw nix::OutOfBounds("Trying to access a dimension out of range", 0);
}
return this->array.getDimension(idx);
}


NDSize DataView::transform_coordinates(const NDSize &cnt, const NDSize &off) const {

if (!off) {
Expand Down Expand Up @@ -60,4 +69,4 @@ DataType DataView::dataType() const {
return array.dataType();
}

}
}
8 changes: 8 additions & 0 deletions test/BaseTestBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <iterator>
#include <boost/math/constants/constants.hpp>
#include <boost/regex.hpp>

#include <nix/hydra/multiArray.hpp>

Expand Down Expand Up @@ -160,6 +161,13 @@ void BaseTestBlock::testDataArrayAccess() {
CPPUNIT_ASSERT(name && *name == "data_array_c");
}

filteredArrays = block.dataArrays(util::NameFilter<DataArray>("array"));
CPPUNIT_ASSERT(filteredArrays.size() == 0);

boost::regex expression("ARRAY", boost::regex::icase);
filteredArrays = block.dataArrays(util::NameFilter<DataArray>(expression));
CPPUNIT_ASSERT(filteredArrays.size() == names.size());

for (auto it = ids.begin(); it != ids.end(); it++) {
CPPUNIT_ASSERT(block.hasDataArray(*it));
CPPUNIT_ASSERT(block.getDataArray(*it).id() == *it);
Expand Down
8 changes: 8 additions & 0 deletions test/BaseTestDataAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ void BaseTestDataAccess::testRetrieveData() {
CPPUNIT_ASSERT(data_size.size() == 3);
CPPUNIT_ASSERT(data_size[0] == 1 && data_size[1] == 7 && data_size[2] == 2);

CPPUNIT_ASSERT_THROW(data_view.getDimension(0), nix::OutOfBounds);
CPPUNIT_ASSERT_THROW(data_view.getDimension(data_size.size() + 1), nix::OutOfBounds);
for (size_t i = 1; i == data_size.size(); ++i){
CPPUNIT_ASSERT_NO_THROW(data_view.getDimension(i));
CPPUNIT_ASSERT_EQUAL(data_view.getDimension(i).dimensionType(),
data_array.getDimension(i).dimensionType());
}

DataView times_view = util::retrieveData(times_tag, 0);
data_size = times_view.dataExtent();
std::vector<double> times(data_size.size());
Expand Down
1 change: 1 addition & 0 deletions test/BaseTestMultiTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void BaseTestMultiTag::testPositions() {
CPPUNIT_ASSERT_THROW(tag.positions(""), EmptyString);

tag.positions(positions);
CPPUNIT_ASSERT(tag.positionCount() == positions.dataExtent()[0]);
CPPUNIT_ASSERT(tag.positions().id() == positions.id());
CPPUNIT_ASSERT(tag.hasPositions());
block.deleteDataArray(positions.id());
Expand Down
39 changes: 31 additions & 8 deletions test/BaseTestSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sstream>
#include <iterator>
#include <stdexcept>
#include <boost/regex.hpp>

#include <nix/util/util.hpp>
#include <nix/valid/validate.hpp>
Expand Down Expand Up @@ -126,7 +127,7 @@ void BaseTestSource::testSourceAccess() {

void BaseTestSource::testFindSource() {
/* We create the following tree:
*
*
* source---l1n1---l2n1---l3n1
* | | |
* | ------l2n2
Expand All @@ -135,7 +136,7 @@ void BaseTestSource::testFindSource() {
* | |
* | ------l3n3
* ------l1n2
* |
* |
* ------l1n3---l2n4
* |
* ------l2n5---l3n4
Expand All @@ -162,7 +163,7 @@ void BaseTestSource::testFindSource() {
Source l3n5 = l2n5.createSource("l3n5", "typ2");
mtag.addSource(l2n6.id());
darray.addSource(l3n5.id());

// test if sources are in place
CPPUNIT_ASSERT(mtag.hasSource(l2n6));
CPPUNIT_ASSERT(darray.hasSource(l3n5));
Expand All @@ -178,14 +179,36 @@ void BaseTestSource::testFindSource() {
// test filter
auto filter_typ1 = util::TypeFilter<Source>("typ1");
auto filter_typ2 = util::TypeFilter<Source>("typ2");

CPPUNIT_ASSERT(source.findSources(filter_typ1).size() == 3);
CPPUNIT_ASSERT(source.findSources(filter_typ2).size() == 9);


filter_typ1 = util::TypeFilter<Source>("Typ1");
CPPUNIT_ASSERT(source.findSources(filter_typ1).size() == 0);

boost::regex expression("Typ1", boost::regex::icase);
filter_typ1 = util::TypeFilter<Source>(expression);
CPPUNIT_ASSERT(source.findSources(filter_typ1).size() == 3);

expression = boost::regex("Typ", boost::regex::icase);
filter_typ1 = util::TypeFilter<Source>(expression);
CPPUNIT_ASSERT(source.findSources(filter_typ1).size() == 14);

expression = boost::regex("^typ$", boost::regex::icase);
filter_typ1 = util::TypeFilter<Source>(expression);
CPPUNIT_ASSERT(source.findSources(filter_typ1).size() == 0);

Source l3n6 = l2n5.createSource("l3n6", "typ typ");
filter_typ1 = util::TypeFilter<Source>("typ");
CPPUNIT_ASSERT(source.findSources(filter_typ1).size() == 0);
l2n5.deleteSource(l3n6);


// test deleter
/* chop the tree down to:
*
*
* source---l1n2
* |
* |
* ------l1n3---l2n4
* |
* ------l2n5---l3n4
Expand All @@ -199,7 +222,7 @@ void BaseTestSource::testFindSource() {
source.deleteSource(l1n1.id());
CPPUNIT_ASSERT(source.findSources().size() == 8);
/* chop the tree down to:
*
*
* source---l1n3---l2n4
* |
* ------l2n5---l3n4
Expand All @@ -213,7 +236,7 @@ void BaseTestSource::testFindSource() {
source.deleteSource(l1n2.id());
CPPUNIT_ASSERT(source.findSources().size() == 7);
/* chop the tree down to:
*
*
* source
* mtag
* darray
Expand Down

0 comments on commit 684670e

Please sign in to comment.