text:
namespace password_manager {
namespace urls_collection_experiment {

namespace {

int kParamActivePeriodInDaysValue = 7;
int kParamExperimentLengthInDaysValue = 365;
const char kGroupShowBubbleWithClock[] = "ShowBubbleWithClock";
const char kGroupNeverShowBubbleWithClock[] = "NeverShowBubbleWithClock";

void SetupShowBubbleWithClockExperimentGroup() {
  ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
      kExperimentName, kGroupShowBubbleWithClock));
  std::map<std::string, std::string> params;
  params[kParamActivePeriodInDays] =
      base::IntToString(kParamActivePeriodInDaysValue);
  params[kParamExperimentLengthInDays] =
      base::IntToString(kParamExperimentLengthInDaysValue);
  params[kParamBubbleStatus] = kParamBubbleStatusValueWhenShouldShow;
  ASSERT_TRUE(variations::AssociateVariationParams(
      kExperimentName, kGroupShowBubbleWithClock, params));
}

void SetupNeverShowBubbleWithClockExperimentGroup() {
  ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
      kExperimentName, kGroupNeverShowBubbleWithClock));
}

}  // namespace

// Same as ShouldShowBubble(PrefService* prefs), but specifies a mock
// interface for clock functions for testing.
bool ShouldShowBubbleWithClock(PrefService* prefs, base::Clock* clock);

class PasswordManagerUrlsCollectionExperimentTest : public testing::Test {
 public:
  PasswordManagerUrlsCollectionExperimentTest()
      : field_trial_list_(new metrics::SHA1EntropyProvider("foo")) {}

  void SetUp() override {
    pref_service_.registry()->RegisterBooleanPref(
        prefs::kAllowToCollectURLBubbleWasShown, false);
    pref_service_.registry()->RegisterDoublePref(
        prefs::kAllowToCollectURLBubbleActivePeriodStartFactor, -1);
  }
  void TearDown() override { variations::testing::ClearAllVariationParams(); }

  void SetTimeToBubbleActivePeriod(int experiment_length_in_days) {
    base::Time starting_time =
        DetermineStartOfActivityPeriod(prefs(), experiment_length_in_days);
    test_clock()->SetNow(starting_time);
  }

  void SetTimePastBubbleActivePeriod(int experiment_length_in_days) {
    base::Time starting_time =
        DetermineStartOfActivityPeriod(prefs(), experiment_length_in_days);
    test_clock()->SetNow(starting_time + base::TimeDelta::FromDays(
                                             kParamActivePeriodInDaysValue));
  }

  void PretendBubbleWasAlreadyShown() {
    prefs()->SetBoolean(prefs::kAllowToCollectURLBubbleWasShown, true);
  }

  PrefService* prefs() { return &pref_service_; }

  base::SimpleTestClock* test_clock() { return &test_clock_; }

 private:
  TestingPrefServiceSimple pref_service_;
  base::FieldTrialList field_trial_list_;
  base::SimpleTestClock test_clock_;

  DISALLOW_COPY_AND_ASSIGN(PasswordManagerUrlsCollectionExperimentTest);
};

TEST_F(PasswordManagerUrlsCollectionExperimentTest,
       TestShowBubbleWithClockGroupTimeSpanWhenBubbleShouldAppear) {
  SetupShowBubbleWithClockExperimentGroup();
  SetTimeToBubbleActivePeriod(kParamExperimentLengthInDaysValue);
  EXPECT_TRUE(ShouldShowBubbleWithClock(prefs(), test_clock()));
}

TEST_F(PasswordManagerUrlsCollectionExperimentTest,
       TestShowBubbleWithClockGroupTimeSpanWhenBubbleShouldNotAppear) {
  SetupShowBubbleWithClockExperimentGroup();
  SetTimePastBubbleActivePeriod(kParamExperimentLengthInDaysValue);
  EXPECT_FALSE(ShouldShowBubbleWithClock(prefs(), test_clock()));
}

TEST_F(PasswordManagerUrlsCollectionExperimentTest,
       TestNeverShowBubbleWithClockGroup) {
  SetupNeverShowBubbleWithClockExperimentGroup();
  SetTimeToBubbleActivePeriod(kParamExperimentLengthInDaysValue);
  EXPECT_FALSE(ShouldShowBubbleWithClock(prefs(), test_clock()));
}

TEST_F(PasswordManagerUrlsCollectionExperimentTest, TestBubbleWasAlreadyShown) {
  SetupShowBubbleWithClockExperimentGroup();
  SetTimeToBubbleActivePeriod(kParamExperimentLengthInDaysValue);
  PretendBubbleWasAlreadyShown();
  EXPECT_FALSE(ShouldShowBubbleWithClock(prefs(), test_clock()));
}

}  //  namespace urls_collection_experiment
}  //  namespace password_manager


