{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}



module Torch.Internal.Managed.Type.Module where


import Foreign.C.String
import Foreign.C.Types
import Foreign
import Foreign.ForeignPtr.Unsafe
import Torch.Internal.Type
import Torch.Internal.Class
import Torch.Internal.Cast
import Torch.Internal.Objects
import Control.Monad(forM)
import Control.Concurrent.MVar (MVar(..), newEmptyMVar, putMVar, takeMVar)

import qualified Torch.Internal.Unmanaged.Type.Module as Unmanaged

newModule :: ForeignPtr StdString -> IO (ForeignPtr Module)
newModule :: ForeignPtr StdString -> IO (ForeignPtr Module)
newModule = (Ptr StdString -> IO (Ptr Module))
-> ForeignPtr StdString -> IO (ForeignPtr Module)
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
_cast1 Ptr StdString -> IO (Ptr Module)
Unmanaged.newModule

save :: ForeignPtr Module -> FilePath -> IO ()
save :: ForeignPtr Module -> String -> IO ()
save = (Ptr Module -> String -> IO ())
-> ForeignPtr Module -> String -> IO ()
forall a ca x1 cx1 y cy.
(Castable a ca, Castable x1 cx1, Castable y cy) =>
(ca -> cx1 -> IO cy) -> a -> x1 -> IO y
_cast2 Ptr Module -> String -> IO ()
Unmanaged.save

load :: FilePath -> IO (ForeignPtr Module)
load :: String -> IO (ForeignPtr Module)
load = (String -> IO (Ptr Module)) -> String -> IO (ForeignPtr Module)
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
_cast1 String -> IO (Ptr Module)
Unmanaged.load

forward :: ForeignPtr Module -> (ForeignPtr (StdVector IValue)) -> IO (ForeignPtr IValue)
forward :: ForeignPtr Module
-> ForeignPtr (StdVector IValue) -> IO (ForeignPtr IValue)
forward = (Ptr Module -> Ptr (StdVector IValue) -> IO (Ptr IValue))
-> ForeignPtr Module
-> ForeignPtr (StdVector IValue)
-> IO (ForeignPtr IValue)
forall a ca x1 cx1 y cy.
(Castable a ca, Castable x1 cx1, Castable y cy) =>
(ca -> cx1 -> IO cy) -> a -> x1 -> IO y
_cast2 Ptr Module -> Ptr (StdVector IValue) -> IO (Ptr IValue)
Unmanaged.forward

registerParameter :: ForeignPtr Module -> ForeignPtr StdString -> ForeignPtr Tensor -> CBool -> IO ()
registerParameter :: ForeignPtr Module
-> ForeignPtr StdString -> ForeignPtr Tensor -> CBool -> IO ()
registerParameter = (Ptr Module -> Ptr StdString -> Ptr Tensor -> CBool -> IO ())
-> ForeignPtr Module
-> ForeignPtr StdString
-> ForeignPtr Tensor
-> CBool
-> IO ()
forall a ca x1 cx1 x2 cx2 x3 cx3 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable x3 cx3,
 Castable y cy) =>
(ca -> cx1 -> cx2 -> cx3 -> IO cy) -> a -> x1 -> x2 -> x3 -> IO y
_cast4 Ptr Module -> Ptr StdString -> Ptr Tensor -> CBool -> IO ()
Unmanaged.registerParameter

registerModule :: ForeignPtr Module -> ForeignPtr StdString -> ForeignPtr Module -> IO ()
registerModule :: ForeignPtr Module
-> ForeignPtr StdString -> ForeignPtr Module -> IO ()
registerModule = (Ptr Module -> Ptr StdString -> Ptr Module -> IO ())
-> ForeignPtr Module
-> ForeignPtr StdString
-> ForeignPtr Module
-> IO ()
forall a ca x1 cx1 x2 cx2 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable y cy) =>
(ca -> cx1 -> cx2 -> IO cy) -> a -> x1 -> x2 -> IO y
_cast3 Ptr Module -> Ptr StdString -> Ptr Module -> IO ()
Unmanaged.registerModule

