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

module Torch.Internal.Unmanaged.Type.IntArray where


import qualified Language.C.Inline.Cpp as C
import qualified Language.C.Inline.Cpp.Unsafe as C
import qualified Language.C.Inline.Context as C
import qualified Language.C.Types as C
import qualified Language.C.Inline.Unsafe as CUnsafe
import qualified Data.Map as Map
import Foreign.C.String
import Foreign.C.Types
import Foreign
import Foreign.Marshal.Array
import Torch.Internal.Type

C.context $ C.cppCtx <> mempty { C.ctxTypesTable = typeTable }



C.include "<ATen/ScalarType.h>"
C.include "<vector>"



newIntArray
  :: IO (Ptr IntArray)
newIntArray :: IO (Ptr IntArray)
newIntArray  =
  [C.throwBlock| std::vector<int64_t>* { return new std::vector<int64_t>(
    );
  }|]

intArray_empty
  :: Ptr IntArray
  -> IO (CBool)
intArray_empty :: Ptr IntArray -> IO CBool
intArray_empty Ptr IntArray
_obj =
  [CUnsafe.block| bool { return (*$(std::vector<int64_t>* _obj)).empty(
    );
  }|]

intArray_size
  :: Ptr IntArray
  -> IO (CSize)
intArray_size :: Ptr IntArray -> IO CSize
intArray_size Ptr IntArray
_obj =
  [CUnsafe.block| size_t { return (*$(std::vector<int64_t>* _obj)).size(
    );
  }|]

intArray_at_s
  :: Ptr IntArray
  -> CSize
  -> IO (Int64)
intArray_at_s :: Ptr IntArray -> CSize -> IO Int64
intArray_at_s Ptr IntArray
_obj CSize
_s =
  [CUnsafe.block| int64_t { return (*$(std::vector<int64_t>* _obj)).at(
    $(size_t _s));
  }|]

intArray_push_back_l
  :: Ptr IntArray
  -> Int64
  -> IO (())
intArray_push_back_l :: Ptr IntArray -> Int64 -> IO ()
intArray_push_back_l Ptr IntArray
_obj Int64
_v =
  [C.throwBlock| void {  (*$(std::vector<int64_t>* _obj)).push_back(
    $(int64_t _v));
  }|]

intArray_fromList
  :: Ptr IntArray
  -> [Int64]
  -> IO (())
intArray_fromList :: Ptr IntArray -> [Int64] -> IO ()
intArray_fromList Ptr IntArray
_obj [Int64]
_v = do
  let size :: CInt
size = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int64]
_v
  Ptr Int64
ptr <- [C.throwBlock| int64_t* {
    (*$(std::vector<int64_t>* _obj)).resize($(int size));
    return (int64_t*)((*$(std::vector<int64_t>* _obj)).data());
  }|]
  forall a. Storable a => Ptr a -> [a] -> IO ()
pokeArray (Ptr Int64
ptr :: Ptr Int64)  [Int64]
_v

intArray_toList
  :: Ptr IntArray
  -> IO [Int64]
intArray_toList :: Ptr IntArray -> IO [Int64]
intArray_toList Ptr IntArray
_obj = do
  CSize
size <- Ptr IntArray -> IO CSize
intArray_size Ptr IntArray
_obj
  Ptr Int64
ptr <- [CUnsafe.block| int64_t* {
    return (int64_t*)((*$(std::vector<int64_t>* _obj)).data());
  }|]
  forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (forall a b. (Integral a, Num b) => a -> b
fromIntegral CSize
size) (Ptr Int64
ptr :: Ptr Int64)