project update
This commit is contained in:
63
Modules/ComputationalModules/Binary/AdditionModule.cs
Normal file
63
Modules/ComputationalModules/Binary/AdditionModule.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class AdditionModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports =>
|
||||
base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public override double MaintenanceAlpha => 0.19572021d;
|
||||
public override double MaintenanceBeta => 0.20151779d;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
InputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyTensor
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider!.Add(input1, input2, OutputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup!.SelectedType = OutputGroup!.SelectedType;
|
||||
|
||||
public override string GetDescription => GlobalProvider.EnigmosProvider.ModuleDescription<AdditionModule>();
|
||||
}
|
||||
36
Modules/ComputationalModules/Binary/ComparisionModule.cs
Normal file
36
Modules/ComputationalModules/Binary/ComparisionModule.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ComparisionModule : BinaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
|
||||
private DataOutPort? Output { get; set; }
|
||||
private IBoolParameter Greater { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output });
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Greater = GlobalProvider.DataStructureProvider.NewBoolParameter("Method", "gt", "lt", true);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter>() { Greater };
|
||||
Output = GetPort<DataOutPort>("Output");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
Output!.ResultData.Bit = !(Greater.ParameterValue ^ (input1.Real > input2.Real));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ControlledOutputModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
[Export] private StringName PresetDataType { get; set; }
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
private DataOutPort Output4 { get; set; }
|
||||
private IDataPortGroup OutputGroup { get; set; }
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 });
|
||||
public void Inference() => Input2.SetDataType(OutputGroup.SelectedType);
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Data Type",
|
||||
UsingPreset ? PresetDataType : EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
if (input1.Bit)
|
||||
foreach (DataOutPort port in OutputGroup.OfType<DataOutPort>())
|
||||
port.ResultData.Assign(input2, OutputGroup.SelectedType);
|
||||
else
|
||||
foreach (DataOutPort port in OutputGroup.OfType<DataOutPort>())
|
||||
port.ResultData.Assign(
|
||||
GlobalProvider.DataStructureProvider.DefaultDataPackage,
|
||||
OutputGroup.SelectedType
|
||||
);
|
||||
}
|
||||
}
|
||||
61
Modules/ComputationalModules/Binary/DivisionModule.cs
Normal file
61
Modules/ComputationalModules/Binary/DivisionModule.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class DivisionModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Div(input1, input2, OutputGroup.SelectedType);
|
||||
foreach (DataPort port in OutputGroup)
|
||||
{
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
//(port as DataOutPort)!.DataUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
|
||||
}
|
||||
65
Modules/ComputationalModules/Binary/DotProductModule.cs
Normal file
65
Modules/ComputationalModules/Binary/DotProductModule.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class DotProductModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? VectorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
VectorInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"Vector Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { VectorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider!.Dot(input1, input2, VectorInputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
if (GlobalProvider.DataPackageTypeProvider!.IsComplexTensorType(VectorInputGroup!.SelectedType))
|
||||
OutputGroup!.SelectedType = EnigmosConstant.DataPortTypes.Complex;
|
||||
else
|
||||
OutputGroup!.SelectedType = EnigmosConstant.DataPortTypes.Real;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalAlternativeDenialModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !input1.Bit | !input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalBiconditionalModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !(input1.Bit ^ input2.Bit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalConjunctionModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit & input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalDisjunctionModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit | input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalExclusiveDisjunctionModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit ^ input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalImplicationModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !input1.Bit | input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalJointDenialModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = !input1.Bit & !input2.Bit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class LogicalNonimplicationModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
//Output1.DataUpdated = true;
|
||||
Output1.ResultData.Bit = input1.Bit & !input2.Bit;
|
||||
}
|
||||
}
|
||||
44
Modules/ComputationalModules/Binary/MaxModule.cs
Normal file
44
Modules/ComputationalModules/Binary/MaxModule.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class MaxModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
if (input1.Real > input2.Real)
|
||||
{
|
||||
Output1.ResultData.Real = input1.Real;
|
||||
Output2.ResultData.Real = input1.Real;
|
||||
Output3.ResultData.Real = input1.Real;
|
||||
}
|
||||
else
|
||||
{
|
||||
Output1.ResultData.Real = input2.Real;
|
||||
Output2.ResultData.Real = input2.Real;
|
||||
Output3.ResultData.Real = input2.Real;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
44
Modules/ComputationalModules/Binary/MinModule.cs
Normal file
44
Modules/ComputationalModules/Binary/MinModule.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class MinModule : BinaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
if (input1.Real < input2.Real)
|
||||
{
|
||||
Output1.ResultData.Real = input1.Real;
|
||||
Output2.ResultData.Real = input1.Real;
|
||||
Output3.ResultData.Real = input1.Real;
|
||||
}
|
||||
else
|
||||
{
|
||||
Output1.ResultData.Real = input2.Real;
|
||||
Output2.ResultData.Real = input2.Real;
|
||||
Output3.ResultData.Real = input2.Real;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
56
Modules/ComputationalModules/Binary/MultiplicationModule.cs
Normal file
56
Modules/ComputationalModules/Binary/MultiplicationModule.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class MultiplicationModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup InputGroup { get; set; }
|
||||
private IDataPortGroup OutputGroup { get; set; }
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
private DataOutPort Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 });
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Mul(input1, input2, OutputGroup.SelectedType);
|
||||
foreach (DataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
|
||||
}
|
||||
63
Modules/ComputationalModules/Binary/PowerModule.cs
Normal file
63
Modules/ComputationalModules/Binary/PowerModule.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class PowerModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? TensorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
TensorInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Base Tensor Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
Input2.SetDataType(EnigmosConstant.DataPortTypes.Complex);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { TensorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider!.Pow(input1, input2, TensorInputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
{
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
//(port as DataOutPort)!.DataUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inference() =>
|
||||
OutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider!.ComplexVersionOf(TensorInputGroup.SelectedType);
|
||||
|
||||
}
|
||||
123
Modules/ComputationalModules/Binary/ScalarDivisionModule.cs
Normal file
123
Modules/ComputationalModules/Binary/ScalarDivisionModule.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ScalarDivisionModule : BinaryComputationalModule, IPolymorphismModule, IErrorHandlerModule
|
||||
{
|
||||
private IDataPortGroup? ScalarInputGroup { get; set; }
|
||||
private IDataPortGroup? TensorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public override double MaintenanceAlpha => 0.77852142d;
|
||||
public override double MaintenanceBeta => 0.9544432d;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
TensorInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Tensor Input Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
ScalarInputGroup =GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input2 },
|
||||
"Scalar Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup, TensorInputGroup };
|
||||
SelectedOption = 0;
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
try
|
||||
{
|
||||
IDataPackage res =
|
||||
GlobalProvider.PolymorphismProvider!.ScalarDiv(
|
||||
input1,
|
||||
input2,
|
||||
TensorInputGroup!.SelectedType,
|
||||
ScalarInputGroup!.SelectedType
|
||||
);
|
||||
foreach (IDataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHandler(e, SelectedOption);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
if (GlobalProvider.DataPackageTypeProvider.IsComplexTensorType(ScalarInputGroup.SelectedType))
|
||||
OutputGroup.SelectedType = GlobalProvider.DataPackageTypeProvider.ComplexVersionOf(TensorInputGroup.SelectedType);
|
||||
else
|
||||
OutputGroup.SelectedType = TensorInputGroup.SelectedType;
|
||||
}
|
||||
|
||||
public void ErrorHandler(Exception error, int idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData
|
||||
.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, OutputGroup.SelectedType);
|
||||
break;
|
||||
case 1:
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData
|
||||
.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, OutputGroup.SelectedType);
|
||||
break;
|
||||
case 2:
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData
|
||||
.Assign(GlobalProvider.DataStructureProvider!.DefaultDataPackage, OutputGroup.SelectedType);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] HandlingOptions() =>
|
||||
new[]
|
||||
{
|
||||
"Reset Circuit State",
|
||||
"Return Previous Valid Value",
|
||||
"Return Default Value"
|
||||
};
|
||||
|
||||
public int SelectedOption { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class ScalarMultiplicationModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? ScalarInputGroup { get; set; }
|
||||
private IDataPortGroup? TensorInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
ScalarInputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Scalar Input Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
TensorInputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input2 },
|
||||
"Tensor Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup, TensorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res =
|
||||
GlobalProvider.PolymorphismProvider!
|
||||
.ScalarMul(input1, input2, ScalarInputGroup!.SelectedType, TensorInputGroup!.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
if (
|
||||
GlobalProvider.DataPackageTypeProvider!.IsComplexTensorType(ScalarInputGroup!.SelectedType) ||
|
||||
GlobalProvider.DataPackageTypeProvider.IsComplexTensorType(TensorInputGroup!.SelectedType)
|
||||
)
|
||||
OutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider.ComplexVersionOf(TensorInputGroup!.SelectedType);
|
||||
else
|
||||
OutputGroup!.SelectedType = TensorInputGroup.SelectedType;
|
||||
}
|
||||
|
||||
}
|
||||
58
Modules/ComputationalModules/Binary/SubtractionModule.cs
Normal file
58
Modules/ComputationalModules/Binary/SubtractionModule.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class SubtractionModule : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup InputGroup { get; set; }
|
||||
private IDataPortGroup OutputGroup { get; set; }
|
||||
private DataOutPort Output1 { get; set; }
|
||||
private DataOutPort Output2 { get; set; }
|
||||
private DataOutPort Output3 { get; set; }
|
||||
private DataOutPort Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 });
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyTensor
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Sub(input1, input2, OutputGroup.SelectedType);
|
||||
foreach (DataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
|
||||
}
|
||||
70
Modules/ComputationalModules/Binary/V2Module.cs
Normal file
70
Modules/ComputationalModules/Binary/V2Module.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
using R2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVector;
|
||||
using C2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<System.Numerics.Complex>.FVector;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Binary;
|
||||
|
||||
public partial class V2Module : BinaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? ScalarInputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public override double MaintenanceAlpha => 0.77852142d;
|
||||
public override double MaintenanceBeta => 0.9544432d;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
ScalarInputGroup = GlobalProvider.DataStructureProvider!.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1, Input2 },
|
||||
"Scalar Input Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2)
|
||||
{
|
||||
R2 v2R = new R2(input1.Real, input2.Real);
|
||||
C2 v2C = new C2(input1.Complex, input2.Complex);
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
{
|
||||
if (ScalarInputGroup!.SelectedType == EnigmosConstant.DataPortTypes.Real)
|
||||
(port as DataOutPort)!.ResultData.R2 = v2R;
|
||||
else
|
||||
(port as DataOutPort)!.ResultData.C2 = v2C;
|
||||
}
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
OutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider!.BuildType(OutputGroup.SelectedType, 1, 2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
@@ -20,6 +21,6 @@ public abstract partial class BinaryComputationalModule : ComputationalModule
|
||||
|
||||
|
||||
protected abstract void Compute(IDataPackage input1, IDataPackage input2);
|
||||
protected override void Compute(RootModule root) => Compute(Input1.GetData(root), Input2.GetData(root));
|
||||
protected override void Compute(IRootModule root) => Compute(Input1.GetData(root), Input2.GetData(root));
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Enigmos.Exceptions;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
@@ -13,8 +14,8 @@ public abstract partial class ComputationalModule : BaseModule
|
||||
base.TimeoutHandler(timeout);
|
||||
}
|
||||
|
||||
protected abstract void Compute(RootModule root);
|
||||
public void ComputeWithTimeoutHandle(RootModule root)
|
||||
protected abstract void Compute(IRootModule root);
|
||||
public void ComputeWithTimeoutHandle(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in Ports.OfType<DataOutPort>())
|
||||
port.DataUpdated = true;
|
||||
|
||||
54
Modules/ComputationalModules/Nullary/ConstantModule.cs
Normal file
54
Modules/ComputationalModules/Nullary/ConstantModule.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class ConstantModule : NullaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
|
||||
[Export] private double PresetConstantValue { get; set; }
|
||||
|
||||
private HashSet<DataOutPort> OutputGroup { get; set; } = new();
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
private IDoubleParameter ConstValue { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
ConstValue =
|
||||
GlobalProvider.DataStructureProvider.NewDoubleParameter(
|
||||
"Constant Value",
|
||||
-1,
|
||||
1,
|
||||
UsingPreset ? PresetConstantValue : 0
|
||||
);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { ConstValue };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.ResultData.Real = ConstValue.ParameterValue;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
51
Modules/ComputationalModules/Nullary/KeyListenerModule.cs
Normal file
51
Modules/ComputationalModules/Nullary/KeyListenerModule.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
public partial class KeyListenerModule : NullaryComputationalModule, IParameterizedModule, IKeyListenerModule
|
||||
{
|
||||
[Export] private StringName? PresetActionName { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
public IKeyParameter? ListeningKey { get; set; }
|
||||
public bool Pressed { get; set; }
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
public override IEnumerable<BasePort> Ports => new[] { Output1, Output2, Output3 }!;
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
Output1!.ResultData.Bit = Pressed;
|
||||
Output2!.ResultData.Bit = Pressed;
|
||||
Output3!.ResultData.Bit = Pressed;
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
ListeningKey = GlobalProvider.DataStructureProvider!.NewKeyParameter(
|
||||
"Listening Key",
|
||||
UsingPreset && (PresetActionName != null) ? PresetActionName : "KeyListenAction"
|
||||
);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { ListeningKey };
|
||||
int i = 0;
|
||||
while (InputMap.HasAction($"{ListeningKey.ParameterValue}{i}") && !UsingPreset)
|
||||
i++;
|
||||
ListeningKey.ParameterValue = $"{ListeningKey.ParameterValue}{i}";
|
||||
if(!UsingPreset)
|
||||
InputMap.AddAction(ListeningKey.ParameterValue);
|
||||
GlobalProvider.SceneProvider!.RootScene.KeyListener.Register(this);
|
||||
PostInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Skeleton.Utils.RandomEngines;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class NormalDistributionModule : NullaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
private HashSet<DataOutPort> OutputGroup { get; set; } = new();
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
private IDoubleParameter? Mu { get; set; }
|
||||
private IDoubleParameter? Sigma { get; set; }
|
||||
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Mu = GlobalProvider.DataStructureProvider!.NewDoubleParameter("mu", -1, 1, 0);
|
||||
Sigma = GlobalProvider.DataStructureProvider.NewDoubleParameter("sigma", 0, 2, 1);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { Mu, Sigma };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
{
|
||||
port.ResultData.Real = Normal.Get() * Sigma.ParameterValue - Mu.ParameterValue;
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
public abstract partial class QuaternaryComputationalModule : ComputationalModule
|
||||
{
|
||||
protected DataInPort Input1 { get; set; }
|
||||
protected DataInPort Input2 { get; set; }
|
||||
protected DataInPort Input3 { get; set; }
|
||||
protected DataInPort Input4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3, Input4 };
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Input1 = GetPort<DataInPort>("Input1");
|
||||
Input2 = GetPort<DataInPort>("Input2");
|
||||
Input3 = GetPort<DataInPort>("Input3");
|
||||
Input4 = GetPort<DataInPort>("Input4");
|
||||
}
|
||||
|
||||
|
||||
protected abstract void Compute(IDataPackage input1, IDataPackage input2, IDataPackage input3, IDataPackage input4);
|
||||
|
||||
protected override void Compute(RootModule root) =>
|
||||
Compute(Input1.GetData(root), Input2.GetData(root), Input3.GetData(root), Input4.GetData(root));
|
||||
}
|
||||
46
Modules/ComputationalModules/Ternary/SelectorModule.cs
Normal file
46
Modules/ComputationalModules/Ternary/SelectorModule.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Ternary;
|
||||
|
||||
public partial class SelectorModule : TernaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private IDataPortGroup? DataTypeGroup { get; set; }
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3 })!;
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
DataTypeGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Input2, Input3, Output1, Output2, Output3 },
|
||||
"Data Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1, IDataPackage input2, IDataPackage input3)
|
||||
{
|
||||
|
||||
Output1!.ResultData.Assign(input1.Bit ? input2 : input3, DataTypeGroup.SelectedType);
|
||||
Output2!.ResultData.Assign(input1.Bit ? input2 : input3, DataTypeGroup.SelectedType);
|
||||
Output3!.ResultData.Assign(input1.Bit ? input2 : input3, DataTypeGroup.SelectedType);
|
||||
}
|
||||
|
||||
public void Inference()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,16 @@ using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
public abstract partial class TernaryComputationalModule : ComputationalModule
|
||||
{
|
||||
protected DataInPort Input1 { get; set; }
|
||||
protected DataInPort Input2 { get; set; }
|
||||
protected DataInPort Input3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3 };
|
||||
protected DataInPort? Input1 { get; set; }
|
||||
protected DataInPort? Input2 { get; set; }
|
||||
protected DataInPort? Input3 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3 }!;
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
@@ -21,6 +22,6 @@ public abstract partial class TernaryComputationalModule : ComputationalModule
|
||||
|
||||
protected abstract void Compute(IDataPackage input1, IDataPackage input2, IDataPackage input3);
|
||||
|
||||
protected override void Compute(RootModule root) =>
|
||||
protected override void Compute(IRootModule root) =>
|
||||
Compute(Input1.GetData(root), Input2.GetData(root), Input3.GetData(root));
|
||||
}
|
||||
56
Modules/ComputationalModules/Unary/CopyModule.cs
Normal file
56
Modules/ComputationalModules/Unary/CopyModule.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
public partial class CopyModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] {Input1},
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyType
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
foreach (IDataPort port in OutputGroup!)
|
||||
(port as DataOutPort)!.ResultData.Assign(input1, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup!.SelectedType = OutputGroup!.SelectedType;
|
||||
|
||||
}
|
||||
26
Modules/ComputationalModules/Unary/LogicalNegationModule.cs
Normal file
26
Modules/ComputationalModules/Unary/LogicalNegationModule.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class LogicalNegationModule : UnaryComputationalModule
|
||||
{
|
||||
private DataOutPort Output1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1 });
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Input1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
Output1.ResultData.Bit = !input1.Bit;
|
||||
}
|
||||
|
||||
}
|
||||
58
Modules/ComputationalModules/Unary/NegationModule.cs
Normal file
58
Modules/ComputationalModules/Unary/NegationModule.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class NegationModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] {Input1},
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.AnyTensor
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Neg(input1, OutputGroup.SelectedType);
|
||||
foreach (IDataPort port in OutputGroup)
|
||||
(port as DataOutPort)!.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup.SelectedType = OutputGroup.SelectedType;
|
||||
}
|
||||
60
Modules/ComputationalModules/Unary/SquareModule.cs
Normal file
60
Modules/ComputationalModules/Unary/SquareModule.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class SquareModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
private IDataPortGroup? InputGroup { get; set; }
|
||||
private IDataPortGroup? OutputGroup { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
InputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] {Input1},
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
OutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new DataPort[] { Output1, Output2, Output3, Output4 },
|
||||
"Output Port Type",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
EnigmosConstant.DataPortTypes.NumericTypes
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { OutputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
IDataPackage res = GlobalProvider.PolymorphismProvider.Square(input1, OutputGroup.SelectedType);
|
||||
foreach (DataOutPort port in OutputGroup.OfType<DataOutPort>())
|
||||
port.ResultData.Assign(res, OutputGroup.SelectedType);
|
||||
|
||||
}
|
||||
|
||||
public void Inference() => InputGroup!.SelectedType = OutputGroup!.SelectedType;
|
||||
|
||||
}
|
||||
61
Modules/ComputationalModules/Unary/V2ComponentModule.cs
Normal file
61
Modules/ComputationalModules/Unary/V2ComponentModule.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Unary;
|
||||
|
||||
public partial class V2ComponentModule : UnaryComputationalModule, IPolymorphismModule
|
||||
{
|
||||
private IDataPortGroup? VectorInputGroup { get; set; }
|
||||
private IDataPortGroup? ScalarOutputGroup { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2 })!;
|
||||
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
VectorInputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Input1 },
|
||||
"Vector Input Type",
|
||||
EnigmosConstant.DataPortTypes.R2,
|
||||
EnigmosConstant.DataPortTypes.VectorTypes
|
||||
);
|
||||
ScalarOutputGroup = GlobalProvider.DataStructureProvider.NewDataPortGroup(
|
||||
this,
|
||||
new IDataPort[] { Output1, Output2 },
|
||||
"",
|
||||
EnigmosConstant.DataPortTypes.Real,
|
||||
Array.Empty<StringName>()
|
||||
);
|
||||
ConfigurablePortGroups = new HashSet<IDataPortGroup> { VectorInputGroup };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IDataPackage input1)
|
||||
{
|
||||
if (VectorInputGroup!.SelectedType == EnigmosConstant.DataPortTypes.R2)
|
||||
{
|
||||
Output1!.ResultData.Real = input1.R2[1];
|
||||
Output2!.ResultData.Real = input1.R2[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
Output1!.ResultData.Complex = input1.C2[1];
|
||||
Output2!.ResultData.Complex = input1.C2[2];
|
||||
}
|
||||
}
|
||||
public void Inference() =>
|
||||
ScalarOutputGroup!.SelectedType = GlobalProvider.DataPackageTypeProvider!.GetBaseField(VectorInputGroup.SelectedType);
|
||||
|
||||
}
|
||||
@@ -2,13 +2,14 @@ using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules;
|
||||
|
||||
public abstract partial class UnaryComputationalModule : ComputationalModule
|
||||
{
|
||||
protected DataInPort Input1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1 };
|
||||
protected DataInPort? Input1 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => new[] { Input1 }!;
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
@@ -16,5 +17,5 @@ public abstract partial class UnaryComputationalModule : ComputationalModule
|
||||
}
|
||||
|
||||
protected abstract void Compute(IDataPackage input1);
|
||||
protected override void Compute(RootModule root) => Compute(Input1.GetData(root));
|
||||
protected override void Compute(IRootModule root) => Compute(Input1.GetData(root));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user