ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 13 Mar 2018 20:55:01 -0500Is it possible to get fortran code for an expression?https://ask.sagemath.org/question/41525/is-it-possible-to-get-fortran-code-for-an-expression/Hello, is it possible to get the fortran code for expressions in SageMath?
Here's what I mean:
sage: var('a b x y')
( a, b, x, y )
sage: eq = x^a + 3/2*y^b
sage: get_fortran(eq)
x**a + 3.0/2.0*y**b
Right now the best I can do as a workaround is:
sage: eq.__str__().replace('^', '**')
x**a + 3/2*y**b
but the numbers appear as integers, which makes the division be performed as integer division in Fortran, which forces me to manually change that. Is there a function I can use to get what I want?
Cheers
tomchoTue, 13 Mar 2018 20:55:01 -0500https://ask.sagemath.org/question/41525/call FORTRAN in SAGE (openSuSE 12.3)https://ask.sagemath.org/question/10754/call-fortran-in-sage-opensuse-123/I want to call files written in FORTRAN, because several powerful matrix computation packages are only available in FORTRAN.
----------
I have found two websites:
> From the notebook the magic %fortran will automatically compile any fortran code in a cell and all the subroutines will become callable functions (though the names will be converted to lowercase.) [magic %fortran](http://www.sagemath.org/doc/numerical_sage/f2py.html)
> F2PY is now part of NumPy. All the development and maintenance of F2PY is carried out under NumPy SVN tree. See F2PY for more information. If you need F2PY with Numeric or Numarray array support then you must use the F2PY version found below. [F2PY](http://cens.ioc.ee/projects/f2py2e/)
However,
sage: %fortran
ERROR: Line magic function `%fortran` not found.
----------
Should I install any additional package?
Ops, perhaps I should have installed FORTRAN Compiler firstly...
Shown in YaST (openSuSE 12.3),
gcc-fortran, gcc47-fortran, gdb, libgfortran3, libquropdate1, libquadmath0
are installed.
Thanks in advance!gundamlhTue, 19 Nov 2013 04:26:15 -0600https://ask.sagemath.org/question/10754/incompatible libgfortran version?https://ask.sagemath.org/question/9947/incompatible-libgfortran-version/I am using a python code that someone else wrote that links to some fortran libraries. I can get the code to work with my system installation of python (Python 2.7.2+ default, Oct 4 2011, 20:06:09 [GCC 4.6.1] on linux2). My operating system is Ubuntu 11.10. When I try to use the same python code in sage, I get the following error:
OSError: /opt/sage-4.8-linux-64bit-ubuntu_10.04.3_lts-x86_64-Linux/local/lib/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by [omitting the full path on this website for privacy reasons]/librefprop.so)
when the
ctypes.cdll.LoadLibrary(u"[omitting the full path on this website for privacy reasons]/librefprop.so")
command is run.
I really don't know anything about fortran or how ctypes works, but it appears as though the sage version that I am using has a different libgfortran version than my operating system used when I created the fortran object files from the fortran code and linked them with the gfortran command. Here is some output from the command "dpkg --list | grep compiler|grep fortran"
ii gfortran 4:4.6.1-2ubuntu5 GNU Fortran 95 compiler
ii gfortran-4.6 4.6.1-9ubuntu3 GNU Fortran 95 compiler
Is there some way I can tell sage to use the same libgfortran as my system python distribution? Will updating sage resolve this issue?
kjlvcxzoiperwqWed, 27 Mar 2013 10:28:42 -0500https://ask.sagemath.org/question/9947/Cannot make inline Fortran compiler (f2py) workhttps://ask.sagemath.org/question/9773/cannot-make-inline-fortran-compiler-f2py-work/Hello!
I am trying to make the inline Fortran compiler work. It gave some long errors in Sage 5.5. Now I try in Sage 5.6 (Ubuntu 11.10 64 bit): The evaluation of %fortran cell returns None , but no symbols seem to be defined.
I tried the simple Fibonacci example from the documentation and it did not work as it should.
The ordinary command-line compilation with f2py works ok!
Please, could anyone try to help me.
%fortran
C FILE: FIB3.F
SUBROUTINE FIB(A,N)
C
C CALCULATE FIRST N FIBONACCI NUMBERS
C
INTEGER N
REAL*8 A(N)
Cf2py intent(in) n
Cf2py intent(out) a
Cf2py depend(n) a
DO I=1,N
IF (I.EQ.1) THEN
A(I) = 0.0D0
ELSEIF (I.EQ.2) THEN
A(I) = 1.0D0
ELSE
A(I) = A(I-1) + A(I-2)
ENDIF
ENDDO
END
C END FILE FIB3.F
None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_41.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmliKDUp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpBVbhBE/___code___.py", line 3, in <module>
exec compile(u'fib(_sage_const_5 )
File "", line 1, in <module>
NameError: name 'fib' is not defined
Best wishes,
Sergey SergeyTue, 12 Feb 2013 04:25:39 -0600https://ask.sagemath.org/question/9773/python install and fortranhttps://ask.sagemath.org/question/9507/python-install-and-fortran/I want to install the package PyNIO with sage 5.3
The problem occurs with the fortran compiler. When doing
*sage --python setup.py install*
I get following errors
> customize UnixCCompiler
> customize UnixCCompiler using build_clib
> customize GnuFCompiler
> Found executable /srv/gluster/home/mathieu/opt/sage-5.3-linux-64bit-ubuntu_10.04.4_lts-x86_64-Linux/local/bin/gfortran
> gnu: no Fortran 90 compiler found
> Found executable /usr/bin/ld
> Found executable /usr/bin/ar
> Found executable /usr/bin/ranlib
> gnu: no Fortran 90 compiler found
> customize IntelFCompiler
> Found executable /opt/intel/composer_xe_2011_sp1/bin/ifort
> customize LaheyFCompiler
> Could not locate executable lf95
> customize PGroupFCompiler
> Could not locate executable pgf90
> customize AbsoftFCompiler
> customize NAGFCompiler
> customize VastFCompiler
> customize CompaqFCompiler
> customize IntelItaniumFCompiler
> customize IntelEM64TFCompiler
> customize Gnu95FCompiler
> customize G95FCompiler
> don't know how to compile Fortran code on platform 'posix'
> building 'nio' library
> error: library nio has Fortran sources but no Fortran compiler found
On the other hand when I try to install on a Python 2.7.3 installed in my home directory using
*python setup.py install*
there is apparently no error at all:
> customize UnixCCompiler
> customize UnixCCompiler using build_clib
> customize GnuFCompiler
> Found executable /opt/intel/composer_xe_2011_sp1/bin/ifort
> gnu: no Fortran 90 compiler found
> Could not locate executable g77
> Could not locate executable f77
> gnu: no Fortran 90 compiler found
> customize IntelFCompiler
> customize LaheyFCompiler
> Could not locate executable lf95
> customize PGroupFCompiler
> Could not locate executable pgfortran
> customize AbsoftFCompiler
> customize NAGFCompiler
> customize VastFCompiler
> customize CompaqFCompiler
> customize IntelItaniumFCompiler
> customize IntelEM64TFCompiler
> customize IntelEM64TFCompiler
> customize IntelEM64TFCompiler using build_clib
> building 'nio' library
> compiling C sources
What could explain this difference in behavior between using sage alone and using Python 2.7.3?
Best,
Mathieu
Mathieu Dutour SikiricTue, 06 Nov 2012 21:18:23 -0600https://ask.sagemath.org/question/9507/f2py on Mac OS Lionhttps://ask.sagemath.org/question/9067/f2py-on-mac-os-lion/I use sage both on an iMac running MacOS 10.5 (Leopard) and on a Laptop running 10.7 (Lion). For a while now, I've been trying to figure out how to get f2py work on the Lion laptop, with no success - it works without a problem on the Leopard iMac. A search throughs up some old tickets related to this, the most relevant probably being #8010 (http://trac.sagemath.org/sage_trac/ticket/8010). It is a closed ticket, so I was hoping this problem would eventually be solved by an update, but as of 5.0.1 it is still there. Can anyone help me/point me to the right solution. The ticket talks about a "pach". Is this still relevant/up-to-date. If yes can anyone tell me how to apply it, please?
Thanks!stecherWed, 13 Jun 2012 00:52:51 -0500https://ask.sagemath.org/question/9067/Generation of optimized Fortran code?https://ask.sagemath.org/question/8134/generation-of-optimized-fortran-code/Hey All,
Is it possible to use Sage to generate Fortran code from its expressions which is optimized?
I'm looking for an OSS alternative to the CodeGeneration package of Maple.
I came across a discussion about it from 2008 where it was said that it is a planned feature but I didn't manage to find anything newer about that.
Many thanks,
OmriOmriWed, 08 Jun 2011 03:07:25 -0500https://ask.sagemath.org/question/8134/building sage-4.6.1 from source fails because of missing fortranhttps://ask.sagemath.org/question/7817/building-sage-461-from-source-fails-because-of-missing-fortran/The list of dependencies at the top of the README does not mention fortran. However, a bit later in the README, it says that fortran is required, and even that I have to set some environment variables. I have found, I can build sage fine by installing gfortran. Is this a bug ?GabrielPannwitzWed, 19 Jan 2011 06:04:35 -0600https://ask.sagemath.org/question/7817/Find .f2py_f2cmap file from notebookhttps://ask.sagemath.org/question/7765/find-f2py_f2cmap-file-from-notebook/Is it possible to get f2py (%fortran) to find an .f2py_f2cmap file when using the notebook?
QuestorsSun, 14 Nov 2010 08:27:58 -0600https://ask.sagemath.org/question/7765/