r"""Convert a list if in numpy format
(*lst, nx=None)
| 57 | |
| 58 | |
| 59 | def list_to_array(*lst, nx=None): |
| 60 | r"""Convert a list if in numpy format""" |
| 61 | lst_not_empty = [a for a in lst if len(a) > 0 and not isinstance(a, list)] |
| 62 | if nx is None: # find backend |
| 63 | if len(lst_not_empty) == 0: |
| 64 | type_as = np.zeros(0) |
| 65 | nx = get_backend(type_as) |
| 66 | else: |
| 67 | nx = get_backend(*lst_not_empty) |
| 68 | type_as = lst_not_empty[0] |
| 69 | else: |
| 70 | if len(lst_not_empty) == 0: |
| 71 | type_as = None |
| 72 | else: |
| 73 | type_as = lst_not_empty[0] |
| 74 | if len(lst) > 1: |
| 75 | return [ |
| 76 | nx.from_numpy(np.array(a), type_as=type_as) if isinstance(a, list) else a |
| 77 | for a in lst |
| 78 | ] |
| 79 | else: |
| 80 | if isinstance(lst[0], list): |
| 81 | return nx.from_numpy(np.array(lst[0]), type_as=type_as) |
| 82 | else: |
| 83 | return lst[0] |
| 84 | |
| 85 | |
| 86 | def proj_simplex(v, z=1): |
no test coverage detected