代码块测试

放置代码块

不声明语言

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "FontEngine.h"

FontEngine::FontEngine() {
if (FT_Init_FreeType(&library)) {
SysError(L"Failed to init freetype library");
}

if (FT_New_Face(library, "resources\\font\\LLtype.ttf", 0, &face)) {
SysError(L"Failed to load font");
}

debug_log("Loaded font \"%s\"\n", face->family_name);

if (FT_Set_Pixel_Sizes(face, 0, 128)) {
SysError(L"Failed to set font size");
}

if (FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
SysError(L"Failed to select charset");
}
#ifndef NDEBUG
load_char(L'A');
assert(face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
#endif // !NDEBUG
}

声明为c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "FontEngine.h"

FontEngine::FontEngine() {
if (FT_Init_FreeType(&library)) {
SysError(L"Failed to init freetype library");
}

if (FT_New_Face(library, "resources\\font\\LLtype.ttf", 0, &face)) {
SysError(L"Failed to load font");
}

debug_log("Loaded font \"%s\"\n", face->family_name);

if (FT_Set_Pixel_Sizes(face, 0, 128)) {
SysError(L"Failed to set font size");
}

if (FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
SysError(L"Failed to select charset");
}
#ifndef NDEBUG
load_char(L'A');
assert(face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
#endif // !NDEBUG
}

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import argparse
import torch
from torch.nn import Module
from common_layers import Conv2, Conv1

class Autoencoder(Module):
encoder: Module
decoder: Module

def __init__(self):
super(Autoencoder, self).__init__()
self.encoder = torch.nn.Sequential(
Conv2(3, 32),
torch.nn.MaxPool2d(2),
Conv2(32, 64),
torch.nn.MaxPool2d(2),
Conv2(64, 128),
torch.nn.MaxPool2d(2),
Conv2(128, 256),
torch.nn.MaxPool2d(2),
Conv2(256, 256)
)

self.decoder = torch.nn.Sequential(
torch.nn.ConvTranspose2d(256, 256, 4, stride=2, padding=1),
Conv2(256, 256),
torch.nn.ConvTranspose2d(256, 128, 4, stride=2, padding=1),
Conv2(128, 128),
torch.nn.ConvTranspose2d(128, 64, 4, stride=2, padding=1),
Conv2(64, 64),
torch.nn.ConvTranspose2d(64, 32, 4, stride=2, padding=1),
Conv2(32, 32),
torch.nn.Conv2d(32, 3, 1)
)


def forward(self, x: torch.Tensor):
encoded = self.encoder(x)
decoded = self.decoder(encoded)
return decoded

再放一张图图


代码块测试
https://9-extra.github.io/2023/03/16/代码块测试/
作者
9_Extra
发布于
2023年3月16日
许可协议