• ### Similar Content

• By dejhost
Hello ,
Here are three stepts that I would like to speed up - if possible:
STEP 1: I am generating an array, containing binary numbers  up to a certain amount of digits. My script adds leading zeros, so that each number has equal amount of digits.
Example: 14 digit Binary array:
I am using the code
For \$i = 0 to 2^\$bit-1 ; \$bit amount of digits. for example: 14 \$binary = ( Dec2Bin(\$i) ) ; Check length of binary string \$adig = \$bit - StringLen(\$binary) ; Determine how many leading 0 have to be added \$zeros = "" For \$j = 1 To \$adig ; add leading "0"s \$zeros = \$zeros & "0" Next \$BinArray[\$i] = \$zeros & \$binary ;Write binary-number to file, leading "0" Next Func Dec2Bin(\$D) Return (BitShift(\$D, 1) ? Dec2Bin(BitShift(\$D, 1)) : "") & BitAnd(\$D, 1) EndFunc ;==> Dec2Bin() AutoIt v3.3.12.0   to generate the binary number.
STEP 2: I reduce the array to unique values. In my application, the binary-numbers do not have a start-bit or end-bit. This means, that
are actually the same numbers, and only one of them is to remain in the array. All alterations aren't unique and shall be removed. Here is my code:
For \$i = 0 to Ubound(\$BinArray)-1 ; shift through all rows For \$j = 1 to \$bit ; shift through all the bits If \$i = Ubound(\$BinArray) Then ; exit before exceeding the arrays boundries ExitLoop 2 EndIf \$BinArray[\$i] = StringRight ( \$BinArray[\$i], 1 ) & StringLeft ( \$BinArray[\$i], \$bit-1 ) \$BinArray = _ArrayUnique(\$BinArray, 0, 0, 0, 0, \$ARRAYUNIQUE_AUTO) If @error <> 0 Then Msgbox(0, "Error in _ArrayUnique", "The Error Code is " & @error & " Abort.") Exit EndIf Next Next STEP 3: Finally, I write the remaining array into a text-file.
For \$i = 0 to Ubound(\$BinArray)-1 FileWrite(\$hFileOpen, \$i & @TAB & \$BinArray[\$i] & @CRLF) Next
So my question is: any idea how to speed up this procedure? There certainly is a way to do this smarter. Btw.: Step 2 is optional.
Thanks for helping,
dejhost
• By Massi
Hi, I have update to the most recent Autoit version. I have a little problem with _ArrayUnique function.
If I have one array with two rows. _ArrayUnique crashes. I haven't any problem if there are more than two rows. I know that seems useless use this function with two rows, but these rows are the result of a search (generally I have more than two rows).
"C:\Program Files (x86)\AutoIt3\Include\Array.au3" (2290) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Local \$vFirstElem = ( (\$iDims = 1) ? (\$aArray[\$iBase]) : (\$aArray[\$iColumn][\$iBase]) )
Local \$vFirstElem = ( (\$iDims = 1) ? (\$aArray[\$iBase]) : (^ ERROR

#include <Array.au3> Dim \$Test1[3][6]=[["11","12","13","14","15","16"],["21","22","23","24","25","26"],["21","22","23","24","25","26"]] Dim \$Test[2][6]=[["11","12","13","14","15","16"],["21","22","23","24","25","26"]] Dim \$result=0 _ArrayDisplay(\$Test1) _ArrayDisplay(_ArrayUnique(\$Test1, 2)) _ArrayDisplay(\$Test) _ArrayDisplay(_ArrayUnique(\$Test, 2)) I put a workaround that I don't use _ArrayUnique function if there are only two results
• By Jfish
I think there may be a bug with _ArrayUnique introduced in 3.3.14 (or it could just be me).  I updated ticket #3078 with the attached files to demonstrate.  If you run test.au3 against the test data file in 3.3.12 it works and you see a unique array from _arrayDisplay.  If you do the same in 3.3.14 the _arrayDisplay view will be empty.
I read the script breaking changes and the updates but I don't think it should have cause this.  Please let me know if I am doing something wrong.
#include <Excel.au3> #include <Array.au3> func _openSourceData() \$sourcefile=FileOpenDialog("Please select source file",@ScriptDir,"All (*.*)") If @error Then ; Display the error message. MsgBox(\$MB_SYSTEMMODAL, "", "No file(s) were selected.") else ; Create application object Local \$oAppl = _Excel_Open() If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ***************************************************************************** ; Open an existing workbook and return its object identifier. ; ***************************************************************************** Local \$sWorkbook = \$sourcefile \$oWorkbook = _Excel_BookOpen(\$oAppl, \$sWorkbook, Default, Default, True) If @error Then Exit MsgBox(\$MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & \$sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) \$sourceArray=_Excel_RangeRead(\$oWorkbook) _ArrayDisplay(\$sourceArray) \$unique=_ArrayUnique(\$sourceArray) _ArrayDisplay(\$unique) EndIf EndFunc _openSourceData()
test.au3
testData2.xlsx

• Good Morning AutoIT Geniuses

I have version 3.3.14.1.
I am experiencing an error with the default Array.au3 or _ArrayUnique
I believe it is with this single line in my au3 file...\$aUniqueHostname = _ArrayUnique (\$array01, 1)
SendAndLog("GEN_CSVMinRowLimit01 - Started", \$tempzipdir & '\' & \$LogFileName01, True) ; CSV Minimum Row Limit (FYI - default was originally set to 5000) \$array01 = \$twoDarray MsgBox (0, "", "You are here 1") \$aUniqueHostname = _ArrayUnique (\$array01, 1) ; FYI - The program never makes it to here: MsgBox (0, "", "You are here 2") "C:\Program Files (x86)\AutoIt3\Include\array.au3" (2297) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If IsInt(\$aArray[\$iBase]) Then
If IsInt(^ ERROR
; Title .........: Array
; AutoIt Version : 3.3.14.1
; Autocheck of first element
If \$iIntType = \$ARRAYUNIQUE_AUTO Then
If IsInt(\$aArray[\$iBase]) Then
==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
Switch VarGetType(\$aArray[\$iBase])
Case "Int32"
\$iIntType = \$ARRAYUNIQUE_FORCE32
Case "Int64"
\$iIntType = \$ARRAYUNIQUE_FORCE64
EndSwitch
Else
\$iIntType = \$ARRAYUNIQUE_FORCE32
EndIf
EndIf
I don't believe I've ever seen an error in the default au3 files. Is this something I am doing wrong?
I'm just trying to run my apps through the new version of AutoIT since the fix was put in for...
AutoIt3Help.exe reworked and digitally signed I have looked at bug trackers...
https://www.autoitscript.com/trac/autoit/ticket/3110
https://www.autoitscript.com/trac/autoit/ticket/3078
Is this related somehow - what version of AutoIT do you recommend I use?
Thanks!

• By Gibbo
Recently I found myself needing to "Uniqueify" large arrays of data. Not happy with the speed I decided to check out how _ArrayUnique worked and if it could be improved.
Below is my overhauled version of _ArrayUnique.

"Uniqueify" An array of 500 random numbers (average of 5 results)
Old: 274.597787502462
New: 240.237994573652

"Uniqueify" An array of 1000 random numbers (average of 5 results)
Old: 1070.06629280595
New: 920.537746095923

Still not fast but faster

Changed ALL Dim's to Local's From the help file: "You should use Local or Global, instead of Dim, to explicitly state which scope is desired for a variable/constant/array." Changed: Dim \$aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user For \$i = 0 To \$iUboundDim - 1 _ArrayAdd(\$aArrayTmp, <itemtoadd> ) ;\$iDimension-1 to match Dimension Next _ArrayDelete(\$aArrayTmp, 0) ;Get rid of 1st-element which is blank To: Local \$aArrayTmp[\$iUboundDim] ;Declare array, which will hold the dimension declared by user For \$i = 0 To \$iUboundDim - 1 ;Loop through "Rows" \$aArrayTmp[\$i] = <itemtoadd> ;\$iDimension-1 to match Dimension Next It is silly to declare a "blank" array (and delete the first "empty value")if you already know it's intended dimentions This also removed the need for _ArrayAdd (No more ReDim's YAY!) Changed If,Then, Else statements to Switch statements where appropriate for ease of reading (they are supposed to be faster too) Trimmed: If Not \$iDimension > 0 Then Return SetError(3, 0, 0) ;Check to see if it is valid array dimension, Should be greater than 0 Else To: If \$iDimension < 1 Then Return SetError(3, 0, 0) ;Check to see if it is valid array dimension, Should be greater than 0 Changed: \$aArrayTmp = StringSplit(StringTrimRight(\$sHold, StringLen(\$vDelim)), \$vDelim, 1) ;Split the string into an array Return \$aArrayTmp ;SmOke_N's version used to Return SetError(0, 0, 0) To: \$sHold = StringTrimRight(\$sHold, StringLen(\$vDelim)) \$aArrayTmp = StringSplit(\$sHold, \$vDelim, 1) ;Split the string into an array Return \$aArrayTmp ;SmOke_N's version used to Return SetError(0, 0, 0) For clarity

; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayUnique ; Description ...: Returns the Unique Elements of a 1-dimensional array. ; Syntax.........: _ArrayUnique(\$aArray[, \$iDimension = 1[, \$iBase = 0[, \$iCase = 0[, \$vDelim = "|"]]]]) ; Parameters ....: \$aArray - The Array to use ; \$iDimension - [optional] The Dimension of the Array to use ; \$iBase - [optional] Is the Array 0-base or 1-base index. 0-base by default ; \$iCase - [optional] Flag to indicate if the operations should be case sensitive. ; 0 = not case sensitive, using the user's locale (default) ; 1 = case sensitive ; 2 = not case sensitive, using a basic/faster comparison ; \$vDelim - [optional] One or more characters to use as delimiters. However, cannot forsee its usefullness ; Return values .: Success - Returns a 1-dimensional array containing only the unique elements of that Dimension ; Failure - Returns 0 and Sets @Error: ; 0 - No error. ; 1 - Returns 0 if parameter is not an array. ; 2 - _ArrayUnique failed for some other reason ; 3 - Array dimension is invalid, should be an integer greater than 0 ; Author ........: SmOke_N ; Modified.......: litlmike, Gibbo ; Remarks .......: Returns an array, the first element (\$array[0]) contains the number of strings returned, the remaining elements (\$array[1], \$array[2], etc.) contain the unique strings. ; Related .......: _ArrayMax, _ArrayMin ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _ArrayUnique(\$aArray, \$iDimension = 1, \$iBase = 0, \$iCase = 0, \$vDelim = "|") Local \$iUboundDim ;\$aArray used to be ByRef, but litlmike altered it to allow for the choosing of 1 Array Dimension, without altering the original array If \$vDelim = "|" Then \$vDelim = Chr(01) ; by SmOke_N, modified by litlmike If Not IsArray(\$aArray) Then Return SetError(1, 0, 0) ;Check to see if it is valid array ;Checks that the given Dimension is Valid If \$iDimension < 1 Then Return SetError(3, 0, 0) ;Check to see if it is valid array dimension, Should be greater than 0 ;If Dimension Exists, then get the number of "Rows" \$iUboundDim = UBound(\$aArray, 1) ;Get Number of "Rows" If @error Then Return SetError(3, 0, 0) ;2 = Array dimension is invalid. ;If \$iDimension Exists, And the number of "Rows" is Valid: Switch \$iDimension = 1 Case False ;Makes sure the Array dimension desired is more than 1-dimensional Local \$aArrayTmp[\$iUboundDim] ;Declare array, which will hold the dimension declared by user For \$i = 0 To \$iUboundDim - 1 ;Loop through "Rows" \$aArrayTmp[\$i] = \$aArray[\$i][\$iDimension - 1] ;\$iDimension-1 to match Dimension Next Case Else ;Makes sure the Array dimension desired is 1-dimensional ;If Dimension Exists, And the number of "Rows" is Valid, and the Dimension desired is not > 1, then: ;For the Case that the array is 1-Dimensional Switch UBound(\$aArray, 0) Case 1 ;Makes sure the Array is only 1-Dimensional Local \$aArrayTmp[\$iUboundDim] ;Declare array, which will hold the dimension declared by user For \$i = 0 To \$iUboundDim - 1 \$aArrayTmp[\$i] = \$aArray[\$i] Next Case Else ;For the Case that the array is 2-Dimensional Local \$aArrayTmp[\$iUboundDim] ;Declare array, which will hold the dimension declared by user For \$i = 0 To \$iUboundDim - 1 \$aArrayTmp[\$i] = \$aArray[\$i][\$iDimension - 1] ;\$iDimension-1 to match Dimension Next EndSwitch EndSwitch Local \$sHold ;String that holds the Unique array info For \$iCC = \$iBase To \$iUboundDim - 1 ;Loop Through array ;If Not the case that the element is already in \$sHold, then add it Switch StringInStr(\$vDelim & \$sHold, \$vDelim & \$aArrayTmp[\$iCC] & \$vDelim, \$iCase) Case False \$sHold &= \$aArrayTmp[\$iCC] & \$vDelim EndSwitch Next If \$sHold Then \$sHold = StringTrimRight(\$sHold, StringLen(\$vDelim)) \$aArrayTmp = StringSplit(\$sHold, \$vDelim, 1) ;Split the string into an array Return \$aArrayTmp ;SmOke_N's version used to Return SetError(0, 0, 0) EndIf Return SetError(2, 0, 0) ;If the script gets this far, it has failed EndFunc ;==>_ArrayUnique
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...