train :: ForeignPtr Module -> CBool -> IO ()
train :: ForeignPtr Module -> CBool -> IO ()
train = (Ptr Module -> CBool -> IO ())
-> ForeignPtr Module -> CBool -> IO ()
forall a ca x1 cx1 y cy.
(Castable a ca, Castable x1 cx1, Castable y cy) =>
(ca -> cx1 -> IO cy) -> a -> x1 -> IO y
_cast2 Ptr Module -> CBool -> IO ()
Unmanaged.train

runMethod :: ForeignPtr Module -> ForeignPtr StdString -> ForeignPtr (C10List IValue) -> IO (Ptr IValue)
runMethod :: ForeignPtr Module
-> ForeignPtr StdString
-> ForeignPtr (C10List IValue)
-> IO (Ptr IValue)
runMethod = (Ptr Module
 -> Ptr StdString -> Ptr (C10List IValue) -> IO (Ptr IValue))
-> ForeignPtr Module
-> ForeignPtr StdString
-> ForeignPtr (C10List IValue)
-> IO (Ptr IValue)
forall a ca x1 cx1 x2 cx2 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable y cy) =>
(ca -> cx1 -> cx2 -> IO cy) -> a -> x1 -> x2 -> IO y
_cast3 Ptr Module
-> Ptr StdString -> Ptr (C10List IValue) -> IO (Ptr IValue)
Unmanaged.runMethod

runMethod1 :: ForeignPtr Module -> ForeignPtr StdString -> ForeignPtr IValue -> IO (Ptr IValue)
runMethod1 :: ForeignPtr Module
-> ForeignPtr StdString -> ForeignPtr IValue -> IO (Ptr IValue)
runMethod1 = (Ptr Module -> Ptr StdString -> Ptr IValue -> IO (Ptr IValue))
-> ForeignPtr Module
-> ForeignPtr StdString
-> ForeignPtr IValue
-> IO (Ptr IValue)
forall a ca x1 cx1 x2 cx2 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable y cy) =>
(ca -> cx1 -> cx2 -> IO cy) -> a -> x1 -> x2 -> IO y
_cast3 Ptr Module -> Ptr StdString -> Ptr IValue -> IO (Ptr IValue)
Unmanaged.runMethod1

getParameters :: ForeignPtr Module -> IO (ForeignPtr TensorList)
getParameters :: ForeignPtr Module -> IO (ForeignPtr TensorList)
getParameters = (Ptr Module -> IO (Ptr TensorList))
-> ForeignPtr Module -> IO (ForeignPtr TensorList)
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
_cast1 Ptr Module -> IO (Ptr TensorList)
Unmanaged.getParameters

setParameters :: ForeignPtr Module -> ForeignPtr TensorList -> IO ()
setParameters :: ForeignPtr Module -> ForeignPtr TensorList -> IO ()
setParameters = (Ptr Module -> Ptr TensorList -> IO ())
-> ForeignPtr Module -> ForeignPtr TensorList -> IO ()
forall a ca x1 cx1 y cy.
(Castable a ca, Castable x1 cx1, Castable y cy) =>
(ca -> cx1 -> IO cy) -> a -> x1 -> IO y
_cast2 Ptr Module -> Ptr TensorList -> IO ()
Unmanaged.setParameters

