Skip to content

Commit 176a00b

Browse files
committed
chore: add .clang-format
1 parent 64f6002 commit 176a00b

File tree

7 files changed

+585
-571
lines changed

7 files changed

+585
-571
lines changed

.clang-format

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
BasedOnStyle: Chromium
2+
UseTab: Never
3+
IndentWidth: 4
4+
TabWidth: 4
5+
AllowShortIfStatementsOnASingleLine: false
6+
IndentCaseLabels: false
7+
ColumnLimit: 0
8+
AccessModifierOffset: -4
9+
NamespaceIndentation: All
10+
FixNamespaceComments: false
11+
AlignAfterOpenBracket: true
12+
AlignConsecutiveAssignments: true
13+
IndentCaseLabels: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ test/
33

44
.cache/
55
*.swp
6+
.vscode/

examples/main.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,27 @@ const char* sample_method_str[] = {
8888
const char* schedule_str[] = {
8989
"default",
9090
"discrete",
91-
"karras"
92-
};
91+
"karras"};
9392

9493
struct Option {
95-
int n_threads = -1;
94+
int n_threads = -1;
9695
std::string mode = TXT2IMG;
9796
std::string model_path;
9897
std::string lora_model_dir;
9998
std::string output_path = "output.png";
10099
std::string init_img;
101100
std::string prompt;
102101
std::string negative_prompt;
103-
float cfg_scale = 7.0f;
104-
int w = 512;
105-
int h = 512;
102+
float cfg_scale = 7.0f;
103+
int w = 512;
104+
int h = 512;
106105
SampleMethod sample_method = EULER_A;
107-
Schedule schedule = DEFAULT;
108-
int sample_steps = 20;
109-
float strength = 0.75f;
110-
RNGType rng_type = CUDA_RNG;
111-
int64_t seed = 42;
112-
bool verbose = false;
106+
Schedule schedule = DEFAULT;
107+
int sample_steps = 20;
108+
float strength = 0.75f;
109+
RNGType rng_type = CUDA_RNG;
110+
int64_t seed = 42;
111+
bool verbose = false;
113112

114113
void print() {
115114
printf("Option: \n");
@@ -129,7 +128,7 @@ struct Option {
129128
printf(" sample_steps: %d\n", sample_steps);
130129
printf(" strength: %.2f\n", strength);
131130
printf(" rng: %s\n", rng_type_to_str[rng_type]);
132-
printf(" seed: %lld\n", seed);
131+
printf(" seed: %ld\n", seed);
133132
}
134133
};
135134

@@ -266,7 +265,7 @@ void parse_args(int argc, const char* argv[], Option* opt) {
266265
break;
267266
}
268267
const char* schedule_selected = argv[i];
269-
int schedule_found = -1;
268+
int schedule_found = -1;
270269
for (int d = 0; d < N_SCHEDULES; d++) {
271270
if (!strcmp(schedule_selected, schedule_str[d])) {
272271
schedule_found = d;
@@ -289,7 +288,7 @@ void parse_args(int argc, const char* argv[], Option* opt) {
289288
break;
290289
}
291290
const char* sample_method_selected = argv[i];
292-
int sample_method_found = -1;
291+
int sample_method_found = -1;
293292
for (int m = 0; m < N_SAMPLE_METHODS; m++) {
294293
if (!strcmp(sample_method_selected, sample_method_str[m])) {
295294
sample_method_found = m;
@@ -405,6 +404,7 @@ int main(int argc, const char* argv[]) {
405404
vae_decode_only = false;
406405

407406
int c = 0;
407+
408408
unsigned char* img_data = stbi_load(opt.init_img.c_str(), &opt.w, &opt.h, &c, 3);
409409
if (img_data == NULL) {
410410
fprintf(stderr, "load image from '%s' failed\n", opt.init_img.c_str());

rng.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
#include <vector>
66

77
class RNG {
8-
public:
9-
virtual void manual_seed(uint64_t seed) = 0;
8+
public:
9+
virtual void manual_seed(uint64_t seed) = 0;
1010
virtual std::vector<float> randn(uint32_t n) = 0;
1111
};
1212

1313
class STDDefaultRNG : public RNG {
14-
private:
14+
private:
1515
std::default_random_engine generator;
1616

17-
public:
17+
public:
1818
void manual_seed(uint64_t seed) {
1919
generator.seed((unsigned int)seed);
2020
}
2121

2222
std::vector<float> randn(uint32_t n) {
2323
std::vector<float> result;
24-
float mean = 0.0;
24+
float mean = 0.0;
2525
float stddev = 1.0;
2626
std::normal_distribution<float> distribution(mean, stddev);
2727
for (uint32_t i = 0; i < n; i++) {

rng_philox.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
// RNG imitiating torch cuda randn on CPU.
1010
// Port from: https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ef669de080814067961f28357256e8fe27544f4/modules/rng_philox.py
1111
class PhiloxRNG : public RNG {
12-
private:
12+
private:
1313
uint64_t seed;
1414
uint32_t offset;
1515

16-
private:
16+
private:
1717
std::vector<uint32_t> philox_m = {0xD2511F53, 0xCD9E8D57};
1818
std::vector<uint32_t> philox_w = {0x9E3779B9, 0xBB67AE85};
19-
float two_pow32_inv = 2.3283064e-10f;
20-
float two_pow32_inv_2pi = 2.3283064e-10f * 6.2831855f;
19+
float two_pow32_inv = 2.3283064e-10f;
20+
float two_pow32_inv_2pi = 2.3283064e-10f * 6.2831855f;
2121

2222
std::vector<uint32_t> uint32(uint64_t x) {
2323
std::vector<uint32_t> result(2);
@@ -87,14 +87,14 @@ class PhiloxRNG : public RNG {
8787
return r1;
8888
}
8989

90-
public:
90+
public:
9191
PhiloxRNG(uint64_t seed = 0) {
92-
this->seed = seed;
92+
this->seed = seed;
9393
this->offset = 0;
9494
}
9595

9696
void manual_seed(uint64_t seed) {
97-
this->seed = seed;
97+
this->seed = seed;
9898
this->offset = 0;
9999
}
100100

0 commit comments

Comments
 (0)