class User
{
public string Name { get; set; }
public ICollection<Subscription> Subscriptions { get; set; }
}
Eager/Explicit/Lazy Loading
Load()
у DbContext.Select/SelectMany/GroupMany
context.Users.Select(u => new { u.Name });
context.Users.Where(u => someIds.Contains(u.Id)).SelectMany(u => u.Subscriptions); // Не уверен что запрос корректный
char charToEncode = textToEncrypt[charIndex++];
byte[] colorBytes = new byte[] { originalColor.R, originalColor.G, originalColor.B };
for (int i = 0; i < 3; i++)
{
int bitIndex = (bitsPerChannel * i);
if (bitIndex < 8)
{
colorBytes[i] = (byte)((colorBytes[i] & ~1) | ((charToEncode >> bitIndex) & 1));
}
}
for (int i = 0; i < 3; i++)
{
int bitIndex = (bitsPerChannel * i);
if (bitIndex < 8)
{
charCode |= (byte)((encodedColor.ToArgb() >> bitIndex) & 1);
if (bitIndex <= 2)
{
charCode <<= bitsPerChannel;
}
}
}
~/.opera
директория есть? Возможно там в папке cache
.#!/bin/bash
# I found without setting this the script would fail
export PGPASSWORD=xxxx
# Define your query
QUERY="SELECT current_database(),n.nspname ,c.relname, c.relkind from pg_class c, pg_attribute a, pg_namespace n where c.oid = a.attrelid and a.attname = 'oid' AND c.relnamespace = n.oid AND n.nspname NOT IN ('pg_catalog', 'information_schema') and c.relkind = 'r';"
# Get a list of all databases in the RDS cluster
DATABASES=$(psql -h hostname.eu-west-2.rds.amazonaws.com -p 5432 -U postgres -c "SELECT datname FROM pg_database WHERE datname NOT IN ('template0', 'template1');" -t)
# Loop through each database and execute the query
for DB in $DATABASES; do
echo "Running query on database: $DB"
psql -h qa-hostname.eu-west-2.rds.amazonaws.com -t -c "$QUERY" -U postgres -d $DB
done
import os
import signal
import random
def get_versions_with_addresses():
# Надо уметь получать новые версии
return [
('1.0.1', '0.0.0.0:6665'),
('1.1.0', '0.0.0.0:2222')
]
def generate_config():
config = '''
server {
server_name api.domain.com;
listen 80;
'''
for version, address in get_versions_with_addresses():
config += f'''
location /project_name/{version} {{
proxy_pass http://{address}
}}
'''
config += '\n}'
return config
def notify_nginx():
nginx_pid = ... # Находим PID nginx
os.kill(nginx_pid, signal.SIGHUP)
def update_config(config):
with open('/etc/nginx/nginx.conf', 'w') as file:
file.write(config)
def main():
config = generate_config()
update_config(config)
notify_nginx()
pass
if __name__ == '__main__':
main()
Сначала n=2, затем n=0, потом снова n=2
F(n)
) может вызвать максимум 2 подфункции (F(n - 1)
и F(n -2)
).return F(n -1) + F(n - 2)
. Ответ на твой вопрос кроется здесь.int prev = F(n - 1);
int prevPrev = F(n - 2);
return prev + prevPrev;
return F(n - 1) + F(n - 2)
1 + 1
// Initialize ILGPU.
Context context = Context.CreateDefault();
Accelerator accelerator = context.CreateCLAccelerator(1);//context.GetPreferredDevice(preferCPU: false) .CreateAccelerator(context);
// Load the data.
using MemoryBuffer1D<float, Stride1D.Dense> deviceData = accelerator.Allocate1D(input);
using MemoryBuffer1D<float, Stride1D.Dense> deviceOutput = accelerator.Allocate1D<float>(output);
// load / precompile the kernel
Action<Index1D, ArrayView<float>, ArrayView<float>> loadedKernel =
accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<float>, ArrayView<float>>(Kernel);
// finish compiling and tell the accelerator to start computing the kernel
loadedKernel((int)deviceOutput.Length, deviceData.View, deviceOutput.View);
accelerator.Synchronize();
Setup
метод. Раз уж ты пользуешься BenchmarkDotNet, то вот помощь с этимpublic class SampleBenchmark
{
static void Kernel(Index1D i, ArrayView<float> data, ArrayView<float> output)
{
output[i] = data[i % data.Length];
}
public static IEnumerable<object[]> Arguments => new[] {new object[]{new float[1000000], new float[1000000]} };
private float[] _outputBuffer = new float[1000000];
private float[] _inputBuffer = new float[1000000];
private Context? _context;
private Accelerator? _accelerator;
private Action<Index1D, ArrayView<float>, ArrayView<float>>? _loadedKernel;
private MemoryBuffer1D<float, Stride1D.Dense>? _deviceData;
private MemoryBuffer1D<float, Stride1D.Dense>? _deviceOutput;
[GlobalSetup]
public void Setup()
{
var random = new Random();
for (var i = 0; i < _inputBuffer.Length; i++)
{
_inputBuffer[i] = random.NextSingle();
}
_context = Context.CreateDefault();
_accelerator = _context.GetPreferredDevice(preferCPU: false).CreateAccelerator(_context);
_loadedKernel = _accelerator!.LoadAutoGroupedStreamKernel<Index1D, ArrayView<float>, ArrayView<float>>(Kernel);
_deviceData = _accelerator!.Allocate1D(_inputBuffer);
_deviceOutput = _accelerator!.Allocate1D(_outputBuffer);
}
[GlobalCleanup]
public void TearDown()
{
_context?.Dispose();
_accelerator?.Dispose();
_deviceData?.Dispose();
_deviceOutput?.Dispose();
}
[ArgumentsSource(nameof(Arguments))]
[Benchmark]
public void GPUTest(float[] input, float[] output)
{
// finish compiling and tell the accelerator to start computing the kernel
_loadedKernel!((int)_deviceOutput.Length, _deviceData.View, _deviceOutput.View);
_accelerator!.Synchronize();
}
[Benchmark]
[ArgumentsSource(nameof(Arguments))]
public void CpuTest(float[] input, float[] output)
{
for (var i = 0; i < input.Length; i++)
{
output[i] = input[i];
}
}
}
| Method | input | output | Mean | Error | StdDev |
|-------- |---------------- |---------------- |----------:|---------:|---------:|
| GPUTest | Single[1000000] | Single[1000000] | 61.18 us | 0.101 us | 0.095 us |
| CpuTest | Single[1000000] | Single[1000000] | 243.54 us | 3.114 us | 2.600 us |
ip route
использовать. Например, так:/sbin/ip route|awk '/default/ { print $3 }'