getNamedParameters :: ForeignPtr Module -> IO [(ForeignPtr StdString,ForeignPtr Tensor)]
getNamedParameters :: ForeignPtr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
getNamedParameters ForeignPtr Module
obj = ForeignPtr Module
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Module
obj ((Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
 -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall a b. (a -> b) -> a -> b
$ \Ptr Module
obj' -> do
  [(Ptr StdString, Ptr Tensor)]
v <- Ptr Module -> IO [(Ptr StdString, Ptr Tensor)]
Unmanaged.getNamedParameters Ptr Module
obj'
  [(Ptr StdString, Ptr Tensor)]
-> ((Ptr StdString, Ptr Tensor)
    -> IO (ForeignPtr StdString, ForeignPtr Tensor))
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Ptr StdString, Ptr Tensor)]
v (((Ptr StdString, Ptr Tensor)
  -> IO (ForeignPtr StdString, ForeignPtr Tensor))
 -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> ((Ptr StdString, Ptr Tensor)
    -> IO (ForeignPtr StdString, ForeignPtr Tensor))
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall a b. (a -> b) -> a -> b
$ \(Ptr StdString
a,Ptr Tensor
b) -> do
    ForeignPtr StdString
a' <- Ptr StdString
-> (ForeignPtr StdString -> IO (ForeignPtr StdString))
-> IO (ForeignPtr StdString)
forall r. Ptr StdString -> (ForeignPtr StdString -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr StdString
a ForeignPtr StdString -> IO (ForeignPtr StdString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return 
    ForeignPtr Tensor
b' <- Ptr Tensor
-> (ForeignPtr Tensor -> IO (ForeignPtr Tensor))
-> IO (ForeignPtr Tensor)
forall r. Ptr Tensor -> (ForeignPtr Tensor -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr Tensor
b ForeignPtr Tensor -> IO (ForeignPtr Tensor)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
    (ForeignPtr StdString, ForeignPtr Tensor)
-> IO (ForeignPtr StdString, ForeignPtr Tensor)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr StdString
a',ForeignPtr Tensor
b')

getNamedBuffers :: ForeignPtr Module -> IO [(ForeignPtr StdString,ForeignPtr Tensor)]
getNamedBuffers :: ForeignPtr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
getNamedBuffers ForeignPtr Module
obj = ForeignPtr Module
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Module
obj ((Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
 -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall a b. (a -> b) -> a -> b
$ \Ptr Module
obj' -> do
  [(Ptr StdString, Ptr Tensor)]
v <- Ptr Module -> IO [(Ptr StdString, Ptr Tensor)]
Unmanaged.getNamedBuffers Ptr Module
obj'
  [(Ptr StdString, Ptr Tensor)]
-> ((Ptr StdString, Ptr Tensor)
    -> IO (ForeignPtr StdString, ForeignPtr Tensor))
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Ptr StdString, Ptr Tensor)]
v (((Ptr StdString, Ptr Tensor)
  -> IO (ForeignPtr StdString, ForeignPtr Tensor))
 -> IO [(ForeignPtr StdString, ForeignPtr Tensor)])
-> ((Ptr StdString, Ptr Tensor)
    -> IO (ForeignPtr StdString, ForeignPtr Tensor))
-> IO [(ForeignPtr StdString, ForeignPtr Tensor)]
forall a b. (a -> b) -> a -> b
$ \(Ptr StdString
a,Ptr Tensor
b) -> do
    ForeignPtr StdString
a' <- Ptr StdString
-> (ForeignPtr StdString -> IO (ForeignPtr StdString))
-> IO (ForeignPtr StdString)
forall r. Ptr StdString -> (ForeignPtr StdString -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr StdString
a ForeignPtr StdString -> IO (ForeignPtr StdString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return 
    ForeignPtr Tensor
b' <- Ptr Tensor
-> (ForeignPtr Tensor -> IO (ForeignPtr Tensor))
-> IO (ForeignPtr Tensor)
forall r. Ptr Tensor -> (ForeignPtr Tensor -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr Tensor
b ForeignPtr Tensor -> IO (ForeignPtr Tensor)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
    (ForeignPtr StdString, ForeignPtr Tensor)
-> IO (ForeignPtr StdString, ForeignPtr Tensor)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr StdString
a',ForeignPtr Tensor
b')

getNamedAttributes :: ForeignPtr Module -> IO [(ForeignPtr StdString,ForeignPtr IValue)]
getNamedAttributes :: ForeignPtr Module -> IO [(ForeignPtr StdString, ForeignPtr IValue)]
getNamedAttributes ForeignPtr Module
obj = ForeignPtr Module
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr IValue)])
-> IO [(ForeignPtr StdString, ForeignPtr IValue)]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Module
obj ((Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr IValue)])
 -> IO [(ForeignPtr StdString, ForeignPtr IValue)])
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr IValue)])
-> IO [(ForeignPtr StdString, ForeignPtr IValue)]
forall a b. (a -> b) -> a -> b
$ \Ptr Module
obj' -> do
  [(Ptr StdString, Ptr IValue)]
v <- Ptr Module -> IO [(Ptr StdString, Ptr IValue)]
Unmanaged.getNamedAttributes Ptr Module
obj'
  [(Ptr StdString, Ptr IValue)]
