private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (this.SaveRequested == null) { MessageBox.Show("There is no listener to the save event", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (_kernels.Count == 0) { MessageBox.Show("You need to add kernels before saving", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } SetOperationType operation = (SetOperationType)cboPostOperation.SelectedValue; if (operation == SetOperationType.MaxOf) { if (_kernels.Count < 2) { MessageBox.Show("MaxOf needs at least two children", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } VectorInt firstReduce = _kernels[0].GetReduction(); for (int cntr = 1; cntr < _kernels.Count; cntr++) { VectorInt nextReduce = _kernels[cntr].GetReduction(); if (firstReduce != nextReduce) { MessageBox.Show("When the operation is MaxOf, then all kernels must reduce the same amount", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } } } ConvolutionSet2D set = new ConvolutionSet2D(_kernels.ToArray(), operation); this.SaveRequested(this, set); } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public static bool GetResult(HashSet <T> expectedValues, SetOperationType opType, bool expectedResult, T inValue) { switch (opType) { case SetOperationType.Overlaps: case SetOperationType.SupersetOf: return(expectedResult == expectedValues.Contains(inValue)); case SetOperationType.EqualTo: case SetOperationType.SubsetOf: return(expectedResult == (expectedValues.Count == 1 && expectedValues.Contains(inValue))); default: throw new ArgumentOutOfRangeException(nameof(opType), opType, null); } }
public static bool GetResult(HashSet <T> expectedValues, SetOperationType opType, bool expectedResult, IEnumerable <T> inValues) { switch (opType) { case SetOperationType.Overlaps: return(expectedResult == expectedValues.Overlaps(inValues)); case SetOperationType.SupersetOf: return(expectedResult == expectedValues.IsSupersetOf(inValues)); case SetOperationType.EqualTo: return(expectedResult == expectedValues.SetEquals(inValues)); case SetOperationType.SubsetOf: return(expectedResult == expectedValues.IsSubsetOf(inValues)); default: throw new ArgumentOutOfRangeException(nameof(opType), opType, null); } }
private static string GenerateSetOperationType(SetOperationType setOperationType) => setOperationType switch {
public ConvolutionSet2D(ConvolutionBase2D[] convolutions, SetOperationType operationType, string description = "") { foreach (object child in convolutions) { if (!(child is Convolution2D) && !(child is ConvolutionSet2D)) { throw new ArgumentException("Object passed in must be Convolution2D or ConvolutionSet2D: " + child.GetType().ToString()); } } this.Convolutions = convolutions; this.OperationType = operationType; _description = description; }
public SetOperator(LogicalOperator leftOp, LogicalOperator rightOp, SetOperationType setOpType) { SetOperation = setOpType; SetInOperators(leftOp, rightOp); }