From f4934e0ad6f5218ed54b8c3e50cffeef8bd10e46 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 2 Feb 2022 15:19:19 +0000 Subject: Prepare for matrix inverse and matrix division. It will not be implemented yet however :) --- functions.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'functions.c') diff --git a/functions.c b/functions.c index f1c4b0d..b1003fa 100644 --- a/functions.c +++ b/functions.c @@ -13,7 +13,7 @@ fnmonad monadfunctiondefs[] = { fnRecip, /* ÷ */ fnExponent, /* * */ fnNaturalLog, /* ⍟ */ - 0, /* ⌹ */ + fnMatrixInverse, /* ⌹ */ fnPiTimes, /* ○ */ fnFactorial, /* ! */ fnRoll, /* ? */ @@ -69,7 +69,7 @@ fndyad dyadfunctiondefs[] = { fnDivide, /* ÷ */ fnPower, /* * */ fnLogarithm, /* ⍟ */ - 0, /* ⌹ */ + fnMatrixDivide, /* ⌹ */ fnCircular, /* ○ */ fnBinomial, /* ! */ fnDeal, /* ? */ @@ -315,6 +315,23 @@ fnNaturalLog(Array *right) return res; } +Array * +fnMatrixInverse(Array *right) +{ + if(right->type != AtypeInt && right->type != AtypeFloat) + throwerror(nil, EType); + if(right->rank > 2) + throwerror(nil, ERank); + + if(right->rank == 0) + return rundfn(L"⌹1 1⍴⍵", nil, nil, nil, right); + if(right->rank == 1) + return rundfn(L"⌹(1⍪⍨⍴⍵)⍴⍵", nil, nil, nil, right); + + throwerror(L"Matrix inverse", ENotImplemented); + return nil; +} + Array * fnPiTimes(Array *right) { @@ -982,6 +999,12 @@ SCALAR_FUNCTION_2(fnLogarithm, 1, left->type, break; ) +Array * +fnMatrixDivide(Array *left, Array *right) +{ + return rundfn(L"⍺+.×⌹⍵", nil, nil, left, right); +} + SCALAR_FUNCTION_2(fnCircular, 1, AtypeFloat, case AtypeFloat:{ double v = right->floatdata[i]; -- cgit v1.2.3