Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Dermody committed Sep 8, 2024
1 parent 7c71472 commit a1ba951
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 55 deletions.
75 changes: 38 additions & 37 deletions BrightData/BrightData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@
Length of largest observed string
</summary>
</member>
<member name="T:BrightData.Analysis.SimpleNumericAnalysis`1">
<summary>
Casts to double to perform numerical analysis
</summary>
<typeparam name="T"></typeparam>
</member>
<member name="T:BrightData.Analysis.StaticAnalysers">
<summary>
Static methods to create analyzers
Expand Down Expand Up @@ -711,13 +717,7 @@
<param name="input"></param>
<param name="output"></param>
</member>
<member name="T:BrightData.Buffer.Operations.Helper.SimpleNumericAnalysis`1">
<summary>
Casts to double to perform numerical analysis
</summary>
<typeparam name="T"></typeparam>
</member>
<member name="T:BrightData.Buffer.Operations.Helper.TypedIndexer`1">
<member name="T:BrightData.Buffer.Operations.Conversion.TypedIndexer`1">
<summary>
Maintains a mapping of types to indices
</summary>
Expand Down Expand Up @@ -1605,7 +1605,7 @@
<member name="P:BrightData.DataTable.Columns.Tensor4DColumnType.Size">
<inheritdoc />
</member>
<member name="T:BrightData.DataTable.ConstraintValidation.ColumnFilter`1">
<member name="T:BrightData.DataTable.Meta.ColumnFilter`1">
<summary>

</summary>
Expand All @@ -1615,7 +1615,7 @@
<param name="filter"></param>
<param name="nonConformingRowIndices"></param>
</member>
<member name="M:BrightData.DataTable.ConstraintValidation.ColumnFilter`1.#ctor(System.UInt32,BrightData.BrightDataType,BrightData.IDataTypeSpecification{`0},System.Collections.Generic.HashSet{System.UInt32})">
<member name="M:BrightData.DataTable.Meta.ColumnFilter`1.#ctor(System.UInt32,BrightData.BrightDataType,BrightData.IDataTypeSpecification{`0},System.Collections.Generic.HashSet{System.UInt32})">
<summary>

