Skip to content

Commit

Permalink
Test number of arguments in TransformationFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Aug 29, 2023
1 parent 07bd948 commit b14de32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
6 changes: 0 additions & 6 deletions symja_android_library/doc/functions/TransformationFunction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ TransformationFunction(m)
```

> represents a transformation.
```
TransformationFunction(phi, {0, 1}, {1, 0})
```

> gives a vertical shear by the angle `phi`.

See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,19 +1139,27 @@ private static class TransformationFunction extends AbstractFunctionEvaluator {

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (ast.head().isAST(S.TransformationFunction, 2)) {
IAST operator = (IAST) ast.head();
IExpr m = operator.arg1();
int dim = ast.arg1().isVector();
if (dim > 0) {
IAST v = (IAST) ast.arg1().normal(false);
// Take(m . Join(v, {1}), Length(v))
return F.Take(F.Dot(m, F.Join(v, F.list(F.C1))), F.ZZ(dim));
}
if (!ast.head().isAST(S.TransformationFunction, 2)) {
return F.NIL;
}

IAST operator = (IAST) ast.head();
IExpr m = operator.arg1();
if (!ast.isAST1()) {
// `1` called with `2` arguments; 1 argument is expected.
return Errors.printMessage(S.TransformationFunction, "argx",
F.List(ast, F.ZZ(ast.argSize())), engine);
}
int dim = ast.arg1().isVector();
if (dim > 0) {
IAST v = (IAST) ast.arg1().normal(false);
// Take(m . Join(v, {1}), Length(v))
return F.Take(F.Dot(m, F.Join(v, F.list(F.C1))), F.ZZ(dim));
}
return F.NIL;
}


}

private static class TranslationTransform extends AbstractFunctionEvaluator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public void testTensorProduct() {


public void testRotationTransform() {
check("TransformationFunction(#2)[Sequence()]", //
"TransformationFunction(#2)[]"); //

check("RotationTransform(Pi).TranslationTransform({1, -1})", //
"TransformationFunction(\n" //
+ "{{-1,0,-1},\n" //
Expand Down

0 comments on commit b14de32

Please sign in to comment.