Ask Your Question
0

Stop Sage from overriding Python number types

asked 5 years ago

anonymous user

Anonymous

I'm trying to play around with machine learning inside of the SageMath environment, but since Sage implicitly casts ints, floats, etc. to Integers, RealNumbers, etc., I'm running into problems such as this one:

... --> model.add(Dense(Integer(1), activation="softmax")) ... ValueError: Can't convert Python sequence with mixed types to Tensor.

So far, I've gotten around this by explicitly casting, so my line of code now looks like this:

... model.add(Dense(int(1), activation="softmax")) ...

but I would rather not do this every time I create a model. Is there a way to stop Sage from implicitly casting, and instead use the default Python types?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

tmonteil gravatar image

There are at least two possilbilies:

disable the preparser with preparser(False):

sage: type(1)
<type 'sage.rings.integer.Integer'>
sage: preparser(False)
sage: type(1)
<type 'int'>

or use r suffix to say that the numbers are raw:

sage: type(1)
<type 'sage.rings.integer.Integer'>
sage: type(1r)
<type 'int'>
sage: type(1.0r)
<type 'float'>
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 680 times

Last updated: Oct 20 '19