Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Raw File Download
Permalink

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
content badge Iframe embedding
swh:1:cnt:f011d7902641030f77354a06f4ca687c9e8fef05
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Vector Fields\n",
    "\n",
    "The standard way to represent $N$-dimensional vector fields in *tntorch* is via a list of $N$ tensors, each of which has $N$ dimensions. Functions that accept or return vector fields do so in that form. For example, `gradient()`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3D TT tensor:\n",
      "\n",
      " 64  64  64\n",
      "  |   |   |\n",
      " (0) (1) (2)\n",
      " / \\ / \\ / \\\n",
      "1   10  10  1\n",
      ", 3D TT tensor:\n",
      "\n",
      " 64  64  64\n",
      "  |   |   |\n",
      " (0) (1) (2)\n",
      " / \\ / \\ / \\\n",
      "1   10  10  1\n",
      ", 3D TT tensor:\n",
      "\n",
      " 64  64  64\n",
      "  |   |   |\n",
      " (0) (1) (2)\n",
      " / \\ / \\ / \\\n",
      "1   10  10  1\n",
      "]\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "torch.set_default_dtype(torch.float64)\n",
    "import tntorch as tn\n",
    "\n",
    "t = tn.rand([64]*3, ranks_tt=10)\n",
    "grad = tn.gradient(t)\n",
    "print(grad)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can check that the curl of any gradient is 0:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(1.0344e-06)\n",
      "tensor(1.4569e-06)\n",
      "tensor(2.5995e-06)\n"
     ]
    }
   ],
   "source": [
    "curl = tn.curl(tn.gradient(t))  # List of 3 3D tensors\n",
    "print(tn.norm(curl[0]))\n",
    "print(tn.norm(curl[1]))\n",
    "print(tn.norm(curl[2]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's also check that the divergence of any curl is zero (we'll use a random, non-gradient vector field here):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(4.8832e-08)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vf = [tn.rand([64]*3, ranks_tt=1) for n in range(3)]\n",
    "tn.norm(tn.divergence(tn.curl(vf)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "... and that the Laplacian of a scalar field `t` equals the divergence of `t`'s gradient:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(0.)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tn.norm(tn.laplacian(t) - tn.divergence(tn.gradient(t)))"
   ]
  }
 ],
 "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.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top