[arrayfire] 36/248: Utility functions for generating af_index_t array objects

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:53:52 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.

commit 6ca724712c830fb9215dae9a6ea3e9b6422a650a
Author: pradeep <pradeep at arrayfire.com>
Date:   Wed Sep 2 15:08:08 2015 -0400

    Utility functions for generating af_index_t array objects
---
 docs/details/index.dox |  6 ++++
 include/af/index.h     | 62 ++++++++++++++++++++++++++++++++++++++++++
 src/api/c/index.cpp    | 74 ++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 136 insertions(+), 6 deletions(-)

diff --git a/docs/details/index.dox b/docs/details/index.dox
index 85386b25..90b9924 100644
--- a/docs/details/index.dox
+++ b/docs/details/index.dox
@@ -15,5 +15,11 @@
 \brief Copy and write values in the locations specified by the sequences
 
 \ingroup index_mat
+
+\defgroup index_func_util util
+
+\brief Utility functions to create objects of type \ref af_index_t
+
+\ingroup index_mat
 @}
 */
diff --git a/include/af/index.h b/include/af/index.h
index e3bb77b..98f0e8b 100644
--- a/include/af/index.h
+++ b/include/af/index.h
@@ -289,6 +289,68 @@ extern "C" {
                                 const dim_t ndims, const af_index_t* indices,
                                 const af_array rhs);
 
+    ///
+    /// \brief Create an quadruple of af_index_t array
+    ///
+    /// \param[out] indexers pointer to location where quadruple af_index_t array is created
+    /// \returns \ref af_err error code
+    ///
+    /// \ingroup index_func_util
+    ///
+    AFAPI af_err af_create_indexers(af_index_t** indexers);
+
+    ///
+    /// \brief set \p dim to given indexer af_array \p idx
+    ///
+    /// \param[in] indexer pointer to location where quadruple af_index_t array was created
+    /// \param[in] idx is the af_array indexer for given dimension \p dim
+    /// \param[in] dim is the dimension to be indexed
+    /// \returns \ref af_err error code
+    ///
+    /// \ingroup index_func_util
+    ///
+    AFAPI af_err af_set_array_indexer(af_index_t* indexer, const af_array idx, const dim_t dim);
+
+    ///
+    /// \brief set \p dim to given indexer af_array \p idx
+    ///
+    /// \param[in] indexer pointer to location where quadruple af_index_t array was created
+    /// \param[in] idx is the af_seq indexer for given dimension \p dim
+    /// \param[in] dim is the dimension to be indexed
+    /// \param[in] is_batch indicates if the sequence based indexing is inside a batch operation
+    ///
+    /// \ingroup index_func_util
+    ///
+    AFAPI af_err af_set_seq_indexer(af_index_t* indexer, const af_seq* idx,
+                                  const dim_t dim, const bool is_batch);
+
+    ///
+    /// \brief set \p dim to given indexer af_array \p idx
+    ///
+    /// \param[in] indexer pointer to location where quadruple af_index_t array was created
+    /// \param[in] begin is the beginning index of along dimension \p dim
+    /// \param[in] end is the beginning index of along dimension \p dim
+    /// \param[in] step size along dimension \p dim
+    /// \param[in] dim is the dimension to be indexed
+    /// \param[in] is_batch indicates if the sequence based indexing is inside a batch operation
+    /// \returns \ref af_err error code
+    ///
+    /// \ingroup index_func_util
+    ///
+    AFAPI af_err af_set_seq_param_indexer(af_index_t* indexer,
+                                        const double begin, const double end, const double step,
+                                        const dim_t dim, const bool is_batch);
+
+    ///
+    /// \brief Release's the memory resource used by the quadruple af_index_t array
+    ///
+    /// \param[in] indexers is pointer to location where quadruple af_index_t array is created
+    //  \returns \ref af_err error code
+    ///
+    /// \ingroup index_func_util
+    ///
+    AFAPI af_err af_release_indexers(af_index_t* indexers);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/api/c/index.cpp b/src/api/c/index.cpp
index a9f276d..893559e 100644
--- a/src/api/c/index.cpp
+++ b/src/api/c/index.cpp
@@ -127,12 +127,6 @@ af_err af_lookup(af_array *out, const af_array in, const af_array indices, const
     return AF_SUCCESS;
 }
 
-af_seq
-af_make_seq(double begin, double end, double step) {
-    af_seq seq = {begin, end, step};
-    return seq;
-}
-
 // idxrs parameter to the below static function
 // expects 4 values which is handled appropriately
 // by the C-API af_index_gen
@@ -228,3 +222,71 @@ af_err af_index_gen(af_array *out, const af_array in, const dim_t ndims, const a
 
     return AF_SUCCESS;
 }
+
+af_seq af_make_seq(double begin, double end, double step)
+{
+    af_seq seq = {begin, end, step};
+    return seq;
+}
+
+af_err af_create_indexers(af_index_t** indexers)
+{
+    try {
+        af_index_t* out = new af_index_t[4];
+        std::swap(*indexers, out);
+    }
+    CATCHALL;
+    return AF_SUCCESS;
+}
+
+af_err af_set_array_indexer(af_index_t* indexer, const af_array idx, const dim_t dim)
+{
+    ARG_ASSERT(0, (indexer!=NULL));
+    ARG_ASSERT(1, (idx!=NULL));
+    ARG_ASSERT(2, (dim>=0 && dim<=3));
+    try {
+        indexer[dim].idx.arr = idx;
+        indexer[dim].isBatch = false;
+        indexer[dim].isSeq   = false;
+    }
+    CATCHALL
+        return AF_SUCCESS;
+}
+
+af_err af_set_seq_indexer(af_index_t* indexer, const af_seq* idx, const dim_t dim, const bool is_batch)
+{
+    ARG_ASSERT(0, (indexer!=NULL));
+    ARG_ASSERT(1, (idx!=NULL));
+    ARG_ASSERT(2, (dim>=0 && dim<=3));
+    try {
+        indexer[dim].idx.seq = *idx;
+        indexer[dim].isBatch = is_batch;
+        indexer[dim].isSeq   = true;
+    }
+    CATCHALL
+        return AF_SUCCESS;
+}
+
+af_err af_set_seq_param_indexer(af_index_t* indexer,
+                              const double begin, const double end, const double step,
+                              const dim_t dim, const bool is_batch)
+{
+    ARG_ASSERT(0, (indexer!=NULL));
+    ARG_ASSERT(4, (dim>=0 && dim<=3));
+    try {
+        indexer[dim].idx.seq = af_make_seq(begin, end, step);
+        indexer[dim].isBatch = is_batch;
+        indexer[dim].isSeq   = true;
+    }
+    CATCHALL
+        return AF_SUCCESS;
+}
+
+af_err af_release_indexers(af_index_t* indexers)
+{
+    try {
+        delete[] indexers;
+    }
+    CATCHALL;
+    return AF_SUCCESS;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list