29 GstMemory *dense = NULL;
32 guint8 *output, *input;
34 gsize output_size, element_size;
36 if (!gst_memory_map (mem, &map, GST_MAP_READ)) {
37 nns_loge (
"Failed to map given memory");
42 nns_loge (
"Failed to parse meta info from given memory");
51 if (element_size == 0 || output_size == 0) {
56 output = (guint8 *) g_malloc0 (output_size);
60 indices = (guint *) (input + element_size * nnz);
62 for (i = 0; i < nnz; ++i) {
65 ((int32_t *) output)[indices[i]] = ((int32_t *) input)[i];
68 ((uint32_t *) output)[indices[i]] = ((uint32_t *) input)[i];
71 ((int16_t *) output)[indices[i]] = ((int16_t *) input)[i];
74 ((uint16_t *) output)[indices[i]] = ((uint16_t *) input)[i];
77 ((int8_t *) output)[indices[i]] = ((int8_t *) input)[i];
80 ((uint8_t *) output)[indices[i]] = ((uint8_t *) input)[i];
83 ((
double *) output)[indices[i]] = ((
double *) input)[i];
86 ((
float *) output)[indices[i]] = ((
float *) input)[i];
89 ((int64_t *) output)[indices[i]] = ((int64_t *) input)[i];
92 ((uint64_t *) output)[indices[i]] = ((uint64_t *) input)[i];
95 nns_loge (
"Error occurred during get tensor value");
101 dense = gst_memory_new_wrapped (0, output, output_size, 0, output_size,
105 gst_memory_unmap (mem, &map);
118 GstMemory *sparse = NULL;
125 gsize output_size, header_size, element_size;
126 gulong element_count;
128 if (!gst_memory_map (mem, &map, GST_MAP_READ)) {
129 nns_loge (
"Failed to map given memory");
137 if (element_size == 0 || element_count == 0) {
143 values = g_malloc0 (element_size * element_count);
144 indices = g_malloc0 (
sizeof (guint) * element_count);
146 data_type = meta->
type;
149 for (i = 0; i < element_count; ++i) {
152 if (((int32_t *) map.data)[i] != 0) {
153 ((int32_t *) values)[nnz] = ((int32_t *) map.data)[i];
159 if (((uint32_t *) map.data)[i] != 0) {
160 ((uint32_t *) values)[nnz] = ((uint32_t *) map.data)[i];
166 if (((int16_t *) map.data)[i] != 0) {
167 ((int16_t *) values)[nnz] = ((int16_t *) map.data)[i];
173 if (((uint16_t *) map.data)[i] != 0) {
174 ((uint16_t *) values)[nnz] = ((uint16_t *) map.data)[i];
180 if (((int8_t *) map.data)[i] != 0) {
181 ((int8_t *) values)[nnz] = ((int8_t *) map.data)[i];
187 if (((uint8_t *) map.data)[i] != 0) {
188 ((uint8_t *) values)[nnz] = ((uint8_t *) map.data)[i];
194 if (((
double *) map.data)[i] != 0) {
195 ((
double *) values)[nnz] = ((
double *) map.data)[i];
201 if (((
float *) map.data)[i] != 0) {
202 ((
float *) values)[nnz] = ((
float *) map.data)[i];
208 if (((int64_t *) map.data)[i] != 0) {
209 ((int64_t *) values)[nnz] = ((int64_t *) map.data)[i];
215 if (((uint64_t *) map.data)[i] != 0) {
216 ((uint64_t *) values)[nnz] = ((uint64_t *) map.data)[i];
222 nns_loge (
"Error occurred during get tensor value");
234 output_size = element_size * nnz +
sizeof (guint) * nnz;
237 output_size += header_size;
238 output = g_malloc0 (output_size);
242 memcpy (output + header_size, values, element_size * nnz);
243 memcpy (output + header_size + (element_size * nnz),
244 indices,
sizeof (guint) * nnz);
249 sparse = gst_memory_new_wrapped (0, output, output_size, 0, output_size,
253 gst_memory_unmap (mem, &map);