-> ((Ptr StdString, Ptr IValue)
    -> IO (ForeignPtr StdString, ForeignPtr IValue))
-> IO [(ForeignPtr StdString, ForeignPtr IValue)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Ptr StdString, Ptr IValue)]
v (((Ptr StdString, Ptr IValue)
  -> IO (ForeignPtr StdString, ForeignPtr IValue))
 -> IO [(ForeignPtr StdString, ForeignPtr IValue)])
-> ((Ptr StdString, Ptr IValue)
    -> IO (ForeignPtr StdString, ForeignPtr IValue))
-> IO [(ForeignPtr StdString, ForeignPtr IValue)]
forall a b. (a -> b) -> a -> b
$ \(Ptr StdString
a,Ptr IValue
b) -> do
    ForeignPtr StdString
a' <- Ptr StdString
-> (ForeignPtr StdString -> IO (ForeignPtr StdString))
-> IO (ForeignPtr StdString)
forall r. Ptr StdString -> (ForeignPtr StdString -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr StdString
a ForeignPtr StdString -> IO (ForeignPtr StdString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return 
    ForeignPtr IValue
b' <- Ptr IValue
-> (ForeignPtr IValue -> IO (ForeignPtr IValue))
-> IO (ForeignPtr IValue)
forall r. Ptr IValue -> (ForeignPtr IValue -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr IValue
b ForeignPtr IValue -> IO (ForeignPtr IValue)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
    (ForeignPtr StdString, ForeignPtr IValue)
-> IO (ForeignPtr StdString, ForeignPtr IValue)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr StdString
a',ForeignPtr IValue
b')

getNamedModules :: ForeignPtr Module -> IO [(ForeignPtr StdString,ForeignPtr Module)]
getNamedModules :: ForeignPtr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)]
getNamedModules ForeignPtr Module
obj = ForeignPtr Module
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Module
obj ((Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)])
 -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall a b. (a -> b) -> a -> b
$ \Ptr Module
obj' -> do
  [(Ptr StdString, Ptr Module)]
v <- Ptr Module -> IO [(Ptr StdString, Ptr Module)]
Unmanaged.getNamedModules Ptr Module
obj'
  [(Ptr StdString, Ptr Module)]
-> ((Ptr StdString, Ptr Module)
    -> IO (ForeignPtr StdString, ForeignPtr Module))
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Ptr StdString, Ptr Module)]
v (((Ptr StdString, Ptr Module)
  -> IO (ForeignPtr StdString, ForeignPtr Module))
 -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> ((Ptr StdString, Ptr Module)
    -> IO (ForeignPtr StdString, ForeignPtr Module))
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall a b. (a -> b) -> a -> b
$ \(Ptr StdString
a,Ptr Module
b) -> do
    ForeignPtr StdString
a' <- Ptr StdString
-> (ForeignPtr StdString -> IO (ForeignPtr StdString))
-> IO (ForeignPtr StdString)
forall r. Ptr StdString -> (ForeignPtr StdString -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr StdString
a ForeignPtr StdString -> IO (ForeignPtr StdString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return 
    ForeignPtr Module
b' <- Ptr Module
-> (ForeignPtr Module -> IO (ForeignPtr Module))
-> IO (ForeignPtr Module)
forall r. Ptr Module -> (ForeignPtr Module -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr Module
b ForeignPtr Module -> IO (ForeignPtr Module)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
    (ForeignPtr StdString, ForeignPtr Module)
-> IO (ForeignPtr StdString, ForeignPtr Module)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr StdString
a',ForeignPtr Module
b')

getNamedChildren :: ForeignPtr Module -> IO [(ForeignPtr StdString,ForeignPtr Module)]
getNamedChildren :: ForeignPtr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)]
getNamedChildren ForeignPtr Module
obj = ForeignPtr Module
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Module
obj ((Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)])
 -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> (Ptr Module -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall a b. (a -> b) -> a -> b
$ \Ptr Module
obj' -> do
  [(Ptr StdString, Ptr Module)]
v <- Ptr Module -> IO [(Ptr StdString, Ptr Module)]
Unmanaged.getNamedChildren Ptr Module
obj'
  [(Ptr StdString, Ptr Module)]
-> ((Ptr StdString, Ptr Module)
    -> IO (ForeignPtr StdString, ForeignPtr Module))
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Ptr StdString, Ptr Module)]
v (((Ptr StdString, Ptr Module)
  -> IO (ForeignPtr StdString, ForeignPtr Module))
 -> IO [(ForeignPtr StdString, ForeignPtr Module)])
