Public Class encoder_train

    Public Shared Sub Train(runId As String, cleanDataRoot As String, modelsDir As String, umapEvery As Integer, saveEvery As Integer, backupEvery As Integer, visEvery As Integer, forceRestart As Boolean, visdomServer As String, noVisdom As Boolean)
        '····省略代码····

        ' 设置运行前向传递和损失计算的设备（电脑上没装CUDA，所以第二个选项跳过）
        Dim device As Device = If(TorchSharp.torch.cuda.is_available(), Device.CUDA, Device.CPU)
        Dim lossDevice As Device = Device.CPU

        '' 创建模型和优化器
        Dim model As SpeakerEncoder = New SpeakerEncoder(device, lossDevice)
        Dim optimizer As TorchSharp.torch.OptimizerOptions = TorchSharp.torch.optim.Adam(model.Parameters(), learning_rate_init)

       '····省略代码····
       
    End Sub
End Class

Public Class SpeakerEncoder
    Private ReadOnly _device As DeviceDescriptor
    Private ReadOnly _lossDevice As DeviceDescriptor
    Private ReadOnly _intTensorConverter As IValueConverter(Of Integer)
    Private ReadOnly _lossFn As CrossEntropyLoss

    Public Property TensorSimilarityWeight As TorchSharp.NN.Parameter
    Public Property TensorSimilarityBias As TorchSharp.NN.Parameter

    Public Property Lstm As TorchSharp.NN.Recurrent.LSTM
    Public Property Linear As TorchSharp.NN.Linear
    Public Property Relu As TorchSharp.NN.Activation.ReLU

    Public Sub New(device As DeviceDescriptor, lossDevice As DeviceDescriptor)
        _device = device
        _lossDevice = lossDevice
        _intTensorConverter = ValueConverters.Int64ToFloat.Create()

        ' 定义神经网络结构
        Lstm = New TorchSharp.NN.Recurrent.LSTM(New TorchSharp.NN.Recurrent.LSTMOptions(_device, inputSize:=mel_n_channels, hiddenSize:=model_hidden_size, numLayers:=model_num_layers, batchFirst:=True))
        Linear = New TorchSharp.NN.Linear(New LinearOptions(_device, inFeatures:=model_hidden_size, outFeatures:=model_embedding_size))
        Relu = New TorchSharp.NN.Activation.ReLU(_device)

        ' 初始化余弦相似度缩放参数
        TensorSimilarityWeight = New TorchSharp.NN.Parameter(New Microsoft.ML.OnnxRuntime.Tensors.DenseTensor())
        TensorSimilarityBias = New TorchSharp.NN.Parameter(New Microsoft.ML.OnnxRuntime.Tensors.DenseTensor(Of Single)(_lossDevice, New Integer() {1}, New Single() {-5.0F}))

        ' 初始化损失函数（这里假设有一个自定义的CrossEntropyLoss类，适用于.NET环境）
        _lossFn = New CrossEntropyLoss(_lossDevice)
    End Sub
End Class

