{-# LANGUAGE MultiParamTypeClasses #-}------------------------------------------------------------------------------- |-- Module : BLAS.Tensor.Mutable-- Copyright : Copyright (c) , Patrick Perry <patperry@stanford.edu>-- License : BSD3-- Maintainer : Patrick Perry <patperry@stanford.edu>-- Stability : experimental--moduleBLAS.Tensor.Mutable(MTensor(..),writeElem,modifyElem,)whereimportBLAS.Tensor.BaseimportBLAS.Tensor.ReadOnly-- | Class for modifiable mutable tensors.class(RTensorxiem)=>(MTensorxiem)where-- | Get the maximum number of elements that can be stored in the tensor.getMaxSize::xe->mIntgetMaxSize=getSize-- | Sets all stored elements to zero.setZero::xe->m()-- | Sets all stored elements to the given value.setConstant::e->xe->m()-- | True if the value at a given index can be changedcanModifyElem::xe->i->mBool-- | Set the value of the element at the given index, without doing any-- range checking.unsafeWriteElem::xe->i->e->m()-- | Modify the value of the element at the given index, without doing-- any range checking.unsafeModifyElem::xe->i->(e->e)->m()unsafeModifyElemxif=doe<-unsafeReadElemxiunsafeWriteElemxi(fe)-- | Replace each element by a function applied to itmodifyWith::(e->e)->xe->m()-- | Set the value of the element at the given index.writeElem::(MTensorxiem,Showi)=>xe->i->e->m()writeElemxie=dook<-canModifyElemxicaseokofFalse->fail$"tried to set element at index `"++showi++"'"++" in an object with shape `"++shows++"'"++" but that element cannot be modified"True->unsafeWriteElemxiewheres=shapex-- | Update the value of the element at the given index.modifyElem::(MTensorxiem,Showi)=>xe->i->(e->e)->m()modifyElemxif=dook<-canModifyElemxicaseokofFalse->fail$"tried to modify element at index `"++showi++"'"++" in an object with shape `"++shows++"'"++" but that element cannot be modified"True->unsafeModifyElemxifwheres=shapex