-> ((Ptr StdString, Ptr Module)
    -> IO (ForeignPtr StdString, ForeignPtr Module))
-> IO [(ForeignPtr StdString, ForeignPtr Module)]
forall a b. (a -> b) -> a -> b
$ \(Ptr StdString
a,Ptr Module
b) -> do
    ForeignPtr StdString
a' <- Ptr StdString
-> (ForeignPtr StdString -> IO (ForeignPtr StdString))
-> IO (ForeignPtr StdString)
forall r. Ptr StdString -> (ForeignPtr StdString -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr StdString
a ForeignPtr StdString -> IO (ForeignPtr StdString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return 
    ForeignPtr Module
b' <- Ptr Module
-> (ForeignPtr Module -> IO (ForeignPtr Module))
-> IO (ForeignPtr Module)
forall r. Ptr Module -> (ForeignPtr Module -> IO r) -> IO r
forall a b r. Castable a b => b -> (a -> IO r) -> IO r
uncast Ptr Module
b ForeignPtr Module -> IO (ForeignPtr Module)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
    (ForeignPtr StdString, ForeignPtr Module)
-> IO (ForeignPtr StdString, ForeignPtr Module)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr StdString
a',ForeignPtr Module
b')

toDevice :: ForeignPtr Module -> DeviceType -> Int16 -> IO ()
toDevice :: ForeignPtr Module -> DeviceType -> DeviceType -> IO ()
toDevice = (Ptr Module -> DeviceType -> DeviceType -> IO ())
-> ForeignPtr Module -> DeviceType -> DeviceType -> IO ()
forall a ca x1 cx1 x2 cx2 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable y cy) =>
(ca -> cx1 -> cx2 -> IO cy) -> a -> x1 -> x2 -> IO y
_cast3 Ptr Module -> DeviceType -> DeviceType -> IO ()
Unmanaged.toDevice

clone :: ForeignPtr Module -> IO (ForeignPtr Module)
clone :: ForeignPtr Module -> IO (ForeignPtr Module)
clone = (Ptr Module -> IO (Ptr Module))
-> ForeignPtr Module -> IO (ForeignPtr Module)
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
_cast1 Ptr Module -> IO (Ptr Module)
Unmanaged.clone

define :: ForeignPtr Module -> ForeignPtr StdString -> IO ()
define :: ForeignPtr Module -> ForeignPtr StdString -> IO ()
define = (Ptr Module -> Ptr StdString -> IO ())
-> ForeignPtr Module -> ForeignPtr StdString -> IO ()
forall a ca x1 cx1 y cy.
(Castable a ca, Castable x1 cx1, Castable y cy) =>
(ca -> cx1 -> IO cy) -> a -> x1 -> IO y
_cast2 Ptr Module -> Ptr StdString -> IO ()
Unmanaged.define


-- Note: Not to release "ForeignPtr TensorList" before calling trace, put the pointer to MVar, and touch the reference.
trace :: String -> String -> (ForeignPtr TensorList -> IO (ForeignPtr TensorList)) -> ForeignPtr TensorList -> IO (ForeignPtr Module)
trace :: String
-> String
-> (ForeignPtr TensorList -> IO (ForeignPtr TensorList))
-> ForeignPtr TensorList
-> IO (ForeignPtr Module)
trace String
moduleName String
functionName ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func ForeignPtr TensorList
inputs = do
  MVar (ForeignPtr TensorList)
ref <- IO (MVar (ForeignPtr TensorList))
forall a. IO (MVar a)
newEmptyMVar
  ForeignPtr Module
ret <- (CString -> CString -> Ptr TensorList -> IO (Ptr Module))
-> String
-> String
-> ForeignPtr TensorList
-> IO (ForeignPtr Module)
forall a ca x1 cx1 x2 cx2 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable y cy) =>
(ca -> cx1 -> cx2 -> IO cy) -> a -> x1 -> x2 -> IO y
cast3 (\CString
m CString
f Ptr TensorList
inps -> CString
-> CString
-> (Ptr TensorList -> IO (Ptr TensorList))
-> Ptr TensorList
-> IO (Ptr Module)
Unmanaged.trace CString
m CString
f (MVar (ForeignPtr TensorList)
-> (ForeignPtr TensorList -> IO (ForeignPtr TensorList))
-> Ptr TensorList
-> IO (Ptr TensorList)
trans MVar (ForeignPtr TensorList)
ref ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func) Ptr TensorList
inps) String
moduleName String
functionName ForeignPtr TensorList
inputs
  ForeignPtr TensorList
