Skip to content

Instantly share code, notes, and snippets.

View omar-3's full-sized avatar
🔫
was serving in military for a year

Omar omar-3

🔫
was serving in military for a year
View GitHub Profile
@omar-3
omar-3 / functional.chpl
Last active April 10, 2020 06:45
a very very short itertools-ish module
/* 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 {
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 {
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 {
@omar-3
omar-3 / LRU_caching.chpl
Created March 18, 2020 21:45
a very not-merged-pull-request implementation for lru_cache utility from fuctools in Chapel
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;
@omar-3
omar-3 / example1StarMap.chpl
Created March 27, 2020 00:46
serial and parallel implementation of iterator starmap in Chapel
use RangeChunk only;
// serial
iter starmap(array, function) {
var iterable = array;
for i in iterable {
yield function((...i)); // tuple expansion ... THANK YOU CHAPEL
}
}
@omar-3
omar-3 / example2LRU_Cache.chpl
Last active April 1, 2020 00:21
A very simple implementation of LRU caching utility like the one in python functools
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*/
@omar-3
omar-3 / example3COUNT.chpl
Last active April 2, 2020 17:16
why don't you just use range? :")
use RangeChunk;
// serial
iter count(start: int, step: int, end: int) {
for i in start..end by step do
yield i;
}
@omar-3
omar-3 / example4Permutations.chpl
Last active April 14, 2020 02:19
generating permutations in lexicographic order in serial and parallel fashion
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
@omar-3
omar-3 / example5NotPartial.chpl
Last active March 29, 2020 20:49
not implementation for partial object utility in python
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
@omar-3
omar-3 / first_draft.md
Last active April 3, 2020 12:16
My GSoC 2020 proposal for Chapel Programming Language

Functional Programming Module

This proposal is an extension to itertools project, in which I propose an implementation for a complete-ish functional programming module, with consideration of the current state of Chapel compiler.

Table of contents