-
Notifications
You must be signed in to change notification settings - Fork 0
/
weight.h
49 lines (43 loc) · 1.34 KB
/
weight.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
/**
* Framework for Threes! and its variants (C++ 11)
* weight.h: Lookup table template for n-tuple network
*
* Author: Theory of Computer Games
* Computer Games and Intelligence (CGI) Lab, NYCU, Taiwan
* https://cgilab.nctu.edu.tw/
*/
#pragma once
#include <iostream>
#include <vector>
#include <utility>
class weight {
public:
typedef float type;
public:
weight() {}
weight(size_t len) : value(len) {}
weight(weight&& f) : value(std::move(f.value)) {}
weight(const weight& f) = default;
weight& operator =(const weight& f) = default;
type& operator[] (size_t i) { return value[i]; }
const type& operator[] (size_t i) const { return value[i]; }
size_t size() const { return value.size(); }
public:
friend std::ostream& operator <<(std::ostream& out, const weight& w) {
auto& value = w.value;
uint64_t size = value.size();
out.write(reinterpret_cast<const char*>(&size), sizeof(uint64_t));
out.write(reinterpret_cast<const char*>(value.data()), sizeof(type) * size);
return out;
}
friend std::istream& operator >>(std::istream& in, weight& w) {
auto& value = w.value;
uint64_t size = 0;
in.read(reinterpret_cast<char*>(&size), sizeof(uint64_t));
value.resize(size);
in.read(reinterpret_cast<char*>(value.data()), sizeof(type) * size);
return in;
}
protected:
std::vector<type> value;
};