Updated vimtex and snippets
This commit is contained in:
parent
84a6b218fe
commit
10bf23a6ec
44 changed files with 4209 additions and 69 deletions
109
LuaSnip/python/docs.lua
Normal file
109
LuaSnip/python/docs.lua
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
local helpers = require('personal.luasnip-helper-funcs')
|
||||
local get_visual = helpers.get_visual
|
||||
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
|
||||
return
|
||||
{
|
||||
-- FUNCTION PARAMETERS for use in docstrings, with heading
|
||||
s({trig="PP", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
Parameters
|
||||
----------
|
||||
<> : <>
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- FUNCTION RETURNS for use in docstrings, with heading
|
||||
s({trig="RR", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
Returns
|
||||
----------
|
||||
<> : <>
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- NOTES docstring section
|
||||
s({trig="NN", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
NOTES
|
||||
-----
|
||||
]],
|
||||
{ }
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- PRE-CONDITION docstring section
|
||||
s({trig="prr", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
Pre-Conditions
|
||||
--------------
|
||||
]],
|
||||
{ }
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- -- POST-CONDITION docstring section
|
||||
-- s({trig="pss", snippetType="autosnippet"},
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- Post-Conditions
|
||||
-- ---------------
|
||||
-- ]],
|
||||
-- { }
|
||||
-- ),
|
||||
-- {condition = line_begin}
|
||||
-- ),
|
||||
-- FUNCTION PARAMETER for use in docstrings
|
||||
s({trig="::", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
<> : <>
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- LONG STRING OF DASHES FOR COMMENTS
|
||||
s({trig = "--", snippetType="autosnippet"},
|
||||
{t('# -------------------------------------------------------------------- #')},
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- MULTILINE COMMENT
|
||||
s({trig = "cc", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
"""
|
||||
<>
|
||||
"""
|
||||
]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
}
|
||||
125
LuaSnip/python/mpl.lua
Normal file
125
LuaSnip/python/mpl.lua
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
local helpers = require('personal.luasnip-helper-funcs')
|
||||
local get_visual = helpers.get_visual
|
||||
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
|
||||
return
|
||||
{
|
||||
-- NEW FIGURE, AXES
|
||||
s({trig="fx", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[fig, ax = plt.subplots(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- plt.
|
||||
s({trig=";p", snippetType="autosnippet"},
|
||||
{t("plt.")}
|
||||
),
|
||||
-- plt.plot()
|
||||
s({trig="pll", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[plt.plot(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- plt.show()
|
||||
s({trig="pss", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[plt.show()]],
|
||||
{ }
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- AXIS PLOT
|
||||
s({trig="xp", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[ax.plot(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- AXIS SET_XLABEL
|
||||
s({trig="xxl", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[ax.set_xlabel(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- AXIS SET_YLABEL
|
||||
s({trig="xyl", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[ax.set_ylabel(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- AXIS SET_TITLE
|
||||
s({trig="xt", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[ax.set_title(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- TIGHT LAYOUT
|
||||
s({trig="ttl", snippetType="autosnippet"},
|
||||
{t("plt.tight_layout()")},
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- STEM PLOT
|
||||
s({trig="stem", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
(markers, stemlines, baseline) = ax.stem(<>)
|
||||
plt.setp(markers, marker='o', markerfacecolor=<>, markeredgecolor="none", markersize=6)
|
||||
plt.setp(baseline, color=<>, linestyle="-")
|
||||
plt.setp(stemlines, linestyle="--", color=<>, linewidth=2)
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3),
|
||||
i(4)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- REMOVE SPINE FUNCTION
|
||||
s({trig="spines"},
|
||||
fmta(
|
||||
[[
|
||||
def remove_spines(ax):
|
||||
"""
|
||||
Removes top and right spines from the inputted Matplotlib axis. This is for
|
||||
aesthetic purposes only and has no practical function.
|
||||
"""
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
ax.get_xaxis().tick_bottom()
|
||||
ax.get_yaxis().tick_left()
|
||||
]],
|
||||
{
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
19
LuaSnip/python/numpy.lua
Normal file
19
LuaSnip/python/numpy.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
local helpers = require('personal.luasnip-helper-funcs')
|
||||
local get_visual = helpers.get_visual
|
||||
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
|
||||
return
|
||||
{
|
||||
-- NP.LOADTXT
|
||||
s({trig="nlt", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
np.loadtxt(<>)
|
||||
]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
163
LuaSnip/python/python.lua
Normal file
163
LuaSnip/python/python.lua
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
local helpers = require('personal.luasnip-helper-funcs')
|
||||
local get_visual = helpers.get_visual
|
||||
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
|
||||
return
|
||||
{
|
||||
-- PRINT STATEMENT
|
||||
s({trig="pp", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[print(<>)]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- MAIN FUNCTION
|
||||
s({trig="main", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
if __name__ == "__main__":
|
||||
<>
|
||||
]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- CLASS
|
||||
s({trig="class"},
|
||||
fmta(
|
||||
[[
|
||||
class <>(<>):
|
||||
def __init__(self<>):
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3),
|
||||
i(4),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- EXIT MAIN FUNCTION with sys.exit()
|
||||
s({trig="XX", snippetType="autosnippet"},
|
||||
{ t("sys.exit()") },
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- FUNCTION DEFINITION WITH CHOICE NODE DOCSTRING
|
||||
-- The idea is to let you choose if you want to use the docstring or not
|
||||
s({trig="ff", snippetType="autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
def <>(<>):
|
||||
<><>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
c(3, {sn(nil, {t({"\"\"\"", ""}), t(" "), i(1, ""), t({"", " \"\"\"", " "})}), t("")}),
|
||||
-- t(" "),
|
||||
d(4, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- TIME, i.e. snippet for timing code execution
|
||||
s({trig="time"},
|
||||
fmta(
|
||||
[[
|
||||
start = time.time()
|
||||
<>
|
||||
end = time.time()
|
||||
]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
}
|
||||
)
|
||||
),
|
||||
-- for _ in range()
|
||||
s({trig="frr", snippetType = "autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
for <> in range(<>):
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- IF STATEMENT
|
||||
s({trig="iff", snippetType = "autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
if <>:
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
d(2, get_visual),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- with open(filename) as file
|
||||
s({trig="wof", snippetType = "autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
with open(<>) as <>:
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2, 'file'),
|
||||
i(0),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- RETURN STATEMENT
|
||||
s({trig = ";r", snippetType = "autosnippet"},
|
||||
{ t("return") },
|
||||
{ condition = line_begin }
|
||||
),
|
||||
-- KWARGS STATEMENT
|
||||
s({trig = ";k", snippetType = "autosnippet", wordTrig=false},
|
||||
{ t("kwargs") }
|
||||
),
|
||||
-- KWARGS.GET
|
||||
s({trig="kgg", snippetType = "autosnippet"},
|
||||
fmta(
|
||||
[[
|
||||
kwargs.get('<>', '<>')
|
||||
]],
|
||||
{
|
||||
d(1, get_visual),
|
||||
i(2)
|
||||
}
|
||||
)
|
||||
),
|
||||
-- SELF (for use in classes)
|
||||
s({trig = ";s", snippetType = "autosnippet"},
|
||||
{ t("self.") }
|
||||
),
|
||||
-- SELF (for use in classes) without dot
|
||||
s({trig = ";S", snippetType = "autosnippet"},
|
||||
{ t("self") }
|
||||
),
|
||||
-- TRACEBACK
|
||||
s({trig = "tbb", snippetType = "autosnippet"},
|
||||
{ t("print(traceback.format_exc())") },
|
||||
{ condition = line_begin }
|
||||
),
|
||||
|
||||
}
|
||||
131
LuaSnip/python/torch.lua
Normal file
131
LuaSnip/python/torch.lua
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
local helpers = require('personal.luasnip-helper-funcs')
|
||||
local get_visual = helpers.get_visual
|
||||
|
||||
local line_begin = require("luasnip.extras.expand_conditions").line_begin
|
||||
|
||||
return
|
||||
{
|
||||
-- COMMON IMPORTS
|
||||
s({trig="itorch"},
|
||||
fmt(
|
||||
[[
|
||||
import torch
|
||||
from torch import nn
|
||||
from torch.utils.data import Dataset, DataLoader
|
||||
]],
|
||||
{
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- NETWORK MODEL TEMPLATE
|
||||
s({trig="model"},
|
||||
fmta(
|
||||
[[
|
||||
class FooNet(nn.Module):
|
||||
def __init__(self):
|
||||
super(FooNet, self).__init__()
|
||||
<>
|
||||
|
||||
def forward(self, x):
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- CUSTOM DATASET TEMPLATE
|
||||
s({trig="dataset"},
|
||||
fmta(
|
||||
[[
|
||||
class FooDataset(Dataset):
|
||||
def __init__(self, ...):
|
||||
<>
|
||||
|
||||
def __getitem__(self, index):
|
||||
# Returns the (feature vector, label) tuple at index `index`
|
||||
<>
|
||||
|
||||
def __len__(self):
|
||||
# Return number of instances in dataset
|
||||
<>
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
i(2),
|
||||
i(3)
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- SGD OPTIMIZER
|
||||
s({trig="optim"},
|
||||
fmta(
|
||||
[[
|
||||
optim = torch.optim.SGD(model.parameters(), lr=<>)
|
||||
]],
|
||||
{
|
||||
i(1),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- TRAINING LOOP TEMPLATE
|
||||
s({trig="train"},
|
||||
fmta(
|
||||
[[
|
||||
def train_loop(dataloader, model, loss_fn, optim):
|
||||
N = len(dataloader.dataset)
|
||||
|
||||
# Loop over all minibatches in dataset
|
||||
for mb, (X, y) in enumerate(dataloader):
|
||||
# Compute prediction and loss
|
||||
pred = model(X)
|
||||
loss = loss_fn(pred, y)
|
||||
|
||||
# Backpropagation
|
||||
optimizer.zero_grad()
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
|
||||
# Log loss and number of instances trained
|
||||
if mb % <> == 0:
|
||||
loss, n = loss.item(), mb * len(X)
|
||||
print("loss: {:.7f} [{:5d}/{:5d}]".format(loss, n, N))
|
||||
|
||||
]],
|
||||
{
|
||||
i(1, "100"),
|
||||
}
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
-- TEST LOOP TEMPLATE
|
||||
s({trig="test"},
|
||||
fmta(
|
||||
[[
|
||||
def test_loop(dataloader, model, loss_fn):
|
||||
N = len(dataloader.dataset)
|
||||
num_batches = len(dataloader)
|
||||
test_loss = 0
|
||||
correct_preds = 0
|
||||
|
||||
with torch.no_grad():
|
||||
for X, y in dataloader:
|
||||
pred = model(X)
|
||||
test_loss += loss_fn(pred, y).item()
|
||||
correct_preds += (pred.argmax(1) == y).type(torch.float).sum().item()
|
||||
|
||||
test_loss /= num_batches
|
||||
print("Test Error: \n Accuracy: {:.1f}%\n Avg loss per minibatch: {:8f} \n".format((100*correct_preds/N), test_loss))
|
||||
]],
|
||||
{ }
|
||||
),
|
||||
{condition = line_begin}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue