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.Fri, 14 Feb 2020 09:58:02 -0600How can you import C++ code into a Jupyter notebook?https://ask.sagemath.org/question/49922/how-can-you-import-c-code-into-a-jupyter-notebook/ I have a c++ function that I would like to use with Jupyter. I'd like to be able to call it from the main python thread. A minimal example would be something like the following:
#begin c code definition
#include <vector>
#include <iostream>
void printout(std::vector<int> input){
std::vector<int>::iterator start;
std::vector<int>::iterator end;
end=input.end();
for (start=input.begin();start!=end;++start){
std::cout<< *start;
}
std::cout<< std::endl;
}
int main(){
std::vector<int> sample{1,2,3};
printout(sample);
return 0;
}
#switch back to python
printout((1,2,3))
I don't particularly need to call the function or run the main thread in C++, the main() is included to show how this function would be used in the C++ context. Broadly, I want something like the reverse of CythonizejdoolittFri, 14 Feb 2020 09:58:02 -0600https://ask.sagemath.org/question/49922/sage LD_LIBRARY_PATHhttps://ask.sagemath.org/question/38842/sage-ld_library_path/ I wrote a C++ library and the related python bindings, and I would like to make use of them from sage. But whatever I try, I cannot get sage to load the library. Here is what I tried:
1) FIRST ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/mylib/lib::/opt/mylib/dependencies"
However, when I try to import from a jupyter notebook:
import mylib.mymodule.mysubmodule
I get the error:
ImportError: /usr/lib/libblas.so.3: undefined symbol: sgemv_thread_n
I only could find one reference (ticket 22006 on trac.sagemath.org - sorry, cannot post links yet) to a similar problem, however without resolution (the suggested workaround, namely to install `libopenblas-dev` did not work for me). Note that `mylib` does not depend in any way on BLAS.
2) SECOND ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
echo -e "/opt/mylib/lib\n/opt/mylib/dependencies" > /etc/ld.so.conf/mylib.conf
sudo ldconfig
But the library cannot be found this way:
ImportError: libmylib.so.1: cannot open shared object file: No such file or directory
3) THIRD ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/lib/sagemath/local/lib/libmylib.so.1
sudo ln -s /opt/mylib/lib/libmylib.so.1 /usr/local/lib/libmylib.so.1
This results in the same import error as in SECOND ATTEMPT.
4) FOURTH ATTEMPT
export SAGE_PATH="$SAGE_PATH:/opt/mylib/bindings"
sudo ln -s /opt/mylib/lib/libmylib.so.1 /lib/libmylib.so.1
Now the library finally got loaded, but it cannot find its dependencies.
ImportError: libdependency1.so.1.2.3: cannot open shared object file: No such file or directory
THE QUESTION
What is the proper way to make sage resolve a custom library and its dependencies? I understand that sage tries to isolate itself as much as possible from the system, and I have also read that there is some "magic" going on to adjust environment variables: this seems to cause the problem (1).
ADDITIONAL INFO
Working on Ubuntu 16.04 LTS with sage installed from ppa as follows:
apt-add-repository -y ppa:aims/sagemath
apt-get update
apt install sagemath-upstream-binary
Note that everything works as expected when using the library from the system python console.matpenMon, 18 Sep 2017 03:15:57 -0500https://ask.sagemath.org/question/38842/What's the best way to access sage from a C program?https://ask.sagemath.org/question/24107/whats-the-best-way-to-access-sage-from-a-c-program/I'm new to Python/Sage and confused about what my options are here. I have a C++ program and occasionally I want to process some data with Sage. It would be far too slow to simply have Sage running like a server and then use the C++ program like a client that queries the server.
What I really want to do is write a standalone Python function that uses Sage library functions, convert that function and any relevant portions of Sage into C, and then with my own compiler, compile that C code into a library that my C++ program can call.
I'm confused about how all this could work with Cython and spyx files and so forth. Is this even possible? Would it be possible but slower to instead embed the Python function in the C++ program? Thanks for any help.
Andrew732Fri, 12 Sep 2014 15:42:23 -0500https://ask.sagemath.org/question/24107/I want to display my c++ code with eclipse c++ format on my blog any eclipse plugin? or any other method to get cpp html format as it appears on eclipse IDEhttps://ask.sagemath.org/question/11027/i-want-to-display-my-c-code-with-eclipse-c-format-on-my-blog-any-eclipse-plugin-or-any-other-method-to-get-cpp-html-format-as-it-appears-on-eclipse/
I want to display my c++ code with eclipse c++ format on my blog any eclipse plugin?
or any other method to get cpp to html format as it appears on eclipse IDE
my blog is
<a href="http://fahad-cprogramming.blogspot.com">c++ programming for beginners</a>
IT BeginnerWed, 12 Feb 2014 08:42:10 -0600https://ask.sagemath.org/question/11027/Cython error: ambiguous overloaded methodhttps://ask.sagemath.org/question/10665/cython-error-ambiguous-overloaded-method/Hello all,
I am trying to extend CGraph using C++ containers only to get a cython compile error: `ambiguous overloaded method` on `memset`, `memcopy` and `strlen`. As CGraph uses bitset which I have to manipulate, I need to include `bitset.pxi` and `bitset.pxd.pxi`, so end up with a mix of c and c++ calls for cython to deal with. I am guessing that cython can't decide which `memset` etc calls to use, C++ or C versions.
Does anyone know how I might to resolve this ambiguity?
Regards Martin
QuestorsSun, 27 Oct 2013 03:38:58 -0500https://ask.sagemath.org/question/10665/c++ cython in the notebookhttps://ask.sagemath.org/question/9819/c-cython-in-the-notebook/I recently wanted to cimport sage.rings.number_field.number_field_element_quadratic from the a cython cell in notebook, but was met with gcc compilation errors. This is because that file is a c++ module.
So I am wondering, is there is a way to use the c++ functionality of cython from within a notebook cell?ohanarWed, 27 Feb 2013 11:34:01 -0600https://ask.sagemath.org/question/9819/Python's C API and SAGEhttps://ask.sagemath.org/question/9517/pythons-c-api-and-sage/I have written some python code which imports and uses the sage library. I would like to invoke some of this code from C++ code using the C API for python. The problem is that the C API uses the system-wide python installation, rather than sage's python, and therefore the "from sage.all import *" statement generates ImportError. Can anyone tell me how to<br>
(i) install the sage libraries into the system's python installation, OR<br>
(ii) tell the C API to use sage's python rather than the regular version, OR<br>
(iii) resolve this some other way?
rmp251Fri, 09 Nov 2012 16:47:05 -0600https://ask.sagemath.org/question/9517/