Namespace Microsoft
    Public Module ML
        Public Class OnnxRuntime
            Public Class Tensors

                Public Class ArrayUtilities
                    Public Shared Function GetStrides(dimensions As ReadOnlySpan(Of Integer), Optional reverseStride As Boolean = False) As Integer()
                        Dim strides = New Integer(dimensions.Length - 1) {}

                        If dimensions.Length = 0 Then
                            Return strides
                        End If

                        Dim stride = 1
                        If reverseStride Then
                            For i = 0 To strides.Length - 1
                                strides(i) = stride
                                stride *= dimensions(i)
                            Next
                        Else
                            For i = strides.Length - 1 To 0 Step -1
                                strides(i) = stride
                                stride *= dimensions(i)
                            Next
                        End If

                        Return strides
                    End Function

                End Class

                Public Class ReadOnlySpan(Of T)
                    Public Shared length As Integer
                End Class

                Public Class DenseTensor(Of T)

                    Private Length as Integer= 0


                    Public Sub New()
                        MyBase.New() ' 假设BaseTensor有一个接受数据类型和形状的构造函数
                        InitializeEmptyData()
                    End Sub

                    Private _data As Object

                    Private Sub InitializeEmptyData()
                        ' 根据泛型参数T确定数据类型并创建相应的空数组
                        Dim dataType = GetDefaultDataType()
                        Dim emptyData As Object = Nothing

                        If dataType = DataType.Float Then
                            emptyData = New Single() {}
                        ElseIf dataType = DataType.Double Then
                            emptyData = New Double() {}
                        ElseIf dataType = DataType.Int32 Then
                            emptyData = New Integer() {}
                            ' ... 其他数据类型的处理 ...
                        Else
                            Throw New NotSupportedException($"Unsupported data type: {dataType}")
                            Me._data = emptyData
                        End If
                    End Sub

                    Private Function GetDefaultDataType() As DataType
                        Select Case GetType(T).Name
                            Case "Single"
                                Return DataType.Float
                            Case "Double"
                                Return DataType.Double
                            Case "Int32"
                                Return DataType.Int32
                                ' ... 其他数据类型的映射 ...
                            Case Else
                                Throw New NotSupportedException($"Unsupported data type: {GetType(T)}")
                        End Select
                    End Function

                    <Flags>
                    Public Enum DataType
                        Float = 1
                        [Double] = 2
                        Int32 = 4
                    End Enum


                    Private ReadOnly memory As Memory(Of T)

                    Friend Sub New(ByVal fromArray As Array, Optional ByVal reverseStride As Boolean = False)
                        MyBase.New(fromArray, reverseStride)

                        ' Copy initial array
                        Dim backingArray(fromArray.Length - 1) As T

                        Dim index As Integer = 0
                        If reverseStride Then
                            ' Array is always row-major
                            Dim sourceStrides() As Integer = ArrayUtilities.GetStrides(dimensions)

                            For Each item In fromArray
                                Dim destIndex As Integer = ArrayUtilities.TransformIndexByStrides(index, sourceStrides, False, strides)
                                backingArray(destIndex) = DirectCast(item, T)
                                index += 1
                            Next
                        Else
                            For Each item In fromArray
                                backingArray(index) = DirectCast(item, T)
                                index += 1
                            Next
                        End If

                        memory = backingArray
                    End Sub

                    Public Sub New(ByVal length As Integer)
                        MyBase.New()
                        memory = New T(length - 1) {}
                    End Sub

                    Public Sub New(ByVal dimensions As ReadOnlySpan(Of Integer), Optional ByVal reverseStride As Boolean = False)
                        MyBase.New()
                        memory = New T(Length - 1) {}
                    End Sub

                    Public Sub New(ByVal memory As Memory(Of T), ByVal dimensions As ReadOnlySpan(Of Integer), Optional ByVal reverseStride As Boolean = False)
                        MyBase.New()

                        Me.memory = memory

                        If Length <> memory.Length Then
                            Throw New ArgumentException(
                                $"Length of {NameOf(memory)} ({memory.Length}) must match product of " &
                                $"{NameOf(dimensions)} ({Length}).")
                        End If
                    End Sub
                End Class
            End Class
        End Class
    End Module
End Namespace



请根据上面代码上下文解决下面这段代码中“stride *= dimensions(i)”这一行代码出现的问题：无法为类“ML.OnnxRuntime.Tensors.ReadOnlySpan(Of Integer)”编制索引，因为它没有默认属性。


If reverseStride Then
                            For i = 0 To strides.Length - 1
                                strides(i) = stride
                                stride *= dimensions(i)
                            Next
                        Else
                            For i = strides.Length - 1 To 0 Step -1
                                strides(i) = stride
                                stride *= dimensions(i)
                            Next
                        End If