blasks / barnacle

Python library that implements a sparse tensor decomposition model.
https://barnacle-py.readthedocs.io
MIT License
1 stars 2 forks source link

Different types in `model.decomposition_.weights` #9

Open Ge0rges opened 2 months ago

Ge0rges commented 2 months ago

Hi Stephen,

Another issue I've noticed today.

I noticed that the data type in model.decomposition_.weights[0] where model is a barnacle.decomposition.SparseCP is sometimes a numpy.float64 and other times numpy.int64. I noticed this because I believe it causes the following error:

Traceback (most recent call last):
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-e74ced325d47>", line 1, in <module>
    [factor_match_score(model.decomposition_, c, consider_weights=False, allow_smaller_rank=True) for c in model.candidates_]
  File "<ipython-input-3-e74ced325d47>", line 1, in <listcomp>
    [factor_match_score(model.decomposition_, c, consider_weights=False, allow_smaller_rank=True) for c in model.candidates_]
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/tlviz/_tl_utils.py", line 107, in func2
    out = func(*bound_arguments.args, **bound_arguments.kwargs)
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/tlviz/_tl_utils.py", line 107, in func2
    out = func(*bound_arguments.args, **bound_arguments.kwargs)
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/tlviz/factor_tools.py", line 415, in factor_match_score
    weights1, factors1 = normalise_cp_tensor(cp_tensor1)
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/tlviz/_tl_utils.py", line 107, in func2
    out = func(*bound_arguments.args, **bound_arguments.kwargs)
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/tlviz/_xarray_wrapper.py", line 370, in func2
    out = func(*bound_arguments.args, **bound_arguments.kwargs)
  File "/Users/GeorgesKanaan/micromamba/envs/jupyter/lib/python3.10/site-packages/tlviz/factor_tools.py", line 77, in normalise_cp_tensor
    weights *= norm.ravel()
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'multiply' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

When calling a function such as factor_match_score from tlviz.factor_tools. If it's helpful, I could try to come up with a minimal working example later in the week.

Ge0rges commented 2 months ago

This is also true of model.decomposition_.factors.