importing sage function errors - function

I have a .spyx file that i'm running with using sage.
I have this:
from sage.all import *
which has been handling built-in sage functions like: complement(), clique_number(), and graph(). BUT, it absolutely does not recognize chromatic_number(), even thought it is part of the sage library package.
I have also tried:
from sage.graphs import *
Which is redundant, and not working.
What do I do?

Related

Cython and Exec()?

If I made a python file named hello.py that has a script made like this.
msg = input("insert your message here: ")
script = '''
def say_something():
print("{msg}")
'''
exec(script)
say_something()
And then I tried to use Cython
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("Hello.py")
)
It will show an error like this: undeclared name not builtin: say_something
I do understand why this happens but I'm not really an expert with python and C just yet. This is just an example, but it's similar to what I'm trying to do with one of my projects. Is there any way I could resolve this? I want to find a way to convert the script string into C as well.
I was trying to build an editable python script.
Cython compiles the Python functions to a native binary that does what the CPython interpreter should do. exec is a function that execute arbitrary code at runtime (which is generally a very bad idea for speed, maintainability/readability and security). Cython does not support exec because it would mean that the could would be compiled at runtime. Thus, the code executed by exec cannot be a Cython code. However, the exec function can still be used to execute a pure-Python code. The error can be removed by turning off the Cython.Compiler.Options.error_on_unknown_names in the setup script (just before calling setup) as pointed out by #DavidW. With this Cython will not complain when it does not find a function defined by exec (or similar methods). Please keep in mind that CPython can only be used in this case instead of Cython (which partially defeat the purpose of using Cython in the first place).

Does SystemVerilog support global functions?

I want to make a parity_check function which can be accessed by three different modules. Is this possible in SV? If yes, where do I declare this function and how do I import it into my module?
You can put a function into a separate file and include it using `include:
`include "some_file_name.sv"
However, a much better way is to use a package:
package some_package_name;
function string some_function_name;
return "some_function_name called";
endfunction
endpackage
You would put that into a separate file and you must compile that before compiling any module that uses it. You then import the package into each module:
module some_module_name;
import some_package_name::*; // or import some_package_name::some_function_name;
initial
$display(some_function_name);
endmodule
Putting a function in a package is better than just putting it into a file and using include, because a package is a named scope. Because a package is a named scope, any issues with some clash of names can be resolved by, instead of using import, referring to the full name of the function in its package, eg:
module some_module_name;
initial
$display(some_package_name::some_function_name);
endmodule

how to import function in angular2 using angular-cli?

I've previously used the following code
import { clone } from '../../utilities/javascript';
and in the javaccript.ts
export function clone(source: any) {...}
In my module i made the call using the following syntax:
this.x=clone(y);
And all was working.
However, since I am using Angular-cli, the following exception comes up in Chrome:
error_handler.js:47 EXCEPTION: Cannot read property 'clone' of undefined
Is there something in my syntax that is wrong, which surfaced just as I switched to Angular-cli?
I currently copy this function into every module in which i use it, which solves the problem, but that is not something I am comfortable with.
try to import it in the following way:
import * as javascriptUtils from '../../utilities/javascript';
then call it with:
this.x=javascriptUtils.clone(y);
taken from https://github.com/angular/angular-cli#3rd-party-library-installation

Using JUnit in Jython - NameError for assertTrue

Environment Details
Mac OS X 10.9
Oracle JDK 1.7.0_55 64-bit
jython-standalone-2.5.3.jar
junit-4.11
What I have done so far
I have added the junit jar to /Library/Java/Extensions.
I invoked Jython as follows java -jar jython-standalone-2.5.3.jar
In the Jython interpreter, I imported the following import org.junit.Assert, and this import was successful.
Problem
When I tried to use assertTrue, I got a NameError in the interpreter. Why is this so?
I understand that assertTrue is a static method. Not sure what implication this has when I try to use it in Jython.
Additional Context
I am using XMLUnit in Jython. Was able to successfully import the Diff class from org.custommonkey.xmlunit in Jython. Also able to use the methods in this class, and call them on a Diff object. The result of this method call is what I am trying to pass to assertTrue, when it throws the error.
from org.custommonkey.xmlunit import Diff
import org.junit.Assert
xml1 = ...some XML string...
xml2 = ...some XML string...
myDiff = Diff(xml1, xml2)
assertTrue(myDiff.similar())
Hope this additional information is useful in identifying a solution to this problem.
Latest Status
I narrowed it down to setting this property python.security.respectJavaAccessibility = false, since the Assert() constructor is protected.
Still trying to get it to work. Any help is greatly appreciated.
Figured it out.
In addition to junit.jar file, the hamcrest-core.jar file also needed to be copied to /Library/Java/Extensions.
Then I got rid of the jython.jar file, and instead installed it using the jython installer.
After the installation was completed, I updated the registry file in the installation folder, specifically setting this property python.security.respectJavaAccessibility = false.
Now I am able to see the assertTrue method, and no longer getting a NameError.

Geronimo FTP Server on Fedora 19

I am trying to use the FTP server (factory) in Geronimo 3.0.1 on Fedora 19, in eclipse kepler. I have the following import which produces no error:
import org.apache.mina.*;
However, when I declare
FTPServerFactory ftpFactory;
FTPServer ftpServer;
neither of FTPServer and FTPServerFactory is resolvable. The usual eclipse hints in the editor, which are very cool, offer no help in this case. My build path has the mina-core.jar (This is the only MINA jar that I find in /usr/share/java/apache-mina). The build path dialog flags errors, not explicitly for mina, stating the the following are missing:
org.eclipse.JRE_CONTAINER/
org.eclipse.jdt.internal.debug.uio.launcher.StandardVMType/
java-1.7.0-openjdk-1.7.0.25.x86-64
I suspect that my installation is missing other mina jars and am at a loss for the three errors above except that the last one is strange given that the that the build path has
java-1.7.0-openjdk-1.7.0
My environment is all relatively new, so there could be problems in a number of places. Any advice on where to start?
Thanks in advance.
I am not sure what happened when I logged in. Please disregard the empty question.
I have the following, which does not produce errors.
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.FtpReply;
import org.apache.ftpserver.ftplet.FtpRequest;
import org.apache.ftpserver.ftplet.FtpSession;
import org.apache.ftpserver.ftplet.Ftplet;
import org.apache.ftpserver.ftplet.FtpletContext;
import org.apache.ftpserver.ftplet.FtpletResult;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.ssl.SslConfigurationFactory;
import org.apache.ftpserver.usermanager.*;
import org.apache.ftpserver.usermanager.impl.BaseUser;
My build path includes
ftpserver-core-1.06.jar - /usr/share/java/apache-ftpserver/common/lib
A code fragment follows
//Add the user to the FTP server as well.
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(new File("myusers.properties"));
userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
org.apache.ftpserver.ftplet.UserManager um = userManagerFactory.createUserManager();
BaseUser user = new BaseUser();
user.setName(newCredentials.getUserID());
user.setPassword(ConfigurationValues.get("ftpGenericPassword"));
new File(ConfigurationValues.get("ftpFilesRoot")+newCredentials.getUserID());
user.setHomeDirectory("ftproot");
um.save(user);
I hope this is of use. Takes a little burrowing to sort it out.