<commit_before>import logging
import array
import numpy as np

import gomill
import go_strings

# name -> (function, dtype)
reg_cube = {}
reg_label = {}
def register(where, name):
    def registrator(func):
        where[name] = func
        return func
    return registrator

@register(reg_label, 'simple_label')
def get_label_simple(move, boardsize=19):
    row, col = move
    return np.array((boardsize * row + col,), dtype='uint8')

@register(reg_label, 'expanded_label')
def get_label_exp(move, boardsize=19):
    row, col = move
    ret = np.zeros((boardsize, boardsize), dtype='uint8')
    ret[row][col] = 1
    return ret

@register(reg_cube, 'clark_storkey_2014')
def get_cube_clark_storkey_2014(board, ko_point, player):
    """
    Planes compatible with the Clark and Storkey 2014 paper
    (arXiv:1412.3409v1)
    
    The returned value is pretty inefficient, since only 1 bit out of each
    uint8 is used; so np.packbits should be probably applied before storing
    the data to disk.
    """
    colors, strings, liberties = go_strings.board2strings(board)
    opponent = gomill.common.opponent_of(player)

    def is_our_stone((row, col)):
        return board.get(row, col) == player
    def is_enemy_stone((row, col)):
        return board.get(row, col) == opponent
<commit_msg>cubes: added numpy.binpacked expanded label<commit_after>import logging
import array
import numpy as np

import gomill
import go_strings

# name -> (function, dtype)
reg_cube = {}
reg_label = {}
def register(where, name):
    def registrator(func):
        where[name] = func
        return func
    return registrator

@register(reg_label, 'simple_label')
def get_label_simple(move, boardsize=19):
    row, col = move
    return np.array((boardsize * row + col,), dtype='uint8')

@register(reg_label, 'expanded_label')
def get_label_exp(move, boardsize=19):
    row, col = move
    ret = np.zeros((boardsize, boardsize), dtype='uint8')
    ret[row][col] = 1
    return ret

@register(reg_label, 'expanded_label_packed')
def get_label_exp_packed(move, boardsize=19):
    label = get_label_exp(move, boardsize)
    return np.packbits(label)

@register(reg_cube, 'clark_storkey_2014')
def get_cube_clark_storkey_2014(board, ko_point, player):
    """
    Planes compatible with the Clark and Storkey 2014 paper
    (arXiv:1412.3409v1)
    
    The returned value is pretty inefficient, since only 1 bit out of each
    uint8 is used; so np.packbits should be probably applied before storing
    the data to disk.
    """
    colors, strings, liberties = go_strings.board2strings(board)
    opponent = gomill.common.opponent_of(player)

    def is_our_stone((row, col)):
        return board.get(row, col) == player
    def is_enemy_stone((row, col)):
        return board.get(row, col) == opponent

{'fraction_non_alphanumeric': 0.10658082975679542, 'fraction_numerical': 0.022889842632331903, 'mean_word_length': 3.932980599647266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4238169', 'n_tokens_mistral': 961, 'n_tokens_neox': 912, 'n_words': 256}