This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Support for functional programming capabilities in Chapel | |
| Provides a different number of generators and iterators inspired | |
| by Python, and other functional programming languages: APL, Haskell, Scala. | |
| */ | |
| module functional { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Sort; | |
| var sentialPermutation = [42]; | |
| // return true if the two arrays are equal | |
| proc isEqual(a, b) : bool { | |
| for (i, j) in zip(a,b) { | |
| if i != j { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Sort; | |
| var sentialPermutation = [42]; | |
| // return true if the two arrays are equal | |
| proc isEqual(a, b) : bool { | |
| for (i, j) in zip(a,b) { | |
| if i != j { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private use Map only; | |
| private use List only; | |
| private use Crypto only; | |
| record ordered_map { | |
| /* Type of map keys.*/ | |
| type keyType; | |
| /* Type of map values*/ | |
| type valType; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use RangeChunk only; | |
| // serial | |
| iter starmap(array, function) { | |
| var iterable = array; | |
| for i in iterable { | |
| yield function((...i)); // tuple expansion ... THANK YOU CHAPEL | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private use Map only; | |
| private use List only; | |
| private use Crypto only; | |
| record ordered_map { | |
| /* Type of map keys.*/ | |
| type keyType; | |
| /* Type of map values*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use RangeChunk; | |
| // serial | |
| iter count(start: int, step: int, end: int) { | |
| for i in start..end by step do | |
| yield i; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Sort; | |
| // partitioning between tasks algorithms | |
| // we need to get ALL the permutations of [1,2,3,4,5] so we know | |
| // that if we generate them in lexicographical order we would have | |
| // [1, 2, 3, 4, 5] as the first permutation and [5, 4, 3, 2, 1] as the last permutation | |
| // the partition function do the following: | |
| // assume we have 4 tasks we need to distribute the whole lexicographical range of all permutations | |
| // into 4 intervals. so assume we insert arr to be [1,2,3,4,5] and numOfTasks to 4 tasks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var tobeAdded = (1,2,3); // this would be the input to the partial object | |
| proc adds(a:int, b:int, c:int, d:int) { // this is the function which we want to have 10 as constant input | |
| return a+b+c+d; // and vary the value of "b", "c", "d" | |
| } | |
| var constant = 10; // this is "a" | |
| writeln(adds(constant,(...tobeAdded))); // a is constant and b, c, d are filled from the expanded tuple |
OlderNewer