</summary>
Expand All @@ -1625,19 +1625,19 @@
<param name="filter"></param>
<param name="nonConformingRowIndices"></param>
</member>
<member name="T:BrightData.DataTable.ConstraintValidation.DataTableSpecification">
<member name="T:BrightData.DataTable.Meta.DataTableSpecification">
<summary>
Data table specification
</summary>
<param name="dataTable"></param>
</member>
<member name="M:BrightData.DataTable.ConstraintValidation.DataTableSpecification.#ctor(BrightData.IDataTable)">
<member name="M:BrightData.DataTable.Meta.DataTableSpecification.#ctor(BrightData.IDataTable)">
<summary>
Data table specification
</summary>
<param name="dataTable"></param>
</member>
<member name="T:BrightData.DataTable.ConstraintValidation.DataTypeSpecificationBase`1">
<member name="T:BrightData.DataTable.Meta.DataTypeSpecificationBase`1">
<summary>
Data type specification base
</summary>
Expand All @@ -1647,7 +1647,7 @@
<param name="canRepeat"></param>
<param name="children"></param>
</member>
<member name="M:BrightData.DataTable.ConstraintValidation.DataTypeSpecificationBase`1.#ctor(System.String,BrightData.DataSpecificationType,System.Boolean,BrightData.IDataTypeSpecification[])">
<member name="M:BrightData.DataTable.Meta.DataTypeSpecificationBase`1.#ctor(System.String,BrightData.DataSpecificationType,System.Boolean,BrightData.IDataTypeSpecification[])">
<summary>
Data type specification base
</summary>
Expand All @@ -1657,62 +1657,62 @@
<param name="canRepeat"></param>
<param name="children"></param>
</member>
<member name="T:BrightData.DataTable.ConstraintValidation.FieldSpecification`1">
<member name="T:BrightData.DataTable.Meta.FieldSpecification`1">
<summary>
Field specification
</summary>
<typeparam name="T"></typeparam>
<param name="name"></param>
<param name="canRepeat"></param>
</member>
<member name="M:BrightData.DataTable.ConstraintValidation.FieldSpecification`1.#ctor(System.String,System.Boolean)">
<member name="M:BrightData.DataTable.Meta.FieldSpecification`1.#ctor(System.String,System.Boolean)">
<summary>
Field specification
</summary>
<typeparam name="T"></typeparam>
<param name="name"></param>
<param name="canRepeat"></param>
</member>
<member name="T:BrightData.DataTable.ConstraintValidation.ThrowOnInvalidConstraint`1">
<summary>
Throws an exception if a constraint fails validation
</summary>
<typeparam name="T"></typeparam>
<param name="predicate"></param>
</member>
<member name="M:BrightData.DataTable.ConstraintValidation.ThrowOnInvalidConstraint`1.#ctor(BrightData.DataTable.ConstraintValidation.ThrowOnInvalidConstraint{`0}.Predicate)">
<summary>
Throws an exception if a constraint fails validation
</summary>
<typeparam name="T"></typeparam>
<param name="predicate"></param>
</member>
<member name="T:BrightData.DataTable.Helper.TableDataDimension">
<member name="T:BrightData.DataTable.Meta.TableDataDimension">
<summary>
A data dimension from a table
</summary>
<param name="dataType"></param>
<param name="buffer"></param>
</member>
<member name="M:BrightData.DataTable.Helper.TableDataDimension.#ctor(BrightData.BrightDataType,BrightData.IReadOnlyBuffer)">
<member name="M:BrightData.DataTable.Meta.TableDataDimension.#ctor(BrightData.BrightDataType,BrightData.IReadOnlyBuffer)">
<summary>
A data dimension from a table
</summary>
<param name="dataType"></param>
<param name="buffer"></param>
</member>
<member name="P:BrightData.DataTable.Helper.TableDataDimension.DataType">
<member name="P:BrightData.DataTable.Meta.TableDataDimension.DataType">
<inheritdoc />
</member>
<member name="M:BrightData.DataTable.Helper.TableDataDimension.GetBuffer``1">
<member name="M:BrightData.DataTable.Meta.TableDataDimension.GetBuffer``1">
<inheritdoc />
</member>
<member name="P:BrightData.DataTable.Helper.TableDataDimension.Specification">
<member name="P:BrightData.DataTable.Meta.TableDataDimension.Specification">
<inheritdoc />
</member>
<member name="P:BrightData.DataTable.Helper.TableDataDimension.Size">
<member name="P:BrightData.DataTable.Meta.TableDataDimension.Size">
<inheritdoc />
</member>
<member name="T:BrightData.DataTable.Meta.ThrowOnInvalidConstraint`1">
<summary>
Throws an exception if a constraint fails validation
</summary>
<typeparam name="T"></typeparam>
<param name="predicate"></param>
</member>
<member name="M:BrightData.DataTable.Meta.ThrowOnInvalidConstraint`1.#ctor(BrightData.DataTable.Meta.ThrowOnInvalidConstraint{`0}.Predicate)">
<summary>
Throws an exception if a constraint fails validation
</summary>
<typeparam name="T"></typeparam>
<param name="predicate"></param>
</member>
<member name="T:BrightData.DataTable.Rows.GenericTableRow">
<summary>
Generic table row - column types are not specified
Expand Down Expand Up @@ -10148,15 +10148,13 @@
Returns a list of vector indices ranked by the distance between that vector and a comparison vector
</summary>
<param name="vector">Vector to compare</param>
<param name="distanceMetric"></param>
<returns></returns>
</member>
<member name="M:BrightData.IVectorIndex`1.Closest(System.ReadOnlyMemory{`0}[])">
<summary>
Returns the index of the closest vector in the set to each of the supplied vectors
</summary>
<param name="vector">Vectors to compare</param>
<param name="distanceMetric"></param>
<returns></returns>
</member>
<member name="T:BrightData.ISupportKnnSearch`1">
Expand Down Expand Up @@ -18237,6 +18235,9 @@
<param name="index">Index of element to remove</param>
<exception cref="T:System.ArgumentOutOfRangeException"></exception>
</member>
<member name="P:BrightData.Types.Graph.DirectedGraph`1.Size">
<inheritdoc />
</member>
<member name="T:BrightData.Types.Graph.FixedSizeWeightedDynamicGraph`3">
<summary>
A fixed size weighted graph
Expand Down
1 change: 0 additions & 1 deletion BrightData/ExtensionMethods.TensorSegment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BrightData.Helper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
4 changes: 0 additions & 4 deletions BrightData/Interfaces.DataDimensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrightData
{
Expand Down
3 changes: 0 additions & 3 deletions BrightData/Interfaces.Graphs.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
1 change: 0 additions & 1 deletion BrightData/Interfaces.LinearAlgebra.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using BrightData.Helper;
using BrightData.LinearAlgebra;
using CommunityToolkit.HighPerformance.Buffers;

Expand Down
2 changes: 0 additions & 2 deletions BrightData/Interfaces.VectorIndexing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,13 @@ public interface IVectorIndex<T> : IDisposable
/// Returns a list of vector indices ranked by the distance between that vector and a comparison vector
/// </summary>
/// <param name="vector">Vector to compare</param>
/// <param name="distanceMetric"></param>
/// <returns></returns>
IEnumerable<uint> Rank(ReadOnlySpan<T> vector);

/// <summary>
/// Returns the index of the closest vector in the set to each of the supplied vectors
/// </summary>
/// <param name="vector">Vectors to compare</param>
/// <param name="distanceMetric"></param>
/// <returns></returns>
uint[] Closest(ReadOnlyMemory<T>[] vector);
}
Expand Down
19 changes: 17 additions & 2 deletions BrightData/Types/Graph/DirectedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

