2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
2019-11-19 14:39:36 +01:00
|
|
|
* Copyright (c) 2019 Konduit K.K.
|
2019-06-06 14:21:15 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include "array/NDArray.h"
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-12-02 19:37:21 +01:00
|
|
|
class ND4J_EXPORT MmulHelper {
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// multiptication N-dimensions tensor on other N-dimensions one
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* mmulNxN(const sd::NDArray* A, const sd::NDArray* B, sd::NDArray* C, const double alpha = 1.0, const double beta = 0.0, const char outOrder = 'f');
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
// dot product of vectors (X * Y) = Z[0]
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* dot(const sd::NDArray* X, const sd::NDArray* Y, sd::NDArray* Z, const double alpha = 1.0, const double beta = 0.0);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
// multiptication Matrix to Matrix
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* mmulMxM(const sd::NDArray* A, const sd::NDArray* B, sd::NDArray* C, double alpha = 1.0, double beta = 0.0, const char outOrder = 'f');
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
// multiptication Matrix to vector
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* mmulMxV(const sd::NDArray* A, const sd::NDArray* B, sd::NDArray* C, double alpha = 1.0, double beta = 0.0, const char outOrder = 'f');
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* mmul(const sd::NDArray* A, const sd::NDArray* B, sd::NDArray* C = nullptr, const double alpha = 1.0, const double beta = 0.0, const char outOrder = 'f');
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* tensorDot(const sd::NDArray* A, const sd::NDArray* B, const std::initializer_list<int>& axesA, const std::initializer_list<int>& axesB = {});
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
static sd::NDArray* tensorDot(const sd::NDArray* A, const sd::NDArray* B, const std::vector<int>& axesA, const std::vector<int>& axesB);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
static void tensorDot(const sd::NDArray* a, const sd::NDArray* b, sd::NDArray* c, const std::vector<int>& axes_a, const std::vector<int>& axes_b, const std::vector<int>& permutForC = {});
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __JAVACPP_HACK__
|
|
|
|
/**
|
2019-11-19 14:39:36 +01:00
|
|
|
* 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
|
2019-06-06 14:21:15 +02:00
|
|
|
*/
|
2020-03-02 10:49:41 +01:00
|
|
|
static void tensorDot(const sd::NDArray* a, const sd::NDArray* b, sd::NDArray* c, const std::vector<std::vector<Nd4jLong>>& modifA, const std::vector<std::vector<Nd4jLong>>& modifB, const std::vector<std::vector<Nd4jLong>>& modifC);
|
|
|
|
static sd::NDArray* tensorDot(const sd::NDArray* a, const sd::NDArray* b, const std::vector<std::vector<Nd4jLong>>& modifA, const std::vector<std::vector<Nd4jLong>>& modifB);
|
2019-06-06 14:21:15 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-10 16:57:02 +02:00
|
|
|
static void matmul(const sd::NDArray* x, const sd::NDArray* y, sd::NDArray* z, const bool transX, const bool transY, double alpha = 1.0, double beta = 0.0);
|
2019-06-06 14:21:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif //LIBND4J_MMULHELPER_H
|