# Eigen4AutoIt - Matrix computing with Eigen

## Recommended Posts

@RTFC:

Would you like to update unexpected behavior functions - _CwiseScalarOp... and _CwiseUnaryOp?

From Help:

Apply [operator, scalar] to each cell of matrix A, storing the result in-place

Maybe it would be better to have two variant: - to store in-place and not (default)

These functions have tacit return by ref for passed matrix.

Example shows this tacit return by ref. Let us have two expression:

A = xC - yD

B = yC - xD

There are two version by E4A:

```; long version I
; It returns valid result

;Matrix A
\$matT = _Eigen_CloneMatrix (\$matC)
_Eigen_CwiseScalarOp(\$matT,"*", \$x)
\$matT1 = _Eigen_CloneMatrix (\$matD)
_Eigen_CwiseScalarOp(\$matT1,"*", \$y)
\$matA = _Eigen_CwiseBinaryOp(\$matT,"-",\$matT1)
_MatrixDisplay ( \$matA, "\$matA" )

;Matrix B
\$matT = _Eigen_CloneMatrix (\$matC)
_Eigen_CwiseScalarOp(\$matT,"*", \$y)
\$matT1 = _Eigen_CloneMatrix (\$matD)
_Eigen_CwiseScalarOp(\$matT1,"*", \$x)
\$matB = _Eigen_CwiseBinaryOp(\$matT,"-",\$matT1)
_MatrixDisplay ( \$matB, "\$matB" )

; short version II
; Now it returns invalid result!

\$matA = _Eigen_CwiseBinaryOp(_Eigen_CwiseScalarOp(\$matC,"*", \$x),"-",_Eigen_CwiseScalarOp(\$matD,"*", \$y))
\$matB = _Eigen_CwiseBinaryOp(_Eigen_CwiseScalarOp(\$matC,"*", \$y),"-",_Eigen_CwiseScalarOp(\$matD,"*", \$x))```
Edited by ValeryVal

The point of world view

• Replies 86
• Created

#### Popular Posts

The Eigen C++ template library is a great environment for matrix computing; it is fast, reliable, extensive, and well-documented. It is also completely free, and does not rely on any external dependen

E4A version 4.4 has arrived. The name of the game this time is bitmask support (see _Eigen_ConditMask*, now fully functional), notably: a new family of CwiseLogicalOp functions with which t

E4A version 5,2 is available for download: the "2020 Hindsight" release. This is a maintenance upgrade, fixing many small issues (and the odd catastrophic bug ), filling some consistency gaps in

#### Posted Images

Hmm, never tested that particular embedded scenario.

I'll have a look at it...

Thanks for flagging this issue.

EDIT: Okay, I've had a look.

First off, these E4A functions work exactly as advertised. Your short version II returns a different result from your longer version I because you are doing something different, so technically, the returned result is not invalid, it's just different from what you apparently expected. To use the short, embedded calls version, you should have done this:

```\$matCC=_Eigen_Clone(\$matC)
\$matDD=_Eigen_Clone(\$matD)
\$matA = _Eigen_CwiseBinaryOp(_Eigen_CwiseScalarOp(\$matC,"*", \$x),"-",_Eigen_CwiseScalarOp(\$matD,"*", \$y))
_MatrixDisplay ( \$matA, "\$matA" )
\$matB = _Eigen_CwiseBinaryOp(_Eigen_CwiseScalarOp(\$matCC,"*", \$y),"-",_Eigen_CwiseScalarOp(\$matDD,"*", \$x))
_MatrixDisplay ( \$matB, "\$matB" )```

After the first embedded call, the contents of matC and matD have changed, so you'd get a different result in the second embedded call. I would argue this is completely expected behaviour; if you change contents in place, you cannot expect the next operation to still use the original content.

Now this is not to say you don't have a valid point...

I can see that inPlace vs new results matrix variants might be useful and would be in keeping with the way E4A functions are structured.This would however be script-breaking changes for all (well, most) Cwise functions, and there are an awful lot of them to fix. But as the festive season is approaching, I'll probably find some time over the next few weeks to implement this additional functionality. After all, what are holidays for anyway? I'll see if I can squeeze it into the next release.

Just as long as we're clear this is neither a bug nor an unexpected result, okay?

Edit: as of E4A version 2.3, Cwise functionality has changed; the default functions now store the result in a new results matrix R, whereas a separate funvction with suffix _InPlace perfoms the original operation. This is the way ValeryVal expected these functions to work, and in retrospect I agree that it makes more sense this way.

