Skip to content

Commit fe5eb72

Browse files
committed
code style
1 parent 0280122 commit fe5eb72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+520
-173
lines changed

.github/ISSUE_TEMPLATE/---document-issue-.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ For example: no sample code; The sample code is not helpful; The sample code not
5656
For example:Chinese API in this doc is inconsistent with English API, including params, description, sample code, formula, etc.
5757

5858
#### Other
59-
For example: The doc link is broken; The doc page is missing; Dead link in docs.
59+
For example: The doc link is broken; The doc page is missing; Dead link in docs.

paddle/fluid/distributed/service/graph_brpc_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
#pragma once
1616

17+
#include <ThreadPool.h>
1718
#include <memory>
1819
#include <string>
1920
#include <vector>
20-
#include <ThreadPool.h>
2121

2222
#include <utility>
2323
#include "ThreadPool.h"

paddle/fluid/distributed/table/common_graph_table.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int32_t GraphTable::load_nodes(const std::string &path, std::string node_type) {
124124
std::ifstream file(path);
125125
std::string line;
126126
while (std::getline(file, line)) {
127-
count ++;
127+
count++;
128128
auto values = paddle::string::split_string<std::string>(line, "\t");
129129
if (values.size() < 2) continue;
130130
auto id = std::stoull(values[1]);
@@ -160,12 +160,12 @@ int32_t GraphTable::load_nodes(const std::string &path, std::string node_type) {
160160
<< " not in feature_map.";
161161
}
162162
}
163-
valid_count ++;
163+
valid_count++;
164164
}
165165
}
166166

167-
VLOG(0) << valid_count << "/" << count << " nodes in type " <<
168-
node_type << " are loaded successfully in " << path;
167+
VLOG(0) << valid_count << "/" << count << " nodes in type " << node_type
168+
<< " are loaded successfully in " << path;
169169
return 0;
170170
}
171171

@@ -209,10 +209,11 @@ int32_t GraphTable::load_edges(const std::string &path, bool reverse_edge) {
209209
size_t index = src_shard_id - shard_start;
210210
shards[index].add_graph_node(src_id)->build_edges(is_weighted);
211211
shards[index].add_neighboor(src_id, dst_id, weight);
212-
valid_count ++;
212+
valid_count++;
213213
}
214214
}
215-
VLOG(0) << valid_count << "/" << count << " edges are loaded successfully in " << path;
215+
VLOG(0) << valid_count << "/" << count << " edges are loaded successfully in "
216+
<< path;
216217

217218
// Build Sampler j
218219

