#] #] ********************* #] "$d_Qndfs"'arrays TblOfContents.txt' - ??? # www.BillHowell.ca 26Aug2022 initial # view in text editor, using constant-width font (eg courier), tabWidth = 3 #48************************************************48 #24************************24 # Table of Contents, generate with : # $ grep "^#]" "$d_Qndfs"'arrays TblOfContents.txt' | sed "s/^#\]/ /" # ********************* "$d_Qndfs"'arrays TblOfContents.txt' - ??? Setup (kind of like header info) +-----+ arrays.ndf Table of Contents, generated with : ToDos Warnings and notes +-----+ # 24************************24 #] +-----+ #] arrays.ndf Table of Contents, generated with : # $ grep "^#]" "$d_Qndfs""arrays.ndf" | sed 's/^#\]/ /' # ********************* loaddefs link d_Qndfs 'arrays.ndf' - optrs for TOP level only (not nested!) WARNING! use xxx_chkFor_ary_apply_optrPhr where xxx = [idx,itm,sub] call ary optrs directly to save [vast, redundant] computations +-----+ Setup +-----+ [itm, sub]_in_[ary, table, matrix] operators - see link d_Qndfs 'types.ndf' +-----+ Array restructure [to,from] cart [atm, str, lst, ary] : aryA_catVertical IS OP aryL - joins 2D arrays by "stacking-merging" each above next aryA_catHorizontal IS OP aryL - joins 2D arrays by "side-merging" each alongside next ary_repeatNtimesTo_aryL IS OP ary n - repeats ary n times ary_atm_replaceAllAtm_aryOut IS OP ary atm - replace all atoms of ary with atm handy for test standards, ready for post-replacements, works for atm=null even if is not an atom ary_to_atmL IS OP ary - returns an atmL containing all contents of ary handy for nestAry [test, standard]s, - eg all [bool, chr, int, real, phrase, complex] ary aryP_transStr_isSameStruct IS OP aryP transStr - boolean indicating if aryPL (= [y1, ary2] have same same structure according to transformer transStr ary_allAtmsUnique_bol IS OP ary - converts ary to list of topLevel itms, [atm, single, solitary]s are unique by defn ary_allItmsUnique_bol IS OP ary - res ipsa loquitor [atm, single, solitary]s are unique by defn +-----+ [idx, itm, slc, sub] optrs - (slc = slice hyper-planes) typically returns a LIST : the use of commas, followed by execute string is necessary. I can't get "nulls" to work otherwise use of "ary" instead of "ary" can be confusing, but hightlights minimal information needed 'arrays- testOptrs.ndf' mostly uses "ary" optrs, not "ary, for easy data setup, tracking adrLL_to_idxLL IS OP adrLL - returns a list of "targeted" indexes for each axis, based on adrLL ary_get_idxAll IS OP ary - returns [i j] for ary top level (idx, not str!) ary_symStr_make_idxSymAll IS OP ary symStr - make ary of shape ary, elements 'symStr@[i,j]' for easily following processes! eg see 'matrix operations - symbolic & real-valued.ndf' symStr must end with '@[', usually preceded by the name of the ary being looked at ary_idx_get_itm IS OP ary idx - returns itm of aryTop ary_idx_to_slc IS OP ary idx - convert idx to slc, based on ary null idx values are used to build slc even though they are not "legal" idx values examples : for ary := (4 5 reshape (tell 30)); ary@(0 2) -> 2; ary@(0 null) -> ?address ary_idxSeq_to_slc IS OP ary idxSeq - convert idx sequence to slc, based on ary ary_itm_get_idxL IS OP ary itm - returns all positions of itm in ary, or o (false) itm MUST be an "element" of ary, eg (0 1) in ((0 1) 2 3 4 5), not in (0 1 2 3 4 5) argument oder mirrors sadnard QNial find[, all] ary_itm_get_slcLL IS OP ary itm - get all slices (hyperplanes) through itm in ary slcLL = list of all slcL, one slcL for every occurrence of itm in ary, 2^aryVal slc in each slcL allows subsequent find of sub at point itm, along "free" axis of ary Note that itm can be ANYTHING! (including [null, atm, solitary, single, etc]) ary_slc_to_idxA IS OP ary slc - convert slcA to idxA for itmSlc, a single is converted to a solitary (list) ary_slc_get_sub IS OP ary slc - res ipsa loquitor, not much use except for executables ary_slcA_to_idxAA IS OP ary slcA - convert idxA to slcA ary_slc_invert IS OP ary slc - returns the "inverse Axs-sliceidxL", useful for [cut etc] 17Nov2021 initial draft only, doesn't work yet,list version only so far 17Apr2022 does this even make sense? - do later when I get to it ary_slcA_invert IS OP ary slcA - returns the "inverse Axs-sliceidxA", useful for [cut etc] 11Feb2022 initial ghost only, simply calls ary_slc_invert, difficult to define in ary case? 17Apr2022 does this even make sense? - do later when I get to it ary_sub_get_idx1stL IS OP ary sub - idxA of 1st item of sub in TOP level of ary ary_sub_get_idxLL IS OP ary sub - posnAL of all "itm-sequences=sub" within in ary, or faultL ary_sub_get_slcL IS OP ary sub - get slcL (hyperplanes) for sub in ary sub_idxLL_to_slc IS OP sub idxLL - generate slice that specifies idxA for each itm of sub the slice is for a larger ary, so slice idxs can be greater than allowed by sub +-----+ split[Separate,[At[Front,End]], ] : 14Nov2021 - these optrs have NOT yet been upgraded from list basis to array these optrs return subs of ary, and don't have to apply slice-like! they do not leave non-existant "interior portions" of an ary, because splits do not remove content ary_itm_splits - aren't useful by the definition of an item - arys are already split by itms! ary_slc_get_frontEndSlcP IS OP ary slc - returns [i,j] for ary top level (ghost optr) for retrieval, slc is part of ary for [insert, delete] slc is location in ary before action ary_subL_getLenMatchesTo_subPL IS OP ary subL - return (ary = link subPairs) ary_slc_splitSeparate_subL IS OP ary slc - ary is split at slc, gives [front, slc part, end] or faultL slc must be FULLY specified (not a search) ary_sub_splitSeparate_subL IS OP ary sub - sub [splits ary, separate] 10May2022 WON'T WORK - part way through transition!!!! iteratively does each split, one Axs at a time using result on previous Axs split implicitly uses global g_AxsSplitL (default = 0) to be changed from default before calls? ary_subL_splitSeparate_subLL IS OP ary subL - recursively separate ary where sub occurs, sub separate ary_subP_splitSeparateTo_mididxs_subL IS OP ary subP - split ary, return [idxs, aryAst] ary_sub_splitAtFront_subL IS OP ary sub - splits ary at each point that sub occurs sub in aryAOut combined with next item ary_subL_splitAtFront_subL IS OP ary subL - iteratively split ary at each point that a sub of subL occurs ary_sub_splitAtEnd_subL IS OP ary sub - split ary where sub occurs, sub @end of each split ary_subL_splitAtEnd_subLL IS OP ary subL - iteratively split ary at each point that a sub of subL occurs ary_subP_splitReplace_subL IS OP ary subP - splits ary at each subOld, then replace subOld with subNew ary_subP_splitLftRgtTo_mididxs_subL IS OP ary subP - split ary, return [idxs, aryL] +-----+ cut [itm, slc, sub] - aryOut of different shape : ary_itm_cut_subL IS OP ary itm - cut ary at each itm, omitting itm, returns a array! ary_itmL_cut_subLL IS OP ary itmL - cut a ary at each itm, omitting itm, returns a array! aryA_itmL_cut_subLLL IS OP aryA itmL - cut each aryA by all itmL, omitting itmL note that a character list is just a ary, but I use "itmL" to emphasize that each itm cuts ary_itmA_cut_subL IS OP ary itmA - cut each itmA, remainder of ary as LIST by order of occurence ary_width_cut_subL IS OP ary width - cut ary into subs of equal length broken on word boundaries ary_sub_cut_subL IS OP ary sub - splits ary at each point that sub occurs, omit sub note that bool values must be tru (l) for itms to be cut! (see bolL_opt_cull_lst) IF flag_break THEN BREAK ; ENDIF ; +-----+ get [itm, slc, sub] - aryOut of different shape : ary_itmP_get_sub ary itmP - generate indices to select a region of an array ary_itmPL_get_sub IS OP ary itmPL - select a region of an array ary_getBefore_sub IS OP ary sub - extract ary itms before sub, null if sub not in ary sub does not have to be a slice of ary ary_getAfter_sub IS OP ary sub - extract ary itms after sub, null if sub not in ary sub does not have to be a slice of ary ary_getBetween_slcP IS OP ary slcP - recursive? list from between slcPA, WRONG! - needs work items are ~= like a chr in a str, 14Nov2021 WRONG - need to fix ary_getBetween_subP IS OP ary subP - extracts subs between [lstStrt,lstEndr] screws up! - needs fixing... DUPLICATE OF ary_getBetween_subP? ary_getExSlc_itmL IS OP ary itmL - cut a ary at each itm, omitting itm, returns a array! aryA_getExcSlc_itmL IS OP aryA itmL - cut each aryA by including itmL, omitting non-itmL, ??lists only (not arys, maybe generalize to arrays (several years hence))?? note that a character list is just a ary, but I use "itmL" to emphasize that each itm cuts ary_getL_slc IS OP ary slc - get list of slc in order of occurence, drop other content for an itmL -> relative position information may be important in the result!! aryA_get_idxOdd IS OP aryA - useful for inclusion in a list of aryA for [terminal, file] output ary_slc_get_idxOdd IS OP ary slc - useful for [terminal, file] output ary_width_padItm_get_aryL IS OP ary width padItm - get fixed length (width) from start of str, pad end with padChr to make length if needed (padChr = [null] for no pad) +-----+ insert [itm, slc, sub] - aryOut of different shape : ary_sub_slc_insert_aryOut IS OP ary sub slc - insert sub into ary at index slc sub must be "[all-full-but-[one or none]]" of ary, matching slc index must add sub items if (shape sub < shape slc) aryA_slc_axs_insertBetweenThenLink_aryOut IS OP aryA slc axs - insert slc into aryA @ Axsidx slc must be a "full slice" of ary!!, subs are NOT adequate! aryA_sub_insertBetweenThenLink_aryOut IS OP aryA sub - link (insert sub between aryA items) +-----+ pad with slc - aryOut of different shape : if ary_length >= len, returns ary often used for zero-prepadding numbers to get constant ary length slc must be a "full slice" of ary!!, subs are NOT adequate! ary_slc_length_prepad_aryOut IS OP ary slc length - augment ary to length by prepadding with slc ary_slcL_length_prepad_aryOut IS OP ary slcL length - prepads ary with slcs to get length ary_itm_length_prepad_aryOut IS OP ary itm length - prepads ary with itms to get length ary_slc_length_postpad_aryOut IS OP ary slc length - postpads ary with slcs to get length ary_itm_length_postpad_aryOut IS OP ary itm length - postpads ary with itms to get length +-----+ put [itm, slc, sub] - aryOut of SAME shape, replaces current (unknown) with [itm, slc, sub] (nothing yet) : +-----+ replace [itm, slc, sub] - aryOut of SAME shape : ary_itmP_replace_aryOut IS OP ary itmP - put all itmOld by itmNew in ary ary_subP_replace_aryOut IS OP ary subP - substitutes subNew for subOld in ary insert must be a full slice, not a lesser sub ary_subPL_replaceAll_aryOut IS OP ary subPL - lstOld is putd by lstNew in ary, for all ??21Nov2021 I'm lost!!) +-----+ [sort, cull] aryL - 02Dec2021 not converted from str to ary optr yet! aryA_sortupOn1st IS OP aryA - EACH sortup set of aryL based on first array aryA_sortupOn_col IS OP colNum aryA - EACH sortup set of aryL based on colNum aryA_sortupCullOn1st IS OP aryA - EACH [sortup,cull] set of aryL based on first array Cull QNial Definition - cull IS OPERATION A {­ grid A EACHLEFT in (A EACHLEFT find A) subarray A } strPL_sortCullUnique IS OP strPairL - sort, then cull to get a unique array of strPairs ordering matters : (str1 str2) ~= (str2 str1) aryPL_sortCullUnique IS OP strPairL - sort, then cull to get a unique array of strPairs ordering matters : (str1 str2) ~= (str2 str1) +-----+ cull [itm, option] ["hold, "cut, "get] : ary_itm_option_cull_aryOut IS OP ary itm option - cull ary with itm, according to option option "hold returns a linked ary, ["cut, "get] return a aryA ary_itmL_opt_cull_aryOut IS OP ary itmL option - cull ary with itmL, according to option option "hold returns a linked ary, ["cut, "get] return a aryA aryA_itmL_option_cull_aryOutL IS OP aryA itmL option - cut each aryA by all itmL, omitting itmL note that a character array is just a ary, but I use "itmL" to emphasize that each itm cuts +-----+ Tables, titles - tables are 2D arys with [row, col] titles can't use characters as titles! use one-char phrases instead especially useful for symbol tablesd - reduce # of global variables and "cross-over" problems assumes [row, col]TitL itms are unique all 'get_subTbl' optrs retain titles (eg for 2D : col 0, row 0) 27Aug2022 PROBLEM at present : only handles 2D tables, should be generalised!! should actually use ary optrs for much of this (conceptually open the vista & vision) nCols_labldDat_make_tbl IS OP nCols labldDat - res ipsa loqitor don't remember what labldDat was (from loaddef of something?) tbl_get_titLL IS 0 pick - trivial expression that "hides" structure, allows flexibility tbl_get_tblDat IS 1 pick - trivial expression that "hides" structure, allows flexibility tbl_get_tblDat_titLL IS pass - trivial expression that "hides" structure, allows flexibility normally, just use tblDat titLL := tbl tbl_keyAxiTit_selAxiTitL_get_itmLL IS OP tbl keyAxiTit selAxiTitL - keyTit=null selects ALL itms in selAxiTitL as yet unknown implications of non-[key, sel] axis (included, but), will have to think about it... tbl_keyAxiTit_selAxiTitL_put_itmLL IS OP tbl keyAxiTit selAxiTitL - keyTit=null selects ALL itms in selAxiTitL tbl_axiIdxL_keyL_get_subTbl IS OP tbl axiIdxL keyL - returns a subTbl of key-selected cols as [row, col]TitL will be more common, this simply calls tbl_[row, col]TitL_key_get_subTbl tbl_titLL_get_sub IS OP tbl titLL keyL - returns subTbl from titLL, then with key in axiIdxHyperPlane assumes that tbl_titLL_check has been run, so data is consistent titL=null (part of titLL) retains all axiIdxs for that axis remember : [row, col]TitL are LISTS, if only one returned it is in form of a solitary tbl_keyTitLL_keyItmL_get_adrL IS OP tbl keyTitLL keyItmL - returns an idxLL of keyItmL hits assumes that args are consistent - use _chk to ensure this!! (keyTitL = null) returns ALL idxs of key in tbl, keyTit (for any axis) ignores that axis make sure that single-arg [keyTitLL, keyItmL] are solitaries (protect [str, ary, list, etc] titles) tbl_keyTitLL_keyItmL_get_sub IS OP tbl keyTitLL keyItmL - returns a subTbl showing only hyperPlanes for keyItmL hits assumes that args are consistent - use _chk to ensure this!! make sure that single-arg [keyTitLL, keyItmL] are solitaries (protect [str, ary, list, etc] titles) tbl_make_tblWhole IS OP tbl - human-readable table output, 2D tblWholes ONLY! tbl_writeParts IS OP tbl - res ipsa loqitor tbl_writeSolPassCells IS OP tbl - output table with cells of [solitary, pass] value tblDat_titLL_make_tbl IS OP tblDat titLL - trivial error checks : see tblDat_titLL_compatible in "$d_Qndfs"'types.ndf' tblWhole_make_tbl IS OP tbl - trivial split whole (unified for output) tbl into 2 parts +-----+ Database queries (sort of), see also tables - previous section QNial roster database model : "$d_Qroot"'Qnial_bag/aitools/roster/' ary_posnACommon1stItmIdxL IS OP ary - finds indexs of common items in an ary (by defn TOP level) aryL_keyLIdx_cullSort IS OP aryL keyLIdx - returns arrayList, sorted by common-keys, as per keyLIdx aryL_extractMulplicate_subArys IS OP selectOp aryList - find mulplicates in aryN by selectOp actually, should work with any array type (in form of list), including aryNs 29May2021 - no good for general use, use aryL_keyLIdx_cullSort +-----+ transformers - normal TRANSFORMERs, as well as "generalised transformer" (OPERATORs) aryInn_putWith_aryOut IS OP aryInn aryOut - useful for "general transformers" (optrs with optrPhrs) I was thinking of replacing [atom, str]s in nested arys at the time ... normally just use aryOut := aryInn, which won't help in transformers opPhr_ary_LEAFputWith_aryStatic IS OP optrPhr ary aryStatic - LEAF_aryInn_aryStatic IS TRANSFORMER f OPERATION aryInnStaticPair - # 24************************24 # ToDos # # 21Apr2022 should ary_sub_find_idx1stL faults be returned as a list # to be constent with other optrs? (NO! - cannot rely on solitary lists, use ary_hasFaults) # 01Sep2022 for valence > 2, the [row, col] title concept implies separate lists # optrs should be redesigned for this - more efficient too # # 24************************24 #] Warnings and notes # xxx_chkFor_ary_apply_optrPhr forces proper [idx, sub] valence (not for itm) # provides error-tracking faults # then it checks [idx,itm,sub] compatibility with ary # default axis augmentation (if necessary) is to higher dimensions # where n_axisAdd := - EACH valence ary sub : # gage shape resFltL := link (gage shape ary) ((gage shape sub) link (n_AxisAdd reshape 1)) # faultL if [not found, other reasons], 10Apr2022 actually returns null if not found (should be fault?) # As QNial is an array-oriented language, it has extremely powerful built-in capabilities. # This obviates most of the need for [chr, str, lst, tbl, etc]-specific optrs. # It is best to learn to work in as [high a dimension, deep a nesting] as practical (or won't learn) # My work below comprises very simple arrangements for simple tasks, with some built-in checks. # www.BillHowell.ca 14Apr2020 initial # some Howell optrs date from late 1980's? # 2014-15 'matrix operations - symbolic & real-valued.ndf' # Apr2022 [posn, slice, etc] optrs below, although I did earlier stuff too, nomenclature ripped up! # 11Feb2022 many operatornew and not well defined, or just ghosts, ds much more [work, test]s # view this file in a text editor, with [constant width font, tab = 3 spaces], no line-wrap # see "$d_Qndfs"'arrays.ndf' # "$d_Qndfs"'array notes.txt' # "$d_Qtest"'array- tests.ndf' # "$d_Qtest"'array- test results log.txt" # "$d_Qndfs"'types.ndf' # slc - "[all-full-but-[one or none]]" INDEX of an array # sub - is a sequence of items at the top level of an array, note that a sub can span [one, more, all] Axs # not much use for a separate subSlc of an array - just use sub optrs # [cut, put] - require slc of an array, often built from search for a subAry, # put something in non-sub parts of slc # split - requires a hyper-plane index as a specific place to split ary #] +-----+ # 24************************24 # enddoc