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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
remove _product
gertjanvanzwieten committed Apr 19, 2024
commit 0b314b0ce5d295fdf25ce9d0c822e4e746f49736
46 changes: 12 additions & 34 deletions nutils/evaluable.py
Original file line number Diff line number Diff line change
@@ -858,7 +858,6 @@ def _node(self, cache, subgraph, times):
_add = lambda self, other: None
_inverse = lambda self, axis1, axis2: None
_diagonalize = lambda self, axis: None
_product = lambda self: None
_sign = lambda self: None
_eig = lambda self, symmetric: None
_inflate = lambda self, dofmap, length, axis: None
@@ -1062,9 +1061,6 @@ def _inverse(self, axis1, axis2):
value = numpy.transpose(self.value, axes)
return constant(numpy.transpose(Inverse.evalf(value), numpy.argsort(axes)))

def _product(self):
return constant((numpy.all if self.dtype == bool else numpy.prod)(self.value, -1))

def _multiply(self, other):
if self._isunit:
return other
@@ -1158,9 +1154,6 @@ def evalf(func, length):
def _derivative(self, var, seen):
return insertaxis(derivative(self.func, var, seen), self.ndim-1, self.length)

def _product(self):
return self.func if self.dtype == bool else self.func**astype(self.length, self.func.dtype)

def _power(self, n):
unaligned1, unaligned2, where = unalign(self, n)
if len(where) != self.ndim:
@@ -1425,10 +1418,6 @@ def _unravel(self, axis, shape):
axes.insert(axis+1, orig_axis+1)
return transpose(tryunravel, tuple(axes))

def _product(self):
if self.axes[-1] == self.ndim-1:
return Transpose(Product(self.func), self.axes[:-1])

def _inverse(self, axis1, axis2):
tryinv = self.func._inverse(self.axes[axis1], self.axes[axis2])
if tryinv:
@@ -1505,7 +1494,18 @@ def representations(self):
def _simplified(self):
if _equals_scalar_constant(self.func.shape[-1], 1):
return get(self.func, self.ndim, constant(0))
return self.func._product()
if simple := self._as_any(constant, insertaxis, multiply, IntToFloat, FloatToComplex):
return simple
for f, axis, newaxis in self.func._as(diagonalize):
if newaxis == f.ndim or axis == f.ndim-1:
# TODO what if func.shape[-1] is not constant 1 but _may_ be one
return zeros_like(self)
for f, axis in self.func._as(ravel):
if axis == f.ndim-2:
return Product(Product(f))
for f, axis, length in self.func._as(insertaxis):
if axis == self.ndim:
return f if self.dtype == bool else f**astype(length, self.dtype)

def _derivative(self, var, seen):
grad = derivative(self.func, var, seen)
@@ -1717,9 +1717,6 @@ def _add(self, other):
# all situations an improvement.
return zeros_like(self)

def _product(self):
return multiply(*[Product(f) for f in self._factors])

def _derivative(self, var, seen):
func1, func2 = self.funcs
return einsum('A,AB->AB', func1, derivative(func2, var, seen)) \
@@ -2932,9 +2929,6 @@ def _multiply(self, other):
if isinstance(other, __class__):
return self._newargs(self.args[0] * other.args[0])

def _product(self):
return self._newargs(product(self.args[0], -1))

def _sign(self):
assert self.dtype != complex
return self._newargs(sign(self.args[0]))
@@ -2958,9 +2952,6 @@ def _multiply(self, other):
if isinstance(other, __class__):
return self._newargs(self.args[0] * other.args[0])

def _product(self):
return self._newargs(product(self.args[0], -1))

def _real(self):
return self.args[0]

@@ -3489,10 +3480,6 @@ def _unravel(self, axis, shape):
def _sign(self):
return Diagonalize(Sign(self.func))

def _product(self):
if numeric.isint(self.shape[-1]) and self.shape[-1] > 1:
return Zeros(self.shape[:-1], dtype=self.dtype)

def _loopsum(self, index):
return Diagonalize(loop_sum(self.func, index))

@@ -3785,9 +3772,6 @@ def _power(self, n):
def _sign(self):
return Ravel(Sign(self.func))

def _product(self):
return Product(Product(self.func))

def _loopsum(self, index):
return Ravel(loop_sum(self.func, index))

@@ -4355,12 +4339,6 @@ def _multiply(self, other):
def _get(self, i, item):
return Choose(get(self.index, i, item), *(get(choice, i, item) for choice in self.choices))

def _product(self):
unaligned, where = unalign(self.index)
if self.ndim-1 not in where:
index = align(unaligned, where, self.shape[:-1])
return Choose(index, *map(Product, self.choices))


class NormDim(Array):