Performing tensor SVD using cuTensorNet adopts a very similar workflow as :ref:`QR example`. Here, we highlight the notable differences between the two APIs. The full code can be found in the `NVIDIA/cuQuantum `_ repository (`here `_). ------------------------ Define SVD decomposition ------------------------ As with QR decomposition, we first define the SVD decomposition to perform with the data type, modes partition, and the extents. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_svd_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #2 :end-before: Sphinx: #3 .. note:: To perform fixed extent truncation, we directly set ``maxExtent`` to half of the full extent corresponding to exact SVD. ------------------------------- Setup SVD truncation parameters ------------------------------- Once the SVD decomposition is defined, we can follow the same workflow as :ref:`QR example` for data allocation and tensor descriptor initialization. Before querying workspace, we can choose different SVD options in `cutensornetTensorSVDConfig_t`. Meanwhile, we can create `cutensornetTensorSVDInfo_t` to keep track of runtime truncation information. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_svd_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #5 :end-before: Sphinx: #6 --------- Execution --------- Next, we can query and allocate the workspace with `cutensornetWorkspaceComputeSVDSizes`, which is very similar to its QR counterpart. At this stage, we can perform the SVD decomposition by calling `cutensornetTensorSVD`. .. literalinclude:: ../../../../tensor_network/samples/approxTN/tensor_svd_example.cu :language: c++ :linenos: :lineno-match: :start-after: Sphinx: #7 :end-before: Sphinx: #8 .. note:: Since we turned on weighted truncation options in this example, we need to restore the tensor descriptors for U and V if we wish to perform the same computation multiple times. After the computation, we still need to free up all resources.