Basic tasks for Alya and Andrei
This commit is contained in:
parent
ed007589cf
commit
90f4ff06fd
@ -1,6 +1,5 @@
|
|||||||
package space.kscience.kmath.tensors
|
package space.kscience.kmath.tensors
|
||||||
|
|
||||||
import space.kscience.kmath.linear.LupDecompositionFeature
|
|
||||||
import space.kscience.kmath.nd.MutableNDBuffer
|
import space.kscience.kmath.nd.MutableNDBuffer
|
||||||
import space.kscience.kmath.structures.RealBuffer
|
import space.kscience.kmath.structures.RealBuffer
|
||||||
import space.kscience.kmath.structures.array
|
import space.kscience.kmath.structures.array
|
||||||
@ -15,6 +14,9 @@ public class RealTensor(
|
|||||||
TensorStrides(shape),
|
TensorStrides(shape),
|
||||||
RealBuffer(buffer)
|
RealBuffer(buffer)
|
||||||
) {
|
) {
|
||||||
|
/*
|
||||||
|
* TODO: Andrei remove item()
|
||||||
|
*/
|
||||||
override fun item(): Double {
|
override fun item(): Double {
|
||||||
check(buffer.size > 0) { "The tensor is empty" }
|
check(buffer.size > 0) { "The tensor is empty" }
|
||||||
return buffer[0]
|
return buffer[0]
|
||||||
@ -24,6 +26,10 @@ public class RealTensor(
|
|||||||
|
|
||||||
public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> {
|
public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> {
|
||||||
|
|
||||||
|
override fun RealTensor.value(): Double {
|
||||||
|
TODO("Andrei")
|
||||||
|
}
|
||||||
|
|
||||||
override fun Double.plus(other: RealTensor): RealTensor {
|
override fun Double.plus(other: RealTensor): RealTensor {
|
||||||
val n = other.buffer.size
|
val n = other.buffer.size
|
||||||
val arr = other.buffer.array
|
val arr = other.buffer.array
|
||||||
@ -34,95 +40,95 @@ public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.plus(value: Double): RealTensor {
|
override fun RealTensor.plus(value: Double): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.plus(other: RealTensor): RealTensor {
|
override fun RealTensor.plus(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.plusAssign(value: Double) {
|
override fun RealTensor.plusAssign(value: Double) {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.plusAssign(other: RealTensor) {
|
override fun RealTensor.plusAssign(other: RealTensor) {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun Double.minus(other: RealTensor): RealTensor {
|
override fun Double.minus(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.minus(value: Double): RealTensor {
|
override fun RealTensor.minus(value: Double): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.minus(other: RealTensor): RealTensor {
|
override fun RealTensor.minus(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.minusAssign(value: Double) {
|
override fun RealTensor.minusAssign(value: Double) {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.minusAssign(other: RealTensor) {
|
override fun RealTensor.minusAssign(other: RealTensor) {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun Double.times(other: RealTensor): RealTensor {
|
override fun Double.times(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.times(value: Double): RealTensor {
|
override fun RealTensor.times(value: Double): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.times(other: RealTensor): RealTensor {
|
override fun RealTensor.times(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.timesAssign(value: Double) {
|
override fun RealTensor.timesAssign(value: Double) {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.timesAssign(other: RealTensor) {
|
override fun RealTensor.timesAssign(other: RealTensor) {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.unaryMinus(): RealTensor {
|
override fun RealTensor.unaryMinus(): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.dot(other: RealTensor): RealTensor {
|
override fun RealTensor.dot(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.dotAssign(other: RealTensor) {
|
override fun RealTensor.dotAssign(other: RealTensor) {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.dotRightAssign(other: RealTensor) {
|
override fun RealTensor.dotRightAssign(other: RealTensor) {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun diagonalEmbedding(diagonalEntries: RealTensor, offset: Int, dim1: Int, dim2: Int): RealTensor {
|
override fun diagonalEmbedding(diagonalEntries: RealTensor, offset: Int, dim1: Int, dim2: Int): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.transpose(i: Int, j: Int): RealTensor {
|
override fun RealTensor.transpose(i: Int, j: Int): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.transposeAssign(i: Int, j: Int) {
|
override fun RealTensor.transposeAssign(i: Int, j: Int) {
|
||||||
TODO("Not yet implemented")
|
TODO("Alya")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.view(shape: IntArray): RealTensor {
|
override fun RealTensor.view(shape: IntArray): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.view_as(other: RealTensor): RealTensor {
|
override fun RealTensor.view_as(other: RealTensor): RealTensor {
|
||||||
TODO("Not yet implemented")
|
TODO("Andrei")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun RealTensor.abs(): RealTensor {
|
override fun RealTensor.abs(): RealTensor {
|
||||||
@ -174,6 +180,10 @@ public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun lu_unpack(A_LU: RealTensor, pivots: RealTensor): Triple<RealTensor, RealTensor, RealTensor> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
override fun RealTensor.svd(): Triple<RealTensor, RealTensor, RealTensor> {
|
override fun RealTensor.svd(): Triple<RealTensor, RealTensor, RealTensor> {
|
||||||
/**
|
/**
|
||||||
* Main first task for @AlyaNovikova
|
* Main first task for @AlyaNovikova
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package space.kscience.kmath.tensors
|
package space.kscience.kmath.tensors
|
||||||
|
|
||||||
// https://proofwiki.org/wiki/Definition:Algebra_over_Ring
|
// https://proofwiki.org/wiki/Definition:Algebra_over_Ring
|
||||||
public interface TensorAlgebra<T, TensorType : TensorStructure<T>>{
|
public interface TensorAlgebra<T, TensorType : TensorStructure<T>> {
|
||||||
|
|
||||||
|
public fun TensorType.value(): T
|
||||||
|
|
||||||
public operator fun T.plus(other: TensorType): TensorType
|
public operator fun T.plus(other: TensorType): TensorType
|
||||||
public operator fun TensorType.plus(value: T): TensorType
|
public operator fun TensorType.plus(value: T): TensorType
|
||||||
@ -69,6 +71,9 @@ public interface TensorPartialDivisionAlgebra<T, TensorType : TensorStructure<T>
|
|||||||
//https://pytorch.org/docs/stable/generated/torch.lu.html
|
//https://pytorch.org/docs/stable/generated/torch.lu.html
|
||||||
public fun TensorType.lu(): Pair<TensorType, TensorType>
|
public fun TensorType.lu(): Pair<TensorType, TensorType>
|
||||||
|
|
||||||
|
//https://pytorch.org/docs/stable/generated/torch.lu_unpack.html
|
||||||
|
public fun lu_unpack(A_LU: TensorType, pivots: TensorType): Triple<TensorType, TensorType, TensorType>
|
||||||
|
|
||||||
//https://pytorch.org/docs/stable/generated/torch.svd.html
|
//https://pytorch.org/docs/stable/generated/torch.svd.html
|
||||||
public fun TensorType.svd(): Triple<TensorType, TensorType, TensorType>
|
public fun TensorType.svd(): Triple<TensorType, TensorType, TensorType>
|
||||||
|
|
||||||
|
@ -3,6 +3,10 @@ package space.kscience.kmath.tensors
|
|||||||
import space.kscience.kmath.nd.MutableNDStructure
|
import space.kscience.kmath.nd.MutableNDStructure
|
||||||
|
|
||||||
public interface TensorStructure<T> : MutableNDStructure<T> {
|
public interface TensorStructure<T> : MutableNDStructure<T> {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: Andrei remove item() and value()
|
||||||
|
*/
|
||||||
public fun item(): T
|
public fun item(): T
|
||||||
|
|
||||||
// A tensor can have empty shape, in which case it represents just a value
|
// A tensor can have empty shape, in which case it represents just a value
|
||||||
|
Loading…
Reference in New Issue
Block a user