tinycwrap 0.0.4__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinycwrap
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: Lightweight C-to-Python wrapper generator using CFFI and NumPy
5
5
  Author: TinyCWrap Contributors
6
6
  Requires-Python: >=3.9
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tinycwrap"
7
- version = "0.0.4"
7
+ version = "0.0.5"
8
8
  description = "Lightweight C-to-Python wrapper generator using CFFI and NumPy"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -14,9 +14,9 @@ def cm():
14
14
 
15
15
 
16
16
  def test_dot(cm):
17
- x = np.arange(10, dtype=np.float64)
18
- y = np.ones_like(x)
19
- assert cm.dot(x, y, len_x=len(x)) == np.sum(x * y)
17
+ x = np.array([1.0, 2.0, 3.0], dtype=np.float64)
18
+ y = np.array([4.0, 5.0, 6.0], dtype=np.float64)
19
+ assert cm.dot(x, y, len_x=len(x)) == np.dot(x, y)
20
20
 
21
21
 
22
22
  def test_scale_auto_output(cm):
@@ -52,3 +52,7 @@ def test_repr_pointer_array(cp):
52
52
  repr_str = repr(path)
53
53
  assert "segments=<segments* 0x" in repr_str
54
54
  assert "len_segments=2" in repr_str
55
+
56
+ def test_post_contract(cp):
57
+ segments, len_segments = cp.geom2d_segments_from_rectellipse(1,2,3,4)
58
+ assert segments.shape == (4,)
@@ -6,6 +6,6 @@ from .cmodule import CModule
6
6
  try:
7
7
  __version__ = version("tinycwrap")
8
8
  except PackageNotFoundError:
9
- __version__ = "0.0.4"
9
+ __version__ = "0.0.5"
10
10
 
11
11
  __all__ = ["CModule", "__version__"]
@@ -381,24 +381,22 @@ class CModule:
381
381
  fspec.doc = doc
382
382
  contracts = []
383
383
  for line in doc.splitlines():
384
- if "Contract:" in line or "Post-Contract:" in line:
385
- after = (
386
- line.split("Contract:", 1)[1]
387
- if "Contract:" in line
388
- else line.split("Post-Contract:", 1)[1]
389
- )
390
- is_post = "Post-Contract" in line
391
- for part in after.split(";"):
392
- part = part.strip()
393
- if not part:
394
- continue
395
- mlen = re.match(r"len\((\w+)\)\s*=\s*(.+)", part)
396
- if not mlen:
397
- mlen = re.match(r"(\w+)\s*=\s*(.+)", part)
398
- if mlen:
399
- target = mlen.group(1)
400
- expr = mlen.group(2).strip()
401
- contracts.append((target, expr, is_post))
384
+ m_contract = re.search(r"(post-)?contract:\s*(.*)", line, flags=re.IGNORECASE)
385
+ if not m_contract:
386
+ continue
387
+ is_post = m_contract.group(1) is not None
388
+ after = m_contract.group(2)
389
+ for part in after.split(";"):
390
+ part = part.strip()
391
+ if not part:
392
+ continue
393
+ mlen = re.match(r"len\((\w+)\)\s*=\s*(.+)", part)
394
+ if not mlen:
395
+ mlen = re.match(r"(\w+)\s*=\s*(.+)", part)
396
+ if mlen:
397
+ target = mlen.group(1)
398
+ expr = mlen.group(2).strip()
399
+ contracts.append((target, expr, is_post))
402
400
  fspec.contracts = contracts or None
403
401
 
404
402
  def _mark_length_params_from_contracts(self):
@@ -496,7 +494,15 @@ class CModule:
496
494
  target_dtype = _struct_dtypes.get(f.base_type)
497
495
  provided = kwargs.get(f.name)
498
496
  if provided is not None and target_dtype is not None:
499
- arr = np.ascontiguousarray(provided, dtype=target_dtype)
497
+ try:
498
+ arr = np.ascontiguousarray(provided, dtype=target_dtype)
499
+ except ValueError:
500
+ if hasattr(provided, "_data"):
501
+ arr = np.ascontiguousarray(provided._data, dtype=target_dtype)
502
+ elif isinstance(provided, (list, tuple)) and provided and hasattr(provided[0], "_data"):
503
+ arr = np.ascontiguousarray([p._data for p in provided], dtype=target_dtype)
504
+ else:
505
+ raise
500
506
  children[f.name] = arr
501
507
  data[f.name] = arr.ctypes.data
502
508
  if len_field in dtype.names and len_field not in kwargs:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinycwrap
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: Lightweight C-to-Python wrapper generator using CFFI and NumPy
5
5
  Author: TinyCWrap Contributors
6
6
  Requires-Python: >=3.9
@@ -1,7 +1,7 @@
1
1
  README.md
2
2
  pyproject.toml
3
- tests/test_examples.py
4
3
  tests/test_geom.py
4
+ tests/test_kernels.py
5
5
  tests/test_path.py
6
6
  tinycwrap/__init__.py
7
7
  tinycwrap/cmodule.py
File without changes
File without changes
File without changes