Skip to content
Snippets Groups Projects
Select Git revision
  • 2afaf558e59197094cbb4addf65b13837ba04ca2
  • 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

conftest.py

Blame
  • test_index_kernels.py 1.10 KiB
    import pytest
    
    import sympy as sp
    import numpy as np
    
    from pystencils import Assignment, Field, FieldType, AssignmentCollection
    from pystencils.nbackend.kernelcreation import create_kernel, KernelCreationOptions
    from pystencils.cpu.cpujit import compile_and_load
    
    def test_indexed_kernel():
        arr = np.zeros((3, 4))
        dtype = np.dtype([('x', int), ('y', int), ('value', arr.dtype)])
        index_arr = np.zeros((3,), dtype=dtype)
        index_arr[0] = (0, 2, 3.0)
        index_arr[1] = (1, 3, 42.0)
        index_arr[2] = (2, 1, 5.0)
    
        index_field = Field.create_from_numpy_array('index', index_arr, field_type=FieldType.INDEXED)
        normal_field = Field.create_from_numpy_array('f', arr)
        update_rule = AssignmentCollection([
            Assignment(normal_field[0, 0], index_field('value'))
        ])
    
        options = KernelCreationOptions(index_field=index_field)
        ast = create_kernel(update_rule, options)
        kernel = compile_and_load(ast)
    
        kernel(f=arr, index=index_arr)
    
        for i in range(index_arr.shape[0]):
            np.testing.assert_allclose(arr[index_arr[i]['x'], index_arr[i]['y']], index_arr[i]['value'], atol=1e-13)