v <- MVar (ForeignPtr TensorList) -> IO (ForeignPtr TensorList)
forall a. MVar a -> IO a
takeMVar MVar (ForeignPtr TensorList)
ref
  ForeignPtr TensorList -> IO ()
forall a. ForeignPtr a -> IO ()
touchForeignPtr ForeignPtr TensorList
v
  ForeignPtr Module -> IO (ForeignPtr Module)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignPtr Module
ret
  where
    trans :: MVar (ForeignPtr TensorList) -> (ForeignPtr TensorList -> IO (ForeignPtr TensorList)) -> Ptr TensorList -> IO (Ptr TensorList)
    trans :: MVar (ForeignPtr TensorList)
-> (ForeignPtr TensorList -> IO (ForeignPtr TensorList))
-> Ptr TensorList
-> IO (Ptr TensorList)
trans MVar (ForeignPtr TensorList)
ref ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func Ptr TensorList
inputs = do
      ForeignPtr TensorList
inputs' <- Ptr TensorList -> IO (ForeignPtr TensorList)
forall a. CppObject a => Ptr a -> IO (ForeignPtr a)
fromPtr Ptr TensorList
inputs
      ForeignPtr TensorList
ret <- ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func ForeignPtr TensorList
inputs'
      MVar (ForeignPtr TensorList) -> ForeignPtr TensorList -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (ForeignPtr TensorList)
ref ForeignPtr TensorList
ret
      Ptr TensorList -> IO (Ptr TensorList)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr TensorList -> IO (Ptr TensorList))
-> Ptr TensorList -> IO (Ptr TensorList)
forall a b. (a -> b) -> a -> b
$ ForeignPtr TensorList -> Ptr TensorList
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr TensorList
ret

-- Note: Not to release "ForeignPtr TensorList" after calling trace, put the pointer to MVar, and touch the reference.
traceAsGraph :: (ForeignPtr TensorList -> IO (ForeignPtr TensorList)) -> ForeignPtr TensorList -> IO (ForeignPtr (SharedPtr JitGraph))
traceAsGraph :: (ForeignPtr TensorList -> IO (ForeignPtr TensorList))
-> ForeignPtr TensorList -> IO (ForeignPtr (SharedPtr JitGraph))
traceAsGraph ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func ForeignPtr TensorList
inputs = do
  MVar (ForeignPtr TensorList)
ref <- IO (MVar (ForeignPtr TensorList))
forall a. IO (MVar a)
newEmptyMVar
  ForeignPtr (SharedPtr JitGraph)
ret <- (Ptr TensorList -> IO (Ptr (SharedPtr JitGraph)))
-> ForeignPtr TensorList -> IO (ForeignPtr (SharedPtr JitGraph))
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
cast1 (\Ptr TensorList
inps -> (Ptr TensorList -> IO (Ptr TensorList))
-> Ptr TensorList -> IO (Ptr (SharedPtr JitGraph))
Unmanaged.traceAsGraph (MVar (ForeignPtr TensorList)
-> (ForeignPtr TensorList -> IO (ForeignPtr TensorList))
-> Ptr TensorList
-> IO (Ptr TensorList)
trans MVar (ForeignPtr TensorList)
ref ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func) Ptr TensorList
inps) ForeignPtr TensorList
inputs
  ForeignPtr TensorList
