Beispiel #1
0
 static v3_t init(num_t x = num_t(0), num_t y = num_t(0), num_t z = num_t(0)) {
   v3_t result;
   result.x = x;
   result.y = y;
   result.z = z;
   return result;
 }
Beispiel #2
0
  void init(const v2_t<num_t>& _p0,
            const v2_t<num_t>& _p1,
            const v2_t<num_t>& _p2) {
    p0 = _p0;
    p1 = _p1 - _p0;
    p2 = _p2 - _p0;

    A = num_t(+4) * v2_t<num_t>::dot(p1, p1) -
        num_t(4) * v2_t<num_t>::dot(p1, p2) + v2_t<num_t>::dot(p2, p2);
    B = num_t(-6) * v2_t<num_t>::dot(p1, p1) +
        num_t(3) * v2_t<num_t>::dot(p1, p2);
    C = num_t(+2) * v2_t<num_t>::dot(p1, p1);
  }
Beispiel #3
0
bool _miller_rabin(num_t n, uint32 s, num_t d, uint32 base_no) {
  // n - 1 = d * 2^s.

  const num_t n_prime = montgomery::calc_n_prime(n);
  const num_t r2 = montgomery::calc_r2(n);
  const num_t one = montgomery::init(num_t(1), r2, n, n_prime);
  const num_t minus_one = n - one;

  for (uint32 bi = 0; bi < limits[base_no][1]; ++bi) {
    const num_t base = montgomery::init(num_t(bases[base_no][bi]), r2, n, n_prime);
    if (witness(base, s, d, n, n_prime, one, minus_one)) {
      return false;
    }
  }
  return true;
}
Beispiel #4
0
  std::pair<v2_t<num_t>, num_t> closest_point(v2_t<num_t> pos) const {
    v2_t<num_t> p = pos - p0;
    num_t p1p = v2_t<num_t>::dot(p1, p);
    num_t p2p = v2_t<num_t>::dot(p2, p);

    std::vector<num_t> sol = solve3(A, B, C - p2p + num_t(2) * p1p, -p1p);
    num_t d;
    num_t min_dist = p.lengthsq();
    v2_t<num_t> min_pos = v2_t<num_t>::zero();
    num_t min_t = num_t(0);

    d = (p - p2).lengthsq();
    if (d < min_dist) {
      min_dist = d;
      min_pos = p2;
      min_t = num_t(1);
    }

    for (size_t i = 0; i < sol.size(); ++i) {
      if (sol[i] > num_t(0) && sol[i] < num_t(1)) {
        v2_t<num_t> q = get_relpos(sol[i]);
        d = (p - q).lengthsq();
        if (d < min_dist) {
          min_dist = d;
          min_pos = q;
          min_t = sol[i];
        }
      }
    }

    min_dist = ::sqrt(min_dist);
    if (v2_t<num_t>::orient(min_pos, min_pos + get_tangent(min_t), p) <
        num_t(0)) {
      min_dist = -min_dist;
    }

    return std::make_pair(min_pos + p0, min_dist);
  }
Image2D TestSetGenerator::MakeTestSet(int number, Mask2D& rfi, unsigned width, unsigned height, int gaussianNoise)
{
	Image2D image;
	switch(number)
	{
		case 0: // Image of all zero's
		return Image2D::MakeZeroImage(width, height);
		case 1: // Image of all ones
		image = Image2D::MakeUnsetImage(width, height);
		image.SetAll(1.0);
		break;
		case 2: // Noise
		return MakeNoise(width, height, gaussianNoise);
		case 3: { // Several broadband lines
		image = MakeNoise(width, height, gaussianNoise);
		AddBroadbandToTestSet(image, rfi, 1.0);
		} break;
		case 4: { // Several broadband lines
		image = MakeNoise(width, height, gaussianNoise);
		AddBroadbandToTestSet(image, rfi, 0.5);
		} break;
		case 5: { // Several broadband lines of random length
		image = MakeNoise(width, height, gaussianNoise);
		AddVarBroadbandToTestSet(image, rfi);
		} break;
		case 6: { // Different broadband lines + low freq background
		image = MakeNoise(width, height, gaussianNoise);
		AddVarBroadbandToTestSet(image, rfi);
		for(unsigned y=0;y<image.Height();++y) {
			for(unsigned x=0;x<image.Width();++x) {
				image.AddValue(x, y, sinn(num_t(x)*M_PIn*5.0 / image.Width()) + 0.1);
			}
		}
		} break;
		case 7: { // Different broadband lines + high freq background 
		image = MakeNoise(width, height, gaussianNoise);
		for(unsigned y=0;y<image.Height();++y) {
			for(unsigned x=0;x<image.Width();++x) {
				image.AddValue(x, y, sinn((long double) (x+y*0.1)*M_PIn*5.0L / image.Width() + 0.1));
				image.AddValue(x, y, sinn((long double) (x+pown(y, 1.1))*M_PIn*50.0L / image.Width() + 0.1));
			}
		}
		AddVarBroadbandToTestSet(image, rfi);
		for(unsigned y=0;y<image.Height();++y) {
			for(unsigned x=0;x<image.Width();++x) {
				image.AddValue(x, y, 1.0); 
			}
		}
		} break;
		case 8: {  // Different droadband lines + smoothed&subtracted high freq background
		image = MakeNoise(width, height, gaussianNoise);
		for(unsigned y=0;y<image.Height();++y) {
			for(unsigned x=0;x<image.Width();++x) {
				image.AddValue(x, y, sinn((num_t) (x+y*0.1)*M_PIn*5.0 / image.Width() + 0.1));
				image.AddValue(x, y, sinn((num_t) (x+pown(y, 1.1))*M_PIn*50.0 / image.Width() + 0.1));
			}
		}
		SubtractBackground(image);
		AddVarBroadbandToTestSet(image, rfi);
		} break;
		case 9: { //FFT of 7
		image = MakeTestSet(7, rfi, width, height);
		Image2D copy(image);
		FFTTools::CreateHorizontalFFTImage(image, copy, false);
		for(unsigned y=0;y<rfi.Height();++y) {
			for(unsigned x=0;x<rfi.Width();++x) {
				image.SetValue(x, y, image.Value(x, y) / sqrtn(image.Width()));
			}
		}
		} break;
		case 10: { // Identity matrix
		image = Image2D::MakeZeroImage(width, height);
		unsigned min = width < height ? width : height;
		for(unsigned i=0;i<min;++i) {
			image.SetValue(i, i, 1.0);
			rfi.SetValue(i, i, true);
		}
		} break;
		case 11: { // FFT of identity matrix
		image = MakeTestSet(10, rfi, width, height);
		Image2D copy(image);
		FFTTools::CreateHorizontalFFTImage(image, copy, false);
		for(unsigned y=0;y<rfi.Height();++y) {
			for(unsigned x=0;x<rfi.Width();++x) {
				image.SetValue(x, y, image.Value(x, y) / sqrtn(width)); 
			}
		}
		} break;
		case 12: { // Broadband contaminating all channels
		image = MakeNoise(width, height, gaussianNoise);
		for(unsigned y=0;y<image.Height();++y) {
			for(unsigned x=0;x<image.Width();++x) {
				image.AddValue(x, y, sinn((num_t) (x+y*0.1)*M_PIn*5.0 / image.Width() + 0.1));
				image.AddValue(x, y, sinn((num_t) (x+powl(y, 1.1))*M_PIn*50.0 / image.Width() + 0.1));
			}
		}
		AddBroadbandToTestSet(image, rfi, 1.0);
		} break;
		case 13: { // Model of three point sources with broadband RFI
		SetModelData(image, rfi, 3);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		AddBroadbandToTestSet(image, rfi, 1.0);
		} break;
		case 14: { // Model of five point sources with broadband RFI
		SetModelData(image, rfi, 5);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		AddBroadbandToTestSet(image, rfi, 1.0);
		} break;
		case 15: { // Model of five point sources with partial broadband RFI
		SetModelData(image, rfi, 5);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		AddBroadbandToTestSet(image, rfi, 0.5);
		} break;
		case 16: { // Model of five point sources with random broadband RFI
		SetModelData(image, rfi, 5);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		AddVarBroadbandToTestSet(image, rfi);
		} break;
		case 17: { // Background-fitted model of five point sources with random broadband RFI
		SetModelData(image, rfi, 5);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		SubtractBackground(image);
		AddVarBroadbandToTestSet(image, rfi);
		} break;
		case 18: { // Model of three point sources with random RFI
		SetModelData(image, rfi, 3);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		AddVarBroadbandToTestSet(image, rfi);
		} break;
		case 19: { // Model of three point sources with noise
		SetModelData(image, rfi, 3);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		} break;
		case 20: { // Model of five point sources with noise
		SetModelData(image, rfi, 5);
		Image2D noise = MakeNoise(image.Width(), image.Height(), gaussianNoise);
		image += noise;
		} break;
		case 21: { // Model of three point sources
		SetModelData(image, rfi, 3);
		} break;
		case 22: { // Model of five point sources
		image = Image2D::MakeZeroImage(width, height);
		SetModelData(image, rfi, 5);
		} break;
		case 23:
			image = MakeNoise(width, height, gaussianNoise);
			AddBroadbandToTestSet(image, rfi, 0.5, 0.1, true);
		break;
		case 24:
			image = MakeNoise(width, height, gaussianNoise);
			AddBroadbandToTestSet(image, rfi, 0.5, 10.0, true);
		break;
		case 25:
			image = MakeNoise(width, height, gaussianNoise);
			AddBroadbandToTestSet(image, rfi, 0.5, 1.0, true);
		break;
		case 26: { // Several Gaussian broadband lines
			image = MakeNoise(width, height, gaussianNoise);
			AddBroadbandToTestSet(image, rfi, 1.0, 1.0, false, GaussianShape);
		} break;
		case 27: { // Several Sinusoidal broadband lines
			image = MakeNoise(width, height, gaussianNoise);
			AddBroadbandToTestSet(image, rfi, 1.0, 1.0, false, SinusoidalShape);
		} break;
		case 28: { // Several slewed Gaussian broadband lines
			image = MakeNoise(width, height, gaussianNoise);
			AddSlewedBroadbandToTestSet(image, rfi, 1.0);
		} break;
		case 29: { // Several bursty broadband lines
			image = MakeNoise(width, height, gaussianNoise);
			AddBurstBroadbandToTestSet(image, rfi);
		} break;
		case 30: { // noise + RFI ^-2 distribution
			image = sampleRFIDistribution(width, height, 1.0);
			rfi.SetAll<true>();
		} break;
		case 31: { // noise + RFI ^-2 distribution
			image = sampleRFIDistribution(width, height, 0.1);
			rfi.SetAll<true>();
		} break;
		case 32: { // noise + RFI ^-2 distribution
			image = sampleRFIDistribution(width, height, 0.01);
			rfi.SetAll<true>();
		} break;
	}
	return image;
}
Beispiel #6
0
 v3_t normalize() const {
   num_t rl = num_t(1) / length();
   return init(x * rl, y * rl, z * rl);
 }
Beispiel #7
0
 static v3_t zero() { return v3_t::init(num_t(0), num_t(0), num_t(0)); }
Beispiel #8
0
num_t v3_t<num_t>::tetrahedron_volume(const v3_t<num_t>& a,
                                      const v3_t<num_t>& b,
                                      const v3_t<num_t>& c,
                                      const v3_t<num_t>& d) {
  return dotcross((a - d), (b - d), (c - d)) / num_t(6);
}
Beispiel #9
0
static inline v3_t<num_t> operator/(const v3_t<num_t>& a, num_t b) {
  return a.scale(num_t(1) / b);
}
Beispiel #10
0
 v2_t<num_t> get_tangent(num_t t) const {
   return num_t(2) * (num_t(1) - t) * p1 + num_t(2) * t * (p2 - p1);
 }
Beispiel #11
0
 v2_t<num_t> get_relpos(num_t t) const {
   return num_t(2) * t * (num_t(1) - t) * p1 + t * t * p2;
 }
Beispiel #12
0
 static const num_t limit() {
   return num_t(1) << (8 * sizeof(num_t) - 1);
 }