text:
ONNX provides an optional implementation of shape inference on ONNX
graphs. This implementation covers each of the core operators, as well
as provides an interface for extensibility. Therefore, you may choose
to invoke the existing shape inference functionality on your graphs,
or to define shape inference implementations to go along with your
custom operators (or both!). Shape inference functions are stored as a
member of the OpSchema objects.

## Invoking Shape Inference

Shape inference can be invoked either via C++ or Python. The Python
API is described, with example,
[here](PythonAPIOverview.md#running-shape-inference-on-an-onnx-model).

The C++ API consists of a single function

```
shape_inference::InferShapes(
    ModelProto& m,
    const ISchemaRegistry* schema_registry);
```

The first argument is a `ModelProto` to perform shape inference on,
which is annotated in-place with shape information. The second
argument is optional.

## Implementing Shape Inference For Custom Operators

You can add a shape inference function to your operator's Schema with

```
OpSchema& Opschema::TypeAndShapeInferenceFunction(InferenceFunction inferenceFunction);
```

`InferenceFunction` is defined in
[shape_inference.h](onnx/defs/shape_inference.h), along with the core
interface struct `InferenceContext` and an assortment of helper
methods. `InferenceContext` is the core struct which is provided to
your inference function. It allows accessing information about the
operator's inputs, and also allows writing out inferred information.

To see numerous examples, search for occurences of
`TypeAndShapeInferenceFunction` in the codebase. One that is
relatively involved is the implementation for `Concat`, in
onnx/defs/tensor/defs.cc.

## Limitations

Shape inference is not guaranteed to be complete. In particular, some
dynamic behaviors block the flow of shape inference, for example a
Reshape to a dynamically-provide shape. Also, all operators are not
required to have a shape inference implementation.

Shape inference works only with constants and simple variables. It
does not support arithmetic expressions containing variables. For
example, `Concat` on tensors of shapes `(5, 2)` and `(7, 2)` can be
inferred to produce a result of shape `(12, 2)`, but `Concat` on
tensors of shapes `(5, 2)` and `(N, 2)` will simply produce `(M, 2)`,
rather than containing a representation of `N+5`. Note that differing
unknown symbolic values will be propagated, so the `M` here represents
an unknown quantity that is the same as other occurences of `M`.

These limitations are a property of the current implementation, not
fundamental constraints - if you are in need of something more
advanced, do let us know!

redpajama_set_name: RedPajamaGithub


text:
'use strict';

/**
 * @ngdoc service
 * @name smartiApp.ClientService
 * @description
 * # ClientService
 * Service in the smartiApp.
 */
angular.module('smartiApp')
  .service('ClientService', function ($http, $q, ENV, Configuration, Client) {

    this.list = function() {
      var deferred = $q.defer();

      $http.get(ENV.serviceBaseUrl + '/client').then(function(data){
        deferred.resolve(data.data.map(function(c){return new Client(c);}));
      });

      return deferred.promise;
    };

    this.getById = function(id,copy) {
      var deferred = $q.defer();

      $http.get(ENV.serviceBaseUrl + '/client/' + id).then(function(data){
        var newClient = new Client(data.data,copy);
        if (copy) {
          newClient.data.defaultClient = false;
        }
        deferred.resolve(newClient);
      });

      return deferred.promise;
    };

    this.loadAuthTokens = function (client) {
      return $http.get(ENV.serviceBaseUrl + '/client/' + client.data.id + '/token')
        .then(function (response) {
          return response.data;
        });
    };

    this.createAuthToken = function (client, label) {
      return $http
        .post(ENV.serviceBaseUrl + '/client/' + client.data.id + '/token', {
          label: label
        })
        .then(function (response) {
          return response.data;
        });
    };

    this.updateAuthToken = function (client, token) {
      return $http
        .put(ENV.serviceBaseUrl + '/client/' + client.data.id + '/token/' + token.id, token)
        .then(function (response) {
          return response.data;
        });
    };

    this.revokeAuthToken = function (client, token) {
      return $http
        .delete(ENV.serviceBaseUrl + '/client/' + client.data.id + '/token/' + token.id)
        .then(function (response) {
          return response.data;
        });
    };

    this.listUsers = function (client) {
      return $http
        .get(ENV.serviceBaseUrl + '/client/' + client.data.id + '/user')
        .then(function (response) {
          return response.data;
        });
    };

    this.createUser = function (user, client) {
      return $http
        .post(ENV.serviceBaseUrl + '/client/' + client.data.id + '/user', user)
        .then(function (response) {
          return response.data;
        });
    };

    this.addUser = function (login, client) {
      return $http
        .put(ENV.serviceBaseUrl + '/client/' + client.data.id + '/user/' + login, undefined)
        .then(function (response) {
          return response.data;
        });
    };

    this.removeUser = function (user, client) {
      return $http
        .delete(ENV.serviceBaseUrl + '/client/' + client.data.id + '/user/' + user.login)
        .then(function (response) {
          return response.data;
        });
    };

  });


text:
use alloc::arc::{Arc, Weak};
use collections::VecDeque;
use core::intrinsics;
use spin::Mutex;

use arch::memory::Frame;
use arch::paging::{ActivePageTable, InactivePageTable, Page, PageIter, PhysicalAddress, VirtualAddress};
use arch::paging::entry::{self, EntryFlags};
use arch::paging::mapper::MapperFlushAll;
use arch::paging::temporary_page::TemporaryPage;

#[derive(Debug)]
pub struct Grant {
    start: VirtualAddress,
    size: usize,
    flags: EntryFlags,
    mapped: bool
}

impl Grant {
    pub fn physmap(from: PhysicalAddress, to: VirtualAddress, size: usize, flags: EntryFlags) -> Grant {
        let mut active_table = unsafe { ActivePageTable::new() };

        let mut flush_all = MapperFlushAll::new();

        let start_page = Page::containing_address(to);
        let end_page = Page::containing_address(VirtualAddress::new(to.get() + size - 1));
        for page in Page::range_inclusive(start_page, end_page) {
            let frame = Frame::containing_address(PhysicalAddress::new(page.start_address().get() - to.get() + from.get()));
            let result = active_table.map_to(page, frame, flags);
            flush_all.consume(result);
        }

        flush_all.flush(&mut active_table);

        Grant {
            start: to,
            size: size,
            flags: flags,
            mapped: true
        }
    }

    pub fn map_inactive(from: VirtualAddress, to: VirtualAddress, size: usize, flags: EntryFlags, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) -> Grant {
        let mut active_table = unsafe { ActivePageTable::new() };

        let mut frames = VecDeque::new();

        let start_page = Page::containing_address(from);
        let end_page = Page::containing_address(VirtualAddress::new(from.get() + size - 1));
        for page in Page::range_inclusive(start_page, end_page) {
            let frame = active_table.translate_page(page).expect("grant references unmapped memory");
            frames.push_back(frame);
        }

        active_table.with(new_table, temporary_page, |mapper| {
            let start_page = Page::containing_address(to);
            let end_page = Page::containing_address(VirtualAddress::new(to.get() + size - 1));
            for page in Page::range_inclusive(start_page, end_page) {
                let frame = frames.pop_front().expect("grant did not find enough frames");
                let result = mapper.map_to(page, frame, flags);
                // Ignore result due to mapping on inactive table
                unsafe { result.ignore(); }
            }
        });

        Grant {
            start: to,
            size: size,
            flags: flags,
            mapped: true
        }
    }

    pub fn start_address(&self) -> VirtualAddress {
        self.start
    }

    pub fn size(&self) -> usize {
        self.size
    }

    pub fn flags(&self) -> EntryFlags {
        self.flags
    }

    pub fn unmap(mut self) {
        assert!(self.mapped);

        let mut active_table = unsafe { ActivePageTable::new() };

        let mut flush_all = MapperFlushAll::new();

        let start_page = Page::containing_address(self.start);
        let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size - 1));
        for page in Page::range_inclusive(start_page, end_page) {
            let (result, _frame) = active_table.unmap_return(page);
            flush_all.consume(result);
        }

        flush_all.flush(&mut active_table);

        self.mapped = false;
    }

    pub fn unmap_inactive(mut self, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) {
        assert!(self.mapped);

        let mut active_table = unsafe { ActivePageTable::new() };

        active_table.with(new_table, temporary_page, |mapper| {
            let start_page = Page::containing_address(self.start);
            let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size - 1));
            for page in Page::range_inclusive(start_page, end_page) {
                let (result, _frame) = mapper.unmap_return(page);
                // This is not the active table, so the flush can be ignored
                unsafe { result.ignore(); }
            }
        });

        self.mapped = false;
    }
}

