From 5541cd0efbbb0080604897e41c04e6db70ed859c Mon Sep 17 00:00:00 2001
From: Christoph Groth <christoph.groth@cea.fr>
Date: Sun, 17 Feb 2019 12:00:03 +0100
Subject: [PATCH] factor out cdef definitions into operator.pxd

This allows subclassing of operators by third party libraries
(e.g. tkwant).
---
 kwant/operator.pxd | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 kwant/operator.pyx | 12 ++----------
 2 files changed, 50 insertions(+), 10 deletions(-)
 create mode 100644 kwant/operator.pxd

diff --git a/kwant/operator.pxd b/kwant/operator.pxd
new file mode 100644
index 00000000..c443b0d9
--- /dev/null
+++ b/kwant/operator.pxd
@@ -0,0 +1,48 @@
+from .graph.defs cimport gint
+from .graph.defs import gint_dtype
+
+
+cdef gint _bisect(gint[:] a, gint x)
+
+cdef int _is_herm_conj(complex[:, :] a, complex[:, :] b,
+                       double atol=*, double rtol=*) except -1
+
+cdef int _check_onsite(complex[:, :] M, gint norbs,
+                       int check_hermiticity) except -1
+
+cdef int _check_ham(complex[:, :] H, ham, args, params,
+                    gint a, gint a_norbs, gint b, gint b_norbs,
+                    int check_hermiticity) except -1
+
+cdef void _get_orbs(gint[:, :] site_ranges, gint site,
+                    gint *start_orb, gint *norbs)
+
+
+cdef class BlockSparseMatrix:
+    cdef public gint[:, :] block_offsets, block_shapes
+    cdef public gint[:] data_offsets
+    cdef public complex[:] data
+
+    cdef complex* get(self, gint block_idx)
+
+
+cdef class _LocalOperator:
+    cdef public int check_hermiticity, sum
+    cdef public object syst, onsite, _onsite_param_names
+    cdef public gint[:, :]  where, _site_ranges
+    cdef public BlockSparseMatrix _bound_onsite, _bound_hamiltonian
+
+    cdef BlockSparseMatrix _eval_onsites(self, args, params)
+    cdef BlockSparseMatrix _eval_hamiltonian(self, args, params)
+
+
+cdef class Density(_LocalOperator):
+    pass
+
+
+cdef class Current(_LocalOperator):
+    pass
+
+
+cdef class Source(_LocalOperator):
+    pass
diff --git a/kwant/operator.pyx b/kwant/operator.pyx
index 002eb8b6..8421ba56 100644
--- a/kwant/operator.pyx
+++ b/kwant/operator.pyx
@@ -335,10 +335,6 @@ cdef class BlockSparseMatrix:
         The matrix of each block, stored in row-major (C) order.
     """
 
-    cdef public gint[:, :] block_offsets, block_shapes
-    cdef public gint[:] data_offsets
-    cdef public complex[:] data
-
     @cython.embedsignature
     @cython.boundscheck(False)
     @cython.wraparound(False)
@@ -401,7 +397,8 @@ ctypedef enum operation:
 
 
 cdef class _LocalOperator:
-    """Base class for operators defined by an on-site matrix and the Hamiltonian.
+    """Base class for operators defined by an on-site matrix and the
+    Hamiltonian.
 
     This includes "true" local operators, as well as "currents" and "sources".
 
@@ -431,11 +428,6 @@ cdef class _LocalOperator:
         `~kwant.operator._LocalOperator.__call__` for details).
     """
 
-    cdef public int check_hermiticity, sum
-    cdef public object syst, onsite, _onsite_param_names
-    cdef public gint[:, :]  where, _site_ranges
-    cdef public BlockSparseMatrix _bound_onsite, _bound_hamiltonian
-
     @cython.embedsignature
     def __init__(self, syst, onsite, where, *,
                  check_hermiticity=True, sum=False):
-- 
GitLab