/* * ****************************************************************************** * * * * * * 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 Yurii Shyrma (iuriish@yahoo.com), created on 05.06.2018 // #ifndef LIBND4J_MMULHELPER_H #define LIBND4J_MMULHELPER_H #include "array/NDArray.h" namespace sd { class SD_LIB_EXPORT MmulHelper { private: // multiptication N-dimensions tensor on other N-dimensions one static NDArray* mmulNxN(NDArray* A, NDArray* B, NDArray* C, const double alpha = 1.0, const double beta = 0.0, const char outOrder = 'f'); // dot product of vectors (X * Y) = Z[0] static NDArray* dot(NDArray* X, NDArray* Y, NDArray* Z, const double alpha = 1.0, const double beta = 0.0); // multiptication Matrix to Matrix static NDArray* mmulMxM( NDArray* A, NDArray* B, NDArray* C, double alpha = 1.0, double beta = 0.0, const char outOrder = 'f'); // multiptication Matrix to vector static NDArray* mmulMxV( NDArray* A, NDArray* B, NDArray* C, double alpha = 1.0, double beta = 0.0, const char outOrder = 'f'); public: static NDArray* mmul(NDArray* A, NDArray* B, NDArray* C = nullptr, const double alpha = 1.0, const double beta = 0.0, const char outOrder = 'f'); static NDArray* tensorDot(NDArray* A, NDArray* B, const std::initializer_list& axesA, const std::initializer_list& axesB = {}); static NDArray* tensorDot(NDArray* A, NDArray* B, const std::vector& axesA, const std::vector& axesB); static void tensorDot(NDArray* a, NDArray* b, NDArray* c, std::vector& axes_a, std::vector& axes_b, std::vector& permutForC); static void computeNewShapesAndAxes( NDArray& as_, const std::vector& axes_a, NDArray& bs, const std::vector& axes_b, std::vector& newshape_a, std::vector& newaxes_a, std::vector& newshape_b, std::vector& newaxes_b ); #ifndef __JAVACPP_HACK__ /** * modif - (can be empty) vector containing a subsequence of permutation/reshaping arrays (in any order), user must * take care of correctness of such arrays by himself */ static void tensorDot(NDArray* a, NDArray* b, NDArray* c, std::vector>& modifA, std::vector>& modifB, std::vector>& modifC); static NDArray* tensorDot(NDArray* a, NDArray* b, std::vector>& modifA, std::vector>& modifB); static void tensorDot2(NDArray* a, NDArray* b, NDArray* c, const std::vector& axes_a, const std::vector& axes_b, std::vector& permutAt, std::vector& permuteBt, std::vector& permuteCt, NDArray* realFinalResult = nullptr); #endif static void matmul(NDArray* x, NDArray* y, NDArray* z, const bool transX, const bool transY, double alpha, double beta, NDArray* realFinalResult = nullptr); static bool resolveTranspose(sd::NDArray& a, sd::NDArray& b, bool& transA, bool& transB); }; } // namespace sd #endif // LIBND4J_MMULHELPER_H