|
| 1 | +#include <iostream> |
| 2 | +#include <taco.h> |
| 3 | + |
| 4 | +using namespace taco; |
| 5 | +using namespace std; |
| 6 | + |
| 7 | +int main() { |
| 8 | + int dim1 = 5, dim2 = 5; |
| 9 | + |
| 10 | + // Define a 2D tensor in COO format |
| 11 | + |
| 12 | + // Seems like this format was fucked up :sob: |
| 13 | + // Format coo({Compressed, Singleton}); |
| 14 | + |
| 15 | + /* |
| 16 | + order is 2, isUnique is false, isOrdered is true, isAOS is false. |
| 17 | + It seems like modeOrdering basically determines the order. |
| 18 | +
|
| 19 | + Ok, so for COO, you effectively need to figure out how to load |
| 20 | + layers in this kind of format, as seen below: |
| 21 | + */ |
| 22 | + |
| 23 | + // Format fmt({Dense({ModeFormat::ORDERED, ModeFormat::UNIQUE}), |
| 24 | + // Compressed({ModeFormat::ORDERED, ModeFormat::UNIQUE})}); |
| 25 | + // Format fmt = COO(2, false, true, false); |
| 26 | + |
| 27 | + Format fmt({Compressed({ModeFormat::ORDERED, ModeFormat::NOT_UNIQUE}), |
| 28 | + Singleton({ModeFormat::ORDERED, ModeFormat::NOT_UNIQUE})}); |
| 29 | + Tensor<double> A({5, 5}, fmt); |
| 30 | + |
| 31 | + // TODO: generate with finch, use experimental parse_taco.cpp and check the |
| 32 | + // tensor below is the same. |
| 33 | + |
| 34 | + // Insert non-zero values with explicit coordinates |
| 35 | + A.insert({0, 0}, 3.5); |
| 36 | + A.insert({1, 2}, 4.2); |
| 37 | + A.insert({1, 1}, 1.1); |
| 38 | + A.insert({2, 3}, 1.4); |
| 39 | + |
| 40 | + A.pack(); |
| 41 | + |
| 42 | + auto index = A.getStorage().getIndex(); |
| 43 | + |
| 44 | + cout << "elements " << A.getAllocSize() << "\n"; |
| 45 | + |
| 46 | + cout << "dimension:" << A.getDimensions().size() << "\n"; |
| 47 | + for (int i = 0; i < index.numModeIndices(); i++) { |
| 48 | + cout << "mode index " << i |
| 49 | + << ", indexArrays: " << index.getModeIndex(i).numIndexArrays() |
| 50 | + << "\n====\n"; |
| 51 | + for (int j = 0; j < index.getModeIndex(i).numIndexArrays(); j++) { |
| 52 | + auto array = index.getModeIndex(i).getIndexArray(j); |
| 53 | + for (int k = 0; k < array.getSize(); k++) { |
| 54 | + cout << array.get(k).get().int32Value << " "; |
| 55 | + } |
| 56 | + cout << "\n"; |
| 57 | + } |
| 58 | + cout << "====\n"; |
| 59 | + } |
| 60 | + |
| 61 | + cout << "===================\n"; |
| 62 | + cout << "Extract some values: \n"; |
| 63 | + for (int k = 0; k < 5; k++) { |
| 64 | + for (int i = 0; i < 5; i++) { |
| 65 | + cout << A(k, i) << " "; |
| 66 | + } |
| 67 | + cout << "\n\n"; |
| 68 | + } |
| 69 | + cout << "===================\n"; |
| 70 | + |
| 71 | + cout << "elements:\n"; |
| 72 | + auto elements = A.getStorage().getValues(); |
| 73 | + for (int i = 0; i < elements.getSize(); i++) { |
| 74 | + cout << elements.get(i).get().float64Value << " "; |
| 75 | + } |
| 76 | + cout << "\n"; |
| 77 | + cout << "data: \n"; |
| 78 | + auto data = (double*) elements.getData(); |
| 79 | + for (int i = 0; i < elements.getSize(); i++) { |
| 80 | + cout << data[i] << " "; |
| 81 | + } |
| 82 | + cout << "\n"; |
| 83 | + cout << endl; |
| 84 | + return 0; |
| 85 | +} |
0 commit comments