Skip to content

Commit

Permalink
Merge pull request #1 from Sopel97/cyclic_reading
Browse files Browse the repository at this point in the history
[WIP] Defer data preparation to native code. Use sparse input tensors.
  • Loading branch information
glinscott committed Nov 8, 2020
2 parents d66419c + 871432b commit f50106b
Show file tree
Hide file tree
Showing 13 changed files with 8,866 additions and 170 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__/
env/
build/
logs/
22 changes: 22 additions & 0 deletions CMakeLists.txt
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 .)
2 changes: 2 additions & 0 deletions compile_data_loader.bat
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
23 changes: 2 additions & 21 deletions halfkp.py
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'
Loading

0 comments on commit f50106b

Please sign in to comment.