v <- MVar (ForeignPtr TensorList) -> IO (ForeignPtr TensorList)
forall a. MVar a -> IO a
takeMVar MVar (ForeignPtr TensorList)
ref
  ForeignPtr TensorList -> IO ()
forall a. ForeignPtr a -> IO ()
touchForeignPtr ForeignPtr TensorList
v
  ForeignPtr (SharedPtr JitGraph)
-> IO (ForeignPtr (SharedPtr JitGraph))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignPtr (SharedPtr JitGraph)
ret
  where
    trans :: MVar (ForeignPtr TensorList) -> (ForeignPtr TensorList -> IO (ForeignPtr TensorList)) -> Ptr TensorList -> IO (Ptr TensorList)
    trans :: MVar (ForeignPtr TensorList)
-> (ForeignPtr TensorList -> IO (ForeignPtr TensorList))
-> Ptr TensorList
-> IO (Ptr TensorList)
trans MVar (ForeignPtr TensorList)
ref ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func Ptr TensorList
inputs = do
      ForeignPtr TensorList
inputs' <- Ptr TensorList -> IO (ForeignPtr TensorList)
forall a. CppObject a => Ptr a -> IO (ForeignPtr a)
fromPtr Ptr TensorList
inputs
      ForeignPtr TensorList
ret <- ForeignPtr TensorList -> IO (ForeignPtr TensorList)
func ForeignPtr TensorList
inputs'
      MVar (ForeignPtr TensorList) -> ForeignPtr TensorList -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar (ForeignPtr TensorList)
ref ForeignPtr TensorList
ret
      Ptr TensorList -> IO (Ptr TensorList)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr TensorList -> IO (Ptr TensorList))
-> Ptr TensorList -> IO (Ptr TensorList)
forall a b. (a -> b) -> a -> b
$ ForeignPtr TensorList -> Ptr TensorList
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr TensorList
ret

printGraph :: ForeignPtr (SharedPtr JitGraph) -> IO (ForeignPtr StdString)
printGraph :: ForeignPtr (SharedPtr JitGraph) -> IO (ForeignPtr StdString)
printGraph ForeignPtr (SharedPtr JitGraph)
graph = (Ptr (SharedPtr JitGraph) -> IO (Ptr StdString))
-> ForeignPtr (SharedPtr JitGraph) -> IO (ForeignPtr StdString)
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
_cast1 Ptr (SharedPtr JitGraph) -> IO (Ptr StdString)
Unmanaged.printGraph ForeignPtr (SharedPtr JitGraph)
graph

printOnnx :: ForeignPtr (SharedPtr JitGraph) -> IO (ForeignPtr StdString)
printOnnx :: ForeignPtr (SharedPtr JitGraph) -> IO (ForeignPtr StdString)
printOnnx ForeignPtr (SharedPtr JitGraph)
graph = (Ptr (SharedPtr JitGraph) -> IO (Ptr StdString))
-> ForeignPtr (SharedPtr JitGraph) -> IO (ForeignPtr StdString)
forall a ca y cy.
(Castable a ca, Castable y cy) =>
(ca -> IO cy) -> a -> IO y
_cast1 Ptr (SharedPtr JitGraph) -> IO (Ptr StdString)
Unmanaged.printOnnx ForeignPtr (SharedPtr JitGraph)
graph

dumpToStr
  :: ForeignPtr Module
  -> CBool
  -> CBool
  -> CBool
  -> IO (ForeignPtr StdString)
dumpToStr :: ForeignPtr Module
-> CBool -> CBool -> CBool -> IO (ForeignPtr StdString)
dumpToStr = (Ptr Module -> CBool -> CBool -> CBool -> IO (Ptr StdString))
-> ForeignPtr Module
-> CBool
-> CBool
-> CBool
-> IO (ForeignPtr StdString)
forall a ca x1 cx1 x2 cx2 x3 cx3 y cy.
(Castable a ca, Castable x1 cx1, Castable x2 cx2, Castable x3 cx3,
 Castable y cy) =>
(ca -> cx1 -> cx2 -> cx3 -> IO cy) -> a -> x1 -> x2 -> x3 -> IO y
_cast4 Ptr Module -> CBool -> CBool -> CBool -> IO (Ptr StdString)
Unmanaged.dumpToStr