Skip to content
Snippets Groups Projects
Select Git revision
  • 6209c0da2f12129cf2e291885f6d45810ebbfefd
  • 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_stencils.py

Blame
  • Markus Holzer's avatar
    Markus Holzer authored and Michael Kuron committed
    70b77136
    History
    test_stencils.py 1.11 KiB
    import pystencils as ps
    import sympy as sp
    
    from pystencils.stencil import coefficient_list, plot_expression
    import pystencils.plot as plt
    
    
    def test_coefficient_list():
        f = ps.fields("f: double[1D]")
        expr = 2 * f[1] + 3 * f[-1]
        coff = coefficient_list(expr)
        assert coff == [3, 0, 2]
        figure = plt.figure()
        plot_expression(expr, matrix_form=True, figure=figure)
    
        f = ps.fields("f: double[3D]")
        expr = 2 * f[1, 0, 0] + 3 * f[0, -1, 0]
        coff = coefficient_list(expr)
        assert coff == [[[0, 3, 0], [0, 0, 2], [0, 0, 0]]]
    
        expr = 2 * f[1, 0, 0] + 3 * f[0, -1, 0] + 4 * f[0, 0, 1]
        coff = coefficient_list(expr, matrix_form=True)
        assert coff[0] == sp.zeros(3, 3)
    
        # in 3D plot only works if there are entries on every of the three 2D planes. In the above examples z-1 was empty
        expr = 2 * f[1, 0, 0] + 1 * f[0, -1, 0] + 1 * f[0, 0, 1] + f[0, 0, -1]
        figure = plt.figure()
        plot_expression(expr, figure=figure)
    
    
    def test_plot_expression():
        f = ps.fields("f: double[2D]")
        figure = plt.figure()
        plot_expression(2 * f[1, 0] + 3 * f[0, -1], matrix_form=True, figure=figure)