From commits-return-11332-archive-asf-public=cust-asf.ponee.io@tvm.apache.org Tue Apr 14 03:18:12 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id EDFEA18066D for ; Tue, 14 Apr 2020 05:18:11 +0200 (CEST) Received: (qmail 59427 invoked by uid 500); 14 Apr 2020 03:18:11 -0000 Mailing-List: contact commits-help@tvm.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tvm.apache.org Delivered-To: mailing list commits@tvm.apache.org Received: (qmail 59418 invoked by uid 99); 14 Apr 2020 03:18:11 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Apr 2020 03:18:11 +0000 From: GitBox To: commits@tvm.apache.org Subject: [GitHub] [incubator-tvm] tqchen commented on a change in pull request #5289: add tensorflow cumsum Message-ID: <158683429127.29721.6012643971369194042.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Tue, 14 Apr 2020 03:18:11 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit tqchen commented on a change in pull request #5289: add tensorflow cumsum URL: https://github.com/apache/incubator-tvm/pull/5289#discussion_r407842044 ########## File path: topi/include/topi/transform.h ########## @@ -1105,6 +1105,88 @@ inline tvm::te::Tensor matmul(const tvm::te::Tensor& A, return tvm::te::compute(output_shape, l, name, tag); } +/** + * Compute the cumulative sum of the tensor `A` along `axis`. + * + * By default, this operation performs an inclusive cumsum, which means that the first + * element of the input is identical to the first element of the output: + * + * ```python + * cumsum([a, b, c]) # [a, a + b, a + b + c] + * ``` + * + * By setting the `exclusive` kwarg to `True`, an exclusive cumsum is performed + * instead: + * + * ```python + * cumsum([a, b, c], exclusive=True) # [0, a, a + b] + * ``` + * + * By setting the `reverse` kwarg to `True`, the cumsum is performed in the + * opposite direction: + * + * ```python + * cumsum([a, b, c], reverse=True) # [a + b + c, b + c, c] + * ``` + * + * The `reverse` and `exclusive` kwargs can also be combined: + * + * ```python + * cumsum([a, b, c], exclusive=True, reverse=True) # [b + c, c, 0] + * ``` + * + * @param A Input tensor + * @param axis Must be in the range `[-rank(x), rank(x))` + * @param exclusive Perform exclusive cumsum + * @param reverse Performed in the opposite direction + * @param name The name of the operation + * @param tag The tag to mark the operation + * @return A Tensor whose op member is the cumsum operation + */ +inline tvm::te::Tensor cumsum(const tvm::te::Tensor& A, + int axis, + bool exclusive = false, + bool reverse = false, + std::string name = "T_cumsum", + std::string tag = kCumsum) { + int totalSize = static_cast(A->shape.size()); + if (axis < 0) { + axis = totalSize + axis; + } + auto maxLength = A->shape[axis]; + auto l = [&](const Array& input_indices) { Review comment: We can do a similar workaround by also run reverse and tranpose on these axis .. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services