Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/yateto-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Codegen Tests
run: |
cd ./tests/code-gen
for example in matmul minimal; do
for example in matmul minimal expression; do
for build_type in Debug Release; do
for precision in single double; do
echo " ====== Test Config: ======"
Expand Down
2 changes: 1 addition & 1 deletion tests/code-gen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(EXAMPLES "matmul;minimal" CACHE STRING "a list of examples to run as tests")
set(SAMPLES hosvd matmul minimal seissol_eqspp stock tce)
set(SAMPLES hosvd matmul minimal seissol_eqspp stock tce expression)
set_property(CACHE EXAMPLES PROPERTY STRINGS ${SAMPLES})

set(VARIANT "Eigen" CACHE STRING "example-specific variant")
Expand Down
16 changes: 16 additions & 0 deletions tests/code-gen/expression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

from yateto import *

def add(g):
n = 32
A = Tensor('A', (n, n))
B = Tensor('B', (n, n))
C = Tensor('C', (n, n))
a = Scalar('a')

g.add('axpy', C['ij'] <= A['ij'] + a * B['ij'])
g.add('axpyNeg', C['ij'] <= A['ij'] - a * B['ij'])

# TODO: add some more simple expression tests here

5 changes: 2 additions & 3 deletions yateto/ast/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def __radd__(self, other):
return self.__add__(other)

def __neg__(self):
self._checkMultipleScalarMults()
return ScalarMultiplication(-1.0, self)
return -1.0 * self
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need to check multiple scalar units here?

Copy link
Copy Markdown
Contributor Author

@davschneller davschneller Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's done via __rmul__ calling __mul__; there we auto-merge with existing scalar multiplications. If we don't have a scalar multiplication, then the old and the new version behave identically (i.e. __mul__ creates a ScalarMultiplication node).
EDIT: that didn't happen so far; nevermind. Both should be completely identical.

The previous implementation (i.e. self._checkMultipleScalarMults()) just aborted at that point instead.

(that said—the case (a * A) * (b * B) should, by tracing the code paths, also still fail with the new version, instead of turning it into (a * b) * A * B or the likes ... Though that might also be rather straight-forward to fix I think)


def __sub__(self, other):
return self._binOp(-other, Add)
Expand Down Expand Up @@ -479,4 +478,4 @@ def nonZeroFlops(self):
return nzFlops

def is_empty(self):
return len(self._children) == 0
return len(self._children) == 0
Loading