提交 82aaceba 编写于 作者: P peterzhang2029

transform to c style

上级 d6bd5b19
...@@ -2,5 +2,5 @@ project(dense) ...@@ -2,5 +2,5 @@ project(dense)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST) aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${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) target_link_libraries(${PROJECT_NAME} -lpaddle_capi_shared)
#include <paddle/capi.h> #include <paddle/capi.h>
#include <time.h> #include <time.h>
#include <iostream>
#include <vector>
#include "../common/common.h" #include "../common/common.h"
...@@ -9,8 +7,8 @@ ...@@ -9,8 +7,8 @@
int main() { int main() {
// Initalize Paddle // Initalize Paddle
std::string comand[] = {"--use_gpu=False"}; char* argv[] = {"--use_gpu=False"};
CHECK(paddle_init(1, (char**)comand)); CHECK(paddle_init(1, (char**)argv));
// Reading config binary file. It is generated by `convert_protobin.sh` // Reading config binary file. It is generated by `convert_protobin.sh`
long size; long size;
...@@ -30,20 +28,19 @@ int main() { ...@@ -30,20 +28,19 @@ int main() {
CHECK(paddle_arguments_resize(in_args, 1)); CHECK(paddle_arguments_resize(in_args, 1));
// Create input matrix. // Create input matrix.
paddle_matrix mat = paddle_matrix_create(/* sample_num */ 10, paddle_matrix mat = paddle_matrix_create(/* sample_num */ 1,
/* size */ 784, /* size */ 784,
/* useGPU */ false); /* useGPU */ false);
srand(time(0)); srand(time(0));
std::vector<paddle_real> input; paddle_real* array;
input.resize(784 * 10);
for (int i = 0; i < input.size(); ++i) { // Get First row.
input[i] = rand() / ((float)RAND_MAX); CHECK(paddle_matrix_get_row(mat, 0, &array));
}
// Set value for the input matrix for (int i = 0; i < 784; ++i) {
CHECK(paddle_matrix_set_value(mat, input.data())); array[i] = rand() / ((float)RAND_MAX);
}
CHECK(paddle_arguments_set_value(in_args, 0, mat)); CHECK(paddle_arguments_set_value(in_args, 0, mat));
...@@ -56,17 +53,15 @@ int main() { ...@@ -56,17 +53,15 @@ int main() {
CHECK(paddle_arguments_get_value(out_args, 0, prob)); CHECK(paddle_arguments_get_value(out_args, 0, prob));
std::vector<paddle_real> result;
uint64_t height; uint64_t height;
uint64_t width; uint64_t width;
CHECK(paddle_matrix_get_shape(prob, &height, &width)); CHECK(paddle_matrix_get_shape(prob, &height, &width));
result.resize(height * width); CHECK(paddle_matrix_get_row(prob, 0, &array));
CHECK(paddle_matrix_get_value(prob, result.data()));
printf("Prob: \n"); printf("Prob: \n");
for (int i = 0; i < height * width; ++i) { for (int i = 0; i < height * width; ++i) {
printf("%.4f ", result[i]); printf("%.4f ", array[i]);
if ((i + 1) % width == 0) { if ((i + 1) % width == 0) {
printf("\n"); printf("\n");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册