microsoft-visualbasic-runtime/Text/Xml/Models/Vector.vb

165 lines
5.6 KiB
VB.net
Raw Normal View History

2019-11-10 15:16:27 +08:00
#Region "Microsoft.VisualBasic::66246ecfcb788370cee68475bb8589c9, Microsoft.VisualBasic.Core\Text\Xml\Models\Vector.vb"
2019-06-15 17:34:52 +08:00
2019-06-28 23:45:04 +08:00
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
2019-06-28 21:29:25 +08:00
2019-06-28 23:45:04 +08:00
' /********************************************************************************/
2019-06-28 21:29:25 +08:00
2019-06-28 23:45:04 +08:00
' Summaries:
2019-06-28 21:29:25 +08:00
2019-06-28 23:45:04 +08:00
' Class NumericVector
'
' Properties: Length, name, vector
'
' Function: GenericEnumerator, GetEnumerator, SequenceEqual, ToString
'
' Class TermsVector
'
' Properties: terms
'
' Function: GenericEnumerator, GetEnumerator, ToString
'
'
' /********************************************************************************/
2018-09-08 00:34:19 +08:00
#End Region
Imports System.Runtime.CompilerServices
Imports System.Xml.Serialization
2019-09-25 19:49:11 +08:00
Imports Microsoft.VisualBasic.Language
2019-06-28 21:29:25 +08:00
Imports Microsoft.VisualBasic.Linq
2018-09-08 00:34:19 +08:00
Imports Microsoft.VisualBasic.Serialization.JSON
Namespace Text.Xml.Models
''' <summary>
''' A <see cref="Double"/> type numeric sequence container
''' </summary>
2019-06-28 21:29:25 +08:00
<XmlType("numerics")>
Public Class NumericVector : Implements Enumeration(Of Double)
2018-09-08 00:34:19 +08:00
2019-06-28 21:29:25 +08:00
''' <summary>
''' 可以用这个属性来简单的标记这个向量所属的对象名称
''' </summary>
''' <returns></returns>
2018-11-24 19:02:27 +08:00
<XmlAttribute> Public Property name As String
2019-06-28 21:29:25 +08:00
''' <summary>
''' 存储于XML文档之中的数据向量
''' </summary>
''' <returns></returns>
2018-11-24 19:02:27 +08:00
<XmlAttribute> Public Property vector As Double()
2018-09-08 00:34:19 +08:00
''' <summary>
''' Get/Set Element ``Xi``
''' </summary>
''' <param name="i"></param>
''' <returns></returns>
Default Public Property Xi(i As Integer) As Double
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
2018-11-24 19:02:27 +08:00
Return vector(i)
2018-09-08 00:34:19 +08:00
End Get
Set(value As Double)
2018-11-24 19:02:27 +08:00
vector(i) = value
2018-09-08 00:34:19 +08:00
End Set
End Property
''' <summary>
''' The vector length for counting the elements in <see cref="Vector"/> property.
''' </summary>
''' <returns></returns>
Public ReadOnly Property Length As Integer
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
2018-11-24 19:02:27 +08:00
Return CInt(vector?.Length)
2018-09-08 00:34:19 +08:00
End Get
End Property
Public Overrides Function ToString() As String
2018-11-24 19:02:27 +08:00
If name.StringEmpty Then
Return vector.GetJson
Else
Return $"Dim {name} As Vector = {vector.GetJson}"
End If
2018-09-08 00:34:19 +08:00
End Function
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Shared Widening Operator CType(v As Double()) As NumericVector
Return New NumericVector With {.name = "NULL", .vector = v}
End Operator
2019-09-25 19:49:11 +08:00
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Shared Widening Operator CType(v As List(Of Double)) As NumericVector
Return New NumericVector With {.name = "NULL", .vector = v}
End Operator
2019-06-28 21:29:25 +08:00
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Shared Widening Operator CType(v As Integer()) As NumericVector
Return New NumericVector With {
.name = "NULL",
.vector = v.Select(Function(x) CDbl(x)).ToArray
}
End Operator
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Shared Narrowing Operator CType(v As NumericVector) As Double()
Return v.vector
End Operator
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Function SequenceEqual(input() As Double) As Boolean
Return vector.SequenceEqual(input)
End Function
2019-06-28 21:29:25 +08:00
Public Function GenericEnumerator() As IEnumerator(Of Double) Implements Enumeration(Of Double).GenericEnumerator
Return vector.AsEnumerable.GetEnumerator
End Function
Public Iterator Function GetEnumerator() As IEnumerator Implements Enumeration(Of Double).GetEnumerator
Yield GenericEnumerator()
End Function
2018-09-08 00:34:19 +08:00
End Class
2019-06-28 21:29:25 +08:00
Public Class TermsVector : Implements Enumeration(Of Double)
2018-09-08 00:34:19 +08:00
<XmlAttribute>
2019-06-10 21:56:35 +08:00
Public Property terms As String()
2018-09-08 00:34:19 +08:00
Public Overrides Function ToString() As String
2019-06-10 21:56:35 +08:00
Return terms.GetJson
2018-09-08 00:34:19 +08:00
End Function
2019-06-28 21:29:25 +08:00
Public Function GenericEnumerator() As IEnumerator(Of Double) Implements Enumeration(Of Double).GenericEnumerator
Return terms.AsEnumerable.GetEnumerator
End Function
Public Iterator Function GetEnumerator() As IEnumerator Implements Enumeration(Of Double).GetEnumerator
Yield GenericEnumerator()
End Function
2018-09-08 00:34:19 +08:00
End Class
End Namespace