71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using Nocturnis.DataStructures.DataPortGroups;
|
|
using Nocturnis.DataStructures.DataTypes;
|
|
using Nocturnis.Enigmos.Modules;
|
|
using Nocturnis.Enigmos.Modules.ComputationalModules;
|
|
using Nocturnis.Enigmos.Ports.DataPorts.Directions;
|
|
using Nocturnis.GlobalManagement.Constants;
|
|
using Nocturnis.GlobalManagement.Providers;
|
|
using Skeleton.DataStructure;
|
|
|
|
namespace Enigmos.Modules.ComputationalModules.Binary;
|
|
|
|
public abstract partial class ScalarMultiplicationModule :
|
|
BinaryComputationalModule,
|
|
IPolymorphismModule,
|
|
IDuplicateOutputModule
|
|
{
|
|
private IDataPortGroup? ScalarInputGroup { get; set; }
|
|
private IDataPortGroup? TensorInputGroup { get; set; }
|
|
private IDataPortGroup? OutputGroup { get; set; }
|
|
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
this.DataOutInit("Output",4);
|
|
ScalarInputGroup = GlobalProvider.DataStructureProvider!.NewDataInGroup(
|
|
this,
|
|
new IDataInPort[] { DataInPorts[0] },
|
|
"Scalar Input Type",
|
|
DataTypeConstant.BaseDataTypes.Real,
|
|
DataTypeConstant.DataTypeOptions.ScalarTypes
|
|
);
|
|
TensorInputGroup = GlobalProvider.DataStructureProvider.NewDataInGroup(
|
|
this,
|
|
new IDataInPort[] { DataInPorts[1] },
|
|
"Tensor Input Type",
|
|
DataTypeConstant.BaseDataTypes.R2,
|
|
DataTypeConstant.DataTypeOptions.VectorTypes
|
|
);
|
|
OutputGroup = GlobalProvider.DataStructureProvider.NewDataOutGroup(
|
|
this,
|
|
DataOutPorts,
|
|
"",
|
|
DataTypeConstant.BaseDataTypes.Real,
|
|
DataTypeConstant.DataTypeOptions.VectorTypes
|
|
);
|
|
ConfigurablePortGroups = new HashSet<IDataPortGroup> { ScalarInputGroup, TensorInputGroup };
|
|
PostInit();
|
|
}
|
|
|
|
|
|
public override void Define()
|
|
{
|
|
(object, DataType) Func(CacheItem cache) =>
|
|
GlobalProvider.PolymorphismProvider!.ScalarMul(this.X(cache), this.Y(cache));
|
|
this.Define(Func);
|
|
}
|
|
|
|
public void Inference()
|
|
{
|
|
if (
|
|
GlobalProvider.DataTypeProvider!.IsComplexTensorType(ScalarInputGroup!.SelectedType) ||
|
|
GlobalProvider.DataTypeProvider.IsComplexTensorType(TensorInputGroup!.SelectedType)
|
|
)
|
|
OutputGroup!.SelectedType = GlobalProvider.DataTypeProvider.ComplexVersionOf(TensorInputGroup!.SelectedType);
|
|
else
|
|
OutputGroup!.SelectedType = TensorInputGroup.SelectedType;
|
|
}
|
|
}
|
|
|