{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.arange(1, 7).view(1, 3, 2).float()\n",
    "twovec = torch.Tensor([1, -1]).view(1,1, 2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = torch.rand(2, 3, 2) * 2 - 1.0\n",
    "y\n",
    "\n",
    "new = torch.zeros_like(y[:,:,0]).long()\n",
    "print(y)\n",
    "print(new)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new - (y[:,:,0] > 0).long()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list(range(10))[:1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.rand(2, 3)\n",
    "c = torch.Tensor([1, -1]).float()\n",
    "c.view(1, -1).mm(x).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.tensor([1.0, 2.0, 3.0, 4.0], requires_grad=True).view(2, 2)\n",
    "x = x.unsqueeze(0)\n",
    "x.repeat_interleave(4, dim=0).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch.nn as nn\n",
    "lin = nn.Linear(3, 4)\n",
    "print(lin)\n",
    "print(lin.weight.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "z = torch.rand(4, 2, 3, 5)\n",
    "z.transpose\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y.t().matmul(z).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = torch.rand(3, 8)\n",
    "y = y.unsqueeze(0).unsqueeze(0)\n",
    "y.repeat_interleave(2, dim=1).repeat_interleave(2,)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y= torch.arange(1, 5).view(2, 2).expand((10, 3, 2, 2))\n",
    "y = torch.tensor([1,2,3,4], dtype=torch.float32, requires_grad=True).view(2, 2)\n",
    "y = y.expand(3, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y[0][0][0] = 9\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import torch.nn.functional as F\n",
    "np.relu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.rand(4, 2, 3)\n",
    "x = x.transpose(0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "z = np.arange(24).reshape(3,2,4)\n",
    "print(z)\n",
    "lo, hi = np.moveaxis(z, 0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "lohis = torch.arange(0, 120).view(5, 3, 2, 4) #(5, 3, 2, 4)\n",
    "lohis.transpose(0, 2)[0] - lohis.transpose(0, 2)[1]\n",
    "\n",
    "lohis.dim()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Want to test the following:\n",
    "\"\"\"\n",
    "Interval MM should work how? \n",
    "[N1, N2, N3, ..., 2, M] and [N, 2, C]\n",
    "\"\"\"\n",
    "# MASK TEST \n",
    "x = torch.rand(5, 2, 3)\n",
    "y = torch.rand(5, 2, 3)\n",
    "z = torch.zeros(5, 3).long()\n",
    "z += (y[:,0,:] > 0.3).long()\n",
    "z -= (y[:,1,:] > 0.7).long()\n",
    "print(x)\n",
    "print(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xx = x.transpose(0, 1).shape\n",
    "xx[(z < 0).expand()] = 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q = torch.rand(4, 2, 3, 3)\n",
    "\n",
    "qq = torch.rand(4, 3)\n",
    "print(qq)\n",
    "qq.unsqueeze(1).expand()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = torch.rand(3, 4)\n",
    "y = torch.rand(3, 4)\n",
    "torch.stack([x,y], dim=1).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo(x, alpha=None, beta=None):\n",
    "    print('alpha', eval('alpha'))\n",
    "    \n",
    "    print(vars())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "foo(1230)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = {1:2}\n",
    "class Foo:\n",
    "    def __init__(self, item):\n",
    "        self.item = item \n",
    "foo = Foo(x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('FOO', foo.item)\n",
    "delattr(foo, 'item')\n",
    "print(x)\n",
    "print(foo.item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class XXX:\n",
    "    def __init__(self, alpha, beta, gamma):\n",
    "        print(vars())\n",
    "XXX(1, 2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def foo(m=123, n=456):\n",
    "    print(locals())\n",
    "    \n",
    "foo(**{'m': 999, 'n':34})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/matt/grad/lipMIP/scratch'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
