2021-02-01 13:31:45 +01:00
|
|
|
/* ******************************************************************************
|
|
|
|
*
|
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.
|
|
|
|
*
|
2021-02-01 13:31:45 +01:00
|
|
|
* See the NOTICE file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2019-06-06 14:21:15 +02:00
|
|
|
* 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 Yurii Shyrma on 11.01.2018
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBND4J_JACOBISVD_H
|
|
|
|
#define LIBND4J_JACOBISVD_H
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <helpers/hhSequence.h>
|
|
|
|
#include <array/NDArray.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-06-06 14:21:15 +02:00
|
|
|
namespace ops {
|
|
|
|
namespace helpers {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class JacobiSVD {
|
|
|
|
|
2020-05-14 17:06:13 +02:00
|
|
|
public:
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
NDArray _m;
|
|
|
|
NDArray _s; // vector with singular values
|
|
|
|
NDArray _u;
|
|
|
|
NDArray _v;
|
2020-05-14 17:06:13 +02:00
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
int _diagSize;
|
|
|
|
int _rows;
|
|
|
|
int _cols;
|
|
|
|
|
|
|
|
// bool _transp;
|
|
|
|
bool _calcU;
|
|
|
|
bool _calcV;
|
|
|
|
bool _fullUV;
|
|
|
|
|
|
|
|
JacobiSVD(const NDArray& matrix, const bool calcU, const bool calcV, const bool fullUV);
|
|
|
|
|
|
|
|
bool isBlock2x2NotDiag(NDArray& block, int p, int q, T& maxElem);
|
|
|
|
|
|
|
|
static bool createJacobiRotation(const T& x, const T& y, const T& z, NDArray& rotation);
|
2020-05-14 17:06:13 +02:00
|
|
|
static void createJacobiRotationGivens(const T& p, const T& q, NDArray& rotation);
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
static void svd2x2(const NDArray& block, int p, int q, NDArray& left, NDArray& right);
|
|
|
|
|
|
|
|
static void mulRotationOnLeft(const int i, const int j, NDArray& block, const NDArray& rotation);
|
|
|
|
|
|
|
|
static void mulRotationOnRight(const int i, const int j, NDArray& block, const NDArray& rotation);
|
|
|
|
|
|
|
|
void evalData(const NDArray& matrix);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif //LIBND4J_JACOBISVD_H
|