From a1ba9514bb3d982a8a302c031a80097b5810ee89 Mon Sep 17 00:00:00 2001 From: Jack Dermody Date: Mon, 9 Sep 2024 07:17:24 +1000 Subject: [PATCH] small refactor --- BrightData/BrightData.xml | 75 ++++++++++--------- BrightData/ExtensionMethods.TensorSegment.cs | 1 - BrightData/Interfaces.DataDimensions.cs | 4 - BrightData/Interfaces.Graphs.cs | 3 - BrightData/Interfaces.LinearAlgebra.cs | 1 - BrightData/Interfaces.VectorIndexing.cs | 2 - BrightData/Types/Graph/DirectedGraph.cs | 19 ++++- .../Types/Graph/DirectedGraphBuilder.cs | 26 +++++-- 8 files changed, 76 insertions(+), 55 deletions(-) diff --git a/BrightData/BrightData.xml b/BrightData/BrightData.xml index 6837c6f3..e60008ad 100644 --- a/BrightData/BrightData.xml +++ b/BrightData/BrightData.xml @@ -332,6 +332,12 @@ Length of largest observed string + + + Casts to double to perform numerical analysis + + + Static methods to create analyzers @@ -711,13 +717,7 @@ - - - Casts to double to perform numerical analysis - - - - + Maintains a mapping of types to indices @@ -1605,7 +1605,7 @@ - + @@ -1615,7 +1615,7 @@ - + @@ -1625,19 +1625,19 @@ - + Data table specification - + Data table specification - + Data type specification base @@ -1647,7 +1647,7 @@ - + Data type specification base @@ -1657,7 +1657,7 @@ - + Field specification @@ -1665,7 +1665,7 @@ - + Field specification @@ -1673,46 +1673,46 @@ - - - Throws an exception if a constraint fails validation - - - - - - - Throws an exception if a constraint fails validation - - - - - + A data dimension from a table - + A data dimension from a table - + - + - + - + + + + Throws an exception if a constraint fails validation + + + + + + + Throws an exception if a constraint fails validation + + + + Generic table row - column types are not specified @@ -10148,7 +10148,6 @@ Returns a list of vector indices ranked by the distance between that vector and a comparison vector Vector to compare - @@ -10156,7 +10155,6 @@ Returns the index of the closest vector in the set to each of the supplied vectors Vectors to compare - @@ -18237,6 +18235,9 @@ Index of element to remove + + + A fixed size weighted graph diff --git a/BrightData/ExtensionMethods.TensorSegment.cs b/BrightData/ExtensionMethods.TensorSegment.cs index b227dd6d..40c504c6 100644 --- a/BrightData/ExtensionMethods.TensorSegment.cs +++ b/BrightData/ExtensionMethods.TensorSegment.cs @@ -1,6 +1,5 @@ using BrightData.Helper; using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/BrightData/Interfaces.DataDimensions.cs b/BrightData/Interfaces.DataDimensions.cs index aaa85431..d9e9b77d 100644 --- a/BrightData/Interfaces.DataDimensions.cs +++ b/BrightData/Interfaces.DataDimensions.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BrightData { diff --git a/BrightData/Interfaces.Graphs.cs b/BrightData/Interfaces.Graphs.cs index 3d65544d..d1a9c7f1 100644 --- a/BrightData/Interfaces.Graphs.cs +++ b/BrightData/Interfaces.Graphs.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Numerics; -using System.Text; -using System.Threading.Tasks; namespace BrightData { diff --git a/BrightData/Interfaces.LinearAlgebra.cs b/BrightData/Interfaces.LinearAlgebra.cs index fb03b759..a3b2a60a 100644 --- a/BrightData/Interfaces.LinearAlgebra.cs +++ b/BrightData/Interfaces.LinearAlgebra.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Numerics; -using BrightData.Helper; using BrightData.LinearAlgebra; using CommunityToolkit.HighPerformance.Buffers; diff --git a/BrightData/Interfaces.VectorIndexing.cs b/BrightData/Interfaces.VectorIndexing.cs index 04fecc10..73b94a8e 100644 --- a/BrightData/Interfaces.VectorIndexing.cs +++ b/BrightData/Interfaces.VectorIndexing.cs @@ -141,7 +141,6 @@ public interface IVectorIndex : IDisposable /// Returns a list of vector indices ranked by the distance between that vector and a comparison vector /// /// Vector to compare - /// /// IEnumerable Rank(ReadOnlySpan vector); @@ -149,7 +148,6 @@ public interface IVectorIndex : IDisposable /// Returns the index of the closest vector in the set to each of the supplied vectors /// /// Vectors to compare - /// /// uint[] Closest(ReadOnlyMemory[] vector); } diff --git a/BrightData/Types/Graph/DirectedGraph.cs b/BrightData/Types/Graph/DirectedGraph.cs index c0e85478..ee379329 100644 --- a/BrightData/Types/Graph/DirectedGraph.cs +++ b/BrightData/Types/Graph/DirectedGraph.cs @@ -5,8 +5,12 @@ namespace BrightData.Types.Graph { - public record struct DirectedGraph : IHaveDataAsReadOnlyByteSpan, IHaveSize - where T: struct, IHaveSingleIndex + /// + /// Directed graph + /// + /// + public readonly record struct DirectedGraph : IHaveDataAsReadOnlyByteSpan, IHaveSize + where T: unmanaged, IHaveSingleIndex { const int HeaderSize = 8; @@ -57,6 +61,12 @@ ReadOnlySpan IHaveDataAsReadOnlyByteSpan.DataAsBytes } } + /// + /// Returns the value associated with the node + /// + /// + /// + /// public bool TryGetValue(uint nodeIndex, [NotNullWhen(true)]out T? value) { var nodeSpan = _nodes.AsSpan(); @@ -69,6 +79,11 @@ public bool TryGetValue(uint nodeIndex, [NotNullWhen(true)]out T? value) return true; } + /// + /// Enumerates the connected nodes from a single node + /// + /// + /// public IEnumerable EnumerateConnectedNodes(uint nodeIndex) { var nodeSpan = _nodes.AsSpan(); diff --git a/BrightData/Types/Graph/DirectedGraphBuilder.cs b/BrightData/Types/Graph/DirectedGraphBuilder.cs index 2ce6b604..d46864f0 100644 --- a/BrightData/Types/Graph/DirectedGraphBuilder.cs +++ b/BrightData/Types/Graph/DirectedGraphBuilder.cs @@ -1,15 +1,16 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using CommunityToolkit.HighPerformance; using CommunityToolkit.HighPerformance.Buffers; namespace BrightData.Types.Graph { + /// + /// Builds a directed graph + /// + /// public class DirectedGraphBuilder - where T: struct, IHaveSingleIndex + where T: unmanaged, IHaveSingleIndex { class Node(T value, int nodeOffset) { @@ -26,6 +27,11 @@ public void AddEdge(int toNodeOffset) } readonly Dictionary _nodes = new(); + /// + /// Add a new node + /// + /// + /// public uint Add(T node) { var nodeIndex = node.Index; @@ -33,6 +39,12 @@ public uint Add(T node) return nodeIndex; } + /// + /// Adds an edge between two nodes + /// + /// + /// + /// public bool AddEdge(uint fromNodeIndex, uint toNodeIndex) { if (_nodes.TryGetValue(fromNodeIndex, out var from) && _nodes.TryGetValue(toNodeIndex, out var to)) { @@ -43,6 +55,10 @@ public bool AddEdge(uint fromNodeIndex, uint toNodeIndex) return false; } + /// + /// Builds the graph + /// + /// public DirectedGraph Build() { using var nodes = new ArrayPoolBufferWriter.Node>();