impl Drop for Grant {
    fn drop(&mut self) {
        assert!(!self.mapped);
    }
}

#[derive(Clone, Debug)]
pub enum SharedMemory {
    Owned(Arc<Mutex<Memory>>),
    Borrowed(Weak<Mutex<Memory>>)
}

impl SharedMemory {
    pub fn with<F, T>(&self, f: F) -> T where F: FnOnce(&mut Memory) -> T {
        match *self {
            SharedMemory::Owned(ref memory_lock) => {
                let mut memory = memory_lock.lock();
                f(&mut *memory)
            },
            SharedMemory::Borrowed(ref memory_weak) => {
                let memory_lock = memory_weak.upgrade().expect("SharedMemory::Borrowed no longer valid");
                let mut memory = memory_lock.lock();
                f(&mut *memory)
            }
        }
    }

    pub fn borrow(&self) -> SharedMemory {
        match *self {
            SharedMemory::Owned(ref memory_lock) => SharedMemory::Borrowed(Arc::downgrade(memory_lock)),
            SharedMemory::Borrowed(ref memory_lock) => SharedMemory::Borrowed(memory_lock.clone())
        }
    }
}

#[derive(Debug)]
pub struct Memory {
    start: VirtualAddress,
    size: usize,
    flags: EntryFlags
}

