Exemple #1
0
    def it_passes_context():
        c = "some context"

        def _test(i, j, context):
            nonlocal c
            assert context == c
            return np.array([1, 2])

        idx = FancyIndexer(lengths=lengths, lookup_fn=_test, context=c)
        got = idx[0, :]
        assert np.all(got == [[1, 2], [1, 2]])
Exemple #2
0
 def ims(self):
     """Return a fancy-indexer that can return slices from [fields, channels, cycles]"""
     return FancyIndexer(
         (self.n_fields, self.n_channels, self.n_cycles),
         lookup_fn=lambda fl, ch, cy: self.field_chcy_ims(fl)[ch, cy],
     )
Exemple #3
0
 def aln_unfilt_ims(self):
     return FancyIndexer(
         (self.n_fields, self.n_channels, self.n_cycles),
         lookup_fn=lambda fl, ch, cy: self.aln_unfilt_chcy_ims(fl)[ch, cy],
     )
Exemple #4
0
 def it_indexes_3_dims_with_slices():
     idx = FancyIndexer(lengths=lengths, lookup_fn=_fn)
     got = idx[0, :]
     assert np.all(got == a[0, :])
Exemple #5
0
 def it_indexes_3_dims_with_sigletons():
     idx = FancyIndexer(lengths=lengths, lookup_fn=_fn)
     got = idx[0, 0]
     assert np.all(got == a[0, 0])
     got = idx[0, 1]
     assert np.all(got == a[0, 1])