batchMatMulGradient :: Test  
batchMatMulGradient = testCase "batchMatMulGradients" $ do
  
  let dfBuild = do
        x <- TF.render $ TF.zeros $ TF.Shape [2,3, 1 :: Int64]
        w <- TF.zeroInitializedVariable $ TF.Shape [2,1, 2 :: Int64]
        let f = x `TF.batchMatMul` TF.readValue w :: TF.Tensor TF.Build Float
        dfs <- TF.gradients f [x]
        return (x, dfs)
  
  (xShape, dxShape) <- TF.runSession $ do
    (x, dl) <- TF.build dfBuild
    dx <-
      case dl of
        [dx] -> pure dx
        _ -> liftIO $ assertFailure "pattern-match failure in batchMatMulGradient"
    TF.run (TF.shape x, TF.shape dx)
  
  assertEqual "Shape of gradient must match shape of input" xShape (dxShape :: V.Vector Int32)


-- test that gradient of batchMatMul can be taken gradient of
batchMatMulGradient :: Test
batchMatMulGradient = testCase "batchMatMulGradients" $ do
  
  let dfBuild = do
        x <- TF.render $ TF.zeros $ TF.Shape [2,3, 1 :: Int64]
        w <- TF.zeroInitializedVariable $ TF.Shape [2,1, 2 :: Int64]
        let f = x `TF.batchMatMul` TF.readValue w :: TF.Tensor TF.Build Float
        dfs <- TF.gradients f [x]
        return (x, dfs)
  
  (xShape, dxShape) <- TF.runSession $ do
    (x, dl) <- TF.build dfBuild
    dx <-
      case dl of
        [dx] -> pure dx
        _ -> liftIO $ assertFailure "pattern-match failure in batchMatMulGradient"
    TF.run (TF.shape x, TF.shape dx)
  
  assertEqual "Shape of gradient must match shape of input" xShape (dxShape :: V.Vector Int32)


-- test that gradient of batchMatMul can be taken gradient of
batchMatMulGradient = testCase "batchMatMulGradients" $ do
  
  let dfBuild = do
        x <- TF.render $ TF.zeros $ TF.Shape [2,3, 1 :: Int64]
        w <- TF.zeroInitializedVariable $ TF.Shape [2,1, 2 :: Int64]
        let f = x `TF.batchMatMul` TF.readValue w :: TF.Tensor TF.Build Float
        dfs <- TF.gradients f [x]
        return (x, dfs)
  
  (xShape, dxShape) <- TF.runSession $ do
    (x, dl) <- TF.build dfBuild
    dx <-
      case dl of
        [dx] -> pure dx
        _ -> liftIO $ assertFailure "pattern-match failure in batchMatMulGradient"
    TF.run (TF.shape x, TF.shape dx)
  
  assertEqual "Shape of gradient must match shape of input" xShape (dxShape :: V.Vector Int32)


-- test that gradient of batchMatMul can be taken gradient of