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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@omar-3
omar-3 / example10Pipe.chpl
Last active April 1, 2020 02:59
implementation of toolz's pipe method in Chapel
proc notAdd(a: int, b: int) {
return (a + b , a + b);
}
proc notMul(a: int, b: int) {
return (a*b , a*b);
}
var h = [notAdd, notMul, notAdd, notMul, notAdd];
@omar-3
omar-3 / example10Groupby.chpl
Last active April 5, 2020 07:23
this is an example of python's groupby function in Chapel with 2 using cases
// this method would be super cool in databases for example in a world without GROUP BY sql command :D
use Set;
use List;
use RangeChunk;
// takes iterable of object or any stuff
// function is the thing that is common between multiple
// of some objects in iterable
@omar-3
omar-3 / example9Starmap.chpl
Created March 29, 2020 04:16
this is an implementation for python's starmap method in Chapel
use RangeChunk;
use Time;
// serial
iter starmap(array, function) {
var iterable = array; // I know that I don't need to copy "array" to new variable "iterable"
for i in iterable {
yield function((...i));
@omar-3
omar-3 / example8Filter.chpl
Created March 29, 2020 03:50
this is an implementation for python's filter method in Chapel
use RangeChunk;
use Time;
iter filter(array, function) {
for i in array {
if function(i) {
yield i;
}
}
}
@omar-3
omar-3 / example7Dropwhile.chpl
Created March 29, 2020 03:17
Implementation of python's dropwhile() method in chapel
use RangeChunk;
use Time;
iter dropwhile(array, function) {
var iterable = array;
var barrier = false;
for i in iterable {
if function(i){
barrier = true;
}
@omar-3
omar-3 / example6Chain.chpl
Last active March 29, 2020 02:53
implementation of python's chain() method in Chapel
use RangeChunk;
iter compress(array, trutharray) {
for (i,j) in zip(array, trutharray) {
if j {
yield i;
}
}
}
@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

@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 / 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