Backends/SiaNet.Backend.TensorSharp/Cuda/CudaStorage.cs
/// <summary>
/// Gets the element as float.
/// </summary>
/// <param name="index">The index.</param>
/// <returns>System.Single.</returns>
/// <exception cref="NotSupportedException">Element type " + ElementType + " not supported</exception>
Gets the element as float.
Gets the element as float .
public override float GetElementAsFloat(long index)
        {
            var ptr = DevicePtrAtElement(index);
            if(ElementType == DType.Float32) { var result = new float[1]; context.CopyToHost(result, ptr); return result[0]; }
            else if (ElementType == DType.Float64) { var result = new double[1]; context.CopyToHost(result, ptr); return (float)result[0]; }
            else if (ElementType == DType.Int32) { var result = new int[1]; context.CopyToHost(result, ptr); return result[0]; }
            else if (ElementType == DType.UInt8) { var result = new byte[1]; context.CopyToHost(result, ptr); return result[0]; }
            else
                throw new NotSupportedException("Element type " + ElementType + " not supported");
        }
public override float GetElementAsFloat ( long index ) { var ptr = DevicePtrAtElement ( index ) ; if ( ElementType == DType . Float32 ) { var result = new float [ 1 ] ; context . CopyToHost ( result , ptr ) ; return result [ 0 ] ; } else if ( ElementType == DType . Float64 ) { var result = new double [ 1 ] ; context . CopyToHost ( result , ptr ) ; return ( float ) result [ 0 ] ; } else if ( ElementType == DType . Int32 ) { var result = new int [ 1 ] ; context . CopyToHost ( result , ptr ) ; return result [ 0 ] ; } else if ( ElementType == DType . UInt8 ) { var result = new byte [ 1 ] ; context . CopyToHost ( result , ptr ) ; return result [ 0 ] ; } else throw new NotSupportedException ( " " + ElementType + " " ) ; }
Gets the element as float.
Gets the element as float .
None
Element type " + ElementType + " not supported
Element type " + ElementType + " not supported
index
long
None