Skip to content

Commit

Permalink
Added Awkward equivalent of some ROOT functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan26roy committed Jan 2, 2024
1 parent 2612ef3 commit db9b24a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/formulate/AST.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ def to_python(self):
return "np.pi"
case "e":
return "np.exp(1)"
case "e":
return "np.exp(1)"
case _ :
raise ValueError("Not a valid function!")

# come-up with a shared notation for functions
# make a to_python function

41 changes: 41 additions & 0 deletions src/formulate/func_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#maybe use num

def root_length(array):
import awkward as ak
while array.layout.purelist_depth > 2:
array = ak.flatten(array, axis=-1)
return ak.count(array, axis=-1)


def root_sum(array):
import awkward as ak
while array.layout.purelist_depth > 2:
array = ak.flatten(array, axis=-1)
return ak.sum(array, axis=-1)


def root_min(array):
import awkward as ak
while array.layout.purelist_depth >= 2:
array = ak.min(array, axis=-1)
return ak.fill_none(array, 0)



def root_max(array):
import awkward as ak
while array.layout.purelist_depth >= 2:
array = ak.max(array, axis=-1)
return ak.fill_none(array, 0)


def root_min_if(array, condition):
import awkward as ak
array = array[condition != 0]
return ak.fill_none(ak.min(array,axis=1),0)

def root_max_if(array, condition):
import awkward as ak
array = array[condition != 0]
return ak.fill_none(ak.max(array,axis=1),0)
4 changes: 2 additions & 2 deletions src/formulate/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


UNARY_OP = {"pos", "neg", "binv", "linv"}
with_sign = {}

BINARY_OP = {
"add",
"sub",
Expand Down Expand Up @@ -59,7 +59,7 @@
FUNC_MAPPING = {
"MATH::PI": "pi", #np.pi
"MATH::E": "e",
"LENGTH$": "no_of_entries", #
"LENGTH$": "no_of_entries", #ak.num, axis = 1
"ITERATION$": "current_iteration",
"SUM$": "sum",
"MIN$": "min",
Expand Down

0 comments on commit db9b24a

Please sign in to comment.