/*! * Copyright (c) 2016 by Contributors * \file op.h * \brief definition of all the operators * \author Chuntao Hong, Xin Li */ #ifndef MXNET_CPP_OP_H_ #define MXNET_CPP_OP_H_ #include <string> #include <vector> #include "mxnet-cpp/base.h" #include "mxnet-cpp/shape.h" #include "mxnet-cpp/op_util.h" #include "mxnet-cpp/operator.h" #include "dmlc/optional.h" #include "nnvm/tuple.h" namespace mxnet { namespace cpp { /*! * \brief Adds arguments element-wise. * * The storage type of ``elemwise_add`` output depends on storage types of inputs * * - elemwise_add(row_sparse, row_sparse) = row_sparse * - elemwise_add(csr, csr) = csr * - elemwise_add(default, csr) = default * - elemwise_add(csr, default) = default * - elemwise_add(default, rsp) = default * - elemwise_add(rsp, default) = default * - otherwise, ``elemwise_add`` generates output with default storage * * * \param symbol_name name of the resulting symbol * \param lhs first input * \param rhs second input * \return new symbol */ inline Symbol elemwise_add(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("elemwise_add") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Subtracts arguments element-wise. * * The storage type of ``elemwise_sub`` output depends on storage types of inputs * * - elemwise_sub(row_sparse, row_sparse) = row_sparse * - elemwise_sub(csr, csr) = csr * - elemwise_sub(default, csr) = default * - elemwise_sub(csr, default) = default * - elemwise_sub(default, rsp) = default * - elemwise_sub(rsp, default) = default * - otherwise, ``elemwise_sub`` generates output with default storage * * * \param symbol_name name of the resulting symbol * \param lhs first input * \param rhs second input * \return new symbol */ inline Symbol elemwise_sub(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("elemwise_sub") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Multiplies arguments element-wise. * * The storage type of ``elemwise_mul`` output depends on storage types of inputs * * - elemwise_mul(default, default) = default * - elemwise_mul(row_sparse, row_sparse) = row_sparse * - elemwise_mul(default, row_sparse) = row_sparse * - elemwise_mul(row_sparse, default) = row_sparse * - elemwise_mul(csr, csr) = csr * - otherwise, ``elemwise_mul`` generates output with default storage * * * \param symbol_name name of the resulting symbol * \param lhs first input * \param rhs second input * \return new symbol */ inline Symbol elemwise_mul(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("elemwise_mul") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Divides arguments element-wise. * * The storage type of ``elemwise_div`` output is always dense * * * \param symbol_name name of the resulting symbol * \param lhs first input * \param rhs second input * \return new symbol */ inline Symbol elemwise_div(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("elemwise_div") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Calculate Smooth L1 Loss(lhs, scalar) by summing * * .. math:: * * f(x) = * \begin{cases} * (\sigma x)^2/2,& \text{if }x < 1/\sigma^2\\ * |x|-0.5/\sigma^2,& \text{otherwise} * \end{cases} * * where :math:`x` is an element of the tensor *lhs* and :math:`\sigma` is the * * Example:: * * smooth_l1([1, 2, 3, 4]) = [0.5, 1.5, 2.5, 3.5] * smooth_l1([1, 2, 3, 4], scalar=1) = [0.5, 1.5, 2.5, 3.5] * * * * Defined in src/operator/tensor/elemwise_binary_scalar_op_extended.cc:L104 * \param symbol_name name of the resulting symbol * \param data source input * \param scalar scalar input * \return new symbol */ inline Symbol smooth_l1(const std::string& symbol_name, Symbol data, mx_float scalar) { return Operator("smooth_l1") .SetParam("scalar", scalar) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Reshapes the input array. * * .. note:: ``Reshape`` is deprecated, use ``reshape`` * * Given an array and a shape, this function returns a copy of the array in the * The shape is a tuple of integers such as (2,3,4). The size of the new shape * * Example:: * * reshape([1,2,3,4], shape=(2,2)) = [[1,2], [3,4]] * * Some dimensions of the shape can take special values from the set {0, -1, -2, * * - ``0`` copy this dimension from the input to the output shape. * * Example:: * * - input shape = (2,3,4), shape = (4,0,2), output shape = (4,3,2) * - input shape = (2,3,4), shape = (2,0,0), output shape = (2,3,4) * * - ``-1`` infers the dimension of the output shape by using the remainder of the * keeping the size of the new array same as that of the input array. * At most one dimension of shape can be -1. * * Example:: * * - input shape = (2,3,4), shape = (6,1,-1), output shape = (6,1,4) * - input shape = (2,3,4), shape = (3,-1,8), output shape = (3,1,8) * - input shape = (2,3,4), shape=(-1,), output shape = (24,) * * - ``-2`` copy all/remainder of the input dimensions to the output shape. * * Example:: * * - input shape = (2,3,4), shape = (-2,), output shape = (2,3,4) * - input shape = (2,3,4), shape = (2,-2), output shape = (2,3,4) * - input shape = (2,3,4), shape = (-2,1,1), output shape = (2,3,4,1,1) * * - ``-3`` use the product of two consecutive dimensions of the input shape as * * Example:: * * - input shape = (2,3,4), shape = (-3,4), output shape = (6,4) * - input shape = (2,3,4,5), shape = (-3,-3), output shape = (6,20) * - input shape = (2,3,4), shape = (0,-3), output shape = (2,12) * - input shape = (2,3,4), shape = (-3,-2), output shape = (6,4) * * - ``-4`` split one dimension of the input into two dimensions passed subsequent * * Example:: * * - input shape = (2,3,4), shape = (-4,1,2,-2), output shape =(1,2,3,4) * - input shape = (2,3,4), shape = (2,-4,-1,3,-2), output shape = (2,1,3,4) * * If the argument `reverse` is set to 1, then the special values are inferred * * Example:: * * - without reverse=1, for input shape = (10,5,4), shape = (-1,0), output shape * - with reverse=1, output shape will be (50,4). * * * * Defined in src/operator/tensor/matrix_op.cc:L201 * \param symbol_name name of the resulting symbol * \param data Input data to reshape. * \param shape The target shape * \param reverse If true then the special values are inferred from right to left * \param target_shape (Deprecated! Use ``shape`` instead.) Target new shape. One and * \param keep_highest (Deprecated! Use ``shape`` instead.) Whether keep the highest dim * unchanged.If set to true, then the first dim in target_shape is ignored,and * \return new symbol */ inline Symbol Reshape(const std::string& symbol_name, Symbol data, Shape shape = Shape(), bool reverse = false, Shape target_shape = Shape(), bool keep_highest = false) { return Operator("Reshape") .SetParam("shape", shape) .SetParam("reverse", reverse) .SetParam("target_shape", target_shape) .SetParam("keep_highest", keep_highest) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Flattens the input array into a 2-D array by collapsing the higher dimensions. * * .. note:: `Flatten` is deprecated. Use `flatten` instead. * * For an input array with shape ``(d1, d2, ..., dk)``, `flatten` operation * the input array into an output array of shape ``(d1, d2*...*dk)``. * * Note that the bahavior of this function is different from numpy.ndarray.flatten, * which behaves similar to mxnet.ndarray.reshape((-1,)). * * Example:: * * x = [[ * [1,2,3], * [4,5,6], * [7,8,9] * ], * [ [1,2,3], * [4,5,6], * [7,8,9] * ]], * * flatten(x) = [[ 1., 2., 3., 4., 5., 6., 7., 8., 9.], * [ 1., 2., 3., 4., 5., 6., 7., 8., 9.]] * * * * Defined in src/operator/tensor/matrix_op.cc:L293 * \param symbol_name name of the resulting symbol * \param data Input array. * \return new symbol */ inline Symbol Flatten(const std::string& symbol_name, Symbol data) { return Operator("Flatten") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Permutes the dimensions of an array. * * Examples:: * * x = [[ 1, 2], * [ 3, 4]] * * transpose(x) = [[ 1., 3.], * [ 2., 4.]] * * x = [[[ 1., 2.], * [ 3., 4.]], * * [[ 5., 6.], * [ 7., 8.]]] * * transpose(x) = [[[ 1., 5.], * [ 3., 7.]], * * [[ 2., 6.], * [ 4., 8.]]] * * transpose(x, axes=(1,0,2)) = [[[ 1., 2.], * [ 5., 6.]], * * [[ 3., 4.], * [ 7., 8.]]] * * * Defined in src/operator/tensor/matrix_op.cc:L377 * \param symbol_name name of the resulting symbol * \param data Source input * \param axes Target axis order. By default the axes will be inverted. * \return new symbol */ inline Symbol transpose(const std::string& symbol_name, Symbol data, Shape axes = Shape()) { return Operator("transpose") .SetParam("axes", axes) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Inserts a new axis of size 1 into the array shape * * For example, given ``x`` with shape ``(2,3,4)``, then ``expand_dims(x, axis=1)`` * will return a new array with shape ``(2,1,3,4)``. * * * * Defined in src/operator/tensor/matrix_op.cc:L418 * \param symbol_name name of the resulting symbol * \param data Source input * \param axis Position where new axis is to be inserted. Suppose that the input * `NDArray`'s dimension is `ndim`, the range of the inserted axis is `[-ndim, * \return new symbol */ inline Symbol expand_dims(const std::string& symbol_name, Symbol data, int axis) { return Operator("expand_dims") .SetParam("axis", axis) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Slices a region of the array. * * .. note:: ``crop`` is deprecated. Use ``slice`` instead. * * This function returns a sliced array between the indices given * by `begin` and `end` with the corresponding `step`. * * For an input array of ``shape=(d_0, d_1, ..., d_n-1)``, * slice operation with ``begin=(b_0, b_1...b_m-1)``, * ``end=(e_0, e_1, ..., e_m-1)``, and ``step=(s_0, s_1, ..., s_m-1)``, * where m <= n, results in an array with the shape * ``(|e_0-b_0|/|s_0|, ..., |e_m-1-b_m-1|/|s_m-1|, d_m, ..., d_n-1)``. * * The resulting array's *k*-th dimension contains elements * from the *k*-th dimension of the input array starting * from index ``b_k`` (inclusive) with step ``s_k`` * until reaching ``e_k`` (exclusive). * * If the *k*-th elements are `None` in the sequence of `begin`, `end`, * and `step`, the following rule will be used to set default values. * If `s_k` is `None`, set `s_k=1`. If `s_k > 0`, set `b_k=0`, `e_k=d_k`; * else, set `b_k=d_k-1`, `e_k=-1`. * * The storage type of ``slice`` output depends on storage types of inputs * * - slice(csr) = csr * - otherwise, ``slice`` generates output with default storage * * .. note:: When input data storage type is csr, it only supports * step=(), or step=(None,), or step=(1,) to generate a csr output. * For other step parameter values, it falls back to slicing * a dense tensor. * * Example:: * * x = [[ 1., 2., 3., 4.], * [ 5., 6., 7., 8.], * [ 9., 10., 11., 12.]] * * slice(x, begin=(0,1), end=(2,4)) = [[ 2., 3., 4.], * [ 6., 7., 8.]] * slice(x, begin=(None, 0), end=(None, 3), step=(-1, 2)) = [[9., 11.], * [5., 7.], * [1., 3.]] * * * Defined in src/operator/tensor/matrix_op.cc:L508 * \param symbol_name name of the resulting symbol * \param data Source input * \param begin starting indices for the slice operation, supports negative indices. * \param end ending indices for the slice operation, supports negative indices. * \param step step for the slice operation, supports negative values. * \return new symbol */ inline Symbol slice(const std::string& symbol_name, Symbol data, Shape begin, Shape end, Shape step = Shape()) { return Operator("slice") .SetParam("begin", begin) .SetParam("end", end) .SetParam("step", step) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Slices along a given axis. * * Returns an array slice along a given `axis` starting from the `begin` index * to the `end` index. * * Examples:: * * x = [[ 1., 2., 3., 4.], * [ 5., 6., 7., 8.], * [ 9., 10., 11., 12.]] * * slice_axis(x, axis=0, begin=1, end=3) = [[ 5., 6., 7., 8.], * [ 9., 10., 11., 12.]] * * slice_axis(x, axis=1, begin=0, end=2) = [[ 1., 2.], * [ 5., 6.], * [ 9., 10.]] * * slice_axis(x, axis=1, begin=-3, end=-1) = [[ 2., 3.], * [ 6., 7.], * [ 10., 11.]] * * * Defined in src/operator/tensor/matrix_op.cc:L598 * \param symbol_name name of the resulting symbol * \param data Source input * \param axis Axis along which to be sliced, supports negative indexes. * \param begin The beginning index along the axis to be sliced, supports negative * \param end The ending index along the axis to be sliced, supports negative indexes. * \return new symbol */ inline Symbol slice_axis(const std::string& symbol_name, Symbol data, int axis, int begin, dmlc::optional<int> end) { return Operator("slice_axis") .SetParam("axis", axis) .SetParam("begin", begin) .SetParam("end", end) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Slices a region of the array like the shape of another array. * * This function is similar to ``slice``, however, the `begin` are always `0`s * and `end` of specific axes are inferred from the second input `shape_like`. * * Given the second `shape_like` input of ``shape=(d_0, d_1, ..., d_n-1)``, * a ``slice_like`` operator with default empty `axes`, it performs the * following operation: * * `` out = slice(input, begin=(0, 0, ..., 0), end=(d_0, d_1, ..., d_n-1))``. * * When `axes` is not empty, it is used to speficy which axes are being sliced. * * Given a 4-d input data, ``slice_like`` operator with ``axes=(0, 2, -1)`` * will perform the following operation: * * `` out = slice(input, begin=(0, 0, 0, 0), end=(d_0, None, d_2, d_3))``. * * Note that it is allowed to have first and second input with different * however, you have to make sure the `axes` are specified and not exceeding the * dimension limits. * * For example, given `input_1` with ``shape=(2,3,4,5)`` and `input_2` with * ``shape=(1,2,3)``, it is not allowed to use: * * `` out = slice_like(a, b)`` because ndim of `input_1` is 4, and ndim of * is 3. * * The following is allowed in this situation: * * `` out = slice_like(a, b, axes=(0, 2))`` * * Example:: * * x = [[ 1., 2., 3., 4.], * [ 5., 6., 7., 8.], * [ 9., 10., 11., 12.]] * * y = [[ 0., 0., 0.], * [ 0., 0., 0.]] * * slice_like(x, y) = [[ 1., 2., 3.] * [ 5., 6., 7.]] * slice_like(x, y, axes=(0, 1)) = [[ 1., 2., 3.] * [ 5., 6., 7.]] * slice_like(x, y, axes=(0)) = [[ 1., 2., 3., 4.] * [ 5., 6., 7., 8.]] * slice_like(x, y, axes=(-1)) = [[ 1., 2., 3.] * [ 5., 6., 7.] * [ 9., 10., 11.]] * * * Defined in src/operator/tensor/matrix_op.cc:L667 * \param symbol_name name of the resulting symbol * \param data Source input * \param shape_like Shape like input * \param axes List of axes on which input data will be sliced according to the * corresponding size of the second input. By default will slice on all axes. * \return new symbol */ inline Symbol slice_like(const std::string& symbol_name, Symbol data, Symbol shape_like, Shape axes = Shape()) { return Operator("slice_like") .SetParam("axes", axes) .SetInput("data", data) .SetInput("shape_like", shape_like) .CreateSymbol(symbol_name); } /*! * \brief Clips (limits) the values in an array. * * Given an interval, values outside the interval are clipped to the interval * Clipping ``x`` between `a_min` and `a_x` would be:: * * clip(x, a_min, a_max) = max(min(x, a_max), a_min)) * * Example:: * * x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] * * clip(x,1,8) = [ 1., 1., 2., 3., 4., 5., 6., 7., 8., 8.] * * The storage type of ``clip`` output depends on storage types of inputs and the * parameter values: * * - clip(default) = default * - clip(row_sparse, a_min <= 0, a_max >= 0) = row_sparse * - clip(csr, a_min <= 0, a_max >= 0) = csr * - clip(row_sparse, a_min < 0, a_max < 0) = default * - clip(row_sparse, a_min > 0, a_max > 0) = default * - clip(csr, a_min < 0, a_max < 0) = csr * - clip(csr, a_min > 0, a_max > 0) = csr * * * * Defined in src/operator/tensor/matrix_op.cc:L725 * \param symbol_name name of the resulting symbol * \param data Input array. * \param a_min Minimum value * \param a_max Maximum value * \return new symbol */ inline Symbol clip(const std::string& symbol_name, Symbol data, mx_float a_min, mx_float a_max) { return Operator("clip") .SetParam("a_min", a_min) .SetParam("a_max", a_max) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Repeats elements of an array. * * By default, ``repeat`` flattens the input array into 1-D and then repeats the * elements:: * * x = [[ 1, 2], * [ 3, 4]] * * repeat(x, repeats=2) = [ 1., 1., 2., 2., 3., 3., 4., 4.] * * The parameter ``axis`` specifies the axis along which to perform repeat:: * * repeat(x, repeats=2, axis=1) = [[ 1., 1., 2., 2.], * [ 3., 3., 4., 4.]] * * repeat(x, repeats=2, axis=0) = [[ 1., 2.], * [ 1., 2.], * [ 3., 4.], * [ 3., 4.]] * * repeat(x, repeats=2, axis=-1) = [[ 1., 1., 2., 2.], * [ 3., 3., 4., 4.]] * * * * Defined in src/operator/tensor/matrix_op.cc:L798 * \param symbol_name name of the resulting symbol * \param data Input data array * \param repeats The number of repetitions for each element. * \param axis The axis along which to repeat values. The negative numbers are * interpreted counting from the backward. By default, use the flattened input * \return new symbol */ inline Symbol repeat(const std::string& symbol_name, Symbol data, int repeats, dmlc::optional<int> axis = dmlc::optional<int>()) { return Operator("repeat") .SetParam("repeats", repeats) .SetParam("axis", axis) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Repeats the whole array multiple times. * * If ``reps`` has length *d*, and input array has dimension of *n*. There are * three cases: * * - **n=d**. Repeat *i*-th dimension of the input by ``reps[i]`` times:: * * x = [[1, 2], * [3, 4]] * * tile(x, reps=(2,3)) = [[ 1., 2., 1., 2., 1., 2.], * [ 3., 4., 3., 4., 3., 4.], * [ 1., 2., 1., 2., 1., 2.], * [ 3., 4., 3., 4., 3., 4.]] * * - **n>d**. ``reps`` is promoted to length *n* by pre-pending 1's to it. Thus for * an input shape ``(2,3)``, ``repos=(2,)`` is treated as ``(1,2)``:: * * * tile(x, reps=(2,)) = [[ 1., 2., 1., 2.], * [ 3., 4., 3., 4.]] * * - **n<d**. The input is promoted to be d-dimensional by prepending new axes. So * shape ``(2,2)`` array is promoted to ``(1,2,2)`` for 3-D replication:: * * tile(x, reps=(2,2,3)) = [[[ 1., 2., 1., 2., 1., 2.], * [ 3., 4., 3., 4., 3., 4.], * [ 1., 2., 1., 2., 1., 2.], * [ 3., 4., 3., 4., 3., 4.]], * * [[ 1., 2., 1., 2., 1., 2.], * [ 3., 4., 3., 4., 3., 4.], * [ 1., 2., 1., 2., 1., 2.], * [ 3., 4., 3., 4., 3., 4.]]] * * * Defined in src/operator/tensor/matrix_op.cc:L859 * \param symbol_name name of the resulting symbol * \param data Input data array * \param reps The number of times for repeating the tensor a. Each dim size of reps must * be a positive integer. If reps has length d, the result will have dimension of * max(d, a.ndim); If a.ndim < d, a is promoted to be d-dimensional by prepending * \return new symbol */ inline Symbol tile(const std::string& symbol_name, Symbol data, Shape reps) { return Operator("tile") .SetParam("reps", reps) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Reverses the order of elements along given axis while preserving array shape. * * Note: reverse and flip are equivalent. We use reverse in the following examples. * * Examples:: * * x = [[ 0., 1., 2., 3., 4.], * [ 5., 6., 7., 8., 9.]] * * reverse(x, axis=0) = [[ 5., 6., 7., 8., 9.], * [ 0., 1., 2., 3., 4.]] * * reverse(x, axis=1) = [[ 4., 3., 2., 1., 0.], * [ 9., 8., 7., 6., 5.]] * * * Defined in src/operator/tensor/matrix_op.cc:L900 * \param symbol_name name of the resulting symbol * \param data Input data array * \param axis The axis which to reverse elements. * \return new symbol */ inline Symbol reverse(const std::string& symbol_name, Symbol data, Shape axis) { return Operator("reverse") .SetParam("axis", axis) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Join a sequence of arrays along a new axis. * * The axis parameter specifies the index of the new axis in the dimensions of the * result. For example, if axis=0 it will be the first dimension and if axis=-1 it * will be the last dimension. * * Examples:: * * x = [1, 2] * y = [3, 4] * * stack(x, y) = [[1, 2], * [3, 4]] * stack(x, y, axis=1) = [[1, 3], * [2, 4]] * * \param symbol_name name of the resulting symbol * \param data List of arrays to stack * \param num_args Number of inputs to be stacked. * \param axis The axis in the result array along which the input arrays are stacked. * \return new symbol */ inline Symbol stack(const std::string& symbol_name, const std::vector<Symbol>& data, int num_args, int axis = 0) { return Operator("stack") .SetParam("num_args", num_args) .SetParam("axis", axis) (data) .CreateSymbol(symbol_name); } /*! * \brief Remove single-dimensional entries from the shape of an array. * Same behavior of defining the output tensor shape as numpy.squeeze for the most * See the following note for exception. * * Examples:: * * data = [[[0], [1], [2]]] * squeeze(data) = [0, 1, 2] * squeeze(data, axis=0) = [[0], [1], [2]] * squeeze(data, axis=2) = [[0, 1, 2]] * squeeze(data, axis=(0, 2)) = [0, 1, 2] * * .. Note:: * The output of this operator will keep at least one dimension not removed. For * squeeze([[[4]]]) = [4], while in numpy.squeeze, the output will become a scalar. * * \param symbol_name name of the resulting symbol * \param data data to squeeze * \param axis Selects a subset of the single-dimensional entries in the shape. If an * \return new symbol */ inline Symbol squeeze(const std::string& symbol_name, const std::vector<Symbol>& data, dmlc::optional<Shape> axis = dmlc::optional<Shape>()) { return Operator("squeeze") .SetParam("axis", axis) (data) .CreateSymbol(symbol_name); } /*! * \brief Rearranges(permutes) data from depth into blocks of spatial data. * Similar to ONNX DepthToSpace operator: * https://github.com/onnx/onnx/blob/master/docs/Operators.md#DepthToSpace. * The output is a new tensor where the values from depth dimension are moved in * to height and width dimension. The reverse of this operation is * * .. math:: * * \begin{gather*} * x \prime = reshape(x, [N, block\_size, block\_size, C / (block\_size ^ 2), H * * x \prime \prime = transpose(x \prime, [0, 3, 4, 1, 5, 2]) \\ * y = reshape(x \prime \prime, [N, C / (block\_size ^ 2), H * block\_size, W * * \end{gather*} * * where :math:`x` is an input tensor with default layout as :math:`[N, C, H, W]`: * and :math:`y` is the output tensor of layout :math:`[N, C / (block\_size ^ 2), * * Example:: * * x = [[[[0, 1, 2], * [3, 4, 5]], * [[6, 7, 8], * [9, 10, 11]], * [[12, 13, 14], * [15, 16, 17]], * [[18, 19, 20], * [21, 22, 23]]]] * * depth_to_space(x, 2) = [[[[0, 6, 1, 7, 2, 8], * [12, 18, 13, 19, 14, 20], * [3, 9, 4, 10, 5, 11], * [15, 21, 16, 22, 17, 23]]]] * * * Defined in src/operator/tensor/matrix_op.cc:L1052 * \param symbol_name name of the resulting symbol * \param data Input ndarray * \param block_size Blocks of [block_size. block_size] are moved * \return new symbol */ inline Symbol depth_to_space(const std::string& symbol_name, Symbol data, int block_size) { return Operator("depth_to_space") .SetParam("block_size", block_size) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Rearranges(permutes) blocks of spatial data into depth. * Similar to ONNX SpaceToDepth operator: * https://github.com/onnx/onnx/blob/master/docs/Operators.md#SpaceToDepth * * The output is a new tensor where the values from height and width dimension are * moved to the depth dimension. The reverse of this operation is * * .. math:: * * \begin{gather*} * x \prime = reshape(x, [N, C, H / block\_size, block\_size, W / block\_size, * x \prime \prime = transpose(x \prime, [0, 3, 5, 1, 2, 4]) \\ * y = reshape(x \prime \prime, [N, C * (block\_size ^ 2), H / block\_size, W / * \end{gather*} * * where :math:`x` is an input tensor with default layout as :math:`[N, C, H, W]`: * and :math:`y` is the output tensor of layout :math:`[N, C * (block\_size ^ 2), * * Example:: * * x = [[[[0, 6, 1, 7, 2, 8], * [12, 18, 13, 19, 14, 20], * [3, 9, 4, 10, 5, 11], * [15, 21, 16, 22, 17, 23]]]] * * * space_to_depth(x, 2) = [[[[0, 1, 2], * [3, 4, 5]], * [[6, 7, 8], * [9, 10, 11]], * [[12, 13, 14], * [15, 16, 17]], * [[18, 19, 20], * [21, 22, 23]]]] * * * Defined in src/operator/tensor/matrix_op.cc:L1106 * \param symbol_name name of the resulting symbol * \param data Input ndarray * \param block_size Blocks of [block_size. block_size] are moved * \return new symbol */ inline Symbol space_to_depth(const std::string& symbol_name, Symbol data, int block_size) { return Operator("space_to_depth") .SetParam("block_size", block_size) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the element-wise sine of the input array. * * The input should be in radians (:math:`2\pi` rad equals 360 degrees). * * .. math:: * sin([0, \pi/4, \pi/2]) = [0, 0.707, 1] * * The storage type of ``sin`` output depends upon the input storage type: * * - sin(default) = default * - sin(row_sparse) = row_sparse * - sin(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L46 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol sin(const std::string& symbol_name, Symbol data) { return Operator("sin") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the element-wise cosine of the input array. * * The input should be in radians (:math:`2\pi` rad equals 360 degrees). * * .. math:: * cos([0, \pi/4, \pi/2]) = [1, 0.707, 0] * * The storage type of ``cos`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L89 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol cos(const std::string& symbol_name, Symbol data) { return Operator("cos") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the element-wise tangent of the input array. * * The input should be in radians (:math:`2\pi` rad equals 360 degrees). * * .. math:: * tan([0, \pi/4, \pi/2]) = [0, 1, -inf] * * The storage type of ``tan`` output depends upon the input storage type: * * - tan(default) = default * - tan(row_sparse) = row_sparse * - tan(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L139 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol tan(const std::string& symbol_name, Symbol data) { return Operator("tan") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise inverse sine of the input array. * * The input should be in the range `[-1, 1]`. * The output is in the closed interval of [:math:`-\pi/2`, :math:`\pi/2`]. * * .. math:: * arcsin([-1, -.707, 0, .707, 1]) = [-\pi/2, -\pi/4, 0, \pi/4, \pi/2] * * The storage type of ``arcsin`` output depends upon the input storage type: * * - arcsin(default) = default * - arcsin(row_sparse) = row_sparse * - arcsin(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L160 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol arcsin(const std::string& symbol_name, Symbol data) { return Operator("arcsin") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise inverse cosine of the input array. * * The input should be in range `[-1, 1]`. * The output is in the closed interval :math:`[0, \pi]` * * .. math:: * arccos([-1, -.707, 0, .707, 1]) = [\pi, 3\pi/4, \pi/2, \pi/4, 0] * * The storage type of ``arccos`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L179 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol arccos(const std::string& symbol_name, Symbol data) { return Operator("arccos") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise inverse tangent of the input array. * * The output is in the closed interval :math:`[-\pi/2, \pi/2]` * * .. math:: * arctan([-1, 0, 1]) = [-\pi/4, 0, \pi/4] * * The storage type of ``arctan`` output depends upon the input storage type: * * - arctan(default) = default * - arctan(row_sparse) = row_sparse * - arctan(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L200 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol arctan(const std::string& symbol_name, Symbol data) { return Operator("arctan") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Converts each element of the input array from radians to degrees. * * .. math:: * degrees([0, \pi/2, \pi, 3\pi/2, 2\pi]) = [0, 90, 180, 270, 360] * * The storage type of ``degrees`` output depends upon the input storage type: * * - degrees(default) = default * - degrees(row_sparse) = row_sparse * - degrees(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L219 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol degrees(const std::string& symbol_name, Symbol data) { return Operator("degrees") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Converts each element of the input array from degrees to radians. * * .. math:: * radians([0, 90, 180, 270, 360]) = [0, \pi/2, \pi, 3\pi/2, 2\pi] * * The storage type of ``radians`` output depends upon the input storage type: * * - radians(default) = default * - radians(row_sparse) = row_sparse * - radians(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L238 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol radians(const std::string& symbol_name, Symbol data) { return Operator("radians") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the hyperbolic cosine of the input array, computed element-wise. * * .. math:: * cosh(x) = 0.5\times(exp(x) + exp(-x)) * * The storage type of ``cosh`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L272 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol cosh(const std::string& symbol_name, Symbol data) { return Operator("cosh") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the hyperbolic sine of the input array, computed element-wise. * * .. math:: * sinh(x) = 0.5\times(exp(x) - exp(-x)) * * The storage type of ``sinh`` output depends upon the input storage type: * * - sinh(default) = default * - sinh(row_sparse) = row_sparse * - sinh(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L257 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol sinh(const std::string& symbol_name, Symbol data) { return Operator("sinh") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the hyperbolic tangent of the input array, computed element-wise. * * .. math:: * tanh(x) = sinh(x) / cosh(x) * * The storage type of ``tanh`` output depends upon the input storage type: * * - tanh(default) = default * - tanh(row_sparse) = row_sparse * - tanh(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L290 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol tanh(const std::string& symbol_name, Symbol data) { return Operator("tanh") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the element-wise inverse hyperbolic sine of the input array, \ * computed element-wise. * * The storage type of ``arcsinh`` output depends upon the input storage type: * * - arcsinh(default) = default * - arcsinh(row_sparse) = row_sparse * - arcsinh(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L306 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol arcsinh(const std::string& symbol_name, Symbol data) { return Operator("arcsinh") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the element-wise inverse hyperbolic cosine of the input array, \ * computed element-wise. * * The storage type of ``arccosh`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L320 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol arccosh(const std::string& symbol_name, Symbol data) { return Operator("arccosh") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the element-wise inverse hyperbolic tangent of the input array, \ * computed element-wise. * * The storage type of ``arctanh`` output depends upon the input storage type: * * - arctanh(default) = default * - arctanh(row_sparse) = row_sparse * - arctanh(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_trig.cc:L337 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol arctanh(const std::string& symbol_name, Symbol data) { return Operator("arctanh") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Return the elements, either from x or y, depending on the condition. * * Given three ndarrays, condition, x, and y, return an ndarray with the elements * depending on the elements from condition are true or false. x and y must have * If condition has the same shape as x, each element in the output array is from * corresponding element in the condition is true, and from y if false. * * If condition does not have the same shape as x, it must be a 1D array whose * the same as x's first dimension size. Each row of the output array is from x's * if the corresponding element from condition is true, and from y's row if false. * * Note that all non-zero values are interpreted as ``True`` in condition. * * Examples:: * * x = [[1, 2], [3, 4]] * y = [[5, 6], [7, 8]] * cond = [[0, 1], [-1, 0]] * * where(cond, x, y) = [[5, 2], [3, 8]] * * csr_cond = cast_storage(cond, 'csr') * * where(csr_cond, x, y) = [[5, 2], [3, 8]] * * * * Defined in src/operator/tensor/control_flow_op.cc:L57 * \param symbol_name name of the resulting symbol * \param condition condition array * \param x * \param y * \return new symbol */ inline Symbol where(const std::string& symbol_name, Symbol condition, Symbol x, Symbol y) { return Operator("where") .SetInput("condition", condition) .SetInput("x", x) .SetInput("y", y) .CreateSymbol(symbol_name); } /*! * \brief Extracts a diagonal or constructs a diagonal array. * * ``diag``'s behavior depends on the input array dimensions: * * - 1-D arrays: constructs a 2-D array with the input as its diagonal, all other * - N-D arrays: extracts the diagonals of the sub-arrays with axes specified by * The output shape would be decided by removing the axes numbered ``axis1`` and * input shape and appending to the result a new axis with the size of the * * For example, when the input shape is `(2, 3, 4, 5)`, ``axis1`` and ``axis2`` * respectively and ``k`` is 0, the resulting shape would be `(3, 5, 2)`. * * Examples:: * * x = [[1, 2, 3], * [4, 5, 6]] * * diag(x) = [1, 5] * * diag(x, k=1) = [2, 6] * * diag(x, k=-1) = [4] * * x = [1, 2, 3] * * diag(x) = [[1, 0, 0], * [0, 2, 0], * [0, 0, 3]] * * diag(x, k=1) = [[0, 1, 0], * [0, 0, 2], * [0, 0, 0]] * * diag(x, k=-1) = [[0, 0, 0], * [1, 0, 0], * [0, 2, 0]] * * x = [[[1, 2], * [3, 4]], * * [[5, 6], * [7, 8]]] * * diag(x) = [[1, 7], * [2, 8]] * * diag(x, k=1) = [[3], * [4]] * * diag(x, axis1=-2, axis2=-1) = [[1, 4], * [5, 8]] * * * * Defined in src/operator/tensor/diag_op.cc:L87 * \param symbol_name name of the resulting symbol * \param data Input ndarray * \param k Diagonal in question. The default is 0. Use k>0 for diagonals above the main * diagonal, and k<0 for diagonals below the main diagonal. If input has shape (S0 * \param axis1 The first axis of the sub-arrays of interest. Ignored when the input is a * \param axis2 The second axis of the sub-arrays of interest. Ignored when the input is * \return new symbol */ inline Symbol diag(const std::string& symbol_name, Symbol data, int k = 0, int axis1 = 0, int axis2 = 1) { return Operator("diag") .SetParam("k", k) .SetParam("axis1", axis1) .SetParam("axis2", axis2) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Adds all input arguments element-wise. * * .. math:: * add\_n(a_1, a_2, ..., a_n) = a_1 + a_2 + ... + a_n * * ``add_n`` is potentially more efficient than calling ``add`` by `n` times. * * The storage type of ``add_n`` output depends on storage types of inputs * * - add_n(row_sparse, row_sparse, ..) = row_sparse * - add_n(default, csr, default) = default * - add_n(any input combinations longer than 4 (>4) with at least one default * - otherwise, ``add_n`` falls all inputs back to default storage and generates * * * * Defined in src/operator/tensor/elemwise_sum.cc:L155 * \param symbol_name name of the resulting symbol * \param args Positional input arguments * \return new symbol */ inline Symbol add_n(const std::string& symbol_name, const std::vector<Symbol>& args) { return Operator("add_n") (args) .CreateSymbol(symbol_name); } /*! * \brief Return an array of zeros with the same shape, type and storage type * as the input array. * * The storage type of ``zeros_like`` output depends on the storage type of the * * - zeros_like(row_sparse) = row_sparse * - zeros_like(csr) = csr * - zeros_like(default) = default * * Examples:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * zeros_like(x) = [[ 0., 0., 0.], * [ 0., 0., 0.]] * * * \param symbol_name name of the resulting symbol * \param data The input * \return new symbol */ inline Symbol zeros_like(const std::string& symbol_name, Symbol data) { return Operator("zeros_like") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Return an array of ones with the same shape and type * as the input array. * * Examples:: * * x = [[ 0., 0., 0.], * [ 0., 0., 0.]] * * ones_like(x) = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * * \param symbol_name name of the resulting symbol * \param data The input * \return new symbol */ inline Symbol ones_like(const std::string& symbol_name, Symbol data) { return Operator("ones_like") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! \brief Output storage type. */ enum class Cast_storageStype { kCsr = 0, kDefault = 1, kRow_sparse = 2 }; /*! * \brief Casts tensor storage type to the new type. * * When an NDArray with default storage type is cast to csr or row_sparse storage, * the result is compact, which means: * * - for csr, zero values will not be retained * - for row_sparse, row slices of all zeros will not be retained * * The storage type of ``cast_storage`` output depends on stype parameter: * * - cast_storage(csr, 'default') = default * - cast_storage(row_sparse, 'default') = default * - cast_storage(default, 'csr') = csr * - cast_storage(default, 'row_sparse') = row_sparse * - cast_storage(csr, 'csr') = csr * - cast_storage(row_sparse, 'row_sparse') = row_sparse * * Example:: * * dense = [[ 0., 1., 0.], * [ 2., 0., 3.], * [ 0., 0., 0.], * [ 0., 0., 0.]] * * # cast to row_sparse storage type * rsp = cast_storage(dense, 'row_sparse') * rsp.indices = [0, 1] * rsp.values = [[ 0., 1., 0.], * [ 2., 0., 3.]] * * # cast to csr storage type * csr = cast_storage(dense, 'csr') * csr.indices = [1, 0, 2] * csr.values = [ 1., 2., 3.] * csr.indptr = [0, 1, 3, 3, 3] * * * * Defined in src/operator/tensor/cast_storage.cc:L71 * \param symbol_name name of the resulting symbol * \param data The input. * \param stype Output storage type. * \return new symbol */ inline Symbol cast_storage(const std::string& symbol_name, Symbol data, Cast_storageStype stype) { static const char *Cast_storageStypeValues[] = { "csr", "default", "row_sparse" }; return Operator("cast_storage") .SetParam("stype", Cast_storageStypeValues[int(stype)]) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! \brief The desired storage type of the forward output given by user, if thecombination * of input storage types and this hint does not matchany implemented ones, the * dot operator will perform fallback operationand still produce an output of the */ enum class DotForwardStype { kNone = 0, kCsr = 1, kDefault = 2, kRow_sparse = 3 }; /*! * \brief Dot product of two arrays. * * ``dot``'s behavior depends on the input array dimensions: * * - 1-D arrays: inner product of vectors * - 2-D arrays: matrix multiplication * - N-D arrays: a sum product over the last axis of the first input and the first * axis of the second input * * For example, given 3-D ``x`` with shape `(n,m,k)` and ``y`` with shape * result array will have shape `(n,m,r,s)`. It is computed by:: * * dot(x,y)[i,j,a,b] = sum(x[i,j,:]*y[:,a,b]) * * Example:: * * x = reshape([0,1,2,3,4,5,6,7], shape=(2,2,2)) * y = reshape([7,6,5,4,3,2,1,0], shape=(2,2,2)) * dot(x,y)[0,0,1,1] = 0 * sum(x[0,0,:]*y[:,1,1]) = 0 * * The storage type of ``dot`` output depends on storage types of inputs, * forward_stype option for output storage type. Implemented sparse operations * * - dot(default, default, transpose_a=True/False, transpose_b=True/False) = * - dot(csr, default, transpose_a=True) = default * - dot(csr, default, transpose_a=True) = row_sparse * - dot(csr, default) = default * - dot(csr, row_sparse) = default * - dot(default, csr) = csr (CPU only) * - dot(default, csr, forward_stype='default') = default * - dot(default, csr, transpose_b=True, forward_stype='default') = default * * If the combination of input storage types and forward_stype does not match any * above patterns, ``dot`` will fallback and generate output with default storage. * * .. Note:: * * If the storage type of the lhs is "csr", the storage type of gradient w.r.t rhs * "row_sparse". Only a subset of optimizers support sparse gradients, including * and Adam. Note that by default lazy updates is turned on, which may perform * from standard updates. For more details, please check the Optimization API at: * https://mxnet.incubator.apache.org/api/python/optimization/optimization.html * * * * Defined in src/operator/tensor/dot.cc:L77 * \param symbol_name name of the resulting symbol * \param lhs The first input * \param rhs The second input * \param transpose_a If true then transpose the first input before dot. * \param transpose_b If true then transpose the second input before dot. * \param forward_stype The desired storage type of the forward output given by user, if * thecombination of input storage types and this hint does not matchany * implemented ones, the dot operator will perform fallback operationand still * \return new symbol */ inline Symbol dot(const std::string& symbol_name, Symbol lhs, Symbol rhs, bool transpose_a = false, bool transpose_b = false, DotForwardStype forward_stype = DotForwardStype::kNone) { static const char *DotForwardStypeValues[] = { "None", "csr", "default", "row_sparse" }; return Operator("dot") .SetParam("transpose_a", transpose_a) .SetParam("transpose_b", transpose_b) .SetParam("forward_stype", DotForwardStypeValues[int(forward_stype)]) .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! \brief The desired storage type of the forward output given by user, if thecombination * of input storage types and this hint does not matchany implemented ones, the * dot operator will perform fallback operationand still produce an output of the */ enum class Batch_dotForwardStype { kNone = 0, kCsr = 1, kDefault = 2, kRow_sparse = 3 }; /*! * \brief Batchwise dot product. * * ``batch_dot`` is used to compute dot product of ``x`` and ``y`` when ``x`` and * ``y`` are data in batch, namely 3D arrays in shape of `(batch_size, :, :)`. * * For example, given ``x`` with shape `(batch_size, n, m)` and ``y`` with shape * `(batch_size, m, k)`, the result array will have shape `(batch_size, n, k)`, * which is computed by:: * * batch_dot(x,y)[i,:,:] = dot(x[i,:,:], y[i,:,:]) * * * * Defined in src/operator/tensor/dot.cc:L125 * \param symbol_name name of the resulting symbol * \param lhs The first input * \param rhs The second input * \param transpose_a If true then transpose the first input before dot. * \param transpose_b If true then transpose the second input before dot. * \param forward_stype The desired storage type of the forward output given by user, if * thecombination of input storage types and this hint does not matchany * implemented ones, the dot operator will perform fallback operationand still * \return new symbol */ inline Symbol batch_dot(const std::string& symbol_name, Symbol lhs, Symbol rhs, bool transpose_a = false, bool transpose_b = false, Batch_dotForwardStype forward_stype = Batch_dotForwardStype::kNone) { static const char *Batch_dotForwardStypeValues[] = { "None", "csr", "default", "row_sparse" }; return Operator("batch_dot") .SetParam("transpose_a", transpose_a) .SetParam("transpose_b", transpose_b) .SetParam("forward_stype", Batch_dotForwardStypeValues[int(forward_stype)]) .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! \brief Output data type. */ enum class Amp_castDtype { kFloat16 = 0, kFloat32 = 1, kFloat64 = 2, kInt32 = 3, kInt64 = 4, kInt8 = 5, kUint8 = 6 }; /*! * \brief Cast function between low precision float/FP32 used by AMP. * * It casts only between low precision float/FP32 and does not do anything for * * * Defined in src/operator/tensor/amp_cast.cc:L37 * \param symbol_name name of the resulting symbol * \param data The input. * \param dtype Output data type. * \return new symbol */ inline Symbol amp_cast(const std::string& symbol_name, Symbol data, Amp_castDtype dtype) { static const char *Amp_castDtypeValues[] = { "float16", "float32", "float64", "int32", "int64", "int8", "uint8" }; return Operator("amp_cast") .SetParam("dtype", Amp_castDtypeValues[int(dtype)]) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Cast function used by AMP, that casts its inputs to the common widest type. * * It casts only between low precision float/FP32 and does not do anything for * * * * Defined in src/operator/tensor/amp_cast.cc:L71 * \param symbol_name name of the resulting symbol * \param data Weights * \param num_outputs Number of input/output pairs to be casted to the widest type. * \return new symbol */ inline Symbol amp_multicast(const std::string& symbol_name, const std::vector<Symbol>& data, int num_outputs) { return Operator("amp_multicast") .SetParam("num_outputs", num_outputs) (data) .CreateSymbol(symbol_name); } /*! \brief The return type. * "value" means to return the top k values, "indices" means to return the indices * of the top k values, "mask" means to return a mask array containing 0 and 1. 1 * means the top k values. "both" means to return a list of both values and */ enum class TopkRetTyp { kBoth = 0, kIndices = 1, kMask = 2, kValue = 3 }; /*! \brief DType of the output indices when ret_typ is "indices" or "both". An error will */ enum class TopkDtype { kFloat16 = 0, kFloat32 = 1, kFloat64 = 2, kInt32 = 3, kUint8 = 4 }; /*! * \brief Returns the top *k* elements in an input array along the given axis. * The returned elements will be sorted. * * Examples:: * * x = [[ 0.3, 0.2, 0.4], * [ 0.1, 0.3, 0.2]] * * // returns an index of the largest element on last axis * topk(x) = [[ 2.], * [ 1.]] * * // returns the value of top-2 largest elements on last axis * topk(x, ret_typ='value', k=2) = [[ 0.4, 0.3], * [ 0.3, 0.2]] * * // returns the value of top-2 smallest elements on last axis * topk(x, ret_typ='value', k=2, is_ascend=1) = [[ 0.2 , 0.3], * [ 0.1 , 0.2]] * * // returns the value of top-2 largest elements on axis 0 * topk(x, axis=0, ret_typ='value', k=2) = [[ 0.3, 0.3, 0.4], * [ 0.1, 0.2, 0.2]] * * // flattens and then returns list of both values and indices * topk(x, ret_typ='both', k=2) = [[[ 0.4, 0.3], [ 0.3, 0.2]] , [[ 2., 0.], [ * * * * Defined in src/operator/tensor/ordering_op.cc:L64 * \param symbol_name name of the resulting symbol * \param data The input array * \param axis Axis along which to choose the top k indices. If not given, the flattened * \param k Number of top elements to select, should be always smaller than or equal to * \param ret_typ The return type. * "value" means to return the top k values, "indices" means to return the indices * of the top k values, "mask" means to return a mask array containing 0 and 1. 1 * means the top k values. "both" means to return a list of both values and * \param is_ascend Whether to choose k largest or k smallest elements. Top K largest * \param dtype DType of the output indices when ret_typ is "indices" or "both". An error * \return new symbol */ inline Symbol topk(const std::string& symbol_name, Symbol data, dmlc::optional<int> axis = dmlc::optional<int>(-1), int k = 1, TopkRetTyp ret_typ = TopkRetTyp::kIndices, bool is_ascend = false, TopkDtype dtype = TopkDtype::kFloat32) { static const char *TopkRetTypValues[] = { "both", "indices", "mask", "value" }; static const char *TopkDtypeValues[] = { "float16", "float32", "float64", "int32", "uint8" }; return Operator("topk") .SetParam("axis", axis) .SetParam("k", k) .SetParam("ret_typ", TopkRetTypValues[int(ret_typ)]) .SetParam("is_ascend", is_ascend) .SetParam("dtype", TopkDtypeValues[int(dtype)]) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns a sorted copy of an input array along the given axis. * * Examples:: * * x = [[ 1, 4], * [ 3, 1]] * * // sorts along the last axis * sort(x) = [[ 1., 4.], * [ 1., 3.]] * * // flattens and then sorts * sort(x, axis=None) = [ 1., 1., 3., 4.] * * // sorts along the first axis * sort(x, axis=0) = [[ 1., 1.], * [ 3., 4.]] * * // in a descend order * sort(x, is_ascend=0) = [[ 4., 1.], * [ 3., 1.]] * * * * Defined in src/operator/tensor/ordering_op.cc:L127 * \param symbol_name name of the resulting symbol * \param data The input array * \param axis Axis along which to choose sort the input tensor. If not given, the * \param is_ascend Whether to sort in ascending or descending order. * \return new symbol */ inline Symbol sort(const std::string& symbol_name, Symbol data, dmlc::optional<int> axis = dmlc::optional<int>(-1), bool is_ascend = true) { return Operator("sort") .SetParam("axis", axis) .SetParam("is_ascend", is_ascend) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! \brief DType of the output indices. It is only valid when ret_typ is "indices" or * "both". An error will be raised if the selected data type cannot precisely */ enum class ArgsortDtype { kFloat16 = 0, kFloat32 = 1, kFloat64 = 2, kInt32 = 3, kUint8 = 4 }; /*! * \brief Returns the indices that would sort an input array along the given axis. * * This function performs sorting along the given axis and returns an array of * as an input array that index data in sorted order. * * Examples:: * * x = [[ 0.3, 0.2, 0.4], * [ 0.1, 0.3, 0.2]] * * // sort along axis -1 * argsort(x) = [[ 1., 0., 2.], * [ 0., 2., 1.]] * * // sort along axis 0 * argsort(x, axis=0) = [[ 1., 0., 1.] * [ 0., 1., 0.]] * * // flatten and then sort * argsort(x, axis=None) = [ 3., 1., 5., 0., 4., 2.] * * * Defined in src/operator/tensor/ordering_op.cc:L177 * \param symbol_name name of the resulting symbol * \param data The input array * \param axis Axis along which to sort the input tensor. If not given, the flattened * \param is_ascend Whether to sort in ascending or descending order. * \param dtype DType of the output indices. It is only valid when ret_typ is "indices" * or "both". An error will be raised if the selected data type cannot precisely * \return new symbol */ inline Symbol argsort(const std::string& symbol_name, Symbol data, dmlc::optional<int> axis = dmlc::optional<int>(-1), bool is_ascend = true, ArgsortDtype dtype = ArgsortDtype::kFloat32) { static const char *ArgsortDtypeValues[] = { "float16", "float32", "float64", "int32", "uint8" }; return Operator("argsort") .SetParam("axis", axis) .SetParam("is_ascend", is_ascend) .SetParam("dtype", ArgsortDtypeValues[int(dtype)]) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the sum of array elements over given axes. * * .. Note:: * * `sum` and `sum_axis` are equivalent. * For ndarray of csr storage type summation along axis 0 and axis 1 is supported. * Setting keepdims or exclude to True will cause a fallback to dense operator. * * Example:: * * data = [[[1, 2], [2, 3], [1, 3]], * [[1, 4], [4, 3], [5, 2]], * [[7, 1], [7, 2], [7, 3]]] * * sum(data, axis=1) * [[ 4. 8.] * [ 10. 9.] * [ 21. 6.]] * * sum(data, axis=[1,2]) * [ 12. 19. 27.] * * data = [[1, 2, 0], * [3, 0, 1], * [4, 1, 0]] * * csr = cast_storage(data, 'csr') * * sum(csr, axis=0) * [ 8. 3. 1.] * * sum(csr, axis=1) * [ 3. 4. 5.] * * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L116 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol sum(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("sum") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the mean of array elements over given axes. * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L132 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol mean(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("mean") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the product of array elements over given axes. * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L147 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol prod(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("prod") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the sum of array elements over given axes treating Not a Numbers * * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L162 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol nansum(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("nansum") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the product of array elements over given axes treating Not a Numbers * * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L177 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol nanprod(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("nanprod") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the max of array elements over given axes. * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L191 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol max(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("max") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes the min of array elements over given axes. * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L205 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis or axes along which to perform the reduction. * * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * * If `axis` is int, a reduction is performed on a particular axis. * * If `axis` is a tuple of ints, a reduction is performed on all the axes * specified in the tuple. * * If `exclude` is true, reduction will be performed on the axes that are * NOT in axis instead. * * Negative values means indexing from right to left. * \param keepdims If this is set to `True`, the reduced axes are left in the result as * \param exclude Whether to perform reduction on axis that are NOT in axis instead. * \return new symbol */ inline Symbol min(const std::string& symbol_name, Symbol data, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), bool keepdims = false, bool exclude = false) { return Operator("min") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("exclude", exclude) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Broadcasts the input array over particular axes. * * Broadcasting is allowed on axes with size 1, such as from `(2,1,3,1)` to * `(2,8,3,9)`. Elements will be duplicated on the broadcasted axes. * * Example:: * * // given x of shape (1,2,1) * x = [[[ 1.], * [ 2.]]] * * // broadcast x on on axis 2 * broadcast_axis(x, axis=2, size=3) = [[[ 1., 1., 1.], * [ 2., 2., 2.]]] * // broadcast x on on axes 0 and 2 * broadcast_axis(x, axis=(0,2), size=(2,3)) = [[[ 1., 1., 1.], * [ 2., 2., 2.]], * [[ 1., 1., 1.], * [ 2., 2., 2.]]] * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L238 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axes to perform the broadcasting. * \param size Target sizes of the broadcasting axes. * \return new symbol */ inline Symbol broadcast_axis(const std::string& symbol_name, Symbol data, Shape axis = Shape(), Shape size = Shape()) { return Operator("broadcast_axis") .SetParam("axis", axis) .SetParam("size", size) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Broadcasts the input array to a new shape. * * Broadcasting is a mechanism that allows NDArrays to perform arithmetic * with arrays of different shapes efficiently without creating multiple copies of * Also see, `Broadcasting * <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_ for more * * Broadcasting is allowed on axes with size 1, such as from `(2,1,3,1)` to * `(2,8,3,9)`. Elements will be duplicated on the broadcasted axes. * * For example:: * * broadcast_to([[1,2,3]], shape=(2,3)) = [[ 1., 2., 3.], * [ 1., 2., 3.]]) * * The dimension which you do not want to change can also be kept as `0` which * So with `shape=(2,0)`, we will obtain the same result as in the above example. * * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L262 * \param symbol_name name of the resulting symbol * \param data The input * \param shape The shape of the desired array. We can set the dim to zero if it's same * as the original. E.g `A = broadcast_to(B, shape=(10, 0, 0))` has the same * \return new symbol */ inline Symbol broadcast_to(const std::string& symbol_name, Symbol data, Shape shape = Shape()) { return Operator("broadcast_to") .SetParam("shape", shape) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Broadcasts lhs to have the same shape as rhs. * * Broadcasting is a mechanism that allows NDArrays to perform arithmetic * with arrays of different shapes efficiently without creating multiple copies of * Also see, `Broadcasting * <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_ for more * * Broadcasting is allowed on axes with size 1, such as from `(2,1,3,1)` to * `(2,8,3,9)`. Elements will be duplicated on the broadcasted axes. * * For example:: * * broadcast_like([[1,2,3]], [[5,6,7],[7,8,9]]) = [[ 1., 2., 3.], * [ 1., 2., 3.]]) * * broadcast_like([9], [1,2,3,4,5], lhs_axes=(0,), rhs_axes=(-1,)) = [9,9,9,9,9] * * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L315 * \param symbol_name name of the resulting symbol * \param lhs First input. * \param rhs Second input. * \param lhs_axes Axes to perform broadcast on in the first input array * \param rhs_axes Axes to copy from the second input array * \return new symbol */ inline Symbol broadcast_like(const std::string& symbol_name, Symbol lhs, Symbol rhs, dmlc::optional<Shape> lhs_axes = dmlc::optional<Shape>(), dmlc::optional<Shape> rhs_axes = dmlc::optional<Shape>()) { return Operator("broadcast_like") .SetParam("lhs_axes", lhs_axes) .SetParam("rhs_axes", rhs_axes) .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! \brief The data type of the output. */ enum class NormOutDtype { kNone = 0, kFloat16 = 1, kFloat32 = 2, kFloat64 = 3, kInt32 = 4, kInt64 = 5, kInt8 = 6 }; /*! * \brief Computes the norm on an NDArray. * * This operator computes the norm on an NDArray with the specified axis, depending * on the value of the ord parameter. By default, it computes the L2 norm on the * array. Currently only ord=2 supports sparse ndarrays. * * Examples:: * * x = [[[1, 2], * [3, 4]], * [[2, 2], * [5, 6]]] * * norm(x, ord=2, axis=1) = [[3.1622777 4.472136 ] * [5.3851647 6.3245554]] * * norm(x, ord=1, axis=1) = [[4., 6.], * [7., 8.]] * * rsp = x.cast_storage('row_sparse') * * norm(rsp) = [5.47722578] * * csr = x.cast_storage('csr') * * norm(csr) = [5.47722578] * * * * Defined in src/operator/tensor/broadcast_reduce_op_value.cc:L350 * \param symbol_name name of the resulting symbol * \param data The input * \param ord Order of the norm. Currently ord=1 and ord=2 is supported. * \param axis The axis or axes along which to perform the reduction. * The default, `axis=()`, will compute over all elements into a * scalar array with shape `(1,)`. * If `axis` is int, a reduction is performed on a particular axis. * If `axis` is a 2-tuple, it specifies the axes that hold 2-D matrices, * and the matrix norms of these matrices are computed. * \param out_dtype The data type of the output. * \param keepdims If this is set to `True`, the reduced axis is left in the result as * \return new symbol */ inline Symbol norm(const std::string& symbol_name, Symbol data, int ord = 2, dmlc::optional<Shape> axis = dmlc::optional<Shape>(), NormOutDtype out_dtype = NormOutDtype::kNone, bool keepdims = false) { static const char *NormOutDtypeValues[] = { "None", "float16", "float32", "float64", "int32", "int64", "int8" }; return Operator("norm") .SetParam("ord", ord) .SetParam("axis", axis) .SetParam("out_dtype", NormOutDtypeValues[int(out_dtype)]) .SetParam("keepdims", keepdims) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise sum of the input arrays with broadcasting. * * `broadcast_plus` is an alias to the function `broadcast_add`. * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_add(x, y) = [[ 1., 1., 1.], * [ 2., 2., 2.]] * * broadcast_plus(x, y) = [[ 1., 1., 1.], * [ 2., 2., 2.]] * * Supported sparse operations: * * broadcast_add(csr, dense(1D)) = dense * broadcast_add(dense(1D), csr) = dense * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_basic.cc:L58 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_add(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_add") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise difference of the input arrays with broadcasting. * * `broadcast_minus` is an alias to the function `broadcast_sub`. * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_sub(x, y) = [[ 1., 1., 1.], * [ 0., 0., 0.]] * * broadcast_minus(x, y) = [[ 1., 1., 1.], * [ 0., 0., 0.]] * * Supported sparse operations: * * broadcast_sub/minus(csr, dense(1D)) = dense * broadcast_sub/minus(dense(1D), csr) = dense * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_basic.cc:L106 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_sub(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_sub") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise product of the input arrays with broadcasting. * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_mul(x, y) = [[ 0., 0., 0.], * [ 1., 1., 1.]] * * Supported sparse operations: * * broadcast_mul(csr, dense(1D)) = csr * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_basic.cc:L146 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_mul(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_mul") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise division of the input arrays with broadcasting. * * Example:: * * x = [[ 6., 6., 6.], * [ 6., 6., 6.]] * * y = [[ 2.], * [ 3.]] * * broadcast_div(x, y) = [[ 3., 3., 3.], * [ 2., 2., 2.]] * * Supported sparse operations: * * broadcast_div(csr, dense(1D)) = csr * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_basic.cc:L187 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_div(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_div") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise modulo of the input arrays with broadcasting. * * Example:: * * x = [[ 8., 8., 8.], * [ 8., 8., 8.]] * * y = [[ 2.], * [ 3.]] * * broadcast_mod(x, y) = [[ 0., 0., 0.], * [ 2., 2., 2.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_basic.cc:L222 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_mod(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_mod") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns result of first array elements raised to powers from second array, * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_power(x, y) = [[ 2., 2., 2.], * [ 4., 4., 4.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_extended.cc:L45 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_power(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_power") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise maximum of the input arrays with broadcasting. * * This function compares two input arrays and returns a new array having the * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_maximum(x, y) = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_extended.cc:L80 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_maximum(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_maximum") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise minimum of the input arrays with broadcasting. * * This function compares two input arrays and returns a new array having the * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_maximum(x, y) = [[ 0., 0., 0.], * [ 1., 1., 1.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_extended.cc:L115 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_minimum(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_minimum") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the hypotenuse of a right angled triangle, given its "legs" * with broadcasting. * * It is equivalent to doing :math:`sqrt(x_1^2 + x_2^2)`. * * Example:: * * x = [[ 3., 3., 3.]] * * y = [[ 4.], * [ 4.]] * * broadcast_hypot(x, y) = [[ 5., 5., 5.], * [ 5., 5., 5.]] * * z = [[ 0.], * [ 4.]] * * broadcast_hypot(x, z) = [[ 3., 3., 3.], * [ 5., 5., 5.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_extended.cc:L156 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_hypot(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_hypot") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns indices of the maximum values along an axis. * * In the case of multiple occurrences of maximum values, the indices * are returned. * * Examples:: * * x = [[ 0., 1., 2.], * [ 3., 4., 5.]] * * // argmax along axis 0 * argmax(x, axis=0) = [ 1., 1., 1.] * * // argmax along axis 1 * argmax(x, axis=1) = [ 2., 2.] * * // argmax along axis 1 keeping same dims as an input array * argmax(x, axis=1, keepdims=True) = [[ 2.], * [ 2.]] * * * * Defined in src/operator/tensor/broadcast_reduce_op_index.cc:L52 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis along which to perform the reduction. Negative values means * indexing from right to left. ``Requires axis to be set as int, because global * \param keepdims If this is set to `True`, the reduced axis is left in the result as * \return new symbol */ inline Symbol argmax(const std::string& symbol_name, Symbol data, dmlc::optional<int> axis = dmlc::optional<int>(), bool keepdims = false) { return Operator("argmax") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns indices of the minimum values along an axis. * * In the case of multiple occurrences of minimum values, the indices * are returned. * * Examples:: * * x = [[ 0., 1., 2.], * [ 3., 4., 5.]] * * // argmin along axis 0 * argmin(x, axis=0) = [ 0., 0., 0.] * * // argmin along axis 1 * argmin(x, axis=1) = [ 0., 0.] * * // argmin along axis 1 keeping same dims as an input array * argmin(x, axis=1, keepdims=True) = [[ 0.], * [ 0.]] * * * * Defined in src/operator/tensor/broadcast_reduce_op_index.cc:L77 * \param symbol_name name of the resulting symbol * \param data The input * \param axis The axis along which to perform the reduction. Negative values means * indexing from right to left. ``Requires axis to be set as int, because global * \param keepdims If this is set to `True`, the reduced axis is left in the result as * \return new symbol */ inline Symbol argmin(const std::string& symbol_name, Symbol data, dmlc::optional<int> axis = dmlc::optional<int>(), bool keepdims = false) { return Operator("argmin") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns argmax indices of each channel from the input array. * * The result will be an NDArray of shape (num_channel,). * * In case of multiple occurrences of the maximum values, the indices * are returned. * * Examples:: * * x = [[ 0., 1., 2.], * [ 3., 4., 5.]] * * argmax_channel(x) = [ 2., 2.] * * * * Defined in src/operator/tensor/broadcast_reduce_op_index.cc:L97 * \param symbol_name name of the resulting symbol * \param data The input array * \return new symbol */ inline Symbol argmax_channel(const std::string& symbol_name, Symbol data) { return Operator("argmax_channel") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! \brief Specify how out-of-bound indices behave. Default is "clip". "clip" means clip * to the range. So, if all indices mentioned are too large, they are replaced by * the index that addresses the last element along an axis. "wrap" means to wrap */ enum class PickMode { kClip = 0, kWrap = 1 }; /*! * \brief Picks elements from an input array according to the input indices along the * * Given an input array of shape ``(d0, d1)`` and indices of shape ``(i0,)``, the * an output array of shape ``(i0,)`` with:: * * output[i] = input[i, indices[i]] * * By default, if any index mentioned is too large, it is replaced by the index * the last element along an axis (the `clip` mode). * * This function supports n-dimensional input and (n-1)-dimensional indices arrays. * * Examples:: * * x = [[ 1., 2.], * [ 3., 4.], * [ 5., 6.]] * * // picks elements with specified indices along axis 0 * pick(x, y=[0,1], 0) = [ 1., 4.] * * // picks elements with specified indices along axis 1 * pick(x, y=[0,1,0], 1) = [ 1., 4., 5.] * * y = [[ 1.], * [ 0.], * [ 2.]] * * // picks elements with specified indices along axis 1 using 'wrap' mode * // to place indicies that would normally be out of bounds * pick(x, y=[2,-1,-2], 1, mode='wrap') = [ 1., 4., 5.] * * y = [[ 1.], * [ 0.], * [ 2.]] * * // picks elements with specified indices along axis 1 and dims are maintained * pick(x,y, 1, keepdims=True) = [[ 2.], * [ 3.], * [ 6.]] * * * * Defined in src/operator/tensor/broadcast_reduce_op_index.cc:L154 * \param symbol_name name of the resulting symbol * \param data The input array * \param index The index array * \param axis int or None. The axis to picking the elements. Negative values means * indexing from right to left. If is `None`, the elements in the index w.r.t the * \param keepdims If true, the axis where we pick the elements is left in the result as * \param mode Specify how out-of-bound indices behave. Default is "clip". "clip" means * clip to the range. So, if all indices mentioned are too large, they are * replaced by the index that addresses the last element along an axis. "wrap" * \return new symbol */ inline Symbol pick(const std::string& symbol_name, Symbol data, Symbol index, dmlc::optional<int> axis = dmlc::optional<int>(-1), bool keepdims = false, PickMode mode = PickMode::kClip) { static const char *PickModeValues[] = { "clip", "wrap" }; return Operator("pick") .SetParam("axis", axis) .SetParam("keepdims", keepdims) .SetParam("mode", PickModeValues[int(mode)]) .SetInput("data", data) .SetInput("index", index) .CreateSymbol(symbol_name); } /*! \brief Data type of weight. */ enum class EmbeddingDtype { kFloat16 = 0, kFloat32 = 1, kFloat64 = 2, kInt32 = 3, kInt64 = 4, kInt8 = 5, kUint8 = 6 }; /*! * \brief Maps integer indices to vector representations (embeddings). * * This operator maps words to real-valued vectors in a high-dimensional space, * called word embeddings. These embeddings can capture semantic and syntactic * For example, it has been noted that in the learned embedding spaces, similar * to be close to each other and dissimilar words far apart. * * For an input array of shape (d1, ..., dK), * the shape of an output array is (d1, ..., dK, output_dim). * All the input values should be integers in the range [0, input_dim). * * If the input_dim is ip0 and output_dim is op0, then shape of the embedding * (ip0, op0). * * By default, if any index mentioned is too large, it is replaced by the index * the last vector in an embedding matrix. * * Examples:: * * input_dim = 4 * output_dim = 5 * * // Each row in weight matrix y represents a word. So, y = (w0,w1,w2,w3) * y = [[ 0., 1., 2., 3., 4.], * [ 5., 6., 7., 8., 9.], * [ 10., 11., 12., 13., 14.], * [ 15., 16., 17., 18., 19.]] * * // Input array x represents n-grams(2-gram). So, x = [(w1,w3), (w0,w2)] * x = [[ 1., 3.], * [ 0., 2.]] * * // Mapped input x to its vector representation y. * Embedding(x, y, 4, 5) = [[[ 5., 6., 7., 8., 9.], * [ 15., 16., 17., 18., 19.]], * * [[ 0., 1., 2., 3., 4.], * [ 10., 11., 12., 13., 14.]]] * * * The storage type of weight can be either row_sparse or default. * * .. Note:: * * If "sparse_grad" is set to True, the storage type of gradient w.r.t weights * "row_sparse". Only a subset of optimizers support sparse gradients, including * and Adam. Note that by default lazy updates is turned on, which may perform * from standard updates. For more details, please check the Optimization API at: * https://mxnet.incubator.apache.org/api/python/optimization/optimization.html * * * * Defined in src/operator/tensor/indexing_op.cc:L519 * \param symbol_name name of the resulting symbol * \param data The input array to the embedding operator. * \param weight The embedding weight matrix. * \param input_dim Vocabulary size of the input indices. * \param output_dim Dimension of the embedding vectors. * \param dtype Data type of weight. * \param sparse_grad Compute row sparse gradient in the backward calculation. If set to * \return new symbol */ inline Symbol Embedding(const std::string& symbol_name, Symbol data, Symbol weight, int input_dim, int output_dim, EmbeddingDtype dtype = EmbeddingDtype::kFloat32, bool sparse_grad = false) { static const char *EmbeddingDtypeValues[] = { "float16", "float32", "float64", "int32", "int64", "int8", "uint8" }; return Operator("Embedding") .SetParam("input_dim", input_dim) .SetParam("output_dim", output_dim) .SetParam("dtype", EmbeddingDtypeValues[int(dtype)]) .SetParam("sparse_grad", sparse_grad) .SetInput("data", data) .SetInput("weight", weight) .CreateSymbol(symbol_name); } /*! \brief Specify how out-of-bound indices bahave. Default is "clip". "clip" means clip * to the range. So, if all indices mentioned are too large, they are replaced by * the index that addresses the last element along an axis. "wrap" means to wrap */ enum class TakeMode { kClip = 0, kRaise = 1, kWrap = 2 }; /*! * \brief Takes elements from an input array along the given axis. * * This function slices the input array along a particular axis with the provided * * Given data tensor of rank r >= 1, and indices tensor of rank q, gather entries * dimension of data (by default outer-most one as axis=0) indexed by indices, and * in an output tensor of rank q + (r - 1). * * Examples:: * * x = [4. 5. 6.] * * // Trivial case, take the second element along the first axis. * * take(x, [1]) = [ 5. ] * * // The other trivial case, axis=-1, take the third element along the first axis * * take(x, [3], axis=-1, mode='clip') = [ 6. ] * * x = [[ 1., 2.], * [ 3., 4.], * [ 5., 6.]] * * // In this case we will get rows 0 and 1, then 1 and 2. Along axis 0 * * take(x, [[0,1],[1,2]]) = [[[ 1., 2.], * [ 3., 4.]], * * [[ 3., 4.], * [ 5., 6.]]] * * // In this case we will get rows 0 and 1, then 1 and 2 (calculated by wrapping * // Along axis 1 * * take(x, [[0, 3], [-1, -2]], axis=1, mode='wrap') = [[[ 1. 2.] * [ 2. 1.]] * * [[ 3. 4.] * [ 4. 3.]] * * [[ 5. 6.] * [ 6. 5.]]] * * The storage type of ``take`` output depends upon the input storage type: * * - take(default, default) = default * - take(csr, default, axis=0) = csr * * * * Defined in src/operator/tensor/indexing_op.cc:L695 * \param symbol_name name of the resulting symbol * \param a The input array. * \param indices The indices of the values to be extracted. * \param axis The axis of input array to be taken.For input tensor of rank r, it could * \param mode Specify how out-of-bound indices bahave. Default is "clip". "clip" means * clip to the range. So, if all indices mentioned are too large, they are * replaced by the index that addresses the last element along an axis. "wrap" * \return new symbol */ inline Symbol take(const std::string& symbol_name, Symbol a, Symbol indices, int axis = 0, TakeMode mode = TakeMode::kClip) { static const char *TakeModeValues[] = { "clip", "raise", "wrap" }; return Operator("take") .SetParam("axis", axis) .SetParam("mode", TakeModeValues[int(mode)]) .SetInput("a", a) .SetInput("indices", indices) .CreateSymbol(symbol_name); } /*! * \brief Takes elements from a data batch. * * .. note:: * `batch_take` is deprecated. Use `pick` instead. * * Given an input array of shape ``(d0, d1)`` and indices of shape ``(i0,)``, the * an output array of shape ``(i0,)`` with:: * * output[i] = input[i, indices[i]] * * Examples:: * * x = [[ 1., 2.], * [ 3., 4.], * [ 5., 6.]] * * // takes elements with specified indices * batch_take(x, [0,1,0]) = [ 1. 4. 5.] * * * * Defined in src/operator/tensor/indexing_op.cc:L753 * \param symbol_name name of the resulting symbol * \param a The input array * \param indices The index array * \return new symbol */ inline Symbol batch_take(const std::string& symbol_name, Symbol a, Symbol indices) { return Operator("batch_take") .SetInput("a", a) .SetInput("indices", indices) .CreateSymbol(symbol_name); } /*! \brief DType of the output */ enum class One_hotDtype { kFloat16 = 0, kFloat32 = 1, kFloat64 = 2, kInt32 = 3, kInt64 = 4, kInt8 = 5, kUint8 = 6 }; /*! * \brief Returns a one-hot array. * * The locations represented by `indices` take value `on_value`, while all * other locations take value `off_value`. * * `one_hot` operation with `indices` of shape ``(i0, i1)`` and `depth` of ``d`` * in an output array of shape ``(i0, i1, d)`` with:: * * output[i,j,:] = off_value * output[i,j,indices[i,j]] = on_value * * Examples:: * * one_hot([1,0,2,0], 3) = [[ 0. 1. 0.] * [ 1. 0. 0.] * [ 0. 0. 1.] * [ 1. 0. 0.]] * * one_hot([1,0,2,0], 3, on_value=8, off_value=1, * dtype='int32') = [[1 8 1] * [8 1 1] * [1 1 8] * [8 1 1]] * * one_hot([[1,0],[1,0],[2,0]], 3) = [[[ 0. 1. 0.] * [ 1. 0. 0.]] * * [[ 0. 1. 0.] * [ 1. 0. 0.]] * * [[ 0. 0. 1.] * [ 1. 0. 0.]]] * * * Defined in src/operator/tensor/indexing_op.cc:L799 * \param symbol_name name of the resulting symbol * \param indices array of locations where to set on_value * \param depth Depth of the one hot dimension. * \param on_value The value assigned to the locations represented by indices. * \param off_value The value assigned to the locations not represented by indices. * \param dtype DType of the output * \return new symbol */ inline Symbol one_hot(const std::string& symbol_name, Symbol indices, int depth, double on_value = 1, double off_value = 0, One_hotDtype dtype = One_hotDtype::kFloat32) { static const char *One_hotDtypeValues[] = { "float16", "float32", "float64", "int32", "int64", "int8", "uint8" }; return Operator("one_hot") .SetParam("depth", depth) .SetParam("on_value", on_value) .SetParam("off_value", off_value) .SetParam("dtype", One_hotDtypeValues[int(dtype)]) .SetInput("indices", indices) .CreateSymbol(symbol_name); } /*! * \brief Gather elements or slices from `data` and store to a tensor whose * shape is defined by `indices`. * * Given `data` with shape `(X_0, X_1, ..., X_{N-1})` and indices with shape * `(M, Y_0, ..., Y_{K-1})`, the output will have shape `(Y_0, ..., Y_{K-1}, X_M, * where `M <= N`. If `M == N`, output shape will simply be `(Y_0, ..., Y_{K-1})`. * * The elements in output is defined as follows:: * * output[y_0, ..., y_{K-1}, x_M, ..., x_{N-1}] = data[indices[0, y_0, ..., * ..., * indices[M-1, y_0, ..., y_{K-1}], * x_M, ..., x_{N-1}] * * Examples:: * * data = [[0, 1], [2, 3]] * indices = [[1, 1, 0], [0, 1, 0]] * gather_nd(data, indices) = [2, 3, 0] * * data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] * indices = [[0, 1], [1, 0]] * gather_nd(data, indices) = [[3, 4], [5, 6]] * * * \param symbol_name name of the resulting symbol * \param data data * \param indices indices * \return new symbol */ inline Symbol gather_nd(const std::string& symbol_name, Symbol data, Symbol indices) { return Operator("gather_nd") .SetInput("data", data) .SetInput("indices", indices) .CreateSymbol(symbol_name); } /*! * \brief Scatters data into a new tensor according to indices. * * Given `data` with shape `(Y_0, ..., Y_{K-1}, X_M, ..., X_{N-1})` and indices * `(M, Y_0, ..., Y_{K-1})`, the output will have shape `(X_0, X_1, ..., X_{N-1})`, * where `M <= N`. If `M == N`, data shape should simply be `(Y_0, ..., Y_{K-1})`. * * The elements in output is defined as follows:: * * output[indices[0, y_0, ..., y_{K-1}], * ..., * indices[M-1, y_0, ..., y_{K-1}], * x_M, ..., x_{N-1}] = data[y_0, ..., y_{K-1}, x_M, ..., x_{N-1}] * * all other entries in output are 0. * * .. warning:: * * If the indices have duplicates, the result will be non-deterministic and * the gradient of `scatter_nd` will not be correct!! * * * Examples:: * * data = [2, 3, 0] * indices = [[1, 1, 0], [0, 1, 0]] * shape = (2, 2) * scatter_nd(data, indices, shape) = [[0, 0], [2, 3]] * * data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] * indices = [[0, 1], [1, 1]] * shape = (2, 2, 2, 2) * scatter_nd(data, indices, shape) = [[[[0, 0], * [0, 0]], * * [[1, 2], * [3, 4]]], * * [[[0, 0], * [0, 0]], * * [[5, 6], * [7, 8]]]] * * * \param symbol_name name of the resulting symbol * \param data data * \param indices indices * \param shape Shape of output. * \return new symbol */ inline Symbol scatter_nd(const std::string& symbol_name, Symbol data, Symbol indices, Shape shape) { return Operator("scatter_nd") .SetParam("shape", shape) .SetInput("data", data) .SetInput("indices", indices) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **equal to** (==) comparison operation with * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_equal(x, y) = [[ 0., 0., 0.], * [ 1., 1., 1.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L46 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_equal(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_equal") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **not equal to** (!=) comparison operation * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_not_equal(x, y) = [[ 1., 1., 1.], * [ 0., 0., 0.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L64 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_not_equal(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_not_equal") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **greater than** (>) comparison operation * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_greater(x, y) = [[ 1., 1., 1.], * [ 0., 0., 0.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L82 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_greater(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_greater") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **greater than or equal to** (>=) comparison * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_greater_equal(x, y) = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L100 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_greater_equal(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_greater_equal") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **lesser than** (<) comparison operation * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_lesser(x, y) = [[ 0., 0., 0.], * [ 0., 0., 0.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L118 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_lesser(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_lesser") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **lesser than or equal to** (<=) comparison * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_lesser_equal(x, y) = [[ 0., 0., 0.], * [ 1., 1., 1.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L136 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_lesser_equal(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_lesser_equal") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **logical and** with broadcasting. * * Example:: * * x = [[ 1., 1., 1.], * [ 1., 1., 1.]] * * y = [[ 0.], * [ 1.]] * * broadcast_logical_and(x, y) = [[ 0., 0., 0.], * [ 1., 1., 1.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L154 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_logical_and(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_logical_and") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **logical or** with broadcasting. * * Example:: * * x = [[ 1., 1., 0.], * [ 1., 1., 0.]] * * y = [[ 1.], * [ 0.]] * * broadcast_logical_or(x, y) = [[ 1., 1., 1.], * [ 1., 1., 0.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L172 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_logical_or(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_logical_or") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of element-wise **logical xor** with broadcasting. * * Example:: * * x = [[ 1., 1., 0.], * [ 1., 1., 0.]] * * y = [[ 1.], * [ 0.]] * * broadcast_logical_xor(x, y) = [[ 0., 0., 1.], * [ 1., 1., 0.]] * * * * Defined in src/operator/tensor/elemwise_binary_broadcast_op_logic.cc:L190 * \param symbol_name name of the resulting symbol * \param lhs First input to the function * \param rhs Second input to the function * \return new symbol */ inline Symbol broadcast_logical_xor(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("broadcast_logical_xor") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Computes rectified linear activation. * * .. math:: * max(features, 0) * * The storage type of ``relu`` output depends upon the input storage type: * * - relu(default) = default * - relu(row_sparse) = row_sparse * - relu(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L85 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol relu(const std::string& symbol_name, Symbol data) { return Operator("relu") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes sigmoid of x element-wise. * * .. math:: * y = 1 / (1 + exp(-x)) * * The storage type of ``sigmoid`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L119 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol sigmoid(const std::string& symbol_name, Symbol data) { return Operator("sigmoid") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes hard sigmoid of x element-wise. * * .. math:: * y = max(0, min(1, alpha * x + beta)) * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L133 * \param symbol_name name of the resulting symbol * \param data The input array. * \param alpha Slope of hard sigmoid * \param beta Bias of hard sigmoid. * \return new symbol */ inline Symbol hard_sigmoid(const std::string& symbol_name, Symbol data, mx_float alpha = 0.200000003, mx_float beta = 0.5) { return Operator("hard_sigmoid") .SetParam("alpha", alpha) .SetParam("beta", beta) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Computes softsign of x element-wise. * * .. math:: * y = x / (1 + abs(x)) * * The storage type of ``softsign`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L163 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol softsign(const std::string& symbol_name, Symbol data) { return Operator("softsign") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise gauss error function of the input. * * Example:: * * erf([0, -1., 10.]) = [0., -0.8427, 1.] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L964 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol erf(const std::string& symbol_name, Symbol data) { return Operator("erf") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise inverse gauss error function of the input. * * Example:: * * erfinv([0, 0.5., -1.]) = [0., 0.4769, -inf] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L985 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol erfinv(const std::string& symbol_name, Symbol data) { return Operator("erfinv") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Stops gradient computation. * * Stops the accumulated gradient of the inputs from flowing through this operator * in the backward direction. In other words, this operator prevents the * of its inputs to be taken into account for computing gradients. * * Example:: * * v1 = [1, 2] * v2 = [0, 1] * a = Variable('a') * b = Variable('b') * b_stop_grad = stop_gradient(3 * b) * loss = MakeLoss(b_stop_grad + a) * * executor = loss.simple_bind(ctx=cpu(), a=(1,2), b=(1,2)) * executor.forward(is_train=True, a=v1, b=v2) * executor.outputs * [ 1. 5.] * * executor.backward() * executor.grad_arrays * [ 0. 0.] * [ 1. 1.] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L299 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol BlockGrad(const std::string& symbol_name, Symbol data) { return Operator("BlockGrad") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Make your own loss function in network construction. * * This operator accepts a customized loss function symbol as a terminal loss and * the symbol should be an operator with no backward dependency. * The output of this function is the gradient of loss with respect to the input * * For example, if you are a making a cross entropy loss function. Assume ``out`` * predicted output and ``label`` is the true label, then the cross entropy can be * * cross_entropy = label * log(out) + (1 - label) * log(1 - out) * loss = make_loss(cross_entropy) * * We will need to use ``make_loss`` when we are creating our own loss function or * combine multiple loss functions. Also we may want to stop some variables' * from backpropagation. See more detail in ``BlockGrad`` or ``stop_gradient``. * * The storage type of ``make_loss`` output depends upon the input storage type: * * - make_loss(default) = default * - make_loss(row_sparse) = row_sparse * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L332 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol make_loss(const std::string& symbol_name, Symbol data) { return Operator("make_loss") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Reshape some or all dimensions of `lhs` to have the same shape as some or all * * Returns a **view** of the `lhs` array with a new shape without altering any * * Example:: * * x = [1, 2, 3, 4, 5, 6] * y = [[0, -4], [3, 2], [2, 2]] * reshape_like(x, y) = [[1, 2], [3, 4], [5, 6]] * * More precise control over how dimensions are inherited is achieved by * slices over the `lhs` and `rhs` array dimensions. Only the sliced `lhs` * are reshaped to the `rhs` sliced dimensions, with the non-sliced `lhs` * * Examples:: * * - lhs shape = (30,7), rhs shape = (15,2,4), lhs_begin=0, lhs_end=1, * - lhs shape = (3, 5), rhs shape = (1,15,4), lhs_begin=0, lhs_end=2, * * Negative indices are supported, and `None` can be used for either `lhs_end` or * * Example:: * * - lhs shape = (30, 12), rhs shape = (4, 2, 2, 3), lhs_begin=-1, lhs_end=None, * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L485 * \param symbol_name name of the resulting symbol * \param lhs First input. * \param rhs Second input. * \return new symbol */ inline Symbol reshape_like(const std::string& symbol_name, Symbol lhs, Symbol rhs) { return Operator("reshape_like") .SetInput("lhs", lhs) .SetInput("rhs", rhs) .CreateSymbol(symbol_name); } /*! * \brief Returns a 1D int64 array containing the shape of data. * * Example:: * * shape_array([[1,2,3,4], [5,6,7,8]]) = [2,4] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L544 * \param symbol_name name of the resulting symbol * \param data Input Array. * \param lhs_begin Defaults to 0. The beginning index along which the lhs dimensions are * \param lhs_end Defaults to None. The ending index along which the lhs dimensions are * \param rhs_begin Defaults to 0. The beginning index along which the rhs dimensions are * \param rhs_end Defaults to None. The ending index along which the rhs dimensions are * \return new symbol */ inline Symbol shape_array(const std::string& symbol_name, Symbol data, dmlc::optional<int> lhs_begin = dmlc::optional<int>(), dmlc::optional<int> lhs_end = dmlc::optional<int>(), dmlc::optional<int> rhs_begin = dmlc::optional<int>(), dmlc::optional<int> rhs_end = dmlc::optional<int>()) { return Operator("shape_array") .SetParam("lhs_begin", lhs_begin) .SetParam("lhs_end", lhs_end) .SetParam("rhs_begin", rhs_begin) .SetParam("rhs_end", rhs_end) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns a 1D int64 array containing the size of data. * * Example:: * * size_array([[1,2,3,4], [5,6,7,8]]) = [8] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L596 * \param symbol_name name of the resulting symbol * \param data Input Array. * \return new symbol */ inline Symbol size_array(const std::string& symbol_name, Symbol data) { return Operator("size_array") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! \brief Output data type. */ enum class CastDtype { kFloat16 = 0, kFloat32 = 1, kFloat64 = 2, kInt32 = 3, kInt64 = 4, kInt8 = 5, kUint8 = 6 }; /*! * \brief Casts all elements of the input to a new type. * * .. note:: ``Cast`` is deprecated. Use ``cast`` instead. * * Example:: * * cast([0.9, 1.3], dtype='int32') = [0, 1] * cast([1e20, 11.1], dtype='float16') = [inf, 11.09375] * cast([300, 11.1, 10.9, -1, -3], dtype='uint8') = [44, 11, 10, 255, 253] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L634 * \param symbol_name name of the resulting symbol * \param data The input. * \param dtype Output data type. * \return new symbol */ inline Symbol Cast(const std::string& symbol_name, Symbol data, CastDtype dtype) { static const char *CastDtypeValues[] = { "float16", "float32", "float64", "int32", "int64", "int8", "uint8" }; return Operator("Cast") .SetParam("dtype", CastDtypeValues[int(dtype)]) .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Numerical negative of the argument, element-wise. * * The storage type of ``negative`` output depends upon the input storage type: * * - negative(default) = default * - negative(row_sparse) = row_sparse * - negative(csr) = csr * * * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol negative(const std::string& symbol_name, Symbol data) { return Operator("negative") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the reciprocal of the argument, element-wise. * * Calculates 1/x. * * Example:: * * reciprocal([-2, 1, 3, 1.6, 0.2]) = [-0.5, 1.0, 0.33333334, 0.625, 5.0] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L686 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol reciprocal(const std::string& symbol_name, Symbol data) { return Operator("reciprocal") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise absolute value of the input. * * Example:: * * abs([-2, 0, 3]) = [2, 0, 3] * * The storage type of ``abs`` output depends upon the input storage type: * * - abs(default) = default * - abs(row_sparse) = row_sparse * - abs(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L708 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol abs(const std::string& symbol_name, Symbol data) { return Operator("abs") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise sign of the input. * * Example:: * * sign([-2, 0, 3]) = [-1, 0, 1] * * The storage type of ``sign`` output depends upon the input storage type: * * - sign(default) = default * - sign(row_sparse) = row_sparse * - sign(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L727 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol sign(const std::string& symbol_name, Symbol data) { return Operator("sign") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise rounded value to the nearest integer of the input. * * Example:: * * round([-1.5, 1.5, -1.9, 1.9, 2.1]) = [-2., 2., -2., 2., 2.] * * The storage type of ``round`` output depends upon the input storage type: * * - round(default) = default * - round(row_sparse) = row_sparse * - round(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L746 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol round(const std::string& symbol_name, Symbol data) { return Operator("round") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise ceiling of the input. * * The ceil of the scalar x is the smallest integer i, such that i >= x. * * Example:: * * ceil([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-2., -1., 2., 2., 3.] * * The storage type of ``ceil`` output depends upon the input storage type: * * - ceil(default) = default * - ceil(row_sparse) = row_sparse * - ceil(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L786 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol ceil(const std::string& symbol_name, Symbol data) { return Operator("ceil") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise floor of the input. * * The floor of the scalar x is the largest integer i, such that i <= x. * * Example:: * * floor([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-3., -2., 1., 1., 2.] * * The storage type of ``floor`` output depends upon the input storage type: * * - floor(default) = default * - floor(row_sparse) = row_sparse * - floor(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L805 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol floor(const std::string& symbol_name, Symbol data) { return Operator("floor") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Return the element-wise truncated value of the input. * * The truncated value of the scalar x is the nearest integer i which is closer to * zero than x is. In short, the fractional part of the signed number x is * * Example:: * * trunc([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-2., -1., 1., 1., 2.] * * The storage type of ``trunc`` output depends upon the input storage type: * * - trunc(default) = default * - trunc(row_sparse) = row_sparse * - trunc(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L825 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol trunc(const std::string& symbol_name, Symbol data) { return Operator("trunc") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise rounded value to the nearest integer of the input. * * .. note:: * - For input ``n.5`` ``rint`` returns ``n`` while ``round`` returns ``n+1``. * - For input ``-n.5`` both ``rint`` and ``round`` returns ``-n-1``. * * Example:: * * rint([-1.5, 1.5, -1.9, 1.9, 2.1]) = [-2., 1., -2., 2., 2.] * * The storage type of ``rint`` output depends upon the input storage type: * * - rint(default) = default * - rint(row_sparse) = row_sparse * - rint(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L767 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol rint(const std::string& symbol_name, Symbol data) { return Operator("rint") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise rounded value to the nearest \ * integer towards zero of the input. * * Example:: * * fix([-2.1, -1.9, 1.9, 2.1]) = [-2., -1., 1., 2.] * * The storage type of ``fix`` output depends upon the input storage type: * * - fix(default) = default * - fix(row_sparse) = row_sparse * - fix(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L843 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol fix(const std::string& symbol_name, Symbol data) { return Operator("fix") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise squared value of the input. * * .. math:: * square(x) = x^2 * * Example:: * * square([2, 3, 4]) = [4, 9, 16] * * The storage type of ``square`` output depends upon the input storage type: * * - square(default) = default * - square(row_sparse) = row_sparse * - square(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L883 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol square(const std::string& symbol_name, Symbol data) { return Operator("square") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise square-root value of the input. * * .. math:: * \textrm{sqrt}(x) = \sqrt{x} * * Example:: * * sqrt([4, 9, 16]) = [2, 3, 4] * * The storage type of ``sqrt`` output depends upon the input storage type: * * - sqrt(default) = default * - sqrt(row_sparse) = row_sparse * - sqrt(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L907 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol sqrt(const std::string& symbol_name, Symbol data) { return Operator("sqrt") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise inverse square-root value of the input. * * .. math:: * rsqrt(x) = 1/\sqrt{x} * * Example:: * * rsqrt([4,9,16]) = [0.5, 0.33333334, 0.25] * * The storage type of ``rsqrt`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L927 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol rsqrt(const std::string& symbol_name, Symbol data) { return Operator("rsqrt") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise cube-root value of the input. * * .. math:: * cbrt(x) = \sqrt[3]{x} * * Example:: * * cbrt([1, 8, -125]) = [1, 2, -5] * * The storage type of ``cbrt`` output depends upon the input storage type: * * - cbrt(default) = default * - cbrt(row_sparse) = row_sparse * - cbrt(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L950 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol cbrt(const std::string& symbol_name, Symbol data) { return Operator("cbrt") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise inverse cube-root value of the input. * * .. math:: * rcbrt(x) = 1/\sqrt[3]{x} * * Example:: * * rcbrt([1,8,-125]) = [1.0, 0.5, -0.2] * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1004 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol rcbrt(const std::string& symbol_name, Symbol data) { return Operator("rcbrt") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise exponential value of the input. * * .. math:: * exp(x) = e^x \approx 2.718^x * * Example:: * * exp([0, 1, 2]) = [1., 2.71828175, 7.38905621] * * The storage type of ``exp`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1044 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol exp(const std::string& symbol_name, Symbol data) { return Operator("exp") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise Natural logarithmic value of the input. * * The natural logarithm is logarithm in base *e*, so that ``log(exp(x)) = x`` * * The storage type of ``log`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1057 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol log(const std::string& symbol_name, Symbol data) { return Operator("log") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise Base-10 logarithmic value of the input. * * ``10**log10(x) = x`` * * The storage type of ``log10`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1074 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol log10(const std::string& symbol_name, Symbol data) { return Operator("log10") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise Base-2 logarithmic value of the input. * * ``2**log2(x) = x`` * * The storage type of ``log2`` output is always dense * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1086 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol log2(const std::string& symbol_name, Symbol data) { return Operator("log2") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise ``log(1 + x)`` value of the input. * * This function is more accurate than ``log(1 + x)`` for small ``x`` so that * :math:`1+x\approx 1` * * The storage type of ``log1p`` output depends upon the input storage type: * * - log1p(default) = default * - log1p(row_sparse) = row_sparse * - log1p(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1171 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol log1p(const std::string& symbol_name, Symbol data) { return Operator("log1p") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns ``exp(x) - 1`` computed element-wise on the input. * * This function provides greater precision than ``exp(x) - 1`` for small values * * The storage type of ``expm1`` output depends upon the input storage type: * * - expm1(default) = default * - expm1(row_sparse) = row_sparse * - expm1(csr) = csr * * * * Defined in src/operator/tensor/elemwise_unary_op_basic.cc:L1189 * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol expm1(const std::string& symbol_name, Symbol data) { return Operator("expm1") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the gamma function (extension of the factorial function \ * to the reals), computed element-wise on the input array. * * The storage type of ``gamma`` output is always dense * * * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol gamma(const std::string& symbol_name, Symbol data) { return Operator("gamma") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns element-wise log of the absolute value of the gamma function \ * of the input. * * The storage type of ``gammaln`` output is always dense * * * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol gammaln(const std::string& symbol_name, Symbol data) { return Operator("gammaln") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Returns the result of logical NOT (!) function * * Example: * logical_not([-2., 0., 1.]) = [0., 1., 0.] * * * \param symbol_name name of the resulting symbol * \param data The input array. * \return new symbol */ inline Symbol logical_not(const std::string& symbol_name, Symbol data) { return Operator("logical_not") .SetInput("data", data) .CreateSymbol(symbol_name); } /*! * \brief Update function for SignSGD optimizer. * * .. math:: * * g_t = \nabla J(W_{t-1})\\ * W_t = W_{t-1} - \eta_t \text{sign}(g_t) * * It updates the weights using:: * * weight = weight - learning_rate * sign(gradient) * * .. note:: * - sparse ndarray not supported for this optimizer yet. * * * Defined in src/operator/optimizer_op.cc:L61 * \param symbol_name name of the resulting symbol * \param weight Weight * \param grad Gradient * \param lr Learning rate * \param wd Weight decay augments the objective function with a regularization term that * penalizes large weights. The penalty scales with the square of the magnitude of * \param rescale_grad Rescale gradient to grad = rescale_grad*grad. * \param clip_gradient Clip gradient to the range of [-clip_gradient, clip_gradient] If * clip_gradient <= 0, gradient clipping is turned off. grad = max(min(grad, * \return new symbol */ inline Symbol signsgd_update(const std::string& symbol_name, Symbol weight, Symbol grad, mx_float lr, mx_float wd = 0, mx_float rescale_grad = 1, mx_float clip_gradient = -1) { return Operator("signsgd_update") .SetParam("lr", lr) .SetParam("wd", wd) .SetParam("rescale_grad", rescale_grad) .SetParam("clip_gradient", clip_gradient) .SetInput("weight", weight) .SetInput("grad", grad) .CreateSymbol(symbol_name); } /*! * \brief SIGN momentUM (Signum) optimizer. * * .. math:: * * g_t = \nabla J(W_{t-1})\\ * m_t = \beta m_{t-1} + (1 - \beta) g_t\\ * W_t = W_{t-1} - \eta_t \text{sign}(m_t) * * It updates the weights using:: * state = momentum * state + (1-momentum) * gradient * weight = weight - learning_rate * sign(state) * * Where the parameter ``momentum`` is the decay rate of momentum estimates at * * .. note:: * - sparse ndarray not supported for this optimizer yet. * * * Defined in src/operator/optimizer_op.cc:L90 * \param symbol_name name of the resulting symbol * \param weight Weight * \param grad Gradient * \param mom Momentum * \param lr Learning rate * \param momentum The decay rate of momentum estimates at each epoch. * \param wd Weight decay augments the objective function with a regularization term that * penalizes large weights. The penalty scales with the square of the magnitude of * \param rescale_grad Rescale gradient to grad = rescale_grad*grad. * \param clip_gradient Clip gradient to the range of [-clip_gradient, clip_gradient] If * clip_gradient <= 0, gradient clipping is turned off. grad = max(min(grad, * \param wd_lh The amount of weight decay that does not go into gradient/momentum * \return new symbol */ inline Symbol signum_update(const std::string& symbol_name, Symbol weight, Symbol grad, Symbol mom, mx_float lr, mx_float momentum = 0, mx_float wd = 0, mx_float rescale_grad = 1, mx_float clip_gradient = -1, mx_float wd_lh = 0) { return Operator("signum_update") .SetParam("lr", lr) .SetParam("momentum", momentum) .SetParam("wd", wd) .SetParam("rescale_grad", rescale_grad) .SetParam("clip_gradient", clip_gradient) .SetParam("wd_lh", wd_lh) .SetInput("weight", weight) .SetInput("grad", grad) .SetInput("mom", mom) .CreateSymbol(symbol_name); } /*! * \brief Update function for Stochastic Gradient Descent (SGD) optimizer. * * It updates the weights using:: * * weight = weight - learning_rate * (gradient + wd * weight) * * However, if gradient is of ``row_sparse`` storage type and ``lazy_update`` is * only the row slices whose indices appear in grad.indices are updated:: * * for row in gradient.indices: * weight[row] = weight[row] - learning_rate * (gradient[row] + wd * weight[row]) * * *