/+     None&'ST To define a sparseT dimension we need a cumulative array, an index array and a dimensionality parameterCumulative array (# nonzero entries per degree of freedom). Not all storage formats (e.g. COO for rank-2 tensors) need this information.(Index array (indices of nonzero entries)'Size of the tensor along this dimension To define a dense4 dimension we only need the dimensionality parameterNone&'ST wA statically-typed tensor shape parameter that supports both sparse and dense dimensions. Dimensions are indexed with 7 indices, which should be enough for most applications. #Constructor for a dense dimension #Constructor for a sparse dimension +Rank of a shape (i.e. number of dimensions)3Dimension of a shape (i.e. list of dimension sizes)Shape of a dense vectorShape of a sparse vector)Shape of a dense rank-2 tensor (a matrix) MShape of a rank-2 CSR tensor (dense in the first index, sparse in the second)!5Shape of a rank-2 COO tensor (sparse in both indices)"#$%& '() ! Safe&'-FST*!Zero-rank dimensionality - scalar+"List-like concatenation of indices,+*,*+None&'3STU The  9 type. Tensor data entries are stored as one single array-8Construct a tensor given a shape and a vector of entries.Access the shape of a  /Access the raw data of a  0!Number of nonzero tensor elements1 Tensor rank2Tensor dimensions ./012  Safe&'QV i3inner product of two vectorsmatrix-vector actionmatrix-matrix productParametric higher-order abstract syntax (PHOAS), after B. Oliveira, A. Loeh, `Abstract Syntax Graphs for Domain Specific Languages` *Inject a constant into the abstract syntaxBind a variable into a closure!Bind two variables into a closure4Helper functions 59Benchmark: `tree 50` should compute the answer instantly.AThis proves that the PHOAS formulation preserves variable sharing Semantic function for evaluation6789:;<3=>?@4AB5CDEF678<;:93>=@?None&'U+ ExceptionsG/IN: Tensor reduction syntax (Einstein notation).OUT: stride program (how to read/write memory)Ytaco compiles a tensor expression (e.g. C = A_{ijk}B_{k} ) into a series of nested loops.*dimensions : can be either dense or sparse%internally, tensor data is stored in dense vectors,"contract A_{ijk}B_{k} over the third index"Tensor contraction Inject two   constant into @\s, while ensuring that all the contraction indices are compatible with those of the tensors. Throws a L if any index is nonnegative or too large for the shape of the given tensor.Tensor contraction indicesContraction function   H       !"#$%&'()*+,-./012345!"6789:;<=>?@ABCDEFGHIJK#taco-0.2.0.0-5MnrWPGYOEEAD5eA7lXWNzData.Tensor.CompilerData.Dim Data.ShapeData.Shape.Static Data.TensorData.Tensor.Compiler.PHOASSdsCmlsIdxsDimDddDimShZDSTensorPhoasvarlet_let2_eval CException IncompatShape IncompatIxcontract$fExceptionCException$fShowCException$fEqCExceptionbaseGHC.IntInt32rankdimmkD1mkS1mkD2mkCSRmkCOOCOOCSRD2S1D1:.:#Zi:!IdxmkTtshapetdatannzExprlift1treeEEICW2BinOpDivMulSubAddDotKonstLetVarlift2plusk evalBinOpv1v2mkVar