forked from daphne-project/daphne
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartesian.h
More file actions
142 lines (129 loc) · 4.08 KB
/
Copy pathCartesian.h
File metadata and controls
142 lines (129 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef SRC_RUNTIME_LOCAL_KERNELS_CARTESIAN_H
#define SRC_RUNTIME_LOCAL_KERNELS_CARTESIAN_H
#include <runtime/local/context/DaphneContext.h>
#include <runtime/local/datastructures/DataObjectFactory.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/datastructures/Frame.h>
#include <runtime/local/datastructures/ValueTypeCode.h>
#include <runtime/local/datastructures/ValueTypeUtils.h>
#include <stdexcept>
#include <tuple>
#include <unordered_set>
#include <cstddef>
#include <cstdint>
template<typename VTCol>
void cartesianSetValue(
DenseMatrix<VTCol> * res,
const DenseMatrix<VTCol> * arg,
const int64_t targetRow,
const int64_t fromRow,
DCTX(ctx)
){
const VTCol argValue = arg->get(fromRow, 0);
res->set(targetRow, 0, argValue);
}
template<typename VTCol>
void cartesianSet(
ValueTypeCode vtcType,
Frame *&res,
const Frame * arg,
const int64_t toRow,
const int64_t toCol,
const int64_t fromRow,
const int64_t fromCol,
DCTX(ctx)
) {
if(vtcType == ValueTypeUtils::codeFor<VTCol>){
cartesianSetValue<VTCol>(
res->getColumn<VTCol>(toCol),
arg->getColumn<VTCol>(fromCol),
toRow,
fromRow,
ctx
);
}
}
void cartesian(
Frame *& res,
const Frame * lhs, const Frame * rhs,
DCTX(ctx)
) {
const size_t numRowRhs = rhs->getNumRows();
const size_t numRowLhs = lhs->getNumRows();
const size_t totalRows = numRowRhs * numRowLhs;
const size_t numColRhs = rhs->getNumCols();
const size_t numColLhs = lhs->getNumCols();
const size_t totalCols = numColRhs + numColLhs;
const std::string * oldlabels_l = lhs->getLabels();
const std::string * oldlabels_r = rhs->getLabels();
int64_t row_idx_res = 0;
int64_t col_idx_res = 0;
ValueTypeCode schema[totalCols];
std::string newlabels[totalCols];
// Setting Schema and Labels
for(size_t col_idx_l = 0; col_idx_l < numColLhs; col_idx_l++){
schema[col_idx_res] = lhs->getColumnType(col_idx_l);
newlabels[col_idx_res] = oldlabels_l[col_idx_l];
col_idx_res++;
}
for(size_t col_idx_r = 0; col_idx_r < numColRhs; col_idx_r++){
schema[col_idx_res] = rhs->getColumnType(col_idx_r);
newlabels[col_idx_res] = oldlabels_r[col_idx_r];
col_idx_res++;
}
// Creating Result Frame
res = DataObjectFactory::create<Frame>(totalRows, totalCols, schema, newlabels, false);
for(size_t row_idx_l = 0; row_idx_l < numRowLhs; row_idx_l++){
for(size_t row_idx_r = 0; row_idx_r < numRowRhs; row_idx_r++){
col_idx_res = 0;
for(size_t idx_c = 0; idx_c < numColLhs; idx_c++){
cartesianSet<int64_t>(
schema[col_idx_res],
res,
lhs,
row_idx_res,
col_idx_res,
row_idx_l,
idx_c,
ctx
);
cartesianSet<double>(
schema[col_idx_res],
res,
lhs,
row_idx_res,
col_idx_res,
row_idx_l,
idx_c,
ctx
);
col_idx_res++;
}
for(size_t idx_c = 0; idx_c < numColRhs; idx_c++){
cartesianSet<int64_t>(
schema[col_idx_res],
res,
rhs,
row_idx_res,
col_idx_res,
row_idx_r,
idx_c,
ctx
);
cartesianSet<double>(
schema[col_idx_res],
res,
rhs,
row_idx_res,
col_idx_res,
row_idx_r,
idx_c,
ctx
);
col_idx_res++;
}
row_idx_res++;
}
}
}
#endif //SRC_RUNTIME_LOCAL_KERNELS_CARTESIAN_H