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

transform to c style

上级 d6bd5b19
......@@ -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)
#include <paddle/capi.h>
#include <time.h>
#include <iostream>
#include <vector>
#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<paddle_real> 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<paddle_real> 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");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册