# Path: arrayfire/algorithm.py
# def sum(a, dim=None, nan_val=None):
#     """
#     Calculate the sum of all the elements along a specified dimension.
# 
#     Parameters
#     ----------
#     a  : af.Array
#          Multi dimensional arrayfire array.
#     dim: optional: int. default: None
#          Dimension along which the sum is required.
#     nan_val: optional: scalar. default: None
#          The value that replaces NaN in the array
# 
#     Returns
#     -------
#     out: af.Array or scalar number
#          The sum of all elements in `a` along dimension `dim`.
#          If `dim` is `None`, sum of the entire Array is returned.
#     """
#     if (nan_val is not None):
#         if dim is not None:
#             return _nan_parallel_dim(a, dim, backend.get().af_sum_nan, nan_val)
#         else:
#             return _nan_reduce_all(a, backend.get().af_sum_nan_all, nan_val)
#     else:
#         if dim is not None:
#             return _parallel_dim(a, dim, backend.get().af_sum)
#         else:
#             return _reduce_all(a, backend.get().af_sum_all)
# 
# def count(a, dim=None):
#     """
#     Count the number of non zero elements in an array along a specified dimension.
# 
#     Parameters
#     ----------
#     a  : af.Array
#          Multi dimensional arrayfire array.
#     dim: optional: int. default: None
#          Dimension along which the the non zero elements are to be counted.
# 
#     Returns
#     -------
#     out: af.Array or scalar number
#          The count of non zero elements in `a` along `dim`.
#          If `dim` is `None`, the total number of non zero elements in `a`.
#     """
#     if dim is not None:
#         return _parallel_dim(a, dim, backend.get().af_count)
#     else:
#         return _reduce_all(a, backend.get().af_count_all)
# 
# Path: arrayfire/arith.py
# def cast(a, dtype):
#     """
#     Cast an array to a specified type
# 
#     Parameters
#     ----------
#     a    : af.Array
#            Multi dimensional arrayfire array.
#     dtype: af.Dtype
#            Must be one of the following:
#                - Dtype.f32 for float
#                - Dtype.f64 for double
#                - Dtype.b8  for bool
#                - Dtype.u8  for unsigned char
#                - Dtype.s32 for signed 32 bit integer
#                - Dtype.u32 for unsigned 32 bit integer
#                - Dtype.s64 for signed 64 bit integer
#                - Dtype.u64 for unsigned 64 bit integer
#                - Dtype.c32 for 32 bit complex number
#                - Dtype.c64 for 64 bit complex number
#     Returns
#     --------
#     out  : af.Array
#            array containing the values from `a` after converting to `dtype`.
#     """
#     out=Array()
#     safe_call(backend.get().af_cast(c_pointer(out.arr), a.arr, dtype.value))
#     return out


import inspect
import os
        import numpy as np
from .library import *
from .util import *
from .util import _is_number
from .bcast import _bcast_var
from .base import *
from .index import *
from .index import _Index4
from .algorithm import (sum, count)
from .arith import cast

            if (isinstance(key, Array) and key.type() == Dtype.b8.value):
                n_dims = 1
                if (count(key) == 0):
                    return out

            inds = _get_indices(key)

            safe_call(backend.get().af_index_gen(c_pointer(out.arr),
                                    self.arr, c_dim_t(n_dims), inds.pointer))
            return out
        except RuntimeError as e:
            raise IndexError(str(e))


    def __setitem__(self, key, val):
        """
        Perform self[key] = val

        Note
        ----
        Ellipsis not supported as key
        """
        try:
            n_dims = self.numdims()

            is_boolean_idx = isinstance(key, Array) and key.type() == Dtype.b8.value

            if (is_boolean_idx):
                n_dims = 1

# Path: arrayfire/algorithm.py
# def sum(a, dim=None, nan_val=None):
#     """
#     Calculate the sum of all the elements along a specified dimension.
# 
#     Parameters
#     ----------
#     a  : af.Array
#          Multi dimensional arrayfire array.
#     dim: optional: int. default: None
#          Dimension along which the sum is required.
#     nan_val: optional: scalar. default: None
#          The value that replaces NaN in the array
# 
#     Returns
#     -------
#     out: af.Array or scalar number
#          The sum of all elements in `a` along dimension `dim`.
#          If `dim` is `None`, sum of the entire Array is returned.
#     """
#     if (nan_val is not None):
#         if dim is not None:
#             return _nan_parallel_dim(a, dim, backend.get().af_sum_nan, nan_val)
#         else:
#             return _nan_reduce_all(a, backend.get().af_sum_nan_all, nan_val)
#     else:
#         if dim is not None:
#             return _parallel_dim(a, dim, backend.get().af_sum)
#         else:
#             return _reduce_all(a, backend.get().af_sum_all)
# 
# def count(a, dim=None):
#     """
#     Count the number of non zero elements in an array along a specified dimension.
# 
#     Parameters
#     ----------
#     a  : af.Array
#          Multi dimensional arrayfire array.
#     dim: optional: int. default: None
#          Dimension along which the the non zero elements are to be counted.
# 
#     Returns
#     -------
#     out: af.Array or scalar number
#          The count of non zero elements in `a` along `dim`.
#          If `dim` is `None`, the total number of non zero elements in `a`.
#     """
#     if dim is not None:
#         return _parallel_dim(a, dim, backend.get().af_count)
#     else:
#         return _reduce_all(a, backend.get().af_count_all)
# 
# Path: arrayfire/arith.py
# def cast(a, dtype):
#     """
#     Cast an array to a specified type
# 
#     Parameters
#     ----------
#     a    : af.Array
#            Multi dimensional arrayfire array.
#     dtype: af.Dtype
#            Must be one of the following:
#                - Dtype.f32 for float
#                - Dtype.f64 for double
#                - Dtype.b8  for bool
#                - Dtype.u8  for unsigned char
#                - Dtype.s32 for signed 32 bit integer
#                - Dtype.u32 for unsigned 32 bit integer
#                - Dtype.s64 for signed 64 bit integer
#                - Dtype.u64 for unsigned 64 bit integer
#                - Dtype.c32 for 32 bit complex number
#                - Dtype.c64 for 64 bit complex number
#     Returns
#     --------
#     out  : af.Array
#            array containing the values from `a` after converting to `dtype`.
#     """
#     out=Array()
#     safe_call(backend.get().af_cast(c_pointer(out.arr), a.arr, dtype.value))
#     return out


# Path: arrayfire/array.py
import inspect
import os
        import numpy as np
from .library import *
from .util import *
from .util import _is_number
from .bcast import _bcast_var
from .base import *
from .index import *
from .index import _Index4
from .algorithm import (sum, count)
from .arith import cast


            if (isinstance(key, Array) and key.type() == Dtype.b8.value):
                n_dims = 1
                if (count(key) == 0):
                    return out

            inds = _get_indices(key)

            safe_call(backend.get().af_index_gen(c_pointer(out.arr),
                                    self.arr, c_dim_t(n_dims), inds.pointer))
            return out
        except RuntimeError as e:
            raise IndexError(str(e))


    def __setitem__(self, key, val):
        """
        Perform self[key] = val

        Note
        ----
        Ellipsis not supported as key
        """
        try:
            n_dims = self.numdims()

            is_boolean_idx = isinstance(key, Array) and key.type() == Dtype.b8.value

            if (is_boolean_idx):
                n_dims = 1

                num = count(key)