-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
113 lines (86 loc) · 2.73 KB
/
utils.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Ethereal is a UCI chess playing engine authored by Andrew Grant.
<https://github.com/AndyGrant/Ethereal> <[email protected]>
Ethereal is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ethereal is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <assert.h>
#include <stdalign.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
#include <sys/time.h>
#endif
#include "types.h"
#define ALIGN64 alignas(64)
/// Vector Declarations
typedef struct Vector {
int length;
float ALIGN64 *values;
} Vector;
Vector *create_vector(int length);
void delete_vector(Vector *vector);
void set_vector(Vector *vector, float *values);
void zero_vector(Vector *vector);
/// Matrix Declarations
typedef struct Matrix {
int rows, cols;
float ALIGN64 *values;
} Matrix;
Matrix *create_matrix(int rows, int cols);
void delete_matrix(Matrix *matrix);
void zero_matrix(Matrix *matrix);
/// Evaluator Declarations
typedef struct Evaluator {
Vector **unactivated;
Vector **activated;
int layers;
} Evaluator;
Evaluator *create_evaluator(Network *nn);
void delete_evaluator(Evaluator *eval);
/// Gradient Declarations
typedef struct Gradient {
Matrix **weights;
Vector **biases;
int layers;
} Gradient;
Gradient *create_gradient(Network *nn);
void delete_gradient(Gradient *grad);
void zero_gradient(Gradient *grad);
/// Optimizer Declarations
typedef struct Optimizer {
Gradient *momentum, *velocity;
uint64_t iteration, last_seen[MAX_INPUTS];
} Optimizer;
Optimizer *create_optimizer(Network *nn);
void delete_optimizer(Optimizer *opt);
void save_optimizer(Optimizer *opt, const char *fname);
void load_optimizer(Optimizer *opt, const char *fname);
/// Chess Utility Declarations
int getlsb(uint64_t bb);
int poplsb(uint64_t *bb);
int file_of(int sq);
int rank_of(int sq);
int square(int rank, int file);
int relative_rank_of(int colour, int sq);
int relative_square(int colour, int sq);
int sq64_to_sq32(int sq);
int sq32_to_sq64(int sq);
int queen_side_sq(int sq);
int mirror_square(int sq);
// Operating System Function Declarations
void* align_malloc(size_t size);
void align_free(void *ptr);
double get_time_point();