Commit d93372be authored by Médéric Boquien's avatar Médéric Boquien
Browse files

InfoDict was made to overcome the slowness to copy an OrderedDict. However...

InfoDict was made to overcome the slowness to copy an OrderedDict. However since we have removed OrderedDict now, we can just switch to a regular dictionary, which happens to be fast to copy.
parent 8ab9cb83
......@@ -32,7 +32,6 @@ Such SED is characterised by:
import numpy as np
from . import utils
from .infodict import InfoDict
from .io.vo import save_sed_to_vo
from scipy.constants import c, parsec
from import Database
......@@ -69,7 +68,7 @@ class SED(object):
self.contribution_names = []
self.luminosity = None
self.luminosities = None = InfoDict() = dict()
self.mass_proportional_info = set()
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Institute of Astronomy
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Médéric Boquien
This class is the implementation of a light weight ordered-dictionary-like
object. Its main advantage is that it is very fast to copy, unlike
OrderedDict(), which can take a significant fraction of the runtime.
It makes some very strong assumptions on the data and how the object is
used. Because of this, it should not be used for anything else other than the
info member of the SED class.
The implementation is based on the emulation of a container type and therefore
gives some standard function to behave like a dictionary, making it a drop-in
replacement. The class members are self-explanatory.
class InfoDict(object):
"""Light weight ordered-dictionary-like object that is fast to copy.
def __init__(self, keys=[], values=[]):
self.k = keys[:]
self.v = values[:]
def __len__(self):
return len(self.k)
def __getitem__(self, key):
idx = self.k.index(key)
return self.v[idx]
except ValueError:
raise KeyError
def __setitem__(self, key, value):
if key not in self.k:
self.v[self.k.index(key)] = value
def __contains__(self, key):
if key in self.k:
return True
return False
def keys(self):
return self.k[:]
def values(self):
return self.v[:]
def items(self):
return ((k, v) for k, v in zip(self.k, self.v))
def copy(self):
return InfoDict(self.k, self.v)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment