From 8d36ad63c794601b3cb682b67f172dcdd0f14a81 Mon Sep 17 00:00:00 2001 From: Starlitnightly Date: Thu, 29 Aug 2024 12:41:42 +0800 Subject: [PATCH] Fixed type error of `float128` #134 --- omicverse/externel/cnmf/cnmf.py | 2 +- omicverse/pp/_sccomposite.py | 20 ++++++++++++-------- omicverse_guide/docs/Release_notes.md | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/omicverse/externel/cnmf/cnmf.py b/omicverse/externel/cnmf/cnmf.py index 42ed5461..20cc5408 100644 --- a/omicverse/externel/cnmf/cnmf.py +++ b/omicverse/externel/cnmf/cnmf.py @@ -4,7 +4,7 @@ import pandas as pd import os, errno, sys import datetime -import uuid + import itertools import yaml import subprocess diff --git a/omicverse/pp/_sccomposite.py b/omicverse/pp/_sccomposite.py index 0e0cdd21..6033f313 100644 --- a/omicverse/pp/_sccomposite.py +++ b/omicverse/pp/_sccomposite.py @@ -191,19 +191,23 @@ def log_joint_one_k_rna(data, theta, alpha, beta, decay, k0): return log_joint def prob_k0_rna(data, theta, alpha, beta, decay, k0, k=3): - ''' - Probability calculation at k0 - ''' + # Check if float128 is supported, otherwise fall back to float64 + try: + np.dtype('float128') + float_type = np.float128 + except TypeError: + float_type = np.float64 + log_joint_k0 = log_joint_one_k_rna(data, theta, alpha, beta, decay, k0) - one_ks = np.ones((data.shape[0],k)) + one_ks = np.ones((data.shape[0], k), dtype=float_type) for i in np.arange(k): - one_ks[:,i] = log_joint_one_k_rna(data, theta, alpha, beta, decay, i) + one_ks[:, i] = log_joint_one_k_rna(data, theta, alpha, beta, decay, i) - logsumexp_ks = special.logsumexp(one_ks, axis = 1) + logsumexp_ks = special.logsumexp(one_ks, axis=1) log_prob = log_joint_k0 - logsumexp_ks - log_prob = log_prob.astype('float128') - prob = np.exp(log_prob, dtype=np.float128) + log_prob = log_prob.astype(float_type) + prob = np.exp(log_prob, dtype=float_type) return prob diff --git a/omicverse_guide/docs/Release_notes.md b/omicverse_guide/docs/Release_notes.md index ec1c7529..2ede027b 100644 --- a/omicverse_guide/docs/Release_notes.md +++ b/omicverse_guide/docs/Release_notes.md @@ -447,5 +447,6 @@ Support Raw Windows platform ### PP Module - Updated constraint error of ov.pp.mde #129 +- Fixed type error of `float128` #134