-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Sopel97/cyclic_reading
[WIP] Defer data preparation to native code. Use sparse input tensors.
- Loading branch information
Showing
13 changed files
with
8,866 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
__pycache__/ | ||
env/ | ||
build/ | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(training_data_loader) | ||
|
||
if(NOT DEFINED CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE RelWithDebInfo) | ||
endif() | ||
|
||
set(CMAKE_CXX_FLAGS_DEBUG "-g") | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | ||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3") | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED 17) | ||
|
||
add_library(training_data_loader SHARED training_data_loader.cpp) | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
target_link_libraries(training_data_loader Threads::Threads) | ||
|
||
install(TARGETS training_data_loader RUNTIME DESTINATION .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cmake . -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="./" | ||
cmake --build ./build --config RelWithDebInfo --target install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
import chess | ||
import torch | ||
|
||
NUM_SQ = 64 | ||
NUM_PT = 10 | ||
NUM_PT = 10 | ||
NUM_PLANES = (NUM_SQ * NUM_PT + 1) | ||
INPUTS = NUM_PLANES * NUM_SQ # 41024 | ||
|
||
def orient(is_white_pov: bool, sq: int): | ||
return (63 * (not is_white_pov)) ^ sq | ||
|
||
def halfkp_idx(is_white_pov: bool, king_sq: int, sq: int, p: chess.Piece): | ||
p_idx = (p.piece_type - 1) * 2 + (p.color != is_white_pov) | ||
return 1 + orient(is_white_pov, sq) + p_idx * NUM_SQ + king_sq * NUM_PLANES | ||
|
||
def get_halfkp_indices(board: chess.Board): | ||
def piece_indices(turn): | ||
indices = torch.zeros(INPUTS) | ||
for sq, p in board.piece_map().items(): | ||
if p.piece_type == chess.KING: | ||
continue | ||
indices[halfkp_idx(turn, orient(turn, board.king(turn)), sq, p)] = 1.0 | ||
return indices | ||
return (piece_indices(chess.WHITE), piece_indices(chess.BLACK)) | ||
NAME = 'HalfKP' |
Oops, something went wrong.