Safe item method and view_as added

This commit is contained in:
Roland Grinis 2021-03-02 09:32:36 +00:00
parent f15ac20323
commit 4aa1df0628
2 changed files with 10 additions and 1 deletions

View File

@ -14,8 +14,12 @@ public class RealTensor(
TensorStrides(shape), TensorStrides(shape),
RealBuffer(buffer) RealBuffer(buffer)
) { ) {
override fun item(): Double = buffer[0] override fun item(): Double {
check(buffer.size > 0) { "The tensor is empty" }
return buffer[0]
} }
}
public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> { public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor> {
@ -116,6 +120,10 @@ public class RealTensorAlgebra : TensorPartialDivisionAlgebra<Double, RealTensor
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun RealTensor.view_as(other: RealTensor): RealTensor {
TODO("Not yet implemented")
}
override fun RealTensor.abs(): RealTensor { override fun RealTensor.abs(): RealTensor {
TODO("Not yet implemented") TODO("Not yet implemented")
} }

View File

@ -40,6 +40,7 @@ public interface TensorAlgebra<T, TensorType : TensorStructure<T>>{
//https://pytorch.org/docs/stable/tensor_view.html //https://pytorch.org/docs/stable/tensor_view.html
public fun TensorType.view(shape: IntArray): TensorType public fun TensorType.view(shape: IntArray): TensorType
public fun TensorType.view_as(other: TensorType): TensorType
//https://pytorch.org/docs/stable/generated/torch.abs.html //https://pytorch.org/docs/stable/generated/torch.abs.html
public fun TensorType.abs(): TensorType public fun TensorType.abs(): TensorType