Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Representations #867

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
377e65b
fix error messages
gertjanvanzwieten Apr 18, 2024
bd6444b
introduce _util.reentrant_iter
gertjanvanzwieten Feb 23, 2024
1ae23a6
introduce _util.iter_product
gertjanvanzwieten Mar 13, 2024
21c87b7
introduce util.iter_many
gertjanvanzwieten Apr 19, 2024
ce780d3
introduce Pointwise linear, zero_preserving attrs
gertjanvanzwieten Apr 18, 2024
f996885
add representations
gertjanvanzwieten Mar 13, 2024
ec3d180
add helper methods
gertjanvanzwieten Apr 18, 2024
291eedd
reimplement shape_str using representations
gertjanvanzwieten Mar 5, 2024
ed5d8c2
reimplement unalign using representations
gertjanvanzwieten Mar 5, 2024
624969f
separate optimize from simplify
gertjanvanzwieten Apr 10, 2024
2e54014
temporarily add Transpose._rinflate
gertjanvanzwieten Apr 19, 2024
ed580eb
remove _takediag
gertjanvanzwieten Apr 18, 2024
de700f6
remove _take, _rtake
gertjanvanzwieten Apr 18, 2024
e72b445
remove _sum
gertjanvanzwieten Apr 18, 2024
6779093
remove _determinant
gertjanvanzwieten Apr 18, 2024
0b314b0
remove _product
gertjanvanzwieten Apr 18, 2024
40537da
remove _unravel
gertjanvanzwieten Apr 18, 2024
7b90979
remove _inverse
gertjanvanzwieten Apr 18, 2024
8a257f7
remove _power
gertjanvanzwieten Apr 18, 2024
e8db610
remove _sign
gertjanvanzwieten Apr 18, 2024
f367c06
remove _loopsum
gertjanvanzwieten Apr 18, 2024
786ee3a
remove _add
gertjanvanzwieten Apr 18, 2024
6f5cdc5
remove _multiply
gertjanvanzwieten Apr 18, 2024
c5a50de
remove _transpose
gertjanvanzwieten Apr 18, 2024
e7d63ac
remove _diagonalize
gertjanvanzwieten Apr 18, 2024
d608030
remove _inflate, _rinflate
gertjanvanzwieten Apr 18, 2024
c20a341
remove _insertaxis
gertjanvanzwieten Apr 18, 2024
a23abce
remove _ravel
gertjanvanzwieten Apr 18, 2024
d52dc0f
remove _real, _imag, _conjugate
gertjanvanzwieten Apr 18, 2024
c44e56f
remove _eig
gertjanvanzwieten Apr 18, 2024
b85caed
streamline LoopConcatenate._simplified
gertjanvanzwieten Apr 18, 2024
b759efa
streamline Polyval._simplified
gertjanvanzwieten Apr 18, 2024
849a6e9
streamline Pointwise._simplified
gertjanvanzwieten Apr 18, 2024
16ab248
streamline Legendre._simplified
gertjanvanzwieten Apr 19, 2024
b6931ee
enhance PolyMul._simplified
gertjanvanzwieten Apr 19, 2024
38e44c5
enhance PolyGrad._simplified
gertjanvanzwieten Apr 19, 2024
6a6add4
add RavelIndex._simplified
gertjanvanzwieten Apr 18, 2024
182378a
remove Multiply._factors
gertjanvanzwieten Apr 18, 2024
ab7183b
remove Add._terms
gertjanvanzwieten Apr 18, 2024
5b671f6
remove unused methods, attributes
gertjanvanzwieten Mar 4, 2024
01cf78a
remove defunct diagnostics
gertjanvanzwieten Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions nutils/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,4 +1082,72 @@ def shallow_replace(func, *funcargs, **funckwargs):
return rstack[0]


class reentrant_iter:

def __init__(self, iterable):
self.iterator = iter(iterable)
self.items = []

def __iter__(self):
return self.Iter(self.iterator, self.items)

class Iter:
def __init__(self, iterator, items):
self.iterator = iterator
self.items = items
self.index = 0
def __iter__(self):
return self
def __next__(self):
if self.index == len(self.items):
v = next(self.iterator)
assert self.index == len(self.items)
self.items.append(v)
else:
v = self.items[self.index]
self.index += 1
return v

@classmethod
def property(cls, f):
return functools.cached_property(lambda self: cls(f(self)))


def iter_product(iter1, iter2):
iter1 = iter(iter1)
iter2 = iter(iter2)
try:
item1 = next(iter1)
item2 = next(iter2)
except StopIteration:
return
yield item1, item2
items1 = [item1]
items2 = [item2]
try:
for item1 in iter1:
items1.append(item1)
items2.append(next(iter2))
yield from zip(reversed(items1), items2)
except StopIteration:
del items1[0]
yield from zip(reversed(items1), items2)
for item1 in iter1:
del items1[0]
items1.append(item1)
yield from zip(reversed(items1), items2)
else:
for item2 in iter2:
del items2[0]
items2.append(item2)
yield from zip(reversed(items1), items2)
for i in range(1, len(items2)):
yield from zip(reversed(items1), items2[i:])


def iter_many(iters):
iter0, *rem = iters
return ((v, *w) for v, w in iter_product(iter0, iter_many(rem))) if rem else ((v,) for v in iter0)


# vim:sw=4:sts=4:et
Loading
Loading