{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nBasic 1d upsampling\n===================\n\nIn this example we demonstrate how to employ the utility functions from\n:py:mod:`symjax.tensor.interpolation` which can be used for upsampling\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nimport symjax\nimport symjax.tensor as T\nimport numpy as np\n\nw = T.Placeholder((3,), \"float32\", name=\"w\")\nw_interp1 = T.interpolation.upsample_1d(w, repeat=4, mode=\"nearest\")\nw_interp2 = T.interpolation.upsample_1d(\n    w, repeat=4, mode=\"linear\", boundary_condition=\"mirror\"\n)\nw_interp3 = T.interpolation.upsample_1d(\n    w, repeat=4, mode=\"linear\", boundary_condition=\"periodic\"\n)\nw_interp4 = T.interpolation.upsample_1d(w, repeat=4)\n\nf = symjax.function(w, outputs=[w_interp1, w_interp2, w_interp3, w_interp4])\n\nsamples = f(np.array([1, 2, 3]))\nfig = plt.figure(figsize=(6, 6))\nplt.subplot(411)\nplt.plot(samples[0], \"xg\", linewidth=3, markersize=15)\nplt.plot([0, 5, 10], [1, 2, 3], \"ok\", alpha=0.5)\nplt.title(\"nearest-periodic\")\nplt.xticks([])\n\nplt.subplot(412)\nplt.plot(samples[1], \"xg\", linewidth=3, markersize=15)\nplt.plot([0, 5, 10], [1, 2, 3], \"ok\", alpha=0.5)\nplt.title(\"linear-mirror\")\nplt.xticks([])\n\nplt.subplot(413)\nplt.plot(samples[2], \"xg\", linewidth=3, markersize=15)\nplt.plot([0, 5, 10], [1, 2, 3], \"ok\", alpha=0.5)\nplt.title(\"linear-periodic\")\nplt.xticks([])\n\nplt.subplot(414)\nplt.plot(samples[3], \"xg\", linewidth=3, markersize=15)\nplt.plot([0, 5, 10], [1, 2, 3], \"ok\", alpha=0.5)\nplt.title(\"constant-0\")\n\nplt.tight_layout()"
      ]
    }
  ],
  "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.7.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}