paddle/fluid/distributed/table/graph_edge.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
namespace paddle {
1818
namespace distributed {
1919

20-
void GraphEdgeBlob::add_edge(uint64_t id, float weight=1){
20+
void GraphEdgeBlob::add_edge(uint64_t id, float weight = 1) {
2121
id_arr.push_back(id);
2222
}
2323

24-
void WeightedGraphEdgeBlob::add_edge(uint64_t id, float weight=1){
24+
void WeightedGraphEdgeBlob::add_edge(uint64_t id, float weight = 1) {
2525
id_arr.push_back(id);
2626
weight_arr.push_back(weight);
2727
}
28-
2928
}
3029
}

paddle/fluid/distributed/table/graph_node.cc

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
namespace paddle {
1818
namespace distributed {
1919

20-
2120
GraphNode::~GraphNode() {
22-
if (sampler != nullptr){
21+
if (sampler != nullptr) {
2322
delete sampler;
2423
sampler = nullptr;
2524
}
26-
if (edges != nullptr){
25+
if (edges != nullptr) {
2726
delete edges;
2827
edges = nullptr;
2928
}
@@ -33,9 +32,7 @@ int Node::weight_size = sizeof(float);
3332
int Node::id_size = sizeof(uint64_t);
3433
int Node::int_size = sizeof(int);
3534

36-
int Node::get_size(bool need_feature) {
37-
return id_size + int_size;
38-
}
35+
int Node::get_size(bool need_feature) { return id_size + int_size; }
3936

4037
void Node::to_buffer(char* buffer, bool need_feature) {
4138
memcpy(buffer, &id, id_size);
@@ -45,36 +42,34 @@ void Node::to_buffer(char* buffer, bool need_feature) {
4542
memcpy(buffer, &feat_num, sizeof(int));
4643
}
4744

48-
void Node::recover_from_buffer(char* buffer) {
49-
memcpy(&id, buffer, id_size);
50-
}
45+
void Node::recover_from_buffer(char* buffer) { memcpy(&id, buffer, id_size); }
5146

5247
int FeatureNode::get_size(bool need_feature) {
53-
int size = id_size + int_size; // id, feat_num
54-
if (need_feature){
48+
int size = id_size + int_size; // id, feat_num
49+
if (need_feature) {
5550
size += feature.size() * int_size;
56-
for (const std::string& fea: feature){
51+
for (const std::string& fea : feature) {
5752
size += fea.size();
5853
}
5954
}
6055
return size;
6156
}
6257

6358
void GraphNode::build_edges(bool is_weighted) {
64-
if (edges == nullptr){
65-
if (is_weighted == true){
59+
if (edges == nullptr) {
60+
if (is_weighted == true) {
6661
edges = new WeightedGraphEdgeBlob();
6762
} else {
6863
edges = new GraphEdgeBlob();
6964
}
7065
}
7166
}
7267
void GraphNode::build_sampler(std::string sample_type) {
73-
if (sample_type == "random"){
68+
if (sample_type == "random") {
7469
sampler = new RandomSampler();
75-
} else if (sample_type == "weighted"){
70+
} else if (sample_type == "weighted") {
7671
sampler = new WeightedSampler();
77-
}
72+
}
7873
sampler->build(edges);
7974
}
8075
void FeatureNode::to_buffer(char* buffer, bool need_feature) {
@@ -87,7 +82,7 @@ void FeatureNode::to_buffer(char* buffer, bool need_feature) {
8782
feat_num += feature.size();
8883
memcpy(buffer, &feat_num, sizeof(int));
8984
buffer += sizeof(int);
90-
for (int i = 0; i < feat_num; ++i){
85+
for (int i = 0; i < feat_num; ++i) {
9186
feat_len = feature[i].size();
9287
memcpy(buffer, &feat_len, sizeof(int));
9388
buffer += sizeof(int);
@@ -99,14 +94,13 @@ void FeatureNode::to_buffer(char* buffer, bool need_feature) {
9994
}
10095
}
10196
void FeatureNode::recover_from_buffer(char* buffer) {
102-
10397
int feat_num, feat_len;
10498
memcpy(&id, buffer, id_size);
10599
buffer += id_size;
106-
100+
107101
memcpy(&feat_num, buffer, sizeof(int));
108102
buffer += sizeof(int);
109-
103+
110104
feature.clear();
111105
for (int i = 0; i < feat_num; ++i) {
112106
memcpy(&feat_len, buffer, sizeof(int));
@@ -118,7 +112,6 @@ void FeatureNode::recover_from_buffer(char* buffer) {
118112
str[feat_len] = '\0';
119113
feature.push_back(std::string(str));
120114
}
121-
122115
}
123116
}
124117
}

paddle/fluid/distributed/table/weighted_sampler.cc

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,73 @@
1414

1515
#include "paddle/fluid/distributed/table/weighted_sampler.h"
1616
#include <iostream>
17-
#include<unordered_map>
17+
#include <unordered_map>
1818
namespace paddle {
1919
namespace distributed {
2020

21-
void RandomSampler::build(GraphEdgeBlob* edges) {
22-
this->edges = edges;
23-
}
21+
void RandomSampler::build(GraphEdgeBlob *edges) { this->edges = edges; }
2422

2523
std::vector<int> RandomSampler::sample_k(int k) {
2624
int n = edges->size();
27-
if (k > n){
25+
if (k > n) {
2826
k = n;
2927
}
3028
struct timespec tn;
3129
clock_gettime(CLOCK_REALTIME, &tn);
3230
srand(tn.tv_nsec);
3331
std::vector<int> sample_result;
3432
std::unordered_map<int, int> replace_map;
35-
while(k--){
33+
while (k--) {
3634
int rand_int = rand() % n;
3735
auto iter = replace_map.find(rand_int);
38-
if(iter == replace_map.end()){
36+
if (iter == replace_map.end()) {
3937
sample_result.push_back(rand_int);
40-
}else{
38+
} else {
4139
sample_result.push_back(iter->second);
4240
}
4341

4442
iter = replace_map.find(n - 1);
45-
if(iter == replace_map.end()){
43+
if (iter == replace_map.end()) {
4644
replace_map[rand_int] = n - 1;
47-
}else{
45+
} else {
4846
replace_map[rand_int] = iter->second;
4947
}
5048
--n;
5149
}
5250
return sample_result;
5351
}
5452

55-
WeightedSampler::WeightedSampler(){
53+
WeightedSampler::WeightedSampler() {
5654
left = nullptr;
5755
right = nullptr;
5856
edges = nullptr;
5957
}
6058

6159
WeightedSampler::~WeightedSampler() {
62-
if(left != nullptr){
60+
if (left != nullptr) {
6361
delete left;
6462
left = nullptr;
6563
}
66-
if(right != nullptr){
64+
if (right != nullptr) {
6765
delete right;
6866
right = nullptr;
6967
}
7068
}
7169

72-
void WeightedSampler::build(GraphEdgeBlob* edges) {
73-
if(left != nullptr){
70+
void WeightedSampler::build(GraphEdgeBlob *edges) {
71+
if (left != nullptr) {
7472
delete left;
7573
left = nullptr;
7674
}
77-
if(right != nullptr){
75+
if (right != nullptr) {
7876
delete right;
7977
right = nullptr;
8078
}
81-
return build_one((WeightedGraphEdgeBlob*)edges, 0, edges->size());
79+
return build_one((WeightedGraphEdgeBlob *)edges, 0, edges->size());
8280
}
8381

84-
void WeightedSampler::build_one(WeightedGraphEdgeBlob *edges, int start, int end) {
82+
void WeightedSampler::build_one(WeightedGraphEdgeBlob *edges, int start,
83+
int end) {
8584
count = 0;
8685
this->edges = edges;
8786
if (start + 1 == end) {
@@ -137,7 +136,7 @@ int WeightedSampler::sample(
137136
if (right_count == 0 ||
138137
left_count > 0 && left->weight - left_subtract >= query_weight) {
139138
return_idx = left->sample(query_weight, subtract_weight_map,
140-
subtract_count_map, subtract);
139+
subtract_count_map, subtract);
141140
} else {
142141
return_idx =
143142
right->sample(query_weight - (left->weight - left_subtract),

paddle/fluid/distributed/table/weighted_sampler.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,38 @@ namespace paddle {
2121
namespace distributed {
2222

2323
class Sampler {
24-
public:
24+
public:
2525
virtual ~Sampler() {}
26-
virtual void build(GraphEdgeBlob* edges) = 0;
26+
virtual void build(GraphEdgeBlob *edges) = 0;
2727
virtual std::vector<int> sample_k(int k) = 0;
2828
};
2929

30-
class RandomSampler: public Sampler {
31-
public:
30+
class RandomSampler : public Sampler {
31+
public:
3232
virtual ~RandomSampler() {}
33-
virtual void build(GraphEdgeBlob* edges);
33+
virtual void build(GraphEdgeBlob *edges);
3434
virtual std::vector<int> sample_k(int k);
35-
GraphEdgeBlob* edges;
35+
GraphEdgeBlob *edges;
3636
};
3737

38-
class WeightedSampler: public Sampler {
38+
class WeightedSampler : public Sampler {
3939
public:
4040
WeightedSampler();
4141
virtual ~WeightedSampler();
4242
WeightedSampler *left, *right;
4343
float weight;
4444
int count;
4545
int idx;
46-
GraphEdgeBlob * edges;
47-
virtual void build(GraphEdgeBlob* edges);
46+
GraphEdgeBlob *edges;
47+
virtual void build(GraphEdgeBlob *edges);
4848
virtual void build_one(WeightedGraphEdgeBlob *edges, int start, int end);
4949
virtual std::vector<int> sample_k(int k);
5050

5151
private:
52-
int sample(
53-
float query_weight,
54-
std::unordered_map<WeightedSampler *, float> &subtract_weight_map,
55-
std::unordered_map<WeightedSampler *, int> &subtract_count_map,
56-
float &subtract);
52+
int sample(float query_weight,
53+
std::unordered_map<WeightedSampler *, float> &subtract_weight_map,
54+
std::unordered_map<WeightedSampler *, int> &subtract_count_map,
55+
float &subtract);
5756
};
5857
}
5958
}

paddle/fluid/inference/api/demo_ci/clean.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
set -x
216
cd `dirname $0`
317
rm -rf build/ data/

paddle/fluid/train/demo/run.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/bin/bash
22

3+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
317
set -x
418

519
PADDLE_ROOT=$1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
114

215
set -exu
316
build/demo_trainer --flagfile="train.cfg"

0 commit comments

Comments
 (0)