using xvec related api in scheduler
This commit is contained in:
parent
06209930f9
commit
924bc1517b
11 changed files with 689 additions and 70 deletions
115
src/lib/xvec.c
115
src/lib/xvec.c
|
|
@ -268,3 +268,118 @@ int xvec_idval_store(xvec_idval_t* v, int idx, float val)
|
|||
|
||||
return v->count;
|
||||
}
|
||||
|
||||
int xvec_idval_store_idx(xvec_idval_t* v, int idx)
|
||||
{
|
||||
int pos;
|
||||
int rc;
|
||||
|
||||
if ((v == NULL) || (idx < 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pos = v->count;
|
||||
rc = xvec_put(&(v->idxs), pos, &idx);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
v->count = pos + 1;
|
||||
return v->count;
|
||||
}
|
||||
|
||||
int xvec_fill_idval(xvec_idval_t* v, xvec_t* src)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ((v == NULL) || (src == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (v->count < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (src->elsize != sizeof(float)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < v->count; i++) {
|
||||
int idx = ((int*)v->idxs.data)[i];
|
||||
float* vals = (float*)v->vals.data;
|
||||
|
||||
if (idx < 0) {
|
||||
vals[i] = 0.0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx >= src->count) {
|
||||
vals[i] = 0.0;
|
||||
} else {
|
||||
vals[i] = ((float*)src->data)[idx];
|
||||
}
|
||||
}
|
||||
|
||||
return v->count;
|
||||
}
|
||||
|
||||
#define DEFINE_XVEC_IDVAL_OP(op) \
|
||||
static inline int xvec_idval_##op(xvec_t* d, xvec_idval_t* v) \
|
||||
{ \
|
||||
int rc, maxidx; \
|
||||
int i; \
|
||||
\
|
||||
maxidx = 0; \
|
||||
for (i = 0; i < v->count; i++) { \
|
||||
if (maxidx < ((int*)v->idxs.data)[i]) { \
|
||||
maxidx = ((int*)v->idxs.data)[i]; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
rc = xvec_resize(d, maxidx + 1); \
|
||||
if (rc < 0) { \
|
||||
return rc; \
|
||||
} \
|
||||
\
|
||||
for (i = 0; i < v->count; i++) { \
|
||||
int idx = ((int*)v->idxs.data)[i]; \
|
||||
\
|
||||
if (idx < 0) { \
|
||||
continue; \
|
||||
} \
|
||||
\
|
||||
((float*)d->data)[idx] X_OP(op)((float*)v->vals.data)[i]; \
|
||||
} \
|
||||
\
|
||||
return v->count; \
|
||||
}
|
||||
|
||||
DEFINE_XVEC_IDVAL_OP(add)
|
||||
DEFINE_XVEC_IDVAL_OP(sub)
|
||||
|
||||
int xvec_idval(xvec_t* d, xvec_idval_t* v, xvec_op_t op)
|
||||
{
|
||||
if ((d == NULL) || (v == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (d->elsize != sizeof(float)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((v->idxs.elsize != sizeof(int)) || (v->vals.elsize != sizeof(float))) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (op) {
|
||||
case XVEC_ADD_INT:
|
||||
case XVEC_SUB_INT:
|
||||
return -EINVAL;
|
||||
case XVEC_ADD_FLOAT:
|
||||
return xvec_idval_add(d, v);
|
||||
case XVEC_SUB_FLOAT:
|
||||
return xvec_idval_sub(d, v);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue