Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
27
Task/Deconvolution-1D/JavaScript/deconvolution-1d.js
Normal file
27
Task/Deconvolution-1D/JavaScript/deconvolution-1d.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
function deconv(g, f) {
|
||||
const h = new Array(g.length - f.length + 1);
|
||||
for (let n = 0; n < h.length; n++) {
|
||||
h[n] = g[n];
|
||||
const lower = Math.max(n - f.length + 1, 0);
|
||||
for (let i = lower; i < n; i++)
|
||||
h[n] -= h[i] * f[n - i];
|
||||
h[n] /= f[0];
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const h = [-8, -9, -3, -1, -6, 7];
|
||||
const f = [-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1];
|
||||
const g = [24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96,
|
||||
96, 31, 55, 36, 29, -43, -7];
|
||||
|
||||
let output = '';
|
||||
output += `h = ${JSON.stringify(h)}\n`;
|
||||
output += `deconv(g, f) = ${JSON.stringify(deconv(g, f))}\n`;
|
||||
output += `f = ${JSON.stringify(f)}\n`;
|
||||
output += `deconv(g, h) = ${JSON.stringify(deconv(g, h))}\n`;
|
||||
console.log(output);
|
||||
}
|
||||
|
||||
main();
|
||||
39
Task/Deconvolution-1D/Rust/deconvolution-1d.rs
Normal file
39
Task/Deconvolution-1D/Rust/deconvolution-1d.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
fn print_vector(list: &Vec<i32>) {
|
||||
print!("[");
|
||||
for i in 0..list.len() - 1 {
|
||||
print!("{}, ", list[i]);
|
||||
}
|
||||
println!("{}]", list.last().unwrap());
|
||||
}
|
||||
|
||||
fn deconvolution(a: &Vec<i32>, b: &Vec<i32>) -> Vec<i32> {
|
||||
let mut result = vec![0; a.len() - b.len() + 1];
|
||||
for n in 0..result.len() {
|
||||
result[n] = a[n];
|
||||
let start = std::cmp::max(n as i64 - b.len() as i64 + 1, 0) as usize;
|
||||
for i in start..n {
|
||||
result[n] -= result[i] * b[n - i];
|
||||
}
|
||||
result[n] /= b[0];
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let h: Vec<i32> = vec![-8, -9, -3, -1, -6, 7];
|
||||
let f: Vec<i32> = vec![-3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1];
|
||||
let g: Vec<i32> = vec![24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52,
|
||||
25, -67, -96, 96, 31, 55, 36, 29, -43, -7];
|
||||
|
||||
print!("h = ");
|
||||
print_vector(&h);
|
||||
|
||||
print!("deconvolution(g, f) = ");
|
||||
print_vector(&deconvolution(&g, &f));
|
||||
|
||||
print!("f = ");
|
||||
print_vector(&f);
|
||||
|
||||
print!("deconvolution(g, h) = ");
|
||||
print_vector(&deconvolution(&g, &h));
|
||||
}
|
||||
54
Task/Deconvolution-1D/Zig/deconvolution-1d.zig
Normal file
54
Task/Deconvolution-1D/Zig/deconvolution-1d.zig
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
const std = @import("std");
|
||||
|
||||
fn printVector(list: []const i32) void {
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
stdout.print("[", .{}) catch unreachable;
|
||||
for (0..list.len - 1) |i| {
|
||||
stdout.print("{}, ", .{list[i]}) catch unreachable;
|
||||
}
|
||||
stdout.print("{}]\n", .{list[list.len - 1]}) catch unreachable;
|
||||
}
|
||||
|
||||
fn deconvolution(allocator: std.mem.Allocator, a: []const i32, b: []const i32) ![]i32 {
|
||||
const result_len = a.len - b.len + 1;
|
||||
var result = try allocator.alloc(i32, result_len);
|
||||
@memset(result, 0);
|
||||
|
||||
for (0..result_len) |n| {
|
||||
result[n] = a[n];
|
||||
const start = @max(@as(i64, @intCast(n)) - @as(i64, @intCast(b.len)) + 1, 0);
|
||||
var i: usize = @intCast(start);
|
||||
while (i < n) : (i += 1) {
|
||||
result[n] -= result[i] * b[n - i];
|
||||
}
|
||||
result[n] = @divTrunc(result[n], b[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
defer _ = gpa.deinit();
|
||||
|
||||
const h = [_]i32{ -8, -9, -3, -1, -6, 7 };
|
||||
const f = [_]i32{ -3, -6, -1, 8, -6, 3, -1, -9, -9, 3, -2, 5, 2, -2, -7, -1 };
|
||||
const g = [_]i32{ 24, 75, 71, -34, 3, 22, -45, 23, 245, 25, 52, 25, -67, -96, 96, 31, 55, 36, 29, -43, -7 };
|
||||
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
try stdout.print("h = ", .{});
|
||||
printVector(&h);
|
||||
|
||||
const deconv_gf = try deconvolution(allocator, &g, &f);
|
||||
defer allocator.free(deconv_gf);
|
||||
try stdout.print("deconvolution(g, f) = ", .{});
|
||||
printVector(deconv_gf);
|
||||
|
||||
try stdout.print("f = ", .{});
|
||||
printVector(&f);
|
||||
|
||||
const deconv_gh = try deconvolution(allocator, &g, &h);
|
||||
defer allocator.free(deconv_gh);
|
||||
try stdout.print("deconvolution(g, h) = ", .{});
|
||||
printVector(deconv_gh);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue