jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def get_pdos(self, atoms=':', kpts=':', spd=':'):
        '''
        Get site/k-points/spd-orbital projected partial density of states (PDOS)
        '''

        if self._tdos is None:
            self.init_dos()

        pdos = []
        proj = self.get_pw(atoms, kpts, spd)

        atoms, kpts, spd = self.translate_selection(atoms, kpts, spd)

        if len(np.arange(self._nkpts)[kpts]) == self._nkpts:
            if np.all(
                np.sort(np.arange(self._nkpts)[kpts]) == np.arange(self._nkpts)
            ):
                used_all_kpts = True
            else:
                used_all_kpts = False
        else:
            used_all_kpts = False

        for ispin in range(self._nspin):
            pw = proj[ispin]

            if used_all_kpts:
                td = self._tdos[ispin, kpts]
            else:
                # if not all the k-points are used, then probably we should get
                # rid of the k-point weights
                td = self._tdos[ispin, kpts, ...] / \
                    self._kptw[ispin, kpts, np.newaxis, np.newaxis]

            pdos.append(np.sum(pw[..., np.newaxis] * td, axis=(0, 1)))

            # pwht = np.sum(self._aproj[ispin][kpts,:,atoms,spd], axis=(-1, -2))
            # pdos.append(np.sum(pwht[..., np.newaxis] * self._tdos[ispin][kpts,...], axis=(0, 1)))

        # only return one dos if not spin-polarized
        # p = pdos[0] if self._nspin == 1 else pdos
        pdos = np.array(pdos, dtype=float)

        return self._xen, pdos
//  [python]
def test_clearmode_from_lines_wrap_to_dots_scroll(self):
        """A specific test to check that a spike that appears in lines wrap mode is
           correctly cleared by a change to dots scroll."""
        plotter = self.make_a_Plotter("lines", "wrap")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource_onespike()
        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen then wrap to write another 20 values
        for _ in range(200 + 20):
            plotter.data_add((test_source1.data(),))

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique2 == [0, 1]),
                        "Checking pixels are now a mix of 0 and 1")

        plotter.change_stylemode("dots", "scroll")
        unique3, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique3 == [0]),
                        "Checking all pixels are now 0 after change_stylemode")

        plotter.display_off()
//  [python]
def test_clearmode_from_lines_wrap_to_dots_scroll(self):
        """A specific test to check that a spike that appears in lines wrap mode is
           correctly cleared by a change to dots scroll."""
        plotter = self.make_a_Plotter("lines", "wrap")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource_onespike()
        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen then wrap to write another 20 values
        for _ in range(200 + 20):
            plotter.data_add((test_source1.data(),))

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique2 == [0, 1]),
                        "Checking pixels are now a mix of 0 and 1")

        plotter.change_stylemode("dots", "scroll")
        unique3, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique3 == [0]),
                        "Checking all pixels are now 0 after change_stylemode")

        plotter.display_off()
//  [python]
def test00_CompareTable(self):
        """Comparing written unaligned time data with read data in a Table."""

        # Create test Table with data.
        tbl = self.h5file.create_table('/', 'test', self.MyTimeRow)

        # Size of the test.
        nrows = tbl.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        # nrows = 10

        row = tbl.row
        for i in range(nrows):
            row['i8col'] = i
            row['t32col'] = i
            j = i * 2
            row['t64col'] = (j + 0.012, j+1+0.012)
            row.append()

        self._reopen()

        # Check the written data.
        recarr = self.h5file.root.test.read()
        self.h5file.close()

        # Int8 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int8)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", recarr['i8col'][:])
        self.assertTrue(numpy.alltrue(recarr['i8col'][:] == orig_val),
                        "Stored and retrieved values do not match.")

        # Time32 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int32)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", recarr['t32col'][:])
        self.assertTrue(numpy.alltrue(recarr['t32col'][:] == orig_val),
                        "Stored and retrieved values do not match.")

        # Time64 column.
        orig_val = numpy.arange(0, nrows * 2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", recarr['t64col'][:])
        self.assertTrue(allequal(recarr['t64col'][:], orig_val, numpy.float64),
                        "Stored and retrieved values do not match.")
//  [python]
def test00_CompareTable(self):
        """Comparing written unaligned time data with read data in a Table."""

        # Create test Table with data.
        tbl = self.h5file.create_table('/', 'test', self.MyTimeRow)

        # Size of the test.
        nrows = tbl.nrowsinbuf + 34  # Add some more rows than buffer.
        # Only for home checks; the value above should check better
        # the I/O with multiple buffers.
        # nrows = 10

        row = tbl.row
        for i in range(nrows):
            row['i8col'] = i
            row['t32col'] = i
            j = i * 2
            row['t64col'] = (j + 0.012, j+1+0.012)
            row.append()

        self._reopen()

        # Check the written data.
        recarr = self.h5file.root.test.read()
        self.h5file.close()

        # Int8 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int8)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", recarr['i8col'][:])
        self.assertTrue(numpy.all(recarr['i8col'][:] == orig_val),
                        "Stored and retrieved values do not match.")

        # Time32 column.
        orig_val = numpy.arange(nrows, dtype=numpy.int32)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", recarr['t32col'][:])
        self.assertTrue(numpy.all(recarr['t32col'][:] == orig_val),
                        "Stored and retrieved values do not match.")

        # Time64 column.
        orig_val = numpy.arange(0, nrows * 2, dtype=numpy.int32) + 0.012
        orig_val.shape = (nrows, 2)
        if common.verbose:
            print("Original values:", orig_val)
            print("Retrieved values:", recarr['t64col'][:])
        self.assertTrue(allequal(recarr['t64col'][:], orig_val, numpy.float64),
                        "Stored and retrieved values do not match.")
//  [python]
def test_spike_after_wrap_and_overwrite_one_channel(self):
        """A specific test to check that a spike that appears in wrap mode is
           correctly cleared by subsequent flat data."""
        plotter = self.make_a_Plotter("lines", "wrap")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource_onespike()
        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique2 == [0, 1]),
                        "Checking pixels are now a mix of 0 and 1")

        # Rewrite whole screen with new data as we are in wrap mode
        for _ in range(190):
            plotter.data_add((test_source1.data(),))

        non_zero_rows = self.count_nz_rows(plot)

        if verbose >= 4:
            print("y=99", plot[:, 99])
            print("y=100", plot[:, 100])

        self.assertTrue(9 not in non_zero_rows,
                        "Check nothing is just above 90 which plots at 10")
        self.assertEqual(non_zero_rows, [99, 100],
                         "Only pixels left plotted should be from"
                         + "values 0 and 1 being plotted at 99 and 100")
        self.assertTrue(numpy.alltrue(plot[:, 99] == [1] * 190 + [0] * 10),
                        "Checking row 99 precisely")
        self.assertTrue(numpy.alltrue(plot[:, 100] == [0] * 190 + [1] * 10),
                        "Checking row 100 precisely")

        plotter.display_off()
//  [python]
def test_spike_after_wrap_and_overwrite_one_channel(self):
        """A specific test to check that a spike that appears in wrap mode is
           correctly cleared by subsequent flat data."""
        plotter = self.make_a_Plotter("lines", "wrap")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource_onespike()
        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique2 == [0, 1]),
                        "Checking pixels are now a mix of 0 and 1")

        # Rewrite whole screen with new data as we are in wrap mode
        for _ in range(190):
            plotter.data_add((test_source1.data(),))

        non_zero_rows = self.count_nz_rows(plot)

        if verbose >= 4:
            print("y=99", plot[:, 99])
            print("y=100", plot[:, 100])

        self.assertTrue(9 not in non_zero_rows,
                        "Check nothing is just above 90 which plots at 10")
        self.assertEqual(non_zero_rows, [99, 100],
                         "Only pixels left plotted should be from"
                         + "values 0 and 1 being plotted at 99 and 100")
        self.assertTrue(numpy.all(plot[:, 99] == [1] * 190 + [0] * 10),
                        "Checking row 99 precisely")
        self.assertTrue(numpy.all(plot[:, 100] == [0] * 190 + [1] * 10),
                        "Checking row 100 precisely")

        plotter.display_off()
//  [python]
def test_clear_after_scrolling_one_channel(self):
        """A specific test to check screen clears after a scroll to help
           investigate a bug with that failing to happen in most cases."""
        plotter = self.make_a_Plotter("lines", "scroll")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource()
        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique2 == [0, 1]),
                        "Checking pixels are now a mix of 0 and 1")
        self.assertEqual(plotter._values, 200)
        self.assertEqual(plotter._data_values, 200)

        # Force a single scroll of the data
        for _ in range(10):
            plotter.data_add((test_source1.data(),))

        self.assertEqual(plotter._values, 200 + 10)
        self.assertEqual(plotter._data_values, 200 + 10 - self._SCROLL_PX)

        # This should clear all data and the screen
        if verbose >= 3:
            print("change_stylemode() to a new mode which will clear screen")
        plotter.change_stylemode("dots", "wrap")
        unique3, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique3 == [0]),
                        "Checking all pixels are now 0")

        plotter.display_off()
//  [python]
def test_clear_after_scrolling_one_channel(self):
        """A specific test to check screen clears after a scroll to help
           investigate a bug with that failing to happen in most cases."""
        plotter = self.make_a_Plotter("lines", "scroll")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource()
        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique2 == [0, 1]),
                        "Checking pixels are now a mix of 0 and 1")
        self.assertEqual(plotter._values, 200)
        self.assertEqual(plotter._data_values, 200)

        # Force a single scroll of the data
        for _ in range(10):
            plotter.data_add((test_source1.data(),))

        self.assertEqual(plotter._values, 200 + 10)
        self.assertEqual(plotter._data_values, 200 + 10 - self._SCROLL_PX)

        # This should clear all data and the screen
        if verbose >= 3:
            print("change_stylemode() to a new mode which will clear screen")
        plotter.change_stylemode("dots", "wrap")
        unique3, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique3 == [0]),
                        "Checking all pixels are now 0")

        plotter.display_off()
//  [python]
def isEqual(self, val1, val2):
        val1 = numpy.array(val1, 'i')
        val2 = numpy.array(val2, 'i')
        return numpy.alltrue(val1, val2)
//  [python]
def isEqual(self, val1, val2):
        val1 = numpy.array(val1, 'i')
        val2 = numpy.array(val2, 'i')
        return numpy.all(val1 == val2)
//  [python]
def isEqual(self, val1, val2):
        try:
            len(val1)
        except:
            val1 = [val1]
        try:
            len(val2)
        except:
            val2 = [val2]
        val1 = numpy.array(val1, 'i')
        val2 = numpy.array(val2, 'i')
        if val1.shape != val2.shape:
            return False
        return numpy.alltrue(val1, val2)
//  [python]
def isEqual(self, val1, val2):
        try:
            len(val1)
        except:
            val1 = [val1]
        try:
            len(val2)
        except:
            val2 = [val2]
        val1 = numpy.array(val1, 'i')
        val2 = numpy.array(val2, 'i')
        if val1.shape != val2.shape:
            return False
        return numpy.all(val1 == val2)
//  [python]
def timestamps_roughly_match(f1, f2):
    parser = GenericSubtitleParser(skip_ssa_info=True)
    extractor = SubtitleSpeechTransformer(sample_rate=ffsubsync.DEFAULT_FRAME_RATE)
    pipe = make_pipeline(parser, extractor)
    f1_bitstring = pipe.fit_transform(f1).astype(bool)
    f2_bitstring = pipe.fit_transform(f2).astype(bool)
    return np.alltrue(f1_bitstring == f2_bitstring)
//  [python]
def timestamps_roughly_match(f1, f2):
    parser = GenericSubtitleParser(skip_ssa_info=True)
    extractor = SubtitleSpeechTransformer(sample_rate=ffsubsync.DEFAULT_FRAME_RATE)
    pipe = make_pipeline(parser, extractor)
    f1_bitstring = pipe.fit_transform(f1).astype(bool)
    f2_bitstring = pipe.fit_transform(f2).astype(bool)
    return np.all(f1_bitstring == f2_bitstring)
//  [python]
def test_clear_after_scrolling_three_channels(self):
        """A specific test to check screen clears after a scroll with
           multiple channels being plotted (three) to help
           investigate a bug with that failing to happen in most cases
           for the second and third channels."""
        plotter = self.make_a_Plotter("lines", "scroll")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_triplesource1 = self.make_a_PlotSource(channels=3)

        self.ready_plot_source(plotter, test_triplesource1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen
        for _ in range(200):
            plotter.data_add(test_triplesource1.data())

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique2 == [0, 1, 2, 3]),
                        "Checking pixels are now a mix of 0, 1, 2, 3")
        # Force a single scroll of the data
        for _ in range(10):
            plotter.data_add(test_triplesource1.data())

        # This should clear all data and the screen
        if verbose >= 3:
            print("change_stylemode() to a new mode which will clear screen")
        plotter.change_stylemode("dots", "wrap")
        unique3, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique3 == [0]),
                        "Checking all pixels are now 0")

        plotter.display_off()
//  [python]
def test_clear_after_scrolling_three_channels(self):
        """A specific test to check screen clears after a scroll with
           multiple channels being plotted (three) to help
           investigate a bug with that failing to happen in most cases
           for the second and third channels."""
        plotter = self.make_a_Plotter("lines", "scroll")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_triplesource1 = self.make_a_PlotSource(channels=3)

        self.ready_plot_source(plotter, test_triplesource1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen
        for _ in range(200):
            plotter.data_add(test_triplesource1.data())

        unique2, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique2 == [0, 1, 2, 3]),
                        "Checking pixels are now a mix of 0, 1, 2, 3")
        # Force a single scroll of the data
        for _ in range(10):
            plotter.data_add(test_triplesource1.data())

        # This should clear all data and the screen
        if verbose >= 3:
            print("change_stylemode() to a new mode which will clear screen")
        plotter.change_stylemode("dots", "wrap")
        unique3, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique3 == [0]),
                        "Checking all pixels are now 0")

        plotter.display_off()
//  [python]
def test_auto_rescale_wrap_mode(self):
        """Ensure the auto-scaling is working and not leaving any remnants of previous plot."""
        plotter = self.make_a_Plotter("lines", "wrap")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource_bilevel(first_v=60, second_v=900)

        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.alltrue(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen with first 200
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        non_zero_rows1 = self.count_nz_rows(plot)
        self.assertEqual(non_zero_rows1, list(range(0, 40 + 1)),
                         "From value 60 being plotted at 40 but also upward line at end")

        # Rewrite screen with next 200 but these should force an internal
        # rescaling of y axis
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        self.assertEqual(plotter.y_range, (-108.0, 1000.0),
                         "Check rescaled y range")

        non_zero_rows2 = self.count_nz_rows(plot)
        self.assertEqual(non_zero_rows2, [18],
                         "Only pixels now should be from value 900 being plotted at 18")

        plotter.display_off()
//  [python]
def test_auto_rescale_wrap_mode(self):
        """Ensure the auto-scaling is working and not leaving any remnants of previous plot."""
        plotter = self.make_a_Plotter("lines", "wrap")
        (tg, plot) = (Mock(), numpy.zeros((self._PLOT_WIDTH, self._PLOT_HEIGHT), numpy.uint8))
        plotter.display_on(tg_and_plot=(tg, plot))
        test_source1 = self.make_a_PlotSource_bilevel(first_v=60, second_v=900)

        self.ready_plot_source(plotter, test_source1)

        unique1, _ = numpy.unique(plot, return_counts=True)
        self.assertTrue(numpy.all(unique1 == [0]),
                        "Checking all pixels start as 0")

        # Fill screen with first 200
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        non_zero_rows1 = self.count_nz_rows(plot)
        self.assertEqual(non_zero_rows1, list(range(0, 40 + 1)),
                         "From value 60 being plotted at 40 but also upward line at end")

        # Rewrite screen with next 200 but these should force an internal
        # rescaling of y axis
        for _ in range(200):
            plotter.data_add((test_source1.data(),))

        self.assertEqual(plotter.y_range, (-108.0, 1000.0),
                         "Check rescaled y range")

        non_zero_rows2 = self.count_nz_rows(plot)
        self.assertEqual(non_zero_rows2, [18],
                         "Only pixels now should be from value 900 being plotted at 18")

        plotter.display_off()
//  [python]
def test_iter(self):
        # Override testIter.

        index = self.cls(TEXTS, self.w2v_model)
        for sims in index:
            self.assertTrue(numpy.alltrue(sims >= 0.0))
            self.assertTrue(numpy.alltrue(sims <= 1.0))
//  [python]
def test_iter(self):
        # Override testIter.

        index = self.cls(TEXTS, self.w2v_model)
        for sims in index:
            self.assertTrue(numpy.all(sims >= 0.0))
            self.assertTrue(numpy.all(sims <= 1.0))
//  [python]
def test_full(self, num_best=None):
        # Override testFull.

        index = self.cls(TEXTS, self.w2v_model)
        index.num_best = num_best
        query = TEXTS[0]
        sims = index[query]

        if num_best is not None:
            # Sparse array.
            for i, sim in sims:
                # Note that similarities are bigger than zero, as they are the 1/ 1 + distances.
                self.assertTrue(numpy.alltrue(sim > 0.0))
        else:
            self.assertTrue(sims[0] == 1.0)  # Similarity of a document with itself is 0.0.
            self.assertTrue(numpy.alltrue(sims[1:] > 0.0))
            self.assertTrue(numpy.alltrue(sims[1:] < 1.0))
//  [python]
def test_full(self, num_best=None):
        # Override testFull.

        index = self.cls(TEXTS, self.w2v_model)
        index.num_best = num_best
        query = TEXTS[0]
        sims = index[query]

        if num_best is not None:
            # Sparse array.
            for i, sim in sims:
                # Note that similarities are bigger than zero, as they are the 1/ 1 + distances.
                self.assertTrue(numpy.all(sim > 0.0))
        else:
            self.assertTrue(sims[0] == 1.0)  # Similarity of a document with itself is 0.0.
            self.assertTrue(numpy.all(sims[1:] > 0.0))
            self.assertTrue(numpy.all(sims[1:] < 1.0))
//  [python]
def test_AddTimeFeatures(start, target, is_train: bool):
    pred_length = 13
    t = transform.AddTimeFeatures(
        start_field=FieldName.START,
        target_field=FieldName.TARGET,
        output_field="myout",
        pred_length=pred_length,
        time_features=[time_feature.day_of_week, time_feature.day_of_month],
        dtype=np.float64,
    )

    assert_serializable(t)

    data = {"start": start, "target": target}
    res = t.map_transform(data, is_train=is_train)
    mat = res["myout"]
    expected_length = len(target) + (0 if is_train else pred_length)
    assert mat.shape == (2, expected_length)
    tmp_idx = pd.period_range(
        start=start, freq=start.freq, periods=expected_length
    )
    assert np.alltrue(mat[0] == time_feature.day_of_week(tmp_idx))
    assert np.alltrue(mat[1] == time_feature.day_of_month(tmp_idx))
//  [python]
def test_AddTimeFeatures(start, target, is_train: bool):
    pred_length = 13
    t = transform.AddTimeFeatures(
        start_field=FieldName.START,
        target_field=FieldName.TARGET,
        output_field="myout",
        pred_length=pred_length,
        time_features=[time_feature.day_of_week, time_feature.day_of_month],
        dtype=np.float64,
    )

    assert_serializable(t)

    data = {"start": start, "target": target}
    res = t.map_transform(data, is_train=is_train)
    mat = res["myout"]
    expected_length = len(target) + (0 if is_train else pred_length)
    assert mat.shape == (2, expected_length)
    tmp_idx = pd.period_range(
        start=start, freq=start.freq, periods=expected_length
    )
    assert np.all(mat[0] == time_feature.day_of_week(tmp_idx))
    assert np.all(mat[1] == time_feature.day_of_month(tmp_idx))
//  [python]
def test_chunking(self):
        # Override testChunking.

        index = self.cls(TEXTS, self.w2v_model)
        query = TEXTS[:3]
        sims = index[query]

        for i in range(3):
            self.assertTrue(numpy.alltrue(sims[i, i] == 1.0))  # Similarity of a document with itself is 0.0.

        # test the same thing but with num_best
        index.num_best = 3
        sims = index[query]
        for sims_temp in sims:
            for i, sim in sims_temp:
                self.assertTrue(numpy.alltrue(sim > 0.0))
                self.assertTrue(numpy.alltrue(sim <= 1.0))
//  [python]
def test_chunking(self):
        # Override testChunking.

        index = self.cls(TEXTS, self.w2v_model)
        query = TEXTS[:3]
        sims = index[query]

        for i in range(3):
            self.assertTrue(numpy.all(sims[i, i] == 1.0))  # Similarity of a document with itself is 0.0.

        # test the same thing but with num_best
        index.num_best = 3
        sims = index[query]
        for sims_temp in sims:
            for i, sim in sims_temp:
                self.assertTrue(numpy.all(sim > 0.0))
                self.assertTrue(numpy.all(sim <= 1.0))
//  [python]
def 全部真(*args,  **kwargs):
		return cn_array(numpy.alltrue(*args,  **kwargs))
//  [python]
def 全部真(*args,  **kwargs):
		return cn_array(numpy.all(*args,  **kwargs))
//  [python]
def test_bins(self):
        """Linear and quantile bins are correct
        """

        for filename in ['%s/population_padang_1.asc' % TESTDATA,
                         '%s/test_grid.asc' % TESTDATA]:

            R = read_layer(filename)
            min, max = R.get_extrema()

            for N in [2, 3, 5, 7, 10, 16]:
                linear_intervals = R.get_bins(N=N, quantiles=False)

                assert linear_intervals[0] == min
                assert linear_intervals[-1] == max

                d = (max - min) / N
                for i in range(N):
                    assert numpy.allclose(linear_intervals[i], min + i * d)

                quantiles = R.get_bins(N=N, quantiles=True)
                A = R.get_data(nan=True).flat[:]

                mask = numpy.logical_not(numpy.isnan(A))  # Omit NaN's
                l1 = len(A)
                A = A.compress(mask)
                l2 = len(A)

                if filename == '%s/test_grid.asc' % TESTDATA:
                    # Check that NaN's were removed
                    assert l1 == 35
                    assert l2 == 30

                # Assert that there are no NaN's
                assert not numpy.alltrue(numpy.isnan(A))

                number_of_elements = len(A)
                average_elements_per_bin = number_of_elements / N

                # Count elements in each bin and check
                i0 = quantiles[0]
                for i1 in quantiles[1:]:
                    count = numpy.sum((i0 < A) & (A < i1))
                    if i0 == quantiles[0]:
                        refcount = count

                    if i1 < quantiles[-1]:
                        # Number of elements in each bin must vary by no
                        # more than 1
                        assert abs(count - refcount) <= 1
                        assert abs(count - average_elements_per_bin) <= 3
                    else:
                        # The last bin is allowed vary by more
                        pass

                    i0 = i1
//  [python]
def test_bins(self):
        """Linear and quantile bins are correct
        """

        for filename in ['%s/population_padang_1.asc' % TESTDATA,
                         '%s/test_grid.asc' % TESTDATA]:

            R = read_layer(filename)
            min, max = R.get_extrema()

            for N in [2, 3, 5, 7, 10, 16]:
                linear_intervals = R.get_bins(N=N, quantiles=False)

                assert linear_intervals[0] == min
                assert linear_intervals[-1] == max

                d = (max - min) / N
                for i in range(N):
                    assert numpy.allclose(linear_intervals[i], min + i * d)

                quantiles = R.get_bins(N=N, quantiles=True)
                A = R.get_data(nan=True).flat[:]

                mask = numpy.logical_not(numpy.isnan(A))  # Omit NaN's
                l1 = len(A)
                A = A.compress(mask)
                l2 = len(A)

                if filename == '%s/test_grid.asc' % TESTDATA:
                    # Check that NaN's were removed
                    assert l1 == 35
                    assert l2 == 30

                # Assert that there are no NaN's
                assert not numpy.all(numpy.isnan(A))

                number_of_elements = len(A)
                average_elements_per_bin = number_of_elements / N

                # Count elements in each bin and check
                i0 = quantiles[0]
                for i1 in quantiles[1:]:
                    count = numpy.sum((i0 < A) & (A < i1))
                    if i0 == quantiles[0]:
                        refcount = count

                    if i1 < quantiles[-1]:
                        # Number of elements in each bin must vary by no
                        # more than 1
                        assert abs(count - refcount) <= 1
                        assert abs(count - average_elements_per_bin) <= 3
                    else:
                        # The last bin is allowed vary by more
                        pass

                    i0 = i1
//  [python]
def test_iter(self):
        index = self.cls(CORPUS, self.similarity_matrix)
        for sims in index:
            self.assertTrue(numpy.alltrue(sims >= 0.0))
            self.assertTrue(numpy.alltrue(sims <= 1.0))
//  [python]
def test_iter(self):
        index = self.cls(CORPUS, self.similarity_matrix)
        for sims in index:
            self.assertTrue(numpy.all(sims >= 0.0))
            self.assertTrue(numpy.all(sims <= 1.0))
//  [python]
def test_chunking(self):
        index = self.cls(CORPUS, self.similarity_matrix)
        query = [DICTIONARY.doc2bow(document) for document in TEXTS[:3]]
        sims = index[query]

        for i in range(3):
            self.assertTrue(numpy.alltrue(sims[i, i] == 1.0))  # Similarity of a document with itself is 1.0.

        # test the same thing but with num_best
        index.num_best = 5
        sims = index[query]
        for i, chunk in enumerate(sims):
            expected = i
            self.assertAlmostEqual(expected, chunk[0][0], places=2)
            expected = 1.0
            self.assertAlmostEqual(expected, chunk[0][1], places=2)
//  [python]
def test_chunking(self):
        index = self.cls(CORPUS, self.similarity_matrix)
        query = [DICTIONARY.doc2bow(document) for document in TEXTS[:3]]
        sims = index[query]

        for i in range(3):
            self.assertTrue(numpy.all(sims[i, i] == 1.0))  # Similarity of a document with itself is 1.0.

        # test the same thing but with num_best
        index.num_best = 5
        sims = index[query]
        for i, chunk in enumerate(sims):
            expected = i
            self.assertAlmostEqual(expected, chunk[0][0], places=2)
            expected = 1.0
            self.assertAlmostEqual(expected, chunk[0][1], places=2)
//  [python]
def _check_units(contours):
    units = [contour.units for contour in contours]
    if not numpy.alltrue([u == units[0] for u in units]):
        raise ValueError('All contours must have the same units in order to plot them on the same axes.')
    units = units[0]
    return units
//  [python]
def _check_units(contours):
    units = [contour.units for contour in contours]
    if not numpy.all([u == units[0] for u in units]):
        raise ValueError('All contours must have the same units in order to plot them on the same axes.')
    units = units[0]
    return units
//  [python]
def test_temperature_WODflags(classic1):
    '''
    check WOD flags are not returned = [--, --, --, --]
    '''

    qc = classic1.t_level_qc('WOD')
    assert numpy.alltrue(qc.mask) , \
        'temperature_WODflags should not be in file, instead read %s' % qc.__str__()
//  [python]
def test_temperature_WODflags(classic1):
    '''
    check WOD flags are not returned = [--, --, --, --]
    '''

    qc = classic1.t_level_qc('WOD')
    assert numpy.all(qc.mask) , \
        'temperature_WODflags should not be in file, instead read %s' % qc.__str__()
//  [python]
def test_full(self, num_best=None):
        # Single query
        index = self.cls(CORPUS, self.similarity_matrix, num_best=num_best)
        query = DICTIONARY.doc2bow(TEXTS[0])
        sims = index[query]
        if num_best is not None:
            # Sparse array.
            for i, sim in sims:
                self.assertTrue(numpy.alltrue(sim <= 1.0))
                self.assertTrue(numpy.alltrue(sim >= 0.0))
        else:
            self.assertAlmostEqual(1.0, sims[0])  # Similarity of a document with itself is 1.0.
            self.assertTrue(numpy.alltrue(sims[1:] >= 0.0))
            self.assertTrue(numpy.alltrue(sims[1:] < 1.0))

        # Corpora
        for query in (
                CORPUS,  # Basic text corpus.
                self.tfidf[CORPUS]):  # Transformed corpus without slicing support.
            index = self.cls(query, self.similarity_matrix, num_best=num_best)
            sims = index[query]
            if num_best is not None:
                # Sparse array.
                for result in sims:
                    for i, sim in result:
                        self.assertTrue(numpy.alltrue(sim <= 1.0))
                        self.assertTrue(numpy.alltrue(sim >= 0.0))
            else:
                for i, result in enumerate(sims):
                    self.assertAlmostEqual(1.0, result[i])  # Similarity of a document with itself is 1.0.
                    self.assertTrue(numpy.alltrue(result[:i] >= 0.0))
                    self.assertTrue(numpy.alltrue(result[:i] < 1.0))
                    self.assertTrue(numpy.alltrue(result[i + 1:] >= 0.0))
                    self.assertTrue(numpy.alltrue(result[i + 1:] < 1.0))
//  [python]
def test_full(self, num_best=None):
        # Single query
        index = self.cls(CORPUS, self.similarity_matrix, num_best=num_best)
        query = DICTIONARY.doc2bow(TEXTS[0])
        sims = index[query]
        if num_best is not None:
            # Sparse array.
            for i, sim in sims:
                self.assertTrue(numpy.all(sim <= 1.0))
                self.assertTrue(numpy.all(sim >= 0.0))
        else:
            self.assertAlmostEqual(1.0, sims[0])  # Similarity of a document with itself is 1.0.
            self.assertTrue(numpy.all(sims[1:] >= 0.0))
            self.assertTrue(numpy.all(sims[1:] < 1.0))

        # Corpora
        for query in (
                CORPUS,  # Basic text corpus.
                self.tfidf[CORPUS]):  # Transformed corpus without slicing support.
            index = self.cls(query, self.similarity_matrix, num_best=num_best)
            sims = index[query]
            if num_best is not None:
                # Sparse array.
                for result in sims:
                    for i, sim in result:
                        self.assertTrue(numpy.all(sim <= 1.0))
                        self.assertTrue(numpy.all(sim >= 0.0))
            else:
                for i, result in enumerate(sims):
                    self.assertAlmostEqual(1.0, result[i])  # Similarity of a document with itself is 1.0.
                    self.assertTrue(numpy.all(result[:i] >= 0.0))
                    self.assertTrue(numpy.all(result[:i] < 1.0))
                    self.assertTrue(numpy.all(result[i + 1:] >= 0.0))
                    self.assertTrue(numpy.all(result[i + 1:] < 1.0))
//  [python]
def test_temperature_IQUODflags(classic1):
    '''
    check IQUOD flags are returned = [0, 0, 0, 0]
    '''

    errors = []
    truth = [0, 0, 0, 0]
    qc = classic1.t_level_qc('IQUOD')
    # replace assertions by conditions
    if numpy.alltrue(qc.mask):
        errors.append("Temperature_IQUODflags not found in file")
    if not numpy.array_equal(qc, truth):
        errors.append('Temperature_IQUODflags should have been [0, 0, 0, 0], instead read %s' % qc.__str__())

    # assert no error message has been registered, else print messages
    assert not errors, "errors occured:\n{}".format("\n".join(errors))
//  [python]
def test_temperature_IQUODflags(classic1):
    '''
    check IQUOD flags are returned = [0, 0, 0, 0]
    '''

    errors = []
    truth = [0, 0, 0, 0]
    qc = classic1.t_level_qc('IQUOD')
    # replace assertions by conditions
    if numpy.all(qc.mask):
        errors.append("Temperature_IQUODflags not found in file")
    if not numpy.array_equal(qc, truth):
        errors.append('Temperature_IQUODflags should have been [0, 0, 0, 0], instead read %s' % qc.__str__())

    # assert no error message has been registered, else print messages
    assert not errors, "errors occured:\n{}".format("\n".join(errors))
//  [python]
def createSorMask(pupil,wfs_n=1,minarea=0.):
    """typically, pupil will be the telescope pupil (phase points), wfs_n will be number of pixels (of phase) per subaperture in 1 direction, and minarea will be the fraction of pixels required to have a valid subaperture.  If n=1 and minarea=0 (default), then the pupil function will be exactly that given...
    This should be flattened (mask.flat) before being used with util.sor.
    """
    n=wfs_n
    if type(pupil)==numpy.ndarray:#Numeric.ArrayType:
        pass
    else:
        pupil=pupil.fn
    npup=pupil.shape[0]
    nx=npup/n
    pupfn=numpy.zeros((nx+2,nx+2),numpy.int32)
    imirr=numpy.zeros((nx,nx),numpy.int32)
    total=0
    for i in range(nx):
        for j in range(nx):
            subarea=numpy.sum(numpy.sum(pupil[i*n:(i+1)*n,j*n:(j+1)*n]))
            if subarea>=minarea*n*n:
                pupfn[i+1,j+1]=1
                total+=1

    for i in range(nx):
        for j in range(nx):
            k=i+1
            l=j+1
            fl2=numpy.array(pupfn[k-1:k+2,l-1:l+2],copy=1)
            fl2[0,0]=1
            fl2[0,2]=1
            fl2[2,0]=1
            fl2[2,2]=1
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=1
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,0,1],[0,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=2
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,0,1],[1,1,0],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=3
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,1,1],[0,1,1],[1,0,1]],numpy.int32) ) ) )) :
                imirr[j][i]=4
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,0],[1,0,1]],numpy.int32) ) ) )) :
                imirr[j][i]=5
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,0,1],[1,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=6
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,1],[1,0,1]],numpy.int32) ) ) )) :
                imirr[j][i]=7
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,1,1],[0,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=8
            if( numpy.alltrue(numpy.alltrue( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,0],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=9
    return imirr
//  [python]
def createSorMask(pupil,wfs_n=1,minarea=0.):
    """typically, pupil will be the telescope pupil (phase points), wfs_n will be number of pixels (of phase) per subaperture in 1 direction, and minarea will be the fraction of pixels required to have a valid subaperture.  If n=1 and minarea=0 (default), then the pupil function will be exactly that given...
    This should be flattened (mask.flat) before being used with util.sor.
    """
    n=wfs_n
    if type(pupil)==numpy.ndarray:#Numeric.ArrayType:
        pass
    else:
        pupil=pupil.fn
    npup=pupil.shape[0]
    nx=npup/n
    pupfn=numpy.zeros((nx+2,nx+2),numpy.int32)
    imirr=numpy.zeros((nx,nx),numpy.int32)
    total=0
    for i in range(nx):
        for j in range(nx):
            subarea=numpy.sum(numpy.sum(pupil[i*n:(i+1)*n,j*n:(j+1)*n]))
            if subarea>=minarea*n*n:
                pupfn[i+1,j+1]=1
                total+=1

    for i in range(nx):
        for j in range(nx):
            k=i+1
            l=j+1
            fl2=numpy.array(pupfn[k-1:k+2,l-1:l+2],copy=1)
            fl2[0,0]=1
            fl2[0,2]=1
            fl2[2,0]=1
            fl2[2,2]=1
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=1
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,0,1],[0,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=2
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,0,1],[1,1,0],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=3
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,1,1],[0,1,1],[1,0,1]],numpy.int32) ) ) )) :
                imirr[j][i]=4
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,0],[1,0,1]],numpy.int32) ) ) )) :
                imirr[j][i]=5
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,0,1],[1,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=6
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,1],[1,0,1]],numpy.int32) ) ) )) :
                imirr[j][i]=7
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,1,1],[0,1,1],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=8
            if( numpy.all(numpy.all( numpy.equal( fl2 , numpy.array([[1,1,1],[1,1,0],[1,1,1]],numpy.int32) ) ) )) :
                imirr[j][i]=9
    return imirr
//  [python]
def test01a_read(self):
        """Test for point-selections (read, boolean keys)."""

        nparr = self.nparr
        tbarr = self.tbarr
        for value1, value2 in self.limits:
            key = (nparr >= value1) & (nparr < value2)
            if common.verbose:
                print("Selection to test:", key)
            a = nparr[key]
            b = tbarr[key]
            self.assertTrue(
                numpy.alltrue(a == b),
                "NumPy array and PyTables selections does not match.")
//  [python]
def test01a_read(self):
        """Test for point-selections (read, boolean keys)."""

        nparr = self.nparr
        tbarr = self.tbarr
        for value1, value2 in self.limits:
            key = (nparr >= value1) & (nparr < value2)
            if common.verbose:
                print("Selection to test:", key)
            a = nparr[key]
            b = tbarr[key]
            self.assertTrue(
                numpy.all(a == b),
                "NumPy array and PyTables selections does not match.")
//  [python]
def test01b_read(self):
        """Test for point-selections (read, integer keys)."""

        nparr = self.nparr
        tbarr = self.tbarr
        for value1, value2 in self.limits:
            key = numpy.where((nparr >= value1) & (nparr < value2))
            if common.verbose:
                print("Selection to test:", key)
            a = nparr[key]
            b = tbarr[key]
            self.assertTrue(
                numpy.alltrue(a == b),
                "NumPy array and PyTables selections does not match.")