Edited by RTFC

My Contributions and Wrappers

Spoiler
##### Share on other sites

Hmm, never tested that particular embedded scenario.

BTW. This known "bug" is from time of Fortran (pass-by-reference language). Example:

http://stackoverflow.com/questions/7994360/passing-arguments-by-pass-by-reference-to-a-swap-function

So according to assertion that "we can know more than we can tell" (See http://en.wikipedia.org/wiki/Tacit_knowledge) my script induces me to remember about one real girl making that tacit returns by ref from many nested procedures (fifth or more levels). It was very severe work to fish out her hand coding.

...

I can see that inPlace vs new results matrix variants might be useful and would be in keeping with the way E4A functions are structured.This would however be script-breaking changes for all (well, most) Cwise functions, and there are an awful lot of them to fix. But as the festive season is approaching, I'll probably find some time over the next few weeks to implement this additional functionality. After all, what are holidays for anyway? I'll see if I can squeeze it into the next release.

Just as long as we're clear this is neither a bug nor an unexpected result, okay?

In any case I've written valid script to solve my tasks under Eigen4AutoIt v.2.2

Thank you.

;-)

Edited by ValeryVal

The point of world view

##### Share on other sites

That sounds like fun.

But the benefit of such experiences is that it rids you of one's own tacit assumptions that everyone else sees the world (or solves its problems) in the same way you do yourself.

My Contributions and Wrappers

Spoiler
##### Share on other sites

That sounds like fun.

But the benefit of such experiences is that it rids you of one's own tacit assumptions that everyone else sees the world (or solves its problems) in the same way you do yourself.

ValeryVal:

Everyone has own unique tacit knowledge. However, not everyone has ability to tell about it.

The point of world view

##### Share on other sites
• 2 weeks later...

Xmas Version 2.3 released.

Following ValeryVal's interesting suggestion, all Cwise and related functions have now been split into a regular version (storing output in new results matrix R) and an in-place version (these latter versions used to be the default, but are now accessed by adding the _InPlace suffix to the function name, as would be expected). Upon deep reflection after two weeks of fasting in a Himalayan cave, I came to the conclusion that  the proposed new arrangement is internally far more consistent and flexible than my original design, even though this implies SCIRPT-BREAKING CHANGES for all Cwise functions! NB This includes Conditional Cwise functions.

As feared, this was rather a lot of work:

E4A functions: +40

dll variants: +253!

alias wrappers: +106

Needless to say, the package has gained some extra weight in the process, now taking almost 25 MB to install uncompressed .

Originally I'd planned to add graphics support in this release,but that'll have to wait until I've sorted out a number of other issues, after recovering over the Xmas break from this latest effort.   Additional info on the few other changes and fixes in this release can be found as usual in the History/ChangeLog in the Help file (online version already updated too).

So ValeryVal, I hope these additions satisfy your requirements. Anyone else who is vexed/annoyed/disgruntled/homicidal upon discovering all Cwise functions no longer work as advertised earlier, please get in touch with ValeryVal; I just work here.

Happy holidays!

Edited by RTFC

My Contributions and Wrappers

Spoiler
##### Share on other sites

Xmas Version 2.3 released.

So ValeryVal, I hope these additions satisfy your requirements. Anyone else who is vexed/annoyed/disgruntled/homicidal upon discovering all Cwise functions no longer work as advertised earlier, please get in touch with ValeryVal; I just work here.

Happy holidays!

Yes! I'm ready to foil any onrush to 2.3.

I guess you were near the entrance to Shambhala from that trans-Himalayan cave.

Meantime I've found the Efficient Portfolio Frontier by means E4A

and Robert C. Merton article

http://www.people.hbs.edu/rmerton/analytical%20derivation.72.pdf

Thank you.

Happy New Year

Edited by ValeryVal

The point of world view

##### Share on other sites

Ah yes, I got lost and then passed that place on my way up to the cave I'd rented, and asked if I could spend the night there, but this fat guy Lord Maitreya something or other flatly refused me entry, mumbling about impure souls and karmic burden and whatnot. Said I would have to make quite a bit more code available to the forum before he'd even discuss my ever coming back there, with my blemished record in this life and several others before that. Burned my maps too, then had his yaks chase me down the road. Well, guess who's not getting a favourable write-up from me on the holiday destination review websites... That'll teach him.

