Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomlogo committed Mar 10, 2024
1 parent 3e44375 commit 8a1e8fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
7 changes: 1 addition & 6 deletions flax/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,7 @@ def type2strn(x):

def transpose(x, filler=None):
"""transpose: transpose x"""
return list(
map(
lambda x: list(filter(None.__ne__, x)),
itertools.zip_longest(*map(iterable, x), fillvalue=filler),
)
)
return [[j for j in i if j is not None] for i in itertools.zip_longest(*[iterable(i) for i in x], fillvalue=filler)]


def trim(w, x):
Expand Down
26 changes: 20 additions & 6 deletions test/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,30 @@ def test_convolve():
def test_depth():
assert depth(0) == 0
assert depth("string") == 1
assert depth([]) == 0
assert depth([]) == 1
assert depth([1]) == 1
assert depth([[[1]], 1, 3]) == 3


"test_diagonal_leading"
"test_diagonal_trailing"
"test_diagonals"
"test_digits"
"test_digits_i"
def test_diagonal_leading():
assert diagonal_leading([[1,0,2],[2,3,4],[5,6,7]]) == [1,3,7]

def test_diagonal_trailing():
assert diagonal_trailing([[1,0,2],[2,3,4],[5,6,7]]) == [2,3,5]

def test_diagonals():
assert diagonals([[1,2,3],[4,5,6],[7,8,9]]) == [[1], [4, 2], [7, 5, 3], [8, 6], [9]]
assert diagonals([[1,2,3],[4,5,6],[7,8,9]], antidiagonals=True) == [[7], [4, 8], [1, 5, 9], [2, 6], [3]]

def test_digits():
assert digits(123) == [1, 2, 3]
assert digits(3.1415) == [3,1,4,1,5]
assert digits(mpc(123,456)) == [mpc(1,4), mpc(2,5), mpc(3,6)]

def test_digits_i():
assert digits_i([3,1,4,1,5]) == 31415
assert digits_i([mpc(1,4), mpc(2,5), mpc(3,6)]) == mpc(123,456)

"test_enumerate_md"
"test_ensure_square"
"test_fibonacci"
Expand Down

0 comments on commit 8a1e8fc

Please sign in to comment.