impl Memory {
    pub fn new(start: VirtualAddress, size: usize, flags: EntryFlags, clear: bool) -> Self {
        let mut memory = Memory {
            start: start,
            size: size,
            flags: flags
        };

        memory.map(clear);

        memory
    }

    pub fn to_shared(self) -> SharedMemory {
        SharedMemory::Owned(Arc::new(Mutex::new(self)))
    }

    pub fn start_address(&self) -> VirtualAddress {
        self.start
    }

    pub fn size(&self) -> usize {
        self.size
    }

    pub fn flags(&self) -> EntryFlags {
        self.flags
    }

    pub fn pages(&self) -> PageIter {
        let start_page = Page::containing_address(self.start);
        let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size - 1));
        Page::range_inclusive(start_page, end_page)
    }

    fn map(&mut self, clear: bool) {
        let mut active_table = unsafe { ActivePageTable::new() };

        let mut flush_all = MapperFlushAll::new();

        for page in self.pages() {
            let result = active_table.map(page, self.flags);
            flush_all.consume(result);
        }

        flush_all.flush(&mut active_table);

        if clear {
            assert!(self.flags.contains(entry::WRITABLE));
            unsafe {
                intrinsics::write_bytes(self.start_address().get() as *mut u8, 0, self.size);
            }
        }
    }

    fn unmap(&mut self) {
        let mut active_table = unsafe { ActivePageTable::new() };

        let mut flush_all = MapperFlushAll::new();

        for page in self.pages() {
            let result = active_table.unmap(page);
            flush_all.consume(result);
        }

        flush_all.flush(&mut active_table);
    }

    /// A complicated operation to move a piece of memory to a new page table
    /// It also allows for changing the address at the same time
    pub fn move_to(&mut self, new_start: VirtualAddress, new_table: &mut InactivePageTable, temporary_page: &mut TemporaryPage) {
        let mut active_table = unsafe { ActivePageTable::new() };

        let mut flush_all = MapperFlushAll::new();

        for page in self.pages() {
            let (result, frame) = active_table.unmap_return(page);
            flush_all.consume(result);

            active_table.with(new_table, temporary_page, |mapper| {
                let new_page = Page::containing_address(VirtualAddress::new(page.start_address().get() - self.start.get() + new_start.get()));
                let result = mapper.map_to(new_page, frame, self.flags);
                // This is not the active table, so the flush can be ignored
                unsafe { result.ignore(); }
            });
        }

        flush_all.flush(&mut active_table);

        self.start = new_start;
    }

    pub fn remap(&mut self, new_flags: EntryFlags) {
        let mut active_table = unsafe { ActivePageTable::new() };

        let mut flush_all = MapperFlushAll::new();

        for page in self.pages() {
            let result = active_table.remap(page, new_flags);
            flush_all.consume(result);
        }

        flush_all.flush(&mut active_table);

        self.flags = new_flags;
    }

    pub fn resize(&mut self, new_size: usize, clear: bool) {
        let mut active_table = unsafe { ActivePageTable::new() };

        //TODO: Calculate page changes to minimize operations
        if new_size > self.size {
            let mut flush_all = MapperFlushAll::new();

            let start_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size));
            let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + new_size - 1));
            for page in Page::range_inclusive(start_page, end_page) {
                if active_table.translate_page(page).is_none() {
                    let result = active_table.map(page, self.flags);
                    flush_all.consume(result);
                }
            }

            flush_all.flush(&mut active_table);

            if clear {
                unsafe {
                    intrinsics::write_bytes((self.start.get() + self.size) as *mut u8, 0, new_size - self.size);
                }
            }
        } else if new_size < self.size {
            let mut flush_all = MapperFlushAll::new();

            let start_page = Page::containing_address(VirtualAddress::new(self.start.get() + new_size));
            let end_page = Page::containing_address(VirtualAddress::new(self.start.get() + self.size - 1));
            for page in Page::range_inclusive(start_page, end_page) {
                if active_table.translate_page(page).is_some() {
                    let result = active_table.unmap(page);
                    flush_all.consume(result);
                }
            }

            flush_all.flush(&mut active_table);
        }

        self.size = new_size;
    }
}

impl Drop for Memory {
    fn drop(&mut self) {
        self.unmap();
    }
}

#[derive(Debug)]
pub struct Tls {
    pub master: VirtualAddress,
    pub file_size: usize,
    pub mem: Memory
}