Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix missing conversion to RDF
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Aug 10, 2020
1 parent 1f00faa commit 8e8158c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/sage/geometry/polyhedron/cdd_file_format.py
Expand Up @@ -62,6 +62,12 @@ def cdd_Vrepresentation(cdd_type, vertices, rays, lines, file_output=None):
vertices = [[0]*ambient_dim]
num += 1

if cdd_type is 'real':
from sage.rings.all import RDF
base_ring = RDF
else:
base_ring = None

s = 'V-representation\n'
if lines is not None:
n = len(lines)
Expand All @@ -71,13 +77,13 @@ def cdd_Vrepresentation(cdd_type, vertices, rays, lines, file_output=None):
s += ' ' + repr(num) + ' ' + repr(ambient_dim+1) + ' ' + cdd_type + '\n'
if lines is not None:
for l in lines:
s += ' 0 ' + _to_space_separated_string(l) + '\n'
s += ' 0 ' + _to_space_separated_string(l, base_ring) + '\n'
if rays is not None:
for r in rays:
s += ' 0 ' + _to_space_separated_string(r) + '\n'
s += ' 0 ' + _to_space_separated_string(r, base_ring) + '\n'
if vertices is not None:
for v in vertices:
s += ' 1 ' + _to_space_separated_string(v) + '\n'
s += ' 1 ' + _to_space_separated_string(v, base_ring) + '\n'
s += 'end\n'

if file_output is not None:
Expand Down Expand Up @@ -116,6 +122,12 @@ def cdd_Hrepresentation(cdd_type, ieqs, eqns, file_output=None):
num, ambient_dim = _common_length_of(ieqs, eqns)
ambient_dim -= 1

if cdd_type is 'real':
from sage.rings.all import RDF
base_ring = RDF
else:
base_ring = None

s = 'H-representation\n'
if eqns is not None:
assert len(eqns)>0
Expand All @@ -126,10 +138,10 @@ def cdd_Hrepresentation(cdd_type, ieqs, eqns, file_output=None):
s += ' ' + repr(num) + ' ' + repr(ambient_dim+1) + ' ' + cdd_type + '\n'
if eqns is not None:
for e in eqns:
s += ' ' + _to_space_separated_string(e) + '\n'
s += ' ' + _to_space_separated_string(e, base_ring) + '\n'
if ieqs is not None:
for i in ieqs:
s += ' ' + _to_space_separated_string(i) + '\n'
s += ' ' + _to_space_separated_string(i, base_ring) + '\n'
s += 'end\n'

if file_output is not None:
Expand Down
8 changes: 7 additions & 1 deletion src/sage/geometry/polyhedron/misc.py
Expand Up @@ -11,14 +11,16 @@
# **********************************************************************


def _to_space_separated_string(l):
def _to_space_separated_string(l, base_ring=None):
"""
Convert a container to a space-separated string.
INPUT:
- ``l`` -- anything iterable.
- ``base_ring`` -- ring (default: ``None``); convert this ring, if given
OUTPUT:
String.
Expand All @@ -28,7 +30,11 @@ def _to_space_separated_string(l):
sage: import sage.geometry.polyhedron.misc as P
sage: P._to_space_separated_string([2,3])
'2 3'
sage: P._to_space_separated_string([2, 1/5], RDF)
'2.0 0.2'
"""
if base_ring:
return ' '.join(repr(base_ring(x)) for x in l)
return ' '.join(repr(x) for x in l)


Expand Down

0 comments on commit 8e8158c

Please sign in to comment.