lundi 13 juin 2016

Python: linear algebra package with domain checks


Does it exists a (possibly efficient) linear algebra package that uses some form of domain check before performing linear operations?

numpy performs already some kind of domain check before linear operations: if dimensions don't match, it raises a ValueError. I would like to identify my domains more accurately (e.g. by having a tag that specifies the basis of the space) and obtain the same behavior if the domains don't match.

Suppose I have a two 3-d vecor spaces

  • Vector space A represents fruits: dimension 1 = bananas, 2 = apples, 3 = pear. A vector of A is a recipe

  • Vector space B represents clothes: dimension 1 = shoes, 2 = trousers, 3 = shirts. A vector of B is a wardrobe.

The following is what I would like to have (and can't do in numpy)

import numpy as np
a = np.array([1,2,3], domain='fruits')
b = np.array([3,2,1], domain='clothes')
a + b # I want it to raise a ValueError: can't sum clothes and fruits

Aucun commentaire:

Enregistrer un commentaire