Skip to content
Snippets Groups Projects
Select Git revision
  • d065462537241f2a60ab834743f34224d7b2101c
  • master default protected
  • v2.0-dev protected
  • zikeliml/Task-96-dotExporterForAST
  • zikeliml/124-rework-tutorials
  • fma
  • fhennig/v2.0-deprecations
  • holzer-master-patch-46757
  • 66-absolute-access-is-probably-not-copied-correctly-after-_eval_subs
  • gpu_bufferfield_fix
  • hyteg
  • vectorization_sqrt_fix
  • target_dh_refactoring
  • const_fix
  • improved_comm
  • gpu_liveness_opts
  • release/1.3.7 protected
  • release/1.3.6 protected
  • release/2.0.dev0 protected
  • release/1.3.5 protected
  • release/1.3.4 protected
  • release/1.3.3 protected
  • release/1.3.2 protected
  • release/1.3.1 protected
  • release/1.3 protected
  • release/1.2 protected
  • release/1.1.1 protected
  • release/1.1 protected
  • release/1.0.1 protected
  • release/1.0 protected
  • release/0.4.4 protected
  • last/Kerncraft
  • last/OpenCL
  • last/LLVM
  • release/0.4.3 protected
  • release/0.4.2 protected
36 results

test_address_of.py

Blame
  • test_address_of.py 1.53 KiB
    """
    Test of pystencils.data_types.address_of
    """
    import pytest
    import pystencils
    from pystencils.typing import PointerType, CastFunc, BasicType
    from pystencils.sympyextensions.pointers import AddressOf
    from pystencils.simp.simplifications import sympy_cse
    
    import sympy as sp
    
    
    def test_address_of():
        x, y = pystencils.fields('x, y: int64[2d]')
        s = pystencils.TypedSymbol('s', PointerType(BasicType('int64')))
    
        assert AddressOf(x[0, 0]).canonical() == x[0, 0]
        assert AddressOf(x[0, 0]).dtype == PointerType(x[0, 0].dtype, restrict=True)
        with pytest.raises(ValueError):
            assert AddressOf(sp.Symbol("a")).dtype
    
        assignments = pystencils.AssignmentCollection({
            s: AddressOf(x[0, 0]),
            y[0, 0]: CastFunc(s, BasicType('int64'))
        })
    
        kernel = pystencils.create_kernel(assignments).compile()
        # pystencils.show_code(kernel.ast)
    
        assignments = pystencils.AssignmentCollection({
            y[0, 0]: CastFunc(AddressOf(x[0, 0]), BasicType('int64'))
        })
    
        kernel = pystencils.create_kernel(assignments).compile()
        # pystencils.show_code(kernel.ast)
    
    
    def test_address_of_with_cse():
        x, y = pystencils.fields('x, y: int64[2d]')
    
        assignments = pystencils.AssignmentCollection({
            x[0, 0]: CastFunc(AddressOf(x[0, 0]), BasicType('int64')) + 1
        })
    
        kernel = pystencils.create_kernel(assignments).compile()
        # pystencils.show_code(kernel.ast)
        assignments_cse = sympy_cse(assignments)
    
        kernel = pystencils.create_kernel(assignments_cse).compile()
        # pystencils.show_code(kernel.ast)