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

setup.py

Blame
  • test_field_equality.ipynb 6.29 KiB
    In [1]:
    from pystencils.session import *

    Test field equality behaviour

    Fields create with same parameters are equal

    In [2]:
    f1 = ps.Field.create_generic('f', spatial_dimensions=2, index_dimensions=0)
    f2 = ps.Field.create_generic('f', spatial_dimensions=2, index_dimensions=0)
    
    assert f1 == f2
    In [3]:
    print("Field ids equal in accesses: ", id(f1.center._field) == id(f2.center._field))
    print("Field accesses equal: ", f1.center == f2.center)
    Out [3]:
    Field ids equal in accesses:  True
    Field accesses equal:  True
    
    In [4]:
    f1 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0)
    f2 = ps.Field.create_generic('f', spatial_dimensions=2, index_dimensions=0)
    assert f1 != f2
    In [5]:
    f1 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0)
    f2 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0, dtype=np.float32)
    assert f1 != f2

    Properties of fields:

    • field_type: enum distinguishing normal from index or buffer fields
    • _dtype: data type of field elements
    • _layout: tuple indicating the memory linearization order
    • shape: size of field for each dimension
    • strides: number of elements to jump over to increase coordinate of this dimension by one
    • latex_name: optional display name when field is printed as latex

    Equality compare of fields:

    • field has __eq__ and __hash__ overridden
    • all parameter but latex_name are considered for equality

    Test field access equality behaviour

    In [6]:
    f1 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0)
    f2 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0)
    assert f1.center == f2.center
    In [7]:
    f1 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0)
    f2 = ps.Field.create_generic('f', spatial_dimensions=1, index_dimensions=0, dtype=np.float32)
    assert f1.center != f2.center
    In [8]:
    def print_field_accesses_debug(expr):
        from pystencils import Field
        fas = list(expr.atoms(Field.Access))
        fields = list({e.field for e in fas})
        print("Field Accesses:")
        for fa in fas:
            print(f"   - {fa}, hash {hash(fa)}, offsets {fa._offsets}, index {fa._index}, {fa._hashable_content()}")
        print("")
        for i in range(len(fas)):
            for j in range(len(fas)):
                if not i < j: 
                    continue
                print( f"   -> {i},{j}  {fas[i]} == {fas[j]}: {fas[i] == {fas[j]}}")
        
        print("Fields")
        for f in fields:
            print(f"  - {f}, {id(f)}, shape {f.shape}, strides {f.strides}, {f._dtype}, {f.field_type}, layout {f.layout}")
        print("")
        for i in range(len(fields)):
            for j in range(len(fields)):
                if not i < j: 
                    continue
                print(f"  - {fields[i]} == {fields[j]}: {fields[i] == fields[j]}, ids equal {id(fields[i])==id(fields[j])}, hash equal {hash(fields[i])==hash(fields[j])}")
    In [9]:
    print_field_accesses_debug(f1.center * f2.center)
    Out [9]:
    Field Accesses:
       - f[0], hash -8859424145258271267, offsets (0,), index (), ((('f_C', ('commutative', True), ('complex', True), ('extended_real', True), ('finite', True), ('hermitian', True), ('imaginary', False), ('infinite', False), ('real', True)), 2305067722319023373), ((0,), (_size_f_0,), (_stride_f_0,), <FieldType.GENERIC: 0>, 'f', None, double), 0)
       - f[0], hash -6454673863007224785, offsets (0,), index (), ((('f_C', ('commutative', True), ('complex', True), ('extended_real', True), ('finite', True), ('hermitian', True), ('imaginary', False), ('infinite', False), ('real', True)), 4093629613697528859), ((0,), (_size_f_0,), (_stride_f_0,), <FieldType.GENERIC: 0>, 'f', None, float), 0)
    
       -> 0,1  f[0] == f[0]: False
    Fields
      - f, 4881406800, shape (_size_f_0,), strides (_stride_f_0,), double, FieldType.GENERIC, layout (0,)
      - f, 4881445024, shape (_size_f_0,), strides (_stride_f_0,), float, FieldType.GENERIC, layout (0,)
    
      - f == f: False, ids equal False, hash equal False