Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions include/operators/Where.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,19 @@ template <typename T> class Where : public baseOperator<T> {

// bool getAttribute<int>(OPATTR attrName, int& obj) ;

void compute(void) {
// CHANGE return-type and args
// AND ADD YOUR FUNCTIONAL CODE HERE
tensor<T> compute(tensor<bool> &B, tensor<T> &X, tensor<T> &Y) {
if (typeid(B) != typeid(tensor<bool>))
throw std::invalid_argument(
"tensor types not appropriate for Where operator.");
if (X.shape() != Y.shape() || X.shape() != B.shape() || Y.shape() != B.shape())
throw std::invalid_argument(
"tensor dimenions not appropriate for Where operator.");

tensor<T> result(X.shape(), X.name());
for (size_t i = 0; i < X.length(); i++)
result[i] = B[i] ? X[i] : Y[i];

return result;
}
};
} // namespace dnnc
4 changes: 2 additions & 2 deletions src/operators/Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using namespace dnnc;
using namespace Eigen;

//#define DNNC_ADD_TEST 1
#define DNNC_ADD_TEST 1
#ifdef DNNC_ADD_TEST
#include <iostream>

Expand All @@ -37,7 +37,7 @@ int main() {
tensor<float> b(2, 3);
b.load(d2);

Add<float> m("localOpName", 0x0);
Add<float> m("localOpName");
auto result = m.compute(a, b);

std::cout << result;
Expand Down
23 changes: 22 additions & 1 deletion src/operators/Where.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,30 @@
using namespace dnnc;
using namespace Eigen;

#define DNNC_WHERE_TEST 1
#ifdef DNNC_WHERE_TEST
#include <iostream>
int main() {
// ADD YOUR TEST CODE HERE

int d1[8] = {1, 2, 3, 4, 5, 6};
int d2[8] = {9, 8, 7, 6, 5, 4};
bool d3[8] = {1, 0, 0, 1, 0, 1};

tensor<int> a(2, 4);
a.load(d1);

tensor<int> b(2, 4);
b.load(d2);

tensor<bool> c(2, 4);
c.load(d3);

Where<int> w("localOpName");
auto result = w.compute(c, a, b);

std::cout << result;
std::cout << "\n";

return 0;
}
#endif
Binary file modified src/operators/a.out
100644 → 100755
Binary file not shown.