Aux function.
(dict_, outer_sep=";", inner_sep=":")
| 2909 | |
| 2910 | |
| 2911 | def _serialize(dict_, outer_sep=";", inner_sep=":"): |
| 2912 | """Aux function.""" |
| 2913 | s = [] |
| 2914 | for key, value in dict_.items(): |
| 2915 | if callable(value): |
| 2916 | value = value.__name__ |
| 2917 | elif isinstance(value, Integral): |
| 2918 | value = int(value) |
| 2919 | elif isinstance(value, dict): |
| 2920 | # py35 json does not support numpy int64 |
| 2921 | for subkey, subvalue in value.items(): |
| 2922 | if isinstance(subvalue, list): |
| 2923 | if len(subvalue) > 0: |
| 2924 | if isinstance(subvalue[0], int | np.integer): |
| 2925 | value[subkey] = [int(i) for i in subvalue] |
| 2926 | |
| 2927 | for cls in (np.random.RandomState, Covariance): |
| 2928 | if isinstance(value, cls): |
| 2929 | value = cls.__name__ |
| 2930 | |
| 2931 | s.append(key + inner_sep + json.dumps(value)) |
| 2932 | |
| 2933 | return outer_sep.join(s) |
| 2934 | |
| 2935 | |
| 2936 | def _deserialize(str_, outer_sep=";", inner_sep=":"): |