$ python xp_nested_array.py --src-xp numpy --dst-xp numpy --shape "(3, 224, 224)" --batch-size 10
Shape: (3, 224, 224)
Batch size: 10
Running numpy.array(<List[numpy.ndarray]>) in 10000 times...
3.857709832955152
This file contains hidden or 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
import argparse | |
import timeit | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--number', type=int, default=10000000) | |
parser.add_argument('--device', type=str, default="native:0") | |
parser.add_argument('--variables', type=int, default=1) | |
parser.add_argument('--require-grad', action="store_true", default=False) | |
parser.add_argument('--batch-size', type=int, default=1) | |
parser.add_argument('--unsafe', action="store_true", default=False) |
This file contains hidden or 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
import argparse | |
import timeit | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--number', type=int, default=20) | |
parser.add_argument('--device', type=str, default="native:0") | |
parser.add_argument('--batch-size', type=int, default=1) | |
parser.add_argument('--indices', choices=['list', 'numpy', 'chainerx']) | |
parser.add_argument('--data', default='mnist', help='Path to the directory that contains MNIST dataset') | |
args = parser.parse_args() |
This file contains hidden or 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
#include QMK_KEYBOARD_H | |
extern keymap_config_t keymap_config; | |
#define _QWERTY 0 | |
#define _LOWER 1 | |
#define _RAISE 2 | |
#define _ADJUST 16 | |
enum custom_keycodes { |
This file contains hidden or 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
>>> np.array([[[0, 4], [2, 6]], [[1, 5], [3, 7]]], dtype='b') | |
array([[[0, 4], | |
[2, 6]], | |
[[1, 5], | |
[3, 7]]], dtype=int8) | |
>>> ctypes.string_at(np.array([[[0, 4], [2, 6]], [[1, 5], [3, 7]]], dtype='b').ctypes.data, 8) # .data.tobytes() doesn't work properly | |
b'\x00\x04\x02\x06\x01\x05\x03\x07' | |
>>> np.array([[[0, 4], [2, 6]], [[1, 5], [3, 7]]], dtype='b').__array_interface__ | |
{'data': (23426096, False), 'strides': None, 'descr': [('', '|i1')], 'typestr': '|i1', 'shape': (2, 2, 2), 'version': 3} | |
>>> np.array([[[0, 4], [2, 6]], [[1, 5], [3, 7]]], dtype='b').flags |
This file contains hidden or 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
#!/usr/bin/env python | |
import argparse | |
import chainer | |
import chainer.functions as F | |
import chainer.links as L | |
from chainer import training | |
from chainer.training import extensions | |
import numpy as np |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import FreeCAD | |
import importCSG | |
import importDXF | |
def csg_to_dxf(src, dst): | |
doc = importCSG.open(src) | |
importDXF.export([doc.TopologicalSortedObjects[0]], dst) # assumes it has single root object | |
FreeCAD.closeDocument(doc.Name) |
This file contains hidden or 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
// The original idea comes from a post by Alex Krush. | |
// https://medium.com/@akrush95/global-cached-state-in-react-using-hooks-context-and-local-storage-166eacf8ab46 | |
import React, { useCallback, useEffect, useReducer, useRef } from 'react'; | |
export const createCachedContext = ({ storageKey, defaultValue }) => { | |
const initializer = (initialState) => { | |
const localState = localStorage.getItem(storageKey); | |
if (localState) { | |
try { |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# ref. https://qiita.com/k-jimon/items/f02fae75e853a9c02127 | |
from collections import deque, defaultdict, Counter | |
from itertools import chain, islice, takewhile | |
import MeCab | |
import os | |
import random | |
import re |