chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @created by George A. Shulinok <sgazeos@gmail.com> 4/18/2019
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_BARNES_HUT_TSNE_H
|
||||
#define LIBND4J_HEADERS_BARNES_HUT_TSNE_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This operation used as helper with BarnesHutTsne class
|
||||
* to compute edge forces using barnes hut
|
||||
*
|
||||
* Expected input:
|
||||
* 0: 1D row-vector (or with shape (1, m))
|
||||
* 1: 1D integer vector with slice nums
|
||||
* 2: 1D float-point values vector with same shape as above
|
||||
* 3: 2D float-point matrix with data to search
|
||||
*
|
||||
* Int args:
|
||||
* 0: N - number of slices
|
||||
*
|
||||
* Output:
|
||||
* 0: 2D matrix with the same shape and type as the 3th argument
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_barnes_edge_forces)
|
||||
DECLARE_CUSTOM_OP(barnes_edge_forces, 4, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation used as helper with BarnesHutTsne class
|
||||
* to Symmetrize the value matrix
|
||||
*
|
||||
* Expected input:
|
||||
* 0: 1D int row-vector
|
||||
* 1: 1D int col-vector
|
||||
* 2: 1D float vector with values
|
||||
*
|
||||
* Output:
|
||||
* 0: 1D int result row-vector
|
||||
* 1: 1D int result col-vector
|
||||
* 2: a float-point tensor with shape 1xN, with values from the last input vector
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_barnes_symmetrized)
|
||||
DECLARE_CUSTOM_OP(barnes_symmetrized, 3, 3, false, 0, -1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation used as helper with BranesHutTsne class
|
||||
* to compute x = x + 2 * yGrads / abs(yGrads) != yIncs / abs(yIncs)
|
||||
*
|
||||
* Expected input:
|
||||
* 0: input tensor
|
||||
* 1: input gradient
|
||||
* 2: gradient step tensor
|
||||
*
|
||||
* Output:
|
||||
* 0: result of expression above
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_barnes_gains)
|
||||
DECLARE_OP(barnes_gains, 3, 1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation used as helper with Cell class
|
||||
* to check vals in given set
|
||||
*
|
||||
* Expected input:
|
||||
* 0: 1D float row-vector (corners)
|
||||
* 1: 1D float col-vector (widths)
|
||||
* 2: 1D float vector (point)
|
||||
*
|
||||
* Output:
|
||||
* 0: bool val
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_cell_contains)
|
||||
DECLARE_CUSTOM_OP(cell_contains, 3, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif // LIBND4J_HEADERS_BARNES_HUT_TSNE_H
|
||||
@@ -0,0 +1,199 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_ACTIVATIONS_H
|
||||
#define LIBND4J_HEADERS_ACTIVATIONS_H
|
||||
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This is Sigmoid activation function implementation
|
||||
* Math is: 1 / 1 + exp(-x)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sigmoid)
|
||||
DECLARE_CONFIGURABLE_OP(sigmoid, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(sigmoid_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Softsign activation function implementation
|
||||
* Math is: x / 1 + abs(x)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_softsign)
|
||||
DECLARE_CONFIGURABLE_OP(softsign, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(softsign_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Tanh activation function implementation
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_tanh)
|
||||
DECLARE_CONFIGURABLE_OP(tanh, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(tanh_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Softplus activation function implementation
|
||||
* Math is: log(1 + exp(x))
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_softplus)
|
||||
DECLARE_CONFIGURABLE_OP(softplus, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(softplus_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is RELU activation function implementation
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_relu)
|
||||
DECLARE_CONFIGURABLE_OP(relu, 1, 1, true, 1, 0);
|
||||
DECLARE_CONFIGURABLE_OP(relu_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is SELU activation function implementation
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_selu)
|
||||
DECLARE_CONFIGURABLE_OP(selu, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(selu_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Leaky RELU activation function.
|
||||
* Math is: x < 0 ? alpha * x : x;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lrelu)
|
||||
DECLARE_CONFIGURABLE_OP(lrelu, 1, 1, true, -2, 0);
|
||||
DECLARE_CONFIGURABLE_OP(lrelu_bp, 2, 1, true, -2, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op is ELU activation function.
|
||||
* Math is: x >= 0 ? x : exp(x) - 1;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_elu)
|
||||
DECLARE_CONFIGURABLE_OP(elu, 1, 1, true, -2, 0);
|
||||
DECLARE_CONFIGURABLE_OP(elu_bp, 2, 1, true, -2, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Cube activation function.
|
||||
* Math is: x^3
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_cube)
|
||||
DECLARE_CONFIGURABLE_OP(cube, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(cube_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is RectifiedTanh activation function.
|
||||
* Math is: max(0, tanh(x))
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rectifiedtanh)
|
||||
DECLARE_CONFIGURABLE_OP(rectifiedtanh, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(rectifiedtanh_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is RationalTanh activation function.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rationaltanh)
|
||||
DECLARE_CONFIGURABLE_OP(rationaltanh, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(rationaltanh_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is HardTanh activation function.
|
||||
* Math is: x < -1.0 ? -1.0 : x > 1.0 ? 1.0 : x;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_hardtanh)
|
||||
DECLARE_CONFIGURABLE_OP(hardtanh, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(hardtanh_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is HardSigmoid activation function.
|
||||
* Math is: min(1, max(0, 0.2 * x + 0.5))
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_hardsigmoid)
|
||||
DECLARE_CONFIGURABLE_OP(hardsigmoid, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(hardsigmoid_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Indentity operation. It passes signal umodified in both directions.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_identity)
|
||||
DECLARE_OP(identity, 1, 1, true);
|
||||
DECLARE_OP(identity_bp, 2, 1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Indentity operation. It passes signal umodified in both directions.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_identity_n)
|
||||
DECLARE_CUSTOM_OP(identity_n, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is Concatenated RELU implementation.
|
||||
* What happens inside: RELU(Concat((x, -x, {-1})))
|
||||
*
|
||||
* PLEASE NOTE: Concatenation will double amount of features available in input
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_crelu)
|
||||
DECLARE_CUSTOM_OP(crelu, 1, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(crelu_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is RELU6 activation function implementation
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_relu6)
|
||||
DECLARE_CONFIGURABLE_OP(relu6, 1, 1, true, 1, 0);
|
||||
DECLARE_CONFIGURABLE_OP(relu6_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Parametric Rectified Linear Unit
|
||||
* f(x) = alpha * x for x < 0, f(x) = x for x >= 0
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_prelu)
|
||||
DECLARE_CONFIGURABLE_OP(prelu, 2, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(prelu_bp, 3, 2, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Thresholded Rectified Linear Unit
|
||||
* f(x) = x for x > theta, f(x) = 0 otherwise
|
||||
* theta must be >= 0
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_thresholdedrelu)
|
||||
DECLARE_CONFIGURABLE_OP(thresholdedrelu, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(thresholdedrelu_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,130 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_BITWISE_H
|
||||
#define LIBND4J_HEADERS_BITWISE_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This operation toggles individual bits of each element in array
|
||||
*
|
||||
* PLEASE NOTE: This operation is possible only on integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_toggle_bits)
|
||||
DECLARE_OP(toggle_bits, -1, -1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation shift individual bits of each element in array to the left: <<
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_shift_bits)
|
||||
DECLARE_BROADCASTABLE_OP(shift_bits, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation shift individual bits of each element in array to the right: >>
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rshift_bits)
|
||||
DECLARE_BROADCASTABLE_OP(rshift_bits, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation shift individual bits of each element in array, shifting to the left
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_cyclic_shift_bits)
|
||||
DECLARE_BROADCASTABLE_OP(cyclic_shift_bits, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation shift individual bits of each element in array, shifting to the right
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_cyclic_rshift_bits)
|
||||
DECLARE_BROADCASTABLE_OP(cyclic_rshift_bits, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation applies bitwise AND
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_bitwise_and)
|
||||
DECLARE_BROADCASTABLE_OP(bitwise_and, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation applies bitwise OR
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_bitwise_or)
|
||||
DECLARE_BROADCASTABLE_OP(bitwise_or, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation applies bitwise XOR
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_bitwise_xor)
|
||||
DECLARE_BROADCASTABLE_OP(bitwise_xor, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation returns hamming distance based on bits
|
||||
*
|
||||
* PLEASE NOTE: This operation is applicable only to integer data types
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_bits_hamming_distance)
|
||||
DECLARE_CUSTOM_OP(bits_hamming_distance, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,130 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
#ifndef LIBND4J_HEADERS_BLAS_H
|
||||
#define LIBND4J_HEADERS_BLAS_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
/**
|
||||
* This op is general matmum implementation. Depending on inputs dimensionality output result might be different.
|
||||
* matrix x matrix = BLAS gemm
|
||||
* vector x matrix = BLAS gemm
|
||||
* vector x vector = BLAS dot
|
||||
* vector x scalar = element-wise mul
|
||||
* scalar x vector = element-wise mul
|
||||
*
|
||||
* Optional T arguments:
|
||||
* 0: alpha (where applicable)
|
||||
* 1: beta (where applicable)
|
||||
*
|
||||
* Optional Integer arguments:
|
||||
* 0: transA (where applicable)
|
||||
* 1: transB (where applicable)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_matmul)
|
||||
DECLARE_CUSTOM_OP(matmul, 2, 1, false, 0, -2);
|
||||
DECLARE_CUSTOM_OP(matmul_bp, 3, 2, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* tensorMmul/tensorDot operation
|
||||
* takes 2 ndarrays, and 2 sets of axes
|
||||
*
|
||||
* Integer argumens map:
|
||||
* IArgs[0] - number of axes along for first array
|
||||
* IArgs[1]... axes values for first array
|
||||
* IArgs[] - number of axes along for second array
|
||||
* IArgs[1]... axes values for second array
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_tensormmul)
|
||||
DECLARE_CUSTOM_OP(tensormmul, 2, 1, false, 0, -1);
|
||||
DECLARE_CUSTOM_OP(tensormmul_bp, 4, 2, false, 0, -1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op is simple implementation of BLAS AXPY method.
|
||||
* Math is: y += a * x;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_axpy)
|
||||
DECLARE_CONFIGURABLE_OP(axpy, 2, 1, false, -2, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation implements batched matrix multiplication
|
||||
* Expected arguments:
|
||||
* alpha: vector of T
|
||||
* beta: vector of T
|
||||
* ...: A, B matrices sequentially. i.e: AAAAABBBBB
|
||||
*
|
||||
* Integer arguments:
|
||||
* transA, transB, M, N, K, ldA, ldB, ldC - usual BLAS gemm arguments
|
||||
* batchCount - number of operations in this batch
|
||||
*
|
||||
* PLEASE NOTE: M, N, K, ldA, ldB, ldC should be equal for all matrices within batch.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_batched_gemm)
|
||||
DECLARE_CUSTOM_OP(batched_gemm, -1, -1, false, 0, 2);
|
||||
DECLARE_CUSTOM_OP(batched_gemm_bp, -1, -1, false, 0, 2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* performs singular value decomposition (SVD) of one or more matrices, evaluates the SVD of each inner-most 2D matrix
|
||||
* in input array: x[..., :, :] = u[..., :, :] * s[...,:] * transpose(v[..., :, :])
|
||||
*
|
||||
* Input array:
|
||||
* x[..., Rows, Cols], the necessary condition is: rank of x >= 2
|
||||
*
|
||||
* Outputs arrays:
|
||||
* s[..., diagSize] - array with singular values which are stored in decreasing order, diagSize is smaller among Rows
|
||||
* and Cols u[..., Rows, Rows] if IArgs[1] is true, else u[..., Rows, diagSize] - array with right singular vectors
|
||||
* v[..., Cols, Cols] if IArgs[1] is true, else v[..., Cols, diagSize] - array with left singular vectors
|
||||
*
|
||||
* Integer arguments:
|
||||
* IArgs[0] - bool, whether to calculate u and v, s is calculated in any case
|
||||
* IArgs[1] - bool, whether to calculate full-sized u and v
|
||||
* IArgs[2] - the number of cols or rows which determines what algorithm to use. More precisely:
|
||||
* if diagSize < IArgs[2] then Jacobi algorithm is used, in opposite case the Divide-And-Conquer is applied
|
||||
* Recommended value is 16.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_svd)
|
||||
DECLARE_CUSTOM_OP(svd, 1, 1, false, 0, 3);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* calculates square root of matrix such that
|
||||
* x[..., M, M] = z[..., M, M] x z[..., M, M]
|
||||
*
|
||||
* Input array:
|
||||
* x[..., M, M], the necessary condition is: rank of x >= 2 and equality of last two dimensions
|
||||
*
|
||||
* Outputs arrays:
|
||||
* z - same shape as x
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sqrtm)
|
||||
DECLARE_CONFIGURABLE_OP(sqrtm, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,157 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_BOOLEAN_H
|
||||
#define LIBND4J_HEADERS_BOOLEAN_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
/**
|
||||
* This is scalar boolean op.
|
||||
* Both operands should be scalars.
|
||||
*
|
||||
* Returns true if x < y
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lt_scalar)
|
||||
DECLARE_BOOLEAN_OP(lt_scalar, 2, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is scalar boolean op.
|
||||
* Both operands should be scalars.
|
||||
*
|
||||
* Returns true if x > y
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_gt_scalar)
|
||||
DECLARE_BOOLEAN_OP(gt_scalar, 2, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is scalar boolean op.
|
||||
* Both operands should be scalars.
|
||||
*
|
||||
* Returns true if x <= y
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lte_scalar)
|
||||
DECLARE_BOOLEAN_OP(lte_scalar, 2, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is scalar boolean op.
|
||||
* Both operands should be scalars.
|
||||
*
|
||||
* Returns true if x >= y
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_gte_scalar)
|
||||
DECLARE_BOOLEAN_OP(gte_scalar, 2, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is scalar boolean op.
|
||||
* Both operands should be scalars.
|
||||
*
|
||||
* Returns true if both operands are equal.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_eq_scalar)
|
||||
DECLARE_BOOLEAN_OP(eq_scalar, 2, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is scalar boolean op.
|
||||
* Both operands should be scalars.
|
||||
*
|
||||
* Returns true if x != y
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_neq_scalar)
|
||||
DECLARE_BOOLEAN_OP(neq_scalar, 2, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 n-dimensional arrays as input, and return
|
||||
* array of the same shape, with elements, either from x or y, depending on the condition.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_Where)
|
||||
DECLARE_CUSTOM_OP(Where, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_where_np)
|
||||
DECLARE_CUSTOM_OP(where_np, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 n-dimensional arrays as input, and return
|
||||
* array of the same shape, with elements, either from x or y, depending on the condition.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_select)
|
||||
DECLARE_CUSTOM_OP(select, 3, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes either 1 argument and 1 scalar
|
||||
* or 1 argument and another comparison array
|
||||
* and runs a pre defined conditional op.
|
||||
*
|
||||
* The output of the op is dynamic in size and returns a flat vector of elements
|
||||
* that return true on the given condition.
|
||||
* In numpy parlance, most people might understand:
|
||||
* a[a > 2]
|
||||
* where a is a numpy array and the condition is true when an element is
|
||||
* > 2. Libnd4j already implements a number of pre defined conditions.
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_choose)
|
||||
DECLARE_CUSTOM_OP(choose, -1, 1, false, -2, -1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 1 n-dimensional array as input, and returns true if for every adjacent pair we have x[i] <= x[i+1].
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_is_non_decreasing)
|
||||
DECLARE_BOOLEAN_OP(is_non_decreasing, 1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 1 n-dimensional array as input, and returns true if for every adjacent pair we have x[i] < x[i+1].
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_is_strictly_increasing)
|
||||
DECLARE_BOOLEAN_OP(is_strictly_increasing, 1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 1 n-dimensional array as input, and returns true if input is a numeric array.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_is_numeric_tensor)
|
||||
DECLARE_BOOLEAN_OP(is_numeric_tensor, 1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_boolean_not)
|
||||
DECLARE_OP(boolean_not, 1, 1, true);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,388 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_BROADCASTABLE_H
|
||||
#define LIBND4J_HEADERS_BROADCASTABLE_H
|
||||
#include <ops/declarable/BroadcastableBoolOp.h>
|
||||
#include <ops/declarable/BroadcastableOp.h>
|
||||
#include <ops/declarable/generic/helpers/BroadcastHelper.h>
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
// TODO: make broadcastables separate class
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Max(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_maximum)
|
||||
DECLARE_BROADCASTABLE_OP(maximum, 0, 0);
|
||||
DECLARE_CUSTOM_OP(maximum_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Min(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_minimum)
|
||||
DECLARE_BROADCASTABLE_OP(minimum, 0, 0);
|
||||
DECLARE_CUSTOM_OP(minimum_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Add(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_add)
|
||||
DECLARE_BROADCASTABLE_OP(add, 0, 0);
|
||||
DECLARE_CUSTOM_OP(add_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Subtract(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_subtract)
|
||||
DECLARE_BROADCASTABLE_OP(subtract, 0, 0);
|
||||
DECLARE_CUSTOM_OP(subtract_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Subtract(Y, X)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_reversesubtract)
|
||||
DECLARE_BROADCASTABLE_OP(reversesubtract, 0, 0);
|
||||
DECLARE_CUSTOM_OP(reversesubtract_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = ReverseMod(X, Y) == Mod(Y, X)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_reversemod)
|
||||
DECLARE_BROADCASTABLE_OP(reversemod, 0, 0);
|
||||
DECLARE_CUSTOM_OP(reversemod_bp, 3, 2, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Subtract(X, Y) * Subtract(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_squaredsubtract)
|
||||
DECLARE_BROADCASTABLE_OP(squaredsubtract, 0, 0)
|
||||
DECLARE_CUSTOM_OP(squaredsubtract_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Multiply(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_multiply)
|
||||
DECLARE_BROADCASTABLE_OP(multiply, 0, 0);
|
||||
DECLARE_CUSTOM_OP(multiply_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Divide(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_divide)
|
||||
DECLARE_BROADCASTABLE_OP(divide, 0, 0);
|
||||
DECLARE_CUSTOM_OP(divide_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Divide(X, Y) with exception, 0 if Y = 0
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_divide_no_nan)
|
||||
DECLARE_BROADCASTABLE_OP(divide_no_nan, 0, 0);
|
||||
#endif
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Divide(Y, x)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_reversedivide)
|
||||
DECLARE_BROADCASTABLE_OP(reversedivide, 0, 0);
|
||||
DECLARE_CUSTOM_OP(reversedivide_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = FloorMod(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_floormod)
|
||||
DECLARE_BROADCASTABLE_OP(floormod, 0, 0);
|
||||
DECLARE_CUSTOM_OP(floormod_bp, 3, 2, true, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_mod)
|
||||
DECLARE_BROADCASTABLE_OP(mod, 0, 0);
|
||||
DECLARE_CUSTOM_OP(mod_bp, 3, 2, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = FloorDiv(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_floordiv)
|
||||
DECLARE_BROADCASTABLE_OP(floordiv, 0, 0)
|
||||
DECLARE_CUSTOM_OP(floordiv_bp, 2, 1, true, 0, 0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Divide(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_realdiv)
|
||||
DECLARE_BROADCASTABLE_OP(realdiv, 0, 0);
|
||||
DECLARE_CUSTOM_OP(realdiv_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_truncatediv)
|
||||
DECLARE_BROADCASTABLE_OP(truncatediv, 0, 0);
|
||||
#endif
|
||||
/**
|
||||
* This is one of auto-broadcastable operations. It accepts 2 operands, and operation is applied based on their shapes:
|
||||
* 1) if shapes are equal that's pairwise operation, result will have the same shape.
|
||||
* 2) if shape X is scalar and shape Y is array - result will have shape equal to Y.
|
||||
* 3) if shape X is array and shape Y is scalar - result will have shape equal to X.
|
||||
* 4) if shape X and Y are both arrays, but shapes aren't equal - result shape will be broadcast result.
|
||||
*
|
||||
* This operation returns Z = Assign(X, Y)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_assign)
|
||||
DECLARE_BROADCASTABLE_OP(assign, 0, 0);
|
||||
DECLARE_CUSTOM_OP(assign_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
|
||||
#if NOT_EXCLUDED(OP_meshgrid)
|
||||
DECLARE_CUSTOM_OP(meshgrid, -1, -1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 equally shaped arrays as input, and provides binary matrix as output.
|
||||
* Math is: _x == _y ? (T) 1.0f : (T) 0.0f;
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_equals)
|
||||
DECLARE_BROADCASTABLE_BOOL_OP(equals, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 equally shaped arrays as input, and provides binary matrix as output.
|
||||
* Math is: _x != _y ? (T) 1.0f : (T) 0.0f;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_not_equals)
|
||||
DECLARE_BROADCASTABLE_BOOL_OP(not_equals, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 equally shaped arrays as input, and provides binary matrix as output.
|
||||
* Math is: _x <= _y ? (T) 1.0f : (T) 0.0f;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_less_equal)
|
||||
DECLARE_BROADCASTABLE_BOOL_OP(less_equal, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 equally shaped arrays as input, and provides binary matrix as output.
|
||||
* Math is: _x >= _y ? (T) 1.0f : (T) 0.0f;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_greater_equal)
|
||||
DECLARE_BROADCASTABLE_BOOL_OP(greater_equal, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 equally shaped arrays as input, and provides binary matrix as output.
|
||||
* Math is: _x < _y ? (T) 1.0f : (T) 0.0f;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_less)
|
||||
DECLARE_BROADCASTABLE_BOOL_OP(less, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op takes 2 equally shaped arrays as input, and provides binary matrix as output.
|
||||
* Math is: _x > _y ? (T) 1.0f : (T) 0.0f;
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_greater)
|
||||
DECLARE_BROADCASTABLE_BOOL_OP(greater, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_boolean_and)
|
||||
DECLARE_BROADCASTABLE_OP(boolean_and, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_boolean_or)
|
||||
DECLARE_BROADCASTABLE_OP(boolean_or, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_boolean_xor)
|
||||
DECLARE_BROADCASTABLE_OP(boolean_xor, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation performs calculation of percentile of input array along given axises
|
||||
*
|
||||
* Input - tensor with rank N > 0
|
||||
* Output - tensor with rank (N - length(axis)) or scalar if number of Integer arguments is zero
|
||||
* Float arguments:
|
||||
* 0: percentile (scalar) in range [0,100] (inclusively)
|
||||
* 1: interpolation (optional), possible values are 0-"lower", 1-"higher", 2-"nearest"(default)
|
||||
* 2: keepDims (optional), if it is non zero, then unities are kept in reduced resulting shape of output array,
|
||||
* default is 0 Integer arguments - axis - the sequence of axises to calculate percentile along, if sequence is empty
|
||||
* then calculate percentile for whole input tensor and return result as scalar
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_percentile)
|
||||
DECLARE_CUSTOM_OP(percentile, 1, 1, false, 1, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Special atan2 op impl for TF's args order
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_tf_atan2)
|
||||
DECLARE_BROADCASTABLE_OP(tf_atan2, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Broadcastable pow implementation
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_Pow)
|
||||
DECLARE_BROADCASTABLE_OP(Pow, 0, 0);
|
||||
DECLARE_CUSTOM_OP(Pow_bp, 3, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Broadcastable igamma implementation
|
||||
*
|
||||
* igamma(a, x) = gamma(а, x) / Gamma(a) - Gamma distribution function P(a,x)
|
||||
* Gamma(a) = int from 0 to infinity { t ^ {a - 1} e^{-t}dt }
|
||||
* gamma(a, x) = int from 0 to x { t ^ {a - 1} e^{-t}dt }
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_igamma)
|
||||
DECLARE_BROADCASTABLE_OP(igamma, 0, 0);
|
||||
#endif
|
||||
/**
|
||||
* Broadcastable igammac implementation
|
||||
* igammac(a, x) = Gamma(a,x)/Gamma(а) - Gamma distribution function Q(a,x)
|
||||
* Gamma(a) = int from 0 to infinity { t ^ {a - 1} e^{-t}dt }
|
||||
* Gamma(a, x) = int from x to infinity { t ^ {a - 1} e^{-t}dt }
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_igammac)
|
||||
DECLARE_BROADCASTABLE_OP(igammac, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_OPS_DECLARABLE_COMMON_H
|
||||
#define LIBND4J_OPS_DECLARABLE_COMMON_H
|
||||
#include <array/NDArray.h>
|
||||
#include <array/ShapeList.h>
|
||||
#include <graph/Context.h>
|
||||
#include <helpers/ArrayUtils.h>
|
||||
#include <helpers/ShapeUtils.h>
|
||||
#include <ops/declarable/BooleanOp.h>
|
||||
#include <ops/declarable/DeclarableListOp.h>
|
||||
#include <ops/declarable/BroadcastableOp.h>
|
||||
#include <ops/declarable/DeclarableReductionOp.h>
|
||||
#include <ops/declarable/LogicOp.h>
|
||||
#include <ops/declarable/OpRegistrator.h>
|
||||
#include <types/float16.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef SAMEDIFF_COMPAT_H
|
||||
#define SAMEDIFF_COMPAT_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This operation splits input string into pieces separated by delimiter
|
||||
* PLEASE NOTE: This implementation is compatible with TF 1.x
|
||||
*
|
||||
* Input[0] - string to split
|
||||
* Input[1] - delimiter
|
||||
*
|
||||
* Returns:
|
||||
* Output[0] - indices tensor
|
||||
* Output[1] - values tensor
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_compat_string_split)
|
||||
DECLARE_CUSTOM_OP(compat_string_split, 2, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation converts TF sparse array representation to dense NDArray
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_compat_sparse_to_dense)
|
||||
DECLARE_CUSTOM_OP(compat_sparse_to_dense, 4, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif // SAMEDIFF_COMPAT_H
|
||||
@@ -0,0 +1,331 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_CONVOL_H
|
||||
#define LIBND4J_HEADERS_CONVOL_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
/**
|
||||
* 1D temporal convolution implementation
|
||||
* Expected input:
|
||||
* x: 3D array
|
||||
* weight: 3D Array
|
||||
* bias: optional vector
|
||||
*
|
||||
* Int args:
|
||||
* 0: kernel
|
||||
* 1: stride
|
||||
* 2: padding
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_conv1d)
|
||||
DECLARE_CUSTOM_OP(conv1d, 2, 1, false, 0, 5);
|
||||
DECLARE_CUSTOM_OP(conv1d_bp, 3, 2, false, 0, 5);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 2D convolution implementation
|
||||
* Expected input:
|
||||
* x: 4D array
|
||||
* weight: 4D Array
|
||||
* bias: optional vector, length of outputChannels
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: kernel height
|
||||
* 1: kernel width
|
||||
* 2: stride height
|
||||
* 3: stride width
|
||||
* 4: padding height
|
||||
* 5: padding width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
* 8: same mode: 1 true, 0 false
|
||||
* 9: data format: 1 NHWC, 0 NCHW
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_conv2d)
|
||||
DECLARE_CUSTOM_OP(conv2d, 2, 1, false, 0, 9);
|
||||
DECLARE_CUSTOM_OP(conv2d_bp, 3, 2, false, 0, 9);
|
||||
DECLARE_CUSTOM_OP(conv2d_input_bp, 3, 1, false, 0, 9);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Depthwise convolution2d op:
|
||||
* Expected inputs:
|
||||
* x: 4D array, NCHW format
|
||||
* weightsDepth: 4D array,
|
||||
* weightsPointwise: optional, 4D array
|
||||
* bias: optional, vector
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sconv2d)
|
||||
DECLARE_CUSTOM_OP(sconv2d, 2, 1, false, 0, 9);
|
||||
DECLARE_CUSTOM_OP(sconv2d_bp, 3, 2, false, 0, 9);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 2D deconvolution implementation
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: kernel height
|
||||
* 1: kernel width
|
||||
* 2: stride height
|
||||
* 3: stride width
|
||||
* 4: padding height
|
||||
* 5: padding width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
* 8: same mode: 0 false, 1 true
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_deconv2d)
|
||||
DECLARE_CUSTOM_OP(deconv2d, 2, 1, false, 0, 9);
|
||||
DECLARE_CUSTOM_OP(deconv2d_bp, 3, 2, false, 0, 9);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 3D deconvolution implementation
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: filter(kernel) depth
|
||||
* 1: filter(kernel) height
|
||||
* 2: filter(kernel) width
|
||||
* 3: strides depth
|
||||
* 4: strides height
|
||||
* 5: strides width
|
||||
* 6: paddings depth
|
||||
* 7: paddings height
|
||||
* 8: paddings width
|
||||
* 9: dilations depth
|
||||
* 10: dilations height
|
||||
* 11: dilations width
|
||||
* 12: same mode: 0 false, 1 true
|
||||
* 13: data format (optional): 0-NDHWC, 1-NCDHW, default is 1
|
||||
*/
|
||||
|
||||
#if NOT_EXCLUDED(OP_deconv3d)
|
||||
DECLARE_CUSTOM_OP(deconv3d, 2, 1, false, 0, 13);
|
||||
DECLARE_CUSTOM_OP(deconv3d_bp, 3, 2, false, 0, 13);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op implements max pooling for convolution networks.
|
||||
* Expected Input: 4D array, NCHW format.
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: kernel height
|
||||
* 1: kernel width
|
||||
* 2: stride height
|
||||
* 3: stride width
|
||||
* 4: padding height
|
||||
* 5: padding width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
* 8: same mode: 0 false, 1 true
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_maxpool2d)
|
||||
DECLARE_CUSTOM_OP(maxpool2d, 1, 1, false, 0, 10);
|
||||
DECLARE_CUSTOM_OP(maxpool2d_bp, 2, 1, false, 0, 10);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op implements average pooling for convolution networks.
|
||||
* Expected Input: 4D array, NCHW format.
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: kernel height
|
||||
* 1: kernel width
|
||||
* 2: stride height
|
||||
* 3: stride width
|
||||
* 4: padding height
|
||||
* 5: padding width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
* 8: same mode: 0 false, 1 true
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_avgpool2d)
|
||||
DECLARE_CUSTOM_OP(avgpool2d, 1, 1, false, 0, 10);
|
||||
DECLARE_CUSTOM_OP(avgpool2d_bp, 2, 1, false, 0, 10);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op implements pnorm pooling for convolution networks.
|
||||
* Expected Input: 4D array, NCHW format.
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: kernel height
|
||||
* 1: kernel width
|
||||
* 2: stride height
|
||||
* 3: stride width
|
||||
* 4: padding height
|
||||
* 5: padding width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
* 8: same mode: 0 false, 1 true
|
||||
* 9: p for p-norm
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_pnormpool2d)
|
||||
DECLARE_CUSTOM_OP(pnormpool2d, 1, 1, false, 0, 10);
|
||||
DECLARE_CUSTOM_OP(pnormpool2d_bp, 2, 1, false, 1, 10);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op implements im2col algorithm, widely used in convolution neural networks
|
||||
* Input: 4D input expected
|
||||
*
|
||||
* Int args:
|
||||
* 0: kernel height
|
||||
* 1: kernel width
|
||||
* 2: stride height
|
||||
* 3: stride width
|
||||
* 4: padding height
|
||||
* 5: padding width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
* 8: isSameMode
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_im2col)
|
||||
DECLARE_CUSTOM_OP(im2col, 1, 1, false, 0, 9);
|
||||
DECLARE_CUSTOM_OP(im2col_bp, 2, 1, false, 0, 9);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op implements col2im algorithm, widely used in convolution neural networks
|
||||
* Input: 6D input expected (like output of im2col op)
|
||||
*
|
||||
* Int args:
|
||||
* 0: stride height
|
||||
* 1: stride width
|
||||
* 2: padding height
|
||||
* 3: padding width
|
||||
* 4: image height
|
||||
* 5: image width
|
||||
* 6: dilation height
|
||||
* 7: dilation width
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_col2im)
|
||||
DECLARE_CUSTOM_OP(col2im, 1, 1, false, 0, 9);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Expected input: 4D array
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: scale factor for rows (height)
|
||||
* 1: scale factor for columns (width)
|
||||
* 2: data format: 0 NHWC (default), 1 NCHW
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_upsampling2d)
|
||||
DECLARE_CUSTOM_OP(upsampling2d, 1, 1, false, 0, 2);
|
||||
DECLARE_CUSTOM_OP(upsampling2d_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Expected input: 4D array
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: scale factor for depth
|
||||
* 1: scale factor for rows (height)
|
||||
* 2: scale factor for columns (width)
|
||||
* 3: data format: 0 NDHWC (default), 1 NCDHW
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_upsampling3d)
|
||||
DECLARE_CUSTOM_OP(upsampling3d, 1, 1, false, 0, 3);
|
||||
DECLARE_CUSTOM_OP(upsampling3d_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op produces binary matrix wrt to target dimension.
|
||||
* Maximum value within each TAD is replaced with 1, other values are set to true.
|
||||
*
|
||||
* Int args:
|
||||
* 0: axis
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ismax)
|
||||
DECLARE_CONFIGURABLE_OP(ismax, 1, 1, true, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Dilation2D op
|
||||
*
|
||||
* Int args:
|
||||
* 0: isSameMode
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_dilation2d)
|
||||
DECLARE_CUSTOM_OP(dilation2d, 2, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_conv3dnew)
|
||||
DECLARE_CUSTOM_OP(conv3dnew, 2, 1, false, 0, 13);
|
||||
DECLARE_CUSTOM_OP(conv3dnew_bp, 3, 2, false, 0, 13);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_avgpool3dnew)
|
||||
DECLARE_CUSTOM_OP(avgpool3dnew, 1, 1, false, 0, 10);
|
||||
DECLARE_CUSTOM_OP(avgpool3dnew_bp, 2, 1, false, 0, 10);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_maxpool3dnew)
|
||||
DECLARE_CUSTOM_OP(maxpool3dnew, 1, 1, false, 0, 10);
|
||||
DECLARE_CUSTOM_OP(maxpool3dnew_bp, 2, 1, false, 0, 10);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op same as maxpool2d with a variant to return a matrix of indexes for max values
|
||||
*
|
||||
* Input - 4D tensor
|
||||
* Output:
|
||||
* 0 - 4D tensor as input
|
||||
* 1 - 4D tensor with max value indexes
|
||||
*
|
||||
* Int params:
|
||||
* 9 int with 2x4 vectors and 1 bool value
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_max_pool_with_argmax)
|
||||
DECLARE_CUSTOM_OP(max_pool_with_argmax, 1, 2, false, 0, 9);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_depthwise_conv2d)
|
||||
DECLARE_CUSTOM_OP(depthwise_conv2d, 2, 1, false, 0, 9);
|
||||
DECLARE_CUSTOM_OP(depthwise_conv2d_bp, 3, 2, false, 0, 9);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* point-wise 2D convolution
|
||||
* Expected input:
|
||||
* x: 4D array
|
||||
* weight: 4D Array [1, 1, iC, oC] (NHWC) or [oC, iC, 1, 1] (NCHW)
|
||||
* bias: optional vector, length of oC
|
||||
*
|
||||
* IntArgs:
|
||||
* 0: data format: 1 NHWC, 0 NCHW (optional, by default = NHWC)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_pointwise_conv2d)
|
||||
DECLARE_CUSTOM_OP(pointwise_conv2d, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_deconv2d_tf)
|
||||
DECLARE_CUSTOM_OP(deconv2d_tf, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
#ifndef LIBND4J_HEADERS_DTYPE_H
|
||||
#define LIBND4J_HEADERS_DTYPE_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This operation casts elements of input array to double data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_double)
|
||||
DECLARE_CUSTOM_OP(to_double, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to float16 data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_float16)
|
||||
DECLARE_CUSTOM_OP(to_float16, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to float data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_float32)
|
||||
DECLARE_CUSTOM_OP(to_float32, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to int32 data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_int32)
|
||||
DECLARE_CUSTOM_OP(to_int32, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to int64 (aka long long) data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_int64)
|
||||
DECLARE_CUSTOM_OP(to_int64, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to unsigned int32 data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_uint32)
|
||||
DECLARE_CUSTOM_OP(to_uint32, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to unsigned int64 (aka unsigned long long) data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_to_uint64)
|
||||
DECLARE_CUSTOM_OP(to_uint64, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to specified data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*
|
||||
*
|
||||
* Int args:
|
||||
* 0: target DataType
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_cast)
|
||||
DECLARE_CUSTOM_OP(cast, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation casts elements of input array to specified data type
|
||||
*
|
||||
* PLEASE NOTE: This op is disabled atm, and reserved for future releases.
|
||||
*
|
||||
*
|
||||
* Int args:
|
||||
* 0: target DataType
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_min_max_datatype)
|
||||
DECLARE_CUSTOM_OP(min_max_datatype, -2, 1, false, 0, 2);
|
||||
#endif
|
||||
/**
|
||||
* This operation change type of input and modified shape of output to conform with given data type
|
||||
*
|
||||
* all as above op
|
||||
* */
|
||||
#if NOT_EXCLUDED(OP_bitcast)
|
||||
DECLARE_CUSTOM_OP(bitcast, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author AbdelRauf
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_DECODER_H
|
||||
#define LIBND4J_HEADERS_DECODER_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
/**
|
||||
* Implementation of CTC beam search
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: logits - logits NDArray logit NDArray {BATCH_LEN, MAX_FRAME_LEN, CLASS_LEN }. It should include a blank label
|
||||
* as well. type float 1: sequence_length - NDArray {BATCH_LEN} length of frames. type integer
|
||||
*
|
||||
* Input integer arguments (IArgs):
|
||||
* 0: blank_index the index of the blank label in logits. default is last class. CLASS_LEN-1
|
||||
* 1: beam_width the width of the beam search. default is 25
|
||||
* 2: nbest_len the number of top best results that should be returned. default is 1
|
||||
* NOTE: if it is > beam_width it will be defaulted to beam_width size.
|
||||
* Input bool argument (BArgs):
|
||||
* 0: normalize_logit when its true it will normalize logits. by default it is assumed logit contains already
|
||||
* normalized log-probabilities Output array: 0: result_sequences NDArray {BATCH_LEN, NBEST, MAX_FRAME_LEN} result
|
||||
* sequences. NOTE: result_sequences NdArray should be c order and have ews == 1. type integer 1: result_probs NDArray
|
||||
* {BATCH_LEN, NBEST} negative log probabilities for each sequence. type float NOTE: result_probs NdArray should be c
|
||||
* order and have ews == 1 2: result_sequence_length NDArray {BATCH_LEN, NBEST} the length of the each sequence. type
|
||||
* integer NOTE: result_sequence_length NdArray should be c order and have ews == 1
|
||||
*
|
||||
* NOTE:
|
||||
* maximum value of integer indexing type should be >= CLASS_LEN to make sense. And also it should consider frame
|
||||
* lengthes as well. For now this case is mostly fine as only Indexing types are allowed as integer.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ctc_beam)
|
||||
DECLARE_CUSTOM_OP(ctc_beam, 2, 3, false, 0, -2);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,276 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author Oleh Semeniv (oleg.semeniv@gmail.com)
|
||||
//
|
||||
//
|
||||
// @author AbdelRauf (rauf@konduit.ai)
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_IMAGES_H
|
||||
#define LIBND4J_HEADERS_IMAGES_H
|
||||
#include <execution/Threads.h>
|
||||
#include <helpers/ConstantTadHelper.h>
|
||||
#include <ops/declarable/CustomOperations.h>
|
||||
#include <ops/declarable/headers/common.h>
|
||||
#include <ops/declarable/helpers/imagesHelpers.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
/**
|
||||
* Rgb To Hsv
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, must have at least one dimension equal 3, that is dimension containing channels.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with 3 channels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rgb_to_hsv)
|
||||
DECLARE_CONFIGURABLE_OP(rgb_to_hsv, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Hsv To Rgb
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, must have at least one dimension equal 3, that is dimension containing channels.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with 3 channels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_hsv_to_rgb)
|
||||
DECLARE_CONFIGURABLE_OP(hsv_to_rgb, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Rgb To GrayScale
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, the RGB tensor to convert. Last dimension must have size 3 and should contain RGB
|
||||
* values.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rgb_to_grs)
|
||||
DECLARE_CUSTOM_OP(rgb_to_grs, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Rgb To Yuv
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, must have at least one dimension equal 3, that is dimension containing channels.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with 3 channels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rgb_to_yuv)
|
||||
DECLARE_CONFIGURABLE_OP(rgb_to_yuv, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Yuv To Rgb
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, must have at least one dimension equal 3, that is dimension containing channels.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with 3 channels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rgb_to_yuv)
|
||||
DECLARE_CONFIGURABLE_OP(yuv_to_rgb, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Rgb To Yiq
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, must have at least one dimension equal 3, that is dimension containing channels.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with 3 channels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rgb_to_yiq)
|
||||
DECLARE_CONFIGURABLE_OP(rgb_to_yiq, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Yiq To Rgb
|
||||
* Input arrays:
|
||||
* 0 - input array with rank >= 1, must have at least one dimension equal 3, that is dimension containing channels.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with 3 channels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_yiq_to_rgb)
|
||||
DECLARE_CONFIGURABLE_OP(yiq_to_rgb, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* resize_images - resize image with given size and method
|
||||
* there are 4 methods allowed: RESIZE_BILINEAR(0), RESIZE_NEIGHBOR(1), RESIZE_AREA(2) and RESIZE_BICUBIC(3)
|
||||
* inputs:
|
||||
* 0 - 4D tensor with shape {batch, height, width, channels}
|
||||
* 1 - 1D integer tensor with {new_height, new_width} (optional)
|
||||
* 2 - 0D integer tensor with method (0 to 3) (optional)
|
||||
*
|
||||
* int args:
|
||||
* 0 - new_height
|
||||
* 1 - new_width
|
||||
* 2 - method
|
||||
*
|
||||
* bool args:
|
||||
* 0 - align corners (default false) - optional
|
||||
* 1 - preserve_aspect_ratio (default false) - optional
|
||||
*
|
||||
* CAUTION: one of methods can be used to give size and method - as tensors or as int args only
|
||||
*
|
||||
* output:
|
||||
* 0 - 4D float32 tensor with shape {batch, new_height, new_width, channels}
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_resize_images)
|
||||
DECLARE_CUSTOM_OP(resize_images, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op make bilinear or nearest neighbor interpolated resize for given tensor
|
||||
*
|
||||
* input array:
|
||||
* 0 - 4D-Tensor with shape (batch, sizeX, sizeY, channels) numeric type
|
||||
* 1 - 2D-Tensor with shape (num_boxes, 4) float type
|
||||
* 2 - 1D-Tensor with shape (num_boxes) int type
|
||||
* 3 - 1D-Tensor with 2 values (newWidth, newHeight) (optional) int type
|
||||
*
|
||||
* float arguments (optional)
|
||||
* 0 - exprapolation_value (optional) default 0.f
|
||||
*
|
||||
* int arguments: (optional)
|
||||
* 0 - mode (default 0 - bilinear interpolation)
|
||||
*
|
||||
* output array:
|
||||
* the 4D-Tensor with resized to crop_size images given - float type
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_crop_and_resize)
|
||||
DECLARE_CUSTOM_OP(crop_and_resize, 4, 1, false, -1, -1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op make bilinear interpolated resize for given tensor
|
||||
*
|
||||
* input array:
|
||||
* 0 - 4D-Tensor with shape (batch, sizeX, sizeY, channels)
|
||||
* 1 - 1D-Tensor with 2 values (newWidth, newHeight) (optional)
|
||||
*
|
||||
* int arguments: (optional)
|
||||
* 0 - new width
|
||||
* 1 - new height
|
||||
*
|
||||
* output array:
|
||||
* the 4D-Tensor with calculated backproped dots
|
||||
*
|
||||
* CAUTION: either size tensor or a pair of int params should be provided.
|
||||
*/
|
||||
|
||||
#if NOT_EXCLUDED(OP_resize_bilinear)
|
||||
DECLARE_CUSTOM_OP(resize_bilinear, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op make nearest neighbor interpolated resize for given tensor
|
||||
*
|
||||
* input array:
|
||||
* 0 - 4D-Tensor with shape (batch, sizeX, sizeY, channels)
|
||||
* 1 - 1D-Tensor with 2 values (newWidth, newHeight) (optional)
|
||||
*
|
||||
* int arguments: (optional)
|
||||
* 0 - new width
|
||||
* 1 - new height
|
||||
*
|
||||
* output array:
|
||||
* the 4D-Tensor with resized image (shape is {batch, newWidth, newHeight, channels})
|
||||
*
|
||||
* CAUTION: either size tensor or a pair of int params should be provided.
|
||||
*/
|
||||
|
||||
#if NOT_EXCLUDED(OP_resize_nearest_neighbor)
|
||||
DECLARE_CUSTOM_OP(resize_nearest_neighbor, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op make bicubic interpolated resize for given tensor
|
||||
*
|
||||
* input array:
|
||||
* 0 - 4D-Tensor with shape (batch, sizeX, sizeY, channels)
|
||||
* 1 - 1D-Tensor with 2 values (newWidth, newHeight)
|
||||
*
|
||||
* output array:
|
||||
* the 4D-Tensor with resized image (shape is {batch, newWidth, newHeight, channels})
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_resize_bicubic)
|
||||
DECLARE_CUSTOM_OP(resize_bicubic, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op make area interpolated resize (as OpenCV INTER_AREA algorithm) for given tensor
|
||||
*
|
||||
* input array:
|
||||
* 0 - images - 4D-Tensor with shape (batch, sizeX, sizeY, channels)
|
||||
* 1 - size - 1D-Tensor with 2 values (newWidth, newHeight) (if missing a pair of integer args should be provided).
|
||||
*
|
||||
* int args: - proveded only when size tensor is missing
|
||||
* 0 - new height
|
||||
* 1 - new width
|
||||
* boolean args:
|
||||
* 0 - align_corners - optional (default is false)
|
||||
*
|
||||
* output array:
|
||||
* the 4D-Tensor with resized image (shape is {batch, newWidth, newHeight, channels})
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_resize_area)
|
||||
DECLARE_CUSTOM_OP(resize_area, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op make interpolated resize for given tensor with given algorithm.
|
||||
* Supported algorithms are bilinear, bicubic, nearest_neighbor, lanczos5, gaussian, area and mitchellcubic.
|
||||
*
|
||||
* input array:
|
||||
* 0 - 4D-Tensor with shape (batch, sizeX, sizeY, channels)
|
||||
* 1 - 1D-Tensor with 2 values (newWidth, newHeight)
|
||||
*
|
||||
* optional float args:
|
||||
* 0 -bicubicCoefficient - only effective for the bicubic method
|
||||
*
|
||||
* optional int args:
|
||||
* 0 - algorithm - bilinear by default
|
||||
* 1 - coordinateTransformationMode - Transformation function of the coordinate in the resized NdArray
|
||||
* to the coordinate in the original NdArray
|
||||
* 2 - nearestMode - Effective only for the ResizeNearest interpolation.
|
||||
* Indicates how to get "nearest" pixel in NDArray from original coordinate
|
||||
*
|
||||
* optional bool args:
|
||||
* 0 - preserve_aspect_ratio - default False
|
||||
* 1 - antialias - default False
|
||||
* 2 - exclude_outside - only effective for the bicubic method when antialias is False
|
||||
* If set to true, the weight of sampling locations outside the NdArray will be set to 0
|
||||
* and the weight will be renormalized so that their sum is 1.0
|
||||
*
|
||||
* output array:
|
||||
* the 4D-Tensor with resized by given algorithm image (shape is {batch, newWidth, newHeight, channels})
|
||||
*
|
||||
*/
|
||||
|
||||
#if NOT_EXCLUDED(OP_image_resize)
|
||||
DECLARE_CUSTOM_OP(image_resize, 2, 1, false, -2, -2);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_KERNELS_H
|
||||
#define LIBND4J_KERNELS_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
#if NOT_EXCLUDED(OP_knn_mindistance)
|
||||
DECLARE_CUSTOM_OP(knn_mindistance, 3, 1, false, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif // LIBND4J_KERNELS_H
|
||||
@@ -0,0 +1,140 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_LIST_H
|
||||
#define LIBND4J_HEADERS_LIST_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
// list operations, basically all around NDArrayList
|
||||
|
||||
/**
|
||||
* This operations puts given NDArray into (optionally) given NDArrayList.
|
||||
* If no NDArrayList was provided - new one will be created
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_write_list)
|
||||
DECLARE_LIST_OP(write_list, 2, 1, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation concatenates given NDArrayList, and returns NDArray as result
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_stack_list)
|
||||
DECLARE_LIST_OP(stack_list, 1, 1, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operations selects specified index fron NDArrayList and returns it as NDArray
|
||||
* Expected arguments:
|
||||
* x: non-empty list
|
||||
* indices: optional, scalar with index
|
||||
*
|
||||
* Int args:
|
||||
* optional, index
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_read_list)
|
||||
DECLARE_LIST_OP(read_list, 1, 1, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operations selects specified indices fron NDArrayList and returns them as NDArray
|
||||
* Expected arguments:
|
||||
* x: non-empty list
|
||||
* indices: optional, vector with indices
|
||||
*
|
||||
* Int args:
|
||||
* optional, indices
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_pick_list)
|
||||
DECLARE_LIST_OP(pick_list, 1, 1, -2, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operations returns scalar, with number of existing arrays within given NDArrayList
|
||||
* Expected arguments:
|
||||
* x: list
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_size_list)
|
||||
DECLARE_LIST_OP(size_list, 1, 1, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation creates new empty NDArrayList
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_create_list)
|
||||
DECLARE_LIST_OP(create_list, -2, 2, 0, -2);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* This operation creates new empty NDArrayList
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_delete_list)
|
||||
DECLARE_LIST_OP(delete_list,-2, 1, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation unpacks given NDArray into specified NDArrayList wrt specified indices
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_scatter_list)
|
||||
DECLARE_LIST_OP(scatter_list, 1, 1, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation splits given NDArray into chunks, and stores them into given NDArrayList wert sizes
|
||||
* Expected arguments:
|
||||
* list: optional, NDArrayList. if not available - new NDArrayList will be created
|
||||
* array: array to be split
|
||||
* sizes: vector with sizes for each chunk
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_split_list)
|
||||
DECLARE_LIST_OP(split_list, 2, 1, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation builds NDArray from NDArrayList using indices
|
||||
* Expected arguments:
|
||||
* x: non-empty list
|
||||
* indices: vector with indices for gather operation
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_gather_list)
|
||||
DECLARE_LIST_OP(gather_list, 2, 1, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation clones given NDArrayList
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_clone_list)
|
||||
DECLARE_LIST_OP(clone_list, 1, 1, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation unstacks given NDArray into NDArrayList by the first dimension
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_unstack_list)
|
||||
DECLARE_LIST_OP(unstack_list, 1, 1, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,402 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_LOSS_H
|
||||
#define LIBND4J_HEADERS_LOSS_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of hinge loss function max(0, 1 - labels*logits)
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: logits - logits, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, expected to be 0. or 1., type float.
|
||||
* Must have the same shape as logits.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as logits.
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as logits or just single scalar, depending on reduction mode (see input
|
||||
* integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_hinge_loss)
|
||||
DECLARE_CUSTOM_OP(hinge_loss, 3, 1, false, 0, 1);
|
||||
DECLARE_CUSTOM_OP(hinge_loss_grad, 3, 3, false, 0, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of Huber loss function:
|
||||
* 0.5 * (labels-predictions)^2 if |labels-predictions| <= delta
|
||||
* 0.5 * delta^2 + delta * (|labels-predictions| - delta) if |labels-predictions| > delta
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: predictions - the predicted values, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels, and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, type float.
|
||||
* Must have the same shape as predictions.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as predictions
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: point where the huber loss function changes from a quadratic to linear.
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as predictions or just single scalar, depending on reduction mode (see
|
||||
* input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_huber_loss)
|
||||
DECLARE_CUSTOM_OP(huber_loss, 3, 1, false, 1, 1);
|
||||
DECLARE_CUSTOM_OP(huber_loss_grad, 3, 1, false, 1, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of logarithmic loss function ( y_i * log(p_i) + (1 - y_i) * log(1 - p_i) )
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: predictions - the predicted values, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels, and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, type float.
|
||||
* Must have the same shape as predictions.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as predictions
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: a small increment to add to avoid taking a log of zero.
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as predictions or just single scalar, depending on reduction mode (see
|
||||
* input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_log_loss)
|
||||
DECLARE_CUSTOM_OP(log_loss, 3, 1, false, 1, 1);
|
||||
DECLARE_CUSTOM_OP(log_loss_grad, 3, 3, false, 1, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* l2_loss op.
|
||||
* compute a l2 norm for given array.
|
||||
*
|
||||
* input param - an array (tensor)
|
||||
* output value - a real number with given type (e.g. float or double)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_l2_loss)
|
||||
DECLARE_CUSTOM_OP(l2_loss, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op calculates logarithmic loss of poisson distributed input.
|
||||
* Input arrays:
|
||||
* 0: log_predictions - must be already pre-transformed to log(x)
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, expected to be 0. or 1., type float.
|
||||
* Must have the same shape as logits.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as logits.
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights 1: optional - boolean value
|
||||
* compute_full_loss: 0 (default) or 1 (compute)
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as log_predictions or just single scalar, depending on reduction mode (see
|
||||
* input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_log_poisson_loss)
|
||||
DECLARE_CUSTOM_OP(log_poisson_loss, 3, 1, true, 0, 1);
|
||||
DECLARE_CUSTOM_OP(log_poisson_loss_grad, 3, 3, true, 0, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of pairwise-errors-squared loss function
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: predictions - the predicted values, type float.
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, type float.
|
||||
* Must have the same shape as predictions.
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss value, it is just single scalar, type float.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_mean_pairwssqerr_loss)
|
||||
DECLARE_CUSTOM_OP(mean_pairwssqerr_loss, 3, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(mean_pairwssqerr_loss_grad, 3, 3, false, 0, 0);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of Sum-of-Squares loss function 1/N * sum_{i}^{N}(predictions_i - labels_i)^2
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: predictions - the predicted values, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, type float.
|
||||
* Must have the same shape as predictions.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as predictions
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as predictions or just single scalar, depending on reduction mode (see
|
||||
* input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_mean_sqerr_loss)
|
||||
DECLARE_CUSTOM_OP(mean_sqerr_loss, 3, 1, false, 0, 1);
|
||||
DECLARE_CUSTOM_OP(mean_sqerr_loss_grad, 3, 3, false, 0, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of sigmoid cross-entropy loss function max(logits, 0.) - logits * labels + log(1. +
|
||||
* exp(-abs(logits)));
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: logits - logits, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels, and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, expected to be 0. or 1., type float.
|
||||
* Must have the same shape as logits.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as logits.
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: smoothing value, if it is greater than 0 then apply smoothing to the labels (smooth the labels towards 1/2):
|
||||
* new_labels = labels * (1 - labelsSmoothing)+ 0.5 * labelsSmoothing
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as logits or just single scalar, depending on reduction mode (see input
|
||||
* integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sigm_cross_entropy_loss)
|
||||
DECLARE_CUSTOM_OP(sigm_cross_entropy_loss, 3, 1, false, 1, 1);
|
||||
DECLARE_CUSTOM_OP(sigm_cross_entropy_loss_grad, 3, 3, false, 1, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of softmax cross-entropy loss function max(logits, 0.) - logits * labels + log(1. +
|
||||
* exp(-abs(logits)));
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: logits - logits, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels, and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, expected to be 0. or 1., type float.
|
||||
* Must have the same shape as logits.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as logits.
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: smoothing value, if it is greater than 0 then apply smoothing to the labels (smooth the labels towards
|
||||
* 1/numClasses): new_labels = labels * (1 - labelsSmoothing) + labelsSmoothing / numClasses
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with shape as in logits except last dimension is equal to unity or just single scalar,
|
||||
* depending on reduction mode (see input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_softmax_cross_entropy_loss)
|
||||
DECLARE_CUSTOM_OP(softmax_cross_entropy_loss, 3, 1, false, 1, 1);
|
||||
DECLARE_CUSTOM_OP(softmax_cross_entropy_loss_grad, 3, 3, false, 1, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of Absolute Difference loss function |predictions - labels|
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: predictions - the predicted values, type float.
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, type float.
|
||||
* Must have the same shape as predictions.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as predictions
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as predictions or just single scalar, depending on reduction mode (see
|
||||
* input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_absolute_difference_loss)
|
||||
DECLARE_CUSTOM_OP(absolute_difference_loss, 3, 1, false, 0, 1);
|
||||
DECLARE_CUSTOM_OP(absolute_difference_loss_grad, 3, 3, false, 0, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of cosine-distance loss function 1. - (predictions * labels).reduce_sum_along(dimension)
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: predictions - the predicted values, type float
|
||||
* 1: weights - is used for weighting (multiplying) of loss values, type float.
|
||||
* Can be single scalar or has the same rank as labels and must be broadcastable to labels.
|
||||
* 2: labels - ground truth vales, type float.
|
||||
* Must have the same shape as predictions.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: type of reduction to apply to loss
|
||||
* 0 - "none", unreduced weighted losses with the same shape as predictions
|
||||
* 1 - "weighted_sum", output is scalar and equal to sum of all elements of weightedLosses array
|
||||
* 2 - "weighted_mean", output is scalar and equal to sum of all elements of weightedLosses array divided by sum
|
||||
* of all elements of weightsBroad array 3 - "weighted_sum_by_nonzero_weights", output is scalar and equal to scalar sum
|
||||
* of all elements of weightedLosses array divided by number of non-zero weights 1: dimension along which the cosine
|
||||
* distance is computed.
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float.
|
||||
* Can be an array with the same shape as predictions or just single scalar, depending on reduction mode (see
|
||||
* input integer argument)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_cosine_distance_loss)
|
||||
DECLARE_CUSTOM_OP(cosine_distance_loss, 3, 1, false, 0, 2);
|
||||
DECLARE_CUSTOM_OP(cosine_distance_loss_grad, 3, 3, false, 0, 2);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of softmax cross-entropy loss function
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: logits - logits, type float
|
||||
* 1: labels - ground truth vales, expected to be 0. or 1., type float.
|
||||
* Must have the same shape as logits.
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: optional (default is last dimension) dimension with classes
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float. An array with shape resulting from reducing of logits shape along dimension with
|
||||
* classes
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_softmax_cross_entropy_loss_with_logits)
|
||||
DECLARE_CUSTOM_OP(softmax_cross_entropy_loss_with_logits, 2, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(softmax_cross_entropy_loss_with_logits_grad, 2, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of sparse softmax cross-entropy loss function
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: labels - ground truth vales, expected to be within range [0, num_classes), type float.
|
||||
* Must have rank equal logits rank minus 1.
|
||||
* 1: logits - logits, type float
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float. Has the same shape as labels
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sparse_softmax_cross_entropy_loss_with_logits)
|
||||
DECLARE_CUSTOM_OP(sparse_softmax_cross_entropy_loss_with_logits, 2, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(sparse_softmax_cross_entropy_loss_with_logits_grad, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Implementation of CTC loss function
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: labels - labels NDArray {BATCH_LEN, MAX_TARGET_LEN}, type integer
|
||||
* 1: logits - logits NDArray {BATCH_LEN, FRAME_LEN, CLASS_LEN }. It should include a blank label as well, type float
|
||||
* NOTE: we expect normalized logits (softmax normalized logarithm values for logits).
|
||||
* 2: targetLabelLengths - Length of label sequence in labels NDArray {BATCH_LEN}, type integer
|
||||
* 3: logitsLengths - Length of input sequence in logits NDArray {BATCH_LEN}, type integer
|
||||
*
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: blank index - index of the blank label in logits
|
||||
*
|
||||
* Output array:
|
||||
* 0: loss values, type float. NDArray {BATCH_LEN} negative log probabilities of loss
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ctc_loss)
|
||||
DECLARE_CUSTOM_OP(ctc_loss, 4, 1, false, 0, 1);
|
||||
DECLARE_CUSTOM_OP(ctc_loss_grad, 4, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef DEV_TESTS_NLP_H
|
||||
#define DEV_TESTS_NLP_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
#if NOT_EXCLUDED(OP_skipgram)
|
||||
DECLARE_CONFIGURABLE_OP(skipgram, 12, 12, true, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_skipgram_inference)
|
||||
DECLARE_CONFIGURABLE_OP(skipgram_inference, 6, 6, true, -2, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_cbow)
|
||||
DECLARE_CONFIGURABLE_OP(cbow, 15, 15, true, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_cbow_inference)
|
||||
DECLARE_CONFIGURABLE_OP(cbow_inference,6, 6, true, -2, -2);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif // DEV_TESTS_NLP_H
|
||||
@@ -0,0 +1,293 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_NN_H
|
||||
#define LIBND4J_HEADERS_NN_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
#if NOT_EXCLUDED(OP_softmax)
|
||||
DECLARE_CONFIGURABLE_OP(softmax, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(softmax_bp, 3, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Local response normalization implementation as TF.
|
||||
* input: 4D array
|
||||
*
|
||||
* T args:
|
||||
*
|
||||
* 0: bias
|
||||
* 1: alpha
|
||||
* 2: beta
|
||||
*
|
||||
* Int arg: depth - optional local radius
|
||||
*
|
||||
* output - 4D array
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lrn)
|
||||
DECLARE_CONFIGURABLE_OP(lrn, 1, 1, true, 3, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Local response normalization - backprop variant.
|
||||
* input:
|
||||
* 0 - 4D array of data
|
||||
* 1 - epsilon - 4D array of approximation
|
||||
*
|
||||
* T args:
|
||||
*
|
||||
* 0: bias
|
||||
* 1: alpha
|
||||
* 2: beta
|
||||
*
|
||||
* Int arg: depth - optional local radius
|
||||
*
|
||||
* output - next approximation as 4D array
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lrn)
|
||||
DECLARE_CONFIGURABLE_OP(lrn_bp, 2, 1, true, 3, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Batch normalization implementation.
|
||||
* Reference: https://arxiv.org/abs/1502.03167v3
|
||||
*
|
||||
* Expected arguments:
|
||||
* input: input array (any number of dimensions)
|
||||
* mean:
|
||||
* variance:
|
||||
* gamma:
|
||||
* beta:
|
||||
*
|
||||
* Int args:
|
||||
* 0: apply scale
|
||||
* 1: apply offset
|
||||
*
|
||||
*
|
||||
* T args:
|
||||
* 0: epsilon
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_batchnorm)
|
||||
DECLARE_CUSTOM_OP(batchnorm, 3, 1, false, 1, 2);
|
||||
/**
|
||||
* back prop in batch normalization
|
||||
*
|
||||
* Expected arguments:
|
||||
* input: input array (any number of dimensions)
|
||||
* mean:
|
||||
* variance:
|
||||
* gamma: optional
|
||||
* beta: optional
|
||||
* dLdOut: next epsilon
|
||||
*
|
||||
* Int args:
|
||||
* 0: apply scale
|
||||
* 1: apply offset
|
||||
*
|
||||
* T args:
|
||||
* 0: epsilon
|
||||
*
|
||||
* output arrays:
|
||||
* dL/dInput
|
||||
* dL/dMean
|
||||
* dL/dVariance
|
||||
* dL/dGamma, optional
|
||||
* dL/dBeta, optional
|
||||
*/
|
||||
DECLARE_CUSTOM_OP(batchnorm_bp, 4, 3, false, 1, 2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation updates parameters with provided gradients, wrt learning rate
|
||||
* Expected arguments:
|
||||
* x: parameters, any shape
|
||||
* y: gradients. same shape as x
|
||||
* lr: optional, learning rate
|
||||
*
|
||||
* T args:
|
||||
* 0: optional, learning rate
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_apply_sgd)
|
||||
DECLARE_CONFIGURABLE_OP(apply_sgd, 2, 1, true, -2, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation performs batch normalization of layer, it is based on following article
|
||||
* https://arxiv.org/abs/1502.03167. Expected arguments: x: input 4D array of shape [bS,iH,iW,iD] (data format = NHWC)
|
||||
* or [bS,iD,iH,iW] (data format = NCHW), where bS - batch size iH - input height iW - input width iD - input depth (or
|
||||
* number of channels) scale: 1D input array of scale factors, shape [iD] offset: 1D input array of offsets (shifts),
|
||||
* shape [iD] mean: 1D input array of population mean used for inference, shape [iD], this array is required only if
|
||||
* isTraining = false variance: 1D input array of population mean used for inference, shape [iD], this array is required
|
||||
* only if isTraining = false
|
||||
*
|
||||
* T input arguments:
|
||||
* 0: epsilon, it is optional argument, default value is 0.001, this is small number to be added to the variance of x
|
||||
*
|
||||
* integer input arguments:
|
||||
* 0: dataFormat, may have two values: zero -> NHWC, unity -> NCHW
|
||||
* 1: isTraining, may have two values: zero -> inference, unity -> training
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_fused_batch_norm)
|
||||
DECLARE_CUSTOM_OP(fused_batch_norm, 3, 1, false, 0, 2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_log_softmax)
|
||||
DECLARE_CONFIGURABLE_OP(log_softmax, 1, 1, true, 0, 0);
|
||||
DECLARE_CONFIGURABLE_OP(log_softmax_bp, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* relu_layer = relu(x*w + b)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_relu_layer)
|
||||
DECLARE_CUSTOM_OP(relu_layer, 3, 1, false, 0, 0);
|
||||
#endif
|
||||
/**
|
||||
* applies layer normalization to input
|
||||
* y = g * standardize(x) + b
|
||||
*
|
||||
* see sd::ops::standardize
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_layer_norm)
|
||||
DECLARE_CONFIGURABLE_OP(layer_norm, 3, 1, true, 0, -2);
|
||||
DECLARE_CUSTOM_OP(layer_norm_bp, 4, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation performs dot product attention on the given timeseries input with the given queries
|
||||
* out = sum(similarity(k_i, q) * v_i)
|
||||
*
|
||||
* similarity(k, q) = softmax(k * q) where x * q is the dot product of x and q
|
||||
*
|
||||
* Optionally with normalization step:
|
||||
* similarity(k, q) = softmax(k * q / sqrt(size(q))
|
||||
*
|
||||
* See also "Attention is all you need" (https://arxiv.org/abs/1706.03762, p. 4, eq. 1)
|
||||
*
|
||||
* Note: This supports multiple queries at once, if only one query is available the queries vector still has to
|
||||
* be 3D but can have queryCount = 1
|
||||
*
|
||||
* Note: keys and values usually is the same array. If you want to use it as the same array, simply pass it for
|
||||
* both.
|
||||
*
|
||||
* Expected arguments:
|
||||
* q: input 3D array "queries" of shape [batchSize, featureKeys, queryCount] or 4D array of shape [batchSize, numHeads,
|
||||
* featureKeys, queryCount] k: input 3D array "keys" of shape [batchSize, featureKeys, timesteps] or 4D array of shape
|
||||
* [batchSize, numHeads, featureKeys, timesteps] v: input 3D array "values" of shape [batchSize, featureValues,
|
||||
* timesteps] or 4D array of shape [batchSize, numHeads, featureValues, timesteps] mask: OPTIONAL; array that defines
|
||||
* which values should be skipped of shape [batchSize, timesteps]
|
||||
*
|
||||
* integer input arguments:
|
||||
* 0: normalization, may have two values: zero -> do not apply normalization, one -> apply normalization
|
||||
* 1: withWeights, may have two values: zero -> do not return weights, one -> return weights
|
||||
*
|
||||
* Output Arrays:
|
||||
* 0: Attention result arrays of shape [batchSize, featureValues, queryCount] or [batchSize, numHeads, featureValues,
|
||||
* queryCount] 1: OPTIONAL; Attention weights of shape [batchSize, timesteps, queryCount] or [batchSize, numHeads,
|
||||
* timesteps, queryCount]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_dot_product_attention)
|
||||
DECLARE_CUSTOM_OP(dot_product_attention, 3, -1, false, 0, 2);
|
||||
DECLARE_CUSTOM_OP(dot_product_attention_bp, 4, 3, false, 0, 1);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* This operation performs dot product attention on the given timeseries input with the given queries
|
||||
* out = sum(similarity(k_i, q) * v_i)
|
||||
*
|
||||
* similarity(k, q) = softmax(k * q) where x * q is the dot product of x and q
|
||||
*
|
||||
* Optionally with normalization step:
|
||||
* similarity(k, q) = softmax(k * q / sqrt(size(q))
|
||||
*
|
||||
* See also "Attention is all you need" (https://arxiv.org/abs/1706.03762, p. 4, eq. 1)
|
||||
*
|
||||
* Note: This supports multiple queries at once, if only one query is available the queries vector still has to
|
||||
* be 3D but can have queryCount = 1
|
||||
*
|
||||
* Note: keys and values usually is the same array. If you want to use it as the same array, simply pass it for
|
||||
* both.
|
||||
*
|
||||
* Expected arguments:
|
||||
* q: input 3D array "queries" of shape [batchSize, featureKeys, queryCount] or 4D array of shape [batchSize, numHeads,
|
||||
* featureKeys, queryCount] k: input 3D array "keys" of shape [batchSize, featureKeys, timesteps] or 4D array of shape
|
||||
* [batchSize, numHeads, featureKeys, timesteps] v: input 3D array "values" of shape [batchSize, featureValues,
|
||||
* timesteps] or 4D array of shape [batchSize, numHeads, featureValues, timesteps] mask: OPTIONAL; array that defines
|
||||
* which values should be skipped of shape [batchSize, timesteps]
|
||||
*
|
||||
* integer input arguments:
|
||||
* 0: normalization, may have two values: zero -> do not apply normalization, one -> apply normalization
|
||||
* 1: withWeights, may have two values: zero -> do not return weights, one -> return weights
|
||||
*
|
||||
* Output Arrays:
|
||||
* 0: Attention result arrays of shape [batchSize, featureValues, queryCount] or [batchSize, numHeads, featureValues,
|
||||
* queryCount] 1: OPTIONAL; Attention weights of shape [batchSize, timesteps, queryCount] or [batchSize, numHeads,
|
||||
* timesteps, queryCount]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_dot_product_attention_v2)
|
||||
DECLARE_CUSTOM_OP(dot_product_attention_v2, -2, -1, false, -2, 2);
|
||||
DECLARE_CUSTOM_OP(dot_product_attention_v2_bp, -2, -3, false, -2, 1);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* This performs multi-headed dot product attention on the given timeseries input
|
||||
* out = concat(head_1, head_2, ..., head_n) * Wo
|
||||
* head_i = dot_product_attention(Wq_i*q, Wk_i*k, Wv_i*v)
|
||||
*
|
||||
* Optionally with normalization when calculating the attention for each head.
|
||||
*
|
||||
* See also "Attention is all you need" (https://arxiv.org/abs/1706.03762, pp. 4,5, "3.2.2 Multi-Head Attention")
|
||||
*
|
||||
* This makes use of dot_product_attention OP support for rank 4 inputs.
|
||||
*
|
||||
* Expected arguments:
|
||||
* q: input 3D array "queries" of shape [batchSize, featureKeys, queryCount]
|
||||
* k: input 3D array "keys" of shape [batchSize, featureKeys, timesteps]
|
||||
* v: input 3D array "values" of shape [batchSize, featureValues, timesteps]
|
||||
* Wq: input query projection weights of shape [numHeads, projectedKeys, featureKeys]
|
||||
* Wk: input key projection weights of shape [numHeads, projectedKeys, featureKeys]
|
||||
* Wv: input value projection weights of shape [numHeads, projectedValues, featureValues]
|
||||
* Wo: output projection weights of shape [numHeads * projectedValues, outSize]
|
||||
* mask: OPTIONAL; array that defines which values should be skipped of shape [batchSize, timesteps]
|
||||
*
|
||||
* integer input arguments:
|
||||
* 0: normalization, may have two values: zero -> do not apply normalization, one -> apply normalization
|
||||
* 1: withWeights, may have two values: zero -> do not return weights, one -> return weights
|
||||
*
|
||||
* Output Arrays:
|
||||
* 0: Attention result arrays of shape [batchSize, outSize, queryCount]
|
||||
* 1: OPTIONAL; Attention weights of shape [batchSize, numHeads, timesteps, queryCount]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_multi_head_dot_product_attention)
|
||||
DECLARE_CUSTOM_OP(multi_head_dot_product_attention, 7, -1, false, 0, 2);
|
||||
DECLARE_CUSTOM_OP(multi_head_dot_product_attention_bp, 8, 7, false, 0, 1);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* *
|
||||
* *
|
||||
* * This program and the accompanying materials are made available under the
|
||||
* * terms of the Apache License, Version 2.0 which is available at
|
||||
* * https://www.apache.org/licenses/LICENSE-2.0.
|
||||
* *
|
||||
* * See the NOTICE file distributed with this work for additional
|
||||
* * information regarding copyright ownership.
|
||||
* * Unless required by applicable law or agreed to in writing, software
|
||||
* * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* * License for the specific language governing permissions and limitations
|
||||
* * under the License.
|
||||
* *
|
||||
* * SPDX-License-Identifier: Apache-2.0
|
||||
* *****************************************************************************
|
||||
*/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_RANDOM_H
|
||||
#define LIBND4J_HEADERS_RANDOM_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
#if NOT_EXCLUDED(OP_set_seed)
|
||||
DECLARE_CUSTOM_OP(set_seed, -2, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_get_seed)
|
||||
DECLARE_CUSTOM_OP(get_seed, -2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* random_uniform distribution for types int32,int64, float16, float and double
|
||||
* by default dtype is float32
|
||||
*
|
||||
* input:
|
||||
* 0 - shape of output (1D int tensor)
|
||||
* 1 - min val (0D of output type) - optional (0 as default)
|
||||
* 2 - max val (0D of output type) - optional (inf as default)
|
||||
*
|
||||
* output:
|
||||
* 0 - uniformly distributed values of given type (between min and max)
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_randomuniform)
|
||||
DECLARE_CUSTOM_OP(randomuniform, 1, 1, false, 0, -1);
|
||||
#endif
|
||||
/*
|
||||
* multinomial (categorical) random generator draws samples from a multinomial distribution
|
||||
*
|
||||
* Input array:
|
||||
* 0 - 2D ndarray with unnormalized log-probabilities with shape [batch_size (N), num_classes (K)]
|
||||
* 1 - array with one int value of samples number, number of independent samples to draw for each experiment 1,N.
|
||||
* Int arguments:
|
||||
* 0 - optional argument, corresponds to dimension with batch_size
|
||||
* 1 - optional argument, integer type to use for the output. Default int64.
|
||||
*
|
||||
* Output array:
|
||||
* 0 - 2D ndarray with the drawn samples of shape [batch_size, num_samples]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_random_multinomial)
|
||||
DECLARE_CUSTOM_OP(random_multinomial, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_random_normal)
|
||||
DECLARE_CUSTOM_OP(random_normal, 1, 1, true, 2, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_random_bernoulli)
|
||||
DECLARE_CUSTOM_OP(random_bernoulli, 1, 1, true, 0, 1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_random_exponential)
|
||||
DECLARE_CUSTOM_OP(random_exponential, 1, 1, true, 1, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_random_crop)
|
||||
DECLARE_CUSTOM_OP(random_crop, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* random_gamma op.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_random_gamma)
|
||||
DECLARE_CUSTOM_OP(random_gamma, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* random_poisson op.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_random_poisson)
|
||||
DECLARE_CUSTOM_OP(random_poisson, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,421 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_RECURRENT_H
|
||||
#define LIBND4J_HEADERS_RECURRENT_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if NOT_EXCLUDED(OP_sru)
|
||||
/**
|
||||
* Implementation of operation for Simple Recurrent Unit: "Training RNNs as Fast as CNNs" Tao Lei, Yu Zhang, Yoav Artzi
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input 3d tensor with shape [bS x K x N], N - number of time steps, bS - batch size, K - number of features
|
||||
* 1: 2d tensor of weights [3K x K]
|
||||
* 2: row of biases with twice length [1 x 2K]
|
||||
* 3: 2d tensor of previous cell state [bS x K]
|
||||
* 4: optional, 2d tensor of dropout mask [bS x K]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: 3d tensor of cell output [bS x K x N]
|
||||
* 1: 3d tensor of cell state [bS x K x N]
|
||||
*/
|
||||
DECLARE_CUSTOM_OP(sru, 5, 2, false, 0, 0);
|
||||
/**
|
||||
* Implementation of operation for back propagation in Simple Recurrent Unit: "Training RNNs as Fast as CNNs" Tao Lei,
|
||||
* Yu Zhang, Yoav Artzi
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input 3d tensor with shape [bS x K x N], N - number of time steps, bS - batch size, K - number of features
|
||||
* 1: 2d tensor of weights [3K x K]
|
||||
* 2: row of biases with twice length [1 x 2K]
|
||||
* 3: 2d tensor of previous cell state [bS x K]
|
||||
* 4: 3d tensor of cell state [bS x K x N]
|
||||
* 5: 2d tensor of cell state gradients [bS x K]
|
||||
* 6: 3d tensor of state output gradients [bS x K x N]
|
||||
* 7: optional, 2d tensor of dropout mask [bS x K]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: 3d tensor of input gradients [bS x K x N]
|
||||
* 1: 3d tensor of weights gradients [bS x 3K x K]
|
||||
* 2: 2d, row of biases gradients [1 x 2K]
|
||||
* 3: 2d, tensor of state gradients [bS x K]
|
||||
*/
|
||||
DECLARE_CUSTOM_OP(sru_bp, 8, 4, true, 0, 0);
|
||||
#endif
|
||||
|
||||
|
||||
#if NOT_EXCLUDED(OP_sru_bi)
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation for Simple Recurrent Unit (bidirectional case): "Training RNNs as Fast as CNNs" Tao Lei,
|
||||
* Yu Zhang, Yoav Artzi
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input 3d tensor with shape [N x bS x 2K], N - number of time steps, bS - batch size, K - number of features
|
||||
* 1: 2d tensor of weights [2K x 6K]
|
||||
* 2: row of biases with twice length [1 x 4K]
|
||||
* 3: 2d tensor of previous cell state [bS x 2K]
|
||||
* 4: optional, 2d tensor of dropout mask [bS x 2K]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: 3d tensor of cell output [N x bS x 2K]
|
||||
* 1: 3d tensor of cell state [N x bS x 2K]
|
||||
*/
|
||||
|
||||
DECLARE_CUSTOM_OP(sru_bi, 5, 2, true, 0, 0);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation for back propagation in Simple Recurrent Unit (bidirectional case): "Training RNNs as
|
||||
* Fast as CNNs" Tao Lei, Yu Zhang, Yoav Artzi
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input 3d tensor with shape [N x bS x 2K], N - number of time steps, bS - batch size, K - number of features
|
||||
* 1: 2d tensor of weights [2K x 6K]
|
||||
* 2: row of biases with twice length [1 x 4K]
|
||||
* 3: 2d tensor of previous cell state [bS x 2K]
|
||||
* 4: 3d tensor of cell state [N x bS x 2K]
|
||||
* 5: 2d tensor of cell state gradients [bS x 2K]
|
||||
* 6: 3d tensor of state output gradients [N x bS x 2K]
|
||||
* 7: optional, 2d tensor of dropout mask [bS x 2K]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: 3d tensor of input gradients [N x bS x 2K]
|
||||
* 1: 3d tensor of weights gradients [N x 2K x 6K]
|
||||
* 2: 2d, row of biases gradients [1 x 4K]
|
||||
* 3: 2d, tensor of state gradients [bS x 2K]
|
||||
*/
|
||||
DECLARE_CUSTOM_OP(sru_bi_bp, 8, 4, true, 0, 0);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation for LSTM cell with peep hole connections:
|
||||
* S. Hochreiter and J. Schmidhuber. "Long Short-Term Memory". Neural Computation
|
||||
* and
|
||||
* https://research.google.com/pubs/archive/43905.pdf
|
||||
* Hasim Sak, Andrew Senior, and Francoise Beaufays. "Long short-term memory recurrent neural network architectures
|
||||
* for large scale acoustic modeling." INTERSPEECH, 2014.
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [batchSize x inSize], batchSize - batch size, inSize - number of features
|
||||
* 1: previous cell output [batchSize x numProj], that is at previous time step t-1, in case of projection=false ->
|
||||
* numProj=numUnits!!! 2: previous cell state [batchSize x numUnits], that is at previous time step t-1 3:
|
||||
* input-to-hidden weights, [inSize x 4*numUnits] 4: hidden-to-hidden weights, [numProj x 4*numUnits] 5: diagonal
|
||||
* weights for peephole connections [3*numUnits] 6: projection weights [numUnits x numProj] 7: biases, [4*numUnits]
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: if not zero, provide peephole connections
|
||||
* 1: if not zero, then projection is performed, if zero then numProj==numUnits is mandatory!
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: clipping value for cell state, if it is not equal to zero, then cell state is clipped
|
||||
* 1: clipping value for projected cell output, if it is not equal to zero, then projected cell output is clipped
|
||||
* 2: the bias added to forget gates in order to reduce the scale of forgetting in the beginning of the training
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: current cell output [batchSize x numProj], that is at current time step t
|
||||
* 1: current cell state [batchSize x numUnits], that is at current time step t
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lstmCell)
|
||||
DECLARE_CUSTOM_OP(lstmCell, 8, 2, false, 3, 2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_lstmLayerCell)
|
||||
DECLARE_CUSTOM_OP(lstmLayerCell, 5, 2, false, 1, 3);
|
||||
DECLARE_CUSTOM_OP(lstmLayerCellBp, 7, 5, false, 1, 3);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation for LSTM cell with optional peep hole connections:
|
||||
* S. Hochreiter and J. Schmidhuber. "Long Short-Term Memory". Neural Computation
|
||||
* and
|
||||
* https://research.google.com/pubs/archive/43905.pdf
|
||||
* Hasim Sak, Andrew Senior, and Francoise Beaufays. "Long short-term memory recurrent neural network architectures
|
||||
* for large scale acoustic modeling." INTERSPEECH, 2014. See also: https://arxiv.org/pdf/1503.04069.pdf
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input [bS, inSize] at time t
|
||||
* 1: previous cell state [bS, numUnits], time t-1
|
||||
* 2: previous output [bS, numUnits], time t-1
|
||||
* 3: Weights - concatenated (input-to-hidden, hidden-to-hidden weights) weights, [(inSize+numUnits), 4*numUnits]
|
||||
* 4: weights - cell peephole (t-1) connections to input modulation gate, [numUnits]
|
||||
* 5: weights - cell peephole (t-1) connections to forget gate, [numUnits]
|
||||
* 6: weights - cell peephole (t) connections to output gate, [numUnits]
|
||||
* 7: biases, shape [4*numUnits]
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: if not zero, provide peephole connections
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: the bias added to forget gates in order to reduce the scale of forgetting in the beginning of the training
|
||||
* 1: clipping value for cell state, if it is not equal to zero, then cell state is clipped
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: i - Input modulation gate activations [bS, numUnits]
|
||||
* 1: c (cs) - Cell state (pre tanh) [bs, numUnits] (cs)
|
||||
* 2: f - Output - forget gate activations [bs, numUnits]
|
||||
* 3: o - Output - output gate activations [bs, numUnits]
|
||||
* 4: z (ci) - Output - block input [bs, numUnits]
|
||||
* 5: h (co) - Cell state, post tanh [bs, numUnits]
|
||||
* 6: y (h) - Current cell output [bS, numUnits], time t
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lstmBlockCell)
|
||||
DECLARE_CUSTOM_OP(lstmBlockCell, 8, 7, false, 2, 1);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation for LSTM layer with optional peep hole connections.
|
||||
* See lstmBlockCell for details. lstmBlockCell is used internally for computation.
|
||||
* This method expects as input (and returns as output) sequences in one of 3 formats, depending on the data format arg:
|
||||
* dataFormat = 0 -> TNS: shape [timeLength, numExamples, inOutSize] - sometimes referred to as "time major"
|
||||
* dataFormat = 1 -> NST: shape [numExamples, inOutSize, timeLength]
|
||||
* dataFormat = 2 -> NTS: shape [numExamples, timeLength, inOutSize] - TF "time_major=false" layout
|
||||
*
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: max sequence length; long/int64 scalar
|
||||
* 1: input [seqLength, bS, inSize] at time t
|
||||
* 2: previous/initial cell state [bS, numUnits]
|
||||
* 3: previous/initial output [bS, numUnits]
|
||||
* 4: Weights - concatenated (input-to-hidden, hidden-to-hidden weights) weights, [(inSize+numUnits), 4*numUnits]
|
||||
* 5: weights - cell peephole (t-1) connections to input modulation gate, [numUnits]
|
||||
* 6: weights - cell peephole (t-1) connections to forget gate, [numUnits]
|
||||
* 7: weights - cell peephole (t) connections to output gate, [numUnits]
|
||||
* 8: biases, Shape [4*numUnits]
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: if not zero, provide peephole connections
|
||||
* 1: Data format - 0=TNS=[seqLen,mb,size]; 1=NST=[mb,size,seqLen]; 2=NTS=[mb,seqLen,size]
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: the bias added to forget gates in order to reduce the scale of forgetting in the beginning of the training
|
||||
* 1: clipping value for cell state, if it is not equal to zero, then cell state is clipped
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: i - Input modulation gate activations, rank 3, shape as per dataFormat
|
||||
* 1: c (cs) - Cell state (pre tanh), rank 3, shape as per dataFormat
|
||||
* 2: f - Output - forget gate activations, rank 3, shape as per dataFormat
|
||||
* 3: o - Output - output gate activations, rank 3, shape as per dataFormat
|
||||
* 4: z (ci) - Output - block input, rank 3, shape as per dataFormat
|
||||
* 5: h (co) - Cell state, post tanh, rank 3, shape as per dataFormat
|
||||
* 6: y (h) - Current cell output, rank 3, shape as per dataFormat
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lstmBlock)
|
||||
DECLARE_CUSTOM_OP(lstmBlock, 9, 7, false, 2, 2);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if NOT_EXCLUDED(OP_lstmLayer)
|
||||
DECLARE_CUSTOM_OP(lstmLayer, 3, 1, false, 1, 5);
|
||||
DECLARE_CUSTOM_OP(lstmLayer_bp, 4, 1, false, 1, 5);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operations for Simple Recurrent Unit cell: "Training RNNs as Fast as CNNs" Tao Lei, Yu Zhang, Yoav
|
||||
* Artzi
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [batchSize x inSize], batchSize - batch size, inSize - number of features
|
||||
* 1: previous cell state [batchSize x inSize], that is at previous time step t-1
|
||||
* 2: weights [inSize x 3*inSize]
|
||||
* 3: biases [1 x 2*inSize]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: current cell output [batchSize x inSize], that is at current time step t
|
||||
* 1: current cell state [batchSize x inSize], that is at current time step t
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sruCell)
|
||||
DECLARE_CUSTOM_OP(sruCell, 4, 2, false, 0, 0);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of gated Recurrent Unit cell:
|
||||
* Kyunghyun Cho, Bart van Merrienboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, Yoshua
|
||||
* Bengio "Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation"
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [batchSize x inSize], batchSize - batch size, inSize - number of features
|
||||
* 1: previous cell output [batchSize x numUnits], that is at previous time step t-1
|
||||
* 2: RU weights - [(inSize+numUnits), 2*numUnits] - reset and update gates (input/recurrent weights)
|
||||
* 3: C weights - [(inSize+numUnits), numUnits] - cell gate (input/recurrent weights)
|
||||
* 4: reset and update biases, [2*numUnits] - reset and update gates
|
||||
* 5: cell biases, [numUnits]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: Reset gate output [bS, numUnits]
|
||||
* 1: Update gate output [bS, numUnits]
|
||||
* 2: Cell gate output [bS, numUnits]
|
||||
* 3: Current cell output [bS, numUnits]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_gruCell)
|
||||
DECLARE_CUSTOM_OP(gruCell, 6, 4, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(gruCell_bp, 10, 6, false, 0, 0);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation "LSTM time sequences" with peep hole connections:
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [time x batchSize x inSize], time - number of time steps, batchSize - batch size, inSize -
|
||||
* number of features 1: initial cell output [batchSize x numProj], that is at time step = 0, in case of
|
||||
* projection=false -> numProj=numUnits!!! 2: initial cell state [batchSize x numUnits], that is at time step = 0 3:
|
||||
* input-to-hidden weights, [inSize x 4*numUnits] 4: hidden-to-hidden weights, [numProj x 4*numUnits] 5: diagonal
|
||||
* weights for peephole connections [3*numUnits] 6: projection weights [numUnits x numProj] 7: biases, [4*numUnits]
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: if not zero, provide peephole connections
|
||||
* 1: if not zero, then projection is performed, if zero then numProj==numUnits is mandatory!
|
||||
*
|
||||
* Input float arguments:
|
||||
* 0: clipping value for cell state, if it is not equal to zero, then cell state is clipped
|
||||
* 1: clipping value for projected cell output, if it is not equal to zero, then projected cell output is clipped
|
||||
* 2: the bias added to forget gates in order to reduce the scale of forgetting in the beginning of the training
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: cell outputs [time x batchSize x numProj], that is per each time step
|
||||
* 1: cell states [time x batchSize x numUnits], that is per each time step
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_lstm)
|
||||
DECLARE_CUSTOM_OP(lstm, 8, 2, false, 3, 2);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of gated Recurrent Unit:
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [time x batchSize x inSize], time - number of time steps, batchSize - batch size, inSize -
|
||||
* number of features 1: initial cell output [batchSize x numUnits], that is at time step = 0 2: input-to-hidden
|
||||
* weights, [inSize x 3*numUnits] 3: hidden-to-hidden weights, [numUnits x 3*numUnits] 4: biases, [3*numUnits]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: cell outputs [time x batchSize x numUnits], that is per each time step
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_gru)
|
||||
DECLARE_CUSTOM_OP(gru, 5, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(gru_bp, 6, 5, false, 0, 0);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation "static RNN time sequences" with peep hole connections:
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [time x batchSize x inSize], time - number of time steps, batchSize - batch size, inSize -
|
||||
* number of features 1: input-to-hidden weights, [inSize x numUnits] 2: hidden-to-hidden weights, [numUnits x
|
||||
* numUnits] 3: biases, [2*numUnits] 4: (optional) initial cell output [batchSize x numUnits], that is at time step = 0
|
||||
* 5: (optional) vector with shape [batchSize] containing integer values within [0,time), each element of this vector
|
||||
* set max time step per each input in batch, this provides no calculations for time >= maxTimeStep
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: cell outputs [time x batchSize x numUnits]
|
||||
* 1: cell final non-zero output [batchSize x numUnits]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_static_rnn)
|
||||
DECLARE_CUSTOM_OP(static_rnn, 4, 2, false, 0, 0);
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation "static RNN time sequences" with peep hole connections:
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [time x batchSize x inSize] or [batchSize x time x numUnits], time - number of time steps,
|
||||
* batchSize - batch size, inSize - number of features 1: input-to-hidden weights, [inSize x numUnits] 2:
|
||||
* hidden-to-hidden weights, [numUnits x numUnits] 3: biases, [2*numUnits] 4: (optional) initial cell output [batchSize
|
||||
* x numUnits], that is at time step = 0 5: (optional) vector with shape [batchSize] containing integer values within
|
||||
* [0,time), each element of this vector set max time step per each input in batch, this provides no calculations for
|
||||
* time >= maxTimeStep
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: (optional) timeMajor - if non zero then input shape is [time, batchSize, ...], else [batchSize, time, ...]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: cell outputs [time x batchSize x numUnits] or [batchSize x time x numUnits]
|
||||
* 1: cell final non-zero output [batchSize x numUnits]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_dynamic_rnn)
|
||||
DECLARE_CUSTOM_OP(dynamic_rnn, 4, 2, false, 0, 0);
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation "static RNN time sequences" with peep hole connections:
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [time x batchSize x inSize], time - number of time steps, batchSize - batch size, inSize -
|
||||
* number of features 1: input-to-hidden weights for forward RNN, [inSize x numUnitsFW] 2: hidden-to-hidden weights
|
||||
* for forward RNN, [numUnitsFW x numUnitsFW] 3: biases for forward RNN, [2*numUnitsFW] 4: input-to-hidden weights for
|
||||
* backward RNN, [inSize x numUnitsBW] 5: hidden-to-hidden weights for backward RNN, [numUnitsBW x numUnitsBW] 6:
|
||||
* biases for backward RNN, [2*numUnitsBW] 7: (optional) initial cell output for forward RNN [batchSize x numUnitsFW],
|
||||
* that is at time step = 0 8: (optional) initial cell output for backward RNN [batchSize x numUnitsBW], that is at time
|
||||
* step = 0 9: (optional) vector with shape [batchSize] containing integer values within [0,time), each element of this
|
||||
* vector set max time step per each input in batch, this provides no calculations for time >= maxTimeStep
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: cell outputs [time x batchSize x (numUnitsFW + numUnitsBW)]
|
||||
* 1: cell final non-zero output for forward RNN [batchSize x numUnitsFW]
|
||||
* 2: cell final non-zero output for backward RNN [batchSize x numUnitsBW]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_static_bidirectional_rnn)
|
||||
DECLARE_CUSTOM_OP(static_bidirectional_rnn, 7, 3, false, 0, 0);
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Implementation of operation "static RNN time sequences" with peep hole connections:
|
||||
*
|
||||
* Input arrays:
|
||||
* 0: input with shape [time x batchSize x inSize] or [batchSize x time x inSize], time - number of time steps,
|
||||
* batchSize - batch size, inSize - number of features 1: input-to-hidden weights for forward RNN, [inSize x
|
||||
* numUnitsFW] 2: hidden-to-hidden weights for forward RNN, [numUnitsFW x numUnitsFW] 3: biases for forward RNN,
|
||||
* [2*numUnitsFW] 4: input-to-hidden weights for backward RNN, [inSize x numUnitsBW] 5: hidden-to-hidden weights for
|
||||
* backward RNN, [numUnitsBW x numUnitsBW] 6: biases for backward RNN, [2*numUnitsBW] 7: (optional) initial cell output
|
||||
* for forward RNN [batchSize x numUnitsFW], that is at time step = 0 8: (optional) initial cell output for backward RNN
|
||||
* [batchSize x numUnitsBW], that is at time step = 0 9: (optional) vector with shape [batchSize] containing integer
|
||||
* values within [0,time), each element of this vector set max time step per each input in batch, this provides no
|
||||
* calculations for time >= maxTimeStep
|
||||
*
|
||||
* Input integer arguments:
|
||||
* 0: (optional) timeMajor - if non zero then input shape is [time, batchSize, ...], else [batchSize, time, ...]
|
||||
*
|
||||
* Output arrays:
|
||||
* 0: cell outputs for forward RNN [time x batchSize x numUnitsFW] or [batchSize x time x numUnitsFW]
|
||||
* 1: cell outputs for backward RNN [time x batchSize x numUnitsBW] or [batchSize x time x numUnitsBW]
|
||||
* 2: cell final non-zero output for forward RNN [batchSize x numUnitsFW]
|
||||
* 3: cell final non-zero output for backward RNN [batchSize x numUnitsBW]
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_dynamic_bidirectional_rnn)
|
||||
DECLARE_CUSTOM_OP(dynamic_bidirectional_rnn, 7, 4, false, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
#endif
|
||||
@@ -0,0 +1,145 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_SHAPE_H
|
||||
#define LIBND4J_HEADERS_SHAPE_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
#define RESHAPE_NO_COPY_F_ORDER_MARKER -102
|
||||
#define RESHAPE_NO_COPY_C_ORDER_MARKER -99
|
||||
|
||||
#if NOT_EXCLUDED(OP_permute)
|
||||
DECLARE_CUSTOM_OP(permute, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_reshapeas)
|
||||
DECLARE_CUSTOM_OP(reshapeas, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_linear_copy)
|
||||
DECLARE_CUSTOM_OP(linear_copy, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
|
||||
#if NOT_EXCLUDED(OP_transpose)
|
||||
DECLARE_CUSTOM_OP(transpose, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#if NOT_EXCLUDED(OP_shape_of)
|
||||
DECLARE_CUSTOM_OP(shape_of, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_shapes_of)
|
||||
DECLARE_CUSTOM_OP(shapes_of, -1, -1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_set_shape)
|
||||
DECLARE_CUSTOM_OP(set_shape, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_squeeze)
|
||||
DECLARE_CUSTOM_OP(squeeze, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_expand_dims)
|
||||
DECLARE_CUSTOM_OP(expand_dims, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_flatten_2d)
|
||||
DECLARE_CUSTOM_OP(flatten_2d, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_reshape)
|
||||
DECLARE_CUSTOM_OP(reshape, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_reshape_no_copy)
|
||||
DECLARE_CUSTOM_OP(reshape_no_copy, -2, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_size_at)
|
||||
DECLARE_CUSTOM_OP(size_at, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op changes order of given array to specified order.
|
||||
* In other words: C/F order switch
|
||||
*
|
||||
* Int args:
|
||||
* 0 - isForder. set to 1 for F order output, or 0 for C order output
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_order)
|
||||
DECLARE_CUSTOM_OP(order, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op boosts specified input up to specified shape
|
||||
*
|
||||
* @tparam T
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_tile_to_shape)
|
||||
DECLARE_CUSTOM_OP(tile_to_shape, 1, 1, false, 0, -1);
|
||||
DECLARE_CUSTOM_OP(tile_to_shape_bp, 2, 1, false, 0, -1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This op broadcast given input up to given shape
|
||||
*
|
||||
* inputs:
|
||||
* input array - array to be broadcasted to given shape
|
||||
* shape array - array containing shape be broadcasted to
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_broadcast_to)
|
||||
DECLARE_CUSTOM_OP(broadcast_to, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_evaluate_reduction_shape)
|
||||
DECLARE_CUSTOM_OP(evaluate_reduction_shape, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation creates new array
|
||||
* Input:
|
||||
* array with shape values
|
||||
*
|
||||
* IArgs:
|
||||
* order value
|
||||
* data type value
|
||||
*
|
||||
* BArgs:
|
||||
* initialization option
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_create)
|
||||
DECLARE_CUSTOM_OP(create, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef SAMEDIFF_STRINGS_H
|
||||
#define SAMEDIFF_STRINGS_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This operation splits input string into pieces separated by delimiter
|
||||
*
|
||||
* Input[0] - string to split
|
||||
* Input[1] - delimiter
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_split_string)
|
||||
DECLARE_CUSTOM_OP(split_string, 2, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif // SAMEDIFF_STRINGS_H
|
||||
@@ -0,0 +1,50 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
#if NOT_EXCLUDED(OP_test_output_reshape)
|
||||
DECLARE_OP(test_output_reshape, 1, 1, true);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_test_scalar)
|
||||
DECLARE_CUSTOM_OP(test_scalar, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_testreduction)
|
||||
DECLARE_REDUCTION_OP(testreduction, 1, 1, false, 0, -1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_noop)
|
||||
DECLARE_OP(noop, -2, -2, true);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_testop2i2o)
|
||||
DECLARE_OP(testop2i2o, 2, 2, true);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_testcustom)
|
||||
DECLARE_CUSTOM_OP(testcustom, 1, 1, false, 0, -1);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
@@ -0,0 +1,33 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_TPARTY_H
|
||||
#define LIBND4J_HEADERS_TPARTY_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,237 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_TRANSFORMS_H
|
||||
#define LIBND4J_HEADERS_TRANSFORMS_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
#if NOT_EXCLUDED(OP_clipbyvalue)
|
||||
DECLARE_CONFIGURABLE_OP(clipbyvalue, -1, 1, true, -1, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_clipbynorm)
|
||||
DECLARE_CONFIGURABLE_OP(clipbynorm, -1, 1, true, -1, 0);
|
||||
DECLARE_CUSTOM_OP(clipbynorm_bp, -1, 1, false, -1, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_clipbyavgnorm)
|
||||
DECLARE_CONFIGURABLE_OP(clipbyavgnorm, -1, 1, true, -1, 0);
|
||||
DECLARE_CUSTOM_OP(clipbyavgnorm_bp, -1, 1, false, -1, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_cumsum)
|
||||
DECLARE_CONFIGURABLE_OP(cumsum, 1, 1, true, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_cumprod)
|
||||
DECLARE_CONFIGURABLE_OP(cumprod, 1, 1, true, 0, 2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_tile)
|
||||
DECLARE_CUSTOM_OP(tile, 1, 1, false, 0, -2);
|
||||
DECLARE_CUSTOM_OP(tile_bp, 2, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_repeat)
|
||||
DECLARE_CUSTOM_OP(repeat, 1, 1, true, 0, -1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_invert_permutation)
|
||||
DECLARE_CONFIGURABLE_OP(invert_permutation, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_concat)
|
||||
DECLARE_CUSTOM_OP(concat, -1, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(concat_bp, -1, -1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_mergemax)
|
||||
DECLARE_OP(mergemax, -1, 1, false);
|
||||
DECLARE_CUSTOM_OP(mergemax_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
/*
|
||||
* Complete tensor with max indices merged from all input tensors list
|
||||
*
|
||||
* INPUT: tensors with the same shape
|
||||
* OUTPUT: integer tensor with the same shape
|
||||
* INT_ARG: result type (one of int), INT32 by default
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_mergemaxindex)
|
||||
DECLARE_CUSTOM_OP(mergemaxindex, -1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_mergeadd)
|
||||
DECLARE_OP(mergeadd, -1, 1, false);
|
||||
DECLARE_CUSTOM_OP(mergeadd_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_mergeavg)
|
||||
DECLARE_OP(mergeavg, -1, 1, false);
|
||||
DECLARE_CUSTOM_OP(mergeavg_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_scatter_update)
|
||||
DECLARE_CONFIGURABLE_OP(scatter_update, -2, 1, true, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_Floor)
|
||||
DECLARE_OP(Floor, 1, 1, true);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_Log1p)
|
||||
DECLARE_OP(Log1p, 2, 1, true);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_reverse)
|
||||
DECLARE_CONFIGURABLE_OP(reverse, 1, 1, true, 0, -2);
|
||||
DECLARE_CUSTOM_OP(reverse_bp, 2, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_gather)
|
||||
DECLARE_CUSTOM_OP(gather, 1, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_pad)
|
||||
DECLARE_CUSTOM_OP(pad, 2, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* creates identity 2D matrix or batch of identical 2D identity matrices
|
||||
*
|
||||
* Input array:
|
||||
* provide some array - in any case operation simply neglects it
|
||||
*
|
||||
* Input float argument (if passed):
|
||||
* TArgs[0] - type of elements of output array, default value is 5 (float)
|
||||
*
|
||||
* Input integer arguments:
|
||||
* IArgs[0] - order of output identity matrix, 99 -> 'c'-order, 102 -> 'f'-order
|
||||
* IArgs[1] - the number of rows in output inner-most 2D identity matrix
|
||||
* IArgs[2] - optional, the number of columns in output inner-most 2D identity matrix, if this argument is not
|
||||
* provided then it is taken to be equal to number of rows IArgs[3,4,...] - optional, shape of batch, output matrix will
|
||||
* have leading batch dimensions of this shape
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_eye)
|
||||
DECLARE_CUSTOM_OP(eye, -2, 1, false, -2, 2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_gather_nd)
|
||||
DECLARE_CUSTOM_OP(gather_nd, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_reverse_sequence)
|
||||
DECLARE_CUSTOM_OP(reverse_sequence, 2, 1, false, 0, 2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_trace)
|
||||
DECLARE_CUSTOM_OP(trace, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_random_shuffle)
|
||||
DECLARE_OP(random_shuffle, 1, 1, true);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* clip a list of given tensors with given average norm when needed
|
||||
*
|
||||
* Input:
|
||||
* a list of tensors (at least one)
|
||||
*
|
||||
* Input floating point argument:
|
||||
* clip_norm - a value that used as threshold value and norm to be used
|
||||
*
|
||||
* return a list of clipped tensors
|
||||
* and global_norm as scalar tensor at the end
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_clip_by_global_norm)
|
||||
DECLARE_CUSTOM_OP(clip_by_global_norm, 1, 2, true, 1, 0);
|
||||
#endif
|
||||
#if NOT_EXCLUDED(OP_tri)
|
||||
DECLARE_CUSTOM_OP(tri, -2, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_triu)
|
||||
DECLARE_CUSTOM_OP(triu, 1, 1, false, 0, 0);
|
||||
DECLARE_CUSTOM_OP(triu_bp, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_mirror_pad)
|
||||
DECLARE_CUSTOM_OP(mirror_pad, 2, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_cumsum)
|
||||
DECLARE_CUSTOM_OP(cumsum_bp, 2, -1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_cumprod)
|
||||
DECLARE_CUSTOM_OP(cumprod_bp, 2, -21, false, 0, 2);
|
||||
#endif
|
||||
|
||||
#if NOT_EXCLUDED(OP_flatten)
|
||||
DECLARE_CUSTOM_OP(flatten, -1, 1, false, 0, 1);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* returns histogram (as 1D array) with fixed bins width
|
||||
*
|
||||
* Input arrays:
|
||||
* - input array with elements to be binned into output histogram
|
||||
* - range array with first element being bottom limit and second element being top limit of histogram,
|
||||
please note that input_value <= range[0] will be mapped to histogram[0], input_value >= range[1] will be mapped to
|
||||
histogram[-1]
|
||||
*
|
||||
* Input integer arguments:
|
||||
* nbins (optional) - number of histogram bins, default value is 100
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_histogram_fixed_width)
|
||||
DECLARE_CUSTOM_OP(histogram_fixed_width, 2, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* standardizes input array to be zero mean unit variance along the given axis
|
||||
*
|
||||
*
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_standardize)
|
||||
DECLARE_CONFIGURABLE_OP(standardize, 1, 1, true, 0, -2);
|
||||
DECLARE_CUSTOM_OP(standardize_bp, 2, 1, false, 0, -2);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation calculates hash code, optionally along dimension
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_hashcode)
|
||||
DECLARE_CUSTOM_OP(hashcode, 1, 1, false, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation calculates number of entries per bin
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_histogram)
|
||||
DECLARE_CUSTOM_OP(histogram, 1, 1, false, 0, 1);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* *
|
||||
* *
|
||||
* * This program and the accompanying materials are made available under the
|
||||
* * terms of the Apache License, Version 2.0 which is available at
|
||||
* * https://www.apache.org/licenses/LICENSE-2.0.
|
||||
* *
|
||||
* * See the NOTICE file distributed with this work for additional
|
||||
* * information regarding copyright ownership.
|
||||
* * Unless required by applicable law or agreed to in writing, software
|
||||
* * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* * License for the specific language governing permissions and limitations
|
||||
* * under the License.
|
||||
* *
|
||||
* * SPDX-License-Identifier: Apache-2.0
|
||||
* *****************************************************************************
|
||||
*/
|
||||
|
||||
//
|
||||
// @author Oleh Semeniv (oleg.semeniv@gmail.com)
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_HEADERS_UPDATERS_H
|
||||
#define LIBND4J_HEADERS_UPDATERS_H
|
||||
#include <execution/Threads.h>
|
||||
#include <helpers/ConstantTadHelper.h>
|
||||
#include <ops/declarable/headers/common.h>
|
||||
#include <ops/declarable/helpers/updatersHelpers.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
|
||||
/**
|
||||
* SGD updater
|
||||
* Input arrays:
|
||||
* 0 - input array with gradients.
|
||||
* Optional:
|
||||
* 1 - scalar learning rate value
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_sgd_updater)
|
||||
DECLARE_CONFIGURABLE_OP(sgd_updater, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RmsPropUpdater updater
|
||||
* Input arrays:
|
||||
* 0 - input array with gradients.
|
||||
* 1 - Initial state
|
||||
* Optional:
|
||||
* 2 - scalar learning rate value
|
||||
* 3 - scalar rms decay
|
||||
* 4 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - scalar rms decay
|
||||
* 2 - epsilon
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_rms_prop_updater)
|
||||
DECLARE_CONFIGURABLE_OP(rms_prop_updater, 2, 2, true, 0, 0);
|
||||
#endif
|
||||
// AdaGrad
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - historical grad state
|
||||
* Optional :
|
||||
* 2 - scalar learning rate value
|
||||
* 3 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - epsilon
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ada_grad_updater)
|
||||
DECLARE_CONFIGURABLE_OP(ada_grad_updater, 2, 2, true, 0, 0);
|
||||
#endif
|
||||
// AdaMax
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - gradient state V
|
||||
* 2 - gradient state M
|
||||
* Optional :
|
||||
* 3 - scalar learning rate value
|
||||
* 4 - beta 1 value
|
||||
* 5 - beta 2 value
|
||||
* 6 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - beta 1 value
|
||||
* 2 - beta 2 value
|
||||
* 3 - epsilon
|
||||
* Optional:
|
||||
* I args
|
||||
* 0 - iteration
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ada_max_updater)
|
||||
DECLARE_CONFIGURABLE_OP(ada_max_updater, 3, 3, true, 0, 0);
|
||||
#endif
|
||||
// Nesterov's momentum
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - V grad state
|
||||
* Optional :
|
||||
* 2 - scalar learning rate value
|
||||
* 3 - scalar momentum value
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - learning rate value
|
||||
* 1 - momentum value
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_nesterovs_updater)
|
||||
DECLARE_CONFIGURABLE_OP(nesterovs_updater, 2, 2, true, 0, 0);
|
||||
#endif
|
||||
// Adam
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - gradient state V
|
||||
* 2 - gradient state M
|
||||
* Optional :
|
||||
* 3 - scalar learning rate value
|
||||
* 4 - beta 1 value
|
||||
* 5 - beta 2 value
|
||||
* 6 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - beta 1 value
|
||||
* 2 - beta 2 value
|
||||
* 3 - epsilon
|
||||
* Optional:
|
||||
* I args
|
||||
* 0 - iteration
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_adam_updater)
|
||||
DECLARE_CONFIGURABLE_OP(adam_updater, 3, 3, true, 0, 0);
|
||||
#endif
|
||||
// AdaBelief
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - gradient state V
|
||||
* 2 - gradient state M
|
||||
* Optional :
|
||||
* 3 - scalar learning rate value
|
||||
* 4 - beta 1 value
|
||||
* 5 - beta 2 value
|
||||
* 6 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - beta 1 value
|
||||
* 2 - beta 2 value
|
||||
* 3 - epsilon
|
||||
* Optional:
|
||||
* I args
|
||||
* 0 - iteration
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_adabelief_updater)
|
||||
DECLARE_CONFIGURABLE_OP(adabelief_updater, 3, 3, true, 0, 0);
|
||||
#endif
|
||||
// AdaDelta
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - gradient state V
|
||||
* 2 - gradient state M
|
||||
* Optional :
|
||||
* 3 - rho value
|
||||
* 6 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - rho
|
||||
* 1 - epsilon
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ada_delta_updater)
|
||||
DECLARE_CONFIGURABLE_OP(ada_delta_updater, 3, 3, true, 0, 0);
|
||||
#endif
|
||||
// Nadam
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - gradient state V
|
||||
* 2 - gradient state M
|
||||
* Optional :
|
||||
* 3 - scalar learning rate value
|
||||
* 4 - beta 1 value
|
||||
* 5 - beta 2 value
|
||||
* 6 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - beta 1 value
|
||||
* 2 - beta 2 value
|
||||
* 3 - epsilon
|
||||
* Optional:
|
||||
* I args
|
||||
* 0 - iteration
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_nadam_updater)
|
||||
DECLARE_CONFIGURABLE_OP(nadam_updater, 3, 3, true, 0, 0);
|
||||
#endif
|
||||
// AmsGrad
|
||||
/* Input arrays :
|
||||
* 0 - input array with gradients.
|
||||
* 1 - gradient state V - sqrd gradients
|
||||
* 2 - gradient state M - moving avg
|
||||
* 3 - gradient state H - max
|
||||
* Optional :
|
||||
* 4 - scalar learning rate value
|
||||
* 5 - beta 1 value
|
||||
* 6 - beta 2 value
|
||||
* 7 - epsilon
|
||||
* Optional:
|
||||
* T args
|
||||
* 0 - scalar learning rate value
|
||||
* 1 - beta 1 value
|
||||
* 2 - beta 2 value
|
||||
* 3 - epsilon
|
||||
* Optional:
|
||||
* I args
|
||||
* 0 - iteration
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_ams_grad_updater)
|
||||
DECLARE_CONFIGURABLE_OP(ams_grad_updater, 4, 4, true, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
/* ******************************************************************************
|
||||
*
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License, Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
******************************************************************************/
|
||||
|
||||
//
|
||||
// @author raver119@gmail.com
|
||||
//
|
||||
|
||||
#ifndef LIBND4J_UTILS_H
|
||||
#define LIBND4J_UTILS_H
|
||||
#include <ops/declarable/headers/common.h>
|
||||
|
||||
namespace sd {
|
||||
namespace ops {
|
||||
/**
|
||||
* This operation prints out NDArray content, either on host or device.
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_print_variable)
|
||||
DECLARE_CUSTOM_OP(print_variable, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This operation prints out affinity & locality status of given NDArray
|
||||
*/
|
||||
#if NOT_EXCLUDED(OP_print_affinity)
|
||||
DECLARE_CUSTOM_OP(print_affinity, 1, 1, true, 0, 0);
|
||||
#endif
|
||||
} // namespace ops
|
||||
} // namespace sd
|
||||
|
||||
#endif // LIBND4J_UTILS_H
|
||||
Reference in New Issue
Block a user