From e110253d8f38171b91d4417c115713585e9faa29 Mon Sep 17 00:00:00 2001 From: Roland Grinis Date: Thu, 13 May 2021 19:26:18 +0100 Subject: [PATCH] remove cov from tensors API --- .../kmath/tensors/api/AnalyticTensorAlgebra.kt | 10 ---------- .../kscience/kmath/tensors/core/DoubleTensorAlgebra.kt | 10 +++++++++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt index 1db986e77..e58af14db 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/api/AnalyticTensorAlgebra.kt @@ -67,16 +67,6 @@ public interface AnalyticTensorAlgebra : TensorPartialDivisionAlgebra { */ public fun Tensor.variance(dim: Int, keepDim: Boolean): Tensor - /** - * Returns the covariance matrix M of given vectors. - * - * M[i, j] contains covariance of i-th and j-th given vectors - * - * @param tensors the [List] of 1-dimensional tensors with same shape - * @return the covariance matrix - */ - public fun cov(tensors: List>): Tensor - //For information: https://pytorch.org/docs/stable/generated/torch.exp.html public fun Tensor.exp(): Tensor diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt index c1694644f..78989f1f3 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt @@ -629,7 +629,15 @@ public open class DoubleTensorAlgebra : return ((x - x.mean()) * (y - y.mean())).mean() * n / (n - 1) } - override fun cov(tensors: List>): DoubleTensor { + /** + * Returns the covariance matrix M of given vectors. + * + * M[i, j] contains covariance of i-th and j-th given vectors + * + * @param tensors the [List] of 1-dimensional tensors with same shape + * @return the covariance matrix + */ + public fun cov(tensors: List>): DoubleTensor { check(tensors.isNotEmpty()) { "List must have at least 1 element" } val n = tensors.size val m = tensors[0].shape[0]