146
146
import pexpect
147
147
from sage .misc .verbose import verbose
148
148
from sage .misc .instancedoc import instancedoc
149
+ from sage .misc .temporary_file import tmp_filename
149
150
from sage .cpython .string import bytes_to_str
150
151
151
152
@@ -156,13 +157,13 @@ class Octave(Expect):
156
157
EXAMPLES::
157
158
158
159
sage: octave.eval("a = [ 1, 1, 2; 3, 5, 8; 13, 21, 33 ]") # optional - octave
159
- 'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n\n '
160
+ 'a =\n\n 1 1 2\n 3 5 8\n 13 21 33\n'
160
161
sage: octave.eval("b = [ 1; 3; 13]") # optional - octave
161
- 'b =\n\n 1\n 3\n 13\n\n '
162
- sage: octave.eval("c=a \ \ b") # solves linear equation: a*c = b # optional - octave; random output
163
- 'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n '
162
+ 'b =\n\n 1\n 3\n 13\n'
163
+ sage: octave.eval(r "c=a \ b") # solves linear equation: a*c = b # optional - octave; random output
164
+ 'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n'
164
165
sage: octave.eval("c") # optional - octave; random output
165
- 'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n\n '
166
+ 'c =\n\n 1\n 7.21645e-16\n -7.21645e-16\n'
166
167
167
168
TESTS:
168
169
@@ -186,12 +187,14 @@ def __init__(self, maxread=None, script_subdirectory=None, logfile=None,
186
187
command = os .getenv ('SAGE_OCTAVE_COMMAND' ) or 'octave-cli'
187
188
if server is None :
188
189
server = os .getenv ('SAGE_OCTAVE_SERVER' ) or None
190
+ # Use a temporary workspace file.
191
+ workspace_file = tmp_filename ()
189
192
Expect .__init__ (self ,
190
193
name = 'octave' ,
191
194
# We want the prompt sequence to be unique to avoid confusion with syntax error messages containing >>>
192
195
prompt = r'octave\:\d+> ' ,
193
196
# We don't want any pagination of output
194
- command = command + " --no-line-editing --silent --eval 'PS2(PS1());more off' --persist" ,
197
+ command = command + f " --no-line-editing --silent --eval 'PS2(PS1());more off; octave_core_file_name ( \" { workspace_file } \" ) ' --persist" ,
195
198
maxread = maxread ,
196
199
server = server ,
197
200
server_tmpdir = server_tmpdir ,
@@ -510,9 +513,9 @@ def solve_linear_system(self, A, b):
510
513
sb = self .sage2octave_matrix_string (b )
511
514
self .eval ("a = " + sA )
512
515
self .eval ("b = " + sb )
513
- soln = octave .eval ("c = a \ \ b" )
516
+ soln = octave .eval (r "c = a \ b" )
514
517
soln = soln .replace ("\n \n " ,"[" )
515
- soln = soln .replace ( " \n \n " , "]" )
518
+ soln = soln .rstrip () + "]"
516
519
soln = soln .replace ("\n " ,"," )
517
520
sol = soln [3 :]
518
521
return eval (sol )
0 commit comments