for (i = 0; i < array_size; i++) {
double expected = (i + 1) * (b + 1);
- EXPECT_EQ (((double *) info.data)[i], expected);
+ EXPECT_DOUBLE_EQ (((double *) info.data)[i], expected);
}
gst_memory_unmap (mem, &info);
for (i = 0; i < array_size; i++) {
float expected = (i + 1) * (b + 1) + .2 + .5;
- EXPECT_EQ (((float *) info.data)[i], expected);
+ EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
}
gst_memory_unmap (mem, &info);
for (i = 0; i < array_size; i++) {
double expected = ((i + 1) * (b + 1) + .2) * .5;
- EXPECT_EQ (((double *) info.data)[i], expected);
+ EXPECT_DOUBLE_EQ (((double *) info.data)[i], expected);
+ }
+
+ gst_memory_unmap (mem, &info);
+ gst_buffer_unref (out_buf);
+ }
+
+ EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_transform arithmetic (typecast uint8 > float32, add .5, mul .2)
+ */
+TEST (test_tensor_transform, arithmetic_3)
+{
+ const guint num_buffers = 3;
+ const guint array_size = 5;
+
+ GstHarness *h;
+ GstBuffer *in_buf, *out_buf;
+ GstTensorConfig config;
+ GstMemory *mem;
+ GstMapInfo info;
+ guint i, b;
+ gsize data_in_size, data_out_size;
+
+ h = gst_harness_new ("tensor_transform");
+
+ g_object_set (h->element, "mode", "arithmetic",
+ "option", "typecast:float32,add:.5,mul:0.2", NULL);
+
+ /* input tensor info */
+ config.info.type = _NNS_UINT8;
+ get_tensor_dimension ("5", config.info.dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
+ data_in_size = gst_tensor_info_get_size (&config.info);
+
+ config.info.type = _NNS_UINT32;
+ data_out_size = gst_tensor_info_get_size (&config.info);
+
+ /* push buffers */
+ for (b = 0; b < num_buffers; b++) {
+ /* set input buffer */
+ in_buf = gst_harness_create_buffer (h, data_in_size);
+
+ mem = gst_buffer_peek_memory (in_buf, 0);
+ ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
+
+ for (i = 0; i < array_size; i++) {
+ uint8_t value = (i + 1) * (b + 1);
+ ((uint8_t *) info.data)[i] = value;
+ }
+
+ gst_memory_unmap (mem, &info);
+
+ EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
+
+ /* get output buffer */
+ out_buf = gst_harness_pull (h);
+
+ ASSERT_TRUE (out_buf != NULL);
+ ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
+ ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
+
+ mem = gst_buffer_peek_memory (out_buf, 0);
+ ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
+
+ for (i = 0; i < array_size; i++) {
+ float expected = ((i + 1) * (b + 1) + .5) * .2;
+ EXPECT_FLOAT_EQ (((float *) info.data)[i], expected);
+ }
+
+ gst_memory_unmap (mem, &info);
+ gst_buffer_unref (out_buf);
+ }
+
+ EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_transform arithmetic (typecast uint8 > float64, add .2, add .1, typecast uint16)
+ */
+TEST (test_tensor_transform, arithmetic_4)
+{
+ const guint num_buffers = 3;
+ const guint array_size = 5;
+
+ GstHarness *h;
+ GstBuffer *in_buf, *out_buf;
+ GstTensorConfig config;
+ GstMemory *mem;
+ GstMapInfo info;
+ guint i, b;
+ gsize data_in_size, data_out_size;
+
+ h = gst_harness_new ("tensor_transform");
+
+ g_object_set (h->element, "mode", "arithmetic",
+ "option", "typecast:float64,add:0.2,add:0.1,typecast:uint16", NULL);
+
+ /* input tensor info */
+ config.info.type = _NNS_UINT8;
+ get_tensor_dimension ("5", config.info.dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
+ data_in_size = gst_tensor_info_get_size (&config.info);
+
+ config.info.type = _NNS_UINT16;
+ data_out_size = gst_tensor_info_get_size (&config.info);
+
+ /* push buffers */
+ for (b = 0; b < num_buffers; b++) {
+ /* set input buffer */
+ in_buf = gst_harness_create_buffer (h, data_in_size);
+
+ mem = gst_buffer_peek_memory (in_buf, 0);
+ ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
+
+ for (i = 0; i < array_size; i++) {
+ uint8_t value = (i + 1) * (b + 1);
+ ((uint8_t *) info.data)[i] = value;
+ }
+
+ gst_memory_unmap (mem, &info);
+
+ EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
+
+ /* get output buffer */
+ out_buf = gst_harness_pull (h);
+
+ ASSERT_TRUE (out_buf != NULL);
+ ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
+ ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
+
+ mem = gst_buffer_peek_memory (out_buf, 0);
+ ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
+
+ for (i = 0; i < array_size; i++) {
+ uint16_t expected = (i + 1) * (b + 1);
+ EXPECT_EQ (((uint16_t *) info.data)[i], expected);
+ }
+
+ gst_memory_unmap (mem, &info);
+ gst_buffer_unref (out_buf);
+ }
+
+ EXPECT_EQ (gst_harness_buffers_received (h), num_buffers);
+ gst_harness_teardown (h);
+}
+
+/**
+ * @brief Test for tensor_transform arithmetic (typecast uint8 > int32, mul 2, div 2, add -1)
+ */
+TEST (test_tensor_transform, arithmetic_5)
+{
+ const guint num_buffers = 3;
+ const guint array_size = 5;
+
+ GstHarness *h;
+ GstBuffer *in_buf, *out_buf;
+ GstTensorConfig config;
+ GstMemory *mem;
+ GstMapInfo info;
+ guint i, b;
+ gsize data_in_size, data_out_size;
+
+ h = gst_harness_new ("tensor_transform");
+
+ g_object_set (h->element, "mode", "arithmetic",
+ "option", "typecast:int32,mul:2,div:2,add:-1", NULL);
+
+ /* input tensor info */
+ config.info.type = _NNS_UINT8;
+ get_tensor_dimension ("5", config.info.dimension);
+ config.rate_n = 0;
+ config.rate_d = 1;
+
+ gst_harness_set_src_caps (h, gst_tensor_caps_from_config (&config));
+ data_in_size = gst_tensor_info_get_size (&config.info);
+
+ config.info.type = _NNS_INT32;
+ data_out_size = gst_tensor_info_get_size (&config.info);
+
+ /* push buffers */
+ for (b = 0; b < num_buffers; b++) {
+ /* set input buffer */
+ in_buf = gst_harness_create_buffer (h, data_in_size);
+
+ mem = gst_buffer_peek_memory (in_buf, 0);
+ ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_WRITE));
+
+ for (i = 0; i < array_size; i++) {
+ uint8_t value = (i + 1) * (b + 1);
+ ((uint8_t *) info.data)[i] = value;
+ }
+
+ gst_memory_unmap (mem, &info);
+
+ EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
+
+ /* get output buffer */
+ out_buf = gst_harness_pull (h);
+
+ ASSERT_TRUE (out_buf != NULL);
+ ASSERT_EQ (gst_buffer_n_memory (out_buf), 1);
+ ASSERT_EQ (gst_buffer_get_size (out_buf), data_out_size);
+
+ mem = gst_buffer_peek_memory (out_buf, 0);
+ ASSERT_TRUE (gst_memory_map (mem, &info, GST_MAP_READ));
+
+ for (i = 0; i < array_size; i++) {
+ int32_t expected = (i + 1) * (b + 1) - 1;
+ EXPECT_EQ (((int32_t *) info.data)[i], expected);
}
gst_memory_unmap (mem, &info);