protected override void SetVariables(ATypes type) { this.type = ATypes.AInteger; this.fillerElement = AInteger.Create(1); this.function = DyadicFunctionInstance.And; }
public void IdentityBoxUni() { AType expected = ABox.Create(AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(2), AInteger.Create(3))); AType result = this.engineUni.Execute <AType>("+ <1 2 3"); Assert.AreEqual(expected, result); }
public void UnmappingBecauseIndex2() { AType expected = AArray.Create(ATypes.AInteger, AInteger.Create(5), AInteger.Create(6), AInteger.Create(7)); ScriptScope scope = this.engine.CreateScope(); this.engine.Execute<AType>(string.Format("a := 1 beam `{0}", MappedFiles.IntegerMatrix.GetFileName()), scope); this.engine.Execute<AType>("c := a[0]", scope); this.engine.Execute<AType>("a[0] := 1", scope); AType result = scope.GetVariable<AType>("c"); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); Assert.AreEqual(expected, result); }
public void ComplexAppendScalar() { AType expected = AArray.Create(ATypes.ABox, ABox.Create( AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(-3)) ), ABox.Create( AArray.Create(ATypes.AInteger, AInteger.Create(2), AInteger.Create(2)) ) ); ScriptScope scope = this.engine.CreateScope(); scope.SetVariable(".a", AArray.Create( ATypes.ABox, ABox.Create(AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0))), ABox.Create(AArray.Create(ATypes.AInteger, AInteger.Create(2), AInteger.Create(2))) ) ); this.engine.Execute <AType>("(0 pick a)[,] := -3", scope); Assert.AreEqual(expected, scope.GetVariable <AType>(".a"), "Incorrect value assigned"); }
public void AppendAssignPresetCallback() { AType expected = Helpers.BuildStrand( new AType[] { ASymbol.Create("b"), ASymbol.Create(""), Utils.ANull(), ABox.Create(AArray.Create(ATypes.AInteger, AInteger.Create(2), AInteger.Create(3))), AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(4)), Helpers.BuildString("static") } ); AType expectedValue = AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(2), AInteger.Create(3), AInteger.Create(4)); ScriptScope scope = this.engine.CreateScope(); this.engine.Execute("b := 1 2", scope); this.engine.Execute("cbf{a;b;c;d;e;f}:{.result := (a;b;c;d;e;f); := b}", scope); this.engine.Execute("_spcb{`b;(cbf;'static')}", scope); this.engine.Execute("b[,] := 3 4", scope); Assert.AreEqual(expected, scope.GetVariable <AType>(".result")); Assert.AreEqual(expectedValue, scope.GetVariable <AType>(".b")); }
public void Matrix2MatrixCatenate() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1)), AArray.Create(ATypes.AInteger, AInteger.Create(2), AInteger.Create(3)), AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1)), AArray.Create(ATypes.AInteger, AInteger.Create(2), AInteger.Create(3)) ); AType result = this.engine.Execute <AType>("(iota 2 2), (iota 2 2)"); Assert.AreEqual <AType>(expected, result, "Incorrect result created"); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public void NullArray2IntegerArrayCatenate() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(4)) ); AType result = this.engine.Execute <AType>("(0 2 rho 0), 3 4"); Assert.AreEqual <AType>(expected, result, "Incorrect result created"); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public AType ExecutePrimitive(AInteger rightArgument, AInteger leftArgument) { int number = (leftArgument.asInteger != rightArgument.asInteger) ? 1 : 0; return(AInteger.Create(number)); }
public AType ExecutePrimitive(AInteger rightArgument, AFloat leftArgument) { return(FloatEqual(rightArgument, leftArgument)); }
/// <summary> /// Search the <see cref="left"/> argument in the <see cref="right"/> argument. /// </summary> /// <param name="right">The data where the search should be performed.</param> /// <param name="left">Element to search in the right argument.</param> /// <param name="environment"></param> /// <returns></returns> public override AType Execute(AType right, AType left, Aplus environment = null) { if (right.Length == 0) { switch (left.Rank) { case 0: return(AInteger.Create(0)); default: return(DyadicFunctionInstance.Reshape.Execute(AInteger.Create(0), left.Shape.ToAArray())); } } else if (!(left.IsNumber && right.IsNumber) && (right.Type != left.Type)) { throw new Error.Type(this.TypeErrorText); } SearchInfo searchInfo = new SearchInfo() { // convert the right argument to an array (make life easier..) SearchWhere = right.IsArray ? right : AArray.Create(right.Type, right), ErrorText = this.LengthErrorText }; if (left.Rank < searchInfo.SearchWhere[0].Rank) { // The item we are looking for have a lesser rank than the items of the right argument throw new Error.Rank(this.RankErrorText); } AType result; if (!left.IsArray) { // Process a simple scalar result = ProcessScalar(left, searchInfo); } else { searchInfo.Result = AArray.Create(ATypes.AInteger); ProcessMatrix(left, searchInfo); searchInfo.Result.UpdateInfo(); // Check how many elements we need to return int elementCount = left.Shape.Count - Math.Max(right.Rank - 1, 0); if ((elementCount == 0) && searchInfo.Result.TryFirstScalar(out result)) { // need to return a simple scalar // 'result' contains the desired value } else { // reshape the result to the required shape List <int> desiredShape = left.Shape.GetRange(0, elementCount); result = DyadicFunctionInstance.Reshape.Execute(searchInfo.Result, desiredShape.ToAArray()); } } return(result); }
public void AndMatrix2Matrix() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1)), AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(1)) ); AType result = this.engine.Execute <AType>("(iota 2 2) & iota 2 2"); Assert.AreEqual(expected, result); }
public AType ExecutePrimitive(AInteger rightArgument, AInteger leftArgument) { return(AInteger.Create(Math.Max(leftArgument.asInteger, rightArgument.asInteger))); }
public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument) { return(AFloat.Create(Math.Max(leftArgument.asFloat, rightArgument.asFloat))); }
public void ScanAndFloatMatrix() { AType expected = AArray.Create( ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(2), AInteger.Create(8)), AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1), AInteger.Create(1)), AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1), AInteger.Create(1)) ); AType result = this.engine.Execute <AType>(@"&\ 3 2.00000000000005 8 , iota 2 3"); Assert.AreEqual(expected, result); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public void IntervalVector() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1), AInteger.Create(2)), AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(4), AInteger.Create(5)), AArray.Create(ATypes.AInteger, AInteger.Create(6), AInteger.Create(7), AInteger.Create(8)) ); AType result = this.engine.Execute <AType>("iota 3 3"); Assert.AreEqual(expected, result); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public AType ExecutePrimitive(ASymbol rightArgument, ASymbol leftArgument) { int number = (leftArgument.asString != rightArgument.asString) ? 1 : 0; return(AInteger.Create(number)); }
public override AType ExecutePrimitive(AInteger argument, Aplus environment = null) { return(calculateExp(argument.asFloat)); }
public AType ExecutePrimitive(AChar rightArgument, AChar leftArgument) { return(AInteger.Create((leftArgument != rightArgument) ? 1 : 0)); }
public void MultiDim2MultiDimRankDiffCatenate() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1), AInteger.Create(2)), AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(4), AInteger.Create(5)) ), AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(6), AInteger.Create(7), AInteger.Create(8)), AArray.Create(ATypes.AInteger, AInteger.Create(9), AInteger.Create(10), AInteger.Create(11)) ), AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1), AInteger.Create(2)), AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(4), AInteger.Create(5)) ) ); AType result = this.engine.Execute <AType>("(iota 2 2 3), (iota 2 3)"); Assert.AreEqual <AType>(expected, result, "Incorrect result created"); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public AType ExecuteDefault(AType rightArgument, AType leftArgument) { return(AInteger.Create(1)); }
public void AppendLengthError() { ScriptScope scope = this.engine.CreateScope(); scope.SetVariable( ".a", AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(0)), AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(0)) ) ); this.engine.Execute <AType>("a[,] := 3 4", scope); }
private AType FloatEqual(AType right, AType left) { int number = (!Utils.ComparisonTolerance(left.asFloat, right.asFloat)) ? 1 : 0; return(AInteger.Create(number)); }
public void MatrixAppendScalar() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(0)), AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(0)), AArray.Create(ATypes.AInteger, AInteger.Create(3), AInteger.Create(3), AInteger.Create(3)) ); ScriptScope scope = this.engine.CreateScope(); scope.SetVariable( ".a", AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(0)), AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(0), AInteger.Create(0)) ) ); this.engine.Execute <AType>("a[,] := 3", scope); Assert.AreEqual(expected, scope.GetVariable <AType>(".a"), "Incorrect value assigned"); }
private static AType TestMethod(Aplus env, AType arg2, AType arg1, AType arg0) { return(AInteger.Create(0)); }
public AType ExecutePrimitive(AFloat rightArgument, AInteger leftArgument) { return(CalculateAnd(rightArgument, leftArgument)); }
public override DLR.Expression Generate(AplusScope scope) { // TODO: Add usage of Protected Execute Flag // Save the previous return target DLR.LabelTarget oldTarget = scope.ReturnTarget; scope.ReturnTarget = DLR.Expression.Label(typeof(AType), "EXIT"); DLR.Expression protectedCode = DLR.Expression.Label( scope.ReturnTarget, this.codeblock.Generate(scope) ); // Restore the return target; scope.ReturnTarget = oldTarget; // Code block contining the strandard execution's result // wrapped in a strand DLR.Expression block = DLR.Expression.Call( typeof(Runtime.Helpers).GetMethod("BuildStrand"), DLR.Expression.NewArrayInit( typeof(AType), // We need to pass in reverse order protectedCode, DLR.Expression.Constant(AInteger.Create(0), typeof(AType)) ) ); // Parameter for Catch block DLR.ParameterExpression errorVariable = DLR.Expression.Parameter(typeof(Error), "error"); // Catch block, returns the ([errorcode]; [errortext]) strand DLR.CatchBlock catchBlock = DLR.Expression.Catch( errorVariable, DLR.Expression.Call( typeof(Runtime.Helpers).GetMethod("BuildStrand"), DLR.Expression.NewArrayInit( typeof(AType), // We need to pass in reverse order // Error Text DLR.Expression.Call( typeof(Runtime.Helpers).GetMethod("BuildString"), DLR.Expression.Property(errorVariable, "ErrorText") ), // Error Code DLR.Expression.Call( typeof(AInteger).GetMethod("Create", new Type[] { typeof(int) }), DLR.Expression.Convert( DLR.Expression.Property(errorVariable, "ErrorType"), typeof(int) ) ) ) ) ); DLR.Expression result = DLR.Expression.TryCatch( block, catchBlock ); return(result); }
public void MultiIndexing() { AType expected = AArray.Create(ATypes.AInteger, AArray.Create(ATypes.AInteger, AInteger.Create(5), AInteger.Create(1), AInteger.Create(7)), AArray.Create(ATypes.AInteger, AInteger.Create(9), AInteger.Create(8), AInteger.Create(2)) ); ScriptScope scope = this.engine.CreateScope(); this.engine.Execute<AType>(string.Format("a := 1 beam `{0}", MappedFiles.IntegerMatrix.GetFileName()), scope); this.engine.Execute<AType>("a[0;1] := 1", scope); AType result = this.engine.Execute<AType>(string.Format("b := 1 beam `{0}", MappedFiles.IntegerMatrix.GetFileName())); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); Assert.AreEqual(expected, result); }
public void IntervalFloatTolerablyInteger() { AType expected = AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(1), AInteger.Create(2), AInteger.Create(3) ); AType result = this.engine.Execute <AType>("iota 4.0"); Assert.AreEqual(expected, result); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public void RotatematrixMatrix2matrixWithFrame() { AType expected = AArray.Create( ATypes.AInteger, AArray.Create( ATypes.AInteger, AArray.Create( ATypes.AInteger, AInteger.Create(0), AInteger.Create(5) ), AArray.Create( ATypes.AInteger, AInteger.Create(10), AInteger.Create(15) ) ), AArray.Create( ATypes.AInteger, AArray.Create( ATypes.AInteger, AInteger.Create(4), AInteger.Create(9) ), AArray.Create( ATypes.AInteger, AInteger.Create(14), AInteger.Create(3) ) ), AArray.Create( ATypes.AInteger, AArray.Create( ATypes.AInteger, AInteger.Create(8), AInteger.Create(13) ), AArray.Create( ATypes.AInteger, AInteger.Create(2), AInteger.Create(7) ) ), AArray.Create( ATypes.AInteger, AArray.Create( ATypes.AInteger, AInteger.Create(12), AInteger.Create(1) ), AArray.Create( ATypes.AInteger, AInteger.Create(6), AInteger.Create(11) ) ) ); AType result = this.engine.Execute <AType>("(iota 2 2) rot iota 4 2 2"); Assert.AreEqual(expected, result); Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected)); }
public override AType Execute(AType right, AType left, Aplus environment = null) { return(AInteger.Create(left.Equals(right) ? 1 : 0)); }