//  [python]
def test01b_read(self):
        """Test for point-selections (read, integer keys)."""

        nparr = self.nparr
        tbarr = self.tbarr
        for value1, value2 in self.limits:
            key = numpy.where((nparr >= value1) & (nparr < value2))
            if common.verbose:
                print("Selection to test:", key)
            a = nparr[key]
            b = tbarr[key]
            self.assertTrue(
                numpy.all(a == b),
                "NumPy array and PyTables selections does not match.")
//  [python]
def test02a_write(self):
        """Test for point-selections (write, boolean keys)."""

        nparr = self.nparr
        tbarr = self.tbarr
        for value1, value2 in self.limits:
            key = (nparr >= value1) & (nparr < value2)
            if common.verbose:
                print("Selection to test:", key)
            s = nparr[key]
            nparr[key] = s * 2
            tbarr[key] = s * 2
            a = nparr[:]
            b = tbarr[:]
            self.assertTrue(
                numpy.alltrue(a == b),
                "NumPy array and PyTables modifications does not match.")
//  [python]
def test02a_write(self):
        """Test for point-selections (write, boolean keys)."""

        nparr = self.nparr
        tbarr = self.tbarr
        for value1, value2 in self.limits:
            key = (nparr >= value1) & (nparr < value2)
            if common.verbose:
                print("Selection to test:", key)
            s = nparr[key]
            nparr[key] = s * 2
            tbarr[key] = s * 2
            a = nparr[:]
            b = tbarr[:]
            self.assertTrue(
                numpy.all(a == b),
                "NumPy array and PyTables modifications does not match.")