BTW, you never cease to amaze me, a typewritten paper from 1972? Where do you dig up these little gems? So if this financial stuff works out for you, you won't forget this humble servant who gave you access to Eigen's wonderful functions, now would you? I'm really good at keeping secrets too...

Edited by RTFC

My Contributions and Wrappers

Spoiler
##### Share on other sites

>a typewritten paper from 1972...this financial stuff works out for you

Hmm. Long John Silver from Treasure Island are using old and smoky map of island

>I'm really good at keeping secrets too

This secret is simple.

Long John Silver tell about how he keeps his wealth,

I puts it all away, some here, some there, and none too much anywheres…”

BTW Have you read a story of previous Silver's life

Flint and Silver: A Prequel to Treasure Island

http://www.amazon.com/Flint-Silver-Prequel-Treasure-Island/dp/B004JZWOPG

John Silver had never killed a man. Until now, his charisma, sheer size and, when all else failed, powerful fists had been enough to dispatch his enemies. But on a smoldering deck off the coast of Madagascar, his shipmates dead or dying all around him, his cutlass has just claimed the lives of six pirates. Surrounded by their revenge-thirsty crewmates, Silver fears for his life, but then the pirate captain makes him an offer he can’t refuse.

On the other side of the world, Joseph Flint, a naval officer wronged by his superiors, plots a bloody mutiny. Strikingly handsome, brilliant but prey to sadistic tendencies, Flint is regarded as the most dangerous bandit on the high seas and fate would have it that his course intersects with Silver’s.

Together these gentlemen of fortune forge a deadly and unstoppable partnership, steering a course through treachery and betrayal while amassing vast treasure.

Edited by ValeryVal

The point of world view

##### Share on other sites
• 2 months later...

When I try to run any of the examples, the process just run and never returns, and has to be killed manually.

I'm using the latest version of autoit and the script is pointing to the directory of the DLLs.

I'm not getting any error, the process just runs until it's killed.

I don't know this is an error with the engine, the wrapper, or if I'm just plain missing something obvious.

Edited by nullschritt
##### Share on other sites

Sorry nullschritt, that's not enough information for me to figure out what might be going wrong in your environment.

Which example script were you running? What OS? Are you running AutoIt 3.3.12? How far does the example script get? Up to _Eigen_Startup? Up to the first dll call? Which dll call(s) fail(s)?

As several hundred other users are not experiencing such a total failure, I would hazard a guess that something in your particular set-up is not working the way it should. I haven't come across this situation, else it would be documented in the remarks section of the main script.

E4A v.2.3: EigenDense.dll, 3,926,016 bytes, MD5: 0xDA2EA43A53782B56EF19AC1A4B68CBC9

E4A v.2.3: EigenDense_Debug.dll, 5,680,640 bytes, MD5: 0x817AB67DABC8D584A881F6E2235DB5B9

Note to all other users as well: the wrapper for _Eigen_OuterProduct() contains a bug that will be fixed in the next release (that will also incorporate the latest Eigen release), within the next few weeks, as soon as multi-processing has passed the initial testing phase. In the meantime, the function will only work if the two input vectors are parsed in the order: colvector, rowvector (it's supposed to reverse the order internally otherwise, but this currently fails, due to a brainfade when I wrote that wrapper).

Edited by RTFC

My Contributions and Wrappers

Spoiler
##### Share on other sites

Okay I just didn't have the path right, but now I am experiencing a small hiccup. With my native matrix multiply function my matricies all multiply fine.

But when I try to replace it with your functions, it throws an error saying it's expecting 10 values when there are only 8, and it should never be expecting 10 values because all the matrices are 8x8.

Edit: I lied, one of the arrays does have 10 rows, but it's within the rules of matrix multiplication (a 10x8 matrix * a 8x8 matrix) as only the columns have to match, not rows.

Edit Edit: Is this because the empty array I'm using as a placeholder is only 8x8? If so, is there a way to get the size of a matrix, so my code knows what size to make the empty array?

Edited by nullschritt
##### Share on other sites

nullschritt,

You really should read about matrix operations. The matrix multiply op (dot in matrix parlance) goes as follows: A.B with A dimension NxK and B KxN.

So to perform the product of a 10x8 matrix with B, B must have dimension 8x10.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

##### Share on other sites

@jchd: Thank you!

@nullschritt: Well, I'm glad your initial problem was resolved. As far as getting matrix properties, you may seek enlightenment in the extensive Help file (also online); in section Matrix Management you'll find functions such as GetMatrixRows, GetMatrixCols, GetMatrixType, etc. If you want more information on the matrix contents, study section Reduction (specifically the MatrixSpecs functions).

And to clarify your matrix multiplication issues , you could read the Help file's section on Matrix Multiplication, or study this image:

Note that matrix multiplication is NOT commutative, so A.B is not the same as B.A.

Finally, I'd also like to gently remind you of the posting rules I stated in post #1 of this thread, notably, that I won't be answering any basic maths questions ; I've listed several internet resources in the Remarks section of the main script (Eigen4AutoIt.au3) to get novice users started, but other than that, you'll have to work it out yourself. It's definitely worth it; maths looks different (and often easier) when viewed through a matrix lens.

Edited by RTFC

My Contributions and Wrappers

Spoiler
##### Share on other sites

@jchd: Thank you!

@nullschritt: Well, I'm glad your initial problem was resolved. As far as getting matrix properties, you may seek enlightenment in the extensive Help file (also online); in section Matrix Management you'll find functions such as GetMatrixRows, GetMatrixCols, GetMatrixType, etc. If you want more information on the matrix contents, study section Reduction (specifically the MatrixSpecs functions).

And to clarify your matrix multiplication issues , you could read the Help file's section on Matrix Multiplication, or study this image:

Note that matrix multiplication is NOT commutative, so A.B is not the same as B.A.

Finally, I'd also like to gently remind you of the posting rules I stated in post #1 of this thread, notably, that I won't be answering any basic maths questions ; I've listed several internet resources in the Remarks section of the main script (Eigen4AutoIt.au3) to get novice users started, but other than that, you'll have to work it out yourself. It's definitely worth it; maths looks different (and often easier) when viewed through a matrix lens.

I wasn't asking a math question I KNOW how matrix multiplication works(the rules), I'm already doing it with NATIVE autoit functions. I stated that already, yet everyone seems to be under the impression I'm asking math questions, when I'm asking questions about the UDF. I was asking a question about your UDF, specifically, if my problem was that the place-holder array was too small for the output of the problem, and how to get the size to correct the problem. (: Which you did answer, thank you.

Edit: Would you maybe consider automatically putting the output of matrix math problems into an array properly sized for it, as opposed to having to manually define the size of the output matrix each time?

It would save a LOT of lines of code.

Edited by nullschritt
##### Share on other sites

nullschritt,

You really should read about matrix operations. The matrix multiply op (dot in matrix parlance) goes as follows: A.B with A dimension NxK and B KxN.

So to perform the product of a 10x8 matrix with B, B must have dimension 8x10.

Edit: You literally just said the exact same sentence as my question, but in a statement.

Edited by nullschritt
##### Share on other sites

@nullschritt: one of the advantages of the E4A environment is that you don't have to provide an output matrix (or several results matrices, some UDFs can produce over a dozen per call) in advance; instead you just parse the matrix IDs of your inputs, and the UDF automatically creates an output of the right dimensions for you, stores the result in there, and returns its handle to you (that is, the matrix ID, i.e., its index to the global array \$matrixlist). For flexibility, you can alternatively pre-create the output container(s) and parse it/them explicitly (this can be useful to re-use/conserve memory resources, for example), but normally , you never have to think about what size your output(s) should be until after you receive them.

Secondly, if your calculation comes back with an error message that there's something wrong with the dimensions of your matrices, then if your first reaction is to suspect a bug rather than a simple mistake on your part, then you could at least test this assumption thoroughly before posting. So you could examine the AutoIt wrapper for _Eigen_Multiply_AB, inspect the C++ dll source code I wrote for that function, read up on the intricacies of matrix multiplication, visit Eigen's own forum, and (most helpful would be to) write a tiny test script that reproduces the bug, so I can actually figure out what's going wrong, if something really is going wrong. I'm still weeding out bugs, typos, and oversights, so it's perfectly possible that you stumble across these, but please take the time and effort to rule out an error on your part before you post here that something unexpected occurred.

Edited by RTFC

My Contributions and Wrappers

Spoiler
##### Share on other sites

@nullschritt: one of the advantages of the E4A environment is that you don't have to provide an output matrix (or several results matrices, some UDFs can produce over a dozen per call) in advance; instead you just parse the matrix IDs of your inputs, and the UDF automatically creates an output of the right dimensions for you, stores the result in there, and returns its handle to you (that is, the matrix ID, i.e., its index to the global array \$matrixlist). For flexibility, you can alternatively pre-create the output container(s) and parse it/them explicitly (this can be useful to re-use/conserve memory resources, for example), but normally , you never have to think about what size your output(s) should be until after you receive them.

Secondly, if your calculation comes back with an error message that there's something wrong with the dimensions of your matrices, then if your first reaction is to suspect a bug rather than a simple mistake on your part, then you could at least test this assumption thoroughly before posting. So you could examine the AutoIt wrapper for _Eigen_Multiply_AB, inspect the C++ dll source code I wrote for that function, read up on the intricacies of matrix multiplication, visit Eigen's own forum, and (most helpful would be to) write a tiny test script that reproduces the bug, so I can actually figure out what's going wrong, if something really is going wrong. I'm still weeding out bugs, typos, and oversights, so it's perfectly possible that you stumble across these, but please take the time and effort to rule out an error on your part before you post here that something unexpected occurred.

I did edit the post to point out the error was on my part, I was pre-defining the emprty matrix and placing the output matrix in it, as shown in the example, I didn't realize it didn't need to be pre-defined, thanks!

##### Share on other sites

That's okay, nullschritt, and you're welcome. But the E4A Help file really is your friend here; the optional outputs are mentioned on virtually every page that describes a computational function, at the bottom of the table of parsed arguments (below the function defintion box). A single results matrix is (usually) generically referred to as \$matR. It would make me very happy to know that people actually consult that Help doc, as it took me considerable effort to produce it.

My Contributions and Wrappers

Spoiler
##### Share on other sites

nullschritt,

Thank you very much for your lecture but you seem to have forgotten what you yourself said:

one of the arrays does have 10 rows, but it's within the rules of matrix multiplication (a 10x8 matrix * a 8x8 matrix) as only the columns have to match, not rows

I was answering the part in bold and especially the underscored part, which is just plain wrong.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

## Create an account

Register a new account

• ### Similar Content

• By UEZ
I don't think I ever posted The Matrix here, so here's the upload:

The Matrix v1.31.au3

Can you decipher the code?

• By RTFC
The Short Version:
This set of well-annotated example scripts shows how to solve sudoku puzzles with simple, powerful bitmask functions applied on a massive scale, demonstrating both common solving techniques and highly-optimised brute-force.
All you need is:
to like sudoku's basic logic primary school maths to download & install this bundle (v1.2; 25 July 2020) and this #include file (v5.1+) the CrossFilter GUI
• By RTFC
Eigen4AutoIt Features:
free, fast matrix computing environment for Windows (runs under Wine on Linux and Mac) built upon the robust Eigen code base (open-source), with many enhancements simple, intuitive functions, with extensive online documentation supports integer, single, and double precision, in real and complex matrices Tutorials with scripts, plus Test scripts for each function section easily exchange data between native binary files (.mat) and ASCII, Excel, and Xbase files, or AutoIt arrays 32-bit (x86-mode) and 64-bit (x64-mode) support in x64-mode, matrices can be any size that fits into available virtual memory (>4GB), and can be shared between processes over one thousand alias wrappers for flexibility and ease-of-use
This computing environment allows you to do matrix I/O (memory & files), matrix arithmetic, transformation, reduction, and decomposition, solve systems of linear equations, and perform statistics. Most functions can act on integer, real, or complex matrices (or the latter's real/imaginary parts separately). Much of the actual complexity of using Eigen in its native C++ environment has been hidden for AutoIt users, through extensive bounds and error checks, an intuitive function-naming convention, a large help file, and detailed tutorials and test examples.

• Hello friends! I have been working on an encryption algorithm in autoit as a proof of concept for some time now. Basically the algorithm uses a progressive recursion to encode data inside a matrix using a key that changes according to the date-time of the system, which is extracted from a larger key array. Recently after a drive failure, I lost the source and had to start from scratch, now I can't quite get it working the way it was before, and I can't see what I'm doing wrong, if anyone who understands matrix math or encryption could help I would much appreciate it. The problem is that the values returned by the decryption (extraction) process are way too big.

I have figured out the solution to my problem, it was a typo, please disregard this thread.
I will post my project into example scripts when it's ready.

• By Edano
i searched the forum, but didn't find anything.
has anyone an idea or ever done it with autoit ? simple image transforming, like sharpness, brightness, blurring etc. ?
maybe, does gdiplus.dll feature that ?
here is a tutorial on how to do it the hard (mathematical) way. http://lodev.org/cgtutor/filtering.html before i try that, i wanted to know if there is already an existing project or an idea or anyone has experiences.
thx
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...