convexengineering / gpkit

Geometric programming for engineers
http://gpkit.readthedocs.org
MIT License
206 stars 40 forks source link

weird type recognition for Variable #1487

Closed 1ozturkbe closed 4 years ago

1ozturkbe commented 4 years ago

This is some odd behavior which should probably be addressed. Here is an MWE:

from gpkit import Variable, VectorVariable, Monomial
a = Variable()
isinstance(a, Variable) # returns False
isinstance(a, VectorVariable) # also False
isinstance(a, Monomial) # finally a True!
type(a) # gpkit.nomials.variables.Variable

Same issue occurs for VectorVariables. Kind of a pain when you try to muck with GPkit objects.

bqpd commented 4 years ago

yup this is to make VectorizableVariable work. a bit hacky! but for now hasattr(a, "key") and not a.key.shape might work for ya. In general I wouldn't recommend doing anything that requires variable objects: instead make functions that accept nomials or accept varkeys, and pull the keys from Variables