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]