From 82aaceba08bf587d51e4598a989c37eab0f3ccb6 Mon Sep 17 00:00:00 2001 From: peterzhang2029 Date: Wed, 22 Nov 2017 15:54:35 +0800 Subject: [PATCH] transform to c style --- .../model_inference/dense/CMakeLists.txt | 2 +- .../dense/{main.cpp => main.c} | 27 ++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) rename paddle/capi/examples/model_inference/dense/{main.cpp => main.c} (77%) diff --git a/paddle/capi/examples/model_inference/dense/CMakeLists.txt b/paddle/capi/examples/model_inference/dense/CMakeLists.txt index 31759310ce1..008a488fd9e 100644 --- a/paddle/capi/examples/model_inference/dense/CMakeLists.txt +++ b/paddle/capi/examples/model_inference/dense/CMakeLists.txt @@ -2,5 +2,5 @@ project(dense) cmake_minimum_required(VERSION 2.8) aux_source_directory(. SRC_LIST) add_executable(${PROJECT_NAME} ${SRC_LIST}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99) target_link_libraries(${PROJECT_NAME} -lpaddle_capi_shared) diff --git a/paddle/capi/examples/model_inference/dense/main.cpp b/paddle/capi/examples/model_inference/dense/main.c similarity index 77% rename from paddle/capi/examples/model_inference/dense/main.cpp rename to paddle/capi/examples/model_inference/dense/main.c index 4ec208fff21..5eeaf7e31fa 100644 --- a/paddle/capi/examples/model_inference/dense/main.cpp +++ b/paddle/capi/examples/model_inference/dense/main.c @@ -1,7 +1,5 @@ #include #include -#include -#include #include "../common/common.h" @@ -9,8 +7,8 @@ int main() { // Initalize Paddle - std::string comand[] = {"--use_gpu=False"}; - CHECK(paddle_init(1, (char**)comand)); + char* argv[] = {"--use_gpu=False"}; + CHECK(paddle_init(1, (char**)argv)); // Reading config binary file. It is generated by `convert_protobin.sh` long size; @@ -30,20 +28,19 @@ int main() { CHECK(paddle_arguments_resize(in_args, 1)); // Create input matrix. - paddle_matrix mat = paddle_matrix_create(/* sample_num */ 10, + paddle_matrix mat = paddle_matrix_create(/* sample_num */ 1, /* size */ 784, /* useGPU */ false); srand(time(0)); - std::vector input; - input.resize(784 * 10); + paddle_real* array; - for (int i = 0; i < input.size(); ++i) { - input[i] = rand() / ((float)RAND_MAX); - } + // Get First row. + CHECK(paddle_matrix_get_row(mat, 0, &array)); - // Set value for the input matrix - CHECK(paddle_matrix_set_value(mat, input.data())); + for (int i = 0; i < 784; ++i) { + array[i] = rand() / ((float)RAND_MAX); + } CHECK(paddle_arguments_set_value(in_args, 0, mat)); @@ -56,17 +53,15 @@ int main() { CHECK(paddle_arguments_get_value(out_args, 0, prob)); - std::vector result; uint64_t height; uint64_t width; CHECK(paddle_matrix_get_shape(prob, &height, &width)); - result.resize(height * width); - CHECK(paddle_matrix_get_value(prob, result.data())); + CHECK(paddle_matrix_get_row(prob, 0, &array)); printf("Prob: \n"); for (int i = 0; i < height * width; ++i) { - printf("%.4f ", result[i]); + printf("%.4f ", array[i]); if ((i + 1) % width == 0) { printf("\n"); } -- GitLab