namespace BrightData.Types.Graph
{
public record struct DirectedGraph<T> : IHaveDataAsReadOnlyByteSpan, IHaveSize
where T: struct, IHaveSingleIndex
/// <summary>
/// Directed graph
/// </summary>
/// <typeparam name="T"></typeparam>
public readonly record struct DirectedGraph<T> : IHaveDataAsReadOnlyByteSpan, IHaveSize
where T: unmanaged, IHaveSingleIndex
{
const int HeaderSize = 8;

Expand Down Expand Up @@ -57,6 +61,12 @@ ReadOnlySpan<byte> IHaveDataAsReadOnlyByteSpan.DataAsBytes
}
}

/// <summary>
/// Returns the value associated with the node
/// </summary>
/// <param name="nodeIndex"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryGetValue(uint nodeIndex, [NotNullWhen(true)]out T? value)
{
var nodeSpan = _nodes.AsSpan();
Expand All @@ -69,6 +79,11 @@ public bool TryGetValue(uint nodeIndex, [NotNullWhen(true)]out T? value)
return true;
}

/// <summary>
/// Enumerates the connected nodes from a single node
/// </summary>
/// <param name="nodeIndex"></param>
/// <returns></returns>
public IEnumerable<T> EnumerateConnectedNodes(uint nodeIndex)
{
var nodeSpan = _nodes.AsSpan();
Expand Down
26 changes: 21 additions & 5 deletions BrightData/Types/Graph/DirectedGraphBuilder.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Builds a directed graph
/// </summary>
/// <typeparam name="T"></typeparam>
public class DirectedGraphBuilder<T>
where T: struct, IHaveSingleIndex
where T: unmanaged, IHaveSingleIndex
{
class Node(T value, int nodeOffset)
{
Expand All @@ -26,13 +27,24 @@ public void AddEdge(int toNodeOffset)
}
readonly Dictionary<uint /* node index */, Node> _nodes = new();

/// <summary>
/// Add a new node
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
public uint Add(T node)
{
var nodeIndex = node.Index;
_nodes.Add(nodeIndex, new Node(node, _nodes.Count));
return nodeIndex;
}

/// <summary>
/// Adds an edge between two nodes
/// </summary>
/// <param name="fromNodeIndex"></param>
/// <param name="toNodeIndex"></param>
/// <returns></returns>
public bool AddEdge(uint fromNodeIndex, uint toNodeIndex)
{
if (_nodes.TryGetValue(fromNodeIndex, out var from) && _nodes.TryGetValue(toNodeIndex, out var to)) {
Expand All @@ -43,6 +55,10 @@ public bool AddEdge(uint fromNodeIndex, uint toNodeIndex)
return false;
}

/// <summary>
/// Builds the graph
/// </summary>
/// <returns></returns>
public DirectedGraph<T> Build()
{
using var nodes = new ArrayPoolBufferWriter<DirectedGraph<T>.Node>();
Expand Down

0 comments on commit a1ba951

Please sign in to comment.