cNMF icon indicating copy to clipboard operation
cNMF copied to clipboard

cnmf consensus TypeError: H should have the same dtype as X. Got H.dtype = float64.

Open qinting opened this issue 2 years ago • 6 comments

Hi, I encountered the "TypeError: H should have the same dtype as X. Got H.dtype = float64." when running the last step (cnmf consensus). I have tried all suggestions in https://github.com/dylkot/cNMF/issues/9 and https://github.com/dylkot/cNMF/issues/8#issue-651940726, but all failed. Could anyone please let me know how to solve the problem? Where exactly I should add norm_counts.X = norm_counts.X.astype(np.float64) in cnmf.py?

BTW, I used the most recent version of cnmf.py in the master branch.

qinting avatar Dec 15 '22 16:12 qinting

The solution #10 helped with the problem. I had the exact same error as yours before and I found that there's actually no need to add norm_counts.X = norm_counts.X.astype(np.float64).

Hi, I encountered the "TypeError: H should have the same dtype as X. Got H.dtype = float64." when running the last step (cnmf consensus). I have tried all suggestions in #9 and #8 (comment), but all failed. Could anyone please let me know how to solve the problem? Where exactly I should add norm_counts.X = norm_counts.X.astype(np.float64) in cnmf.py?

BTW, I used the most recent version of cnmf.py in the master branch.

humengying0907 avatar Jan 04 '23 22:01 humengying0907

Thanks! According to the #10 post, my understanding is that H = H.astype(np.float64) should be added within the "def _check_w_h" function (as suggested by njh219). However, I am not sure which script to locate. I can only find the cnmf.py. Could you please point me to the NMF Scikit-learn code? I really appreciated your help!

The solution #10 helped with the problem. I had the exact same error as yours before and I found that there's actually no need to add norm_counts.X = norm_counts.X.astype(np.float64).

Hi, I encountered the "TypeError: H should have the same dtype as X. Got H.dtype = float64." when running the last step (cnmf consensus). I have tried all suggestions in #9 and #8 (comment), but all failed. Could anyone please let me know how to solve the problem? Where exactly I should add norm_counts.X = norm_counts.X.astype(np.float64) in cnmf.py? BTW, I used the most recent version of cnmf.py in the master branch.

qinting avatar Jan 04 '23 23:01 qinting

You can search in your conda env: cnmf_env/lib/python3.7/site-packages/sklearn/decomposition/_nfm.py

humengying0907 avatar Jan 05 '23 21:01 humengying0907

I, too, encountered this error when running the consensus step.

I am a little concerned about tweaking the sklearn _cnmf.py and cnmf.py scripts as they are installed packages.

Is it possible for the authors to add in this bug fix?

andhamel avatar Jan 26 '23 20:01 andhamel

Hi @humengying0907. I followed your instructions and still getting the same error.

Is it right to modify _nfm.py in my conda environment like this?

elif not update_H:
            _check_init(H, (self._n_components, n_features), "NMF (input H)")
            H = H.astype(np.float64)
            if H.dtype != X.dtype:
                raise TypeError(
                    "H should have the same dtype as X. Got H.dtype = {}.".format(
                        H.dtype
                    )
                )

Thanks!

ryanhchung avatar May 24 '23 07:05 ryanhchung

It might help to update anndata to version >0.9 in your python environment (see #71)

lucas-diedrich avatar Aug 07 '23 13:08 lucas-diedrich

This should be addressed now as per issue #71. Sorry for being slow to get to this. Let me know if there are ongoing issues.

dylkot avatar May 07 '24 22:05 dylkot