Skip to content

Instantly share code, notes, and snippets.

@TobCap
TobCap / gist:5cce10e98840ee651829b21a68efdc13
Last active December 4, 2021 07:36
R lang tail recursion optimization

R language tail (call|recursion) (optimization|elimination)

List of packages or documents

URL type author (twitter) depends on note
trampoline package @ecologician coro, fastmap, rlang
rcompilertools (tweet post) package @dirk_sch compiler, utils, tibble byte compiler
tailr

調査目的

Windows 10 laptop の価格を比較

調査時点

2020/05/24

背景

Windows 10 WSL2 で NDIVIA GeForce を動かしたい。RAM 32GB 限定

条件

# Original is https://gist.github.com/msakai/e39c25930b661e8175759cc15175d952
# Forked at 2020-01-09
# Attempt to mimick following GADT (Generalized algebraic data type) in Python:
#
# data Expr a where
# Const :: a -> Expr a
# Add :: Expr Int -> Expr Int -> Expr Int
# Eq :: Expr Int -> Expr Int -> Expr Bool
# IfThenElse :: Expr Bool -> Expr a -> Expr a -> Expr a
@TobCap
TobCap / async-example.py
Created August 27, 2019 14:32
python async await example
import asyncio
from time import time
async def slow_a():
print("a start")
await asyncio.sleep(2.5)
print("a end")
async def slow_b():
print("b start")
@TobCap
TobCap / repeat_dataframe.r
Created August 21, 2018 06:24
repeat_dataframe
library(tidyverse)
A <- data.frame(x = 1:3, y = letters[1:3], stringsAsFactors = FALSE)
shape <- matrix(1, 2, 3)
rep_df <- function(df_, shape) {
df_ %>%
list() %>%
matrix %>%
kronecker(shape, FUN = rep.int) %>%
@TobCap
TobCap / 20180620
Created June 20, 2018 04:02
too long sentences for rechord.cc
# Copyright(c) 2018 @tobakucptlsm
# Released under the MIT license
# http://opensource.org/licenses/mit-license.php
Gm911|Em911|Fm79/Bb|=|
Gm911|Em911|EbM7913|=|
Gm911======Em911|=|
Fm7911|====_Gbm7911_Gm911|
=======Em911|=======EbM7913|
=|=|
Sys.setenv(LANG="C") # for english error message on Windows
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.4.4
#> Warning: package 'tibble' was built under R version 3.4.4
#> Warning: package 'tidyr' was built under R version 3.4.4

#sessionInfo()
#with(R.version, print(c(platform, version.string)))
MulLayer <- function(){
x_ <- NA
y_ <- NA
forward <- function(x, y){
x_ <<- x
y_ <<- y
x * y
}
@TobCap
TobCap / out.txt
Last active January 31, 2018 15:06
$ python --version
Python 3.6.0 :: Anaconda 4.3.1 (x86_64)
$ python -c "import pandas as pd; print(pd.__version__)"
0.19.2
$ python
Python 3.6.0 |Anaconda 4.3.1 (x86_64)| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exam1(False)
rise_error=False