{-# LANGUAGE MultiParamTypeClasses, FlexibleContexts #-}------------------------------------------------------------------------------- |-- Module : Data.Tensor.Class.ITensor-- Copyright : Copyright (c) , Patrick Perry <patperry@stanford.edu>-- License : BSD3-- Maintainer : Patrick Perry <patperry@stanford.edu>-- Stability : experimental---- Overloaded interface for immutable tensors.moduleData.Tensor.Class.ITensor(ITensor(..),(!),)whereimportData.Tensor.ClassimportData.Ixinfixl9!infixl7*>infixl5`shift`-- | A class for immutable tensors.class(Shapedxi)=>ITensorxiewhere-- | Get the numer of elements stored in the tensor.size::xne->Int-- | Get a new tensor by replacing the elements at the given indices.(//)::xne->[(i,e)]->xne-- | Get the value at the given index, without doing any bounds-checking.unsafeAt::xne->i->e-- | Same as '(//)' but doesn't do any bounds-checking.unsafeReplace::xne->[(i,e)]->xne-- | Get the indices of the elements stored in the tensor.indices::xne->[i]indices=fst.unzip.assocs{-# INLINE indices #-}-- | Get the elements stored in the tensor.elems::xne->[e]elems=snd.unzip.assocs{-# INLINE elems #-}-- | Get the list of @(@index@,@ element@)@ pairs stored in the tensor.assocs::xne->[(i,e)]-- accum :: (e -> e' -> e) -> x e -> [(i,e')] -> x e-- | Apply a function elementwise to a tensor.tmap::(e->e)->xne->xne-- ixmap :: i -> (i -> i) -> x e -> x e-- unsafeIxMap-- | Scale every element by the given value.(*>)::(Nume)=>e->xne->xne(*>)k=tmap(k*){-# INLINE (*>) #-}-- | Add a constant to every element.shift::(Nume)=>e->xne->xneshiftk=tmap(k+){-# INLINE shift #-}-- | Get the value at the given index. Range-checks the argument.(!)::(ITensorxie)=>xne->i->e(!)xi=case(inRangebi)ofFalse->error$"tried to get element at a index `"++showi++"'"++" in an object with shape `"++shows++"'"True->unsafeAtxiwhereb=boundsxs=shapex{-# INLINE (!) #-}