blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 3 264 | content_id stringlengths 40 40 | detected_licenses listlengths 0 85 | license_type stringclasses 2
values | repo_name stringlengths 5 140 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 905
values | visit_date timestamp[us]date 2015-08-09 11:21:18 2023-09-06 10:45:07 | revision_date timestamp[us]date 1997-09-14 05:04:47 2023-09-17 19:19:19 | committer_date timestamp[us]date 1997-09-14 05:04:47 2023-09-06 06:22:19 | github_id int64 3.89k 681M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 22
values | gha_event_created_at timestamp[us]date 2012-06-07 00:51:45 2023-09-14 21:58:39 ⌀ | gha_created_at timestamp[us]date 2008-03-27 23:40:48 2023-08-21 23:17:38 ⌀ | gha_language stringclasses 141
values | src_encoding stringclasses 34
values | language stringclasses 1
value | is_vendor bool 1
class | is_generated bool 2
classes | length_bytes int64 3 10.4M | extension stringclasses 115
values | content stringlengths 3 10.4M | authors listlengths 1 1 | author_id stringlengths 0 158 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
954ac03d773f8ebc6022792c98179222d7e1bba5 | b8080b01c7805e6088cee53ee07d551bdf88bde8 | /openglwidget.h | 5bf5114bfe7e220796decbc9f8bc8a3d639512a4 | [] | no_license | AminoACID123/CG-Project | 1b319b795e422424e031041a1b7345d58cb5eeb2 | 06931ead0b19d203749001c2d1de63898531ac92 | refs/heads/master | 2020-04-14T05:14:23.774112 | 2018-12-31T09:10:47 | 2018-12-31T09:10:47 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,027 | h | #ifndef OPENGLWIDGET_H
#define OPENGLWIDGET_H
#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QVector>
#include <QDebug>
#include <QFile>
#include <QString>
#include <QtGui>
#include <QSlider>
#include <QWheelEvent>
struct vertice{
double x;
double y;
double z;
};
class OpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
QString filename;
OpenGLWidget(QWidget *parent = 0);
private slots:
void setXRotate(){
xRotate=xSlider->value();
update();
}
protected:
void initializeGL();
void paintGL();
void resizeGL(int w, int h);
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent*event);
private:
double xRotate=0;
double yRotate=0;
double zRotate=0;
double ratio=1;
QSlider *xSlider;
QSlider *ySlider;
QSlider *zSlider;
int nVertices;
int nFaces;
QVector<QVector<int>> Faces;
QVector<vertice> Vertices;
};
#endif // OPENGLWIDGET_H
| [
"1300019770@qq.com"
] | 1300019770@qq.com |
11e35f5145911be006a3453ab4f968f044db556e | c3fc8f5f930fec33c8d02d7c392a97ff48966dda | /src/YOLO_PPF_ros.cpp | 980d0a35446767619f02c8fa732bfd9938faf6fc | [] | no_license | EmilyJrxx/YOLO_azure_pose_estimation_ros | 5f54c8b5c0ea51eaad174d0d27847c3bac40e8ef | fe4605fad9382acb5d70129a57bb0660c304438f | refs/heads/master | 2023-01-09T18:50:41.664850 | 2020-11-12T06:24:52 | 2020-11-12T06:24:52 | 304,258,034 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 6,030 | cpp | # include <ros/ros.h>
# include <message_filters/macros.h>
# include <message_filters/subscriber.h>
# include <message_filters/time_synchronizer.h>
# include <message_filters/sync_policies/approximate_time.h>
# include <sensor_msgs/image_encodings.h>
# include <sensor_msgs/Image.h>
# include <sensor_msgs/CameraInfo.h>
# include <sensor_msgs/PointCloud2.h>
# include <std_msgs/Header.h>
# include <opencv4/opencv2/core/eigen.hpp>
# include <opencv4/opencv2/core.hpp>
# include <opencv4/opencv2/highgui/highgui.hpp>
# include <cv_bridge/cv_bridge.h>
# include <pcl/point_types.h>
# include <pcl/io/ply_io.h>
# include <pcl_conversions/pcl_conversions.h>
# include <pcl/filters/filter.h>
# include <iostream>
# include <fstream>
# include "../include/YOLO_Detection_class.h"
# include "../include/CloudProcessing.h"
using namespace std;
using namespace cv;
using namespace sensor_msgs;
using namespace message_filters;
using namespace pcl;
// ROS configuration
const string rgb_topic = "/rgb/image_raw";
const string depth_topic = "/depth_to_rgb/image_raw";
const string cloud_topic = "/points2";
const string info_topic = "/rgb/camera_info";
const string output_dir = "/home/emilyjr/Desktop/Azure_ROS_Recorded/";
// YOLO parameters
const int inpHeight = 416;
const int inpWidth = 416;
const double confThreshold = 0.5;
const double nmsThreshold = 0.4;
const string modelConfiguration = "/home/emilyjr/Packages/darknet/cfg/yolov3.cfg";
const string modelWeights = "/home/emilyjr/Packages/darknet/yolov3.weights";
const string classesFile = "/home/emilyjr/Packages/darknet/data/coco.names";
const string modelFile = "/home/emilyjr/ppf_matching/src/Camera/clouds/";
const string PPFDetectorFile = "/home/emilyjr/ppf_matching/src/Camera/clouds/";
// PPF parameters
double relativeSamplingStep = 0.025;
double relativeDistanceStep = 0.05;
// Camera Parameters
// Detectors Announcement
yolo::YOLODetector yolo_detector (modelConfiguration, modelWeights);
ppf::CloudProcessor ppf_processor (relativeSamplingStep, relativeDistanceStep);
void Callback(const sensor_msgs::Image::ConstPtr & rgb,
const sensor_msgs::Image::ConstPtr & depth,
const sensor_msgs::PointCloud2::ConstPtr & cloud,
const sensor_msgs::CameraInfo::ConstPtr & info
)
{
int tick1 = getTickCount();
cv_bridge::CvImagePtr rgb_ptr;
cv_bridge::CvImagePtr depth_ptr;
try{
rgb_ptr = cv_bridge::toCvCopy(rgb, image_encodings::BGR8);
}
catch (cv_bridge::Exception& e){
ROS_ERROR("cv_bridge exception: %s", e.what());
return ;
}
try{
depth_ptr = cv_bridge::toCvCopy(depth, image_encodings::TYPE_32FC1);
}
catch (cv_bridge::Exception& e){
ROS_ERROR("cv_bridge exception: %s", e.what());
return ;
}
Mat rgb_frame = rgb_ptr->image;
Mat depth_frame = depth_ptr->image;
int tick2 = getTickCount();
tick1 = getTickCount();
PointCloud<PointXYZRGB>::Ptr pcl_cloud (new PointCloud<PointXYZRGB>);
PCLPointCloud2 pcl_pc2;
pcl_conversions::toPCL(*cloud, pcl_pc2);
pcl::fromPCLPointCloud2(pcl_pc2, *pcl_cloud);
PointCloud<PointXYZRGB>::Ptr cloud_filtered (new PointCloud<PointXYZRGB>);
vector<int> indices;
pcl::removeNaNFromPointCloud(*pcl_cloud, *cloud_filtered, indices);
Mat CameraInfo(3, 3, CV_32F, (void*)info->K.data());
tick2 = getTickCount();
cout << "Message Receiving: "
<< (tick2 - tick1)/getTickFrequency() << "sec.\n";
// YOLO Detection
tick1 = getTickCount();
yolo_detector.reloadImages(rgb_frame, depth_frame);
vector<Mat> outs[1];
yolo_detector.detect(outs, inpWidth, inpHeight);
yolo_detector.postprocess(outs, confThreshold, nmsThreshold);
tick2 = getTickCount();
cout << "YOLO Detection: "
<< (tick2 - tick1)/getTickFrequency() << "sec.\n";
// PPF Recognition
tick1 = getTickCount();
vector<Rect> bboxes_2d_ppf; vector<int> classIds_ppf; vector<int> indices_ppf;
yolo_detector.TransferResults(bboxes_2d_ppf, classIds_ppf, indices_ppf);
PointCloud<PointXYZ>::Ptr scene (new PointCloud<PointXYZ>);
copyPointCloud(*cloud_filtered, *scene);
ppf_processor.ReloadScenes(scene, depth_frame, bboxes_2d_ppf, classIds_ppf, indices_ppf);
ppf_processor.SceneCropping(CameraInfo);
ppf_processor.Subsampling(0.005f);
ppf_processor.OutlierProcessing(50, 1.2);
vector<PointCloud<PointNormal>> objects_with_normals;
objects_with_normals = ppf_processor.NormalEstimation(30);
tick2 = getTickCount();
cout << "Cloud Preprocessing "
<< (tick2 - tick1)/getTickFrequency() << "sec.\n";
Mat object_wn_mat;
ppf_processor.PointCloudXYZNormalToMat(object_wn_mat, objects_with_normals[0].makeShared());
Pose3D result_pose = ppf_processor.Matching("bottle", object_wn_mat);
cout << "Result_pose (model -> scene): " << endl;
result_pose.printPose();
}
int main(int argc, char** argv)
{
// YOLO global configuration
yolo_detector.LoadClassNames(classesFile);
// PPF global configuration
Mat bottle = ppf_match_3d::loadPLYSimple(modelFile.c_str(), 1);
ppf_processor.LoadSingleModel(bottle, "bottle");
ppf_processor.LoadTrainedDetector("bottle", PPFDetectorFile);
// ROS init and configuartion
ros::init(argc, argv, "Azure_YOLO_PPF");
ros::NodeHandle nh;
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, rgb_topic, 3);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, depth_topic, 3);
message_filters::Subscriber<sensor_msgs::PointCloud2> cloud_sub(nh, cloud_topic, 5);
message_filters::Subscriber<sensor_msgs::CameraInfo> info_sub (nh, info_topic, 3);
typedef sync_policies::ApproximateTime<Image, Image> MySyncPolicy;
Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), rgb_sub, depth_sub, cloud_sub, info_sub);
cout << "Subscriber Configured" << endl;
sync.registerCallback(boost::bind(&Callback, _1, _2, _3, _4));
ros::spin();
return 0;
}
| [
"metalgearMGS@163.com"
] | metalgearMGS@163.com |
ed8c4a3ea7915af83e4855476a1108978147bc06 | 1919a541061659bece049bd22058e7e6ea91d97e | /2020/14500.cpp | 8a04e5f72e6ba915e2a63aeba5bb146cc8e993c4 | [] | no_license | sjyn01/Baekjoon | 97d767e37d916a0ab43f246a033815ba83a297ae | 507416b93aa20675f090540cdf1a8ce2951c2926 | refs/heads/master | 2022-03-13T22:21:23.176699 | 2022-02-04T02:53:04 | 2022-02-04T02:53:04 | 204,905,483 | 0 | 0 | null | null | null | null | WINDOWS-1252 | C++ | false | false | 420 | cpp | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int row, col;
int rtotal = 0;
int ctotal = 0;
scanf("%d %d",&row, &col);
int arr[500][500];//¸Þ¸ð¸®³¶ºñ?
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
scanf("%d", &arr[i][j]);
}
}
for (int i = 0; i < row; i++) {
for (int j = 0; j < col-4; j++) {
}
}
return 0;
} | [
"sjyn0@ajou.ac.kr"
] | sjyn0@ajou.ac.kr |
033564efce78d6a064c16410a463e8120c1c31d8 | 57101246803ba9cae8a21fdccc4f7a18f8e26674 | /qt_sample/image-filter/filter-plugin-designer/filterwidget.h | 23d8d61e0489dffeb1dde89cb377f348377af1b5 | [] | no_license | hieuletrung/personal | 024272c46c862ff8602fd93957e0f5eb35e4151d | 86eedc8d2ccfc2ba7e046a2677cee9121fee433a | refs/heads/master | 2022-07-13T12:39:45.017296 | 2020-04-02T14:33:32 | 2020-04-02T14:33:32 | 160,024,587 | 0 | 0 | null | 2022-07-06T20:09:42 | 2018-12-02T07:39:11 | C++ | UTF-8 | C++ | false | false | 1,251 | h | #ifndef FILTERWIDGET_H
#define FILTERWIDGET_H
#include <QWidget>
#include <memory>
#include "filter-plugin-global.h"
#include "filter.h"
namespace Ui {
class FilterWidget;
}
class FILTERPLUGINDESIGNERSHARED_EXPORT FilterWidget : public QWidget
{
Q_OBJECT
Q_ENUMS(FilterType)
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(FilterType filterType READ filterType WRITE setFilterType)
public:
enum FilterType { Original, Blur, Grayscale };
explicit FilterWidget(QWidget *parent = nullptr);
~FilterWidget();
void process();
void setSourcePicture(const QImage&sourcePicture);
void updateThumbnail(const QImage&sourceThumbnail);
QString title() const;
FilterType filterType() const;
public slots:
void setTitle(const QString& tile);
void setFilterType(FilterType filterType);
signals:
void pictureProcessed(const QImage& picture);
protected:
void mousePressEvent(QMouseEvent*) override;
private:
Ui::FilterWidget *ui;
std::unique_ptr<Filter> mFilter;
FilterType mFilterType;
QImage mDefaultSourcePicture;
QImage mSourcePicture;
QImage mSourceThumbnail;
QImage mFilteredPicture;
QImage mFilteredThumbnail;
};
#endif // FILTERWIDGET_H
| [
"hieuletrung@gmail.com"
] | hieuletrung@gmail.com |
e56b652326e224575b60243732101d3c3e8d263d | 560090526e32e009e2e9331e8a2b4f1e7861a5e8 | /Compiled/blaze-3.2/blazemark/blazemark/blitz/Mat3Mat3Mult.h | 107e6eb53aa49aba2392ac48dcbac5a74136b7a0 | [
"BSD-3-Clause"
] | permissive | jcd1994/MatlabTools | 9a4c1f8190b5ceda102201799cc6c483c0a7b6f7 | 2cc7eac920b8c066338b1a0ac495f0dbdb4c75c1 | refs/heads/master | 2021-01-18T03:05:19.351404 | 2018-02-14T02:17:07 | 2018-02-14T02:17:07 | 84,264,330 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,026 | h | //=================================================================================================
/*!
// \file blazemark/blitz/Mat3Mat3Mult.h
// \brief Header file for the Blitz++ 3D matrix/matrix multiplication kernel
//
// Copyright (C) 2012-2017 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZEMARK_BLITZ_MAT3MAT3MULT_H_
#define _BLAZEMARK_BLITZ_MAT3MAT3MULT_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blazemark/system/Types.h>
namespace blazemark {
namespace blitz {
//=================================================================================================
//
// KERNEL FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Blitz++ kernel functions */
//@{
double mat3mat3mult( size_t N, size_t steps );
//@}
//*************************************************************************************************
} // namespace blitz
} // namespace blazemark
#endif
| [
"jonathan.doucette@alumni.ubc.ca"
] | jonathan.doucette@alumni.ubc.ca |
4998f1928cddd77665ca02d4253036690d1aceb7 | 0509e367ee369133f0c57f2cbd6cb6fd959da1d5 | /chapter12/rei12.1_4.cpp | 511746d40fd076f9e5cd41a943dc98d2ff90c2e3 | [] | no_license | Hiroaki-K4/cpp_learn | 5a1e6916d504027c18c64a16c353ee72429ed383 | 69d38f317f9c144b4e092361936d61b62d3bed3b | refs/heads/main | 2023-02-25T12:40:56.497944 | 2021-01-30T13:27:00 | 2021-01-30T13:27:00 | 317,693,373 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,095 | cpp | #include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
class Shape {
public:
virtual void example() = 0;
};
class Rectangle: public Shape {
public:
void example() {
cout << "*****\n* *\n*****\n";
}
};
class Triangle: public Shape {
public:
void example() {
cout << "*\n* *\n* *\n*****\n";
}
};
class Line: public Shape {
public:
void example() {
cout << "******\n";
}
};
class NullShape: public Shape {
public:
void example() {
}
};
Shape *generator()
{
switch(rand() % 4) {
case 0:
return new Line;
case 1:
return new Rectangle;
case 2:
return new Triangle;
case 3:
return new NullShape;
}
return NULL;
}
int main()
{
int i;
Shape *p;
for (i = 0; i < 10; i++) {
p = generator();
cout << typeid(*p).name() << endl;
if (typeid(*p) != typeid(NullShape))
p->example();
}
return 0;
} | [
"49no19@gmail.com"
] | 49no19@gmail.com |
d5dcba228e1da866ee4585cc2eead8bf6dd46e91 | 357fe03065b6cb5e15272f0f426e2bfaec39b004 | /2019-20-2/objektumelv/hf3/vector2d.h | 074654198d67daa4899aa25da05e89efd2781eda | [] | no_license | imdonix/elte-ik-bsc | f2101456dac556264ee5bed0650829bf9522fbaa | 126181bebcf9af323b54222a2177eb8dbb797144 | refs/heads/master | 2023-07-30T23:36:03.440246 | 2022-05-17T21:25:57 | 2022-05-17T21:25:57 | 219,555,437 | 6 | 4 | null | 2021-11-17T22:07:07 | 2019-11-04T17:15:05 | C++ | UTF-8 | C++ | false | false | 515 | h | #ifndef V2D_INCLUDED
#define V2D_INCLUDED
#include <iostream>
class Vector2D
{
private:
int x;
int y;
public:
Vector2D(int _x, int _y){ x = _x; y = _y;}
friend std::ostream& operator<< (std::ostream &s, const Vector2D &v)
{
s << "(" << v.x << " , " << v.y << ")";
return s;
}
int skalar(const Vector2D& a);
void multiple(int s);
void add(const Vector2D& right);
bool isMeroleges(const Vector2D& a);
};
#endif | [
"tamas.donix@gmail.com"
] | tamas.donix@gmail.com |
25ad2829f41f6a09eb334ca11e4e780869f45d8e | 95613a70265e6871c25a4be18075c180427d0980 | /src/qt/guiutil.h | d814172fcf6aa7e17991047d96f2c3fcd6fa4701 | [
"MIT"
] | permissive | CryptoLover705/NocNoc | 394b7426a25a0b048fb5e2ae6c02b5f75099189e | fafa860f29c63d7357721a231fef7ad314355263 | refs/heads/master | 2023-02-11T04:11:49.555586 | 2021-01-01T00:21:57 | 2021-01-01T00:21:57 | 318,871,415 | 1 | 0 | MIT | 2020-12-05T19:25:13 | 2020-12-05T19:25:12 | null | UTF-8 | C++ | false | false | 8,770 | h | // Copyright (c) 2011-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_GUIUTIL_H
#define BITCOIN_QT_GUIUTIL_H
#include "amount.h"
#include <QEvent>
#include <QHeaderView>
#include <QMessageBox>
#include <QObject>
#include <QProgressBar>
#include <QString>
#include <QTableView>
#include <QTableWidget>
#include <boost/filesystem.hpp>
class QValidatedLineEdit;
class SendCoinsRecipient;
QT_BEGIN_NAMESPACE
class QAbstractItemView;
class QDateTime;
class QFont;
class QLineEdit;
class QUrl;
class QWidget;
QT_END_NAMESPACE
/** Utility functions used by the NocNoc Qt UI.
*/
namespace GUIUtil
{
// Create human-readable string from date
QString dateTimeStr(const QDateTime& datetime);
QString dateTimeStr(qint64 nTime);
// Render NocNoc addresses in monospace font
QFont bitcoinAddressFont();
// Set up widgets for address and amounts
void setupAddressWidget(QValidatedLineEdit* widget, QWidget* parent);
void setupAmountWidget(QLineEdit* widget, QWidget* parent);
// Parse "NocNoc:" URI into recipient object, return true on successful parsing
bool parseBitcoinURI(const QUrl& uri, SendCoinsRecipient* out);
bool parseBitcoinURI(QString uri, SendCoinsRecipient* out);
QString formatBitcoinURI(const SendCoinsRecipient& info);
// Returns true if given address+amount meets "dust" definition
bool isDust(const QString& address, const CAmount& amount);
// HTML escaping for rich text controls
QString HtmlEscape(const QString& str, bool fMultiLine = false);
QString HtmlEscape(const std::string& str, bool fMultiLine = false);
/** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing
is selected.
@param[in] column Data column to extract from the model
@param[in] role Data role to extract from the model
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
*/
void copyEntryData(QAbstractItemView* view, int column, int role = Qt::EditRole);
/** Return a field of the currently selected entry as a QString. Does nothing if nothing
is selected.
@param[in] column Data column to extract from the model
@param[in] role Data role to extract from the model
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
*/
QString getEntryData(QAbstractItemView *view, int column, int role);
void setClipboard(const QString& str);
/** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
when no suffix is provided by the user.
@param[in] parent Parent window (or 0)
@param[in] caption Window caption (or empty, for default)
@param[in] dir Starting directory (or empty, to default to documents directory)
@param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
@param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
Can be useful when choosing the save file format based on suffix.
*/
QString getSaveFileName(QWidget* parent, const QString& caption, const QString& dir, const QString& filter, QString* selectedSuffixOut);
/** Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
@param[in] parent Parent window (or 0)
@param[in] caption Window caption (or empty, for default)
@param[in] dir Starting directory (or empty, to default to documents directory)
@param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
@param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
Can be useful when choosing the save file format based on suffix.
*/
QString getOpenFileName(QWidget* parent, const QString& caption, const QString& dir, const QString& filter, QString* selectedSuffixOut);
/** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.
@returns If called from the GUI thread, return a Qt::DirectConnection.
If called from another thread, return a Qt::BlockingQueuedConnection.
*/
Qt::ConnectionType blockingGUIThreadConnection();
// Determine whether a widget is hidden behind other windows
bool isObscured(QWidget* w);
// Open debug.log
void openDebugLogfile();
// Open NocNoc.conf
void openConfigfile();
// Open masternode.conf
void openMNConfigfile();
// Browse backup folder
void showBackups();
// Replace invalid default fonts with known good ones
void SubstituteFonts(const QString& language);
/** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
representation if needed. This assures that Qt can word-wrap long tooltip messages.
Tooltips longer than the provided size threshold (in characters) are wrapped.
*/
class ToolTipToRichTextFilter : public QObject
{
Q_OBJECT
public:
explicit ToolTipToRichTextFilter(int size_threshold, QObject* parent = 0);
protected:
bool eventFilter(QObject* obj, QEvent* evt);
private:
int size_threshold;
};
/**
* Makes a QTableView last column feel as if it was being resized from its left border.
* Also makes sure the column widths are never larger than the table's viewport.
* In Qt, all columns are resizable from the right, but it's not intuitive resizing the last column from the right.
* Usually our second to last columns behave as if stretched, and when on strech mode, columns aren't resizable
* interactively or programatically.
*
* This helper object takes care of this issue.
*
*/
class TableViewLastColumnResizingFixer : public QObject
{
Q_OBJECT
public:
TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth);
void stretchColumnWidth(int column);
private:
QTableView* tableView;
int lastColumnMinimumWidth;
int allColumnsMinimumWidth;
int lastColumnIndex;
int columnCount;
int secondToLastColumnIndex;
void adjustTableColumnsWidth();
int getAvailableWidthForColumn(int column);
int getColumnsWidth();
void connectViewHeadersSignals();
void disconnectViewHeadersSignals();
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
void resizeColumn(int nColumnIndex, int width);
private slots:
void on_sectionResized(int logicalIndex, int oldSize, int newSize);
void on_geometriesChanged();
};
/**
* Extension to QTableWidgetItem that facilitates proper ordering for "DHMS"
* strings (primarily used in the masternode's "active" listing).
*/
class DHMSTableWidgetItem : public QTableWidgetItem
{
public:
DHMSTableWidgetItem(const int64_t seconds);
virtual bool operator<(QTableWidgetItem const& item) const;
private:
// Private backing value for DHMS string, used for sorting.
int64_t value;
};
bool GetStartOnSystemStartup();
bool SetStartOnSystemStartup(bool fAutoStart);
/** Save window size and position */
void saveWindowGeometry(const QString& strSetting, QWidget* parent);
/** Restore window size and position */
void restoreWindowGeometry(const QString& strSetting, const QSize& defaultSizeIn, QWidget* parent);
/** Load global CSS theme */
QString loadStyleSheet();
/** Check whether a theme is not build-in */
bool isExternal(QString theme);
/* Convert QString to OS specific boost path through UTF-8 */
boost::filesystem::path qstringToBoostPath(const QString& path);
/* Convert OS specific boost path to QString through UTF-8 */
QString boostPathToQString(const boost::filesystem::path& path);
/* Convert seconds into a QString with days, hours, mins, secs */
QString formatDurationStr(int secs);
/* Format CNodeStats.nServices bitmask into a user-readable string */
QString formatServicesStr(quint64 mask);
/* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
QString formatPingTime(double dPingTime);
/* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
QString formatTimeOffset(int64_t nTimeOffset);
#if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
// workaround for Qt OSX Bug:
// https://bugreports.qt-project.org/browse/QTBUG-15631
// QProgressBar uses around 10% CPU even when app is in background
class ProgressBar : public QProgressBar
{
bool event(QEvent* e)
{
return (e->type() != QEvent::StyleAnimationUpdate) ? QProgressBar::event(e) : false;
}
};
#else
typedef QProgressBar ProgressBar;
#endif
} // namespace GUIUtil
#endif // BITCOIN_QT_GUIUTIL_H
| [
"edward.thomas3@yahoo.com"
] | edward.thomas3@yahoo.com |
e3c4ac6538e84fd34cd846343f92c8600107131e | cb096ebccdfdae740bf206578160e39d4d947921 | /32/main.cpp | 0103d4a2e1a0e32023448883165487b3baae508c | [] | no_license | andrewsprin/ProjectEuler | 3509b5b549436daa42d9d1a02eeb4123e0f139bc | 3eff7b1a66566e7f757d3a6c2cb98f028d120cf3 | refs/heads/master | 2016-09-16T13:22:51.063866 | 2014-09-13T22:13:25 | 2014-09-13T22:13:25 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,124 | cpp | // Author: Andrew Springer
// SPOILERS for Project Euler Problem 32
//
#include <iostream>
#include <vector>
using namespace std;
// Function Prototypes
vector<int> getFactors(int num);
void printVector(vector<int> v);
vector<int> getMultiplicands(int num);
int main(){
//Print the factors of 20 without multipliers
//printVector(getMultiplicands(20));
cout << "Factors of 20: " << endl;
printVector(getFactors(20));
//Print the factors of 100 without multipliers
//printVector(getMultiplicands(100));
//printVector(getFactors(100));
return 0;
}
vector<int> getFactors(int num){
vector<int> v;
for(int i = 0; i < num; i++){
if((num % i) == 0){
v.push_back(i);
}
}
return v;
}
void printVector(vector<int> v){
for(int i = 0; i < v.size(); i++){
cout << v[i] << ", ";
}
cout << endl;
}
vector<int> getMultiplicands(int num){
vector<int> v = getFactors(num);
int temp = 0;
//Get rid of the multipliers
for(int x = 0; x < v.size(); x++){
temp = ((int) num/v[x]);
for(int y = 0; y < v.size(); y++){
if(v[y] == temp){
v.erase(v.begin() + y);
}
}
}
return v;
}
| [
"andrewsprin@gmail.com"
] | andrewsprin@gmail.com |
3597cf71038fb42a62cc5d2a702dca8718b1eab9 | 5b9694353f59f0c8a0326a6eda78d4b50dcc7f6a | /yarn/Bool.cpp | 9787e7dc4fab2609ec19920f0a5b9e876fb9f693 | [
"MIT"
] | permissive | kchaloux/kitten | 9c83445f09892d89eab17bcd8959a0c23b022b63 | 04c712287f6c09c3e891883783889826f33b7ddf | refs/heads/master | 2021-01-19T06:46:49.048510 | 2013-12-21T19:06:21 | 2013-12-21T19:06:21 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 274 | cpp | #include "Bool.h"
#include <iomanip>
#include <ostream>
Bool::Bool(const type value)
: value(value) {}
MutableValuePtr
Bool::copy() const {
return std::make_shared<Bool>(*this);
}
void
Bool::write(std::ostream& stream) const {
stream << std::boolalpha << value;
}
| [
"evincarofautumn@gmail.com"
] | evincarofautumn@gmail.com |
94557e4bbbc3155549120aa1f92de593f4cab75c | 366bcea9c1de9b2ce0763bab32764550170e3424 | /shell/ProcShell.h | b88eadcbb6347f9de05bf706c65cb23c25e8432a | [] | no_license | ysanquer/mouton | a1b4b8863ad3daa318a141a111a61d6440bc20a0 | 3f5db49da4b9cebd7e5b68e085cd04a12fafe2d1 | refs/heads/master | 2021-01-21T11:23:16.550842 | 2017-03-17T11:39:19 | 2017-03-17T11:39:19 | 83,563,468 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,084 | h | #ifndef _PROC_SHELL_H
#define _PROC_SHELL_H
#include "Shell.h"
#include <map>
///
/// \brief An implementation of a Shell that executes procedures
/// (take-nothing, return-nothing) functions
///
/// \authors Yann Sanquer
///
/// This Shell implementation simply maps commands to their callbacks
/// and matches the commands against a word from the input stream
///
class ProcShell : public Shell< std::function<void()> >
{
public:
///
/// \brief Procedure
///
typedef std::function<void()> Proc;
private:
std::map< std::string, std::pair< Proc, std::string > > _command_map;
public:
///
/// \brief Constructor
///
ProcShell();
///
/// \brief Destructor
///
virtual ~ProcShell();
virtual ProcShell &when(std::string const &command, Proc callback, std::string const &explain) override;
virtual std::string explain(std::string const &command) const override;
private:
virtual void parse_istream(std::istream &) override;
};
#endif
| [
"ysanquer@outlook.fr"
] | ysanquer@outlook.fr |
8f3ee4643eec744303f3ac8decad1e3686101f05 | ee9c5d0ca8f5b0884827f808fd74289f5f8fc5f2 | /problems/COI/2007/COI-07-kolekcija.cpp | d37c2a81ef4e78208a94acc9125e2fcc2d6bc31a | [] | no_license | caoash/competitive-programming | a1f69a03da5ea6eae463c6ae521a55bf32011752 | f98d8d547d25811a26cf28316fbeb76477b6c63f | refs/heads/master | 2022-05-26T12:51:37.952057 | 2021-10-10T22:01:03 | 2021-10-10T22:01:03 | 162,861,707 | 21 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 7,149 | cpp | /*
First, realize the order of songs doesn't matter, so sort it. Also, if you cover some interval of length x, you can extend it to y > x.
The problem reduces to: given N points, place disjoint segments of length X >= K whose sum of lengths is minimized
and covers all points.
Then observe some interval should end at a point, and either start at a point or be length K (and possibly not start at a point).
This is because for interval of length V > K that doesn't start at a point, you can either make it length K or make it start at a point.
Then dp[i] = minimum sum of lengths that covers all points storing prefix maximums of DP values.
Then store prefix maximums in the form of dp[i - 1] - (pt(i) - 1) for fast transitions.
*/
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define fax(i, a) for (int i = 0; i < (a); i++)
#define f0x(i, a, b) for (int i = (a); i < (b); i++)
#define f0xd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define faxd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define memeset memset
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
template <class T, int ...Ns> struct BIT {
T val = 0;
void upd(T v) { val += v; }
T query() { return val; }
};
template <class T, int N, int... Ns> struct BIT<T, N, Ns...> {
BIT<T,Ns...> bit[N + 1];
template<typename... Args> void upd(int pos, Args... args) {
for (; pos <= N; pos += (pos&-pos)) bit[pos].upd(args...);
}
template<typename... Args> T sum(int r, Args... args) {
T res = 0; for (; r; r -= (r&-r)) res += bit[r].query(args...);
return res;
}
template<typename... Args> T query(int l, int r, Args... args) {
return sum(r,args...)-sum(l-1,args...);
}
};
namespace input {
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class T> void re(T& x) { cin >> x; }
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class T, class... Ts> void re(T& t, Ts&... ts) {
re(t); re(ts...);
}
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { fax(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { fax(i,SZ) re(a[i]); }
}
using namespace input;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(ld x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T> void pr(const T& x);
template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
pr(t); pr(ts...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
pr("{",x.f,", ",x.s,"}");
}
template<class T> void pr(const T& x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0;
pr("}");
}
void ps() { pr("\n"); } // print w/ spaces
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
pr(t); if (sizeof...(ts)) pr(" "); ps(ts...);
}
void pc() { pr("]\n"); } // debug w/ commas
template<class T, class... Ts> void pc(const T& t, const Ts&... ts) {
pr(t); if (sizeof...(ts)) pr(", "); pc(ts...);
}
#define dbg(x...) pr("[",#x,"] = ["), pc(x);
}
using namespace output;
namespace io {
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}
}
using namespace io;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 300005;
const ld PI = 4*atan((ld)1);
ll dp[MX]; pair<ll, int> pre[MX]; int fr[MX];
int main() {
setIO();
int n, k, m; re(n, k, m);
set<pi> a; vi b, q;
b.pb(0);
fax(i, m){
int x; re(x);
b.pb(x), q.pb(x);
}
sort(all(b));
fax(i, sz(b)){
a.insert(mp(b[i], i));
}
fax(i, m + 1) dp[i] = INF;
dp[0] = 0;
f0x(i, 1, m + 1){
if(b[i] <= k){
dp[i] = k;
fr[i] = -1;
}
else{
auto it = a.lb(mp(b[i] - (k - 1), INT_MIN));
// dbg(*it);
--it;
// dbg(b[i], k, i, (it -> s));
int pv = (it -> s);
if(dp[pv] + k < dp[i]){
dp[i] = dp[pv] + k;
fr[i] = -1;
}
if(pre[pv].f + b[i] < dp[i]){
dp[i] = pre[pv].f + b[i];
fr[i] = pre[pv].s;
}
ckmin(dp[i], pre[(it -> s)].f + b[i]);
}
pre[i] = min(pre[i - 1], mp(dp[i - 1] - (b[i] - 1), i));
// dbg(i, dp[i], pre[i]);
}
int cur = m;
set<pi> segs;
while(cur > 0){
// dbg(cur, fr[cur], b[cur]);
if(fr[cur] == -1){
if(b[cur] <= k){
segs.insert(mp(1, k));
break;
}
else{
segs.insert(mp(b[cur] - (k - 1), b[cur]));
auto to = a.lb(mp(b[cur] - (k - 1), INT_MIN));
--to;
cur = (to -> s);
}
}
else{
segs.insert(mp(b[fr[cur]], b[cur]));
// dbg(cur, b[fr[cur]], b[cur]);
cur = fr[cur] - 1;
}
// dbg(cur, fr[cur]);
// cout << endl;
}
// dbg(segs);
stack<pi> mrg;
set<pi> nsegs;
trav(curr, segs){
if(mrg.empty()){
mrg.push(curr);
}
else{
if(mrg.top().s < curr.f){
mrg.push(curr);
}
else{
pi nxt = mp(mrg.top().f, curr.s);
mrg.pop();
mrg.push(nxt);
}
}
}
ps(dp[m]);
while(!mrg.empty()) {
nsegs.insert(mrg.top());
mrg.pop();
}
// dbg(segs, nsegs);
trav(curr, q){
auto seg = nsegs.ub(mp(curr, INT_MAX));
--seg;
int l = max({1, (seg -> f), curr - (k - 1)}); int r = min(n, l + (k - 1));
ps(l, r);
}
} | [
"caoash@gmail.com"
] | caoash@gmail.com |
ed3b3df9e12d76632375b1905843d77ca5c7eb6b | 77f1be96da9c29c21d06e503243289273320ce81 | /0560.和为K的子数组/0560-和为K的子数组.cpp | b36b23b502144e5b8cbeb5483d6d4a6ca0af15dc | [] | no_license | Huqingnan123/MyLeetcode | 951615fd5d60e873f77f50f008af5feec499b225 | b4c708821a7036afd67c8157a842621b329cb801 | refs/heads/master | 2023-04-11T08:40:30.559536 | 2021-04-10T04:34:48 | 2021-04-10T04:34:48 | 151,220,244 | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 802 | cpp | class Solution {
public:
//采用前缀和的思想,要找到一个子数组[j,i]的和为K,只要前缀和之差pre[i] - pre[j-1] == K
//采用hash表记录“前缀和为key的[0,i]子数组的个数value”,采用pre记录[0,curretIndex]的区间前缀和
//一次遍历,不断更新前缀和preSum以及hash表,count加上hash[preSum-K]的值(就是[j,current_i]子数组的个数)
int subarraySum(vector<int>& nums, int k) {
unordered_map<int, int> hash;
hash[0] = 1;
int count = 0;
int preSum = 0;
for (auto& num : nums) {
preSum += num;
if (hash.find(preSum - k) != hash.end()) {
count += hash[preSum - k];
}
hash[preSum]++;
}
return count;
}
}; | [
"897703334@qq.com"
] | 897703334@qq.com |
bb959921ccd3fb308ad544adce22b1c9e8560500 | 902820b240dc4ac906983c69739b9b2889f84926 | /Searching and Sorting/Sort01.cpp | ae2eb1159b0fa5c3b98b6bc13d42690811230b98 | [] | no_license | DigantaChauduri06/CODING-NINJAS-CPP-COURSE-ANSWERS | 350296e940e1cf6f2a97c6f6867f2f95fc67c2e8 | b2e361f2bbcb24319d47717b6d2cf866506a98ab | refs/heads/master | 2023-07-06T09:13:20.151337 | 2021-08-08T18:54:03 | 2021-08-08T18:54:03 | 393,769,406 | 0 | 0 | null | 2021-08-08T18:54:04 | 2021-08-07T19:04:45 | C++ | UTF-8 | C++ | false | false | 1,825 | cpp | /*Sort 0 1 2
Send Feedback
You are given an integer array/list(ARR) of size N. It contains only 0s, 1s and 2s. Write a solution to sort this array/list in a 'single scan'.
'Single Scan' refers to iterating over the array/list just once or to put it in other words, you will be visiting each element in the array/list just once.
Note:
You need to change in the given array/list itself. Hence, no need to return or print anything.
Input format :
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
First line of each test case or query contains an integer 'N' representing the size of the array/list.
Second line contains 'N' single space separated integers(all 0s, 1s and 2s) representing the elements in the array/list.
Output Format :
For each test case, print the sorted array/list elements in a row separated by a single space.
Output for every test case will be printed in a separate line.
Constraints :
1 <= t <= 10^2
0 <= N <= 10^5
Time Limit: 1 sec
Sample Input 1:
1
7
0 1 2 0 2 0 1
Sample Output 1:
0 0 0 1 1 2 2
Sample Input 2:
2
5
2 2 0 1 1
7
0 1 2 0 1 2 0
Sample Output 2:
0 1 1 2 2
0 0 0 1 1 2 2*/
void sort012(int *arr, int n)
{
int cnt0 = 0, cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++)
{
switch (arr[i])
{
case 0:
cnt0++;
break;
case 1:
cnt1++;
break;
case 2:
cnt2++;
break;
default:
continue;
}
}
int i = 0;
while (i < cnt0)
{
arr[i] = 0;
i++;
}
int j = 0;
while (j < cnt1)
{
arr[i] = 1;
i++;
j++;
}
int k = 0;
while (k < cnt2)
{
arr[i] = 2;
i++;
k++;
}
} | [
"digantachaudhuri03@gmail.com"
] | digantachaudhuri03@gmail.com |
7d1cb0ac53602f51f75e448918c4501c29ef6488 | cb5ed402b086c58b7d67600f0b8d49662a0a9dc6 | /include/itkTileMontage.h | 8f747c3706d37348101415aebbec85192a1755e0 | [
"Apache-2.0"
] | permissive | fbudin69500/ITKMontage | 9e0fa050506f8650550399d5abd72f37fc52b91d | 4982fda5b0809ff0ef5e24b6570ef5ec9e002630 | refs/heads/master | 2021-05-04T00:54:04.384005 | 2019-05-10T20:15:16 | 2019-05-10T21:31:37 | 120,355,349 | 0 | 0 | null | 2018-02-05T20:06:08 | 2018-02-05T20:06:07 | null | UTF-8 | C++ | false | false | 10,601 | h | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkTileMontage_h
#define itkTileMontage_h
#include "itkImageFileReader.h"
#include "itkMaxPhaseCorrelationOptimizer.h"
#include "itkPhaseCorrelationImageRegistrationMethod.h"
#include <vector>
namespace itk
{
/** \class TileMontage
* \brief Determines registrations for an n-Dimensional mosaic of images.
*
* Determines registrations which can be used to resample a mosaic into a single image.
*
* \author Dženan Zukić, dzenan.zukic@kitware.com
*
* \ingroup Montage
*/
template< typename TImageType, typename TCoordinate = float >
class ITK_TEMPLATE_EXPORT TileMontage : public ProcessObject
{
public:
ITK_DISALLOW_COPY_AND_ASSIGN( TileMontage );
/** Standard class type aliases. */
using Self = TileMontage;
using Superclass = ProcessObject;
using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;
using ImageType = TImageType;
// using ImagePointer = typename ImageType::Pointer;
// using ImageConstPointer = typename ImageType::ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro( Self );
/** Run-time type information (and related methods). */
itkTypeMacro( TileMontage, ProcessObject );
/** Dimensionality of input images. */
itkStaticConstMacro( ImageDimension, unsigned int, ImageType::ImageDimension );
/** Montage size and tile index types. */
using SizeType = Size< ImageDimension >;
using TileIndexType = Size< ImageDimension >;
using ContinuousIndexType = ContinuousIndex< TCoordinate, ImageDimension >;
/** Image's dependent types. */
using PixelType = typename ImageType::PixelType;
using RegionType = typename ImageType::RegionType;
using PointType = typename ImageType::PointType;
using SpacingType = typename ImageType::SpacingType;
using OffsetType = typename ImageType::OffsetType;
using ImageIndexType = typename ImageType::IndexType;
/** Internal PhaseCorrelationImageRegistrationMethod's type alias. */
using PCMType = PhaseCorrelationImageRegistrationMethod< ImageType, ImageType >;
using RealType = typename itk::NumericTraits< PixelType >::RealType;
using PCMOperatorType = itk::PhaseCorrelationOperator< RealType, ImageDimension >;
using PCMOptimizerType = itk::MaxPhaseCorrelationOptimizer< PCMType >;
/** Type for the transform. */
using TransformType = typename PCMType::TransformType;
using TransformPointer = typename TransformType::Pointer;
using TransformConstPointer = typename TransformType::ConstPointer;
/** Type for the output: Using Decorator pattern for enabling
* the Transform to be passed in the data pipeline */
using TransformOutputType = DataObjectDecorator< TransformType >;
/** Smart Pointer type to a DataObject. */
using DataObjectPointer = typename DataObject::Pointer;
/** Passes ReleaseDataFlag to internal filters. */
void SetReleaseDataFlag( bool flag ) override
{
Superclass::SetReleaseDataFlag( flag );
m_PCM->SetReleaseDataFlag( flag );
}
/** Passes ReleaseDataBeforeUpdateFlag to internal filters. */
void SetReleaseDataBeforeUpdateFlag( const bool flag ) override
{
Superclass::SetReleaseDataBeforeUpdateFlag( flag );
m_PCM->SetReleaseDataBeforeUpdateFlag( flag );
}
/** Set/Get the OriginAdjustment. Origin adjustment multiplied by tile index
* is added to origin of images when only their filename is specified.
* This allows assumed positions for tiles even if files have zero origin. */
itkSetMacro( OriginAdjustment, PointType );
itkGetConstMacro( OriginAdjustment, PointType );
/** Set/Get forced spacing.
* If set, overrides spacing for images read from files. */
itkSetMacro( ForcedSpacing, SpacingType );
itkGetConstMacro( ForcedSpacing, SpacingType );
/** Set/Get obligatory padding.
* If set, padding of this many pixels is added on both beginning and end
* sides of each dimension of the image. */
virtual void SetObligatoryPadding( const SizeType pad )
{
if ( this->m_ObligatoryPadding != pad )
{
this->m_ObligatoryPadding = pad;
m_PCM->SetObligatoryPadding( pad );
this->Modified();
}
}
itkGetConstMacro( ObligatoryPadding, SizeType );
/** Set/Get the PhaseCorrelationImageRegistrationMethod. */
virtual void SetPCM( PCMType* pcm )
{
if ( this->m_PCM != pcm )
{
this->m_PCM = pcm;
m_PCM->SetObligatoryPadding( m_ObligatoryPadding );
this->Modified();
}
}
itkGetModifiableObjectMacro( PCM, PCMType );
/** Set/Get the PhaseCorrelationImageRegistrationMethod. */
itkSetObjectMacro( PCMOptimizer, PCMOptimizerType );
itkGetModifiableObjectMacro( PCMOptimizer, PCMOptimizerType );
/** Get/Set size of the image mosaic. */
itkGetConstMacro( MontageSize, SizeType );
void SetMontageSize( SizeType montageSize );
/** To be called for each tile position in the mosaic
* before the call to Update(). */
void SetInputTile( TileIndexType position, ImageType* image )
{
SizeValueType linearIndex = this->nDIndexToLinearIndex( position );
this->SetNthInput( linearIndex, image );
m_FFTCache[linearIndex] = nullptr;
}
void SetInputTile( TileIndexType position, const std::string& imageFilename )
{
SizeValueType linearIndex = this->nDIndexToLinearIndex( position );
m_Filenames[linearIndex] = imageFilename;
this->SetInputTile( position, m_Dummy );
}
/** After Update(), the transform for each tile is available. */
TransformConstPointer GetOutputTransform( TileIndexType position )
{
return static_cast< TransformOutputType* >( this->GetOutput( this->nDIndexToLinearIndex( position ) ) )->Get();
}
protected:
TileMontage();
virtual ~TileMontage(){};
void PrintSelf( std::ostream& os, Indent indent ) const override;
/** Method invoked by the pipeline in order to trigger the computation of the registration. */
void GenerateData() override;
/** Method invoked by the pipeline to determine the output information. */
void GenerateOutputInformation() override;
using Superclass::MakeOutput;
/** Make a DataObject of the correct type to be used as the specified output. */
DataObjectPointer MakeOutput( DataObjectPointerArraySizeType ) override
{
return TransformOutputType::New();
}
/** For reading if only filename was given. */
using ReaderType = itk::ImageFileReader< ImageType >;
template <typename TImageToRead>
typename TImageToRead::Pointer
GetImageHelper( TileIndexType nDIndex, bool metadataOnly, RegionType region,
ImageFileReader< TImageToRead >* reader = nullptr );
/** Just get image pointer if the image is present, otherwise read it from file. */
typename ImageType::Pointer GetImage( TileIndexType nDIndex, bool metadataOnly );
DataObjectPointerArraySizeType nDIndexToLinearIndex( TileIndexType nDIndex ) const;
TileIndexType LinearIndexTonDIndex( DataObjectPointerArraySizeType linearIndex ) const;
/** Register a pair of images with given indices. Handles FFTcaching. */
TransformPointer RegisterPair( TileIndexType fixed, TileIndexType moving );
/** If possible, removes from memory tile with index smaller by 1 along all dimensions. */
void ReleaseMemory( TileIndexType finishedTile );
/** Montage this dimension, and all lower dimensions. */
void MontageDimension( int d, TileIndexType initialTile );
/** Accesses output, sets a transform to it, and updates progress. */
void WriteOutTransform( TileIndexType index, TransformPointer transform );
/** Updates mosaic bounds. The transform applies to input.
* input0 is tile in the top-left corner. */
void UpdateMosaicBounds(
TileIndexType index,
TransformConstPointer transform,
const ImageType *input,
const ImageType *input0 );
/** Image's FFT type. */
using FFTType = typename PCMType::ComplexImageType;
using FFTPointer = typename FFTType::Pointer;
using FFTConstPointer = typename FFTType::ConstPointer;
using TransformVector = std::vector< TransformPointer >;
using ConfidencesType = typename PCMType::ConfidencesVector;
// convets translation from index space into physical space
TransformPointer OffsetToTransform( const typename PCMOptimizerType::OffsetType& translation,
typename ImageType::Pointer tileInformation );
void OptimizeTiles();
private:
SizeType m_MontageSize;
SizeValueType m_LinearMontageSize = 0;
SizeValueType m_FinishedTiles = 0;
PointType m_OriginAdjustment;
SpacingType m_ForcedSpacing;
SizeType m_ObligatoryPadding;
std::vector< std::string > m_Filenames;
std::vector< FFTConstPointer > m_FFTCache;
std::vector< TransformVector > m_TransformCandidates; // to adjacent tiles
std::vector< ConfidencesType > m_CandidateConfidences;
std::vector< TransformPointer > m_CurrentAdjustments;
typename PCMType::Pointer m_PCM = PCMType::New();
typename ReaderType::Pointer m_Reader = ReaderType::New();
typename ImageType::Pointer m_Dummy = ImageType::New();
typename PCMOperatorType::Pointer m_PCMOperator = PCMOperatorType::New();
typename PCMOptimizerType::Pointer m_PCMOptimizer = PCMOptimizerType::New();
// members needed for ResampleIntoSingleImage
ContinuousIndexType m_MinInner; // minimum index for cropped montage
ContinuousIndexType m_MaxInner; // maximum index for cropped montage
ContinuousIndexType m_MinOuter; // minimum index for total montage
ContinuousIndexType m_MaxOuter; // maximum index for total montage
template< typename TImageTypeInner, typename TPixelAccumulateType, typename TInterpolatorInner >
friend class TileMergeImageFilter;
}; // class TileMontage
} // namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkTileMontage.hxx"
#endif
#endif // itkTileMontage_h
| [
"dzenan.zukic@kitware.com"
] | dzenan.zukic@kitware.com |
6504cffd549e2ee3ba35e13df6f206bb9c5887fe | 8c277a53b168aeef7e7e287ddbce1f19db4d4e2c | /Core/examplefeeder.cpp | 8eca4f77b97f9c6f7fd5c1e86808cf3c2c612fd7 | [] | no_license | morice-net/Awale | dc384d2b62a383a13f5ce4b6eb6e20a59e114915 | 5c59ae2be9432976cc372dfeb9fef73f63651768 | refs/heads/master | 2020-12-29T02:35:57.923552 | 2018-04-29T09:55:27 | 2018-04-29T09:55:27 | 44,384,504 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,180 | cpp | #include "examplefeeder.h"
#include <QDebug>
#include <QString>
#include <QFile>
ExampleFeeder::ExampleFeeder(QObject *parent) : QObject(parent), m_recordFile("AwaleTrain.csv")
{
connect(this, SIGNAL(record(const QString &)), SLOT(onRecord(const QString &)));
}
void ExampleFeeder::addExample(const QVector<Awale> &awales, const QVector<int> &plays, bool reverse)
{
for (int i = 0; i < plays.size(); ++i)
{
QStringList row;
if (! reverse) {
foreach (int hole, awales.at(i).playerHalve1()) {
row << QString::number(hole);
}
}
foreach (int hole, awales.at(i).playerHalve2()) {
row << QString::number(hole);
}
if (reverse) {
foreach (int hole, awales.at(i).playerHalve1()) {
row << QString::number(hole);
}
}
row << QString::number(plays.at(i));
emit record(row.join(" ").append(QString("\n")));
i++;
}
}
void ExampleFeeder::onRecord(const QString &row)
{
if (!m_recordFile.isOpen()) {
m_recordFile.open(QIODevice::WriteOnly);
}
m_recordFile.write(row.toUtf8());
}
| [
"jeannicolasartaud@gmail.com"
] | jeannicolasartaud@gmail.com |
591269049c81a5e85dc9fdd671aba1eb35f38055 | 7c6db5d82a88ae341ebf418a03a319c392f180f1 | /FrameWork/ProjetFRW/core/Evaluator.h | 204d6b1e6b54fef23b1ab7dd7335ae916f05979e | [] | no_license | gryffenferd/ProjetFW | 24154d210531597547e443c0f5875d8d0a6c3ee4 | 220d3ef1602e5b08ee856d7dbd0f813e0b34cbc9 | refs/heads/master | 2021-01-19T09:42:15.619582 | 2015-05-17T13:41:10 | 2015-05-17T13:41:10 | 35,767,576 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,142 | h | #ifndef EVALUATOR_H
#define EVALUATOR_H
#include <vector>
#include "ValueModel.h"
#include "Expression.h"
namespace core
{
template <class T>
class Evaluator
{
public:
typedef std::pair<std::vector<T>,std::vector<T>> Shape;
static Shape buildShape(T,T,T,core::ValueModel<T>*, core::Expression<T>*);
static std::ostream& printShape(const Shape& , std::ostream&);
};
template <class T>
typename Evaluator<T>::Shape Evaluator<T>::buildShape(T min, T max, T step, core::ValueModel<T>* v, core::Expression<T>* e)
{
std::vector<T> x,y;
T mem = v -> evaluate();
for (T i = min; i <= max ; i += step)
{
v -> setValue(i);
y.push_back(e -> evaluate());
x.push_back(i);
}
v -> setValue(mem)
return Shape(x,y);
}
template <class T>
std::ostream& Evaluator<T>::printShape(const Shape& s, std::ostream& os)
{
os << '[';
typename std::vector<T>::const_iterator it = s.first.begin();
for(;it!=s.first.end();++it)
os << *it << ' ';
os << ']';
os << std::endl;
os << '[';
it = s.second.begin();
for(; it != s.second.end(); ++it)
os << *it << ' ';
os << ']';
return os;
}
}
#endif | [
"axeljacki@gmail.com"
] | axeljacki@gmail.com |
49a79a0a43d7f5bd4c27d4708370a99565842152 | 08b8cf38e1936e8cec27f84af0d3727321cec9c4 | /data/crawl/collectd/hunk_260.cpp | a9051051e55d26ce42a6a8bce461599bf20dd475 | [] | no_license | ccdxc/logSurvey | eaf28e9c2d6307140b17986d5c05106d1fd8e943 | 6b80226e1667c1e0760ab39160893ee19b0e9fb1 | refs/heads/master | 2022-01-07T21:31:55.446839 | 2018-04-21T14:12:43 | 2018-04-21T14:12:43 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 294 | cpp |
static PyObject *cpy_info(PyObject *self, PyObject *args) {
const char *text;
- if (PyArg_ParseTuple(args, "s", &text) == 0) return NULL;
+ if (PyArg_ParseTuple(args, "et", NULL, &text) == 0) return NULL;
Py_BEGIN_ALLOW_THREADS
plugin_log(LOG_INFO, "%s", text);
Py_END_ALLOW_THREADS
| [
"993273596@qq.com"
] | 993273596@qq.com |
1a7f878a759d89a1bbab49d730a67a4fd429d2e6 | f772ab10ebfab4ac0175ae267248821a3facb574 | /080_Remove_Duplicates_from_Sorted_Array_II.cpp | 1fc2fb94b9e490247a2ff9878c17486b38239536 | [] | no_license | cjhgo/leetcode | a9e357423006e82402547c6114bc5f36772cd87f | 8217f3b29ed601427f89d121b2fca447c01eeb9b | refs/heads/master | 2020-03-20T21:56:18.847107 | 2019-09-10T14:09:09 | 2019-09-10T14:09:09 | 137,769,523 | 4 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,426 | cpp | #include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
static const auto x=[](){
std::ios::sync_with_stdio(false);
std:cin.tie(nullptr);
return nullptr;
}();
class Solution
{
public:
int removeDuplicates(vector<int>& nums)
{
if(nums.size() < 2) return nums.size();
int counter = 2, cnt=0;
for(size_t i = 2; i < nums.size(); i++)
{
if( nums[i] != nums[counter-2])
{
nums[counter] = nums[i];
counter++;
}
}
return counter;
}
int removeDuplicates2(vector<int>& nums)
{
if(nums.size() < 2) return nums.size();
int counter = 1, cnt=0;
for(size_t i = 1; i < nums.size(); i++)
{
if( nums[i] != nums[i-1])
{
nums[counter] = nums[i];
counter++;
cnt=0;
}
else//nums[i] == nums[]
{
++cnt;
nums[counter] = nums[i];
if( cnt < 2)
counter++;
}
}
return counter;
}
};
int main(int argc, char const *argv[])
{
Solution sol;
vector<int> nums = {0,0,1,1,1,1,2,3,3};
//{0,0,1,1,1,2,2,3,3,4};
cout<<sol.removeDuplicates(nums)<<endl;
for(auto e: nums)
cout<<e<<"\t";
return 0;
} | [
"1728533217en@gmail.com"
] | 1728533217en@gmail.com |
99d9a337777ccd974991770343f169498e073e35 | d95c9b7f654b8f0b14721ea585f5665cff071b7b | /source/P2PService/Socket/SysEvent.h | c2143eac866ef4937e97844f746711330fad598c | [] | no_license | MiracleZhang/P2PCenter | 8e2cfdeb1dbbdedee7103b5e42afec851530128b | 2d84774f63a7f8f50fa752f158816876055168eb | refs/heads/master | 2020-07-06T23:28:39.167915 | 2019-08-21T11:18:40 | 2019-08-21T11:18:40 | 203,171,841 | 0 | 0 | null | 2019-08-19T12:49:26 | 2019-08-19T12:49:26 | null | UTF-8 | C++ | false | false | 2,661 | h | #if !defined(SysEvent_H)
#define SysEvent_H
#include <string>
using namespace std;
////////////////////////////////////////////////////////////////////////
// SysEvent
class SysEvent
{
string m_name; // name of event
HANDLE m_hEvent; // handle to user event
bool m_attached; // shows if just attached to event
public:
SysEvent () :
m_name (),
m_hEvent (NULL),
m_attached(false)
{}
SysEvent ( SysEvent & event ) :
m_name (),
m_hEvent (NULL),
m_attached(false)
{ *this = event; }
virtual ~SysEvent ()
{ release(); }
// create/release
bool create ()
{
// release if needed
release();
// init name
m_name = "";
// create event
m_attached = false;
m_hEvent = ::CreateEvent( NULL, TRUE, FALSE, NULL );
if ( m_hEvent == NULL )
return false;
else
return true;
}
bool create ( LPTSTR name )
{
if ( !name )
return false;
// release if needed
release();
// create named event
m_attached = false;
m_hEvent = ::CreateEvent( NULL, TRUE, FALSE, (LPCTSTR) name );
if ( m_hEvent == NULL )
return false;
else
return true;
}
void release ()
{
// if only attached just detach
// else destroy event and name
if ( m_attached )
detach();
else
{
if ( m_hEvent )
{
::CloseHandle(m_hEvent);
m_hEvent = NULL;
}
if ( !m_name.empty() )
m_name.erase();
}
}
// attach/detach from event
bool attached ()
{ return m_attached; }
bool attach ( HANDLE hEvent )
{
if ( !hEvent )
return false;
// get handle show attached
m_hEvent = hEvent;
m_attached = true;
return true;
}
void detach ()
{
// if not attached stop
if ( !m_attached )
return;
m_hEvent = NULL;
if ( !m_name.empty() )
m_name.erase();
m_attached = false;
}
// set/reset event
void set ()
{
::SetEvent( m_hEvent );
}
void reset ()
{
::ResetEvent( m_hEvent );
}
// get event handle
HANDLE getEvent ()
{ return m_hEvent; }
// ref operators
HANDLE operator & ()
{ return m_hEvent; }
operator HANDLE ()
{
return m_hEvent;
}
// sort operators
bool operator < ( SysEvent & event )
{
if ( m_hEvent < event.m_hEvent )
return true;
else
return false;
}
bool operator == ( SysEvent & event )
{
if ( m_hEvent == event.m_hEvent )
return true;
else
return false;
}
bool operator = ( SysEvent & event )
{
m_name = event.m_name;
m_hEvent = event.m_hEvent;
m_attached = event.m_attached;
}
};
#endif | [
"kan8888@379a83a1-4744-0410-80de-eb4b870af569"
] | kan8888@379a83a1-4744-0410-80de-eb4b870af569 |
39b6c1cde6b18bb31aafcecb5efa6c6215c4930b | cbcd6fa6e023596929e706dfa21679cf56dafa3b | /src/texture.cpp | 40b98e41a051129f7d223e992af8ca901587da5d | [] | no_license | Asoelter/atomic | 50a151de1b61caf89e15579efea31a7b75a59562 | 36859ea0c53291656138027759e6a55d270bccc8 | refs/heads/master | 2020-04-11T17:18:22.157714 | 2019-02-04T00:27:21 | 2019-02-04T00:27:21 | 161,955,781 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,172 | cpp | #define STB_IMAGE_IMPLEMENTATION
#include "texture.h"
int Texture::textureCount_ = 0;
Texture::Texture(const std::string& filePath)
: id_(0)
, textureNumber_(textureCount_)
{
int width = 0;
int height = 0;
int numChannels = 0;
stbi_set_flip_vertically_on_load(true);
unsigned char* data = stbi_load(filePath.c_str(), &width, &height, &numChannels, 0);
glGenTextures(1, &id_);
glBindTexture(GL_TEXTURE_2D, id_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(data)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
std::cout << "Unable to load texture" << std::endl;
}
stbi_image_free(data);
++textureCount_;
}
void Texture::bind() const
{
glActiveTexture(GL_TEXTURE0 + textureNumber_);
glBindTexture(GL_TEXTURE_2D, id_);
}
void Texture::unbind() const
{
glActiveTexture(GL_TEXTURE0 + textureNumber_);
glBindTexture(GL_TEXTURE_2D, 0);
}
| [
"adamdlsoelter@gmail.com"
] | adamdlsoelter@gmail.com |
e64e88ca500d00e874b72f916529cca5db8f7b58 | 0997dd974ba4f8b9d7f3bfec461a71b9d0a11bc3 | /Poj/Poj1068/Poj1068.cpp | af51c5dae53ffc72ce1e7d22dec9f25d9d528df2 | [] | no_license | mobileliker/mobileliker-OJ | a4a11fc95518832699c036d51f526f5909540df1 | f5a685ee4934a7eab3db25bcd2aaf58cd03c6368 | refs/heads/master | 2018-10-09T21:37:57.512449 | 2018-06-23T01:13:03 | 2018-06-23T01:13:03 | 25,805,440 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,007 | cpp | #include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
//freopen("D://input.txt","r",stdin);
int i,j;
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
int *arr_p = new int[n];
for(i = 0; i < n; ++i) cin >> arr_p[i];
//for(i = 0; i < n; ++i) cout << arr_p[i] << endl;
vector<char> v_sym;
int pre_p = 0;
for(i = 0; i < n; ++i)
{
for(j = pre_p; j < arr_p[i]; ++j) v_sym.push_back('(');
v_sym.push_back(')');
pre_p = arr_p[i];
}
vector<char>::size_type sym_i;
//for(sym_i = 0; sym_i != v_sym.size(); ++sym_i) cout << v_sym[sym_i];
//cout << endl;
stack<int> s_sym;// -1 (, -2 )
for(sym_i = 0; sym_i != v_sym.size(); ++sym_i)
{
if('(' == v_sym[sym_i]) s_sym.push(-1);
else
{
int count = 1;
while(s_sym.top() != -1)
{
count += s_sym.top();
s_sym.pop();
}
s_sym.pop();
cout << count << " ";
s_sym.push(count);
}
}
cout << endl;
delete [] arr_p;
}
return 0;
} | [
"mobileliker@gmail.com"
] | mobileliker@gmail.com |
6479f91625b03344166f8abda025a772a8c7427e | a489e3c28cbdbdc68405c161d50db66744ed343c | /src/wallet/ismine.h | 730fc09dceb039ed9cd5c18efec1463b55431811 | [
"MIT"
] | permissive | satcoin-dev/satcoin | 5284f9f13f3a8797b38f97aa5f3a7c074e648a7e | a68f5965a8c28cfcaf8855a661ea3f15de9ae7d5 | refs/heads/master | 2023-05-08T06:13:54.490717 | 2021-05-31T11:17:18 | 2021-05-31T11:17:18 | 329,268,860 | 4 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 1,265 | h | // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef SATCOIN_WALLET_ISMINE_H
#define SATCOIN_WALLET_ISMINE_H
#include <script/standard.h>
#include <stdint.h>
#include <bitset>
class CWallet;
class CScript;
/** IsMine() return codes */
enum isminetype : unsigned int
{
ISMINE_NO = 0,
ISMINE_WATCH_ONLY = 1 << 0,
ISMINE_SPENDABLE = 1 << 1,
ISMINE_USED = 1 << 2,
ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE,
ISMINE_ALL_USED = ISMINE_ALL | ISMINE_USED,
ISMINE_ENUM_ELEMENTS,
};
/** used for bitflags of isminetype */
typedef uint8_t isminefilter;
/**
* Cachable amount subdivided into watchonly and spendable parts.
*/
struct CachableAmount
{
// NO and ALL are never (supposed to be) cached
std::bitset<ISMINE_ENUM_ELEMENTS> m_cached;
CAmount m_value[ISMINE_ENUM_ELEMENTS];
inline void Reset()
{
m_cached.reset();
}
void Set(isminefilter filter, CAmount value)
{
m_cached.set(filter);
m_value[filter] = value;
}
};
#endif // SATCOIN_WALLET_ISMINE_H
| [
"satcoindev@gmail.com"
] | satcoindev@gmail.com |
2aa5221382af80836a694109d5984c74afe095a8 | a3d6556180e74af7b555f8d47d3fea55b94bcbda | /third_party/blink/renderer/modules/xr/xr_joint_pose.h | 246c7c22dd67e274cf62fe4e92dcc65f14ffb444 | [
"LGPL-2.0-or-later",
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.1-only",
"GPL-1.0-or-later",
"GPL-2.0-only",
"LGPL-2.0-only",
"BSD-2-Clause",
"LicenseRef-scancode-other-copyleft",
"BSD-3-Clause",
"MIT",
"Apache-2.0"
] | permissive | chromium/chromium | aaa9eda10115b50b0616d2f1aed5ef35d1d779d6 | a401d6cf4f7bf0e2d2e964c512ebb923c3d8832c | refs/heads/main | 2023-08-24T00:35:12.585945 | 2023-08-23T22:01:11 | 2023-08-23T22:01:11 | 120,360,765 | 17,408 | 7,102 | BSD-3-Clause | 2023-09-10T23:44:27 | 2018-02-05T20:55:32 | null | UTF-8 | C++ | false | false | 765 | h | // Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_JOINT_POSE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_JOINT_POSE_H_
#include "third_party/blink/renderer/modules/xr/xr_pose.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "ui/gfx/geometry/transform.h"
namespace blink {
class XRJointPose : public XRPose {
DEFINE_WRAPPERTYPEINFO();
public:
XRJointPose(const gfx::Transform& transform, float radius);
float radius() const { return radius_; }
private:
float radius_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_JOINT_POSE_H_
| [
"chromium-scoped@luci-project-accounts.iam.gserviceaccount.com"
] | chromium-scoped@luci-project-accounts.iam.gserviceaccount.com |
d7b0106f8912fe63046c53a090e6387e0c591c34 | 0753dddd7136c69430d5f768ff0c478895748fb4 | /dzy_trackers/trackerscompare_1.cpp | 4e2daf88ef8ebf8db49139d739d92dc1a94703aa | [] | no_license | anhuipl2010/Object-Tracking | 922c31f66377fdba3818991b956345896118a7ab | 1a40898f5998fda57f85e195026bbccbe3b2c499 | refs/heads/master | 2020-07-24T22:39:13.193479 | 2019-01-28T16:30:50 | 2019-01-28T16:30:50 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 10,712 | cpp |
#include "kcf/kcftracker.hpp"
#include "eco/eco.hpp"
#include "eco/parameters.hpp"
#ifdef USE_CAFFE
#include "goturn/network/regressor.h"
#include "goturn/tracker/tracker.h"
#endif
#include "inputs/readdatasets.hpp"
#include "inputs/readvideo.hpp"
//#include "inputs/openpose.hpp"
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <opencv2/opencv.hpp>
//#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace cv;
using namespace std;
// Convert to string
int main(int argc, char **argv)
{
int key,flag = 0;
/*
// Read using openpose============================================
cv::Rect2f bboxGroundtruth;
cv::Mat frame, frameDraw;
OpenPose openpose;
openpose.IniRead(bboxGroundtruth);
VideoCapture capture(0); // open the default camera
if (!capture.isOpened()) // check if we succeeded
return -1;
capture.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
capture >> frame;
//frame.copyTo(frameDraw);
//rectangle(frameDraw, bboxGroundtruth, Scalar(0, 0, 0), 2, 1);
//imshow("Tracking", frameDraw);
*/
// Read from Video and choose a bbox===============================
//::google::InitGoogleLogging(argv[0]);
cv::Rect2f bboxGroundtruth;
cv::Mat frame, frameDraw;
//cv::VideoCapture capture;
//capture.open("sequences/oneperson.mp4");
VideoCapture capture(1); // open the default camera
if (!capture.isOpened())
{
std::cout << "Capture device failed to open!" << std::endl;
return -1;
}
capture.set(CV_CAP_PROP_FRAME_WIDTH, 480);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);
capture >> frameDraw;
frameDraw.copyTo(frame);
std::string window_name = "OpenTracker";
cv::namedWindow(window_name, 0);
ReadVideo readvideo;
//readvideo.IniRead(bboxGroundtruth, frameDraw, window_name, capture);
// Read from the datasets==========================================
// ::google::InitGoogleLogging(argv[0]);
/* cv::Rect2f bboxGroundtruth;
cv::Mat frame, frameDraw;
ReadDatasets readdatasets;
readdatasets.IniRead(bboxGroundtruth, frame);
frame.copyTo(frameDraw);
readdatasets.DrawGroundTruth(bboxGroundtruth, frameDraw);
*/
// Init the trackers=================================================
// Create Opencv tracker:
// string trackerTypes[6] = {"BOOSTING", "MIL", "KCF", "TLD", "MEDIANFLOW", "GOTURN"};
// string trackerType = trackerTypes[2];
// Ptr<cv::Tracker> opencvtracker;
// if (trackerType == "BOOSTING")
// opencvtracker = cv::TrackerBoosting::create();
// if (trackerType == "MIL")
// opencvtracker = cv::TrackerMIL::create();
// if (trackerType == "KCF")
// opencvtracker = cv::TrackerKCF::create();
// if (trackerType == "TLD")
// opencvtracker = cv::TrackerTLD::create();
// if (trackerType == "MEDIANFLOW")
// opencvtracker = cv::TrackerMedianFlow::create();
// if (trackerType == "GOTURN")
// opencvtracker = cv::TrackerGOTURN::create();
// Rect2d opencvbbox((int)bboxGroundtruth.x, (int)bboxGroundtruth.y, (int)bboxGroundtruth.width, (int)bboxGroundtruth.height);
// opencvtracker->init(frame, opencvbbox);
// Create KCFTracker:
/* bool HOG = true, FIXEDWINDOW = true, MULTISCALE = true, LAB = true, DSST = false; //LAB color space features
kcf::KCFTracker kcftracker(HOG, FIXEDWINDOW, MULTISCALE, LAB, DSST);
Rect2d kcfbbox((int)bboxGroundtruth.x, (int)bboxGroundtruth.y, (int)bboxGroundtruth.width, (int)bboxGroundtruth.height);
kcftracker.init(frame, kcfbbox);
// Create DSSTTracker:
DSST = true;
kcf::KCFTracker dssttracker(HOG, FIXEDWINDOW, MULTISCALE, LAB, DSST);
Rect2d dsstbbox((int)bboxGroundtruth.x, (int)bboxGroundtruth.y, (int)bboxGroundtruth.width, (int)bboxGroundtruth.height);
dssttracker.init(frame, dsstbbox);
#ifdef USE_CAFFE
// Create GOTURN tracker:
const string model_file = "goturn/nets/deploy.prototxt";
const string pretrain_file = "goturn/nets/goturun_tracker.caffemodel";
int gpu_id = 0;
Regressor regressor(model_file, pretrain_file, gpu_id, false);
goturn::Tracker goturntracker(false);
cv::Rect goturnbbox(bboxGroundtruth.x, bboxGroundtruth.y, bboxGroundtruth.width, bboxGroundtruth.height);
BoundingBox bbox_gt;
BoundingBox bbox_estimate_uncentered;
bbox_gt.getRect(goturnbbox);
goturntracker.Init(frame, bbox_gt, ®ressor);
#endif
*/
// Create ECO trakcer;
eco::ECO ecotracker;
Rect2f ecobbox(bboxGroundtruth.x, bboxGroundtruth.y, bboxGroundtruth.width, bboxGroundtruth.height);
eco::EcoParameters parameters;
//parameters.max_score_threshhold = 0.1;
// when use cn feature:
parameters.useCnFeature = false;
parameters.cn_features.fparams.tablename = "/usr/local/include/opentracker/eco/look_tables/CNnorm.txt";
//ecotracker.init(frame, ecobbox, parameters);
while (frame.data)
{
frame.copyTo(frameDraw);
key = cvWaitKey(10);
if(key == 's'){
flag = 1;
putText(frameDraw, "!Choose Target!", cv::Point(10, 20), FONT_HERSHEY_SIMPLEX,0.5, Scalar(255, 0, 0), 2);
readvideo.IniRead(bboxGroundtruth, frameDraw, window_name, capture);
Rect2f ecobbox(bboxGroundtruth.x, bboxGroundtruth.y, bboxGroundtruth.width, bboxGroundtruth.height);
ecotracker.init(frame, ecobbox, parameters);
}
else if(key == 'e'){
flag = 0;
}
//Opencv=====================
// double timercv = (double)getTickCount();
// bool okopencv = opencvtracker->update(frame, opencvbbox);
// float fpscv = getTickFrequency() / ((double)getTickCount() - timercv);
// if (okopencv)
// {
// rectangle(frameDraw, opencvbbox, Scalar(255, 0, 0), 2, 1);
// }
// else
// {
// putText(frameDraw, "Opencv tracking failure detected", cv::Point(10, 50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(255, 0, 0), 2);
// }
/* //KCF=========================
double timerkcf = (double)getTickCount();
bool okkcf = kcftracker.update(frame, kcfbbox);
float fpskcf = getTickFrequency() / ((double)getTickCount() - timerkcf);
if (okkcf)
{
rectangle(frameDraw, kcfbbox, Scalar(0, 255, 0), 2, 1);
}
else
{
putText(frameDraw, "Kcf tracking failure detected", cv::Point(10, 80), FONT_HERSHEY_SIMPLEX,
0.75, Scalar(0, 255, 0), 2);
}
//DSST========================
double timerdsst = (double)getTickCount();
bool okdsst = dssttracker.update(frame, dsstbbox);
float fpsdsst = getTickFrequency() / ((double)getTickCount() - timerdsst);
if (okdsst)
{
rectangle(frameDraw, dsstbbox, Scalar(0, 0, 255), 2, 1);
}
else
{
putText(frameDraw, "DSST tracking failure detected", cv::Point(10, 110), FONT_HERSHEY_SIMPLEX,
0.75, Scalar(0, 0, 255), 2);
}
#ifdef USE_CAFFE
//GOTURN=====================
double timergoturn = (double)getTickCount();
goturntracker.Track(frame, ®ressor, &bbox_estimate_uncentered);
bbox_estimate_uncentered.putRect(goturnbbox);
float fpsgoturn = getTickFrequency() / ((double)getTickCount() - timergoturn);
rectangle(frameDraw, goturnbbox, Scalar(255, 255, 0), 2, 1);
#endif
*/
//ECO========================
if(flag){
double timeeco = (double)getTickCount();
bool okeco = ecotracker.update(frame, ecobbox);
float fpseco = getTickFrequency() / ((double)getTickCount() - timeeco);
if (okeco){
rectangle(frameDraw, ecobbox, Scalar(0, 0, 255), 2);
}
else{
putText(frameDraw, "!!!NO Target!!!", cv::Point(10, 50), FONT_HERSHEY_SIMPLEX,
0.5, Scalar(0, 255, 0), 2);
}
// Draw ground truth box===========================================
//readdatasets.DrawGroundTruth(bboxGroundtruth, frameDraw);
// Display FPS on frameDraw
ostringstream os;
os << float(fpseco);
putText(frameDraw, "FPS: " + os.str(), Point(10, 20), FONT_HERSHEY_SIMPLEX,
0.5, Scalar(0, 0, 255), 2);
// Draw the label of trackers
//putText(frameDraw, "Opencv ", cv::Point(frameDraw.cols - 180, 50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(255, 0, 0), 2);
//line(frameDraw, cv::Point(frameDraw.cols - 100, 50), cv::Point(frameDraw.cols - 10, 50), Scalar(255, 0, 0), 2, 1);
// putText(frameDraw, "KCF ", cv::Point(frameDraw.cols - 180, 75), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 255, 0), 2);
// line(frameDraw, cv::Point(frameDraw.cols - 100, 75), cv::Point(frameDraw.cols - 10, 75), Scalar(0, 255, 0), 2, 1);
// putText(frameDraw, "DSST ", cv::Point(frameDraw.cols - 180, 100), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 0, 255), 2);
// line(frameDraw, cv::Point(frameDraw.cols - 100, 100), cv::Point(frameDraw.cols - 10, 100), Scalar(0, 0, 255), 2, 1);
//putText(frameDraw, "ECO ", cv::Point(frameDraw.cols - 180, 125), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(255, 0, 255), 2);
//line(frameDraw, cv::Point(frameDraw.cols - 100, 125), cv::Point(frameDraw.cols - 10, 125), Scalar(255, 0, 255), 2, 1);
#ifdef USE_CAFFE
//putText(frameDraw, "GOTURN ", cv::Point(frameDraw.cols - 180, 150), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(255, 255, 0), 2);
//line(frameDraw, cv::Point(frameDraw.cols - 100, 150), cv::Point(frameDraw.cols - 10, 150), Scalar(255, 255, 0), 2, 1);
#endif
// Display frameDraw.=========================================================
//cvNamedWindow("Tracking", CV_WINDOW_NORMAL);
}
imshow("OpenTracker", frameDraw);
//int c = cvWaitKey(1);
//if (c != -1)
// c = c % 256;
//if (c == 27)
//{
// cvDestroyWindow("OpenTracker");
// return 0;
//}
//waitKey(1);
// Read the next frame
/* Read from dataset */
//readdatasets.ReadNextFrame(bboxGroundtruth, frame);
// Read from video and choose a bbox
capture >> frame;
if (frame.empty())
return false;
}
//#ifdef USE_MULTI_THREAD
void *status;
int rc = pthread_join(ecotracker.thread_train_, &status);
if (rc)
{
cout << "Error:unable to join," << rc << std::endl;
exit(-1);
}
//#endif
cvDestroyWindow("OpenTracker");
return 0;
}
| [
"568314913@qq.com"
] | 568314913@qq.com |
c85e857cd5c2713ac412d20d029ecc6ddb7d3fac | 41311be8620b1e78bc9e74c327f0110ced0663f2 | /src/Scene/Track.h | 80bae276d28551cd4f2cb0e9d09d9b49b6eb79d1 | [
"MIT"
] | permissive | Keiiko/OpenNFS | be2c5b87175aa61da6f9e61d6452b80c9c8cb280 | 9824ca7cb9025346d7d88837ff94d8b06cfdc324 | refs/heads/master | 2020-06-19T05:23:20.645200 | 2019-07-12T13:48:42 | 2019-07-12T13:48:42 | 196,577,315 | 1 | 0 | MIT | 2019-07-12T13:48:43 | 2019-07-12T12:41:03 | C++ | UTF-8 | C++ | false | false | 1,293 | h | #pragma once
#include "Model.h"
class Track : public Model {
public:
Track(std::vector<glm::vec3> verts, std::vector<glm::vec3> norms, std::vector<glm::vec2> uvs, std::vector<unsigned int> texture_indices, std::vector<unsigned int> indices, std::vector<glm::vec4> shading_data, std::vector<uint32_t> debug_data, glm::vec3 center_position);
Track(std::vector<glm::vec3> verts, std::vector<glm::vec2> uvs, std::vector<unsigned int> texture_indices, std::vector<unsigned int> indices, std::vector<glm::vec4> shading_data, glm::vec3 center_position);
Track(std::vector<glm::vec3> verts, std::vector<glm::vec3> norms, std::vector<glm::vec2> uvs, std::vector<unsigned int> texture_indices, std::vector<unsigned int> indices, std::vector<glm::vec4> shading_data, glm::vec3 center_position);
Track();
void update() override;
void destroy() override;
void render() override;
bool genBuffers()override;
std::vector<unsigned int> m_texture_indices;
std::vector<glm::vec4> m_shading_data;
std::vector<uint32_t> m_debug_data;
private:
GLuint vertexbuffer;
GLuint uvbuffer;
GLuint textureIndexBuffer;
GLuint shadingBuffer;
GLuint normalBuffer;
GLuint debugBuffer;
std::vector<glm::vec4> shadingData;
typedef Model super;
};
| [
"AmrikSadhra@gmail.com"
] | AmrikSadhra@gmail.com |
eee45812165d79c8a951e8e9f7b49823b19905f4 | 90129aa5a1de22c859e0b60f462eefe4740c6ab3 | /QtLocationPlugin/GeoTiledMappingManagerEngine.cpp | b89ccef701fc8bea992da05c4cd0a6c0fe3a8a5d | [] | no_license | jasonisnotmyrealname/MapPlginDemo | 91f3fa3631419f2e9e427c493972e6b310de4a9e | 3cad97f1284fd3cbae979126f8201cb186a3698d | refs/heads/master | 2020-03-31T09:23:50.060626 | 2018-10-08T14:45:19 | 2018-10-08T14:45:19 | 152,094,346 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,930 | cpp | #include "MapEngine.h"
#include "GeoTiledMappingManagerEngine.h"
#include "GeoTileFetcher.h"
#include <QtLocation/private/qgeocameracapabilities_p.h>
#include <QtLocation/private/qgeomaptype_p.h>
#if QT_VERSION < 0x050500
#include <QtLocation/private/qgeotiledmapdata_p.h>
#else
#include <QtLocation/private/qgeotiledmap_p.h>
#if QT_VERSION >= 0x050600
#include <QtLocation/private/qgeofiletilecache_p.h>
#else
#include <QtLocation/private/qgeotilecache_p.h>
#endif
#endif
#include <QDir>
#include <QStandardPaths>
#if QT_VERSION >= 0x050500
//-----------------------------------------------------------------------------
GeoTiledMap::GeoTiledMap(QGeoTiledMappingManagerEngine *engine, QObject *parent)
: QGeoTiledMap(engine, parent)
{
}
#endif
//-----------------------------------------------------------------------------
GeoTiledMappingManagerEngine::GeoTiledMappingManagerEngine(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString)
: QGeoTiledMappingManagerEngine()
{
QGeoCameraCapabilities cameraCaps;
cameraCaps.setMinimumZoomLevel(2.0);
cameraCaps.setMaximumZoomLevel(MAX_MAP_ZOOM);
cameraCaps.setSupportsBearing(true);
setCameraCapabilities(cameraCaps);
setTileSize(QSize(256, 256));
setTileFetcher(new GeoTileFetcher(this));
*error = QGeoServiceProvider::NoError;
errorString->clear();
}
//-----------------------------------------------------------------------------
GeoTiledMappingManagerEngine::~GeoTiledMappingManagerEngine()
{
}
#if QT_VERSION < 0x050500
//-----------------------------------------------------------------------------
QGeoMapData *GeoTiledMappingManagerEngine::createMapData()
{
return new QGeoTiledMapData(this, 0);
}
#else
//-----------------------------------------------------------------------------
QGeoMap*
GeoTiledMappingManagerEngine::createMap()
{
return new GeoTiledMap(this);
}
#endif
| [
"jxchao@126.com"
] | jxchao@126.com |
69f5c7abb0d4f606efb2b2a22bb88224e436d298 | 369a6e29e653fc2a3c8b1310941a5bf91d26cfc7 | /malti/object.cpp | 2e83d61c91d23d0ef492ef381c1be351cf1c5942 | [] | no_license | taikiyamaguchi16/syusyokusakuhin | 9559a80dcb8ba652c7493b5080405b232984a984 | 2ea9ade8b1d27b838e7746bd5b1f1ba14df16e21 | refs/heads/main | 2023-01-30T10:22:12.649731 | 2020-10-22T15:51:48 | 2020-10-22T15:51:48 | 304,015,736 | 0 | 0 | null | null | null | null | SHIFT_JIS | C++ | false | false | 12,267 | cpp | #include "object.h"
#include "Scene.h"
#include "UserData.h"
#include "nameof.hpp"
#include "ImGuiControl.h"
#include "CCollider.h"
void CObject::Update()
{
if (SceneManager::GetInstance()->m_fpsCount % (60 / m_myFps) == 0) {
for (const auto& com : m_ComponentList)
com->Update();
}
}
void CObject::LateUpdate()
{
if (SceneManager::GetInstance()->m_fpsCount % (60 / m_myFps) == 0) {
for (const auto& com : m_ComponentList)
com->LateUpdate();
}
}
void CObject::Draw()
{
for (const auto& com : m_ComponentList)
com->Draw();
}
void CTransform::Update()
{
DX11MtxIdentity(m_mat);
XMFLOAT4X4 scaleMatrix;
XMFLOAT4X4 velcityMatrix;
XMFLOAT4X4 rotMatrix;
XMFLOAT4X4 positionMatrix;
DX11MtxScale(m_scale, scaleMatrix);
DX11MtxTranslation(m_trans->p, positionMatrix);
DX11MtxRotation(m_angle, rotMatrix);
//Rigidbodyがついている場合
if (m_rb.IsExist()) {
DX11MtxMultiply(m_mat, scaleMatrix, velcityMatrix, rotMatrix, positionMatrix);
}
else {
DX11MtxMultiply(m_mat, scaleMatrix, rotMatrix, positionMatrix);
}
if (m_rb.IsExist()) {
if (m_rb->GetRigidDynamic() != nullptr || m_rb->GetRigidStatic() != nullptr) {
XMFLOAT4X4 workmat;
//シェイプから行列を取り出す場合はこっち
//PxShape* shapes[128];
////シェイプの数取得
//const PxU32 nbShapes = m_rb->GetActor()->getNbShapes();
//m_rb->GetActor()->getShapes(shapes, nbShapes);
//const PxMat44 shapePose(PxShapeExt::getGlobalPose(*shapes[0], *m_rb->GetActor()));
const PxMat44 shapePose(m_rb->GetActor()->getGlobalPose());
workmat._11 = shapePose.column0.x; workmat._12 = shapePose.column0.y; workmat._13 = shapePose.column0.z; workmat._14 = shapePose.column0.w;
workmat._21 = shapePose.column1.x; workmat._22 = shapePose.column1.y; workmat._23 = shapePose.column1.z; workmat._24 = shapePose.column1.w;
workmat._31 = shapePose.column2.x; workmat._32 = shapePose.column2.y; workmat._33 = shapePose.column2.z; workmat._34 = shapePose.column2.w;
workmat._41 = shapePose.column3.x; workmat._42 = shapePose.column3.y; workmat._43 = shapePose.column3.z; workmat._44 = shapePose.column3.w;
//スケール分かける
DX11MtxMultiply(m_mat, scaleMatrix, workmat);
//QuaternionToEulerAngles(m_angle, m_trans->q.getNormalized());
}
else {
}
}
//座標の仮決定
m_trans->p.x = m_mat._41;
m_trans->p.y = m_mat._42;
m_trans->p.z = m_mat._43;
//親がいた場合
if (m_parent != nullptr) {
DX11MtxMultiply(m_mat, m_mat, m_parent->m_mat);
}
}
void CTransform::LateUpdate()
{
//座標の仮決定
m_trans->p.x = m_mat._41;
m_trans->p.y = m_mat._42;
m_trans->p.z = m_mat._43;
XMFLOAT3 _scale;
XMFLOAT3 _vec = XMFLOAT3(m_mat._11, m_mat._12, m_mat._13);
DX11Vec3Length(_vec, _scale.x);
_vec = XMFLOAT3(m_mat._21, m_mat._22, m_mat._23);
DX11Vec3Length(_vec, _scale.y);
_vec = XMFLOAT3(m_mat._31, m_mat._32, m_mat._33);
DX11Vec3Length(_vec, _scale.z);
m_scale = _scale;
}
void CTransform::MoveForward(XMFLOAT3 vec_)
{
DX11MtxIdentity(m_mat);
XMFLOAT4X4 scaleMatrix;
XMFLOAT4X4 velcityMatrix;
XMFLOAT4X4 rotMatrix;
XMFLOAT4X4 positionMatrix;
DX11MtxScale(m_scale, scaleMatrix);
DX11MtxTranslation(m_trans->p, positionMatrix);
DX11MtxRotation(m_angle, rotMatrix);
DX11MtxTranslation(vec_, velcityMatrix);
DX11MtxMultiply(m_mat, scaleMatrix, velcityMatrix, rotMatrix, positionMatrix);
m_trans->p.x = m_mat._41;
m_trans->p.y = m_mat._42;
m_trans->p.z = m_mat._43;
}
void CTransform::Draw()
{
//座標の最終決定
m_trans->p.x = m_mat._41;
m_trans->p.y = m_mat._42;
m_trans->p.z = m_mat._43;
// ワールド変換行列
DX11SetTransform::GetInstance()->SetTransform(DX11SetTransform::TYPE::WORLD, m_mat);
}
void CTransform::Rotation(XMFLOAT4X4 & rotateMat_)
{
XMFLOAT4 axisX;
XMFLOAT4 axisY;
XMFLOAT4 axisZ;
// X軸を取り出す
axisX.x = rotateMat_._11;
axisX.y = rotateMat_._12;
axisX.z = rotateMat_._13;
axisX.w = 0.0f;
// Y軸を取り出す
axisY.x = rotateMat_._21;
axisY.y = rotateMat_._22;
axisY.z = rotateMat_._23;
axisY.w = 0.0f;
// Z軸を取り出す
axisZ.x = rotateMat_._31;
axisZ.y = rotateMat_._32;
axisZ.z = rotateMat_._33;
axisZ.w = 0.0f;
XMFLOAT4 qt; // クオータニオン
// 行列からクオータニオンを生成
DX11GetQtfromMatrix(rotateMat_, qt);
XMFLOAT4 qtx, qty, qtz; // クオータニオン
// 指定軸回転のクオータニオンを生成
DX11QtRotationAxis(qtx, axisX, m_angle.x);
DX11QtRotationAxis(qty, axisY, m_angle.y);
DX11QtRotationAxis(qtz, axisZ, m_angle.z);
// クオータニオンを合成
XMFLOAT4 tempqt1;
DX11QtMul(tempqt1, qt, qtx);
XMFLOAT4 tempqt2;
DX11QtMul(tempqt2, qty, qtz);
XMFLOAT4 tempqt3;
DX11QtMul(tempqt3, tempqt1, tempqt2);
// クオータニオンをノーマライズ
DX11QtNormalize(tempqt3, tempqt3);
// クオータニオンから行列を作成
DX11MtxFromQt(rotateMat_, tempqt3);
// 行列からクオータニオンを生成
DX11GetQtfromMatrix(rotateMat_, qt);
// クオータニオンをノーマライズ
DX11QtNormalize(qt, qt);
m_trans->q = physx::PxQuat(qt.x, qt.y, qt.z, qt.w);
}
void CTransform::Rotation(XMFLOAT3 _angle)
{
physx::PxTransform _p = m_rb->GetRigidDynamic()->getGlobalPose();
physx::PxQuat _q;
//EulerAnglesToQuaternion();
EulerAnglesToQuaternion(_q, _angle);
m_trans->q = _q * _p.q;
m_trans->q.normalize();
m_rb->GetActor()->setGlobalPose(physx::PxTransform(GetPhysXPos(), physx::PxQuat(m_trans->q.x, m_trans->q.y, m_trans->q.z, m_trans->q.w)));
}
void CTransform::ImGuiDraw()
{
ImGui::DragFloat3(u8"座標", &m_trans->p.x, true);
ImGui::DragFloat3(u8"角度", &m_angle.x, true);
//if (m_rb != nullptr) {
if(m_rb.IsExist()){
if (m_rb->GetRigidDynamic() != nullptr) {
XMFLOAT4X4 rot;
DX11MtxIdentity(rot);
Rotation(rot);
m_rb->GetActor()->setGlobalPose(physx::PxTransform(GetPhysXPos(), physx::PxQuat(m_trans->q.x, m_trans->q.y, m_trans->q.z, m_trans->q.w)),true);
}
}
ImGui::DragFloat3(u8"サイズ", &m_scale.x, true);
ImGuiControl::GetInstance()->Select3DGuizm();
/*auto str = FilterGroup::eENEMY;
std::string sss = (std::string)NAMEOF_ENUM(str);
ImGui::Text(sss.c_str());*/
}
void CTransform::SetQuat(XMFLOAT4X4 & rotateMat_)
{
XMFLOAT4 axisX;
XMFLOAT4 axisY;
XMFLOAT4 axisZ;
// X軸を取り出す
XMFLOAT4 qt; // クオータニオン
// 行列からクオータニオンを生成
DX11GetQtfromMatrix(rotateMat_, qt);
// クオータニオンをノーマライズ
DX11QtNormalize(qt, qt);
// クオータニオンから行列を作成
//DX11MtxFromQt(rotateMat_, tempqt3);
if (m_rb.IsExist()) {
if (m_rb->GetRigidDynamic() != NULL) {
m_trans->q = physx::PxQuat(qt.x, qt.y, qt.z, qt.w);
}
}
}
CRigidbody::~CRigidbody()
{
CPhysx::DeleteActor(m_actor);
m_actor->release();
m_material->release();
}
void CRigidbody::Start()
{
m_usegravity = true;
m_transform = Holder->GetWeakComponent<CTransform>();
wp<CRigidbody>wark_wp = Holder->GetWeakComponent<CRigidbody>();
m_transform->SetRigidbody(wark_wp);
m_name = "Rigidbody";
}
void CRigidbody::InitDynamic()
{
m_material = CPhysx::GetPhysics()->createMaterial(0.5f, 0.5f, 0.f);
//physx::PxVec3 boxSize = physx::PxVec3(1.f, 1.f, 1.f);
physx::PxVec3 boxSize = m_transform->GetScale();
CCollider* col;
switch (m_geometryType)
{
case GEOMETRYTYPE::BOX:
m_rigidDynamic = CPhysx::createDynamic(physx::PxTransform(Holder->GetComponent<CTransform>()->GetPhysXPos()),
physx::PxBoxGeometry(boxSize /2.f),
m_material);
CPhysx::SetActor(m_rigidDynamic);
m_rigidDynamic->setMass(m_mass);
//========-こいつらつけるといい感じなる(回転とかが)なんでかは不明
m_rigidDynamic->setMassSpaceInertiaTensor(PxVec3(0.f));
m_rigidDynamic->setMassSpaceInertiaTensor(PxVec3(1.f, 1.f, 1.f));
m_actor = CPhysx::GetActor();
m_rigidDynamic->setAngularDamping(0.4f);
//m_rigidDynamic->setAngularVelocity(physx::PxVec3(0, 0, 1.f));
//大きさにあったコライダーの取り付け
col = Holder->AddComponent<CBoxCollider>();
col->Init();
break;
case GEOMETRYTYPE::CAPSILE:
break;
case GEOMETRYTYPE::SPHERE:
m_rigidDynamic = CPhysx::createDynamic(physx::PxTransform(Holder->GetComponent<CTransform>()->GetPhysXPos()),
physx::PxSphereGeometry(boxSize.x),
m_material);
CPhysx::SetActor(m_rigidDynamic);
m_rigidDynamic->setMass(m_mass);
m_rigidDynamic->setMassSpaceInertiaTensor(PxVec3(1.f, 1.f, 1.f));
m_actor = CPhysx::GetActor();
m_rigidDynamic->setAngularDamping(0.4f);
//m_rigidDynamic->setAngularVelocity(physx::PxVec3(0, 0, 0.1f));
col = Holder->AddComponent<CSphereCollider>();
col->Init();
break;
default:
break;
}
m_actor->setActorFlag(physx::PxActorFlag::eVISUALIZATION, false);
USERDATA* use = new USERDATA();
use->obj = Holder;
m_actor->userData = use;
}
void CRigidbody::InitStatic()
{
m_material = CPhysx::GetPhysics()->createMaterial(0.5f, 0.5f, 0.0f);
//physx::PxVec3 boxSize = physx::PxVec3(1.f, 1.f, 1.f);
physx::PxVec3 boxSize = m_transform->GetScale();
CCollider* col;
PxRigidBody* atta;
switch (m_geometryType)
{
case GEOMETRYTYPE::BOX:
m_rigidStatic = CPhysx::createStatic(physx::PxTransform(Holder->GetComponent<CTransform>()->GetPhysXPos()),
physx::PxBoxGeometry(boxSize / 2.0f),
m_material);
CPhysx::SetActor(m_rigidStatic);
m_actor = CPhysx::GetStaticActor();
col = Holder->AddComponent<CBoxCollider>();
col->Init();
break;
case GEOMETRYTYPE::CAPSILE:
break;
case GEOMETRYTYPE::SPHERE:
m_rigidStatic = CPhysx::createStatic(physx::PxTransform(Holder->GetComponent<CTransform>()->GetPhysXPos()),
physx::PxSphereGeometry(boxSize.x),
m_material);
CPhysx::SetActor(m_rigidStatic);
m_actor = CPhysx::GetStaticActor();
col = Holder->AddComponent<CSphereCollider>();
col->Init();
break;
default:
break;
}
m_actor->setActorFlag(physx::PxActorFlag::eVISUALIZATION, false);
m_actor->userData = new USERDATA();
}
void CRigidbody::Update()
{
if (m_rigidDynamic != nullptr) {
//m_rigidDynamic->setAngularVelocity(physx::PxVec3(0, 0, 1.f));
m_rigidDynamic->wakeUp();
}
}
void CRigidbody::LateUpdate()
{
if (m_rigidDynamic != nullptr) {
//QuaternionToEulerAngles();
CTransform* _tra = Holder->GetComponent<CTransform>();
_tra->GetTrans().q = m_rigidDynamic->getGlobalPose().q;
physx::PxQuat _q = m_rigidDynamic->getGlobalPose().q;
m_actor->setGlobalPose(physx::PxTransform(_tra->GetPhysXPos(), physx::PxQuat(_q.x, _q.y, _q.z, _q.w)), true);
}
}
void CRigidbody::ImGuiDraw()
{
if (ImGui::Checkbox(u8"重力適用", &m_usegravity)) {
m_actor->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, !m_usegravity);
//速度0に
m_rigidDynamic->setLinearVelocity(physx::PxVec3(0, 0, 0));
m_rigidDynamic->setAngularVelocity(physx::PxVec3(0, 0, 0));
}
if (m_rigidDynamic != NULL) {
physx::PxVec3 speed = m_rigidDynamic->getLinearVelocity();
ImGui::Text(u8"速度 x:%.3f y:%.3f z:%.3f", speed.x, speed.y, speed.z);
speed = m_rigidDynamic->getAngularVelocity();
ImGui::Text(u8"角速度 x:%.3f y:%.3f z:%.3f", speed.x, speed.y, speed.z);
}
if (ImGui::Checkbox(u8"トリガーにする", &m_trigger)) {
if (m_trigger) {
PxShape* shapes[128];
//シェイプの数取得
const PxU32 nbShapes = m_actor->getNbShapes();
m_actor->getShapes(shapes, nbShapes);
physx::PxShape* _shape;
for (PxU32 i = 0; i < nbShapes; i++)
{
m_actor->getShapes(&_shape, i+1);
_shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false);
_shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true);
}
}
else {
PxShape* shapes[128];
//シェイプの数取得
const PxU32 nbShapes = m_actor->getNbShapes();
m_actor->getShapes(shapes, nbShapes);
physx::PxShape* _shape;
for (PxU32 i = 0; i < nbShapes; i++)
{
m_actor->getShapes(&_shape, i+1);
_shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, false);
_shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, true);
}
}
}
if (ImGui::Checkbox(u8"シミュレーションする", &m_simulation))
{
m_actor->setActorFlag(PxActorFlag::eDISABLE_SIMULATION, !m_simulation);
}
for (FilterGroup::Layer num : {FilterGroup::eDEFAULT, FilterGroup::eENEMY, FilterGroup::eFLOOR, FilterGroup::ePLAYER}) {
}
}
| [
"taikitpmiita@icloud.com"
] | taikitpmiita@icloud.com |
a511a214082dc7c07dc0b2c4a64dfe8ebed4ca40 | 838dc19e767fcc83913489a4a7662e89ce3fa510 | /game/code/common/engine/system/variable.hpp | a07c9696fc830d96adcf435e40cb9fe8ac6e14bc | [
"MIT"
] | permissive | justinctlam/MarbleStrike | b757df8c7f7b5961d87fd5f9b5c59e6af777e70e | 64fe36a5a4db2b299983b0e2556ab1cd8126259b | refs/heads/master | 2020-09-13T23:49:12.139990 | 2016-09-04T04:02:50 | 2016-09-04T04:02:50 | 67,262,851 | 0 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 809 | hpp | #ifndef VARIABLE_HPP
#define VARIABLE_HPP
//////////////////////////////////////////////////////
// INCLUDES
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// FORWARD DECLARATIONS
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// CLASSES
//////////////////////////////////////////////////////
class Variable
{
public:
enum VariableType
{
VariableType_Int,
VariableType_Float,
VariableType_Bool
};
public:
Variable( VariableType type );
virtual ~Variable();
VariableType GetVariableType();
private:
VariableType mVariableType;
};
#endif
| [
"justin.t.lam@gmail.com"
] | justin.t.lam@gmail.com |
4646651cd308cda4d11af0bfe1342f34e733071f | fa87c63b0bf4798f9d2efe09e7b325082c134c75 | /winui/tsf/tsfapp/tsfedit.cpp | fc99ed8baae9fcada3f1fffe5e67407b4b923eb5 | [
"MIT"
] | permissive | khangthk/tsf-sample-ime-win7 | febb85b3215040c3dbe82ead79a43d5ce7224d46 | 7e0bd994a7d431f946ffbc005cabe4b135c02386 | refs/heads/master | 2023-03-17T09:49:07.168600 | 2020-11-08T08:57:28 | 2020-11-08T08:57:28 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 55,122 | cpp | /**************************************************************************
THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright 2001 Microsoft Corporation. All Rights Reserved.
**************************************************************************/
/**************************************************************************
File: TSFEdit.cpp
Description: CTSFEditWnd Class Implementation
**************************************************************************/
/**************************************************************************
#include statements
**************************************************************************/
#include "TSFEdit.h"
#include "Globals.h"
#include <ctffunc.h>
/*
None of the GUIDs in TSATTRS.H are defined in a LIB, so you have to include
INITGUID.H just before the first time you include TSATTRS.H
*/
#include <initguid.h>
#include <tsattrs.h>
#include <tchar.h>
/**************************************************************************
local function prototypes
**************************************************************************/
/**************************************************************************
global variables and definitions
**************************************************************************/
TCHAR g_szTSFEditClassName[] = TEXT("TSFEditWndClass");
#define THIS_POINTER_OFFSET GWLP_USERDATA
//#define USE_ASSOC_FOCUS
/**************************************************************************
CTSFEditWnd::CTSFEditWnd()
**************************************************************************/
CTSFEditWnd::CTSFEditWnd(HINSTANCE hInstance, HWND hwndParent)
{
m_hWnd = NULL;
m_hwndEdit = NULL;
m_hwndStatus = NULL;
m_hInst = hInstance;
m_ObjRefCount = 1;
m_hwndParent = hwndParent;
m_pThreadMgr = NULL;
m_pDocMgr = NULL;
m_pPrevDocMgr = NULL;
m_pContext = NULL;
m_fLocked = FALSE;
m_dwLockType = 0;
m_fPendingLockUpgrade = FALSE;
m_acpStart = 0;
m_acpEnd = 0;
m_fInterimChar = FALSE;
m_ActiveSelEnd = TS_AE_START;
m_pServices = NULL;
m_cCompositions = 0;
m_pCategoryMgr = NULL;
m_pDisplayAttrMgr = NULL;
m_fLayoutChanged = FALSE;
m_fNotify = TRUE;
m_cchOldLength = 0;
ZeroMemory(&m_AdviseSink, sizeof(m_AdviseSink));
ZeroMemory(&m_rgCompositions, sizeof(m_rgCompositions));
}
/**************************************************************************
CTSFEditWnd::~CTSFEditWnd()
**************************************************************************/
CTSFEditWnd::~CTSFEditWnd()
{
/*
Make sure the advise sink is cleaned up. This should have been done
before, but this is just in case.
*/
_ClearAdviseSink(&m_AdviseSink);
if(m_pServices)
{
m_pServices->Release();
m_pServices = NULL;
}
_Uninitialize();
}
/**************************************************************************
CTSFEditWnd::_Initialize()
**************************************************************************/
BOOL CTSFEditWnd::_Initialize(ITfThreadMgr *ptm, TfClientId tfcId)
{
HRESULT hr;
InitCommonControls();
m_tfClientID = tfcId;
hr = ptm->QueryInterface(IID_ITfThreadMgr, (LPVOID*)&m_pThreadMgr);
if(FAILED(hr))
{
return FALSE;
}
hr = CoCreateInstance( CLSID_TF_CategoryMgr,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITfCategoryMgr,
(LPVOID*)&m_pCategoryMgr);
if(FAILED(hr))
{
return FALSE;
}
//create the display attribute manager
hr = CoCreateInstance( CLSID_TF_DisplayAttributeMgr,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITfDisplayAttributeMgr,
(LPVOID*)&m_pDisplayAttrMgr);
if(FAILED(hr))
{
return FALSE;
}
//create the document manager
hr = m_pThreadMgr->CreateDocumentMgr(&m_pDocMgr);
if(FAILED(hr))
{
return FALSE;
}
//create the context
hr = m_pDocMgr->CreateContext( tfcId,
0,
(ITextStoreACP*)this,
&m_pContext,
&m_EditCookie);
if(FAILED(hr))
{
return FALSE;
}
//push the context onto the document stack
hr = m_pDocMgr->Push(m_pContext);
if(FAILED(hr))
{
return FALSE;
}
WNDCLASS wc;
//If the class is not already registered, register it.
if(!GetClassInfo(m_hInst, g_szTSFEditClassName, &wc))
{
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = CTSFEditWnd::_WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(CTSFEditWnd*);
wc.hInstance = m_hInst;
wc.hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_MAIN_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN_MENU);
wc.lpszClassName = g_szTSFEditClassName;
if(0 == RegisterClass(&wc))
{
return FALSE;
}
}
//create the main window
m_hWnd = CreateWindowEx( 0,
g_szTSFEditClassName,
NULL,
WS_OVERLAPPED |
WS_CHILD |
WS_VISIBLE |
WS_TABSTOP,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
m_hwndParent,
NULL,
m_hInst,
(LPVOID)this);
if(NULL != m_hWnd)
{
m_hwndEdit = CreateWindowEx( WS_EX_CLIENTEDGE,
TEXT("edit"),
NULL,
WS_CLIPSIBLINGS |
WS_CHILD |
WS_VISIBLE |
WS_BORDER |
WS_VSCROLL |
ES_AUTOVSCROLL |
ES_MULTILINE,
0, 0, 0, 0,
m_hWnd,
(HMENU)IDC_EDIT,
m_hInst,
NULL);
if(NULL == m_hwndEdit)
{
return FALSE;
}
//create the status bar
m_hwndStatus = CreateStatusWindow( WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
NULL,
m_hWnd,
IDC_STATUSBAR);
if(m_hwndStatus)
{
_UpdateStatusBar();
}
#ifdef USE_ASSOC_FOCUS
/*
Associate the focus with this window. The TSF Manager watches for
focus changes throughout the system. When a window handle that has
been associated gets the focus, it then knows the window receiving
the focus is TSF enabled.
*/
hr = m_pThreadMgr->AssociateFocus(m_hwndEdit, m_pDocMgr, &m_pPrevDocMgr);
#endif
//initialize the supported attributes
TfGuidAtom guidatom;
//mode bias
m_rgAttributes[ATTR_INDEX_MODEBIAS].dwFlags = 0;
m_rgAttributes[ATTR_INDEX_MODEBIAS].attrid = &GUID_PROP_MODEBIAS;
VariantInit(&(m_rgAttributes[ATTR_INDEX_MODEBIAS].varValue));
hr = m_pCategoryMgr->RegisterGUID(GUID_MODEBIAS_NONE, &guidatom);
if(FAILED(hr))
{
guidatom = TF_INVALID_GUIDATOM;
}
m_rgAttributes[ATTR_INDEX_MODEBIAS].varDefaultValue.vt = VT_I4;
m_rgAttributes[ATTR_INDEX_MODEBIAS].varDefaultValue.lVal = guidatom;
//text orientation - this is a VT_I4 that is always zero in this app
m_rgAttributes[ATTR_INDEX_TEXT_ORIENTATION].dwFlags = 0;
m_rgAttributes[ATTR_INDEX_TEXT_ORIENTATION].attrid = &TSATTRID_Text_Orientation;
VariantInit(&m_rgAttributes[ATTR_INDEX_TEXT_ORIENTATION].varValue);
m_rgAttributes[ATTR_INDEX_TEXT_ORIENTATION].varDefaultValue.vt = VT_I4;
m_rgAttributes[ATTR_INDEX_TEXT_ORIENTATION].varDefaultValue.lVal = 0;
//vertical writing - this is a VT_BOOL that is always FALSE in this app
m_rgAttributes[ATTR_INDEX_TEXT_VERTICALWRITING].dwFlags = 0;
m_rgAttributes[ATTR_INDEX_TEXT_VERTICALWRITING].attrid = &TSATTRID_Text_VerticalWriting;
VariantInit(&m_rgAttributes[ATTR_INDEX_TEXT_VERTICALWRITING].varValue);
m_rgAttributes[ATTR_INDEX_TEXT_VERTICALWRITING].varDefaultValue.vt = VT_BOOL;
m_rgAttributes[ATTR_INDEX_TEXT_VERTICALWRITING].varDefaultValue.lVal = FALSE;
_InitFunctionProvider();
UpdateWindow(m_hWnd);
return TRUE;
}
return FALSE;
}
/**************************************************************************
CTSFEditWnd::_Uninitialize()
**************************************************************************/
void CTSFEditWnd::_Uninitialize()
{
if(m_pThreadMgr)
{
_UninitFunctionProvider();
#ifdef USE_ASSOC_FOCUS
ITfDocumentMgr *pTempDocMgr = NULL;
/*
Its okay if m_pPrevDocMgr is NULL as this will just disassociate the
focus from the window.
*/
m_pThreadMgr->AssociateFocus(m_hwndEdit, m_pPrevDocMgr, &pTempDocMgr);
if(pTempDocMgr)
{
pTempDocMgr->Release();
}
if(m_pPrevDocMgr)
{
m_pPrevDocMgr->Release();
m_pPrevDocMgr = NULL;
}
#endif
int i;
for (i = 0; i < NUM_SUPPORTED_ATTRS; i++)
{
VariantClear(&m_rgAttributes[i].varValue);
VariantClear(&m_rgAttributes[i].varDefaultValue);
m_rgAttributes[i].dwFlags = ATTR_FLAG_NONE;
}
if(m_pDocMgr)
{
//pop all of the contexts off of the stack
m_pDocMgr->Pop(TF_POPF_ALL);
m_pDocMgr->Release();
m_pDocMgr = NULL;
}
if(m_pDisplayAttrMgr)
{
m_pDisplayAttrMgr->Release();
m_pDisplayAttrMgr = NULL;
}
if(m_pContext)
{
m_pContext->Release();
m_pContext = NULL;
}
if(m_pCategoryMgr)
{
m_pCategoryMgr->Release();
m_pCategoryMgr = NULL;
}
m_pThreadMgr->Release();
m_pThreadMgr = NULL;
}
}
/**************************************************************************
CTSFEditWnd::_GetWindow()
**************************************************************************/
HWND CTSFEditWnd::_GetWindow()
{
return m_hWnd;
}
/**************************************************************************
CTSFEditWnd::_OnGetPreservedKey()
**************************************************************************/
HRESULT CTSFEditWnd::_OnGetPreservedKey()
{
HRESULT hr;
ITfKeystrokeMgr *pKeyMgr;
hr = m_pThreadMgr->QueryInterface(IID_ITfKeystrokeMgr, (LPVOID*)&pKeyMgr);
if(SUCCEEDED(hr))
{
GUID guid;
TF_PRESERVEDKEY tfPreKey;
tfPreKey.uVKey = 'F';
tfPreKey.uModifiers = TF_MOD_CONTROL;
hr = pKeyMgr->GetPreservedKey(m_pContext, &tfPreKey, &guid);
if(SUCCEEDED(hr) && !IsEqualGUID(guid, GUID_NULL))
{
BOOL fPreserved;
hr = pKeyMgr->IsPreservedKey(guid, &tfPreKey, &fPreserved);
BOOL fEaten;
guid.Data1 = 12;
hr = pKeyMgr->SimulatePreservedKey(m_pContext, guid, &fEaten);
}
pKeyMgr->Release();
}
return S_OK;
}
/**************************************************************************
CTSFEditWnd::_WndProc()
**************************************************************************/
LRESULT CALLBACK CTSFEditWnd::_WndProc( HWND hWnd,
UINT uMessage,
WPARAM wParam,
LPARAM lParam)
{
CTSFEditWnd *pThis = (CTSFEditWnd*)GetWindowLongPtr(hWnd, THIS_POINTER_OFFSET);
if((NULL == pThis) && (uMessage != WM_NCCREATE))
{
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
switch (uMessage)
{
case WM_NCCREATE:
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
pThis = (CTSFEditWnd*)(lpcs->lpCreateParams);
SetWindowLongPtr(hWnd, THIS_POINTER_OFFSET, (LONG_PTR)pThis);
//set the window handle
pThis->m_hWnd = hWnd;
/*
AddRef() the object. Release() will be called in WM_NCDESTROY.
Many owners will call Release during their WM_DESTROY, but the
child window isn't destroyed until after the parent, so the object
gets deleted while the window still exists. Calling Release()
ourselves in WM_NCDESTROY ensures the object exists for the entire
life of the window.
*/
pThis->AddRef();
}
break;
case WM_CREATE:
return pThis->_OnCreate();
case WM_SIZE:
return pThis->_OnSize(wParam, lParam);
case WM_DESTROY:
return pThis->_OnDestroy();
case WM_SETFOCUS:
return pThis->_OnSetFocus();
case WM_KILLFOCUS:
return pThis->_OnKillFocus();
case WM_COMMAND:
return pThis->_OnCommand( GET_WM_COMMAND_ID(wParam, lParam),
GET_WM_COMMAND_CMD(wParam, lParam),
GET_WM_COMMAND_HWND(wParam, lParam));
case WM_NCDESTROY:
pThis->Release();
pThis->m_hWnd = NULL;
break;
}
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
/**************************************************************************
CTSFEditWnd::_OnCreate()
**************************************************************************/
LRESULT CTSFEditWnd::_OnCreate(VOID)
{
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnDestroy()
**************************************************************************/
LRESULT CTSFEditWnd::_OnDestroy(VOID)
{
_Uninitialize();
PostQuitMessage(0);
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnCommand()
**************************************************************************/
LRESULT CTSFEditWnd::_OnCommand(WORD wID, WORD wCmd, HWND hWnd)
{
switch(wID)
{
case IDC_EDIT:
switch(wCmd)
{
case EN_SETFOCUS:
_OnEditSetFocus();
break;
case EN_KILLFOCUS:
_OnEditKillFocus();
break;
case EN_CHANGE:
_OnEditChange();
break;
}
break;
}
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnSetFocus()
**************************************************************************/
LRESULT CTSFEditWnd::_OnSetFocus(VOID)
{
OutputDebugString(TEXT("CTSFEditWnd::_OnSetFocus\n"));
SetFocus(m_hwndEdit);
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnEditSetFocus()
**************************************************************************/
LRESULT CTSFEditWnd::_OnEditSetFocus(VOID)
{
OutputDebugString(TEXT("CTSFEditWnd::_OnEditSetFocus\n"));
#ifndef USE_ASSOC_FOCUS
m_pThreadMgr->SetFocus(m_pDocMgr);
#endif
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnEditChange()
**************************************************************************/
LRESULT CTSFEditWnd::_OnEditChange(void)
{
if(m_fNotify && m_AdviseSink.pTextStoreACPSink && (m_AdviseSink.dwMask & TS_AS_TEXT_CHANGE))
{
DWORD dwFlags;
TS_TEXTCHANGE tc;
ULONG cch;
cch = GetWindowTextLength(m_hwndEdit);
/*
dwFlags can be 0 or TS_TC_CORRECTION
*/
dwFlags = 0;
tc.acpStart = 0;
tc.acpOldEnd = m_cchOldLength;
tc.acpNewEnd = cch;
m_AdviseSink.pTextStoreACPSink->OnTextChange(dwFlags, &tc);
m_cchOldLength = cch;
}
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnKillFocus()
**************************************************************************/
LRESULT CTSFEditWnd::_OnKillFocus(VOID)
{
OutputDebugString(TEXT("CTSFEditWnd::_OnKillFocus\n"));
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnEditKillFocus()
**************************************************************************/
LRESULT CTSFEditWnd::_OnEditKillFocus(VOID)
{
OutputDebugString(TEXT("CTSFEditWnd::_OnEditKillFocus\n"));
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnNotify()
**************************************************************************/
LRESULT CTSFEditWnd::_OnNotify(UINT, LPNMHDR)
{
return 0;
}
/**************************************************************************
CTSFEditWnd::_OnSize()
**************************************************************************/
LRESULT CTSFEditWnd::_OnSize(WPARAM wParam, LPARAM lParam)
{
//adjust the size and location of the status bar
SendMessage(m_hwndStatus, WM_SIZE, wParam, lParam);
RECT rc;
GetWindowRect(m_hwndStatus, &rc);
MoveWindow( m_hwndEdit,
0,
0,
LOWORD(lParam),
HIWORD(lParam) - (rc.bottom - rc.top),
TRUE);
m_AdviseSink.pTextStoreACPSink->OnLayoutChange(TS_LC_CHANGE, EDIT_VIEW_COOKIE);
return 0;
}
/**************************************************************************
CTSFEditWnd::_IsLocked()
**************************************************************************/
BOOL CTSFEditWnd::_IsLocked(DWORD dwLockType)
{
if(m_dwInternalLockType)
{
return TRUE;
}
return m_fLocked && (m_dwLockType & dwLockType);
}
/**************************************************************************
CTSFEditWnd::_ClearAdviseSink()
**************************************************************************/
HRESULT CTSFEditWnd::_ClearAdviseSink(PADVISE_SINK pAdviseSink)
{
if(pAdviseSink->punkID)
{
pAdviseSink->punkID->Release();
pAdviseSink->punkID = NULL;
}
if(pAdviseSink->pTextStoreACPSink)
{
pAdviseSink->pTextStoreACPSink->Release();
pAdviseSink->pTextStoreACPSink = NULL;
}
pAdviseSink->dwMask = 0;
return S_OK;
}
/**************************************************************************
CTSFEditWnd::_LockDocument()
**************************************************************************/
BOOL CTSFEditWnd::_LockDocument(DWORD dwLockFlags)
{
if(m_fLocked)
{
return FALSE;
}
m_fLocked = TRUE;
m_dwLockType = dwLockFlags;
return TRUE;
}
/**************************************************************************
CTSFEditWnd::_InternalLockDocument()
**************************************************************************/
BOOL CTSFEditWnd::_InternalLockDocument(DWORD dwLockFlags)
{
m_dwInternalLockType = dwLockFlags;
return TRUE;
}
/**************************************************************************
CTSFEditWnd::_UnlockDocument
**************************************************************************/
void CTSFEditWnd::_UnlockDocument()
{
HRESULT hr;
m_fLocked = FALSE;
m_dwLockType = 0;
//if there is a pending lock upgrade, grant it
if(m_fPendingLockUpgrade)
{
m_fPendingLockUpgrade = FALSE;
RequestLock(TS_LF_READWRITE, &hr);
}
//if any layout changes occurred during the lock, notify the manager
if(m_fLayoutChanged)
{
m_fLayoutChanged = FALSE;
m_AdviseSink.pTextStoreACPSink->OnLayoutChange(TS_LC_CHANGE, EDIT_VIEW_COOKIE);
}
}
/**************************************************************************
CTSFEditWnd::_InternalUnlockDocument()
**************************************************************************/
void CTSFEditWnd::_InternalUnlockDocument()
{
m_dwInternalLockType = 0;
}
/**************************************************************************
CTSFEditWnd::_GetCurrentSelection()
**************************************************************************/
BOOL CTSFEditWnd::_GetCurrentSelection(void)
{
//get the selection from the edit control
::SendMessage(m_hwndEdit, EM_GETSEL, (WPARAM)&m_acpStart, (LPARAM)&m_acpEnd);
return TRUE;
}
/**************************************************************************
CTSFEditWnd::_OnUpdate()
**************************************************************************/
void CTSFEditWnd::_OnUpdate(void)
{
//something changed, but it is not known what specifically changed
//just update the status bar
_UpdateStatusBar();
}
/**************************************************************************
CTSFEditWnd::_UpdateStatusBar()
**************************************************************************/
void CTSFEditWnd::_UpdateStatusBar(void)
{
int nParts[2];
HDC hdc;
HFONT hFont;
SIZE size;
TCHAR szComposition[MAX_PATH];
hdc = GetDC(m_hwndStatus);
hFont = (HFONT)SendMessage(m_hwndStatus, WM_GETFONT, 0, 0);
hFont = (HFONT)SelectObject(hdc, hFont);
if(m_cCompositions)
{
_tcscpy_s(szComposition, ARRAYSIZE(szComposition), TEXT("In Composition"));
}
else
{
_tcscpy_s(szComposition, ARRAYSIZE(szComposition), TEXT("No Composition"));
}
GetTextExtentPoint32(hdc, szComposition, lstrlen(szComposition), &size);
nParts[0] = size.cx + (GetSystemMetrics(SM_CXEDGE) * 4);
nParts[1] = -1;
SendMessage(m_hwndStatus, SB_SIMPLE, FALSE, 0);
SendMessage(m_hwndStatus, SB_SETPARTS, ARRAYSIZE(nParts), (LPARAM)nParts);
SendMessage(m_hwndStatus, SB_SETTEXT, 0, (LPARAM)szComposition);
SendMessage(m_hwndStatus, SB_SETTEXT, 1, (LPARAM)TEXT(""));
//reset the DC
SelectObject(hdc, hFont);
ReleaseDC(m_hwndStatus, hdc);
//enable/disable the menu items as necessary
HMENU hMenu = GetMenu(m_hwndParent);
if(NULL != hMenu)
{
}
}
/**************************************************************************
CTSFEditWnd::_OnInitMenuPopup()
**************************************************************************/
LRESULT CTSFEditWnd::_OnInitMenuPopup(WPARAM wParam, LPARAM lParam)
{
HMENU hMenu = (HMENU)wParam;
if(NULL != hMenu)
{
EnableMenuItem(hMenu, IDM_TERMINATE_COMPOSITION, m_cCompositions ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
EnableMenuItem(hMenu, IDM_RECONVERT, _CanReconvertSelection() ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
EnableMenuItem(hMenu, IDM_PLAYBACK, _CanPlaybackSelection() ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
EnableMenuItem(hMenu, IDM_LOAD, !_IsLocked(TS_LF_READ) ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
}
return 0;
}
/**************************************************************************
CTSFEditWnd::_ClearRequestedAttributes()
**************************************************************************/
void CTSFEditWnd::_ClearRequestedAttributes(void)
{
int i;
for (i = 0; i < NUM_SUPPORTED_ATTRS; i++)
{
VariantClear(&m_rgAttributes[i].varValue);
m_rgAttributes[i].dwFlags = ATTR_FLAG_NONE;
}
}
/**************************************************************************
CTSFEditWnd::_ClearText()
**************************************************************************/
void CTSFEditWnd::_ClearText(void)
{
//can't do this if someone has a lock
if(_IsLocked(TS_LF_READ))
{
return;
}
_LockDocument(TS_LF_READWRITE);
//empty the text in the edit control, but don't send a change notification
BOOL fOldNotify = m_fNotify;
m_fNotify = FALSE;
SetWindowTextW(m_hwndEdit, NULL);
m_fNotify = fOldNotify;
//update current selection
m_acpStart = m_acpEnd = 0;
//notify TSF about the changes
m_AdviseSink.pTextStoreACPSink->OnSelectionChange();
_OnEditChange();
_UnlockDocument();
// make sure to send the OnLayoutChange notification AFTER releasing the lock
// so clients can do something useful during the notification
m_AdviseSink.pTextStoreACPSink->OnLayoutChange(TS_LC_CHANGE, EDIT_VIEW_COOKIE);
}
/**************************************************************************
CTSFEditWnd::_GetText()
**************************************************************************/
HRESULT CTSFEditWnd::_GetText(LPWSTR *ppwsz, LPLONG pcch)
{
DWORD cch;
LPWSTR pwszText;
*ppwsz = NULL;
cch = GetWindowTextLength(m_hwndEdit);
pwszText = (LPWSTR)GlobalAlloc(GMEM_FIXED, (cch + 1) * sizeof(WCHAR));
if(NULL == pwszText)
{
return E_OUTOFMEMORY;
}
GetWindowTextW(m_hwndEdit, pwszText, cch + 1);
*ppwsz = pwszText;
if(pcch)
{
*pcch = cch;
}
return S_OK;
}
/**************************************************************************
CTSFEditWnd::_GetDisplayAttributes()
**************************************************************************/
void CTSFEditWnd::_GetDisplayAttributes(void)
{
HRESULT hr;
const GUID *rGuidProperties[1];
ITfReadOnlyProperty *pTrackProperty;
//get the tracking property for the attributes
rGuidProperties[0] = &GUID_PROP_ATTRIBUTE;
hr = m_pContext->TrackProperties( rGuidProperties,
1,
NULL,
0,
&pTrackProperty);
if(SUCCEEDED(hr))
{
ITfRangeACP *pRangeAllText;
LONG acpEnd;
//get the range of the entire text
acpEnd = GetWindowTextLength(m_hwndEdit);
hr = m_pServices->CreateRange(0, acpEnd, &pRangeAllText);
if(SUCCEEDED(hr))
{
IEnumTfRanges *pEnumRanges;
hr = pTrackProperty->EnumRanges(m_EditCookie, &pEnumRanges, pRangeAllText);
if(SUCCEEDED(hr))
{
ITfRange *pPropRange;
ULONG uFetched;
/*
Each range in pEnumRanges represents a span of text that has
the same properties specified in TrackProperties.
*/
while((hr = pEnumRanges->Next(1, &pPropRange, &uFetched)) == S_OK && uFetched)
{
//get the attribute property for the property range
VARIANT var;
VariantInit(&var);
hr = pTrackProperty->GetValue(m_EditCookie, pPropRange, &var);
if(SUCCEEDED(hr))
{
/*
The property is actually a VT_UNKNOWN that contains an
IEnumTfPropertyValue object.
*/
IEnumTfPropertyValue *pEnumPropertyVal;
hr = var.punkVal->QueryInterface(IID_IEnumTfPropertyValue, (LPVOID*)&pEnumPropertyVal);
if(SUCCEEDED(hr))
{
TF_PROPERTYVAL tfPropVal;
while((hr = pEnumPropertyVal->Next(1, &tfPropVal, &uFetched)) == S_OK && uFetched)
{
if(VT_EMPTY == tfPropVal.varValue.vt)
{
//the property for this range has no value
continue;
}
else if(VT_I4 == tfPropVal.varValue.vt)
{
//the property is a guidatom
TfGuidAtom gaVal;
GUID guid;
gaVal = (TfGuidAtom)tfPropVal.varValue.lVal;
hr = m_pCategoryMgr->GetGUID(gaVal, &guid);
if(SUCCEEDED(hr))
{
ITfDisplayAttributeInfo *pDispInfo;
hr = m_pDisplayAttrMgr->GetDisplayAttributeInfo(guid, &pDispInfo, NULL);
if(SUCCEEDED(hr))
{
TF_DISPLAYATTRIBUTE da;
hr = pDispInfo->GetAttributeInfo(&da);
{
GUID guidDispInfo;
hr = pDispInfo->GetGUID(&guidDispInfo);
guidDispInfo.Data1 = 0;
}
{
BSTR bstr;
hr = pDispInfo->GetDescription(&bstr);
if(SUCCEEDED(hr))
{
SysFreeString(bstr);
}
}
pDispInfo->Release();
}
}
}
else
{
//the property is not recognized
}
}
pEnumPropertyVal->Release();
}
VariantClear(&var);
}
pPropRange->Release();
}
pEnumRanges->Release();
}
pRangeAllText->Release();
}
pTrackProperty->Release();
}
}
/**************************************************************************
CTSFEditWnd::_GetTextOwner()
**************************************************************************/
void CTSFEditWnd::_GetTextOwner(void)
{
HRESULT hr;
const GUID *rGuidProperties[1];
ITfReadOnlyProperty *pTrackProperty;
//get the tracking property for the attributes
rGuidProperties[0] = &GUID_PROP_TEXTOWNER;
hr = m_pContext->TrackProperties( rGuidProperties,
1,
NULL,
0,
&pTrackProperty);
if(SUCCEEDED(hr))
{
ITfRangeACP *pRangeAllText;
LONG acpEnd;
//get the range of the entire text
acpEnd = GetWindowTextLength(m_hwndEdit);
hr = m_pServices->CreateRange(0, acpEnd, &pRangeAllText);
if(SUCCEEDED(hr))
{
IEnumTfRanges *pEnumRanges;
hr = pTrackProperty->EnumRanges(m_EditCookie, &pEnumRanges, pRangeAllText);
if(SUCCEEDED(hr))
{
ITfRange *pPropRange;
ULONG uFetched;
/*
Each range in pEnumRanges represents a span of text that has
the same properties specified in TrackProperties.
*/
while((hr = pEnumRanges->Next(1, &pPropRange, &uFetched)) == S_OK && uFetched)
{
//get the attribute property for the property range
VARIANT var;
VariantInit(&var);
hr = pTrackProperty->GetValue(m_EditCookie, pPropRange, &var);
if(SUCCEEDED(hr))
{
/*
The property is actually a VT_UNKNOWN that contains an
IEnumTfPropertyValue object.
*/
IEnumTfPropertyValue *pEnumPropertyVal;
hr = var.punkVal->QueryInterface(IID_IEnumTfPropertyValue, (LPVOID*)&pEnumPropertyVal);
if(SUCCEEDED(hr))
{
TF_PROPERTYVAL tfPropVal;
while((hr = pEnumPropertyVal->Next(1, &tfPropVal, &uFetched)) == S_OK && uFetched)
{
/*
The GUID_PROP_TEXTOWNER attribute value is the CLSID of the text service that owns the text. If the text is not owned, the value is VT_EMPTY.
*/
if(VT_EMPTY == tfPropVal.varValue.vt)
{
//the text is not owned
continue;
}
else if(VT_I4 == tfPropVal.varValue.vt)
{
//the property is a guidatom that represents the CLSID of the text service that owns the text.
TfGuidAtom gaVal;
CLSID clsidOwner;
gaVal = (TfGuidAtom)tfPropVal.varValue.lVal;
hr = m_pCategoryMgr->GetGUID(gaVal, &clsidOwner);
if(SUCCEEDED(hr))
{
}
}
else
{
//the property is not recognized
}
}
pEnumPropertyVal->Release();
}
VariantClear(&var);
}
pPropRange->Release();
}
pEnumRanges->Release();
}
pRangeAllText->Release();
}
pTrackProperty->Release();
}
}
/**************************************************************************
CTSFEditWnd::_GetReadingText()
**************************************************************************/
void CTSFEditWnd::_GetReadingText(void)
{
HRESULT hr;
const GUID *rGuidProperties[1];
ITfReadOnlyProperty *pTrackProperty;
//get the tracking property for the attributes
rGuidProperties[0] = &GUID_PROP_READING;
hr = m_pContext->TrackProperties( rGuidProperties,
1,
NULL,
0,
&pTrackProperty);
if(SUCCEEDED(hr))
{
ITfRangeACP *pRangeAllText;
LONG acpEnd;
//get the range of the entire text
acpEnd = GetWindowTextLength(m_hwndEdit);
hr = m_pServices->CreateRange(0, acpEnd, &pRangeAllText);
if(SUCCEEDED(hr))
{
IEnumTfRanges *pEnumRanges;
hr = pTrackProperty->EnumRanges(m_EditCookie, &pEnumRanges, pRangeAllText);
if(SUCCEEDED(hr))
{
ITfRange *pPropRange;
ULONG uFetched;
/*
Each range in pEnumRanges represents a span of text that has
the same properties specified in TrackProperties.
*/
while((hr = pEnumRanges->Next(1, &pPropRange, &uFetched)) == S_OK && uFetched)
{
//get the attribute property for the property range
VARIANT var;
VariantInit(&var);
hr = pTrackProperty->GetValue(m_EditCookie, pPropRange, &var);
if(SUCCEEDED(hr))
{
/*
The property is actually a VT_UNKNOWN that contains an
IEnumTfPropertyValue object.
*/
IEnumTfPropertyValue *pEnumPropertyVal;
hr = var.punkVal->QueryInterface(IID_IEnumTfPropertyValue, (LPVOID*)&pEnumPropertyVal);
if(SUCCEEDED(hr))
{
TF_PROPERTYVAL tfPropVal;
while((hr = pEnumPropertyVal->Next(1, &tfPropVal, &uFetched)) == S_OK && uFetched)
{
/*
The GUID_PROP_TEXTOWNER attribute value is the CLSID of the text service that owns the text. If the text is not owned, the value is VT_EMPTY.
*/
if(VT_EMPTY == tfPropVal.varValue.vt)
{
//the text is not owned
continue;
}
else if(VT_BSTR == tfPropVal.varValue.vt)
{
//the property is a BSTR.
tfPropVal.varValue.bstrVal;
HRESULT hr;
WCHAR wsz[MAX_PATH];
ULONG cch;
hr = pPropRange->GetText(m_EditCookie, 0, wsz, MAX_PATH-1, &cch);
wsz[cch] = 0;
}
else
{
//the property is not recognized
}
}
pEnumPropertyVal->Release();
}
VariantClear(&var);
}
pPropRange->Release();
}
pEnumRanges->Release();
}
pRangeAllText->Release();
}
pTrackProperty->Release();
}
}
/**************************************************************************
CTSFEditWnd::_GetComposing()
**************************************************************************/
void CTSFEditWnd::_GetComposing(void)
{
HRESULT hr;
const GUID *rGuidProperties[1];
ITfReadOnlyProperty *pTrackProperty;
//get the tracking property for the attributes
rGuidProperties[0] = &GUID_PROP_COMPOSING;
hr = m_pContext->TrackProperties( rGuidProperties,
1,
NULL,
0,
&pTrackProperty);
if(SUCCEEDED(hr))
{
ITfRangeACP *pRangeAllText;
LONG acpEnd;
//get the range of the entire text
acpEnd = GetWindowTextLength(m_hwndEdit);
hr = m_pServices->CreateRange(0, acpEnd, &pRangeAllText);
if(SUCCEEDED(hr))
{
IEnumTfRanges *pEnumRanges;
hr = pTrackProperty->EnumRanges(m_EditCookie, &pEnumRanges, pRangeAllText);
if(SUCCEEDED(hr))
{
ITfRange *pPropRange;
ULONG uFetched;
/*
Each range in pEnumRanges represents a span of text that has
the same properties specified in TrackProperties.
*/
while((hr = pEnumRanges->Next(1, &pPropRange, &uFetched)) == S_OK && uFetched)
{
//get the attribute property for the property range
VARIANT var;
VariantInit(&var);
hr = pTrackProperty->GetValue(m_EditCookie, pPropRange, &var);
if(SUCCEEDED(hr))
{
/*
The property is actually a VT_UNKNOWN that contains an
IEnumTfPropertyValue object.
*/
IEnumTfPropertyValue *pEnumPropertyVal;
hr = var.punkVal->QueryInterface(IID_IEnumTfPropertyValue, (LPVOID*)&pEnumPropertyVal);
if(SUCCEEDED(hr))
{
TF_PROPERTYVAL tfPropVal;
while((hr = pEnumPropertyVal->Next(1, &tfPropVal, &uFetched)) == S_OK && uFetched)
{
/*
The GUID_PROP_COMPOSING attribute value is a VT_I4 that contains a boolean indicating if the text is part of a composition.
*/
BOOL fComposing = FALSE;
if(VT_EMPTY == tfPropVal.varValue.vt)
{
//the text is not part of a composition
}
else if(VT_I4 == tfPropVal.varValue.vt)
{
//the property is a VT_I4.
if(tfPropVal.varValue.lVal)
{
//The text is part of a composition
fComposing = TRUE;
}
}
else
{
//the property is not recognized
}
}
pEnumPropertyVal->Release();
}
VariantClear(&var);
}
pPropRange->Release();
}
pEnumRanges->Release();
}
pRangeAllText->Release();
}
pTrackProperty->Release();
}
}
/**************************************************************************
CTSFEditWnd::_CanReconvertSelection()
**************************************************************************/
BOOL CTSFEditWnd::_CanReconvertSelection(void)
{
BOOL fConv = FALSE;
HRESULT hr;
ITfFunctionProvider *pFuncProv;
_InternalLockDocument(TS_LF_READ);
hr = m_pThreadMgr->GetFunctionProvider(GUID_SYSTEM_FUNCTIONPROVIDER, &pFuncProv);
if(SUCCEEDED(hr))
{
ITfFnReconversion *pRecon;
hr = pFuncProv->GetFunction(GUID_NULL, IID_ITfFnReconversion, (IUnknown**)&pRecon);
if(SUCCEEDED(hr))
{
TF_SELECTION ts;
ULONG uFetched;
hr = m_pContext->GetSelection(m_EditCookie, TF_DEFAULT_SELECTION, 1, &ts, &uFetched);
if(SUCCEEDED(hr))
{
ITfRange *pRange = NULL;
hr = pRecon->QueryRange(ts.range, &pRange, &fConv);
if(SUCCEEDED(hr) && pRange)
{
pRange->Release();
}
ts.range->Release();
}
pRecon->Release();
}
pFuncProv->Release();
}
_InternalUnlockDocument();
return fConv;
}
/**************************************************************************
CTSFEditWnd::_Reconvert()
**************************************************************************/
void CTSFEditWnd::_Reconvert(void)
{
HRESULT hr;
ITfFunctionProvider *pFuncProv;
_InternalLockDocument(TS_LF_READ);
hr = m_pThreadMgr->GetFunctionProvider(GUID_SYSTEM_FUNCTIONPROVIDER, &pFuncProv);
if(SUCCEEDED(hr))
{
ITfFnReconversion *pRecon;
hr = pFuncProv->GetFunction(GUID_NULL, IID_ITfFnReconversion, (IUnknown**)&pRecon);
if(SUCCEEDED(hr))
{
TF_SELECTION ts;
ULONG uFetched;
hr = m_pContext->GetSelection(m_EditCookie, TF_DEFAULT_SELECTION, 1, &ts, &uFetched);
if(SUCCEEDED(hr))
{
ITfRange *pRange;
BOOL fConv;
//get the range that covers the text to be reconverted
hr = pRecon->QueryRange(ts.range, &pRange, &fConv);
if(SUCCEEDED(hr) && pRange)
{
{
WCHAR wsz[MAX_PATH];
ULONG cch = 0;
pRange->GetText(m_EditCookie, 0, wsz, MAX_PATH-1, &cch);
wsz[cch] = 0;
}
//get the list of reconversion candidates
ITfCandidateList *pCandList;
hr = pRecon->GetReconversion(pRange, &pCandList);
if(SUCCEEDED(hr))
{
ULONG i;
ULONG uCandidateCount = 0;
hr = pCandList->GetCandidateNum(&uCandidateCount);
for(i = 0; i < uCandidateCount; i++)
{
ITfCandidateString *pCandString;
hr = pCandList->GetCandidate(i, &pCandString);
if(SUCCEEDED(hr))
{
BSTR bstr;
hr = pCandString->GetString(&bstr);
if(SUCCEEDED(hr))
{
OutputDebugString(TEXT("\tCandidate - \""));
OutputDebugStringW(bstr);
OutputDebugString(TEXT("\"\n"));
SysFreeString(bstr);
}
pCandString->Release();
}
}
pCandList->Release();
}
//cause the reconversion to happen
hr = pRecon->Reconvert(pRange);
}
}
pRecon->Release();
}
pFuncProv->Release();
}
_InternalUnlockDocument();
}
/**************************************************************************
CTSFEditWnd::_CanPlaybackSelection()
**************************************************************************/
BOOL CTSFEditWnd::_CanPlaybackSelection(void)
{
BOOL fCanPlayback = FALSE;
HRESULT hr;
ITfFunctionProvider *pFuncProv;
_InternalLockDocument(TS_LF_READ);
hr = m_pThreadMgr->GetFunctionProvider(CLSID_SapiLayr, &pFuncProv);
if(SUCCEEDED(hr))
{
ITfFnPlayBack *pPlayback;
hr = pFuncProv->GetFunction(GUID_NULL, IID_ITfFnPlayBack, (IUnknown**)&pPlayback);
if(SUCCEEDED(hr))
{
TF_SELECTION ts;
ULONG uFetched;
hr = m_pContext->GetSelection(m_EditCookie, TF_DEFAULT_SELECTION, 1, &ts, &uFetched);
if(SUCCEEDED(hr))
{
ITfRange *pRange = NULL;
hr = pPlayback->QueryRange(ts.range, &pRange, &fCanPlayback);
if(SUCCEEDED(hr) && pRange)
{
pRange->Release();
}
ts.range->Release();
}
pPlayback->Release();
}
pFuncProv->Release();
}
_InternalUnlockDocument();
return fCanPlayback;
}
/**************************************************************************
CTSFEditWnd::_Playback()
**************************************************************************/
void CTSFEditWnd::_Playback(void)
{
HRESULT hr;
ITfFunctionProvider *pFuncProv;
_InternalLockDocument(TS_LF_READ);
hr = m_pThreadMgr->GetFunctionProvider(CLSID_SapiLayr, &pFuncProv);
if(SUCCEEDED(hr))
{
ITfFnPlayBack *pPlayback;
hr = pFuncProv->GetFunction(GUID_NULL, IID_ITfFnPlayBack, (IUnknown**)&pPlayback);
if(SUCCEEDED(hr))
{
TF_SELECTION ts;
ULONG uFetched;
hr = m_pContext->GetSelection(m_EditCookie, TF_DEFAULT_SELECTION, 1, &ts, &uFetched);
if(SUCCEEDED(hr))
{
BOOL fCanPlayback;
ITfRange *pRange = NULL;
hr = pPlayback->QueryRange(ts.range, &pRange, &fCanPlayback);
if(SUCCEEDED(hr) && pRange)
{
hr = pPlayback->Play(pRange);
pRange->Release();
}
ts.range->Release();
}
pPlayback->Release();
}
pFuncProv->Release();
}
_InternalUnlockDocument();
}
///////////////////////////////////////////////////////////////////////////
//
// IUnknown Implementation
//
/**************************************************************************
CTSFEditWnd::QueryInterface
**************************************************************************/
STDMETHODIMP CTSFEditWnd::QueryInterface(REFIID riid, LPVOID *ppReturn)
{
*ppReturn = NULL;
//IUnknown
if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITextStoreACP))
{
*ppReturn = (ITextStoreACP*)this;
}
//ITfContextOwnerCompositionSink
else if(IsEqualIID(riid, IID_ITfContextOwnerCompositionSink))
{
*ppReturn = (ITfContextOwnerCompositionSink*)this;
}
//ITfFunctionProvider
else if(IsEqualIID(riid, IID_ITfFunctionProvider))
{
*ppReturn = (ITfFunctionProvider*)this;
}
if(*ppReturn)
{
(*(LPUNKNOWN*)ppReturn)->AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
/**************************************************************************
CTSFEditWnd::AddRef
**************************************************************************/
STDMETHODIMP_(DWORD) CTSFEditWnd::AddRef()
{
return ++m_ObjRefCount;
}
/**************************************************************************
CTSFEditWnd::Release
**************************************************************************/
STDMETHODIMP_(DWORD) CTSFEditWnd::Release()
{
if(--m_ObjRefCount == 0)
{
delete this;
return 0;
}
return m_ObjRefCount;
}
| [
"nathancorvussolis@gmail.com"
] | nathancorvussolis@gmail.com |
eb62c7218e648a4b5c0431cad3dbccf2a9bda144 | 94c7bcc7fa0749ef3890af6dac39341c14f5d259 | /tensorflow/core/kernels/hexagon/graph_transferer.cc | 7960cb4b0552de2f32cfb17db285b4a9ce42c7a1 | [
"Apache-2.0"
] | permissive | lgeiger/tensorflow | e75e32cd23a45d29bac1fc10eda23499a66d188a | 1bf9ec7f8545c7aa6fa915c6576a3b984af59ded | refs/heads/master | 2023-08-18T23:16:38.380820 | 2018-04-26T20:47:51 | 2018-04-26T20:47:51 | 127,307,734 | 2 | 1 | Apache-2.0 | 2018-03-29T15:02:37 | 2018-03-29T15:02:36 | null | UTF-8 | C++ | false | false | 48,619 | cc | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/core/kernels/hexagon/graph_transferer.h"
#include <algorithm>
#include <cinttypes>
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/graph_transfer_info.pb.h"
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/graph/algorithm.h"
#include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/public/session_options.h"
#include "tensorflow/core/util/tensor_slice_writer.h"
namespace tensorflow {
// function alias
constexpr auto AddOutputTensorShapeTypeByTensorShapeMap =
&RemoteFusedGraphExecuteUtils::AddOutputTensorShapeTypeByTensorShapeMap;
constexpr bool DBG_DUMP_VERIFICATION_STRING = false;
constexpr bool DBG_DUMP_PARAMS = false;
const char RESHAPE_NODE_TYPE_STRING[] = "Reshape";
const char SOURCE_NODE_NAME[] = "_SOURCE";
const char SINK_NODE_NAME[] = "_SINK";
const char INPUTS_NODE_PREFIX[] = "inputs_for_";
const char OUTPUTS_NODE_PREFIX[] = "outputs_for_";
const char DATA_NODE_PREFIX[] = "data_for_op_";
const char CONST_SHAPE_PREFIX[] = "const_shape_";
const char CONST_VAL_PREFIX[] = "const_val_";
const char CONST_TENSOR_PREFIX[] = "const_tensor_";
const char PADDING_ATTR_NAME[] = "padding";
const char STRIDES_ATTR_NAME[] = "strides";
const char KEEP_DIMS_ATTR_NAME[] = "keep_dims";
const char KSIZE_ATTR_NAME[] = "ksize";
const char NULL_OUTPUT_NAME[] = "NULL";
const char AGGREGATED_INPUT_NODE_NAME[] = "graph_transfer_aggregated_input";
const int PADDING_NA_ID = 0; // VALID = 1, SAME = 2
// This is a temporary workaround to support android build
// where std::string is not supported even with c++11 option.
template <typename T>
static string ToString(T val) {
std::stringstream stream;
stream << val;
return stream.str();
}
static Node* FindMutableNodeByName(const string& name, Graph* graph) {
const TensorId tid = ParseTensorName(name);
for (Node* node : graph->nodes()) {
if (node != nullptr && node->name() == tid.first) {
return node;
}
}
return nullptr;
}
GraphTransferer::GraphTransferer() {
graph_transfer_info_ = new GraphTransferInfo();
}
GraphTransferer::~GraphTransferer() { delete graph_transfer_info_; }
/**
* graph loading functions
* - LoadGraphFromProto
* - LoadGraphFromProptoFile
* These functions read a graph definition and store parameters
* of node to transfer the graph to SOC.
*/
Status GraphTransferer::LoadGraphFromProto(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const GraphDef& graph_def,
const std::vector<std::pair<string, Tensor>>& input_node_info_list,
const std::vector<string>& output_node_names,
const bool shape_inference_for_unknown_shape) {
Graph graph(OpRegistry::Global());
ShapeRefiner shape_refiner(graph.versions(), graph.op_registry());
Status status = ImportGraphDef({}, graph_def, &graph, &shape_refiner);
if (!status.ok()) {
return status;
}
if (shape_inference_for_unknown_shape) {
status = RemoteFusedGraphExecuteUtils::PropagateShapeInference(
graph_def, input_node_info_list, &graph, &shape_refiner);
if (!status.ok()) {
return status;
}
}
TF_RETURN_IF_ERROR(TransformGraphToAddAggregatedInputNode(
input_node_info_list, &graph, &shape_refiner));
std::unordered_multimap<string, const Node*> op_name_to_node_multimap(
graph.num_nodes());
for (const Node* const node : graph.nodes()) {
if (node == nullptr) {
continue;
}
CacheNode(*node);
}
for (const Node* const node : graph.nodes()) {
if (node == nullptr) {
continue;
}
VLOG(1) << "<Node> " << node->name();
for (const Node* const input_node : node->in_nodes()) {
const string& name = input_node->name();
op_name_to_node_multimap.emplace(name, node);
VLOG(1) << "Add dependency: " << name << " -> " << node->name();
}
}
for (const Node* const node : graph.nodes()) {
if (node == nullptr) {
continue;
}
status = RegisterNodeIfAllInputsAreCached(
ops_definitions, shape_refiner, *node, false, input_node_info_list,
output_node_names);
if (!status.ok()) {
LOG(ERROR) << "Failed to transfer graph " << status;
return status;
}
}
SortParams(output_node_names);
for (const std::pair<string, Tensor>& input_node_info :
input_node_info_list) {
GraphTransferGraphInputNodeInfo& graph_input_node_info =
*graph_transfer_info_->add_graph_input_node_info();
graph_input_node_info.set_name(input_node_info.first);
graph_input_node_info.set_dtype(input_node_info.second.dtype());
for (const int64 dim : ToTensorShapeArray(input_node_info.second.shape())) {
graph_input_node_info.add_shape(dim);
}
}
for (const string& output_node_name : output_node_names) {
const TensorId tid = ParseTensorName(output_node_name);
const string node_name = tid.first.ToString();
const int port = tid.second;
const int node_id = node_name_to_id_cache_map_.at(node_name);
const Node* node = node_name_cache_list_.at(node_id);
CHECK_NOTNULL(node);
GraphTransferGraphOutputNodeInfo& graph_output_node_info =
*graph_transfer_info_->add_graph_output_node_info();
graph_output_node_info.set_name(strings::StrCat(node_name, ":", port));
// Get output tensor shape type
std::vector<DataType> data_types;
std::vector<TensorShape> shapes;
status = RemoteFusedGraphExecuteUtils::GetOutputTensorShapeType(
node->attrs(), &data_types, &shapes);
if (status.ok()) {
CHECK(data_types.size() > port);
graph_output_node_info.set_dtype(data_types.at(port));
for (const int64 dim : ToTensorShapeArray(shapes.at(port))) {
graph_output_node_info.add_shape(dim);
}
}
}
ClearCache();
if (DBG_DUMP_PARAMS) {
DumpNodeTransferParams();
}
if (DBG_DUMP_VERIFICATION_STRING) {
DumpVerificationStringOfNodeTransferParams();
}
return Status();
}
Status GraphTransferer::LoadGraphFromProtoFile(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const string& graph_def_path,
const std::vector<std::pair<string, Tensor>>& input_node_info_list,
const std::vector<string>& output_node_names, const bool is_text_proto,
const bool shape_inference_for_unknown_shape,
const bool dry_run_for_unknown_shape) {
GraphDef graph_def;
string output;
Status status;
VLOG(1) << "Parse file " << graph_def_path;
if (is_text_proto) {
status = ReadFileToString(Env::Default(), graph_def_path, &output);
if (!protobuf::TextFormat::ParseFromString(output, &graph_def)) {
return errors::InvalidArgument("Cannot parse proto string.");
}
} else {
status = ReadBinaryProto(Env::Default(), graph_def_path, &graph_def);
}
if (!status.ok()) {
VLOG(1) << "Failed to load graph " << status;
return status;
}
if (dry_run_for_unknown_shape) {
VLOG(1) << "Dry run graph to obtain shape of nodes";
RemoteFusedGraphExecuteUtils::TensorShapeMap tensor_shape_map;
status = RemoteFusedGraphExecuteUtils::DryRunInferenceForAllNode(
graph_def, input_node_info_list, true, &tensor_shape_map);
if (!status.ok()) {
return status;
}
for (NodeDef& node_def : *graph_def.mutable_node()) {
TF_CHECK_OK(AddOutputTensorShapeTypeByTensorShapeMap(tensor_shape_map,
&node_def));
}
}
VLOG(1) << "Load graph with output tensors";
return LoadGraphFromProto(ops_definitions, graph_def, input_node_info_list,
output_node_names,
shape_inference_for_unknown_shape);
}
void GraphTransferer::SortParams(const std::vector<string>& output_node_names) {
// TODO(satok): optimize complexity
std::unordered_map<int, GraphTransferNodeInputInfo*> input_map;
for (GraphTransferNodeInputInfo& input :
*graph_transfer_info_->mutable_node_input_info()) {
input_map.emplace(input.node_id(), &input);
}
// Setup dependency map placeholder
std::vector<int> output_node_ids;
std::unordered_map<int, std::unordered_set<int>> dependency_map;
for (const GraphTransferNodeInfo& params :
graph_transfer_info_->node_info()) {
const int node_id = params.node_id();
for (const string& output_node_name : output_node_names) {
if (params.name() == output_node_name) {
output_node_ids.emplace_back(node_id);
}
}
dependency_map.emplace(std::piecewise_construct, std::make_tuple(node_id),
std::make_tuple());
if (params.input_count() == 0) {
continue;
}
CHECK_EQ(input_map.count(node_id), 1);
for (const GraphTransferNodeInput& node_input :
input_map.at(node_id)->node_input()) {
dependency_map.at(node_id).emplace(node_input.node_id());
}
}
// Create dependency map traversed from output nodes
std::unordered_set<int> completed;
for (int output_node_id : output_node_ids) {
FillDependencyRec(output_node_id, dependency_map, completed);
}
std::sort(graph_transfer_info_->mutable_node_info()->begin(),
graph_transfer_info_->mutable_node_info()->end(),
TransferParamsComparator(dependency_map));
}
void GraphTransferer::EnableStrictCheckMode(const bool enable) {
strict_check_mode_ = enable;
}
void GraphTransferer::SetSerializedGraphTransferInfo(
const string& serialized_proto) {
graph_transfer_info_->ParseFromString(serialized_proto);
}
const GraphTransferInfo& GraphTransferer::GetGraphTransferInfo() const {
return *graph_transfer_info_;
}
GraphTransferInfo& GraphTransferer::GetMutableGraphTransferInfo() {
return *graph_transfer_info_;
}
void GraphTransferer::CacheNode(const Node& node) {
if (node_name_to_id_cache_map_.count(node.name()) > 0) {
return;
}
node_name_cache_list_.emplace_back(&node);
const int node_id = node_name_cache_list_.size() - 1;
bool emplace_succeeded = false;
std::tie(std::ignore, emplace_succeeded) =
node_name_to_id_cache_map_.emplace(node.name(), node_id);
CHECK(emplace_succeeded);
}
bool GraphTransferer::AreAllInputsCached(const Node& node) const {
for (const Node* const input_node : node.in_nodes()) {
if (node_name_to_id_cache_map_.count(input_node->name()) <= 0) {
VLOG(1) << "input_node " << input_node->name() << " of " << node.name()
<< " is not cached yet.";
return false;
}
}
return true;
}
Status GraphTransferer::TransformGraphToAddAggregatedInputNode(
const std::vector<std::pair<string, Tensor>>& input_node_info_list,
Graph* graph, ShapeRefiner* shape_refiner) {
// Transform a remote fused graph to add an aggregated input node which takes
// all inputs of the remote graph.
DataTypeVector input_data_types;
std::vector<DataType> data_types;
std::vector<TensorShape> shapes;
std::vector<string> input_nodes;
for (int i = 0; i < input_node_info_list.size(); ++i) {
Node* node = FindMutableNodeByName(input_node_info_list.at(i).first, graph);
CHECK_NOTNULL(node);
input_nodes.emplace_back(node->name());
input_data_types.emplace_back(input_node_info_list.at(i).second.dtype());
data_types.emplace_back(input_node_info_list.at(i).second.dtype());
shapes.emplace_back(input_node_info_list.at(i).second.shape());
}
NodeDef input_node_def;
auto builder =
NodeBuilder(AGGREGATED_INPUT_NODE_NAME, "RemoteFusedGraphExecute")
.Input(std::vector<NodeBuilder::NodeOut>{})
.Attr("Tinputs", DataTypeVector{})
.Attr("Toutputs", input_data_types)
.Attr("serialized_remote_fused_graph_execute_info", "")
.Attr(RemoteFusedGraphExecuteUtils::ATTR_OUTPUT_DATA_TYPES,
data_types)
.Attr(RemoteFusedGraphExecuteUtils::ATTR_OUTPUT_SHAPES, shapes);
Node* input_node;
TF_RETURN_IF_ERROR(builder.Finalize(graph, &input_node));
CHECK_NOTNULL(input_node);
bool refined;
TF_RETURN_IF_ERROR(
shape_refiner->UpdateNode(input_node, false /* relax */, &refined));
shape_inference::InferenceContext* context =
shape_refiner->GetContext(input_node);
for (int i = 0; i < input_node_info_list.size(); ++i) {
shape_inference::ShapeHandle handle;
TF_RETURN_IF_ERROR(context->MakeShapeFromTensorShape(
input_node_info_list.at(i).second.shape(), &handle));
TF_RETURN_IF_ERROR(shape_refiner->SetShape(input_node, i, handle));
}
// Cache the aggregate input node first as it's consumed first.
CacheNode(*input_node);
std::vector<Node*> original_input_nodes(input_nodes.size());
for (int i = 0; i < input_nodes.size(); ++i) {
const string& node_name = input_nodes.at(i);
Node* original_input_node = FindMutableNodeByName(node_name, graph);
CHECK_NOTNULL(original_input_node);
CHECK_EQ(1, original_input_node->num_outputs()); // replaced by identity.
Node* created_node;
TF_RETURN_IF_ERROR(RemoteFusedGraphExecuteUtils::BuildIdentityOpNode(
node_name, AGGREGATED_INPUT_NODE_NAME, i, data_types.at(i), graph,
&created_node));
CHECK_NOTNULL(created_node);
std::vector<DataType> data_types;
std::vector<TensorShape> shapes;
Status status = RemoteFusedGraphExecuteUtils::GetOutputTensorShapeType(
original_input_node->attrs(), &data_types, &shapes);
if (status.ok()) {
created_node->AddAttr(
RemoteFusedGraphExecuteUtils::ATTR_OUTPUT_DATA_TYPES, data_types);
created_node->AddAttr(RemoteFusedGraphExecuteUtils::ATTR_OUTPUT_SHAPES,
shapes);
}
for (const Edge* out_edge : original_input_node->out_edges()) {
Node* dst = out_edge->dst();
int dst_port = out_edge->dst_input();
// Unused edge will be removed when removing node.
graph->AddEdge(created_node, 0, dst, dst_port);
}
original_input_nodes[i] = original_input_node;
TF_RETURN_IF_ERROR(
shape_refiner->UpdateNode(created_node, false /* relax */, &refined));
shape_inference::InferenceContext* context =
shape_refiner->GetContext(created_node);
CHECK_NOTNULL(context);
// Cache replaced input node next to the aggregated input node.
CacheNode(*created_node);
}
// Remove original input nodes after adding new input nodes to avoid
// reusing same pointer in Graph.
for (Node* original_input_node : original_input_nodes) {
graph->RemoveNode(original_input_node);
}
return Status::OK();
}
Status GraphTransferer::RegisterNode(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node,
const std::vector<std::pair<string, Tensor>>& input_node_info_list,
const std::vector<string>& output_node_names) {
VLOG(1) << "Register node: " << node.name() << ", " << std::hex
<< node_name_to_id_cache_map_.at(node.name());
if (node.name() == SOURCE_NODE_NAME || node.name() == SINK_NODE_NAME) {
// Just ignore sink and source
return Status::OK();
} else if (node.name() == AGGREGATED_INPUT_NODE_NAME) {
RegisterInputNode(ops_definitions, shape_refiner, node);
return Status::OK();
} else if (node.IsConstant()) {
RegisterConstantNode(shape_refiner, node);
} else if (IsPadNode(node)) {
RegisterPadNode(ops_definitions, shape_refiner, node);
} else if (HasPaddingAndStrides(node)) {
RegisterNodeWithPaddingAndStrides(ops_definitions, shape_refiner, node);
} else if (NeedsToAddRank(node)) {
RegisterNodeWithRank(ops_definitions, shape_refiner, node);
} else if (IsNodeFlattenReshape(node, shape_refiner)) {
RegisterFlattenNode(ops_definitions, shape_refiner, node);
} else if (ops_definitions.GetOpIdFor(node.type_string(), {}) !=
IRemoteFusedGraphOpsDefinitions::INVALID_OP_ID) {
// TODO(satok): Set correct data type if it's given.
RegisterGenericNode(ops_definitions, shape_refiner, node);
} else {
return errors::InvalidArgument(node.type_string() +
" has not been implemented yet.");
}
return Status::OK();
}
void GraphTransferer::RegisterConstantNode(const ShapeRefiner& shape_refiner,
const Node& node) {
VLOG(1) << "Register constant node: " << node.name();
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
const int output_node_size = node.num_outputs();
CHECK_EQ(output_node_size, 1);
// TODO(satok): support multiple outputs?
const int output_index = 0;
const DataType dt = node.output_type(output_index);
const size_t max_bytes_per_data = DataTypeSize(dt);
CHECK_GT(max_bytes_per_data, 0)
<< "dt = " << dt << ", " + DataTypeString(dt) << ", "
<< max_bytes_per_data << ", " << static_cast<int>(DataTypeSize(dt))
<< ",,,,,,,";
shape_inference::InferenceContext* context = shape_refiner.GetContext(&node);
shape_inference::ShapeHandle shape_handle = context->output(output_index);
const shape_inference::DimensionHandle num_elements_dim =
context->NumElements(shape_handle);
std::array<int64, SHAPE_ARRAY_SIZE> shape_array;
int data_size;
// Shape of constant node must be known
CHECK(context->ValueKnown(num_elements_dim));
const int64 num_output_elements = context->Value(num_elements_dim);
data_size = max_bytes_per_data * num_output_elements;
shape_array = BuildShapeArray(shape_handle, context);
GraphTransferConstNodeInfo& const_node_info =
*graph_transfer_info_->add_const_node_info();
const_node_info.set_name(node.name());
const_node_info.set_node_id(id);
// TODO(satok): Make this generic. Never assume rank is 4.
CHECK_EQ(4, SHAPE_ARRAY_SIZE);
const_node_info.add_shape(shape_array[0]);
const_node_info.add_shape(shape_array[1]);
const_node_info.add_shape(shape_array[2]);
const_node_info.add_shape(shape_array[3]);
const TensorProto* proto = nullptr;
TF_CHECK_OK(GetNodeAttr(node.attrs(), "value", &proto));
Tensor const_tensor;
TF_CHECK_OK(MakeTensorFromProto(*proto, &const_tensor));
const_node_info.set_dtype(const_tensor.dtype());
if (data_size > 0) {
const_node_info.set_data(const_tensor.tensor_data().data(), data_size);
}
}
int GraphTransferer::RegisterConstantShape(const std::vector<int>& shape) {
VLOG(1) << "Cache constant shape.";
// TODO(satok): Handle non-4dim strides
CHECK_EQ(shape.size(), 4);
const string shape_name = CONST_SHAPE_PREFIX + ToString(shape.at(0)) + 'x' +
ToString(shape.at(1)) + 'x' +
ToString(shape.at(2)) + 'x' + ToString(shape.at(3));
if (node_name_to_id_cache_map_.count(shape_name) <= 0) {
node_name_cache_list_.emplace_back(nullptr);
const int id = node_name_cache_list_.size() - 1;
node_name_to_id_cache_map_.emplace(shape_name, id);
GraphTransferConstNodeInfo& const_node_info =
*graph_transfer_info_->add_const_node_info();
const_node_info.set_name(shape_name);
const_node_info.set_node_id(id);
// TODO(satok): Make this generic. Never assume rank is 5.
const_node_info.add_shape(static_cast<int64>(shape[0]));
const_node_info.add_shape(static_cast<int64>(shape[1]));
const_node_info.add_shape(static_cast<int64>(shape[2]));
const_node_info.add_shape(static_cast<int64>(shape[3]));
}
return node_name_to_id_cache_map_[shape_name];
}
int GraphTransferer::RegisterConstTensor(const Tensor& tensor,
const string& suffix) {
VLOG(1) << "Cache const tensor.";
const int dims = tensor.shape().dims();
CHECK(dims <= 4);
const string node_name = strings::StrCat(CONST_TENSOR_PREFIX, "_", suffix);
if (node_name_to_id_cache_map_.count(node_name) <= 0) {
node_name_cache_list_.emplace_back(nullptr);
const int id = node_name_cache_list_.size() - 1;
node_name_to_id_cache_map_.emplace(node_name, id);
GraphTransferConstNodeInfo& const_node_info =
*graph_transfer_info_->add_const_node_info();
const_node_info.set_name(node_name);
const_node_info.set_node_id(id);
CHECK_EQ(4, SHAPE_ARRAY_SIZE);
for (int i = 0; i < SHAPE_ARRAY_SIZE; ++i) {
if (i < SHAPE_ARRAY_SIZE - dims) {
const_node_info.add_shape(1);
} else {
const_node_info.add_shape(
tensor.shape().dim_size(i - (SHAPE_ARRAY_SIZE - dims)));
}
}
const_node_info.set_dtype(tensor.dtype());
const_node_info.set_data(tensor.tensor_data().data(),
tensor.tensor_data().size());
}
return node_name_to_id_cache_map_[node_name];
}
int GraphTransferer::RegisterConstScalar(const DataType dt, const int val,
const int dst_id,
const int dst_input_count) {
VLOG(1) << "Cache const.";
const string val_name =
CONST_VAL_PREFIX + ToString(dst_id) + '_' + ToString(dst_input_count);
if (node_name_to_id_cache_map_.count(val_name) <= 0) {
node_name_cache_list_.emplace_back(nullptr);
const int id = node_name_cache_list_.size() - 1;
node_name_to_id_cache_map_.emplace(val_name, id);
GraphTransferConstNodeInfo& const_node_info =
*graph_transfer_info_->add_const_node_info();
const_node_info.set_name(val_name);
const_node_info.set_node_id(id);
// TODO(satok): Do not assume rank is 4 here.
const_node_info.add_shape(static_cast<int64>(1));
const_node_info.add_shape(static_cast<int64>(1));
const_node_info.add_shape(static_cast<int64>(1));
const_node_info.add_shape(static_cast<int64>(1));
const_node_info.set_data(&val, DataTypeSize(dt));
}
return node_name_to_id_cache_map_[val_name];
}
bool GraphTransferer::HasPaddingAndStrides(const Node& node) {
auto attrs = node.attrs();
return attrs.Find(PADDING_ATTR_NAME) != nullptr &&
attrs.Find(STRIDES_ATTR_NAME) != nullptr;
}
bool GraphTransferer::NeedsToAddRank(const Node& node) {
const StringPiece op_type(node.type_string());
if (op_type == "Transpose" || op_type == "ExpandDims") {
return true;
}
return false;
}
bool GraphTransferer::IsPadNode(const Node& node) {
const StringPiece op_type(node.type_string());
if (op_type == "Pad") {
return true;
}
return false;
}
bool GraphTransferer::IsNodeFlattenReshape(const Node& node,
const ShapeRefiner& shape_refiner) {
// Check if node is reshape op
if (node.type_string() != RESHAPE_NODE_TYPE_STRING) {
return false;
}
shape_inference::InferenceContext* context = shape_refiner.GetContext(&node);
// Check if output count is valid
if (context->num_outputs() != 1) {
return false;
}
shape_inference::ShapeHandle shape_handle = context->output(0);
std::array<int64, SHAPE_ARRAY_SIZE> shape_array;
const shape_inference::DimensionHandle dim_handle =
context->NumElements(shape_handle);
// Obtain shape of output of node
if (context->ValueKnown(dim_handle)) {
shape_array = BuildShapeArray(shape_handle, context);
} else {
std::vector<TensorShape> shapes;
TF_CHECK_OK(RemoteFusedGraphExecuteUtils::GetOutputTensorShapeType(
node.attrs(), nullptr, &shapes));
// Number of outputs should be 1 for reshape node.
CHECK_EQ(1, shapes.size());
shape_array = ToTensorShapeArray(shapes.at(0));
}
// check if reshape op just does flatten
if (shape_array[0] == 1 && shape_array[1] == 1 && shape_array[2] == 1) {
return true;
} else {
return false;
}
}
void GraphTransferer::RegisterNodeWithPaddingAndStrides(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node) {
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
shape_inference::InferenceContext* context = shape_refiner.GetContext(&node);
CHECK(node.attrs().Find(PADDING_ATTR_NAME));
// TODO(satok): Use context->GetAttr(...) instead?
Padding padding;
TF_CHECK_OK(context->GetAttr(PADDING_ATTR_NAME, &padding));
CHECK(node.attrs().Find(STRIDES_ATTR_NAME));
std::vector<int32> strides;
TF_CHECK_OK(context->GetAttr(STRIDES_ATTR_NAME, &strides));
const int stride_id = RegisterConstantShape(strides);
std::vector<int> extra_inputs{stride_id};
if (node.attrs().Find(KSIZE_ATTR_NAME)) {
std::vector<int32> kernel_sizes;
TF_CHECK_OK(context->GetAttr(KSIZE_ATTR_NAME, &kernel_sizes));
const int ksize_id = RegisterConstantShape(kernel_sizes);
extra_inputs.insert(extra_inputs.begin(), ksize_id);
}
// TODO(satok): Set correct data type if it's given.
const int op_type_id = ops_definitions.GetOpIdFor(node.type_string(), {});
CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount())
<< "Op " << node.type_string() << " not found in map(id = " << op_type_id
<< ")";
// Safety check of padding id
CHECK(padding == Padding::VALID ? 1 : 2);
AppendNodeParamsWithIoParams(
shape_refiner, node, node.name(), id, node.type_string(), op_type_id,
static_cast<int>(padding), node.num_inputs(), extra_inputs,
node.num_outputs(), true /* append_input */, true /* append_output */);
}
void GraphTransferer::RegisterNodeWithRank(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node) {
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
shape_inference::InferenceContext* context = shape_refiner.GetContext(&node);
const Node* input0_node;
TF_CHECK_OK(node.input_node(0, &input0_node));
CHECK_NOTNULL(input0_node);
std::vector<TensorShape> shapes;
Status status = RemoteFusedGraphExecuteUtils::GetOutputTensorShapeType(
input0_node->attrs(), nullptr, &shapes);
CHECK_EQ(1, shapes.size()) << "Output size should be 1.";
const int const_val_id =
RegisterConstScalar(DT_INT32, shapes.at(0).dims(), id, node.num_inputs());
std::vector<int> extra_inputs{const_val_id};
// TODO(satok): Set correct data type if it's given.
const int op_type_id = ops_definitions.GetOpIdFor(node.type_string(), {});
CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount())
<< "Op " << node.type_string() << " not found in map(id = " << op_type_id
<< ")";
bool keep_dims = false;
int padding_id = PADDING_NA_ID;
if (context->GetAttr(KEEP_DIMS_ATTR_NAME, &keep_dims).ok()) {
padding_id = keep_dims ? Padding::SAME : Padding::VALID;
}
AppendNodeParamsWithIoParams(
shape_refiner, node, node.name(), id, node.type_string(), op_type_id,
padding_id, node.num_inputs(), extra_inputs, node.num_outputs(),
true /* append_input */, true /* append_output */);
}
void GraphTransferer::RegisterPadNode(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node) {
static constexpr int PAD_WIDTH = 4;
static constexpr int PAD_HEIGHT = 2;
VLOG(1) << "Register generic node: " << node.name();
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
// TODO(satok): Set correct data type if it's given.
const int op_type_id = ops_definitions.GetOpIdFor(node.type_string(), {});
CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount());
CHECK_EQ(2, node.num_inputs());
GraphTransferNodeInputInfo& node_input_info =
*graph_transfer_info_->add_node_input_info();
node_input_info.set_node_id(id);
AddNodeInputByInputIndex(node, 0, &node_input_info);
const Edge* edge = nullptr;
TF_CHECK_OK(node.input_edge(1, &edge));
const Node* input_node = edge->src();
CHECK_NOTNULL(input_node);
CHECK(input_node->IsConstant());
const TensorProto* tensor_proto = nullptr;
TF_CHECK_OK(GetNodeAttr(input_node->attrs(), "value", &tensor_proto));
CHECK_NOTNULL(tensor_proto);
Tensor const_tensor;
TF_CHECK_OK(MakeTensorFromProto(*tensor_proto, &const_tensor));
CHECK_EQ(2, const_tensor.shape().dims());
CHECK_EQ(PAD_HEIGHT, const_tensor.shape().dim_size(1));
if (const_tensor.shape().dim_size(0) == PAD_WIDTH) {
AddNodeInputByInputIndex(node, 1, &node_input_info);
} else if (const_tensor.shape().dim_size(0) < PAD_WIDTH) {
const int width = const_tensor.shape().dim_size(0);
const TensorProto* proto = nullptr;
TF_CHECK_OK(GetNodeAttr(input_node->attrs(), "value", &proto));
Tensor const_tensor;
TF_CHECK_OK(MakeTensorFromProto(*proto, &const_tensor));
CHECK_EQ(DT_INT32, const_tensor.dtype());
// reshape tensor input to be rank 4.
// TODO(satok): Never assume rank is 4.
Tensor new_const_tensor(const_tensor.dtype(), TensorShape{4, 2});
for (int i = 0; i < PAD_HEIGHT; ++i) {
for (int j = 0; j < PAD_WIDTH; ++j) {
if (j < PAD_WIDTH - width) {
new_const_tensor.matrix<int32>()(j, i) = 0;
} else {
new_const_tensor.matrix<int32>()(j, i) =
const_tensor.matrix<int32>()(j - (PAD_WIDTH - width), i);
}
}
}
const int id = RegisterConstTensor(
new_const_tensor,
strings::StrCat(input_node->name(), "_", node.name(), "_1"));
GraphTransferNodeInput& node_input = *node_input_info.add_node_input();
node_input.set_node_id(id);
node_input.set_output_port(0);
} else {
LOG(FATAL);
}
AppendNodeParamsWithIoParams(
shape_refiner, node, node.name(), id, node.type_string(), op_type_id,
PADDING_NA_ID, node.num_inputs(), {}, node.num_outputs(),
false /* append_input */, true /* append_output */);
}
void GraphTransferer::RegisterInputNode(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node) {
const string op_type = node.type_string();
VLOG(1) << "Register input node: " << node.name() << ", " << op_type;
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
// TODO(satok): Set correct data type if it's given.
const int op_type_id = ops_definitions.GetOpIdFor("INPUT", {});
CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount())
<< "Op" << node.name() << ", " << op_type << " is not supported,"
<< op_type_id;
AppendNodeParamsWithIoParams(
shape_refiner, node, node.name(), id, node.type_string(), op_type_id,
PADDING_NA_ID, node.num_inputs(), {}, node.num_outputs(),
true /* append_input */, true /* append_output */);
}
void GraphTransferer::RegisterFlattenNode(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node) {
VLOG(1) << "Register flatten node: " << node.name();
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
// TODO(satok): Remove dependency to specific type
const string op_type = "FLATTEN";
// TODO(satok): Set correct data type if it's given.
const int op_type_id = ops_definitions.GetOpIdFor(op_type, {});
CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount());
AppendNodeParamsWithIoParams(
shape_refiner, node, node.name(), id, node.type_string(), op_type_id,
PADDING_NA_ID, node.num_inputs(), {}, node.num_outputs(),
true /* append_input */, true /* append_output */);
}
void GraphTransferer::RegisterGenericNode(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node) {
VLOG(1) << "Register generic node: " << node.name();
CHECK_EQ(node_name_to_id_cache_map_.count(node.name()), 1);
const int id = node_name_to_id_cache_map_[node.name()];
// TODO(satok): Set correct data type if it's given.
const int op_type_id = ops_definitions.GetOpIdFor(node.type_string(), {});
CHECK(op_type_id >= 0 && op_type_id < ops_definitions.GetTotalOpsCount());
AppendNodeParamsWithIoParams(
shape_refiner, node, node.name(), id, node.type_string(), op_type_id,
PADDING_NA_ID, node.num_inputs(), {}, node.num_outputs(),
true /* append_input */, true /* append_output */);
}
// TODO(satok): Remove this function.
// TODO(satok): Remove only_register_const_node.
Status GraphTransferer::RegisterNodeIfAllInputsAreCached(
const IRemoteFusedGraphOpsDefinitions& ops_definitions,
const ShapeRefiner& shape_refiner, const Node& node,
const bool only_register_const_node,
const std::vector<std::pair<string, Tensor>>& input_node_info_list,
const std::vector<string>& output_node_names) {
if (only_register_const_node && !node.IsConstant()) {
return Status();
}
CHECK(AreAllInputsCached(node));
return RegisterNode(ops_definitions, shape_refiner, node,
input_node_info_list, output_node_names);
}
// CAVEAT: Append inputs and outputs params accordingly
void GraphTransferer::AppendNodeParams(const string& name, const int id,
const string& type, const int type_id,
const int padding, const int inputs_size,
const std::vector<int>& extra_inputs,
const int outputs_size) {
GraphTransferNodeInfo& node_info = *graph_transfer_info_->add_node_info();
node_info.set_name(name);
node_info.set_node_id(id);
node_info.set_type_name(type);
node_info.set_soc_op_id(type_id);
node_info.set_padding_id(padding);
node_info.set_input_count(inputs_size +
static_cast<int>(extra_inputs.size()));
node_info.set_output_count(static_cast<int>(outputs_size));
}
void GraphTransferer::AddNodeInputByInputIndex(
const Node& node, const int idx,
GraphTransferNodeInputInfo* node_input_info) {
const Edge* edge = nullptr;
TF_CHECK_OK(node.input_edge(idx, &edge));
const Node* input_node = edge->src();
CHECK_NOTNULL(input_node);
const int port = edge->src_output();
const std::string& op_name = input_node->name();
CHECK_GT(node_name_to_id_cache_map_.count(op_name), 0) << op_name;
const int src_id = node_name_to_id_cache_map_[op_name];
GraphTransferNodeInput& node_input = *node_input_info->add_node_input();
node_input.set_node_id(src_id);
node_input.set_output_port(port);
}
void GraphTransferer::AppendNodeInputParams(
const int id, const Node& node, const std::vector<int>& extra_inputs) {
VLOG(1) << "Append input params: " << node.name() << ", " << node.num_inputs()
<< ", " << extra_inputs.size();
GraphTransferNodeInputInfo& node_input_info =
*graph_transfer_info_->add_node_input_info();
node_input_info.set_node_id(id);
for (int i = 0; i < node.num_inputs(); ++i) {
AddNodeInputByInputIndex(node, i, &node_input_info);
}
for (const int extra_input : extra_inputs) {
GraphTransferNodeInput& node_input = *node_input_info.add_node_input();
node_input.set_node_id(extra_input);
node_input.set_output_port(0);
}
}
void GraphTransferer::AppendNodeOutputParams(const ShapeRefiner& shape_refiner,
const int id, const Node& node) {
VLOG(1) << "Append output params: " << node.name() << ", "
<< node.num_outputs();
GraphTransferNodeOutputInfo& node_output_info =
*graph_transfer_info_->add_node_output_info();
node_output_info.set_node_id(id);
std::vector<DataType> data_types;
std::vector<TensorShape> shapes;
Status status = RemoteFusedGraphExecuteUtils::GetOutputTensorShapeType(
node.attrs(), &data_types, &shapes);
for (int i = 0; i < node.num_outputs(); ++i) {
int data_size = -1;
const int output_index = i;
const DataType dt = node.output_type(output_index);
const size_t max_bytes_per_data = DataTypeSize(dt);
shape_inference::InferenceContext* context =
shape_refiner.GetContext(&node);
if (context != nullptr && context->ValueKnown(context->NumElements(
context->output(output_index)))) {
const shape_inference::DimensionHandle num_elements_dim =
context->NumElements(context->output(output_index));
const int64 num_output_elements = context->Value(num_elements_dim);
data_size = max_bytes_per_data * num_output_elements;
if (status.ok()) {
TF_CHECK_OK(status);
CHECK_EQ(shapes.at(i).num_elements(), num_output_elements);
}
} else {
TF_CHECK_OK(status);
// Use attribute attached to node
data_size = max_bytes_per_data * shapes.at(i).num_elements();
}
CHECK_GE(data_size, 0);
node_output_info.add_max_byte_size(data_size);
}
}
void GraphTransferer::AppendNodeParamsWithIoParams(
const ShapeRefiner& shape_refiner, const Node& node, const string& name,
const int id, const string& type, const int type_id, const int padding,
const int inputs_size, const std::vector<int>& extra_inputs,
const int outputs_size, const bool append_input_params,
const bool append_output_params) {
VLOG(1) << "Append node with io params: " << node.name();
if (append_input_params) {
AppendNodeInputParams(id, node, extra_inputs);
}
if (append_output_params) {
AppendNodeOutputParams(shape_refiner, id, node);
}
AppendNodeParams(name, id, type, type_id, padding, inputs_size, extra_inputs,
outputs_size);
}
/* static */ std::array<int64, GraphTransferer::SHAPE_ARRAY_SIZE>
GraphTransferer::BuildShapeArray(
const shape_inference::ShapeHandle& shape_handle,
shape_inference::InferenceContext* context) {
switch (context->Rank(shape_handle)) {
case 0:
return std::array<int64, SHAPE_ARRAY_SIZE>{{1, 1, 1, 1}};
case 1:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{1, 1, 1, context->Value(context->Dim(shape_handle, 0))}};
case 2:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{1, 1, context->Value(context->Dim(shape_handle, 0)),
context->Value(context->Dim(shape_handle, 1))}};
case 3:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{1, context->Value(context->Dim(shape_handle, 0)),
context->Value(context->Dim(shape_handle, 1)),
context->Value(context->Dim(shape_handle, 2))}};
case 4:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{context->Value(context->Dim(shape_handle, 0)),
context->Value(context->Dim(shape_handle, 1)),
context->Value(context->Dim(shape_handle, 2)),
context->Value(context->Dim(shape_handle, 3))}};
default:
// TODO(satok): Support more ranks?
LOG(FATAL);
return std::array<int64, SHAPE_ARRAY_SIZE>();
}
}
/* static */ std::array<int64, GraphTransferer::SHAPE_ARRAY_SIZE>
GraphTransferer::ToTensorShapeArray(const TensorShape& shape) {
switch (shape.dims()) {
case 0:
return std::array<int64, SHAPE_ARRAY_SIZE>{{1, 1, 1, 1}};
case 1:
return std::array<int64, SHAPE_ARRAY_SIZE>{{1, 1, 1, shape.dim_size(0)}};
case 2:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{1, 1, shape.dim_size(0), shape.dim_size(1)}};
case 3:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{1, shape.dim_size(0), shape.dim_size(1), shape.dim_size(2)}};
case 4:
return std::array<int64, SHAPE_ARRAY_SIZE>{
{shape.dim_size(0), shape.dim_size(1), shape.dim_size(2),
shape.dim_size(3)}};
default:
// TODO(satok): Support more ranks?
LOG(FATAL);
return std::array<int64, SHAPE_ARRAY_SIZE>();
}
}
/* static */ string GraphTransferer::ToPaddingDebugString(const int padding) {
switch (padding) {
case 0:
return "NN_PAD_NA";
case Padding::VALID:
return "NN_PAD_VALID";
case Padding::SAME:
return "NN_PAD_SAME";
default:
LOG(FATAL);
return "";
}
}
GraphTransferer::TransferParamsComparator::TransferParamsComparator(
const std::unordered_map<int, std::unordered_set<int>>& dep_map)
: dependency_map_(dep_map) {}
bool GraphTransferer::TransferParamsComparator::operator()(
const GraphTransferNodeInfo& obj0, const GraphTransferNodeInfo& obj1) {
const int node_id0 = obj0.node_id();
const int node_id1 = obj1.node_id();
bool obj0_uses_obj1 = false;
if (dependency_map_.count(node_id0) > 0) {
obj0_uses_obj1 = dependency_map_.at(node_id0).count(node_id1) > 0;
}
bool obj1_uses_obj0 = false;
if (dependency_map_.count(node_id1) > 0) {
obj1_uses_obj0 = dependency_map_.at(node_id1).count(node_id0) > 0;
}
CHECK(!obj0_uses_obj1 || !obj1_uses_obj0);
if (obj0_uses_obj1) {
return false;
} else if (obj1_uses_obj0) {
return true;
}
// If there is no dependency between two nodes, it expects that
// the execution order follows node id order.
return node_id0 < node_id1;
}
/* static */ void GraphTransferer::FillDependencyRec(
const int node_id,
std::unordered_map<int, std::unordered_set<int>>& dep_map,
std::unordered_set<int>& completed) {
if (dep_map.count(node_id) == 0 || dep_map.at(node_id).empty() ||
completed.count(node_id) == 1) {
return;
}
CHECK_EQ(dep_map.count(node_id), 1);
// Complete children's dependency map
for (int child_node_id : dep_map.at(node_id)) {
CHECK(child_node_id != node_id);
if (completed.count(child_node_id) != 0) {
continue;
}
FillDependencyRec(child_node_id, dep_map, completed);
}
// Find additional depending ids
std::vector<int> depending_ids;
for (int child_node_id : dep_map.at(node_id)) {
if (dep_map.count(child_node_id) == 0) {
continue;
}
for (int depending_id : dep_map.at(child_node_id)) {
depending_ids.emplace_back(depending_id);
}
}
// Insert additional depending ids
for (int depending_id : depending_ids) {
if (dep_map.at(node_id).count(depending_id) == 0) {
dep_map.at(node_id).emplace(depending_id);
}
}
// DP: Record completed node id
completed.emplace(node_id);
}
/* static */ Status GraphTransferer::MakeTensorFromProto(
const TensorProto& tensor_proto, Tensor* tensor) {
if (tensor_proto.dtype() > 0 && tensor_proto.dtype() <= DataType_MAX) {
Tensor parsed(tensor_proto.dtype());
if (parsed.FromProto(cpu_allocator(), tensor_proto)) {
*tensor = parsed;
return Status::OK();
}
}
return errors::InvalidArgument("Cannot parse tensor from proto: ",
tensor_proto.DebugString());
}
void GraphTransferer::ClearCache() {
node_name_cache_list_.clear();
node_name_to_id_cache_map_.clear();
}
void GraphTransferer::DumpNodeTransferParams() const {
LOG(INFO) << "*** Const Nodes ***";
for (const GraphTransferConstNodeInfo& params :
graph_transfer_info_->const_node_info()) {
// TODO(satok): Stop assuming shape size is 4.
CHECK_EQ(params.shape_size(), 4);
LOG(INFO) << "[ " << params.node_id() << " \"" << params.name()
<< "\" (Const)";
LOG(INFO) << " shape: " << params.shape(0) << params.shape(1)
<< params.shape(2) << params.shape(3);
LOG(INFO) << " data_name: "
<< (params.data().length() <= 0
? ""
: DATA_NODE_PREFIX + ToString(params.node_id()));
LOG(INFO) << " data_size: " << params.data().length() << " bytes"
<< " ]";
}
LOG(INFO) << "******\n";
LOG(INFO) << "*** Op Nodes ***";
for (const GraphTransferNodeInfo& params :
graph_transfer_info_->node_info()) {
LOG(INFO) << "[ " << params.node_id() << " \"" << params.name();
LOG(INFO) << " type: " << params.type_name();
LOG(INFO) << " padding: " << ToPaddingDebugString(params.padding_id());
LOG(INFO) << " inputs: " << INPUTS_NODE_PREFIX + ToString(params.node_id())
<< ", size = " << params.input_count();
LOG(INFO) << " outputs: "
<< (params.output_count() <= 0
? NULL_OUTPUT_NAME
: (OUTPUTS_NODE_PREFIX + ToString(params.node_id())))
<< ", size = " << params.output_count() << " ]";
}
LOG(INFO) << "******\n";
LOG(INFO) << "*** Node input params ***";
for (const GraphTransferNodeInputInfo& params :
graph_transfer_info_->node_input_info()) {
LOG(INFO) << "[ " << params.node_id() << " ]";
for (const GraphTransferNodeInput& node_input : params.node_input()) {
LOG(INFO) << " src node id = " << node_input.node_id()
<< ", output port = " << node_input.output_port();
}
}
LOG(INFO) << "******\n";
LOG(INFO) << "*** Node output params ***";
for (const GraphTransferNodeOutputInfo& params :
graph_transfer_info_->node_output_info()) {
LOG(INFO) << "[ " << params.node_id() << " ]";
for (const int max_size : params.max_byte_size()) {
LOG(INFO) << " max_size = " << max_size;
}
}
LOG(INFO) << "******\n";
}
void GraphTransferer::DumpVerificationStringOfNodeTransferParams() const {
for (const GraphTransferConstNodeInfo& params :
graph_transfer_info_->const_node_info()) {
std::stringstream sstream;
// TODO(satok): Stop assuming shape size is 4.
CHECK_EQ(params.shape_size(), 4);
sstream << "---(CONST) [" << std::hex << params.node_id() << std::dec << ","
<< params.shape(0) << "," << params.shape(1) << ","
<< params.shape(2) << "," << params.shape(3) << ","
<< (params.data().length() <= 0
? ""
: DATA_NODE_PREFIX + ToString(params.node_id()))
<< "," << params.data().length() << "," << params.name() << "]";
LOG(INFO) << sstream.str();
}
LOG(INFO) << "Const node count = "
<< graph_transfer_info_->const_node_info_size();
for (const GraphTransferNodeInfo& params :
graph_transfer_info_->node_info()) {
std::stringstream sstream;
sstream << "---(OP) [" << params.name().c_str() << "," << std::hex
<< params.node_id() << std::dec << "," << params.soc_op_id() << ","
<< ToPaddingDebugString(params.padding_id()) << ","
<< INPUTS_NODE_PREFIX + ToString(params.node_id()) << ","
<< params.input_count() << ","
<< (params.output_count() <= 0
? NULL_OUTPUT_NAME
: (OUTPUTS_NODE_PREFIX + ToString(params.node_id())))
<< "," << params.output_count() << "," << params.type_name() << "]";
LOG(INFO) << sstream.str();
}
LOG(INFO) << "Op node count = " << graph_transfer_info_->node_info_size();
for (const GraphTransferNodeInputInfo& params :
graph_transfer_info_->node_input_info()) {
std::stringstream sstream;
sstream << "---(INPUT) [" << std::hex << params.node_id() << std::dec;
for (const GraphTransferNodeInput& node_input : params.node_input()) {
sstream << "," << std::hex << node_input.node_id() << std::dec << ","
<< node_input.output_port();
}
sstream << "]";
LOG(INFO) << sstream.str();
}
LOG(INFO) << "Input params count = "
<< graph_transfer_info_->node_input_info_size();
for (const GraphTransferNodeOutputInfo& params :
graph_transfer_info_->node_output_info()) {
std::stringstream sstream;
sstream << "---(OUTPUT) [" << std::hex << params.node_id() << std::dec;
for (const int max_size : params.max_byte_size()) {
sstream << "," << max_size;
}
sstream << "]";
LOG(INFO) << sstream.str();
}
LOG(INFO) << "Output params count = "
<< graph_transfer_info_->node_output_info_size();
}
} // namespace tensorflow
| [
"gardener@tensorflow.org"
] | gardener@tensorflow.org |
d2e0f380326ce9094ebfd6c28b51dabdffc21d35 | 8fb258618cb55a2a18de4c1853d0e1dd6401b0e9 | /bin/qimaster/qimastermain.cpp | de0ef2b01eadb4d1ebe8aabefa83d443280dd9d0 | [] | no_license | wenhuizhang/libqi | 133702c01ee9897fbc0b9d6b4330937ed94ac336 | 1b5782824e03a09de02e2263d46d74b82ab7dac7 | refs/heads/master | 2020-06-13T04:30:08.287368 | 2016-11-17T17:33:54 | 2016-11-17T17:33:54 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,441 | cpp | /*
** Author(s):
** - Herve Cuche <hcuche@aldebaran-robotics.com>
**
** Copyright (C) 2012 Aldebaran Robotics
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <qi/log.hpp>
#include <qi/application.hpp>
#include <qi/session.hpp>
qiLogCategory("qimaster");
int main(int argc, char *argv[])
{
qi::Application app(argc, argv);
if (argc == 2 &&
(strcmp(argv[0], "-h") == 0 || strcmp(argv[1], "--help") == 0))
{
std::cerr << "Usage: " << argv[0] << " [ENDPOINTS...]" << std::endl;
return 0;
}
{
qi::Session sd;
std::vector<qi::Url> endpoints;
if (argc == 1)
{
endpoints.push_back("tcp://0.0.0.0:9559");
}
else
{
for (int i = 1; i < argc; i++)
{
qi::Url url(argv[i]);
if (url.protocol() == "tcps")
{
sd.setIdentity(qi::path::findData("qi", "server.key"),
qi::path::findData("qi", "server.crt"));
}
endpoints.push_back(url);
}
}
for (std::vector<qi::Url>::const_iterator it = endpoints.begin();
it != endpoints.end();
it++)
{
qi::Future<void> f = sd.listenStandalone(*it);
f.wait(3000);
if (f.hasError())
{
qiLogError() << "Failed to listen on " << it->str() <<
". Is there another service running on this address?";
exit(1);
}
}
app.run();
}
return 0;
}
| [
"hcuche@aldebaran.com"
] | hcuche@aldebaran.com |
d161bb63aff0c57132b4292193fbba447c4d3345 | 4dcde7b8b10bdee8e2a582d1e6fb1fb4958e9d58 | /c_cpp/c++_primer/ch2/ex2-37.cpp | 146996618bc95741ff8251883f7d7ea48234fc95 | [] | no_license | wangfudex/practice | f103d1453cb917288b5b1101d8e9f6ae17754cbd | ce43a434a4f728d05e896869d3430d600b6c2dbb | refs/heads/master | 2021-06-16T14:19:03.490600 | 2017-04-16T14:59:59 | 2017-04-16T14:59:59 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 311 | cpp | #include <iostream>
int main(void)
{
int a = 3, b = 4;
decltype(a) c = a;
c = 1;
std::cout << a << std::endl; // should be 3
decltype(a = b) d = a; // The type is a reference to the type of the left-hand operand. So it is int&
d = 1;
std::cout << a << std::endl; // should be 1
}
| [
"j84255801912@gmail.com"
] | j84255801912@gmail.com |
d5c7bc24d2b35419f4a3e92aec555cbec3d005ab | 9989ec29859d067f0ec4c7b82e6255e227bd4b54 | /atcoder.jp/agc_015/agc015_c.cpp | 3b2f379849b1f13ea156b92bf1213a467b8b1373 | [] | no_license | hikko624/prog_contest | 8fa8b0e36e4272b6ad56d6506577c13f9a11c9de | 34350e2d298deb52c99680d72345ca44ab6f8849 | refs/heads/master | 2022-09-10T20:43:28.046873 | 2022-08-26T13:59:29 | 2022-08-26T13:59:29 | 217,740,540 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 11 | cpp | // agc015_c | [
"hikko624@gmail.com"
] | hikko624@gmail.com |
39ab543db2cc0877722546f4eae62b0886f577e4 | 71ad97ccbf9c5228007ba606405b14a7185cb596 | /src/Wandering/ImageMenuItem.cpp | 6cac7cf44784e1d9f49112f022e8c7cf51f67f83 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference",
"Unlicense"
] | permissive | NightElfik/Wandering | a29c7772cd40af41164ab6855670e64b43fa0162 | 6a4f0313eac84e7f2cd76f3bf7283fff34e9a067 | refs/heads/master | 2020-04-06T03:41:32.986472 | 2015-01-10T07:06:17 | 2015-01-10T07:06:17 | 28,760,011 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,553 | cpp | #pragma once
#include <string>
#include "IMenuItem.h"
#include "AsciiFont.h"
class ImageMenuItem : public IMenuItem {
protected:
std::string _strImage;
void (*_action)();
public:
ImageMenuItem(const std::string& text, void(*onPressed)() = nullptr, int yOffset = 1, bool focusable = false, Align align = Center) {
AsciiFont::MeasureText(text, _width, _height);
_strImage = AsciiFont::ConvertText(text);
_itemAlign = align;
_yOffset = yOffset;
_isFocusable = focusable;
_action = onPressed;
}
ImageMenuItem(int width, int height, std::string stringImage, void(*onPressed)() = nullptr, int yOffset = 1, bool focusable = false, Align align = Center) {
if (width * height != stringImage.length()) {
stringImage = "width * height != str.length";
width = stringImage.length();
height = 1;
}
_strImage = stringImage;
_width = width;
_height = height;
_itemAlign = align;
_yOffset = yOffset;
_isFocusable = focusable;
_action = onPressed;
}
~ImageMenuItem() {
_action = nullptr;
}
void ChangeToAsciiArtText(const std::string& text) {
AsciiFont::MeasureText(text, _width, _height);
_strImage = AsciiFont::ConvertText(text);
}
virtual bool KeyPressed(int key) {
if (_action != nullptr && key == 13) {
_action();
return true;
}
return false;
}
virtual void PrintAt(ScreenBuffer* buffer, int x, int y) {
for (int yStr = 0; yStr < _height; yStr++) {
for (int xStr = 0; xStr < _width; xStr++) {
buffer->SetCharAt(x + xStr, y + yStr, _strImage[yStr * _width + xStr]);
}
}
}
}; | [
"git@marekfiser.cz"
] | git@marekfiser.cz |
7862c249b945174cc78777b4cbf5f24d2faa521f | 6cd69d24276d418be9fb3ad5fbb850bdcaca9f7e | /oss_src/fileio/file_handle_pool.hpp | 6fe26b6187ef02de4cfbbeb18b79cd63732eb415 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | charles2648/SFrame | e8cd14074932635af067aa20a86d1a9cbf7cf698 | 43fdd3ed9fde4ec0f26d548b5f1eebb4cdf1bea5 | refs/heads/master | 2021-01-18T11:23:21.447110 | 2016-03-16T08:51:56 | 2016-03-16T08:51:56 | 54,029,970 | 1 | 0 | null | 2016-03-16T12:29:02 | 2016-03-16T12:29:02 | null | UTF-8 | C++ | false | false | 3,484 | hpp | /**
* Copyright (C) 2015 Dato, Inc.
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/
#ifndef GRAPHLAB_FILEIO_FILE_HANDLE_POOL_HPP
#define GRAPHLAB_FILEIO_FILE_HANDLE_POOL_HPP
#include <map>
#include <string>
#include <atomic>
#include <parallel/mutex.hpp>
#include <fileio/file_ownership_handle.hpp>
namespace graphlab {
namespace fileio {
/**
* A global file lifespan manager that manages life time for non temporary files
* that are currently in use by any SArray(including the array index file and the
* segment files).
*
* Permanent files used by SArray can be removed when user saves a SArray to a
* directory where there is already a SArray saved there. In case there is some
* SArray actively referencing the files in the directory, we will delay deletion
* of those files until nobody is referencing those files. new files will be
* created under the directory to save the new SArray and the directory index
* will correctly point to the new files.
*
* A file_handle object is created for each file that is in use by SArray. All
* SArrays referencing those files keep a shared pointer to the file handle object.
* On reading from a directory, SAray registers the files with global file_handle_pool,
* When SArray is out of scope, the corresponding ref to the file_handle is removed.
* Once all ref of a given file_handle goes away, the files may or may not be deleted
* depend on whether or not the files are overwritten.
*
* The pool itself keeps a weak pointer to the file_handle object so the files can
* be deleted when all SArrays referencing the file are gone.
*/
class file_handle_pool {
public:
/**
* Singleton retriever
**/
static file_handle_pool& get_instance();
/**
* Register with file pool that a file is in use.
* Returns a file_ownership_handle to the caller that can do auto deletion
* of the file if it goes out of scope.
*
* \param file_name The name of the file to be registered
*
* Returns a shared pointer to the newly created file_ownership_handle
**/
std::shared_ptr<file_ownership_handle> register_file(const std::string& file_name);
/**
* Try to mark the file for deletion, returns success if the mark is
* done successfuly, other wise, the global file pool doesn't know
* about the file, caller is responsible for deleting the files
* The marked files will be deleted when all users are out of scope
*
* \param file_name The name of the file to be marked for deletion
**/
bool mark_file_for_delete(std::string file_name);
/**
* Unmarks a previously marked file for deletion. Returns true if the file
* was previously marked for deletion. False otherwise.
*/
bool unmark_file_for_delete(std::string file_name);
private:
file_handle_pool() {};
file_handle_pool(file_handle_pool const&) = delete;
file_handle_pool& operator=(file_handle_pool const&) = delete;
std::shared_ptr<file_ownership_handle> get_file_handle(const std::string& file_name);
private:
graphlab::mutex m_mutex;
// We need to periodically clear out the map below in order to avoid
// a memory leak. Here we clear out all the expired weak pointers
// every 16K times we register a new file.
size_t num_file_registers = 0;
std::map<std::string, std::weak_ptr<file_ownership_handle>> m_file_handles;
};
} // namespace fileio
} // namespace graphlab
#endif
| [
"toby@dato.com"
] | toby@dato.com |
79749b884ebdc1992c37f389762a9f02c78ecf44 | 47ff8543c73dab22c7854d9571dfc8d5f467ee8c | /BOJ/2010/2010.cpp | df01fe29fbfcbc5770107c97254fc7e6862a1cd4 | [] | no_license | eldsg/BOJ | 4bb0c93dc60783da151e685530fa9a511df3a141 | 6bd15e36d69ce1fcf208d193d5e9067de9bb405e | refs/heads/master | 2020-04-16T02:18:55.808362 | 2017-11-28T11:02:37 | 2017-11-28T11:02:37 | 55,879,791 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 246 | cpp | #include<iostream>
using namespace std;
int main(){
int plugset, result = 0;
int *plug;
cin >> plugset;
plug = new int[plugset];
for (int i = 0; i < plugset; i++){
cin >> plug[i];
result += plug[i] - 1;
}
cout << result + 1 << endl;
} | [
"kgm0219@gmail.com"
] | kgm0219@gmail.com |
76bc053a369fdb60d671f2dcf8f8a72dda010cfe | e56f43b4127ec703a01c8f187b180693300107ad | /MyQueue.hpp | 29fb40d7a2de3d7e96fdb67e0dae9c9b7707f58d | [] | no_license | mrtuborg/FraudulentNotifications | 422565b58cc972b56457cf799a862b966e2ee2b7 | 180e800f1d8f949da41a5e6a5a9289a850b967a3 | refs/heads/master | 2020-05-05T04:26:01.165941 | 2019-05-20T06:15:27 | 2019-05-20T06:15:27 | 179,711,894 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,759 | hpp | #ifndef MYQUEUE_HPP
#define MYQUEUE_HPP
#include <cstddef>
#include <vector>
class myQueue
{
public:
typedef enum {
QUICK_SORT_HOARE,
QUICK_SORT_LOMUTO,
COUNTING_SORT
} sort_t;
typedef struct queue_node_s {
int value;
size_t index;
queue_node_s* next;
queue_node_s* prev;
} queue_node_t;
private:
queue_node_t *head;
queue_node_t *tail;
size_t size;
myQueue::queue_node_t *getNodeByIndex(int index);
int findMax(queue_node_t *in);
void printQueue(void *in, int start = -1, int end = -1);
void printDequeue(void *in, int start = -1, int end = -1);
// Quick sort: O(n^2) .. O(n*log(n))
int hoare_partitionning(int left, int right);
int lomuto_partitionning(int left, int right);
int hoare_quicksort(int start, int end);
int lomuto_quicksort(int start, int end);
// Counting sort: O(n+k)
int count_array(int *out, int k);
int counting_sort(int start, int end);
public:
std::vector<queue_node_t *> arr;
myQueue();
~myQueue();
void xchg(queue_node_t *x, queue_node_t *y);
int addItem(int val);
int addItem(int* array, size_t size);
queue_node_t* getPrevious(queue_node_t *node);
int deleteItem(queue_node_t *node, queue_node_t *prev_node = NULL);
int rc_deleteList(queue_node_t *node);
int it_deleteList(queue_node_t *node);
int sort(sort_t type);
float median();
void printQueue();
void printDequeue();
};
#endif // MYARRAY_HPP
| [
"vn@cypodgroup.com"
] | vn@cypodgroup.com |
e286b68d6c38ae331abdc11e2c353667a3798cf0 | 2de404c4214085e5ce0a3e77ab4fb2f33cd7b969 | /src/rpcdump.cpp | 30db4b4d9473fad22bc6587f1bec9b62d29f9a64 | [
"MIT"
] | permissive | replier2222/BitSolo | 2a5f610d3c941ba4e380c9acc496797ed099704e | 79e1920ad8df7eae02fa4840f0e64f6fbfefd23b | refs/heads/master | 2020-03-19T18:04:06.426889 | 2018-04-08T13:45:42 | 2018-04-08T13:45:42 | 136,792,353 | 0 | 0 | MIT | 2018-06-10T08:34:49 | 2018-06-10T08:34:48 | null | UTF-8 | C++ | false | false | 18,901 | cpp | // Copyright (c) 2009-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2015-2017 The PIVX developers
// Copyright (c) 2018 The BitSolo developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "bip38.h"
#include "init.h"
#include "main.h"
#include "rpcserver.h"
#include "script/script.h"
#include "script/standard.h"
#include "sync.h"
#include "util.h"
#include "utilstrencodings.h"
#include "utiltime.h"
#include "wallet.h"
#include <fstream>
#include <secp256k1.h>
#include <stdint.h>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <openssl/aes.h>
#include <openssl/sha.h>
#include "json/json_spirit_value.h"
using namespace json_spirit;
using namespace std;
void EnsureWalletIsUnlocked();
std::string static EncodeDumpTime(int64_t nTime)
{
return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
}
int64_t static DecodeDumpTime(const std::string& str)
{
static const boost::posix_time::ptime epoch = boost::posix_time::from_time_t(0);
static const std::locale loc(std::locale::classic(),
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ"));
std::istringstream iss(str);
iss.imbue(loc);
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time);
iss >> ptime;
if (ptime.is_not_a_date_time())
return 0;
return (ptime - epoch).total_seconds();
}
std::string static EncodeDumpString(const std::string& str)
{
std::stringstream ret;
BOOST_FOREACH (unsigned char c, str) {
if (c <= 32 || c >= 128 || c == '%') {
ret << '%' << HexStr(&c, &c + 1);
} else {
ret << c;
}
}
return ret.str();
}
std::string DecodeDumpString(const std::string& str)
{
std::stringstream ret;
for (unsigned int pos = 0; pos < str.length(); pos++) {
unsigned char c = str[pos];
if (c == '%' && pos + 2 < str.length()) {
c = (((str[pos + 1] >> 6) * 9 + ((str[pos + 1] - '0') & 15)) << 4) |
((str[pos + 2] >> 6) * 9 + ((str[pos + 2] - '0') & 15));
pos += 2;
}
ret << c;
}
return ret.str();
}
Value importprivkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
"importprivkey \"bitsoloprivkey\" ( \"label\" rescan )\n"
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
"\nArguments:\n"
"1. \"bitsoloprivkey\" (string, required) The private key (see dumpprivkey)\n"
"2. \"label\" (string, optional, default=\"\") An optional label\n"
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
"\nNote: This call can take minutes to complete if rescan is true.\n"
"\nExamples:\n"
"\nDump a private key\n" +
HelpExampleCli("dumpprivkey", "\"myaddress\"") +
"\nImport the private key with rescan\n" + HelpExampleCli("importprivkey", "\"mykey\"") +
"\nImport using a label and without rescan\n" + HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") +
"\nAs a JSON-RPC call\n" + HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false"));
EnsureWalletIsUnlocked();
string strSecret = params[0].get_str();
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();
// Whether to perform rescan after import
bool fRescan = true;
if (params.size() > 2)
fRescan = params[2].get_bool();
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);
if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
CKey key = vchSecret.GetKey();
if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
CPubKey pubkey = key.GetPubKey();
assert(key.VerifyPubKey(pubkey));
CKeyID vchAddress = pubkey.GetID();
{
pwalletMain->MarkDirty();
pwalletMain->SetAddressBook(vchAddress, strLabel, "receive");
// Don't throw error in case a key is already there
if (pwalletMain->HaveKey(vchAddress))
return Value::null;
pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
if (!pwalletMain->AddKeyPubKey(key, pubkey))
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
// whenever a key is imported, we need to scan the whole chain
pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
if (fRescan) {
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
}
}
return Value::null;
}
Value importaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
"importaddress \"address\" ( \"label\" rescan )\n"
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend.\n"
"\nArguments:\n"
"1. \"address\" (string, required) The address\n"
"2. \"label\" (string, optional, default=\"\") An optional label\n"
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
"\nNote: This call can take minutes to complete if rescan is true.\n"
"\nExamples:\n"
"\nImport an address with rescan\n" +
HelpExampleCli("importaddress", "\"myaddress\"") +
"\nImport using a label without rescan\n" + HelpExampleCli("importaddress", "\"myaddress\" \"testing\" false") +
"\nAs a JSON-RPC call\n" + HelpExampleRpc("importaddress", "\"myaddress\", \"testing\", false"));
CScript script;
CBitcoinAddress address(params[0].get_str());
if (address.IsValid()) {
script = GetScriptForDestination(address.Get());
} else if (IsHex(params[0].get_str())) {
std::vector<unsigned char> data(ParseHex(params[0].get_str()));
script = CScript(data.begin(), data.end());
} else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid BSL address or script");
}
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();
// Whether to perform rescan after import
bool fRescan = true;
if (params.size() > 2)
fRescan = params[2].get_bool();
{
if (::IsMine(*pwalletMain, script) == ISMINE_SPENDABLE)
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
// add to address book or update label
if (address.IsValid())
pwalletMain->SetAddressBook(address.Get(), strLabel, "receive");
// Don't throw error in case an address is already there
if (pwalletMain->HaveWatchOnly(script))
return Value::null;
pwalletMain->MarkDirty();
if (!pwalletMain->AddWatchOnly(script))
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
if (fRescan) {
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
pwalletMain->ReacceptWalletTransactions();
}
}
return Value::null;
}
Value importwallet(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"importwallet \"filename\"\n"
"\nImports keys from a wallet dump file (see dumpwallet).\n"
"\nArguments:\n"
"1. \"filename\" (string, required) The wallet file\n"
"\nExamples:\n"
"\nDump the wallet\n" +
HelpExampleCli("dumpwallet", "\"test\"") +
"\nImport the wallet\n" + HelpExampleCli("importwallet", "\"test\"") +
"\nImport using the json rpc call\n" + HelpExampleRpc("importwallet", "\"test\""));
EnsureWalletIsUnlocked();
ifstream file;
file.open(params[0].get_str().c_str(), std::ios::in | std::ios::ate);
if (!file.is_open())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
int64_t nTimeBegin = chainActive.Tip()->GetBlockTime();
bool fGood = true;
int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
file.seekg(0, file.beg);
pwalletMain->ShowProgress(_("Importing..."), 0); // show progress dialog in GUI
while (file.good()) {
pwalletMain->ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100))));
std::string line;
std::getline(file, line);
if (line.empty() || line[0] == '#')
continue;
std::vector<std::string> vstr;
boost::split(vstr, line, boost::is_any_of(" "));
if (vstr.size() < 2)
continue;
CBitcoinSecret vchSecret;
if (!vchSecret.SetString(vstr[0]))
continue;
CKey key = vchSecret.GetKey();
CPubKey pubkey = key.GetPubKey();
assert(key.VerifyPubKey(pubkey));
CKeyID keyid = pubkey.GetID();
if (pwalletMain->HaveKey(keyid)) {
LogPrintf("Skipping import of %s (key already present)\n", CBitcoinAddress(keyid).ToString());
continue;
}
int64_t nTime = DecodeDumpTime(vstr[1]);
std::string strLabel;
bool fLabel = true;
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
if (boost::algorithm::starts_with(vstr[nStr], "#"))
break;
if (vstr[nStr] == "change=1")
fLabel = false;
if (vstr[nStr] == "reserve=1")
fLabel = false;
if (boost::algorithm::starts_with(vstr[nStr], "label=")) {
strLabel = DecodeDumpString(vstr[nStr].substr(6));
fLabel = true;
}
}
LogPrintf("Importing %s...\n", CBitcoinAddress(keyid).ToString());
if (!pwalletMain->AddKeyPubKey(key, pubkey)) {
fGood = false;
continue;
}
pwalletMain->mapKeyMetadata[keyid].nCreateTime = nTime;
if (fLabel)
pwalletMain->SetAddressBook(keyid, strLabel, "receive");
nTimeBegin = std::min(nTimeBegin, nTime);
}
file.close();
pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI
CBlockIndex* pindex = chainActive.Tip();
while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200)
pindex = pindex->pprev;
if (!pwalletMain->nTimeFirstKey || nTimeBegin < pwalletMain->nTimeFirstKey)
pwalletMain->nTimeFirstKey = nTimeBegin;
LogPrintf("Rescanning last %i blocks\n", chainActive.Height() - pindex->nHeight + 1);
pwalletMain->ScanForWalletTransactions(pindex);
pwalletMain->MarkDirty();
if (!fGood)
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");
return Value::null;
}
Value dumpprivkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"dumpprivkey \"bitsoloaddress\"\n"
"\nReveals the private key corresponding to 'bitsoloaddress'.\n"
"Then the importprivkey can be used with this output\n"
"\nArguments:\n"
"1. \"bitsoloaddress\" (string, required) The bitsolo address for the private key\n"
"\nResult:\n"
"\"key\" (string) The private key\n"
"\nExamples:\n" +
HelpExampleCli("dumpprivkey", "\"myaddress\"") + HelpExampleCli("importprivkey", "\"mykey\"") + HelpExampleRpc("dumpprivkey", "\"myaddress\""));
EnsureWalletIsUnlocked();
string strAddress = params[0].get_str();
CBitcoinAddress address;
if (!address.SetString(strAddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid BSL address");
CKeyID keyID;
if (!address.GetKeyID(keyID))
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
CKey vchSecret;
if (!pwalletMain->GetKey(keyID, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
return CBitcoinSecret(vchSecret).ToString();
}
Value dumpwallet(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"dumpwallet \"filename\"\n"
"\nDumps all wallet keys in a human-readable format.\n"
"\nArguments:\n"
"1. \"filename\" (string, required) The filename\n"
"\nExamples:\n" +
HelpExampleCli("dumpwallet", "\"test\"") + HelpExampleRpc("dumpwallet", "\"test\""));
EnsureWalletIsUnlocked();
ofstream file;
file.open(params[0].get_str().c_str());
if (!file.is_open())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file");
std::map<CKeyID, int64_t> mapKeyBirth;
std::set<CKeyID> setKeyPool;
pwalletMain->GetKeyBirthTimes(mapKeyBirth);
pwalletMain->GetAllReserveKeys(setKeyPool);
// sort time/key pairs
std::vector<std::pair<int64_t, CKeyID> > vKeyBirth;
for (std::map<CKeyID, int64_t>::const_iterator it = mapKeyBirth.begin(); it != mapKeyBirth.end(); it++) {
vKeyBirth.push_back(std::make_pair(it->second, it->first));
}
mapKeyBirth.clear();
std::sort(vKeyBirth.begin(), vKeyBirth.end());
// produce output
file << strprintf("# Wallet dump created by BSL %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime()));
file << "\n";
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
const CKeyID& keyid = it->second;
std::string strTime = EncodeDumpTime(it->first);
std::string strAddr = CBitcoinAddress(keyid).ToString();
CKey key;
if (pwalletMain->GetKey(keyid, key)) {
if (pwalletMain->mapAddressBook.count(keyid)) {
file << strprintf("%s %s label=%s # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, EncodeDumpString(pwalletMain->mapAddressBook[keyid].name), strAddr);
} else if (setKeyPool.count(keyid)) {
file << strprintf("%s %s reserve=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
} else {
file << strprintf("%s %s change=1 # addr=%s\n", CBitcoinSecret(key).ToString(), strTime, strAddr);
}
}
}
file << "\n";
file << "# End of dump\n";
file.close();
return Value::null;
}
Value bip38encrypt(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
"bip38encrypt \"bitsoloaddress\"\n"
"\nEncrypts a private key corresponding to 'bitsoloaddress'.\n"
"\nArguments:\n"
"1. \"bitsoloaddress\" (string, required) The bitsolo address for the private key (you must hold the key already)\n"
"2. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with - Valid special chars: !#$%&'()*+,-./:;<=>?`{|}~ \n"
"\nResult:\n"
"\"key\" (string) The encrypted private key\n"
"\nExamples:\n");
EnsureWalletIsUnlocked();
string strAddress = params[0].get_str();
string strPassphrase = params[1].get_str();
CBitcoinAddress address;
if (!address.SetString(strAddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid BSL address");
CKeyID keyID;
if (!address.GetKeyID(keyID))
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
CKey vchSecret;
if (!pwalletMain->GetKey(keyID, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
uint256 privKey = vchSecret.GetPrivKey_256();
string encryptedOut = BIP38_Encrypt(strAddress, strPassphrase, privKey);
Object result;
result.push_back(Pair("Addess", strAddress));
result.push_back(Pair("Encrypted Key", encryptedOut));
return result;
}
Value bip38decrypt(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
"bip38decrypt \"bitsoloaddress\"\n"
"\nDecrypts and then imports password protected private key.\n"
"\nArguments:\n"
"1. \"passphrase\" (string, required) The passphrase you want the private key to be encrypted with\n"
"2. \"encryptedkey\" (string, required) The encrypted private key\n"
"\nResult:\n"
"\"key\" (string) The decrypted private key\n"
"\nExamples:\n");
EnsureWalletIsUnlocked();
/** Collect private key and passphrase **/
string strPassphrase = params[0].get_str();
string strKey = params[1].get_str();
uint256 privKey;
bool fCompressed;
if (!BIP38_Decrypt(strPassphrase, strKey, privKey, fCompressed))
throw JSONRPCError(RPC_WALLET_ERROR, "Failed To Decrypt");
Object result;
result.push_back(Pair("privatekey", HexStr(privKey)));
CKey key;
key.Set(privKey.begin(), privKey.end(), fCompressed);
if (!key.IsValid())
throw JSONRPCError(RPC_WALLET_ERROR, "Private Key Not Valid");
CPubKey pubkey = key.GetPubKey();
pubkey.IsCompressed();
assert(key.VerifyPubKey(pubkey));
result.push_back(Pair("Address", CBitcoinAddress(pubkey.GetID()).ToString()));
CKeyID vchAddress = pubkey.GetID();
{
pwalletMain->MarkDirty();
pwalletMain->SetAddressBook(vchAddress, "", "receive");
// Don't throw error in case a key is already there
if (pwalletMain->HaveKey(vchAddress))
throw JSONRPCError(RPC_WALLET_ERROR, "Key already held by wallet");
pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
if (!pwalletMain->AddKeyPubKey(key, pubkey))
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
// whenever a key is imported, we need to scan the whole chain
pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
}
return result;
}
| [
"root"
] | root |
7bb6f611732267c4d849c61c6b306c0fa2c7fc9d | 888c421f1adf45b49474aeb46e508bb67f7f36f7 | /CCrump.cpp | c64486e5cc2d2550015f286efa811d4450b33cf7 | [] | no_license | lvzl20/OpencvTest | e3f00546f3ae6de56d9652407a84aa81332952a5 | 1a5650ad0e6c6b37acf4aead7dcdcaf3d8ac64d8 | refs/heads/master | 2023-04-28T11:04:05.978590 | 2021-05-20T15:22:28 | 2021-05-20T15:22:28 | 369,241,749 | 0 | 0 | null | null | null | null | GB18030 | C++ | false | false | 2,594 | cpp | #include "CCrump.h"
#include "CTools.h"
CCrump::CCrump(){
}
CCrump::~CCrump(){
}
void CCrump::Init(int x, int y) {
m_Flag = 1;
m_pos.x = x;
m_pos.y = y;
m_frameid = 0;
m_TimeCount = 15;//计时器 倒计时
char name[1000] = { 0 };
for (int i = 0; i < 4; i++) {
sprintf_s(name, "map/crump%d.bmp", i);
m_Image[i] = cv::imread(name);
}
//加载冲击波动画
char name1[] = "map/shockwave-001.bmp";
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
sprintf_s(name1, "map/shockwave-%d%02d.bmp", i, j);
m_ShockWavesImgs[i][j] = cv::imread(name1);
}
}
}
void CCrump::CopyToBack(cv::Mat& showimg) {
if (m_Flag ==0)
return;//炸弹爆炸则不绘制
CTools::CopyToBack(showimg, m_Image[m_frameid], m_pos.x, m_pos.y, 255, 0, 0,true);
}
void CCrump::CrumpChange(cv::Mat& showimg,CGameMap& map) {
if (m_Flag == 0) //炸弹已爆炸,m_Flag为零,则不再有效
return;
m_TimeCount--;
if (m_TimeCount >= 5) {
m_frameid++;
if (m_frameid > 1)//仅循环显示炸弹动画的前两帧,处于待爆炸状态
m_frameid = 0;
}
else if (m_TimeCount < 5) {
m_frameid = 2;
map.ClearMap(m_pos.x, m_pos.y);
CTools::CopyToBack(showimg, m_Image[m_frameid], m_pos.x, m_pos.y, 255, 0, 0, true);
//显示冲击波
int dir[4][2] = {
-1,0,
0,-1,
1,0,
0,1 };
for (int i = 0; i < 4; i++)
{
if (map.m_Map[m_pos.x / 40][m_pos.y / 40] < 5
&& m_pos.x / 40 + dir[i][0] >= 0 //左边界判断
&& m_pos.y / 40 + dir[i][1] >= 0 //上边界判断
&& m_pos.x / 40 + dir[i][0] <= 15 //右边界判断
&& m_pos.y / 40 + dir[i][1] <= 15)//下边界判断
{
map.ClearMap(m_pos.x + dir[i][0] * 40, m_pos.y + dir[i][1] * 40); //炸弹过处,寸草不生
CTools::CopyToBack(showimg, m_ShockWavesImgs[0][i], m_pos.x + 40 * dir[i][0], m_pos.y + 40 * dir[i][1], 255, 0, 0, true);
}
if (m_pos.x / 40 + 2 * dir[i][0] >= 0
&& m_pos.y / 40 + 2 * dir[i][1] >= 0
&& m_pos.x / 40 + 2 * dir[i][0] <= 14
&& m_pos.y / 40 + 2 * dir[i][1] <= 14) //炸弹范围 2
{
map.ClearMap(m_pos.x + 2 * dir[i][0] * 40, m_pos.y + 2 * dir[i][1] * 40);
if (i < 2)
CTools::CopyToBack(showimg, m_ShockWavesImgs[1][i], m_pos.x + 2 * 40 * dir[i][0], m_pos.y + 2 * 40 * dir[i][1]
, 255, 0, 0, true);
else
CTools::CopyToBack(showimg, m_ShockWavesImgs[1][i], m_pos.x + 40 * dir[i][0], m_pos.y + 40 * dir[i][1]
, 255, 0, 0, true);
}
}
}
if (m_TimeCount == 0) {
m_Flag = 0;
m_TimeCount = 30;
map.ClearMap(m_pos.x / 40, m_pos.y / 40);
}
}
void CCrump::Realease() {
} | [
"2522206019@qq.com"
] | 2522206019@qq.com |
79fd7dddaaa0b107e9518cabfb61493cc9f147ac | 17c4e1fa8df9ece967575508ba564a0ed4458550 | /core/gv_displayobject.cpp | 650c10338bd899f31352e69b72a05baffc76dae5 | [] | no_license | storming/OpenGxV | 539e6896af69b87bfc3277334f209cdcb640090d | 298ef02aaf9c1560b76153c75f2fff6b2dfedee6 | refs/heads/master | 2021-01-01T05:48:38.045351 | 2014-07-30T07:45:08 | 2014-07-30T07:45:08 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,420 | cpp | #include "opengxv.h"
#include "gv_displayobject.h"
#include "gv_displayobjectcontainer.h"
#include "gv_stage.h"
namespace gv {
DisplayObject::DisplayObject(bool iscontainer) noexcept
: _parent(),
_stage(),
_iscontainer(iscontainer),
_visible(true),
_matrixDirty(false)
{
_matrix = new Matrix;
_matrix->setIdentity();
_concatenatedMatrix = new Matrix;
}
static std::vector<ptr<DisplayObject>> __objects;
Size2f DisplayObject::size() const {
return _bounds.size();
}
void DisplayObject::size(const Size2f &value) {
if (_bounds.empty()) {
return;
}
Size2f boundsSize = _bounds.size();
if (value == boundsSize) {
return;
}
float sx = value.width / boundsSize.width;
float sy = value.height / boundsSize.height;
*_matrix = (*_matrix) * Scaling(sx, sy, 0.f);
_matrixDirty = true;
updateBounds();
}
float DisplayObject::width() const {
return size().width;
}
void DisplayObject::width(float value) {
size(Size2f(value, height()));
}
float DisplayObject::height() const {
return size().height;
}
void DisplayObject::height(float value) {
size(Size2f(width(), value));
}
Vec3f DisplayObject::position() const {
return Vec3f(_matrix->translation());
}
void DisplayObject::position(const Vec3f &value) {
auto pos = _matrix->translation();
if (pos != value) {
Vec3f d = value - position();
pos = value;
_matrixDirty = true;
updateBounds(_bounds + Vec2f(d.x(), d.y()));
}
}
float DisplayObject::x() const {
return position().x();
}
void DisplayObject::x(float value) {
auto pos = _matrix->translation();
if (pos.x() != value) {
float d = value - pos.x();
pos.x() = value;
_matrixDirty = true;
updateBounds(_bounds + Vec2f(d, 0));
}
}
float DisplayObject::y() const {
return position().y();
}
void DisplayObject::y(float value) {
auto pos = _matrix->translation();
if (pos.y() != value) {
float d = value - pos.y();
pos.y() = value;
_matrixDirty = true;
updateBounds(_bounds + Vec2f(0, d));
}
}
float DisplayObject::z() const {
return position().z();
}
void DisplayObject::z(float value) {
auto pos = _matrix->translation();
if (pos.z() != value) {
pos.z() = value;
_matrixDirty = true;
}
}
Vec3f DisplayObject::rotation() const {
Vec3f rot;
math::matrixLinear(_matrix, &rot, nullptr);
return math::angle(rot);
}
void DisplayObject::rotation(const Vec3f &value) {
Matrix3f scale;
math::matrixLinear(_matrix, (Vec3f*)nullptr, &scale);
_matrix->linear() = math::rotation(math::radian(value)) * scale;
_matrixDirty = true;
updateBounds();
}
float DisplayObject::rotationX() const {
return rotation().x();
}
void DisplayObject::rotationX(float value) {
Vec3f rot;
Matrix3f scale;
math::matrixLinear(_matrix, &rot, &scale);
rot.x() = math::radian(value);
_matrix->linear() = math::rotation(rot) * scale;
_matrixDirty = true;
updateBounds();
}
float DisplayObject::rotationY() const {
return rotation().y();
}
void DisplayObject::rotationY(float value) {
Vec3f rot;
Matrix3f scale;
math::matrixLinear(_matrix, &rot, &scale);
rot.y() = math::radian(value);
_matrix->linear() = math::rotation(rot) * scale;
_matrixDirty = true;
updateBounds();
}
float DisplayObject::rotationZ() const {
return rotation().z();
}
void DisplayObject::rotationZ(float value) {
Vec3f rot;
Matrix3f scale;
math::matrixLinear(_matrix, &rot, &scale);
rot.z() = math::radian(value);
_matrix->linear() = math::rotation(rot) * scale;
_matrixDirty = true;
updateBounds();
}
Vec3f DisplayObject::scale() const {
Matrix3f m;
math::matrixLinear(_matrix, (Matrix3f*)nullptr, &m);
return Vec3f(m(0, 0), m(1, 1), m(2, 2));
}
void DisplayObject::scale(const Vec3f &value) {
Matrix3f rot;
math::matrixLinear(_matrix, &rot, nullptr);
_matrix->linear() = rot * Scaling(value);
_matrixDirty = true;
updateBounds();
}
float DisplayObject::scaleX() const {
return scale().x();
}
void DisplayObject::scaleX(float value) {
Matrix3f rot;
math::matrixLinear(_matrix, &rot, nullptr);
_matrix->linear() = rot * Scaling(value, 0.f, 0.f);
_matrixDirty = true;
updateBounds();
}
float DisplayObject::scaleY() const {
return scale().y();
}
void DisplayObject::scaleY(float value) {
Matrix3f rot;
math::matrixLinear(_matrix, &rot, nullptr);
_matrix->linear() = rot * Scaling(0.f, value, 0.f);
_matrixDirty = true;
updateBounds();
}
float DisplayObject::scaleZ() const {
return scale().z();
}
void DisplayObject::scaleZ(float value) {
Matrix3f rot;
math::matrixLinear(_matrix, &rot, nullptr);
_matrix->linear() = rot * Scaling(0.f, 0.f, value);
_matrixDirty = true;
updateBounds();
}
bool DisplayObject::visible() const {
return _visible;
}
void DisplayObject::visible(bool value) {
_visible = value;
}
inline void DisplayObject::updateBounds(const Box2f &bounds) noexcept {
if (_parent) {
_parent->updateChildBounds(this, _bounds, bounds);
}
_bounds = bounds;
}
void DisplayObject::updateBounds() {
updateBounds((*_matrix) * contentBounds());
}
const Matrix &DisplayObject::concatenatedMatrix() noexcept {
size_t old_size = __objects.size();
DisplayObject *parent = _parent;
size_t n = -1;
while (parent) {
__objects.emplace_back(parent);
if (parent->_matrixDirty) {
n = __objects.size();
}
parent = parent->_parent;
}
Matrix *trans;
if (n != (size_t)-1) {
DisplayObject *obj = __objects[n];
if (obj->_parent) {
*obj->_concatenatedMatrix = (*obj->_parent->_concatenatedMatrix) * (*obj->_matrix);
trans = obj->_concatenatedMatrix;
}
else {
trans = obj->_matrix;
}
for (--n; n <= old_size; --n) {
obj = __objects[n];
*obj->_concatenatedMatrix = (*trans) * (*obj->_matrix);
trans = obj->_concatenatedMatrix;
}
}
else {
if (!_parent) {
trans = _matrix;
goto finish;
}
if (!_matrixDirty) {
trans = _concatenatedMatrix;
goto finish;
}
trans = _parent->_concatenatedMatrix;
}
*_concatenatedMatrix = (*trans) * (*_matrix);
trans = _concatenatedMatrix;
finish:
__objects.resize(old_size);
return *trans;
}
Box2f DisplayObject::bounds(DisplayObject *targetCoordinateSpace) {
if (targetCoordinateSpace == _parent) {
return _bounds;
}
if (targetCoordinateSpace != this) {
if (!targetCoordinateSpace) {
targetCoordinateSpace = Stage::instance();
}
if (_parent) {
return targetCoordinateSpace->concatenatedMatrix().inverse() *
(_parent->concatenatedMatrix() * _bounds);
}
else {
return targetCoordinateSpace->concatenatedMatrix().inverse() * _bounds;
}
}
return contentBounds();
}
bool DisplayObject::dispatchEvent(DisplayObject *parent, ptr<Event> event) noexcept {
size_t old_size = __objects.size();
while (parent) {
__objects.emplace_back(parent);
parent = parent->_parent;
}
bool ret = EventDispatcher::dispatchEvent(event, this, (ptr<EventDispatcher>*)__objects.data() + old_size, __objects.size() - old_size);
__objects.resize(old_size);
return ret;
}
bool DisplayObject::dispatchEvent(ptr<Event> event) {
return dispatchEvent(_parent, event);
}
void DisplayObject::stage(Stage *stage) {
_stage = stage;
if (stage) {
EventDispatcher::dispatchEvent(object<Event>(Event::ADD_TO_STAGE));
}
else {
EventDispatcher::dispatchEvent(object<Event>(Event::REMOVED_FROM_STAGE));
}
}
void DisplayObject::render(Renderer &renderer, const Matrix &mat, int dirty) noexcept {
if (!_visible) {
return;
}
dirty |= (int)_matrixDirty;
if (dirty) {
*_concatenatedMatrix = mat * (*_matrix);
_matrixDirty = false;
}
if (!_stage->checkVisibility((*_concatenatedMatrix) * _bounds)) {
return;
}
draw(renderer, *_concatenatedMatrix);
}
GV_NS_END
| [
"storm@vip.163.com"
] | storm@vip.163.com |
376c27cfe41d9147da4dc31bf0d0796e27a1a1d9 | c9cf0586ace11aa32fa67606d237a130a06364ee | /circular-cylinder-3-20/2.5/p | b52c17b048d7826f03d1af07a693fd4566e9be04 | [] | no_license | jezvonek/CFD-Final-Project | c74cfa21f22545c27d97d85cf30eb6dc8c824dc1 | 7c9a7fb032d74f20888effa0a0b75b212bf899f4 | refs/heads/master | 2022-07-05T14:43:52.967657 | 2020-05-14T03:40:56 | 2020-05-14T03:40:56 | 262,370,756 | 1 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 184,126 | /*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6.0
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "2.5";
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField nonuniform List<scalar>
19200
(
-29.5039
-25.8476
-23.1331
-20.89
-18.8527
-17.0236
-15.3889
-13.9239
-12.609
-11.4282
-10.3674
-9.41402
-8.55695
-7.78621
-7.09287
-6.46889
-5.90705
-5.40086
-4.94452
-4.53281
-4.16106
-3.82509
-3.52119
-3.24603
-2.99665
-2.77044
-2.56503
-2.37815
-2.20778
-2.05442
-29.5457
-25.8983
-23.1863
-20.9424
-18.9033
-17.072
-15.4348
-13.9673
-12.6499
-11.4668
-10.4038
-9.44854
-8.58975
-7.81749
-7.1228
-6.49762
-5.93472
-5.4276
-4.97041
-4.55793
-4.18547
-3.84885
-3.54433
-3.26858
-3.01863
-2.79186
-2.58593
-2.39846
-2.22741
-2.074
-29.5952
-25.9508
-23.2402
-20.9956
-18.9547
-17.1211
-15.4814
-14.0114
-12.6915
-11.5061
-10.4411
-9.48388
-8.6234
-7.84964
-7.15363
-6.52729
-5.96336
-5.45532
-4.99732
-4.58409
-4.21095
-3.87369
-3.56856
-3.29223
-3.04173
-2.81442
-2.60797
-2.41993
-2.2482
-2.09476
-29.6496
-26.0058
-23.2953
-21.0497
-19.0069
-17.1709
-15.5288
-14.0561
-12.7339
-11.5462
-10.479
-9.51997
-8.65782
-7.88259
-7.18529
-6.55781
-5.99289
-5.48396
-5.02517
-4.61123
-4.23743
-3.89955
-3.59385
-3.31697
-3.06592
-2.83809
-2.63113
-2.44252
-2.27013
-2.11667
-29.7072
-26.063
-23.3519
-21.1048
-19.0599
-17.2216
-15.5768
-14.1016
-12.7769
-11.5869
-10.5177
-9.55681
-8.69302
-7.91635
-7.21778
-6.5892
-6.02331
-5.51353
-5.05397
-4.63934
-4.26491
-3.92645
-3.62019
-3.34277
-3.0912
-2.86287
-2.65541
-2.46625
-2.2932
-2.13975
-29.7673
-26.1223
-23.41
-21.1611
-19.114
-17.2731
-15.6257
-14.1479
-12.8207
-11.6284
-10.5572
-9.59439
-8.72898
-7.95088
-7.25108
-6.62143
-6.05459
-5.54399
-5.0837
-4.66841
-4.29338
-3.95436
-3.64757
-3.36964
-3.11757
-2.88875
-2.6808
-2.49109
-2.31741
-2.16399
-29.8293
-26.1832
-23.4695
-21.2186
-19.169
-17.3254
-15.6753
-14.1949
-12.8652
-11.6706
-10.5973
-9.63268
-8.76567
-7.98618
-7.28517
-6.65447
-6.08673
-5.57533
-5.11434
-4.69842
-4.32282
-3.98326
-3.67597
-3.39754
-3.14499
-2.91571
-2.70729
-2.51705
-2.34274
-2.18938
-29.8929
-26.2457
-23.5303
-21.2772
-19.225
-17.3786
-15.7257
-14.2425
-12.9103
-11.7135
-10.6381
-9.67166
-8.80306
-8.0222
-7.32001
-6.68829
-6.11967
-5.60751
-5.14585
-4.72933
-4.35318
-4.01313
-3.70535
-3.42647
-3.17346
-2.94372
-2.73486
-2.54409
-2.36918
-2.21589
-29.9581
-26.3096
-23.5923
-21.3368
-19.2819
-17.4326
-15.7768
-14.2909
-12.9561
-11.7569
-10.6795
-9.71128
-8.84111
-8.05891
-7.35556
-6.72285
-6.15339
-5.64049
-5.17819
-4.76111
-4.38445
-4.04392
-3.73569
-3.45637
-3.20293
-2.97276
-2.76347
-2.57219
-2.39669
-2.2435
-30.0245
-26.3747
-23.6554
-21.3974
-19.3396
-17.4874
-15.8286
-14.3399
-13.0025
-11.801
-10.7215
-9.75149
-8.87978
-8.09625
-7.39177
-6.75811
-6.18782
-5.67423
-5.21132
-4.79371
-4.41656
-4.07559
-3.76694
-3.48721
-3.23336
-3.00279
-2.79308
-2.60132
-2.42524
-2.27217
-30.0922
-26.441
-23.7195
-21.4589
-19.3981
-17.5428
-15.881
-14.3894
-13.0495
-11.8456
-10.764
-9.79225
-8.91901
-8.13418
-7.42859
-6.794
-6.22292
-5.70866
-5.24518
-4.82706
-4.44947
-4.10808
-3.79905
-3.51893
-3.26471
-3.03376
-2.82366
-2.63143
-2.4548
-2.30187
-30.1609
-26.5083
-23.7846
-21.5212
-19.4573
-17.5988
-15.934
-14.4395
-13.0969
-11.8907
-10.8071
-9.83349
-8.95873
-8.17261
-7.46595
-6.83045
-6.25862
-5.74372
-5.27969
-4.86111
-4.4831
-4.14134
-3.83194
-3.55148
-3.29691
-3.06561
-2.85515
-2.66247
-2.4853
-2.33255
-30.2307
-26.5765
-23.8505
-21.5842
-19.5172
-17.6554
-15.9874
-14.49
-13.1447
-11.9362
-10.8505
-9.87513
-8.99887
-8.21149
-7.50378
-6.8674
-6.29484
-5.77933
-5.3148
-4.89577
-4.51739
-4.17528
-3.86556
-3.58478
-3.3299
-3.09828
-2.88748
-2.69438
-2.5167
-2.36415
-30.3013
-26.6455
-23.9171
-21.6479
-19.5776
-17.7125
-16.0412
-14.5408
-13.1929
-11.9819
-10.8942
-9.91709
-9.03935
-8.25073
-7.54199
-6.90476
-6.3315
-5.81541
-5.3504
-4.93097
-4.55224
-4.20982
-3.89982
-3.61876
-3.36359
-3.13168
-2.92059
-2.72709
-2.54893
-2.3966
-30.3728
-26.7153
-23.9844
-21.7121
-19.6384
-17.7699
-16.0954
-14.592
-13.2413
-12.028
-10.9382
-9.9593
-9.08008
-8.29024
-7.58049
-6.94243
-6.3685
-5.85187
-5.38641
-4.96661
-4.58756
-4.24487
-3.93461
-3.65332
-3.3979
-3.16575
-2.95438
-2.76052
-2.5819
-2.42984
-30.4449
-26.7858
-24.0523
-21.7768
-19.6996
-17.8276
-16.1498
-14.6433
-13.2898
-12.0741
-10.9822
-10.0017
-9.12098
-8.32993
-7.61919
-6.98033
-6.40575
-5.8886
-5.42272
-5.00258
-4.62325
-4.28032
-3.96985
-3.68834
-3.43272
-3.20035
-2.98875
-2.79457
-2.61553
-2.46377
-30.5178
-26.8569
-24.1207
-21.8419
-19.7611
-17.8856
-16.2043
-14.6947
-13.3385
-12.1203
-11.0264
-10.0441
-9.16194
-8.3697
-7.65799
-7.01835
-6.44315
-5.9255
-5.45922
-5.03877
-4.65918
-4.31604
-4.00539
-3.72372
-3.46793
-3.23539
-3.0236
-2.82913
-2.6497
-2.49829
-30.5912
-26.9285
-24.1895
-21.9072
-19.8228
-17.9436
-16.2588
-14.7461
-13.3871
-12.1665
-11.0705
-10.0864
-9.20287
-8.40945
-7.69678
-7.05638
-6.48056
-5.96243
-5.49578
-5.07504
-4.69523
-4.35191
-4.04111
-3.75931
-3.50339
-3.27072
-3.05879
-2.86408
-2.68431
-2.53329
-30.6652
-27.0006
-24.2587
-21.9728
-19.8846
-18.0016
-16.3133
-14.7973
-13.4355
-12.2125
-11.1144
-10.1286
-9.24365
-8.44907
-7.73546
-7.0943
-6.51789
-5.99929
-5.53228
-5.11127
-4.73126
-4.38778
-4.07687
-3.79497
-3.53896
-3.3062
-3.09417
-2.89926
-2.71918
-2.5686
-30.7398
-27.0732
-24.3281
-22.0386
-19.9464
-18.0595
-16.3676
-14.8484
-13.4837
-12.2583
-11.1581
-10.1706
-9.28419
-8.48844
-7.7739
-7.13199
-6.55499
-6.03594
-5.56858
-5.14731
-4.76712
-4.42351
-4.11249
-3.83052
-3.57446
-3.34165
-3.12956
-2.9345
-2.75414
-2.60405
-30.815
-27.1461
-24.3978
-22.1043
-20.0081
-18.1172
-16.4217
-14.8992
-13.5316
-12.3037
-11.2015
-10.2122
-9.32436
-8.52746
-7.81199
-7.16935
-6.59176
-6.07226
-5.60456
-5.18304
-4.80265
-4.45891
-4.14781
-3.86578
-3.60968
-3.37685
-3.16474
-2.96957
-2.78898
-2.63942
-30.8908
-27.2195
-24.4677
-22.1701
-20.0695
-18.1746
-16.4753
-14.9495
-13.579
-12.3486
-11.2443
-10.2533
-9.36409
-8.56604
-7.84964
-7.20626
-6.62809
-6.10813
-5.64008
-5.21828
-4.8377
-4.49382
-4.18263
-3.90055
-3.64442
-3.41158
-3.19948
-3.00423
-2.82344
-2.67444
-30.9675
-27.2933
-24.5376
-22.2356
-20.1307
-18.2316
-16.5284
-14.9992
-13.6259
-12.393
-11.2866
-10.2939
-9.40327
-8.60407
-7.88675
-7.24262
-6.66386
-6.14342
-5.675
-5.25291
-4.87211
-4.52807
-4.21677
-3.93461
-3.67844
-3.4456
-3.2335
-3.0382
-2.8572
-2.70878
-31.0453
-27.3675
-24.6076
-22.301
-20.1914
-18.2879
-16.5809
-15.0483
-13.672
-12.4367
-11.3282
-10.3339
-9.4418
-8.64146
-7.92322
-7.27834
-6.69897
-6.17804
-5.70921
-5.2868
-4.90574
-4.5615
-4.25004
-3.96776
-3.71151
-3.47862
-3.26652
-3.07115
-2.8899
-2.74207
-31.1246
-27.4422
-24.6775
-22.3659
-20.2514
-18.3435
-16.6326
-15.0966
-13.7174
-12.4796
-11.3691
-10.373
-9.4796
-8.67814
-7.95897
-7.31333
-6.73334
-6.21189
-5.74262
-5.31984
-4.93846
-4.59395
-4.28227
-3.9998
-3.74338
-3.51037
-3.29818
-3.10267
-2.92112
-2.77387
-31.2056
-27.517
-24.747
-22.4302
-20.3107
-18.3983
-16.6834
-15.1439
-13.7618
-12.5216
-11.4091
-10.4114
-9.51662
-8.71404
-7.99395
-7.34755
-6.76691
-6.24492
-5.77518
-5.35197
-4.97021
-4.62534
-4.31333
-4.03055
-3.77385
-3.54057
-3.32816
-3.13239
-2.95037
-2.80336
-31.2896
-27.5923
-24.816
-22.4936
-20.3688
-18.4518
-16.733
-15.1902
-13.8053
-12.5627
-11.4482
-10.4489
-9.55278
-8.74912
-8.02813
-7.38097
-6.79968
-6.27711
-5.80685
-5.38317
-5.00094
-4.65562
-4.34316
-4.05993
-3.80278
-3.56906
-3.35626
-3.16005
-2.97715
-2.82964
-31.381
-27.6692
-24.884
-22.5554
-20.4253
-18.5037
-16.781
-15.235
-13.8473
-12.6025
-11.4862
-10.4853
-9.58797
-8.78327
-8.06142
-7.41353
-6.8316
-6.30845
-5.83764
-5.41343
-5.03068
-4.68481
-4.37177
-4.08792
-3.8301
-3.59571
-3.38226
-3.18521
-3.00076
-2.85293
-31.4833
-27.7475
-24.9497
-22.6145
-20.4795
-18.5537
-16.8274
-15.2783
-13.8881
-12.6411
-11.523
-10.5207
-9.62215
-8.81648
-8.09381
-7.44522
-6.86267
-6.33895
-5.8676
-5.44283
-5.0595
-4.71301
-4.39927
-4.11461
-3.85586
-3.62038
-3.40547
-3.20632
-3.01975
-2.87395
-31.5735
-27.8184
-25.011
-22.671
-20.5321
-18.6026
-16.873
-15.3209
-13.9282
-12.6791
-11.5593
-10.5555
-9.65579
-8.84915
-8.12567
-7.47638
-6.89322
-6.36893
-5.89703
-5.47171
-5.08778
-4.74064
-4.42614
-4.14061
-3.88082
-3.64387
-3.42652
-3.22445
-3.03759
-2.89096
-32.292
-32.3089
-32.3141
-32.3214
-32.3289
-32.3339
-32.3356
-32.3341
-32.3291
-32.3205
-32.3083
-32.2925
-32.2732
-32.2505
-32.2244
-32.1951
-32.1627
-32.1274
-32.0894
-32.0489
-32.006
-31.9609
-31.9141
-31.8657
-31.8161
-31.7659
-31.716
-31.6677
-31.6242
-31.5902
-28.5013
-28.5295
-28.549
-28.5651
-28.578
-28.587
-28.592
-28.5931
-28.5905
-28.5841
-28.574
-28.5603
-28.5431
-28.5224
-28.4984
-28.4713
-28.4411
-28.408
-28.3722
-28.3339
-28.2932
-28.2504
-28.2057
-28.1594
-28.1117
-28.0632
-28.0143
-27.9655
-27.9175
-27.869
-25.62
-25.6536
-25.6805
-25.702
-25.7188
-25.7313
-25.7396
-25.7438
-25.7441
-25.7407
-25.7335
-25.7227
-25.7084
-25.6907
-25.6697
-25.6456
-25.6184
-25.5884
-25.5557
-25.5204
-25.4828
-25.443
-25.4012
-25.3577
-25.3126
-25.2662
-25.2186
-25.17
-25.12
-25.0676
-23.1958
-23.2314
-23.2615
-23.2862
-23.306
-23.3214
-23.3326
-23.3398
-23.3431
-23.3425
-23.3383
-23.3305
-23.3192
-23.3046
-23.2867
-23.2658
-23.2418
-23.2151
-23.1857
-23.1537
-23.1194
-23.0828
-23.0442
-23.0038
-22.9616
-22.9177
-22.8723
-22.8253
-22.7766
-22.7256
-20.9787
-21.015
-21.0467
-21.0734
-21.0954
-21.113
-21.1265
-21.1361
-21.1418
-21.1437
-21.142
-21.1368
-21.1282
-21.1164
-21.1014
-21.0833
-21.0624
-21.0387
-21.0123
-20.9835
-20.9523
-20.9189
-20.8834
-20.846
-20.8068
-20.7658
-20.723
-20.6785
-20.6322
-20.5839
-18.9833
-19.0197
-19.0521
-19.0798
-19.103
-19.1221
-19.1371
-19.1483
-19.1557
-19.1595
-19.1598
-19.1566
-19.1502
-19.1406
-19.1279
-19.1123
-19.0939
-19.0728
-19.0491
-19.023
-18.9946
-18.964
-18.9314
-18.8968
-18.8604
-18.8221
-18.7821
-18.7403
-18.6967
-18.6512
-17.2023
-17.2383
-17.2706
-17.2986
-17.3223
-17.3419
-17.3578
-17.3699
-17.3784
-17.3834
-17.385
-17.3833
-17.3784
-17.3705
-17.3596
-17.3459
-17.3294
-17.3104
-17.2889
-17.2651
-17.239
-17.2108
-17.1805
-17.1484
-17.1144
-17.0787
-17.0412
-17.002
-16.961
-16.9184
-15.6135
-15.6486
-15.6803
-15.7078
-15.7314
-15.7511
-15.7671
-15.7796
-15.7886
-15.7942
-15.7966
-15.7957
-15.7919
-15.785
-15.7754
-15.763
-15.748
-15.7306
-15.7107
-15.6886
-15.6643
-15.638
-15.6097
-15.5796
-15.5478
-15.5142
-15.4789
-15.4421
-15.4035
-15.3635
-14.1971
-14.231
-14.2616
-14.2883
-14.3113
-14.3306
-14.3463
-14.3587
-14.3677
-14.3734
-14.376
-14.3756
-14.3723
-14.3661
-14.3572
-14.3456
-14.3316
-14.3152
-14.2965
-14.2757
-14.2528
-14.2279
-14.2012
-14.1727
-14.1425
-14.1107
-14.0774
-14.0425
-14.0061
-13.9683
-12.9354
-12.9679
-12.9972
-13.0228
-13.0448
-13.0633
-13.0784
-13.0903
-13.0989
-13.1044
-13.1069
-13.1065
-13.1033
-13.0973
-13.0887
-13.0777
-13.0642
-13.0484
-13.0305
-13.0105
-12.9885
-12.9647
-12.9391
-12.9119
-12.883
-12.8527
-12.8209
-12.7876
-12.753
-12.7171
-11.812
-11.8429
-11.8707
-11.895
-11.9158
-11.9333
-11.9475
-11.9586
-11.9666
-11.9716
-11.9737
-11.973
-11.9695
-11.9635
-11.9549
-11.944
-11.9307
-11.9153
-11.8978
-11.8783
-11.8569
-11.8338
-11.809
-11.7826
-11.7548
-11.7255
-11.6949
-11.663
-11.6298
-11.5955
-10.8115
-10.8408
-10.867
-10.8898
-10.9094
-10.9257
-10.9389
-10.949
-10.9562
-10.9604
-10.9619
-10.9607
-10.9568
-10.9505
-10.9417
-10.9306
-10.9173
-10.9019
-10.8845
-10.8652
-10.8442
-10.8215
-10.7972
-10.7715
-10.7443
-10.7159
-10.6862
-10.6554
-10.6233
-10.5903
-9.92025
-9.94781
-9.97241
-9.99376
-10.0119
-10.027
-10.039
-10.0481
-10.0543
-10.0577
-10.0584
-10.0565
-10.0521
-10.0452
-10.036
-10.0246
-10.0111
-9.9955
-9.97804
-9.95879
-9.93786
-9.91534
-9.89136
-9.866
-9.83937
-9.81153
-9.78255
-9.75251
-9.7214
-9.68939
-9.12569
-9.15159
-9.17459
-9.19443
-9.21119
-9.22495
-9.23578
-9.24376
-9.24895
-9.25143
-9.25128
-9.2486
-9.24347
-9.23599
-9.22625
-9.21437
-9.20044
-9.18458
-9.16689
-9.14749
-9.12648
-9.10399
-9.08012
-9.05497
-9.02863
-9.0012
-8.97274
-8.94332
-8.91295
-8.88177
-8.41672
-8.441
-8.46242
-8.48079
-8.49616
-8.50863
-8.51825
-8.52509
-8.52922
-8.53073
-8.52968
-8.52616
-8.52027
-8.5121
-8.50175
-8.48932
-8.47491
-8.45863
-8.4406
-8.42093
-8.39974
-8.37713
-8.35323
-8.32814
-8.30196
-8.27479
-8.2467
-8.21775
-8.18797
-8.15747
-7.78341
-7.80613
-7.82604
-7.84298
-7.857
-7.86819
-7.87662
-7.88233
-7.88541
-7.88592
-7.88395
-7.87958
-7.8729
-7.864
-7.85298
-7.83995
-7.825
-7.80824
-7.78979
-7.76977
-7.74829
-7.72547
-7.70144
-7.67631
-7.65018
-7.62315
-7.59531
-7.56673
-7.53741
-7.50749
-7.21695
-7.23818
-7.25665
-7.27222
-7.28494
-7.2949
-7.30216
-7.30677
-7.30881
-7.30835
-7.30547
-7.30024
-7.29276
-7.28312
-7.27142
-7.25775
-7.24222
-7.22494
-7.20603
-7.1856
-7.16377
-7.14068
-7.11644
-7.09118
-7.06501
-7.03805
-7.01038
-6.98207
-6.95315
-6.92371
-6.70954
-6.72936
-6.74646
-6.76072
-6.7722
-6.78099
-6.78713
-6.79068
-6.79172
-6.79031
-6.78654
-6.78048
-6.77221
-6.76184
-6.74944
-6.73514
-6.71902
-6.7012
-6.68179
-6.66092
-6.63871
-6.61528
-6.59078
-6.56533
-6.53907
-6.5121
-6.48453
-6.45644
-6.42785
-6.39885
-6.25428
-6.27277
-6.28858
-6.30161
-6.31192
-6.31958
-6.32466
-6.32721
-6.32729
-6.32498
-6.32034
-6.31347
-6.30445
-6.29336
-6.28029
-6.26535
-6.24865
-6.23028
-6.21037
-6.18904
-6.16642
-6.14263
-6.11783
-6.09215
-6.06573
-6.03871
-6.01119
-5.98328
-5.95499
-5.9264
-5.8451
-5.86233
-5.87693
-5.8888
-5.898
-5.90462
-5.90869
-5.91028
-5.90946
-5.90629
-5.90084
-5.8932
-5.88345
-5.87167
-5.85796
-5.84241
-5.82513
-5.80622
-5.78581
-5.76402
-5.74097
-5.7168
-5.69167
-5.66572
-5.63911
-5.61199
-5.58448
-5.55671
-5.5287
-5.50053
-5.47662
-5.49269
-5.50614
-5.51692
-5.52509
-5.53072
-5.53385
-5.53455
-5.53287
-5.5289
-5.52268
-5.51432
-5.50388
-5.49145
-5.47712
-5.46099
-5.44315
-5.42373
-5.40283
-5.38057
-5.35709
-5.33253
-5.30705
-5.28081
-5.25397
-5.2267
-5.19917
-5.17152
-5.14378
-5.11603
-5.14413
-5.1591
-5.17149
-5.18126
-5.18846
-5.19316
-5.19542
-5.19528
-5.19281
-5.18808
-5.18115
-5.17211
-5.16102
-5.14798
-5.13307
-5.11639
-5.09803
-5.0781
-5.05673
-5.03402
-5.01011
-4.98515
-4.9593
-4.93274
-4.90563
-4.87819
-4.8506
-4.82302
-4.79555
-4.76826
-4.84348
-4.85742
-4.86882
-4.87764
-4.88394
-4.88779
-4.88923
-4.88831
-4.8851
-4.87967
-4.87208
-4.8624
-4.85072
-4.83711
-4.82165
-4.80445
-4.7856
-4.76521
-4.74337
-4.72022
-4.69589
-4.67053
-4.6443
-4.61738
-4.58997
-4.5623
-4.5346
-4.50708
-4.47986
-4.45309
-4.571
-4.58398
-4.59446
-4.6024
-4.60787
-4.61092
-4.61161
-4.60997
-4.60608
-4.6
-4.5918
-4.58154
-4.5693
-4.55516
-4.53921
-4.52153
-4.50221
-4.48137
-4.4591
-4.43553
-4.41078
-4.38501
-4.35838
-4.33108
-4.30333
-4.27538
-4.2475
-4.21999
-4.193
-4.16684
-4.32348
-4.33558
-4.3452
-4.35233
-4.35703
-4.35934
-4.35932
-4.35703
-4.35251
-4.34583
-4.33706
-4.32627
-4.31352
-4.2989
-4.28248
-4.26435
-4.24461
-4.22335
-4.20067
-4.17669
-4.15154
-4.12537
-4.09832
-4.07062
-4.04247
-4.01417
-3.98603
-3.95847
-3.93165
-3.90625
-4.09811
-4.10937
-4.11819
-4.12456
-4.12853
-4.13016
-4.1295
-4.12658
-4.12148
-4.11425
-4.10495
-4.09365
-4.08043
-4.06536
-4.04851
-4.02996
-4.00982
-3.98816
-3.96508
-3.94071
-3.91516
-3.88856
-3.86109
-3.83293
-3.80432
-3.77558
-3.74706
-3.71931
-3.69255
-3.66821
-3.89241
-3.90289
-3.91096
-3.91661
-3.91991
-3.92089
-3.91961
-3.91611
-3.91046
-3.9027
-3.8929
-3.88113
-3.86745
-3.85194
-3.83467
-3.81572
-3.79517
-3.77311
-3.74964
-3.72486
-3.69888
-3.67183
-3.64387
-3.61519
-3.58602
-3.55668
-3.52759
-3.49944
-3.4724
-3.44945
-3.70418
-3.71401
-3.72146
-3.72653
-3.72927
-3.72972
-3.72794
-3.72397
-3.71786
-3.70967
-3.69947
-3.68731
-3.67326
-3.65738
-3.63977
-3.62047
-3.59959
-3.5772
-3.55338
-3.52824
-3.50188
-3.47442
-3.446
-3.4168
-3.38703
-3.35703
-3.32721
-3.29843
-3.27073
-3.2495
-3.53145
-3.54084
-3.5479
-3.5526
-3.55501
-3.55517
-3.55313
-3.54892
-3.54261
-3.53425
-3.5239
-3.51162
-3.49747
-3.48153
-3.46386
-3.44453
-3.42363
-3.40123
-3.37742
-3.35228
-3.32591
-3.29842
-3.26994
-3.24062
-3.21067
-3.18037
-3.15013
-3.12085
-3.09261
-3.07569
-3.37258
-3.38087
-3.38687
-3.39061
-3.39211
-3.39143
-3.3886
-3.38369
-3.37674
-3.36779
-3.35692
-3.34418
-3.32963
-3.31334
-3.29538
-3.27581
-3.25471
-3.23215
-3.20821
-3.18298
-3.15653
-3.12896
-3.10037
-3.0709
-3.04071
-3.01002
-2.97916
-2.94863
-2.91854
-2.91063
-29.1032
-29.2474
-29.3775
-29.5166
-29.6611
-29.806
-29.9498
-30.092
-30.2318
-30.3689
-30.5027
-30.633
-30.7593
-30.8815
-30.9994
-31.1129
-31.2218
-31.326
-31.4255
-31.5201
-31.6099
-31.6949
-31.775
-31.8503
-31.9211
-31.9874
-32.0499
-32.1092
-32.1671
-32.2265
-25.3061
-25.4648
-25.6145
-25.7637
-25.9126
-26.0595
-26.2039
-26.3458
-26.4848
-26.6208
-26.7535
-26.8825
-27.0077
-27.1288
-27.2458
-27.3584
-27.4666
-27.5703
-27.6693
-27.7636
-27.8532
-27.9381
-28.0182
-28.0937
-28.1645
-28.231
-28.2932
-28.3515
-28.4062
-28.4564
-22.4456
-22.6068
-22.7624
-22.914
-23.0628
-23.2088
-23.3521
-23.4924
-23.6298
-23.764
-23.8949
-24.0222
-24.1457
-24.2654
-24.381
-24.4924
-24.5996
-24.7023
-24.8006
-24.8944
-24.9836
-25.0681
-25.1481
-25.2235
-25.2943
-25.3606
-25.4224
-25.4797
-25.5323
-25.5794
-20.0706
-20.2281
-20.3819
-20.5317
-20.6781
-20.8217
-20.9625
-21.1003
-21.2351
-21.3667
-21.495
-21.6198
-21.741
-21.8584
-21.9719
-22.0814
-22.1868
-22.288
-22.3849
-22.4775
-22.5656
-22.6493
-22.7285
-22.8033
-22.8735
-22.9392
-23.0004
-23.057
-23.1087
-23.1553
-17.9255
-18.0776
-18.2272
-18.3733
-18.5162
-18.6563
-18.7935
-18.9279
-19.0592
-19.1874
-19.3124
-19.434
-19.5521
-19.6666
-19.7773
-19.8842
-19.9872
-20.0861
-20.1809
-20.2715
-20.3579
-20.4401
-20.5179
-20.5913
-20.6604
-20.7251
-20.7854
-20.841
-20.892
-20.9382
-16.0189
-16.1651
-16.3096
-16.4511
-16.5897
-16.7254
-16.8585
-16.9887
-17.1159
-17.2402
-17.3613
-17.4791
-17.5936
-17.7046
-17.812
-17.9158
-18.0157
-18.1118
-18.204
-18.2922
-18.3763
-18.4563
-18.5321
-18.6038
-18.6713
-18.7344
-18.7933
-18.8478
-18.8977
-18.9432
-14.3372
-14.4777
-14.6168
-14.7532
-14.8868
-15.0179
-15.1463
-15.272
-15.3949
-15.5149
-15.6318
-15.7456
-15.8561
-15.9634
-16.0671
-16.1674
-16.264
-16.3569
-16.446
-16.5313
-16.6128
-16.6902
-16.7637
-16.8332
-16.8986
-16.9599
-17.017
-17.0699
-17.1186
-17.163
-12.853
-12.9879
-13.1215
-13.2527
-13.3814
-13.5076
-13.6314
-13.7525
-13.8709
-13.9864
-14.0991
-14.2087
-14.3152
-14.4185
-14.5185
-14.615
-14.7081
-14.7976
-14.8835
-14.9657
-15.0442
-15.1189
-15.1898
-15.2567
-15.3198
-15.3789
-15.4341
-15.4852
-15.5322
-15.5752
-11.5424
-11.6719
-11.8003
-11.9265
-12.0503
-12.1718
-12.2909
-12.4075
-12.5215
-12.6327
-12.7411
-12.8466
-12.9491
-13.0484
-13.1445
-13.2374
-13.3269
-13.413
-13.4955
-13.5746
-13.65
-13.7217
-13.7898
-13.8542
-13.9147
-13.9715
-14.0245
-14.0736
-14.1188
-14.1602
-10.3846
-10.5092
-10.6327
-10.7541
-10.8733
-10.9903
-11.105
-11.2172
-11.3269
-11.434
-11.5383
-11.6398
-11.7383
-11.8338
-11.9262
-12.0154
-12.1014
-12.184
-12.2633
-12.3391
-12.4115
-12.4803
-12.5455
-12.6072
-12.6652
-12.7196
-12.7703
-12.8172
-12.8605
-12.9001
-9.36121
-9.48129
-9.60021
-9.71718
-9.83206
-9.94481
-10.0553
-10.1635
-10.2691
-10.3722
-10.4727
-10.5703
-10.6651
-10.7569
-10.8457
-10.9315
-11.014
-11.0933
-11.1694
-11.2421
-11.3114
-11.3774
-11.4398
-11.4988
-11.5543
-11.6062
-11.6546
-11.6994
-11.7406
-11.7783
-8.45576
-8.57168
-8.68643
-8.79931
-8.91018
-9.019
-9.12564
-9.22997
-9.33187
-9.43126
-9.52802
-9.62207
-9.71333
-9.8017
-9.88712
-9.96951
-10.0488
-10.125
-10.198
-10.2677
-10.3341
-10.3972
-10.457
-10.5133
-10.5663
-10.6158
-10.6619
-10.7046
-10.7438
-10.7796
-7.65385
-7.76599
-7.87693
-7.98606
-8.09326
-8.19845
-8.30151
-8.4023
-8.50071
-8.59664
-8.69
-8.7807
-8.86864
-8.95376
-9.03599
-9.11526
-9.19151
-9.26468
-9.33473
-9.40161
-9.46528
-9.52571
-9.58286
-9.63673
-9.68727
-9.73449
-9.77838
-9.81892
-9.85612
-9.89006
-6.94291
-7.05159
-7.15906
-7.26478
-7.36861
-7.47047
-7.57023
-7.66776
-7.76294
-7.85567
-7.94586
-8.03343
-8.1183
-8.20039
-8.27963
-8.35597
-8.42934
-8.4997
-8.567
-8.6312
-8.69226
-8.75015
-8.80484
-8.85632
-8.90457
-8.94958
-8.99134
-9.02985
-9.06511
-9.09721
-6.31192
-6.41746
-6.52177
-6.62437
-6.72512
-6.82392
-6.92064
-7.01516
-7.10735
-7.19712
-7.28438
-7.36905
-7.45104
-7.53031
-7.60677
-7.68036
-7.75105
-7.81877
-7.8835
-7.94518
-8.00378
-8.05928
-8.11166
-8.16089
-8.20696
-8.24986
-8.2896
-8.32617
-8.35957
-8.38989
-5.75127
-5.85393
-5.95536
-6.05511
-6.15304
-6.24903
-6.34296
-6.43469
-6.52411
-6.61114
-6.69567
-6.77763
-6.85696
-6.93359
-7.00745
-7.07849
-7.14667
-7.21193
-7.27424
-7.33356
-7.38986
-7.44312
-7.49331
-7.54042
-7.58444
-7.62536
-7.66318
-7.69791
-7.72954
-7.75817
-5.25254
-5.35256
-5.45135
-5.54849
-5.64383
-5.73724
-5.82858
-5.91773
-6.00459
-6.08905
-6.17105
-6.25049
-6.32733
-6.40149
-6.47293
-6.54158
-6.60741
-6.67037
-6.73043
-6.78754
-6.84169
-6.89284
-6.94099
-6.98611
-7.02819
-7.06724
-7.10326
-7.13624
-7.1662
-7.19322
-4.80835
-4.90594
-5.00231
-5.09706
-5.19001
-5.28103
-5.36997
-5.45672
-5.54117
-5.62325
-5.70287
-5.77997
-5.85447
-5.92633
-5.9955
-6.06193
-6.12556
-6.18637
-6.24431
-6.29935
-6.35148
-6.40066
-6.44689
-6.49014
-6.53041
-6.5677
-6.60202
-6.63336
-6.66174
-6.68724
-4.41222
-4.50756
-4.60171
-4.69425
-4.785
-4.87379
-4.9605
-5.045
-5.12721
-5.20705
-5.28444
-5.35933
-5.43165
-5.50135
-5.5684
-5.63272
-5.6943
-5.75309
-5.80905
-5.86216
-5.91239
-5.95972
-6.00414
-6.04564
-6.08421
-6.11985
-6.15257
-6.18238
-6.20927
-6.23334
-4.05843
-4.15168
-4.2438
-4.33432
-4.42302
-4.50974
-4.59435
-4.67674
-4.75683
-4.83456
-4.90986
-4.98267
-5.05293
-5.12061
-5.18565
-5.24801
-5.30765
-5.36454
-5.41864
-5.46993
-5.51838
-5.56398
-5.60671
-5.64656
-5.68353
-5.71763
-5.74885
-5.7772
-5.8027
-5.82542
-3.74194
-3.83325
-3.92352
-4.01219
-4.09898
-4.18376
-4.2664
-4.3468
-4.42489
-4.50062
-4.57394
-4.64479
-4.71311
-4.77888
-4.84203
-4.90254
-4.96036
-5.01546
-5.06781
-5.11738
-5.16416
-5.20813
-5.24926
-5.28757
-5.32304
-5.35568
-5.38549
-5.41249
-5.43668
-5.45814
-3.45827
-3.54781
-3.63645
-3.72341
-3.80843
-3.89139
-3.97215
-4.05066
-4.12685
-4.20069
-4.27213
-4.34112
-4.40761
-4.47157
-4.53294
-4.59169
-4.64779
-4.7012
-4.7519
-4.79986
-4.84506
-4.88749
-4.92713
-4.96398
-4.99804
-5.02932
-5.05781
-5.08353
-5.10649
-5.12676
-3.20343
-3.29141
-3.37865
-3.46408
-3.54744
-3.62867
-3.70766
-3.78436
-3.85875
-3.93078
-4.00043
-4.06766
-4.13241
-4.19464
-4.25432
-4.31141
-4.36588
-4.4177
-4.46683
-4.51326
-4.55698
-4.59795
-4.63619
-4.67167
-4.7044
-4.73439
-4.76165
-4.78617
-4.80799
-4.82715
-2.97379
-3.06051
-3.14667
-3.23073
-3.31255
-3.39213
-3.46942
-3.5444
-3.61706
-3.68737
-3.75531
-3.82085
-3.88395
-3.94454
-4.00262
-4.05813
-4.11105
-4.16135
-4.209
-4.25399
-4.2963
-4.3359
-4.37281
-4.407
-4.43849
-4.46728
-4.49337
-4.51678
-4.53752
-4.55565
-2.76614
-2.85206
-2.93756
-3.0204
-3.10077
-3.17879
-3.25444
-3.32775
-3.39875
-3.46741
-3.53371
-3.59764
-3.65914
-3.71818
-3.77471
-3.82872
-3.88017
-3.92903
-3.97527
-4.01889
-4.05986
-4.09818
-4.13383
-4.16681
-4.19713
-4.22478
-4.24978
-4.27214
-4.29187
-4.30904
-2.5776
-2.66374
-2.74909
-2.83081
-2.90977
-2.98627
-3.06031
-3.13199
-3.20135
-3.2684
-3.33312
-3.39548
-3.45544
-3.51297
-3.56802
-3.62057
-3.6706
-3.71808
-3.76298
-3.80528
-3.84498
-3.88206
-3.91652
-3.94835
-3.97755
-4.00414
-4.02811
-4.04948
-4.06827
-4.08452
-2.40459
-2.49317
-2.57917
-2.65975
-2.73727
-2.81223
-2.88466
-2.9547
-3.02245
-3.08792
-3.15108
-3.21191
-3.27037
-3.32643
-3.38006
-3.43121
-3.47988
-3.52603
-3.56964
-3.6107
-3.64919
-3.6851
-3.71842
-3.74916
-3.77732
-3.80289
-3.82589
-3.84633
-3.86422
-3.87962
-2.23955
-2.33425
-2.42261
-2.50221
-2.57831
-2.65178
-2.72267
-2.79118
-2.85745
-2.92147
-2.98322
-3.04268
-3.09981
-3.15458
-3.20694
-3.25688
-3.30436
-3.34936
-3.39186
-3.43184
-3.46929
-3.5042
-3.53657
-3.56638
-3.59365
-3.61837
-3.64056
-3.66022
-3.67737
-3.69206
-2.07593
-2.18144
-2.27452
-2.3538
-2.42869
-2.50083
-2.57039
-2.63765
-2.7027
-2.76556
-2.82619
-2.88456
-2.94063
-2.99436
-3.04572
-3.09468
-3.14122
-3.18531
-3.22693
-3.26607
-3.30271
-3.33684
-3.36847
-3.39758
-3.42417
-3.44826
-3.46985
-3.48895
-3.50557
-3.51977
-1.95754
-2.07583
-2.16794
-2.24487
-2.31728
-2.38686
-2.45406
-2.5191
-2.58201
-2.64277
-2.70132
-2.75763
-2.81166
-2.86337
-2.91273
-2.95972
-3.00432
-3.0465
-3.08626
-3.12357
-3.15844
-3.19085
-3.2208
-3.24829
-3.27333
-3.29592
-3.31607
-3.3338
-3.34912
-3.36207
0.390909
0.302977
0.202675
0.0893285
-0.0388356
-0.183814
-0.347733
-0.532953
-0.742121
-0.978195
-1.24449
-1.54472
-1.88309
-2.26436
-2.69391
-3.17796
-3.72359
-4.33903
-5.03382
-5.81909
-6.70789
-7.7156
-8.86027
-10.163
-11.6498
-13.3524
-15.2921
-17.4724
-20.1612
-23.824
0.322629
0.23323
0.132317
0.0182161
-0.110793
-0.256618
-0.421388
-0.607484
-0.817568
-1.05461
-1.32195
-1.62333
-1.96297
-2.34566
-2.77683
-3.2627
-3.81044
-4.42829
-5.12584
-5.9143
-6.80676
-7.81865
-8.96806
-10.2762
-11.7689
-13.4779
-15.4243
-17.6106
-20.3014
-23.958
0.252839
0.161932
0.0603699
-0.0545331
-0.184441
-0.331169
-0.496849
-0.683884
-0.894948
-1.13303
-1.40149
-1.70409
-2.04508
-2.42927
-2.86214
-3.34994
-3.89988
-4.52025
-5.22069
-6.01245
-6.9087
-7.9249
-9.07919
-10.3927
-11.8914
-13.6066
-15.5593
-17.7505
-20.4417
-24.0893
0.181639
0.0891844
-0.0130622
-0.128812
-0.259666
-0.407345
-0.573986
-0.76201
-0.974108
-1.21329
-1.48292
-1.78679
-2.12919
-2.51495
-2.94958
-3.43938
-3.99159
-4.61454
-5.31795
-6.1131
-7.0132
-8.03378
-9.19299
-10.512
-12.0165
-13.738
-15.6966
-17.8931
-20.5868
-24.231
0.109095
0.0150529
-0.0879138
-0.204556
-0.336406
-0.485086
-0.652739
-0.841805
-1.05499
-1.29532
-1.56618
-1.87139
-2.21525
-2.60264
-3.03909
-3.53095
-4.08549
-4.7111
-5.41754
-6.21613
-7.12016
-8.14518
-9.30936
-10.6339
-12.1443
-13.872
-15.8367
-18.0388
-20.7365
-24.3809
0.0352799
-0.0603861
-0.164108
-0.28169
-0.414585
-0.564316
-0.733032
-0.923193
-1.13752
-1.37905
-1.6512
-1.9578
-2.30319
-2.69226
-3.1306
-3.62458
-4.18152
-4.80987
-5.5194
-6.32152
-7.22955
-8.25907
-9.42831
-10.7584
-12.2749
-14.0088
-15.9798
-18.1878
-20.89
-24.536
-0.0397306
-0.137053
-0.241565
-0.360131
-0.494121
-0.644953
-0.814783
-1.00609
-1.22161
-1.4644
-1.73789
-2.04594
-2.39291
-2.78374
-3.22403
-3.7202
-4.2796
-4.91074
-5.62345
-6.42918
-7.34128
-8.3754
-9.54976
-10.8855
-12.4081
-14.1485
-16.1259
-18.3398
-21.0469
-24.6953
-0.115862
-0.214871
-0.320204
-0.439802
-0.574935
-0.726918
-0.897912
-1.09042
-1.30719
-1.55129
-1.82618
-2.13573
-2.48434
-2.87697
-3.31927
-3.81769
-4.37963
-5.01364
-5.72959
-6.53899
-7.45524
-8.49403
-9.67361
-11.0151
-12.5439
-14.2908
-16.2748
-18.4948
-21.207
-24.8585
-0.19304
-0.29376
-0.399947
-0.520624
-0.656948
-0.81013
-0.982337
-1.17609
-1.39416
-1.63963
-1.91596
-2.22707
-2.57738
-2.97187
-3.41624
-3.91697
-4.48151
-5.11844
-5.83771
-6.65085
-7.57134
-8.61488
-9.79976
-11.1471
-12.6822
-14.4357
-16.4263
-18.6527
-21.3702
-25.0252
-0.271194
-0.373647
-0.480719
-0.602519
-0.740083
-0.894511
-1.06798
-1.26303
-1.48245
-1.72933
-2.00716
-2.31989
-2.67194
-3.06835
-3.51484
-4.01793
-4.58513
-5.22506
-5.9477
-6.76467
-7.68946
-8.73783
-9.92808
-11.2813
-12.8228
-14.583
-16.5804
-18.8132
-21.5362
-25.1948
-0.350255
-0.454458
-0.562443
-0.685413
-0.824263
-0.979983
-1.15476
-1.35116
-1.57197
-1.82031
-2.0997
-2.41408
-2.76793
-3.16631
-3.61497
-4.12049
-4.6904
-5.33338
-6.05947
-6.88032
-7.80948
-8.86275
-10.0584
-11.4177
-12.9657
-14.7327
-16.7369
-18.9762
-21.7048
-25.3671
-0.430157
-0.536123
-0.645049
-0.769233
-0.909414
-1.06647
-1.2426
-1.44039
-1.66264
-1.91249
-2.19347
-2.50956
-2.86525
-3.26565
-3.71654
-4.22453
-4.79721
-5.4433
-6.17289
-6.99769
-7.93128
-8.98952
-10.1907
-11.556
-13.1106
-14.8844
-16.8956
-19.1414
-21.8756
-25.5417
-0.510841
-0.618577
-0.728468
-0.853909
-0.995465
-1.1539
-1.33142
-1.53064
-1.75438
-2.00578
-2.28839
-2.60623
-2.96382
-3.36628
-3.81944
-4.32996
-4.90545
-5.55471
-6.28786
-7.11665
-8.05475
-9.11802
-10.3248
-11.6962
-13.2573
-15.0381
-17.0562
-19.3086
-22.0485
-25.7184
-0.592253
-0.701761
-0.812638
-0.939376
-1.08235
-1.2422
-1.42115
-1.62184
-1.8471
-2.10009
-2.38438
-2.70401
-3.06353
-3.46809
-3.92357
-4.43665
-5.01501
-5.66748
-6.40424
-7.23709
-8.17974
-9.2481
-10.4605
-11.8381
-13.4059
-15.1936
-17.2187
-19.4777
-22.2232
-25.897
-0.674346
-0.785618
-0.897497
-1.02557
-1.16999
-1.3313
-1.51172
-1.71391
-1.94072
-2.19533
-2.48133
-2.80279
-3.16427
-3.57098
-4.02881
-4.5445
-5.12577
-5.78149
-6.52191
-7.35887
-8.30613
-9.37962
-10.5977
-11.9816
-13.556
-15.3507
-17.3828
-19.6484
-22.3995
-26.0771
-0.75709
-0.870112
-0.983002
-1.11244
-1.25835
-1.42112
-1.60303
-1.80676
-2.03515
-2.29141
-2.57916
-2.90247
-3.26595
-3.67483
-4.13505
-4.65339
-5.2376
-5.89662
-6.64074
-7.48185
-8.43376
-9.51244
-10.7363
-12.1264
-13.7075
-15.5092
-17.5484
-19.8206
-22.5773
-26.2587
-0.840462
-0.955208
-1.06911
-1.19994
-1.34734
-1.51162
-1.69504
-1.90031
-2.1303
-2.38824
-2.67775
-3.00294
-3.36845
-3.77953
-4.24217
-4.76319
-5.35038
-6.01274
-6.76059
-7.6059
-8.56249
-9.6464
-10.876
-12.2724
-13.8603
-15.669
-17.7152
-19.994
-22.7562
-26.4414
-0.924443
-1.04087
-1.15577
-1.288
-1.43693
-1.60271
-1.78765
-1.99447
-2.22608
-2.48571
-2.777
-3.10409
-3.47164
-3.88496
-4.35004
-4.87377
-5.46398
-6.1297
-6.88133
-7.73086
-8.69218
-9.78134
-11.0168
-12.4195
-14.0141
-15.8299
-17.8831
-20.1684
-22.9361
-26.625
-1.00904
-1.12708
-1.24295
-1.37658
-1.52702
-1.69431
-1.88077
-2.08916
-2.32239
-2.58371
-2.87679
-3.20579
-3.57541
-3.99098
-4.45853
-4.98499
-5.57824
-6.24736
-7.00279
-7.85658
-8.82265
-9.9171
-11.1584
-12.5674
-14.1688
-15.9916
-18.0518
-20.3437
-23.1169
-26.8094
-1.09426
-1.21382
-1.33062
-1.46563
-1.61756
-1.78633
-1.9743
-2.18424
-2.41909
-2.68211
-2.97699
-3.30792
-3.67962
-4.09745
-4.5675
-5.0967
-5.69302
-6.36556
-7.12482
-7.9829
-8.95376
-10.0535
-11.3006
-12.716
-14.3242
-16.154
-18.2213
-20.5196
-23.2983
-26.9945
-1.18012
-1.30109
-1.41872
-1.55507
-1.70846
-1.87867
-2.06812
-2.2796
-2.51606
-2.78077
-3.07746
-3.41033
-3.78412
-4.20423
-4.67678
-5.20877
-5.80817
-6.48415
-7.24727
-8.10965
-9.08532
-10.1904
-11.4434
-12.8652
-14.4801
-16.317
-18.3912
-20.6961
-23.4801
-27.1799
-1.26665
-1.38882
-1.50718
-1.64479
-1.79958
-1.97119
-2.16208
-2.37507
-2.61313
-2.87954
-3.17803
-3.51284
-3.88874
-4.31115
-4.78624
-5.32101
-5.92352
-6.60297
-7.36996
-8.23667
-9.21717
-10.3276
-11.5865
-13.0146
-14.6364
-16.4803
-18.5615
-20.8728
-23.6622
-27.3656
-1.35381
-1.47693
-1.59586
-1.73464
-1.89074
-2.0637
-2.25599
-2.47047
-2.71012
-2.97822
-3.27853
-3.61529
-3.99332
-4.41805
-4.89568
-5.43328
-6.03892
-6.72185
-7.49273
-8.36379
-9.34912
-10.4649
-11.7297
-13.1642
-14.7928
-16.6438
-18.732
-21.0498
-23.8445
-27.5514
-1.44151
-1.56524
-1.68455
-1.82437
-1.98169
-2.15593
-2.3496
-2.56557
-2.8068
-3.07661
-3.37876
-3.7175
-4.09768
-4.52475
-5.00495
-5.54539
-6.15417
-6.84061
-7.61539
-8.49081
-9.48099
-10.6022
-11.8728
-13.3138
-14.9492
-16.8072
-18.9024
-21.2268
-24.0269
-27.7373
-1.52948
-1.65336
-1.77284
-1.91359
-2.07208
-2.24758
-2.44263
-2.6601
-2.90296
-3.17451
-3.47852
-3.81928
-4.20164
-4.63108
-5.11388
-5.65718
-6.26913
-6.95909
-7.73778
-8.61756
-9.61259
-10.7391
-12.0157
-13.463
-15.1052
-16.9703
-19.0726
-21.4036
-24.2094
-27.9234
-1.61718
-1.74063
-1.8601
-2.00174
-2.16141
-2.33823
-2.53472
-2.75377
-2.99832
-3.27168
-3.57762
-3.92045
-4.30502
-4.73687
-5.2223
-5.76848
-6.38361
-7.07709
-7.85972
-8.74385
-9.74372
-10.8756
-12.158
-13.6118
-15.2608
-17.133
-19.2425
-21.5803
-24.392
-28.1098
-1.70356
-1.82587
-1.94537
-2.08808
-2.24912
-2.42742
-2.62552
-2.8463
-3.09266
-3.36792
-3.67588
-4.02083
-4.40767
-4.84197
-5.33005
-5.87913
-6.49745
-7.19447
-7.98101
-8.86949
-9.87419
-11.0114
-12.2997
-13.7597
-15.4155
-17.2949
-19.4116
-21.7567
-24.5748
-28.2971
-1.78651
-1.90711
-2.02722
-2.17168
-2.33458
-2.51474
-2.71475
-2.93747
-3.18582
-3.46311
-3.77315
-4.1203
-4.50946
-4.94623
-5.43699
-5.98898
-6.6105
-7.31105
-8.10149
-8.9943
-10.0038
-11.1463
-12.4403
-13.9067
-15.5692
-17.4557
-19.5797
-21.9323
-24.7582
-28.4863
-1.86145
-1.9809
-2.10396
-2.25175
-2.41737
-2.59997
-2.80229
-3.02723
-3.27772
-3.55715
-3.86937
-4.21875
-4.61025
-5.04952
-5.54296
-6.09787
-6.72258
-7.42664
-8.22096
-9.11806
-10.1323
-11.28
-12.5797
-14.0522
-15.7214
-17.6149
-19.7463
-22.1068
-24.9423
-28.6803
-1.91986
-2.04156
-2.17527
-2.32922
-2.49824
-2.68365
-2.88856
-3.11586
-3.36858
-3.65018
-3.96458
-4.31621
-4.71007
-5.15183
-5.64795
-6.20577
-6.83367
-7.54122
-8.33939
-9.24074
-10.2596
-11.4125
-12.7178
-14.1963
-15.8719
-17.7722
-19.9106
-22.2786
-25.1257
-28.8834
1.45578
1.38753
1.28041
1.16194
1.03078
0.883179
0.716861
0.529724
0.319356
0.0830202
-0.182339
-0.480137
-0.814215
-1.1889
-1.6091
-2.08038
-2.60913
-3.20267
-3.86948
-4.61941
-5.46402
-6.41699
-7.49459
-8.71629
-10.1068
-11.6982
-13.5143
-15.5661
-18.1416
-21.7444
1.43296
1.36936
1.26732
1.15453
1.02778
0.88329
0.719385
0.534293
0.32572
0.0910007
-0.172868
-0.469266
-0.802009
-1.17541
-1.59437
-2.06445
-2.59204
-3.18446
-3.85021
-4.59916
-5.44291
-6.39517
-7.47226
-8.69372
-10.0844
-11.6763
-13.4936
-15.546
-18.1172
-21.7043
1.42645
1.35962
1.26002
1.14967
1.02488
0.882113
0.719807
0.536205
0.329023
0.0956189
-0.166993
-0.46218
-0.793751
-1.16602
-1.58387
-2.05289
-2.57945
-3.17091
-3.83576
-4.5839
-5.42696
-6.3787
-7.45548
-8.67688
-10.0677
-11.6601
-13.4777
-15.5294
-18.0937
-21.6608
1.42244
1.35432
1.25554
1.14585
1.02179
0.879904
0.718557
0.535937
0.329748
0.0973413
-0.164269
-0.458456
-0.789032
-1.16031
-1.5772
-2.04527
-2.57093
-3.16153
-3.8256
-4.57304
-5.41553
-6.36686
-7.44343
-8.66485
-10.0559
-11.6486
-13.4665
-15.5181
-18.0793
-21.6358
1.41808
1.34928
1.25065
1.14116
1.01747
0.876115
0.715378
0.533418
0.32793
0.096262
-0.164578
-0.457968
-0.78773
-1.15819
-1.57425
-2.04152
-2.56641
-3.15628
-3.81967
-4.56655
-5.4086
-6.35964
-7.43613
-8.6577
-10.0491
-11.6424
-13.4609
-15.513
-18.0737
-21.6256
1.41245
1.34283
1.24417
1.13477
1.01129
0.870279
0.709956
0.528459
0.323477
0.0923569
-0.167897
-0.460668
-0.789783
-1.15958
-1.57498
-2.04159
-2.56584
-3.15512
-3.818
-4.56446
-5.40621
-6.35713
-7.4337
-8.65561
-10.0477
-11.6418
-13.4612
-15.5145
-18.0758
-21.6257
1.40429
1.33401
1.23539
1.12606
1.00275
0.861997
0.701991
0.520848
0.316252
0.0855494
-0.174256
-0.466549
-0.795162
-1.16444
-1.57931
-2.04541
-2.56917
-3.15802
-3.82053
-4.56672
-5.40835
-6.35934
-7.4362
-8.65868
-10.0516
-11.6469
-13.4678
-15.5225
-18.0851
-21.6347
1.39299
1.32227
1.22381
1.1146
0.991458
0.850946
0.691223
0.510383
0.306106
0.0757379
-0.183715
-0.475639
-0.803867
-1.17275
-1.58723
-2.05295
-2.57637
-3.16492
-3.82722
-4.57332
-5.415
-6.36625
-7.44362
-8.66691
-10.061
-11.6578
-13.4805
-15.5372
-18.1017
-21.6519
1.37841
1.3074
1.20917
1.10013
0.977176
0.836912
0.677463
0.496905
0.292911
0.0628255
-0.196343
-0.487979
-0.815917
-1.18451
-1.59872
-2.06418
-2.58739
-3.17579
-3.83803
-4.5842
-5.42613
-6.37783
-7.45594
-8.68028
-10.0758
-11.6744
-13.4993
-15.5585
-18.1254
-21.6771
1.36056
1.28932
1.19138
1.08253
0.959787
0.819776
0.660598
0.48031
0.276576
0.0467383
-0.212194
-0.503606
-0.831333
-1.19973
-1.61376
-2.07909
-2.60221
-3.19061
-3.85295
-4.59936
-5.44171
-6.39407
-7.47312
-8.69878
-10.096
-11.6968
-13.5242
-15.5863
-18.1561
-21.7097
1.33951
1.26806
1.17042
1.06178
0.939251
0.799488
0.640573
0.460542
0.257049
0.0274309
-0.231306
-0.522547
-0.85013
-1.21842
-1.63237
-2.09767
-2.62083
-3.20936
-3.87194
-4.61875
-5.46171
-6.41493
-7.49516
-8.72237
-10.1216
-11.7248
-13.5551
-15.6205
-18.1935
-21.7494
1.31536
1.24369
1.14635
1.03792
0.915579
0.776048
0.61738
0.437587
0.234312
0.00488453
-0.253695
-0.544815
-0.872317
-1.24056
-1.65453
-2.11991
-2.64322
-3.232
-3.89498
-4.64235
-5.48609
-6.44037
-7.52201
-8.75103
-10.1525
-11.7585
-13.592
-15.6609
-18.2375
-21.7959
1.28823
1.2163
1.11924
1.01099
0.888819
0.749493
0.591043
0.411459
0.208371
-0.0209006
-0.279363
-0.570411
-0.897888
-1.26617
-1.68023
-2.14577
-2.66935
-3.25851
-3.92203
-4.67012
-5.51483
-6.47037
-7.55363
-8.78469
-10.1887
-11.7977
-13.6348
-15.7075
-18.2878
-21.849
1.25824
1.18599
1.08917
0.98107
0.859034
0.719872
0.5616
0.382188
0.17925
-0.0499038
-0.308291
-0.599313
-0.926822
-1.2952
-1.70943
-2.17524
-2.69919
-3.28886
-3.95305
-4.70203
-5.54788
-6.50488
-7.58997
-8.82332
-10.2301
-11.8424
-13.6833
-15.7602
-18.3444
-21.9084
1.22548
1.15286
1.05624
0.948245
0.826293
0.687247
0.529109
0.349826
0.146998
-0.0820806
-0.340438
-0.631484
-0.959085
-1.32763
-1.74212
-2.20828
-2.73272
-3.32302
-3.98802
-4.73804
-5.5852
-6.54384
-7.63098
-8.86684
-10.2767
-11.8926
-13.7375
-15.8187
-18.4071
-21.9741
1.19008
1.11701
1.02054
0.912597
0.790679
0.6517
0.493646
0.314443
0.111675
-0.117378
-0.375758
-0.666887
-0.994642
-1.36342
-1.77825
-2.24487
-2.76988
-3.36093
-4.02688
-4.77809
-5.62673
-6.58721
-7.67661
-8.9152
-10.3283
-11.948
-13.7972
-15.883
-18.4758
-22.0459
1.15211
1.07853
0.982158
0.874218
0.752278
0.61331
0.455283
0.276103
0.0733381
-0.155746
-0.414204
-0.705476
-1.03345
-1.40254
-1.81778
-2.28494
-2.81065
-3.40256
-4.06959
-4.82214
-5.67243
-6.63493
-7.72678
-8.96833
-10.385
-12.0087
-13.8625
-15.953
-18.5503
-22.1236
1.11168
1.0375
0.941176
0.833184
0.711165
0.572145
0.414085
0.234868
0.0320487
-0.197124
-0.455722
-0.747198
-1.07546
-1.44493
-1.86067
-2.32846
-2.85496
-3.44786
-4.1161
-4.87013
-5.72223
-6.68693
-7.78144
-9.02616
-10.4465
-12.0746
-13.9331
-16.0286
-18.6306
-22.2071
1.06885
0.994007
0.897664
0.789567
0.667408
0.528277
0.370123
0.19081
-0.0121258
-0.241448
-0.500247
-0.791992
-1.1206
-1.49053
-1.90685
-2.37537
-2.90276
-3.49676
-4.16634
-4.922
-5.77608
-6.74316
-7.84051
-9.08861
-10.5129
-12.1455
-14.009
-16.1097
-18.7165
-22.2963
1.02368
0.948107
0.851695
0.743438
0.621081
0.481778
0.323468
0.143996
-0.059117
-0.288653
-0.547716
-0.839797
-1.16883
-1.53929
-1.95627
-2.4256
-2.954
-3.54921
-4.22026
-4.97769
-5.8339
-6.80353
-7.90392
-9.1556
-10.5841
-12.2214
-14.0901
-16.1962
-18.8079
-22.3912
0.976257
0.899871
0.803338
0.694867
0.572253
0.432718
0.274191
0.0944975
-0.108857
-0.33867
-0.598065
-0.890549
-1.22008
-1.59115
-2.00888
-2.47911
-3.0086
-3.60514
-4.27778
-5.03713
-5.89562
-6.86797
-7.97159
-9.22706
-10.6599
-12.3022
-14.1763
-16.288
-18.9047
-22.4915
0.926627
0.849363
0.752657
0.643919
0.520992
0.381165
0.222359
0.0423815
-0.161278
-0.391434
-0.651226
-0.944182
-1.27428
-1.64604
-2.06459
-2.53582
-3.06651
-3.66448
-4.33885
-5.10024
-5.96117
-6.93642
-8.04344
-9.30289
-10.7403
-12.3877
-14.2675
-16.3849
-19.0069
-22.5973
0.874854
0.796645
0.699717
0.59066
0.467363
0.327185
0.16804
-0.0122839
-0.216312
-0.446875
-0.707131
-1.00063
-1.33137
-1.70389
-2.12335
-2.59567
-3.12766
-3.72717
-4.40337
-5.16695
-6.03047
-7.00877
-8.11938
-9.383
-10.8252
-12.478
-14.3636
-16.487
-19.1144
-22.7084
0.820997
0.741778
0.644579
0.535154
0.411432
0.270845
0.111301
-0.0694307
-0.273891
-0.504925
-0.765712
-1.05982
-1.39127
-1.76463
-2.18508
-2.65858
-3.19196
-3.79313
-4.47129
-5.23718
-6.10343
-7.08494
-8.19931
-9.4673
-10.9145
-12.5729
-14.4645
-16.5941
-19.2271
-22.8248
0.765116
0.684824
0.587309
0.477465
0.353263
0.21221
0.0522087
-0.128991
-0.333945
-0.565515
-0.826898
-1.12168
-1.45392
-1.82819
-2.24972
-2.72448
-3.25935
-3.86228
-4.54251
-5.31084
-6.17996
-7.16483
-8.28313
-9.55567
-11.0081
-12.6723
-14.5702
-16.7061
-19.3449
-22.9466
0.707272
0.625845
0.527969
0.417658
0.292923
0.151349
-0.00916777
-0.190895
-0.396404
-0.628574
-0.890619
-1.18615
-1.51924
-1.8945
-2.31718
-2.79329
-3.32975
-3.93453
-4.61695
-5.38784
-6.25996
-7.24835
-8.37073
-9.64799
-11.1058
-12.776
-14.6804
-16.8231
-19.468
-23.0738
0.647526
0.564906
0.466625
0.355799
0.230479
0.0883286
-0.0727602
-0.255074
-0.461199
-0.69403
-0.956803
-1.25315
-1.58716
-1.96349
-2.3874
-2.86494
-3.40307
-4.00981
-4.69451
-5.46808
-6.34333
-7.33537
-8.46199
-9.74413
-11.2075
-12.8839
-14.7951
-16.9448
-19.5964
-23.2067
0.585944
0.502073
0.403345
0.291956
0.165999
0.0232184
-0.138498
-0.321457
-0.528258
-0.761813
-1.02538
-1.3226
-1.65761
-2.03507
-2.46029
-2.93934
-3.47923
-4.08802
-4.77512
-5.55147
-6.42997
-7.42579
-8.55678
-9.84395
-11.313
-12.9959
-14.9141
-17.0712
-19.7302
-23.346
0.522589
0.437414
0.338199
0.226201
0.0995554
-0.0439084
-0.206308
-0.389968
-0.597504
-0.831843
-1.09626
-1.39443
-1.7305
-2.10916
-2.53576
-3.01641
-3.55814
-4.16907
-4.85865
-5.6379
-6.51975
-7.51945
-8.65493
-9.94724
-11.4222
-13.1116
-15.037
-17.2019
-19.8696
-23.4933
0.457517
0.370977
0.271231
0.158575
0.0311881
-0.113014
-0.276154
-0.460574
-0.668905
-0.904091
-1.16942
-1.4686
-1.8058
-2.18574
-2.6138
-3.09612
-3.63978
-4.25294
-4.9451
-5.72734
-6.61265
-7.61635
-8.75641
-10.054
-11.5348
-13.2309
-15.1635
-17.3362
-20.0138
-23.6511
1.49278
1.50689
1.48147
1.44979
1.41406
1.37468
1.33191
1.28582
1.23649
1.18401
1.12847
1.06996
1.0086
0.944485
0.877749
0.808529
0.736969
0.663231
0.587486
0.509922
0.430736
0.350139
0.268357
0.185624
0.102184
0.0182911
-0.0657957
-0.14981
-0.233477
-0.316559
1.38941
1.39653
1.37773
1.34989
1.3161
1.27778
1.23554
1.18968
1.14038
1.08779
1.03204
0.973268
0.911573
0.847085
0.779943
0.710288
0.638273
0.564063
0.487833
0.409774
0.330088
0.248987
0.166698
0.083458
-0.000488073
-0.0848862
-0.169477
-0.253996
-0.338165
-0.421746
1.28735
1.2877
1.27081
1.24506
1.21256
1.17483
1.13271
1.08667
1.03701
0.98394
0.927623
0.86821
0.805833
0.740632
0.672755
0.60235
0.529575
0.454599
0.377601
0.298775
0.218322
0.136458
0.0534082
-0.0305913
-0.115296
-0.200454
-0.285809
-0.371098
-0.456047
-0.540424
1.16624
1.16258
1.14637
1.12184
1.09041
1.05341
1.01169
0.96579
0.916067
0.862784
0.806146
0.746326
0.683476
0.617754
0.549315
0.478317
0.404926
0.329316
0.251672
0.172188
0.0910704
0.00853595
-0.0751892
-0.159869
-0.245259
-0.331109
-0.417165
-0.503166
-0.588838
-0.673957
1.03041
1.02363
1.00728
0.983201
0.952393
0.915902
0.874492
0.828703
0.778921
0.725442
0.668498
0.60828
0.544964
0.47872
0.409715
0.338117
0.264098
0.187839
0.109529
0.0293667
-0.0524384
-0.135668
-0.220095
-0.305482
-0.391585
-0.478155
-0.564939
-0.651678
-0.738097
-0.823984
0.879378
0.870046
0.852946
0.828775
0.798156
0.761871
0.720569
0.674753
0.624814
0.571058
0.513735
0.453056
0.38921
0.322383
0.25275
0.180488
0.105778
0.0288061
-0.0502334
-0.131138
-0.213695
-0.297684
-0.382877
-0.469035
-0.555916
-0.64327
-0.730845
-0.818384
-0.905614
-0.992329
0.710467
0.699008
0.680873
0.656245
0.625484
0.589151
0.547773
0.5018
0.451605
0.397497
0.339732
0.278533
0.214104
0.14664
0.0763261
0.0033472
-0.0721088
-0.149849
-0.229675
-0.311378
-0.394746
-0.479554
-0.565572
-0.652562
-0.740281
-0.828479
-0.916908
-1.00531
-1.09341
-1.18102
0.521136
0.507813
0.48851
0.463188
0.432035
0.395439
0.353818
0.307562
0.257016
0.202479
0.144208
0.0824331
0.0173695
-0.050782
-0.121827
-0.195574
-0.271827
-0.350388
-0.431053
-0.513612
-0.597846
-0.683531
-0.770433
-0.858315
-0.946933
-1.03604
-1.12538
-1.21471
-1.30374
-1.39231
0.308833
0.293815
0.27328
0.247101
0.215358
0.178314
0.136293
0.0896265
0.0386287
-0.0164209
-0.0752697
-0.137681
-0.203438
-0.272332
-0.344163
-0.418732
-0.495838
-0.575277
-0.65684
-0.740313
-0.825475
-0.912099
-0.99995
-1.08879
-1.17837
-1.26845
-1.35878
-1.4491
-1.53914
-1.62873
0.0707539
0.0541601
0.0323611
0.00521092
-0.0272778
-0.0649307
-0.107497
-0.154696
-0.206252
-0.261904
-0.321407
-0.384525
-0.451039
-0.520738
-0.593416
-0.668867
-0.746887
-0.827266
-0.909792
-0.994245
-1.0804
-1.16803
-1.25691
-1.34678
-1.4374
-1.52853
-1.61992
-1.7113
-1.80242
-1.89312
-0.196213
-0.214295
-0.237373
-0.265579
-0.298938
-0.337337
-0.380578
-0.42843
-0.480651
-0.536999
-0.597238
-0.661139
-0.728482
-0.799054
-0.872646
-0.949049
-1.02805
-1.10944
-1.193
-1.27851
-1.36573
-1.45445
-1.54442
-1.6354
-1.72714
-1.81941
-1.91194
-2.00448
-2.09677
-2.18865
-0.495525
-0.515034
-0.539398
-0.568724
-0.603056
-0.642315
-0.686352
-0.734973
-0.787963
-0.845104
-0.906169
-0.970934
-1.03919
-1.11071
-1.18529
-1.26272
-1.34278
-1.42526
-1.50993
-1.59657
-1.68495
-1.77484
-1.866
-1.95818
-2.05114
-2.14463
-2.2384
-2.33219
-2.42574
-2.51891
-0.831048
-0.851941
-0.877597
-0.908094
-0.94348
-0.983703
-1.02865
-1.07814
-1.13201
-1.19004
-1.25203
-1.31775
-1.38699
-1.45955
-1.53521
-1.61375
-1.69495
-1.77861
-1.86448
-1.95235
-2.04198
-2.13314
-2.22559
-2.31907
-2.41334
-2.50816
-2.60328
-2.69843
-2.79335
-2.88792
-1.20713
-1.22938
-1.25633
-1.28804
-1.32455
-1.36583
-1.41178
-1.46226
-1.51711
-1.57613
-1.63913
-1.70591
-1.77624
-1.84993
-1.92675
-2.0065
-2.08895
-2.17388
-2.26106
-2.35026
-2.44125
-2.53379
-2.62763
-2.72253
-2.81824
-2.91451
-3.01109
-3.10772
-3.20412
-3.30022
-1.62869
-1.65226
-1.68052
-1.71348
-1.75118
-1.79359
-1.84064
-1.89221
-1.94813
-2.00825
-2.07238
-2.14031
-2.21184
-2.28676
-2.36485
-2.44591
-2.52971
-2.61603
-2.70463
-2.79528
-2.88775
-2.98179
-3.07715
-3.1736
-3.27087
-3.36872
-3.46691
-3.56515
-3.66317
-3.76093
-2.10131
-2.12619
-2.15576
-2.18999
-2.22893
-2.27255
-2.32079
-2.37353
-2.43064
-2.49197
-2.55732
-2.62651
-2.69934
-2.77561
-2.8551
-2.93759
-3.02286
-3.11069
-3.20084
-3.29307
-3.38715
-3.48283
-3.57986
-3.678
-3.77698
-3.87657
-3.9765
-4.07649
-4.1763
-4.27586
-2.63136
-2.65754
-2.68841
-2.72394
-2.76416
-2.80906
-2.85856
-2.91257
-2.97097
-3.0336
-3.10029
-3.17086
-3.24512
-3.32285
-3.40385
-3.48791
-3.57479
-3.66426
-3.7561
-3.85006
-3.9459
-4.04338
-4.14223
-4.24222
-4.34308
-4.44456
-4.5464
-4.64833
-4.75007
-4.85162
-3.22618
-3.25363
-3.2858
-3.32264
-3.36417
-3.41039
-3.46123
-3.51659
-3.57636
-3.6404
-3.70855
-3.78061
-3.85641
-3.93575
-4.0184
-4.10415
-4.19278
-4.28406
-4.37774
-4.47359
-4.57137
-4.67081
-4.77166
-4.87368
-4.97659
-5.08015
-5.1841
-5.28813
-5.39199
-5.4957
-3.89422
-3.92289
-3.95634
-3.99449
-4.03736
-4.08494
-4.13716
-4.19395
-4.25518
-4.32073
-4.39043
-4.46411
-4.54159
-4.62265
-4.70709
-4.7947
-4.88524
-4.97848
-5.07418
-5.17209
-5.27198
-5.37357
-5.47662
-5.58086
-5.68603
-5.79187
-5.89812
-6.00446
-6.11064
-6.21672
-4.64532
-4.67516
-4.70984
-4.74927
-4.79347
-4.84242
-4.89607
-4.95433
-5.0171
-5.08424
-5.15561
-5.23102
-5.31029
-5.39322
-5.4796
-5.56921
-5.66182
-5.7572
-5.85509
-5.95527
-6.05746
-6.16141
-6.26686
-6.37354
-6.48118
-6.58952
-6.69829
-6.80716
-6.91588
-7.02453
-5.49101
-5.52192
-5.55776
-5.59841
-5.6439
-5.69421
-5.74929
-5.80906
-5.87341
-5.94222
-6.01533
-6.09257
-6.17376
-6.25869
-6.34715
-6.43893
-6.53378
-6.63147
-6.73175
-6.83437
-6.93908
-7.0456
-7.15367
-7.26302
-7.37337
-7.48446
-7.59598
-7.70762
-7.8191
-7.93057
-6.44493
-6.47677
-6.51363
-6.55539
-6.60208
-6.65369
-6.71017
-6.77144
-6.83739
-6.90791
-6.98283
-7.06199
-7.14519
-7.23224
-7.32292
-7.417
-7.51426
-7.61444
-7.71729
-7.82257
-7.93
-8.03932
-8.15025
-8.26251
-8.37582
-8.4899
-8.60445
-8.7191
-8.83358
-8.94811
-7.52327
-7.55582
-7.5935
-7.63618
-7.68391
-7.7367
-7.79448
-7.85719
-7.92472
-7.99695
-8.07371
-8.15483
-8.24013
-8.32939
-8.42239
-8.51892
-8.61872
-8.72156
-8.82717
-8.93529
-9.04566
-9.158
-9.27202
-9.38744
-9.50397
-9.62131
-9.73914
-9.85708
-9.97482
-10.0926
-8.74543
-8.77836
-8.81653
-8.85984
-8.90837
-8.96212
-9.02104
-9.08506
-9.15407
-9.22795
-9.30652
-9.38961
-9.47702
-9.56854
-9.66395
-9.76302
-9.86549
-9.97111
-10.0796
-10.1908
-10.3043
-10.4198
-10.5372
-10.656
-10.776
-10.8969
-11.0183
-11.1398
-11.261
-11.3824
-10.136
-10.1688
-10.207
-10.2505
-10.2994
-10.3538
-10.4136
-10.4787
-10.5491
-10.6244
-10.7047
-10.7897
-10.8792
-10.973
-11.0708
-11.1724
-11.2776
-11.3861
-11.4977
-11.612
-11.7287
-11.8477
-11.9686
-12.091
-12.2147
-12.3394
-12.4647
-12.59
-12.7151
-12.8401
-11.7267
-11.7587
-11.7963
-11.8394
-11.8882
-11.9428
-12.003
-12.0689
-12.1403
-12.2169
-12.2987
-12.3854
-12.4769
-12.5728
-12.673
-12.7771
-12.885
-12.9964
-13.111
-13.2285
-13.3486
-13.4711
-13.5956
-13.7219
-13.8495
-13.9783
-14.1077
-14.2372
-14.3663
-14.4952
-13.5412
-13.5715
-13.6075
-13.6494
-13.6974
-13.7515
-13.8117
-13.8779
-13.9499
-14.0275
-14.1105
-14.1987
-14.2918
-14.3896
-14.4919
-14.5984
-14.7089
-14.823
-14.9405
-15.0611
-15.1845
-15.3105
-15.4387
-15.5689
-15.7006
-15.8336
-15.9674
-16.1015
-16.235
-16.3677
-15.5901
-15.6173
-15.6501
-15.6895
-15.7357
-15.7887
-15.8483
-15.9143
-15.9865
-16.0646
-16.1483
-16.2375
-16.332
-16.4313
-16.5354
-16.6439
-16.7565
-16.873
-16.9931
-17.1166
-17.243
-17.3723
-17.504
-17.6379
-17.7736
-17.9108
-18.0492
-18.1881
-18.3267
-18.4637
-18.1552
-18.1743
-18.2011
-18.2366
-18.2803
-18.3318
-18.3904
-18.4559
-18.5279
-18.6062
-18.6904
-18.7803
-18.8756
-18.9761
-19.0815
-19.1915
-19.3059
-19.4243
-19.5466
-19.6724
-19.8014
-19.9334
-20.0682
-20.2055
-20.345
-20.4863
-20.6294
-20.7746
-20.9216
-21.0654
-21.7214
-21.7234
-21.7429
-21.7752
-21.8173
-21.8679
-21.9262
-21.9916
-22.0637
-22.1423
-22.227
-22.3176
-22.4138
-22.5153
-22.6218
-22.7331
-22.8489
-22.9688
-23.0927
-23.2203
-23.3513
-23.4855
-23.6228
-23.763
-23.9061
-24.0519
-24.2009
-24.3555
-24.5176
-24.6737
-0.398895
-0.480013
-0.559792
-0.637985
-0.714381
-0.788784
-0.861018
-0.930929
-0.998383
-1.06327
-1.12548
-1.18496
-1.24165
-1.29549
-1.34648
-1.39459
-1.43983
-1.48221
-1.52175
-1.55849
-1.59246
-1.62371
-1.65227
-1.6781
-1.70106
-1.72068
-1.73617
-1.74447
-1.72769
-1.66561
-0.504606
-0.586232
-0.666527
-0.745239
-0.822155
-0.897082
-0.969841
-1.04028
-1.10826
-1.17366
-1.23639
-1.29638
-1.35355
-1.40788
-1.45934
-1.5079
-1.55357
-1.59636
-1.63629
-1.67338
-1.70767
-1.73918
-1.76789
-1.79376
-1.81649
-1.83556
-1.85051
-1.85883
-1.84608
-1.80975
-0.624114
-0.706579
-0.787743
-0.867351
-0.945195
-1.02108
-1.09484
-1.1663
-1.23534
-1.30184
-1.36569
-1.42683
-1.48518
-1.54071
-1.59338
-1.64317
-1.69008
-1.73412
-1.7753
-1.81364
-1.84916
-1.88187
-1.91174
-1.9387
-1.96249
-1.98267
-1.99902
-2.01018
-2.00867
-1.99702
-0.758424
-0.841678
-0.923658
-1.00411
-1.08283
-1.15962
-1.2343
-1.30673
-1.37677
-1.44428
-1.50918
-1.57139
-1.63083
-1.68746
-1.74124
-1.79216
-1.84021
-1.88538
-1.92769
-1.96714
-2.00376
-2.03755
-2.06847
-2.09646
-2.1213
-2.14269
-2.16046
-2.1738
-2.17943
-2.18161
-0.90925
-0.993312
-1.07613
-1.15743
-1.23703
-1.31473
-1.39035
-1.46374
-1.53476
-1.60329
-1.66922
-1.73247
-1.79298
-1.85069
-1.90557
-1.95758
-2.00673
-2.05301
-2.09642
-2.13697
-2.17467
-2.20953
-2.24151
-2.27056
-2.29653
-2.31922
-2.33853
-2.35396
-2.36433
-2.37388
-1.07846
-1.16339
-1.24709
-1.32932
-1.40986
-1.48852
-1.56513
-1.63954
-1.7116
-1.78119
-1.84821
-1.91257
-1.9742
-2.03304
-2.08907
-2.14225
-2.19256
-2.24
-2.28458
-2.3263
-2.36517
-2.40118
-2.43432
-2.46455
-2.49177
-2.51587
-2.53685
-2.55447
-2.56858
-2.5825
-1.26807
-1.35393
-1.43859
-1.52179
-1.60333
-1.68302
-1.76068
-1.83617
-1.90933
-1.98004
-2.04821
-2.11373
-2.17655
-2.23659
-2.29383
-2.34823
-2.39977
-2.44844
-2.49426
-2.53721
-2.57731
-2.61455
-2.64893
-2.68042
-2.70898
-2.73457
-2.75726
-2.77703
-2.79418
-2.81109
-1.48035
-1.56721
-1.65289
-1.73713
-1.81973
-1.90051
-1.97928
-2.0559
-2.13022
-2.20212
-2.2715
-2.33825
-2.4023
-2.46361
-2.52212
-2.57779
-2.63062
-2.68059
-2.72769
-2.77194
-2.81332
-2.85186
-2.88754
-2.92037
-2.95033
-2.97746
-3.00186
-3.02367
-3.04335
-3.06255
-1.71783
-1.80576
-1.89253
-1.97788
-2.06162
-2.14355
-2.22351
-2.30133
-2.37688
-2.45003
-2.52068
-2.58872
-2.65409
-2.71671
-2.77655
-2.83357
-2.88775
-2.93907
-2.98752
-3.03312
-3.07586
-3.11576
-3.15282
-3.18705
-3.21849
-3.2472
-3.27333
-3.29709
-3.31894
-3.34008
-1.98337
-2.07244
-2.16038
-2.24692
-2.33187
-2.41504
-2.49625
-2.57536
-2.65221
-2.72669
-2.79868
-2.86808
-2.93483
-2.99885
-3.06009
-3.11853
-3.17412
-3.22686
-3.27674
-3.32376
-3.36793
-3.40926
-3.44778
-3.4835
-3.51649
-3.54684
-3.57472
-3.60037
-3.62422
-3.64712
-2.28014
-2.37045
-2.45964
-2.54746
-2.63371
-2.7182
-2.80076
-2.88123
-2.95947
-3.03536
-3.10877
-3.17962
-3.24783
-3.31332
-3.37605
-3.43598
-3.49307
-3.54731
-3.5987
-3.64723
-3.69291
-3.73577
-3.77582
-3.81312
-3.84775
-3.8798
-3.90948
-3.937
-3.96273
-3.98733
-2.61173
-2.70338
-2.79393
-2.88312
-2.97076
-3.05667
-3.14067
-3.22261
-3.30233
-3.37972
-3.45465
-3.52704
-3.5968
-3.66386
-3.72816
-3.78967
-3.84835
-3.90419
-3.95717
-4.0073
-4.0546
-4.09908
-4.14078
-4.17976
-4.21611
-4.24995
-4.28146
-4.31085
-4.33843
-4.36475
-2.98219
-3.07528
-3.1673
-3.25797
-3.34712
-3.43456
-3.5201
-3.6036
-3.68491
-3.76391
-3.84047
-3.9145
-3.98591
-4.05463
-4.12062
-4.18381
-4.24418
-4.30172
-4.35641
-4.40825
-4.45727
-4.50348
-4.54694
-4.58771
-4.62588
-4.66159
-4.69499
-4.7263
-4.75574
-4.78382
-3.39606
-3.49072
-3.58432
-3.67661
-3.76738
-3.85646
-3.94367
-4.02886
-4.11187
-4.19259
-4.27089
-4.34668
-4.41986
-4.49036
-4.55814
-4.62313
-4.68532
-4.74467
-4.80119
-4.85486
-4.90572
-4.9538
-4.99914
-5.04181
-5.08191
-5.11957
-5.15495
-5.18821
-5.21956
-5.24947
-3.85848
-3.95484
-4.05017
-4.1442
-4.23674
-4.3276
-4.41661
-4.50361
-4.58846
-4.67103
-4.7512
-4.82887
-4.90395
-4.97637
-5.04606
-5.11299
-5.17711
-5.23841
-5.29688
-5.35252
-5.40536
-5.45543
-5.50277
-5.54747
-5.58962
-5.62933
-5.66677
-5.70207
-5.7354
-5.76723
-4.37528
-4.4735
-4.57071
-4.66663
-4.76107
-4.85386
-4.94481
-5.03378
-5.12061
-5.20517
-5.28735
-5.36705
-5.44417
-5.51863
-5.59039
-5.65939
-5.7256
-5.78899
-5.84956
-5.90731
-5.96227
-6.01446
-6.06396
-6.11081
-6.15512
-6.197
-6.2366
-6.27402
-6.30941
-6.34327
-4.95307
-5.05331
-5.15256
-5.25054
-5.34706
-5.44193
-5.53499
-5.62607
-5.71504
-5.80175
-5.8861
-5.96797
-6.04729
-6.12396
-6.19793
-6.26916
-6.3376
-6.40323
-6.46605
-6.52607
-6.58329
-6.63777
-6.68955
-6.73869
-6.78529
-6.82947
-6.87133
-6.91097
-6.94853
-6.98453
-5.59938
-5.70183
-5.8033
-5.90351
-6.00228
-6.09941
-6.19474
-6.28812
-6.37939
-6.46843
-6.55511
-6.63933
-6.721
-6.80004
-6.8764
-6.95001
-7.02084
-7.08888
-7.15412
-7.21655
-7.2762
-7.33311
-7.38732
-7.4389
-7.48793
-7.53452
-7.57876
-7.62074
-7.66057
-7.69882
-6.32282
-6.42768
-6.53157
-6.6342
-6.7354
-6.83498
-6.93277
-7.02862
-7.12238
-7.21392
-7.30311
-7.38985
-7.47406
-7.55564
-7.63455
-7.71072
-7.78412
-7.85473
-7.92255
-7.98756
-8.0498
-8.1093
-8.1661
-8.22026
-8.27185
-8.32099
-8.36775
-8.41217
-8.45439
-8.49501
-7.13329
-7.24076
-7.34727
-7.45252
-7.55635
-7.65858
-7.75903
-7.85754
-7.95398
-8.0482
-8.14009
-8.22954
-8.31646
-8.40077
-8.48241
-8.56132
-8.63746
-8.71082
-8.78137
-8.84914
-8.91413
-8.97637
-9.03591
-9.0928
-9.14711
-9.19893
-9.24833
-9.29533
-9.34003
-9.38314
-8.0422
-8.1525
-8.26184
-8.36993
-8.4766
-8.58167
-8.68497
-8.78635
-8.88566
-8.98276
-9.07754
-9.1699
-9.25972
-9.34694
-9.43148
-9.51331
-9.59236
-9.66863
-9.74211
-9.81279
-9.88069
-9.94584
-10.0083
-10.0681
-10.1252
-10.1799
-10.232
-10.2817
-10.329
-10.3747
-9.06285
-9.17619
-9.28858
-9.3997
-9.50941
-9.61753
-9.72388
-9.82833
-9.93071
-10.0309
-10.1288
-10.2242
-10.3171
-10.4074
-10.4951
-10.58
-10.6621
-10.7415
-10.818
-10.8918
-10.9628
-11.031
-11.0965
-11.1593
-11.2195
-11.2771
-11.3321
-11.3846
-11.4346
-11.483
-10.2107
-10.3273
-10.4429
-10.5573
-10.6702
-10.7816
-10.8912
-10.9989
-11.1045
-11.208
-11.3091
-11.4078
-11.504
-11.5976
-11.6885
-11.7767
-11.8621
-11.9447
-12.0245
-12.1015
-12.1757
-12.2471
-12.3158
-12.3818
-12.4451
-12.5058
-12.5639
-12.6193
-12.6721
-12.7231
-11.504
-11.624
-11.7431
-11.8608
-11.9771
-12.0919
-12.2049
-12.316
-12.4251
-12.532
-12.6366
-12.7388
-12.8384
-12.9354
-13.0297
-13.1213
-13.2101
-13.2961
-13.3793
-13.4596
-13.5372
-13.612
-13.684
-13.7533
-13.8199
-13.8839
-13.9451
-14.0036
-14.0592
-14.113
-12.9654
-13.089
-13.2115
-13.3327
-13.4526
-13.5708
-13.6874
-13.8021
-13.9148
-14.0252
-14.1334
-14.2392
-14.3423
-14.4429
-14.5408
-14.6359
-14.7282
-14.8177
-14.9043
-14.9882
-15.0692
-15.1474
-15.2229
-15.2957
-15.3658
-15.4331
-15.4978
-15.5594
-15.6179
-15.6745
-14.6242
-14.7512
-14.8771
-15.0018
-15.1252
-15.247
-15.3672
-15.4855
-15.6018
-15.7159
-15.8278
-15.9372
-16.044
-16.1482
-16.2497
-16.3484
-16.4443
-16.5373
-16.6275
-16.7149
-16.7994
-16.8812
-16.9603
-17.0366
-17.1103
-17.1812
-17.2495
-17.3146
-17.3763
-17.4354
-16.5001
-16.6303
-16.7594
-16.8873
-17.014
-17.1393
-17.263
-17.3849
-17.5048
-17.6226
-17.7381
-17.8511
-17.9616
-18.0694
-18.1744
-18.2767
-18.3761
-18.4726
-18.5663
-18.6571
-18.7452
-18.8305
-18.9132
-18.9932
-19.0706
-19.1455
-19.2177
-19.2867
-19.3519
-19.4133
-18.5987
-18.7314
-18.8629
-18.9934
-19.1229
-19.2513
-19.3783
-19.5035
-19.6269
-19.7481
-19.8671
-19.9836
-20.0974
-20.2086
-20.317
-20.4226
-20.5253
-20.6251
-20.722
-20.8162
-20.9075
-20.9962
-21.0824
-21.166
-21.2473
-21.326
-21.4023
-21.476
-21.546
-21.6106
-21.1984
-21.3302
-21.462
-21.5939
-21.7256
-21.8566
-21.9863
-22.1145
-22.2408
-22.365
-22.4869
-22.6063
-22.7231
-22.8372
-22.9484
-23.0567
-23.1621
-23.2647
-23.3643
-23.4611
-23.5552
-23.6467
-23.7358
-23.8228
-23.9076
-23.9904
-24.0715
-24.1525
-24.2333
-24.3056
-24.7878
-24.9124
-25.0425
-25.1751
-25.3083
-25.441
-25.5727
-25.7029
-25.8312
-25.9574
-26.0813
-26.2026
-26.3212
-26.437
-26.5499
-26.6599
-26.7669
-26.871
-26.9721
-27.0704
-27.1661
-27.2593
-27.3505
-27.44
-27.5283
-27.616
-27.7045
-27.7985
-27.9017
-27.9918
-28.0082
-24.3574
-21.6698
-19.4723
-17.4929
-15.7299
-14.1659
-12.7734
-11.5305
-10.4195
-9.42535
-8.53471
-7.73613
-7.01957
-6.37618
-5.79814
-5.27851
-4.81111
-4.39042
-4.01151
-3.66993
-3.3617
-3.08318
-2.83107
-2.60238
-2.3943
-2.2035
-2.02613
-1.86367
-1.72639
-28.041
-24.406
-21.7241
-19.5268
-17.5463
-15.7816
-14.2154
-12.8205
-11.5751
-10.4617
-9.46505
-8.57204
-7.7712
-7.0525
-6.4071
-5.82719
-5.30583
-4.83684
-4.41472
-4.03454
-3.6919
-3.38284
-3.10381
-2.85165
-2.62357
-2.41695
-2.22904
-2.05897
-1.91281
-1.78665
-28.0826
-24.4537
-21.7755
-19.5788
-17.5975
-15.8312
-14.263
-12.8658
-11.618
-10.5022
-9.50314
-8.60783
-7.80479
-7.08402
-6.43668
-5.85496
-5.33195
-4.86146
-4.438
-4.05667
-3.71307
-3.40329
-3.12384
-2.87162
-2.64392
-2.43817
-2.25183
-2.08465
-1.94234
-1.81551
-28.1285
-24.5018
-21.8255
-19.629
-17.6467
-15.8788
-14.3087
-12.9093
-11.6592
-10.541
-9.53965
-8.64209
-7.83691
-7.11412
-6.46489
-5.88142
-5.3568
-4.88486
-4.4601
-4.07764
-3.73308
-3.42254
-3.14254
-2.89
-2.66222
-2.45661
-2.27066
-2.1041
-1.96168
-1.83127
-28.176
-24.55
-21.8744
-19.6776
-17.6943
-15.9249
-14.3528
-12.9512
-11.6988
-10.5783
-9.57473
-8.67497
-7.86769
-7.14291
-6.49182
-5.90664
-5.38044
-4.90705
-4.48099
-4.09736
-3.75179
-3.44036
-3.1596
-2.90643
-2.67809
-2.47197
-2.2855
-2.1183
-1.97438
-1.84049
-28.2239
-24.5981
-21.9224
-19.7251
-17.7406
-15.9695
-14.3955
-12.9918
-11.7371
-10.6144
-9.6085
-8.70657
-7.89722
-7.17049
-6.51757
-5.93068
-5.4029
-4.92807
-4.50068
-4.11583
-3.76914
-3.4567
-3.175
-2.92094
-2.69172
-2.48468
-2.29722
-2.12883
-1.98301
-1.84612
-28.2717
-24.6459
-21.9698
-19.7716
-17.7858
-16.013
-14.437
-13.0311
-11.7742
-10.6492
-9.6411
-8.73702
-7.92562
-7.19695
-6.54222
-5.95364
-5.42428
-4.94797
-4.51922
-4.1331
-3.78523
-3.47166
-3.18889
-2.93377
-2.70348
-2.49532
-2.30669
-2.13698
-1.98923
-1.84982
-28.3192
-24.6932
-22.0165
-19.8173
-17.8301
-16.0555
-14.4774
-13.0693
-11.8102
-10.6829
-9.67265
-8.76644
-7.95301
-7.22241
-6.56587
-5.97559
-5.44465
-4.96687
-4.53673
-4.1493
-3.80019
-3.48543
-3.20151
-2.94524
-2.7138
-2.50446
-2.31463
-2.14363
-1.9941
-1.85262
-28.3662
-24.74
-22.0626
-19.8622
-17.8735
-16.097
-14.5169
-13.1067
-11.8453
-10.7158
-9.7033
-8.79497
-7.9795
-7.24699
-6.58865
-5.99668
-5.46415
-4.98488
-4.55334
-4.16459
-3.81421
-3.49824
-3.21313
-2.9557
-2.7231
-2.5126
-2.32163
-2.14944
-1.9983
-1.85511
-28.4128
-24.7863
-22.1081
-19.9066
-17.9163
-16.1379
-14.5557
-13.1433
-11.8796
-10.7479
-9.73317
-8.82272
-8.00524
-7.27082
-6.61068
-6.01703
-5.48292
-5.00216
-4.56922
-4.17914
-3.82749
-3.51031
-3.22402
-2.96544
-2.73171
-2.52011
-2.32808
-2.15483
-2.00226
-1.85765
-28.4591
-24.8323
-22.1533
-19.9505
-17.9585
-16.1782
-14.5939
-13.1792
-11.9133
-10.7793
-9.76239
-8.84982
-8.03034
-7.29402
-6.6321
-6.03677
-5.50109
-5.01886
-4.58452
-4.19313
-3.84023
-3.52185
-3.23441
-2.97473
-2.73993
-2.52729
-2.3343
-2.1601
-2.00623
-1.86045
-28.505
-24.878
-22.1981
-19.994
-18.0003
-16.2181
-14.6316
-13.2147
-11.9465
-10.8102
-9.79108
-8.87641
-8.05493
-7.31672
-6.65303
-6.05605
-5.51882
-5.03513
-4.59942
-4.20674
-3.85261
-3.53306
-3.24452
-2.98377
-2.74796
-2.53437
-2.34051
-2.16544
-2.01041
-1.86364
-28.5508
-24.9234
-22.2428
-20.0373
-18.0419
-16.2576
-14.669
-13.2497
-11.9792
-10.8407
-9.81938
-8.90261
-8.07913
-7.33906
-6.67361
-6.07499
-5.53623
-5.05111
-4.61406
-4.22011
-3.8648
-3.54412
-3.25451
-2.99276
-2.75599
-2.54151
-2.34684
-2.171
-2.0149
-1.86729
-28.5966
-24.9689
-22.2873
-20.0804
-18.0832
-16.297
-14.7061
-13.2846
-12.0117
-10.8709
-9.8474
-8.92853
-8.10307
-7.36114
-6.69397
-6.09373
-5.55346
-5.06694
-4.62858
-4.2334
-3.87693
-3.55517
-3.26454
-3.00183
-2.76416
-2.54884
-2.35344
-2.17687
-2.01978
-1.87144
-28.6424
-25.0144
-22.3319
-20.1236
-18.1246
-16.3362
-14.7431
-13.3192
-12.0441
-10.9009
-9.87526
-8.9543
-8.12687
-7.3831
-6.71421
-6.11238
-5.57064
-5.08274
-4.6431
-4.24673
-3.88914
-3.56634
-3.27473
-3.01111
-2.77258
-2.55648
-2.36038
-2.18314
-2.02511
-1.87614
-28.6884
-25.06
-22.3766
-20.1669
-18.166
-16.3755
-14.7801
-13.3539
-12.0764
-10.931
-9.90307
-8.98002
-8.15064
-7.40504
-6.73446
-6.13107
-5.58787
-5.09863
-4.65774
-4.26021
-3.90154
-3.57774
-3.28519
-3.02069
-2.78136
-2.56451
-2.36775
-2.18986
-2.03094
-1.88141
-28.7348
-25.1061
-22.4217
-20.2104
-18.2076
-16.415
-14.8173
-13.3887
-12.1088
-10.961
-9.93092
-9.0058
-8.17447
-7.42707
-6.75482
-6.14988
-5.60526
-5.11471
-4.67261
-4.27395
-3.91424
-3.58946
-3.29601
-3.03067
-2.79055
-2.573
-2.3756
-2.19708
-2.0373
-1.88728
-28.7817
-25.1525
-22.4671
-20.2543
-18.2496
-16.4547
-14.8546
-13.4236
-12.1413
-10.9912
-9.95893
-9.03173
-8.19847
-7.44928
-6.77538
-6.16893
-5.62292
-5.13108
-4.68779
-4.28804
-3.92732
-3.6016
-3.30728
-3.04112
-2.80025
-2.582
-2.38399
-2.20486
-2.04425
-1.89379
-28.8293
-25.1996
-22.5131
-20.2986
-18.2919
-16.4948
-14.8922
-13.4588
-12.1741
-11.0217
-9.98718
-9.0579
-8.22273
-7.47177
-6.79624
-6.1883
-5.64092
-5.14782
-4.70338
-4.30257
-3.94086
-3.61423
-3.31906
-3.05212
-2.81051
-2.59159
-2.39298
-2.21324
-2.05182
-1.90096
-28.8777
-25.2475
-22.5598
-20.3436
-18.3347
-16.5353
-14.9303
-13.4943
-12.2072
-11.0525
-10.0157
-9.08441
-8.24732
-7.49461
-6.81748
-6.20807
-5.65934
-5.16502
-4.71946
-4.3176
-3.95494
-3.62742
-3.33143
-3.06372
-2.8214
-2.60182
-2.40262
-2.22228
-2.06006
-1.90884
-28.9271
-25.2962
-22.6072
-20.3892
-18.3782
-16.5763
-14.9688
-13.5303
-12.2407
-11.0836
-10.0447
-9.11131
-8.27233
-7.51788
-6.83916
-6.22831
-5.67827
-5.18275
-4.73608
-4.33322
-3.96962
-3.64124
-3.34444
-3.07598
-2.83297
-2.61274
-2.41295
-2.23202
-2.06901
-1.91746
-28.9777
-25.346
-22.6556
-20.4357
-18.4223
-16.6179
-15.0079
-13.5668
-12.2747
-11.1153
-10.0741
-9.13867
-8.29781
-7.54164
-6.86136
-6.24909
-5.69776
-5.20106
-4.75333
-4.34948
-3.98497
-3.65575
-3.35816
-3.08897
-2.84527
-2.62441
-2.42404
-2.2425
-2.07872
-1.92688
-29.0298
-25.397
-22.7051
-20.483
-18.4672
-16.6602
-15.0475
-13.6039
-12.3093
-11.1474
-10.1041
-9.16656
-8.32383
-7.56596
-6.88414
-6.27047
-5.71788
-5.22003
-4.77124
-4.36643
-4.00104
-3.67099
-3.37264
-3.10273
-2.85835
-2.63687
-2.43592
-2.25379
-2.08924
-1.93713
-29.0837
-25.4495
-22.7556
-20.5312
-18.5128
-16.7032
-15.0878
-13.6415
-12.3444
-11.1801
-10.1346
-9.19503
-8.35044
-7.59089
-6.90755
-6.29251
-5.73868
-5.2397
-4.78989
-4.38414
-4.01788
-3.68703
-3.38793
-3.11732
-2.87227
-2.65017
-2.44865
-2.26592
-2.10062
-1.94826
-29.1397
-25.5034
-22.8073
-20.5804
-18.5593
-16.7469
-15.1287
-13.6798
-12.3801
-11.2135
-10.1657
-9.22411
-8.37768
-7.61647
-6.93163
-6.31525
-5.7602
-5.26012
-4.80931
-4.40264
-4.03554
-3.7039
-3.40407
-3.13277
-2.88707
-2.66436
-2.46227
-2.27894
-2.11289
-1.96032
-29.1981
-25.5587
-22.8602
-20.6306
-18.6066
-16.7913
-15.1704
-13.7187
-12.4164
-11.2474
-10.1974
-9.25385
-8.4056
-7.64275
-6.95644
-6.33873
-5.78249
-5.28134
-4.82955
-4.42199
-4.05406
-3.72166
-3.42111
-3.14913
-2.9028
-2.67947
-2.47682
-2.2929
-2.1261
-1.97335
-29.2598
-25.6159
-22.9142
-20.6817
-18.6547
-16.8364
-15.2126
-13.7582
-12.4534
-11.282
-10.2298
-9.28427
-8.43422
-7.66975
-6.982
-6.36299
-5.80559
-5.30339
-4.85065
-4.44221
-4.07348
-3.74034
-3.43909
-3.16645
-2.91948
-2.69556
-2.49235
-2.30783
-2.14031
-1.98739
-29.3276
-25.6756
-22.9692
-20.7334
-18.7033
-16.882
-15.2554
-13.7983
-12.491
-11.3172
-10.2629
-9.31534
-8.46352
-7.69748
-7.0083
-6.38803
-5.8295
-5.32628
-4.87261
-4.46334
-4.09383
-3.75996
-3.45802
-3.18474
-2.93716
-2.71266
-2.50889
-2.32378
-2.15553
-2.00247
-29.4036
-25.7378
-23.0246
-20.7852
-18.7521
-16.9281
-15.2987
-13.8389
-12.5291
-11.353
-10.2965
-9.34707
-8.49352
-7.72592
-7.03537
-6.41386
-5.85422
-5.35002
-4.89546
-4.48536
-4.1151
-3.78053
-3.47793
-3.20402
-2.95584
-2.73076
-2.52645
-2.34075
-2.17179
-2.01862
-29.4744
-25.7976
-23.0792
-20.8372
-18.8018
-16.9751
-15.343
-13.8807
-12.5683
-11.3899
-10.3312
-9.37984
-8.52454
-7.75538
-7.06344
-6.4407
-5.87997
-5.37478
-4.91933
-4.50843
-4.13743
-3.80216
-3.49892
-3.22438
-2.9756
-2.74996
-2.54511
-2.35882
-2.18916
-2.0359
-1.51809
-1.00052
-0.70278
-0.495828
-0.368622
-0.271089
-0.204605
-0.152783
-0.113913
-0.0827761
-0.0576508
-0.037331
-0.0213499
-0.00959317
-0.0016162
0.00315906
0.00556813
0.00636854
0.00622158
0.00558023
0.00474745
0.0038908
0.00309982
0.00241126
0.00183625
0.00136922
0.000998911
0.000711807
0.000494006
0.000332702
0.00021483
0.000130246
7.04715e-05
3.14492e-05
4.49975e-06
-7.73362e-06
-1.4437e-05
-5.70836e-06
-8.38866e-06
1.06508e-05
-1.54471
-1.01003
-0.715063
-0.500598
-0.372961
-0.272256
-0.205041
-0.15202
-0.11286
-0.0815416
-0.0566205
-0.0365974
-0.0209843
-0.00954545
-0.00182
0.00278455
0.00508803
0.00583441
0.00566947
0.005036
0.00422762
0.00340595
0.00265587
0.00201087
0.00147957
0.00105524
0.00072527
0.000475655
0.000292283
0.000161817
7.17609e-05
1.15575e-05
-2.68674e-05
-4.69807e-05
-5.76741e-05
-5.53951e-05
-4.9818e-05
-2.94314e-05
-2.29291e-05
8.04831e-06
-1.57263
-1.02083
-0.728358
-0.506291
-0.378014
-0.274081
-0.20601
-0.151733
-0.112197
-0.0806312
-0.0558444
-0.0360596
-0.0207654
-0.00960642
-0.00210322
0.00235283
0.00456724
0.00527163
0.00509766
0.00447808
0.00369842
0.00291453
0.00220728
0.00160715
0.00112064
0.000739577
0.000450502
0.00023881
9.00079e-05
-9.37934e-06
-7.17399e-05
-0.000107395
-0.000124244
-0.000125465
-0.000119783
-0.000103019
-8.52039e-05
-5.31633e-05
-3.7505e-05
5.39143e-06
-1.60185
-1.03292
-0.742681
-0.512934
-0.383791
-0.276582
-0.207521
-0.15193
-0.111931
-0.0800499
-0.0553258
-0.03572
-0.0206942
-0.00977634
-0.00246561
0.00186428
0.00400621
0.00468073
0.00450638
0.00390677
0.00316
0.00241676
0.00175431
0.00120037
0.00075957
0.000422419
0.000174674
1.2246e-06
-0.000112793
-0.000180932
-0.000215486
-0.000226512
-0.000221742
-0.000204027
-0.000181947
-0.000150693
-0.000120615
-7.6912e-05
-5.20863e-05
2.72639e-06
-1.63238
-1.04633
-0.758037
-0.520545
-0.390296
-0.279771
-0.209578
-0.152619
-0.112063
-0.0798006
-0.0550663
-0.0355799
-0.0207712
-0.0100552
-0.00290688
0.00131924
0.00340528
0.004062
0.00389584
0.00332222
0.00261249
0.00191273
0.00129701
0.000790594
0.000396404
0.00010379
-0.000102192
-0.000237089
-0.000316106
-0.000352834
-0.00035947
-0.000345793
-0.000319355
-0.000282665
-0.000244166
-0.000198414
-0.000156053
-0.000100678
-6.66713e-05
4.78689e-08
-1.66422
-1.06106
-0.774431
-0.529143
-0.397533
-0.283659
-0.212186
-0.153803
-0.112597
-0.0798858
-0.0550675
-0.0356403
-0.0209969
-0.0104431
-0.00342679
0.000718026
0.00276476
0.00341569
0.00326627
0.0027246
0.00205601
0.00140254
0.000835454
0.000377858
3.11751e-05
-0.000216284
-0.000380075
-0.000476115
-0.000519915
-0.000525077
-0.000503685
-0.000465232
-0.000417076
-0.000361374
-0.000306437
-0.000246175
-0.000191517
-0.00012446
-8.12579e-05
-2.64937e-06
-1.69736
-1.07712
-0.791865
-0.538748
-0.405505
-0.288257
-0.215347
-0.155486
-0.113534
-0.0803074
-0.0553309
-0.0359022
-0.0213716
-0.01094
-0.00402512
6.09409e-05
0.00208495
0.00274208
0.00261786
0.00211408
0.00149069
0.000886289
0.000369715
-3.7781e-05
-0.000336077
-0.000537774
-0.000658951
-0.000715836
-0.000724206
-0.00069765
-0.000648121
-0.000584824
-0.0005149
-0.000440153
-0.000368757
-0.000293976
-0.000227008
-0.00014826
-9.58464e-05
-5.36836e-06
-1.7318
-1.09452
-0.810335
-0.549375
-0.414215
-0.293575
-0.219064
-0.157673
-0.114876
-0.0810669
-0.0558576
-0.0363667
-0.021896
-0.011546
-0.0047017
-0.000651746
0.00136613
0.0020414
0.00195082
0.0014908
0.000916651
0.00036406
-0.000100135
-0.000456267
-0.00070531
-0.000860647
-0.000938794
-0.000956232
-0.000928963
-0.000870541
-0.000792769
-0.000704561
-0.000612822
-0.000518997
-0.000431125
-0.000341816
-0.000262525
-0.000172077
-0.000110437
-8.11199e-06
-1.76752
-1.11325
-0.829833
-0.561043
-0.423662
-0.299619
-0.22334
-0.160365
-0.116625
-0.0821656
-0.0566484
-0.0370343
-0.0225702
-0.0122612
-0.0054564
-0.00141981
0.000608551
0.00131387
0.00126534
0.000854933
0.000334012
-0.000164048
-0.000574023
-0.000877545
-0.00107648
-0.00118487
-0.00121958
-0.00119728
-0.00113417
-0.00104374
-0.000937621
-0.000824437
-0.000710837
-0.000597903
-0.000493538
-0.000389693
-0.000298068
-0.000195914
-0.00012503
-1.08832e-05
-1.8045
-1.13333
-0.850349
-0.573768
-0.433846
-0.306397
-0.228177
-0.163564
-0.118781
-0.083604
-0.0577042
-0.0379058
-0.0233949
-0.0130859
-0.00628915
-0.00224306
-0.000187577
0.000559695
0.00056159
0.000206615
-0.000257104
-0.000697943
-0.00105188
-0.00130156
-0.00144954
-0.00151041
-0.00150128
-0.00143896
-0.00133981
-0.00121723
-0.00108267
-0.000944444
-0.00080894
-0.000676867
-0.000555993
-0.000437606
-0.000333635
-0.000219769
-0.000139625
-1.36849e-05
-1.84271
-1.15475
-0.871866
-0.587565
-0.444766
-0.313913
-0.233577
-0.167271
-0.121345
-0.0853823
-0.0590253
-0.0389817
-0.0243704
-0.0140201
-0.00719994
-0.00312137
-0.00102207
-0.000220942
-0.000160269
-0.000454011
-0.000856582
-0.00123753
-0.00153362
-0.00172825
-0.00182445
-0.00183723
-0.00178387
-0.00168126
-0.00154587
-0.001391
-0.0012279
-0.00106458
-0.000907126
-0.000755886
-0.00061849
-0.000485555
-0.000369228
-0.000243644
-0.000154223
-1.65201e-05
-1.88214
-1.1775
-0.89436
-0.602449
-0.45642
-0.322171
-0.239541
-0.171485
-0.124317
-0.0875004
-0.0606122
-0.0402625
-0.0254971
-0.0150642
-0.00818882
-0.00405465
-0.00189478
-0.00102788
-0.000900082
-0.00112681
-0.00146431
-0.00178273
-0.00201918
-0.00215756
-0.00220116
-0.0021653
-0.00206732
-0.00192414
-0.00175233
-0.00156503
-0.0013733
-0.00118483
-0.00100539
-0.000834955
-0.000681024
-0.000533537
-0.000404845
-0.00026754
-0.000168824
-1.93912e-05
-1.92273
-1.20159
-0.917804
-0.618436
-0.468806
-0.331173
-0.24607
-0.176206
-0.127696
-0.0899577
-0.0624649
-0.0417483
-0.0267755
-0.0162184
-0.0092559
-0.00504285
-0.00280559
-0.00186096
-0.00165771
-0.00181164
-0.00208016
-0.00233343
-0.00250848
-0.00258942
-0.00257963
-0.00249458
-0.0023516
-0.00216759
-0.00195918
-0.00173932
-0.00151887
-0.00130518
-0.00110372
-0.00091407
-0.000743592
-0.00058155
-0.000440485
-0.000291455
-0.000183427
-2.2301e-05
-1.96446
-1.22701
-0.942165
-0.635538
-0.481921
-0.34092
-0.253167
-0.181432
-0.131483
-0.0927535
-0.0645835
-0.0434396
-0.028206
-0.0174829
-0.0104013
-0.00608599
-0.00375442
-0.00272009
-0.00243304
-0.00250841
-0.00270405
-0.00288956
-0.00300146
-0.0030238
-0.00295981
-0.00282504
-0.0026367
-0.00241159
-0.0021664
-0.00191386
-0.00166459
-0.00142565
-0.00120212
-0.000993229
-0.000806194
-0.000629594
-0.000476148
-0.000315391
-0.000198033
-2.52523e-05
-2.00729
-1.25378
-0.967403
-0.653767
-0.495765
-0.351412
-0.260832
-0.18716
-0.135676
-0.0958865
-0.0669677
-0.0453363
-0.029789
-0.0188584
-0.0116254
-0.00718416
-0.00474126
-0.00360517
-0.00322595
-0.00321698
-0.00333586
-0.00345101
-0.00349802
-0.00346061
-0.00334164
-0.00315663
-0.00292257
-0.00265611
-0.00237396
-0.00208862
-0.00181045
-0.0015462
-0.00130059
-0.00107243
-0.000868822
-0.000677678
-0.000511835
-0.000339345
-0.000212648
-2.82421e-05
-2.05115
-1.2819
-0.993472
-0.673134
-0.510337
-0.362644
-0.269068
-0.19339
-0.140275
-0.0993557
-0.0696174
-0.0474389
-0.0315252
-0.0203451
-0.0129284
-0.0083375
-0.00576612
-0.00451613
-0.00403635
-0.00393724
-0.00397548
-0.00401769
-0.00399807
-0.00389977
-0.00372506
-0.00348929
-0.00320918
-0.00290112
-0.00258186
-0.00226358
-0.00195644
-0.00166683
-0.00139911
-0.00115166
-0.000931477
-0.000725801
-0.000547545
-0.000363317
-0.000227272
-3.12733e-05
-2.096
-1.31138
-1.02032
-0.693646
-0.525638
-0.374615
-0.277875
-0.200117
-0.145279
-0.103159
-0.0725323
-0.0497472
-0.0334147
-0.0219435
-0.0143109
-0.00954613
-0.00682914
-0.00545357
-0.00486365
-0.00466906
-0.00462271
-0.00458933
-0.0045018
-0.0043417
-0.00411005
-0.003823
-0.0034964
-0.00314641
-0.00279005
-0.00243868
-0.00210293
-0.00178775
-0.00149762
-0.00123061
-0.000993909
-0.000773993
-0.000583155
-0.000387244
-0.000241846
-3.46302e-05
-2.14176
-1.34226
-1.0479
-0.715307
-0.541672
-0.387319
-0.287257
-0.207341
-0.150687
-0.107296
-0.0757116
-0.0522612
-0.0354585
-0.0236542
-0.0157729
-0.0108111
-0.00793066
-0.00641671
-0.0057086
-0.00541257
-0.0052778
-0.00516617
-0.00500872
-0.0047854
-0.00449661
-0.00415768
-0.0037843
-0.00339242
-0.00299866
-0.00261414
-0.00224922
-0.00190843
-0.00159613
-0.00130986
-0.0010565
-0.000821949
-0.000618777
-0.000411336
-0.000256634
-3.78427e-05
-2.18836
-1.37457
-1.07614
-0.738118
-0.558445
-0.40075
-0.297215
-0.215056
-0.156498
-0.111763
-0.079155
-0.0549812
-0.0376571
-0.0254782
-0.0173155
-0.0121322
-0.00907062
-0.00740577
-0.00657084
-0.0061675
-0.0059404
-0.00574796
-0.00551891
-0.00523129
-0.00488462
-0.00449333
-0.00407283
-0.00363883
-0.00320752
-0.00278977
-0.00239561
-0.00202918
-0.00169467
-0.00138913
-0.0011191
-0.000869922
-0.000654419
-0.000435453
-0.000271419
-4.11153e-05
-2.23567
-1.40836
-1.10499
-0.762066
-0.575962
-0.4149
-0.307752
-0.223261
-0.162711
-0.11656
-0.0828618
-0.0579071
-0.0400112
-0.0274163
-0.0189393
-0.0135099
-0.0102493
-0.00842086
-0.00745037
-0.00693376
-0.00661041
-0.00633461
-0.00603229
-0.0056793
-0.00527401
-0.00482989
-0.00436196
-0.00388564
-0.00341662
-0.00296555
-0.00254209
-0.00214999
-0.00179324
-0.00146841
-0.00118173
-0.000917905
-0.000690079
-0.000459594
-0.000286201
-4.44499e-05
-2.28355
-1.44365
-1.13436
-0.787127
-0.594226
-0.429757
-0.318866
-0.23195
-0.169322
-0.121684
-0.0868308
-0.0610385
-0.0425211
-0.0294691
-0.0206451
-0.0149448
-0.011467
-0.00946209
-0.00834717
-0.00771128
-0.00728773
-0.00692601
-0.00654876
-0.00612933
-0.00566473
-0.00516732
-0.00465165
-0.00413279
-0.00362595
-0.00314146
-0.00268864
-0.00227084
-0.00189183
-0.0015477
-0.00124436
-0.000965904
-0.000725753
-0.000483754
-0.000300984
-4.7843e-05
-2.33178
-1.48053
-1.16422
-0.81329
-0.613257
-0.445315
-0.330563
-0.241121
-0.176331
-0.127133
-0.0910606
-0.064375
-0.0451873
-0.0316374
-0.0224335
-0.0164373
-0.012724
-0.0105296
-0.00926122
-0.00849997
-0.00797225
-0.00752205
-0.00706823
-0.0065813
-0.0060567
-0.00550557
-0.00494186
-0.00438027
-0.00383547
-0.00331747
-0.00283524
-0.00239171
-0.00199042
-0.00162699
-0.001307
-0.00101392
-0.00076144
-0.000507934
-0.00031577
-5.12972e-05
-2.38023
-1.5193
-1.19467
-0.840612
-0.633125
-0.461601
-0.342866
-0.250787
-0.183747
-0.132912
-0.0955554
-0.0679198
-0.0480127
-0.0339237
-0.0243066
-0.0179889
-0.0140211
-0.0116236
-0.0101926
-0.00929975
-0.00866381
-0.00812257
-0.00759053
-0.00703507
-0.00644981
-0.00584453
-0.00523252
-0.004628
-0.00404513
-0.00349356
-0.00298186
-0.00251259
-0.00208901
-0.00170627
-0.00136963
-0.00106194
-0.000797137
-0.000532131
-0.000330558
-5.48142e-05
-2.42891
-1.5602
-1.22572
-0.869089
-0.653879
-0.478637
-0.355802
-0.260965
-0.191582
-0.13903
-0.100323
-0.0716797
-0.0510033
-0.0363329
-0.0262683
-0.0196023
-0.0153601
-0.0127454
-0.0111419
-0.0101109
-0.00936257
-0.0087276
-0.00811565
-0.00749061
-0.00684401
-0.00618417
-0.0055236
-0.00487598
-0.00425492
-0.00366971
-0.00312851
-0.00263347
-0.00218759
-0.00178554
-0.00143226
-0.00110996
-0.000832843
-0.000556346
-0.000345346
-5.8396e-05
-2.47691
-1.60233
-1.25659
-0.898179
-0.67523
-0.496219
-0.369246
-0.271569
-0.199779
-0.145448
-0.105336
-0.0756369
-0.0541485
-0.0388596
-0.0283163
-0.0212771
-0.0167415
-0.0138959
-0.0121101
-0.0109345
-0.0100694
-0.00933794
-0.00864427
-0.00794848
-0.00723978
-0.00652488
-0.0058154
-0.00512444
-0.00446504
-0.00384606
-0.00327528
-0.00275442
-0.00228621
-0.00186484
-0.0014949
-0.00115801
-0.00086857
-0.000580586
-0.00036014
-6.20464e-05
-2.52141
-1.64377
-1.28608
-0.927009
-0.696609
-0.513915
-0.382883
-0.282364
-0.20816
-0.152028
-0.110491
-0.0797135
-0.0573914
-0.0414633
-0.030423
-0.0229953
-0.0181543
-0.0150684
-0.0130938
-0.0117688
-0.0107837
-0.0099535
-0.00917661
-0.00840904
-0.00763752
-0.00686705
-0.00610829
-0.0053737
-0.00467573
-0.00402283
-0.00342235
-0.00287559
-0.00238499
-0.00194424
-0.00155763
-0.00120612
-0.000904341
-0.000604864
-0.000374947
-6.57703e-05
-2.56344
-1.68843
-1.3173
-0.957429
-0.719242
-0.532486
-0.397208
-0.293667
-0.21693
-0.1589
-0.115867
-0.0839531
-0.0607518
-0.0441483
-0.0325827
-0.0247456
-0.0195846
-0.0162489
-0.0140798
-0.0126022
-0.0114957
-0.0105662
-0.00970616
-0.00886707
-0.00803307
-0.00720738
-0.00639966
-0.00562171
-0.00488541
-0.00419879
-0.00356878
-0.00299627
-0.0024834
-0.00202337
-0.00162017
-0.00125413
-0.000940049
-0.000629121
-0.000389736
-6.95564e-05
-2.61799
-1.75094
-1.36014
-0.996264
-0.748099
-0.555537
-0.414878
-0.307462
-0.227585
-0.167204
-0.12233
-0.0890097
-0.0647115
-0.0472564
-0.0350258
-0.0266728
-0.0211153
-0.0174786
-0.015083
-0.0134348
-0.0121975
-0.011165
-0.0102209
-0.00931103
-0.00841599
-0.00753677
-0.00668179
-0.00586208
-0.00508889
-0.0043698
-0.00371135
-0.00311401
-0.00257961
-0.00210092
-0.00168159
-0.00130139
-0.000975287
-0.000653126
-0.000404393
-7.33556e-05
-2.68189
-1.82247
-1.40761
-1.03964
-0.781125
-0.582073
-0.435502
-0.323718
-0.240302
-0.177239
-0.130249
-0.0952843
-0.069673
-0.0511658
-0.0380875
-0.0290596
-0.0229746
-0.0189353
-0.0162386
-0.0143672
-0.0129637
-0.0118046
-0.010761
-0.00977034
-0.00880784
-0.00787103
-0.00696627
-0.00610328
-0.00529234
-0.00454036
-0.00385328
-0.00323107
-0.00267521
-0.00217795
-0.00174262
-0.00134837
-0.00101032
-0.000677021
-0.000418981
-7.72009e-05
-2.65185
-1.81711
-1.39988
-1.04419
-0.786622
-0.588666
-0.44154
-0.32913
-0.24489
-0.18116
-0.133619
-0.0982568
-0.0723478
-0.0536052
-0.0403114
-0.0310672
-0.0247603
-0.0205002
-0.0175939
-0.0155319
-0.0139601
-0.0126552
-0.0114861
-0.0103873
-0.00933158
-0.00831404
-0.0073393
-0.00641571
-0.00555236
-0.00475519
-0.0040293
-0.0033739
-0.00278986
-0.00226868
-0.00181321
-0.00140172
-0.00104946
-0.000703248
-0.000434704
-8.16364e-05
-2.45621
-1.69649
-1.30402
-0.979989
-0.738252
-0.552325
-0.412935
-0.306122
-0.225869
-0.1653
-0.12044
-0.0875807
-0.0640918
-0.0476638
-0.0364632
-0.028969
-0.0239967
-0.0206574
-0.0183179
-0.0165555
-0.0151016
-0.0138015
-0.0125727
-0.0113809
-0.0102178
-0.00908964
-0.00800743
-0.00698318
-0.00602786
-0.00514835
-0.00434997
-0.00363168
-0.00299392
-0.00242731
-0.00193405
-0.00149082
-0.00111319
-0.000744666
-0.000458743
-8.90229e-05
-2.33686
-1.63984
-1.26422
-0.96422
-0.731511
-0.551652
-0.415014
-0.309643
-0.229834
-0.169318
-0.124253
-0.0911054
-0.0672939
-0.0505539
-0.0390639
-0.0313064
-0.0260928
-0.02253
-0.0199822
-0.0180263
-0.016394
-0.0149309
-0.0135546
-0.0122301
-0.0109484
-0.00971452
-0.00853865
-0.00743186
-0.00640415
-0.00546149
-0.00460832
-0.00384275
-0.00316443
-0.00256313
-0.0020403
-0.00157159
-0.00117259
-0.000784602
-0.000482661
-9.54224e-05
-2.20865
-1.5818
-1.22601
-0.948638
-0.726077
-0.552607
-0.419138
-0.315433
-0.236195
-0.175742
-0.130385
-0.09676
-0.0723515
-0.0549656
-0.0428326
-0.03448
-0.0287459
-0.0247455
-0.0218387
-0.0195901
-0.017718
-0.0160561
-0.0145128
-0.0130465
-0.0116431
-0.0103043
-0.0090377
-0.00785235
-0.00675667
-0.00575528
-0.00485147
-0.0040423
-0.00332657
-0.00269317
-0.00214281
-0.00165018
-0.00123081
-0.000824107
-0.000506488
-0.000101601
-2.07448
-1.51952
-1.18473
-0.928518
-0.717059
-0.550403
-0.420659
-0.319054
-0.240754
-0.180659
-0.135269
-0.101407
-0.0766351
-0.0588255
-0.0462492
-0.0374662
-0.0313345
-0.0269795
-0.0237627
-0.0212456
-0.0191417
-0.0172794
-0.0155623
-0.0139448
-0.0124097
-0.010956
-0.00958917
-0.00831672
-0.00714544
-0.00607865
-0.00511842
-0.00426076
-0.0035035
-0.00283456
-0.00225386
-0.00173503
-0.00129344
-0.000866473
-0.000531899
-0.00010833
-1.9426
-1.45644
-1.14358
-0.906903
-0.707029
-0.547323
-0.421555
-0.322231
-0.245005
-0.185353
-0.139988
-0.105937
-0.0808459
-0.0626596
-0.0496858
-0.0405115
-0.0340106
-0.0293168
-0.0257954
-0.0230074
-0.0206646
-0.0185922
-0.0166908
-0.0149118
-0.0132352
-0.0116576
-0.0101827
-0.00881619
-0.00756321
-0.00642574
-0.0054046
-0.00449461
-0.00369261
-0.00298544
-0.00237216
-0.00182527
-0.00135993
-0.000911409
-0.000558738
-0.000115543
-1.81547
-1.39293
-1.10283
-0.884283
-0.696357
-0.543806
-0.422282
-0.325445
-0.249445
-0.190321
-0.145024
-0.110787
-0.0853636
-0.0667748
-0.0533729
-0.0437756
-0.0368748
-0.0318143
-0.0279634
-0.0248831
-0.022283
-0.0199849
-0.0178862
-0.0159345
-0.0141071
-0.0123979
-0.0108083
-0.00934211
-0.00800275
-0.00679067
-0.00570529
-0.00474021
-0.00389112
-0.00314378
-0.00249627
-0.00191995
-0.00142965
-0.000958563
-0.000586822
-0.000123164
-1.69432
-1.32914
-1.06227
-0.860637
-0.684843
-0.539685
-0.422681
-0.328563
-0.253976
-0.195496
-0.150334
-0.11594
-0.0901828
-0.071174
-0.0573171
-0.0472661
-0.0399346
-0.0344784
-0.0302719
-0.0268766
-0.0239999
-0.0214599
-0.0191501
-0.0170143
-0.0150263
-0.0131774
-0.0114663
-0.0098947
-0.00846418
-0.00717351
-0.00602056
-0.0049976
-0.00409909
-0.00330961
-0.00262623
-0.0020191
-0.00150262
-0.00100796
-0.000616156
-0.000131203
-1.57977
-1.26538
-1.02179
-0.836058
-0.672405
-0.53487
-0.422641
-0.331478
-0.2585
-0.200796
-0.155851
-0.121341
-0.0952638
-0.0758289
-0.0615
-0.0509726
-0.0431855
-0.0373087
-0.0327234
-0.0289921
-0.02582
-0.0230217
-0.0204867
-0.0181547
-0.0159961
-0.0139987
-0.0121589
-0.0104758
-0.00894899
-0.00757541
-0.0063513
-0.00526747
-0.00431702
-0.00348333
-0.00276231
-0.00212292
-0.00157899
-0.00105968
-0.000646778
-0.000139689
-1.47197
-1.20202
-0.981333
-0.81068
-0.659029
-0.529321
-0.422104
-0.334126
-0.262959
-0.206173
-0.161542
-0.126968
-0.100593
-0.0807321
-0.0659187
-0.0548951
-0.0466294
-0.0403087
-0.0353217
-0.0312332
-0.0277468
-0.0246735
-0.0218988
-0.0193582
-0.0170183
-0.0148636
-0.0128874
-0.0110864
-0.00945797
-0.00799702
-0.00669801
-0.00555019
-0.00454521
-0.00366514
-0.00290468
-0.00223152
-0.00165882
-0.00111379
-0.000678707
-0.000148643
-1.37081
-1.13943
-0.940893
-0.784626
-0.644725
-0.523006
-0.42102
-0.336448
-0.267297
-0.211582
-0.167372
-0.132798
-0.106156
-0.0858769
-0.0705711
-0.0590344
-0.0502687
-0.0434809
-0.0380698
-0.0336029
-0.0297829
-0.0264177
-0.0233884
-0.0206264
-0.0180943
-0.0157729
-0.0136525
-0.0117271
-0.00999155
-0.00843865
-0.00706092
-0.00584594
-0.00478378
-0.00385514
-0.00305338
-0.00234494
-0.00174213
-0.00117031
-0.000711944
-0.000158083
-1.27601
-1.07794
-0.900501
-0.758015
-0.629529
-0.515904
-0.41934
-0.338381
-0.271449
-0.216965
-0.173293
-0.138796
-0.11193
-0.0912488
-0.0754491
-0.0633866
-0.0541022
-0.046826
-0.040969
-0.0361028
-0.0319303
-0.0282559
-0.024957
-0.0219605
-0.0192249
-0.0167275
-0.0144549
-0.0123983
-0.01055
-0.00890049
-0.00744015
-0.00615479
-0.00503277
-0.00405335
-0.00320844
-0.00246321
-0.00182894
-0.00122924
-0.000746479
-0.000168022
-1.18723
-1.01786
-0.860245
-0.730966
-0.613502
-0.508003
-0.417022
-0.339864
-0.275348
-0.222259
-0.179252
-0.144918
-0.117881
-0.096825
-0.0805379
-0.0679429
-0.0581251
-0.0503418
-0.0440186
-0.0387334
-0.0341894
-0.0301889
-0.0266052
-0.0233611
-0.0204108
-0.0177276
-0.0152947
-0.0131002
-0.0111334
-0.00938256
-0.0078357
-0.00647671
-0.00529215
-0.00425974
-0.00336982
-0.00258628
-0.00191921
-0.00129058
-0.000782289
-0.000178473
-1.10411
-0.959484
-0.820265
-0.703607
-0.596728
-0.499312
-0.414034
-0.34084
-0.278923
-0.227394
-0.185186
-0.151113
-0.12397
-0.102575
-0.0858165
-0.0726893
-0.0623284
-0.0540227
-0.0472156
-0.0414927
-0.0365595
-0.0322163
-0.028333
-0.0248282
-0.0216519
-0.0187732
-0.0161719
-0.0138325
-0.0117416
-0.00988468
-0.00824737
-0.00681154
-0.00556175
-0.00447416
-0.00353741
-0.00271407
-0.00201286
-0.00135428
-0.000819336
-0.000189441
-1.02632
-0.903046
-0.780743
-0.67608
-0.579312
-0.489859
-0.410356
-0.341259
-0.28211
-0.232301
-0.191028
-0.157322
-0.130149
-0.108463
-0.0912573
-0.0776061
-0.0666987
-0.0578599
-0.050554
-0.0443771
-0.039038
-0.0343363
-0.0301391
-0.0263607
-0.0229472
-0.0198636
-0.0170857
-0.0145948
-0.0123741
-0.0104064
-0.00867475
-0.00715889
-0.00584127
-0.00469636
-0.00371098
-0.00284641
-0.00210978
-0.00142025
-0.00085756
-0.000200926
-0.9536
-0.848772
-0.741894
-0.648544
-0.561377
-0.479692
-0.405982
-0.341083
-0.284844
-0.236908
-0.196708
-0.163481
-0.136362
-0.114443
-0.0968259
-0.0826676
-0.0712173
-0.0618399
-0.0540243
-0.0473796
-0.04162
-0.0365453
-0.0320205
-0.0279565
-0.024295
-0.0209972
-0.0180349
-0.0153858
-0.0130298
-0.0109468
-0.00911714
-0.00751819
-0.00613021
-0.00492594
-0.00389024
-0.00298306
-0.00220977
-0.00148839
-0.000896876
-0.000212922
-0.885731
-0.796858
-0.703945
-0.621174
-0.543061
-0.468882
-0.400925
-0.340283
-0.287072
-0.241147
-0.202153
-0.169521
-0.142549
-0.120465
-0.102481
-0.0878421
-0.0758602
-0.0659449
-0.0576133
-0.0504905
-0.044298
-0.0388376
-0.0339729
-0.0296119
-0.0256924
-0.0221716
-0.0190175
-0.0162039
-0.0137074
-0.0115047
-0.00957348
-0.00788857
-0.00642788
-0.00516233
-0.00407472
-0.00312369
-0.00231258
-0.00155851
-0.000937174
-0.000225411
-0.82256
-0.747479
-0.667128
-0.594157
-0.524519
-0.457521
-0.395216
-0.338847
-0.288749
-0.244956
-0.207295
-0.175373
-0.148645
-0.126472
-0.108176
-0.0930913
-0.0805974
-0.0701516
-0.0613032
-0.053696
-0.0470615
-0.0412049
-0.0359898
-0.0313216
-0.0271351
-0.0233833
-0.0200304
-0.0170465
-0.0144047
-0.0120784
-0.0100423
-0.00826883
-0.0067333
-0.00540476
-0.00426382
-0.0032678
-0.00241786
-0.00163037
-0.000978308
-0.000238362
-0.763972
-0.700789
-0.631669
-0.567691
-0.505919
-0.445722
-0.388907
-0.336783
-0.289847
-0.248281
-0.212066
-0.180968
-0.154584
-0.132403
-0.113858
-0.0983713
-0.0853929
-0.0744315
-0.0650713
-0.0569783
-0.0498962
-0.043636
-0.0380619
-0.0330784
-0.0286169
-0.0246272
-0.0210695
-0.0179102
-0.0151188
-0.0126655
-0.0105217
-0.00865738
-0.00704519
-0.0056522
-0.00445673
-0.0034148
-0.00252515
-0.00170368
-0.00102009
-0.000251731
-0.709882
-0.656925
-0.597777
-0.541975
-0.487437
-0.433616
-0.382075
-0.334116
-0.290353
-0.251082
-0.21641
-0.186239
-0.160297
-0.138195
-0.11947
-0.103633
-0.0902053
-0.0787502
-0.0688898
-0.0603149
-0.0527843
-0.0461161
-0.0401775
-0.0348723
-0.0301298
-0.0258966
-0.0221292
-0.0187904
-0.015846
-0.0132628
-0.0110092
-0.00905217
-0.00736189
-0.00590334
-0.00465241
-0.00356388
-0.00263388
-0.00177803
-0.0010623
-0.000265456
-0.660217
-0.616004
-0.565648
-0.517208
-0.469259
-0.421353
-0.374817
-0.330897
-0.290275
-0.253335
-0.22028
-0.191127
-0.165722
-0.143783
-0.12495
-0.108821
-0.0949875
-0.0830679
-0.0727254
-0.0636784
-0.0557028
-0.0486266
-0.0423211
-0.0366908
-0.0316635
-0.027183
-0.0232026
-0.0196813
-0.0165815
-0.0138665
-0.0115014
-0.00945058
-0.00768131
-0.0061565
-0.00484957
-0.00371405
-0.00274331
-0.00185293
-0.00110465
-0.00027945
-0.614912
-0.578126
-0.535459
-0.493585
-0.451579
-0.409095
-0.36725
-0.327195
-0.289643
-0.255034
-0.223644
-0.195583
-0.170797
-0.149105
-0.130239
-0.113878
-0.0996873
-0.087339
-0.0765389
-0.0670355
-0.0586242
-0.0511445
-0.0444736
-0.0385179
-0.0332047
-0.0284755
-0.0242806
-0.0205756
-0.0173192
-0.0144716
-0.0119945
-0.00984936
-0.00800083
-0.0064096
-0.00504659
-0.00386409
-0.00285256
-0.00192776
-0.00114679
-0.000293604
-0.573904
-0.54338
-0.507377
-0.471296
-0.434593
-0.397023
-0.359515
-0.323108
-0.288509
-0.256192
-0.226486
-0.199568
-0.175471
-0.1541
-0.135272
-0.118744
-0.104248
-0.0915123
-0.0802855
-0.0703476
-0.0615154
-0.0536418
-0.0466116
-0.0403342
-0.0347372
-0.0297606
-0.025352
-0.0214639
-0.0180516
-0.0150719
-0.0124833
-0.0102445
-0.00831723
-0.00666012
-0.00524149
-0.00401249
-0.00296054
-0.00200178
-0.0011883
-0.000307777
-0.537135
-0.511844
-0.481555
-0.450531
-0.418502
-0.385326
-0.351771
-0.318752
-0.286949
-0.256847
-0.228806
-0.203058
-0.179699
-0.158712
-0.139988
-0.123355
-0.108609
-0.0955313
-0.0839142
-0.0735696
-0.0643373
-0.0560852
-0.0487068
-0.0421159
-0.0362413
-0.0310219
-0.0264034
-0.0223352
-0.0187696
-0.01566
-0.0129618
-0.0106311
-0.00862663
-0.00690496
-0.00543189
-0.00415743
-0.00306593
-0.00207407
-0.00122867
-0.000321792
-0.504561
-0.483596
-0.458148
-0.431477
-0.403513
-0.374207
-0.344195
-0.314268
-0.285061
-0.257055
-0.230627
-0.206041
-0.183448
-0.162892
-0.144327
-0.127647
-0.112705
-0.0993342
-0.0873677
-0.0766502
-0.0670447
-0.0584355
-0.0507257
-0.0438346
-0.037693
-0.0322396
-0.0274182
-0.0231759
-0.0194619
-0.0162268
-0.0134228
-0.0110033
-0.00892433
-0.00714045
-0.00561494
-0.00429675
-0.00316715
-0.00214355
-0.0012673
-0.000335439
-0.476158
-0.458722
-0.437312
-0.414329
-0.38984
-0.36388
-0.33698
-0.309815
-0.282965
-0.256896
-0.231986
-0.208524
-0.186696
-0.166595
-0.148232
-0.131555
-0.116469
-0.102854
-0.0905827
-0.0795311
-0.0695857
-0.060647
-0.052629
-0.0454569
-0.0390641
-0.0333899
-0.0283769
-0.0239699
-0.0201155
-0.0167616
-0.0138576
-0.0113541
-0.00920478
-0.00736219
-0.00578723
-0.00442786
-0.00326233
-0.00220893
-0.00130348
-0.000348462
-0.451943
-0.437329
-0.419218
-0.399292
-0.377707
-0.354573
-0.330337
-0.305572
-0.280801
-0.256466
-0.232941
-0.210524
-0.189429
-0.169786
-0.151649
-0.135013
-0.119828
-0.106018
-0.0934889
-0.0821469
-0.0719008
-0.0626673
-0.0543709
-0.0469434
-0.0403215
-0.0344451
-0.0292563
-0.0246981
-0.0207148
-0.0172517
-0.0142558
-0.0116752
-0.00946144
-0.00756505
-0.00594478
-0.00454773
-0.00334929
-0.00226869
-0.00133639
-0.000360558
-0.431985
-0.419565
-0.404067
-0.386596
-0.36736
-0.346529
-0.324491
-0.301733
-0.278723
-0.255878
-0.23356
-0.212071
-0.191641
-0.172428
-0.154521
-0.137951
-0.122707
-0.108746
-0.0960087
-0.0844245
-0.0739232
-0.0644364
-0.055899
-0.0482491
-0.0414267
-0.035373
-0.0300296
-0.0253383
-0.0212415
-0.0176824
-0.0146055
-0.0119572
-0.00968669
-0.00774303
-0.00608296
-0.00465284
-0.00342547
-0.00232109
-0.00136506
-0.000371371
-0.416436
-0.405639
-0.392106
-0.376504
-0.359067
-0.340013
-0.319687
-0.298509
-0.276901
-0.255255
-0.233921
-0.213199
-0.19333
-0.17449
-0.156791
-0.140296
-0.125022
-0.110953
-0.098056
-0.0862818
-0.0755772
-0.0658865
-0.0571536
-0.0493223
-0.0423358
-0.0361365
-0.0306661
-0.0258652
-0.0216749
-0.0180366
-0.0148931
-0.012189
-0.00987177
-0.00788924
-0.00619643
-0.00473914
-0.00348797
-0.00236413
-0.0013884
-0.000380495
-0.405556
-0.39585
-0.383656
-0.369338
-0.353142
-0.335319
-0.316189
-0.296125
-0.275513
-0.254725
-0.234102
-0.213942
-0.194489
-0.175929
-0.158395
-0.141966
-0.126679
-0.112541
-0.0995344
-0.087627
-0.076778
-0.0669411
-0.0580673
-0.0501046
-0.0429989
-0.0366937
-0.0311306
-0.0262498
-0.0219912
-0.018295
-0.0151029
-0.012358
-0.0100067
-0.00799581
-0.00627909
-0.00480204
-0.00353344
-0.00239555
-0.00140508
-0.000387481
-0.399777
-0.390635
-0.379142
-0.365499
-0.349956
-0.332783
-0.314287
-0.294816
-0.274737
-0.254412
-0.234175
-0.214321
-0.195096
-0.176693
-0.159252
-0.142862
-0.127572
-0.113399
-0.100335
-0.0883571
-0.0774306
-0.067515
-0.0585649
-0.050531
-0.0433605
-0.0369976
-0.0313839
-0.0264595
-0.0221637
-0.018436
-0.0152173
-0.0124502
-0.0100803
-0.00805392
-0.00632412
-0.00483639
-0.00355809
-0.00241292
-0.00141357
-0.000391727
-3.15318
-3.15617
-3.15704
-3.15578
-3.15245
-3.14707
-3.13969
-3.13034
-3.11907
-3.10593
-3.09097
-3.07423
-3.05577
-3.03565
-3.01391
-2.99061
-2.9658
-2.93955
-2.91192
-2.88294
-2.85268
-2.82118
-2.7885
-2.75468
-2.71978
-2.6839
-2.64726
-2.6096
-2.57103
-2.55072
-2.89585
-2.899
-2.9003
-2.89975
-2.89737
-2.8932
-2.8873
-2.8797
-2.87045
-2.85959
-2.84718
-2.83326
-2.81789
-2.80112
-2.78301
-2.76363
-2.74301
-2.72123
-2.69834
-2.6744
-2.64945
-2.62356
-2.59675
-2.56905
-2.54047
-2.51101
-2.4806
-2.44828
-2.41353
-2.39428
-2.66427
-2.66715
-2.66845
-2.66817
-2.66633
-2.66298
-2.65815
-2.65188
-2.64419
-2.63514
-2.62476
-2.61309
-2.60018
-2.58608
-2.57082
-2.55446
-2.53704
-2.5186
-2.4992
-2.47888
-2.45768
-2.43564
-2.41278
-2.38914
-2.36472
-2.33954
-2.31357
-2.28591
-2.25643
-2.24133
-2.45389
-2.45622
-2.4572
-2.45683
-2.45513
-2.45212
-2.44785
-2.44234
-2.43561
-2.42771
-2.41867
-2.40853
-2.39731
-2.38506
-2.37182
-2.35762
-2.34251
-2.32652
-2.30969
-2.29207
-2.27369
-2.25459
-2.23481
-2.21438
-2.19333
-2.17172
-2.14959
-2.12617
-2.10171
-2.09033
-2.26194
-2.26394
-2.26478
-2.26445
-2.26298
-2.2604
-2.25672
-2.25198
-2.24621
-2.23942
-2.23166
-2.22296
-2.21333
-2.20283
-2.19148
-2.17931
-2.16636
-2.15268
-2.13828
-2.12322
-2.10752
-2.09122
-2.07436
-2.05697
-2.03908
-2.02076
-2.00201
-1.98217
-1.96169
-1.95249
-2.08617
-2.08798
-2.08878
-2.08858
-2.08741
-2.08527
-2.08219
-2.0782
-2.07332
-2.06757
-2.06098
-2.05358
-2.0454
-2.03645
-2.02678
-2.01641
-2.00538
-1.9937
-1.98143
-1.96858
-1.95519
-1.94129
-1.92692
-1.9121
-1.89688
-1.8813
-1.86537
-1.84853
-1.83139
-1.82382
-1.92444
-1.92616
-1.92701
-1.927
-1.92614
-1.92446
-1.92196
-1.91868
-1.91462
-1.90982
-1.90429
-1.89807
-1.89116
-1.8836
-1.87541
-1.86662
-1.85726
-1.84735
-1.83692
-1.82599
-1.81461
-1.80279
-1.79057
-1.77797
-1.76504
-1.75181
-1.73829
-1.724
-1.70969
-1.70333
-1.77508
-1.7768
-1.77777
-1.77799
-1.77747
-1.77624
-1.77431
-1.7717
-1.76842
-1.76449
-1.75994
-1.75477
-1.74902
-1.7427
-1.73584
-1.72846
-1.72058
-1.71223
-1.70342
-1.6942
-1.68457
-1.67457
-1.66423
-1.65356
-1.64261
-1.63141
-1.61994
-1.60782
-1.59588
-1.59043
-1.63684
-1.63861
-1.63973
-1.6402
-1.64003
-1.63925
-1.63786
-1.63587
-1.6333
-1.63018
-1.6265
-1.6223
-1.61758
-1.61238
-1.60669
-1.60056
-1.59399
-1.58701
-1.57964
-1.57189
-1.56381
-1.55539
-1.54668
-1.53769
-1.52844
-1.51899
-1.50929
-1.49904
-1.48911
-1.48439
-1.50875
-1.5106
-1.51188
-1.51261
-1.51278
-1.51241
-1.51151
-1.5101
-1.50818
-1.50577
-1.50288
-1.49953
-1.49574
-1.49151
-1.48687
-1.48183
-1.47641
-1.47063
-1.4645
-1.45806
-1.4513
-1.44427
-1.43697
-1.42942
-1.42166
-1.41371
-1.40553
-1.3969
-1.38867
-1.38457
-1.39009
-1.39203
-1.39348
-1.39444
-1.39492
-1.39493
-1.39447
-1.39356
-1.39221
-1.39043
-1.38824
-1.38563
-1.38264
-1.37927
-1.37553
-1.37144
-1.36702
-1.36227
-1.35723
-1.3519
-1.3463
-1.34045
-1.33436
-1.32806
-1.32156
-1.3149
-1.30802
-1.30078
-1.29399
-1.29042
-1.28029
-1.28232
-1.28391
-1.28508
-1.28583
-1.28616
-1.28609
-1.28562
-1.28476
-1.28353
-1.28192
-1.27996
-1.27765
-1.27501
-1.27205
-1.26877
-1.2652
-1.26135
-1.25722
-1.25284
-1.24822
-1.24338
-1.23832
-1.23308
-1.22765
-1.22208
-1.2163
-1.21024
-1.20463
-1.20152
-1.17886
-1.18096
-1.18268
-1.18402
-1.185
-1.18561
-1.18586
-1.18576
-1.18532
-1.18454
-1.18344
-1.18202
-1.18029
-1.17826
-1.17595
-1.17336
-1.1705
-1.16739
-1.16404
-1.16046
-1.15666
-1.15266
-1.14847
-1.14411
-1.13958
-1.13491
-1.13006
-1.12497
-1.12033
-1.11761
-1.08535
-1.0875
-1.08933
-1.09082
-1.09198
-1.09282
-1.09334
-1.09355
-1.09345
-1.09305
-1.09236
-1.09139
-1.09015
-1.08863
-1.08686
-1.08483
-1.08257
-1.08008
-1.07737
-1.07445
-1.07133
-1.06803
-1.06456
-1.06092
-1.05713
-1.05321
-1.04912
-1.04482
-1.04094
-1.03855
-0.999351
-1.00155
-1.00345
-1.00505
-1.00637
-1.00739
-1.00812
-1.00858
-1.00876
-1.00868
-1.00833
-1.00773
-1.00687
-1.00578
-1.00445
-1.00289
-1.00111
-0.999129
-0.996943
-0.994566
-0.992007
-0.989276
-0.986383
-0.983338
-0.980153
-0.976839
-0.973365
-0.969716
-0.966429
-0.964302
-0.920479
-0.922702
-0.924659
-0.926348
-0.927774
-0.928939
-0.929848
-0.930503
-0.93091
-0.931074
-0.930998
-0.93069
-0.930155
-0.929398
-0.928427
-0.927248
-0.925868
-0.924294
-0.922535
-0.920598
-0.918492
-0.916224
-0.913803
-0.911239
-0.908541
-0.905717
-0.902743
-0.899612
-0.896782
-0.894863
-0.848356
-0.850588
-0.85258
-0.85433
-0.85584
-0.857114
-0.858154
-0.858964
-0.859547
-0.859907
-0.860048
-0.859976
-0.859695
-0.85921
-0.858527
-0.857652
-0.85659
-0.855348
-0.853933
-0.852351
-0.85061
-0.848716
-0.846676
-0.844499
-0.842194
-0.839765
-0.837194
-0.834478
-0.832002
-0.830244
-0.782621
-0.78485
-0.786858
-0.788646
-0.790215
-0.791568
-0.792706
-0.793632
-0.79435
-0.794863
-0.795174
-0.795287
-0.795206
-0.794937
-0.794483
-0.79385
-0.793042
-0.792066
-0.790927
-0.78963
-0.788182
-0.786589
-0.784857
-0.782992
-0.781003
-0.778894
-0.776647
-0.774266
-0.772066
-0.770433
-0.722934
-0.725146
-0.727156
-0.728963
-0.730569
-0.731975
-0.733183
-0.734195
-0.735014
-0.735642
-0.736082
-0.736339
-0.736415
-0.736314
-0.73604
-0.735598
-0.734992
-0.734227
-0.733308
-0.732239
-0.731027
-0.729675
-0.72819
-0.726577
-0.724843
-0.722992
-0.72101
-0.7189
-0.71692
-0.715383
-0.668972
-0.671158
-0.673157
-0.674968
-0.676592
-0.67803
-0.679284
-0.680356
-0.681247
-0.68196
-0.682498
-0.682863
-0.683059
-0.683089
-0.682956
-0.682663
-0.682216
-0.681618
-0.680874
-0.679987
-0.678962
-0.677804
-0.676518
-0.675108
-0.673581
-0.671938
-0.670171
-0.668283
-0.666479
-0.665018
-0.620436
-0.622589
-0.624566
-0.626369
-0.627996
-0.62945
-0.630732
-0.631842
-0.632783
-0.633556
-0.634165
-0.634611
-0.634897
-0.635025
-0.635
-0.634824
-0.634501
-0.634034
-0.633427
-0.632684
-0.631809
-0.630806
-0.62968
-0.628434
-0.627074
-0.625602
-0.62401
-0.622303
-0.620643
-0.61924
-0.577059
-0.579171
-0.58112
-0.582904
-0.584523
-0.585979
-0.587273
-0.588405
-0.589378
-0.590192
-0.59085
-0.591354
-0.591706
-0.591909
-0.591965
-0.591878
-0.59165
-0.591285
-0.590786
-0.590157
-0.589401
-0.588521
-0.587522
-0.586408
-0.585182
-0.583848
-0.5824
-0.580842
-0.579299
-0.577941
-0.538599
-0.540668
-0.542582
-0.54434
-0.545943
-0.547391
-0.548686
-0.549827
-0.550817
-0.551656
-0.552347
-0.552891
-0.553291
-0.553548
-0.553665
-0.553645
-0.55349
-0.553204
-0.552789
-0.552248
-0.551585
-0.550804
-0.549907
-0.548898
-0.547781
-0.546559
-0.545228
-0.543791
-0.542345
-0.541021
-0.504861
-0.506885
-0.508761
-0.510489
-0.51207
-0.513503
-0.51479
-0.515931
-0.516927
-0.51778
-0.518491
-0.519061
-0.519493
-0.519789
-0.51995
-0.51998
-0.51988
-0.519653
-0.519303
-0.518831
-0.518242
-0.517537
-0.516721
-0.515796
-0.514766
-0.513634
-0.512397
-0.511059
-0.509691
-0.508392
-0.475689
-0.477666
-0.479503
-0.481199
-0.482754
-0.484168
-0.485441
-0.486575
-0.487571
-0.488428
-0.48915
-0.489736
-0.49019
-0.490512
-0.490705
-0.490771
-0.490712
-0.490531
-0.49023
-0.489811
-0.489279
-0.488634
-0.487881
-0.487023
-0.486062
-0.485001
-0.483841
-0.482583
-0.481278
-0.479998
-0.451004
-0.452937
-0.454736
-0.456398
-0.457925
-0.459317
-0.460574
-0.461696
-0.462685
-0.463542
-0.464267
-0.464862
-0.465329
-0.465669
-0.465884
-0.465976
-0.465946
-0.465799
-0.465535
-0.465157
-0.464667
-0.464069
-0.463365
-0.462558
-0.461651
-0.460646
-0.459545
-0.45835
-0.457094
-0.455827
-0.43076
-0.432653
-0.434416
-0.436048
-0.437549
-0.438919
-0.440159
-0.441269
-0.44225
-0.443103
-0.443828
-0.444428
-0.444902
-0.445254
-0.445485
-0.445595
-0.445589
-0.445466
-0.44523
-0.444883
-0.444427
-0.443864
-0.443198
-0.442431
-0.441565
-0.440604
-0.439548
-0.4384
-0.437182
-0.435924
-0.415089
-0.416946
-0.418676
-0.420279
-0.421755
-0.423104
-0.424327
-0.425424
-0.426395
-0.427242
-0.427965
-0.428566
-0.429045
-0.429404
-0.429644
-0.429768
-0.429777
-0.429672
-0.429456
-0.429131
-0.428699
-0.428163
-0.427524
-0.426785
-0.425949
-0.425018
-0.423993
-0.422879
-0.421687
-0.420432
-0.40412
-0.40595
-0.407657
-0.409239
-0.410698
-0.412033
-0.413244
-0.414332
-0.415298
-0.416141
-0.416863
-0.417466
-0.417949
-0.418314
-0.418563
-0.418697
-0.418718
-0.418627
-0.418426
-0.418117
-0.417703
-0.417185
-0.416565
-0.415846
-0.41503
-0.414119
-0.413116
-0.412023
-0.410845
-0.40959
-0.398378
-0.400183
-0.401866
-0.403429
-0.40487
-0.406191
-0.407391
-0.408471
-0.409431
-0.410271
-0.410993
-0.411597
-0.412085
-0.412456
-0.412713
-0.412856
-0.412887
-0.412807
-0.412618
-0.412321
-0.411919
-0.411412
-0.410803
-0.410094
-0.409287
-0.408383
-0.407385
-0.406296
-0.405118
-0.403852
-1.99961
-2.10841
-2.16816
-2.22835
-2.28994
-2.34944
-2.40716
-2.46325
-2.5175
-2.56975
-2.61995
-2.66803
-2.71396
-2.7577
-2.79921
-2.83847
-2.87548
-2.9102
-2.94264
-2.97279
-3.00063
-3.02616
-3.0494
-3.07032
-3.08896
-3.1053
-3.11937
-3.13118
-3.14074
-3.14809
-1.87744
-1.96613
-2.00701
-2.05619
-2.11193
-2.16605
-2.21818
-2.26894
-2.3181
-2.36543
-2.41087
-2.45438
-2.49592
-2.53548
-2.57303
-2.60856
-2.64205
-2.67349
-2.70288
-2.73021
-2.75547
-2.77867
-2.79981
-2.81889
-2.83592
-2.85091
-2.86388
-2.87484
-2.88382
-2.89082
-1.767
-1.85604
-1.89341
-1.93661
-1.98696
-2.03524
-2.08068
-2.12454
-2.16694
-2.20767
-2.24671
-2.28408
-2.31975
-2.35372
-2.38596
-2.41647
-2.44524
-2.47226
-2.49751
-2.52101
-2.54274
-2.56271
-2.58092
-2.59737
-2.61207
-2.62504
-2.63628
-2.6458
-2.65364
-2.6598
-1.67343
-1.75806
-1.79082
-1.8273
-1.87115
-1.91343
-1.95283
-1.9907
-2.02736
-2.06259
-2.09633
-2.12859
-2.15936
-2.18863
-2.21639
-2.24263
-2.26733
-2.2905
-2.31215
-2.33225
-2.35083
-2.36787
-2.38339
-2.3974
-2.40989
-2.42089
-2.43041
-2.43845
-2.44504
-2.45019
-1.5837
-1.65989
-1.68769
-1.71839
-1.75641
-1.79345
-1.82787
-1.86084
-1.89276
-1.92344
-1.9528
-1.98084
-2.00756
-2.03294
-2.057
-2.07971
-2.10109
-2.12112
-2.13982
-2.15718
-2.1732
-2.1879
-2.20128
-2.21335
-2.22411
-2.23358
-2.24176
-2.24868
-2.25434
-2.25876
-1.49431
-1.56195
-1.58593
-1.61235
-1.64559
-1.67818
-1.70837
-1.73718
-1.76504
-1.7918
-1.81739
-1.84179
-1.86503
-1.88709
-1.90799
-1.92772
-1.94627
-1.96366
-1.97989
-1.99495
-2.00886
-2.02163
-2.03324
-2.04373
-2.05308
-2.06133
-2.06846
-2.0745
-2.07946
-2.08335
-1.40595
-1.46574
-1.48664
-1.5096
-1.53867
-1.56728
-1.59375
-1.61893
-1.64325
-1.66662
-1.68895
-1.71025
-1.73052
-1.74977
-1.768
-1.78522
-1.80142
-1.8166
-1.83078
-1.84395
-1.85612
-1.8673
-1.87749
-1.8867
-1.89494
-1.90221
-1.90852
-1.91389
-1.91833
-1.92185
-1.31963
-1.37218
-1.39039
-1.41034
-1.43571
-1.46076
-1.48392
-1.50592
-1.52716
-1.54758
-1.56711
-1.58573
-1.60346
-1.62032
-1.63629
-1.65138
-1.6656
-1.67894
-1.69141
-1.70302
-1.71376
-1.72364
-1.73268
-1.74086
-1.7482
-1.75472
-1.7604
-1.76528
-1.76934
-1.77261
-1.23569
-1.28156
-1.29736
-1.31471
-1.33681
-1.35869
-1.37894
-1.39818
-1.41675
-1.43461
-1.45171
-1.46804
-1.4836
-1.49841
-1.51246
-1.52575
-1.5383
-1.55009
-1.56113
-1.57143
-1.58099
-1.58981
-1.5979
-1.60525
-1.61188
-1.6178
-1.623
-1.6275
-1.6313
-1.63441
-1.1542
-1.19404
-1.20773
-1.22283
-1.24208
-1.26118
-1.2789
-1.29574
-1.312
-1.32767
-1.34268
-1.35704
-1.37075
-1.38381
-1.39623
-1.40801
-1.41914
-1.42962
-1.43947
-1.44868
-1.45725
-1.46519
-1.4725
-1.47918
-1.48523
-1.49067
-1.49549
-1.4997
-1.50331
-1.50633
-1.07535
-1.10985
-1.12171
-1.13488
-1.15167
-1.16837
-1.1839
-1.19867
-1.21296
-1.22674
-1.23998
-1.25266
-1.26479
-1.27638
-1.28741
-1.2979
-1.30784
-1.31723
-1.32607
-1.33436
-1.34211
-1.34932
-1.35598
-1.3621
-1.36768
-1.37273
-1.37725
-1.38124
-1.38471
-1.38766
-0.999369
-1.0292
-1.03952
-1.05107
-1.06574
-1.08038
-1.09403
-1.10704
-1.11965
-1.13184
-1.14356
-1.15482
-1.16562
-1.17595
-1.18582
-1.19522
-1.20415
-1.21262
-1.22061
-1.22814
-1.2352
-1.24179
-1.24792
-1.25357
-1.25876
-1.26349
-1.26776
-1.27157
-1.27493
-1.27783
-0.926519
-0.952307
-0.961373
-0.971559
-0.984441
-0.99732
-1.00938
-1.02091
-1.0321
-1.04293
-1.05339
-1.06345
-1.07311
-1.08239
-1.09127
-1.09976
-1.10785
-1.11554
-1.12282
-1.12971
-1.13618
-1.14226
-1.14793
-1.1532
-1.15806
-1.16252
-1.16658
-1.17024
-1.17351
-1.17638
-0.857069
-0.879389
-0.887454
-0.896522
-0.907898
-0.919295
-0.930019
-0.940298
-0.950291
-0.959993
-0.969375
-0.978427
-0.987149
-0.995539
-1.00359
-1.01131
-1.01869
-1.02572
-1.03241
-1.03875
-1.04474
-1.05038
-1.05566
-1.0606
-1.06519
-1.06942
-1.0733
-1.07683
-1.08002
-1.08286
-0.791275
-0.810634
-0.817921
-0.826086
-0.836205
-0.846363
-0.855968
-0.865203
-0.874199
-0.882952
-0.891436
-0.899643
-0.90757
-0.915215
-0.922573
-0.929642
-0.936418
-0.942897
-0.949077
-0.954956
-0.960532
-0.965801
-0.970764
-0.975418
-0.979763
-0.983798
-0.987525
-0.990942
-0.994052
-0.996856
-0.729361
-0.746201
-0.752897
-0.760339
-0.769418
-0.778543
-0.787218
-0.795583
-0.803748
-0.811708
-0.819441
-0.826939
-0.834199
-0.841217
-0.847989
-0.854511
-0.860778
-0.866789
-0.872539
-0.878026
-0.883246
-0.888198
-0.892879
-0.897289
-0.901425
-0.905287
-0.908874
-0.912187
-0.915225
-0.91799
-0.671504
-0.686205
-0.692458
-0.699327
-0.707547
-0.715815
-0.723716
-0.73136
-0.738831
-0.746129
-0.753234
-0.760138
-0.766836
-0.773325
-0.779601
-0.785659
-0.791496
-0.797107
-0.802489
-0.807639
-0.812553
-0.81723
-0.821667
-0.825862
-0.829813
-0.833519
-0.836979
-0.840193
-0.843161
-0.845883
-0.617822
-0.630713
-0.636633
-0.643049
-0.650563
-0.65812
-0.665378
-0.67242
-0.679313
-0.686057
-0.692634
-0.699037
-0.705262
-0.711303
-0.717158
-0.722822
-0.72829
-0.733558
-0.738623
-0.743482
-0.748131
-0.752567
-0.756789
-0.760793
-0.764578
-0.768142
-0.771484
-0.774604
-0.7775
-0.780174
-0.568381
-0.57974
-0.58541
-0.591465
-0.598396
-0.605362
-0.612085
-0.618625
-0.625034
-0.631312
-0.637444
-0.643424
-0.649247
-0.654908
-0.660404
-0.665729
-0.67088
-0.675852
-0.680642
-0.685247
-0.689663
-0.693887
-0.697916
-0.701749
-0.705383
-0.708816
-0.712047
-0.715076
-0.7179
-0.72052
-0.523194
-0.533259
-0.538736
-0.5445
-0.55095
-0.557424
-0.563698
-0.569817
-0.575819
-0.581704
-0.587459
-0.593079
-0.598559
-0.603895
-0.609081
-0.614115
-0.61899
-0.623705
-0.628254
-0.632635
-0.636844
-0.640879
-0.644736
-0.648413
-0.651908
-0.655219
-0.658345
-0.661284
-0.664036
-0.666599
-0.482232
-0.491202
-0.496526
-0.502052
-0.508103
-0.514165
-0.520063
-0.525826
-0.531484
-0.537034
-0.542469
-0.547781
-0.552966
-0.558021
-0.56294
-0.567719
-0.572355
-0.576843
-0.58118
-0.585363
-0.589388
-0.593252
-0.596953
-0.600488
-0.603854
-0.607051
-0.610077
-0.612929
-0.615607
-0.61811
-0.445434
-0.45348
-0.458676
-0.464005
-0.469722
-0.475439
-0.481018
-0.486479
-0.491843
-0.497109
-0.502268
-0.507316
-0.512247
-0.517057
-0.521743
-0.526301
-0.530725
-0.535014
-0.539163
-0.543169
-0.547028
-0.550739
-0.554297
-0.557702
-0.560949
-0.564039
-0.566968
-0.569736
-0.572341
-0.574783
-0.41272
-0.419985
-0.42507
-0.430232
-0.43567
-0.441095
-0.446404
-0.451607
-0.456721
-0.461742
-0.466665
-0.471483
-0.476194
-0.480792
-0.485274
-0.489637
-0.493876
-0.497987
-0.501969
-0.505816
-0.509527
-0.513098
-0.516527
-0.519812
-0.522949
-0.525938
-0.528776
-0.531463
-0.533996
-0.536375
-0.384001
-0.390612
-0.395598
-0.400617
-0.40582
-0.411
-0.416078
-0.421062
-0.425961
-0.430773
-0.435491
-0.440112
-0.444631
-0.449044
-0.453349
-0.45754
-0.461616
-0.465571
-0.469403
-0.473109
-0.476687
-0.480132
-0.483443
-0.486618
-0.489654
-0.492549
-0.495301
-0.49791
-0.500374
-0.502691
-0.359192
-0.365258
-0.370154
-0.375051
-0.380058
-0.385031
-0.389914
-0.394711
-0.399427
-0.40406
-0.408603
-0.413054
-0.417407
-0.421661
-0.42581
-0.429852
-0.433784
-0.437602
-0.441302
-0.444883
-0.448341
-0.451674
-0.454879
-0.457953
-0.460896
-0.463705
-0.466378
-0.468914
-0.471312
-0.473571
-0.338241
-0.343864
-0.348681
-0.353474
-0.35832
-0.363123
-0.367845
-0.372486
-0.377049
-0.38153
-0.385926
-0.390232
-0.394445
-0.398562
-0.402579
-0.406493
-0.4103
-0.413998
-0.417584
-0.421055
-0.424408
-0.427641
-0.430751
-0.433737
-0.436596
-0.439326
-0.441927
-0.444396
-0.446733
-0.448936
-0.321115
-0.326387
-0.331136
-0.335846
-0.340563
-0.345229
-0.34982
-0.354334
-0.358771
-0.363128
-0.367401
-0.371588
-0.375683
-0.379686
-0.383591
-0.387396
-0.391099
-0.394695
-0.398183
-0.401559
-0.404822
-0.407969
-0.410998
-0.413906
-0.416692
-0.419354
-0.421891
-0.424301
-0.426583
-0.428736
-0.3079
-0.312917
-0.31762
-0.32227
-0.326894
-0.331461
-0.335956
-0.340375
-0.344717
-0.34898
-0.353159
-0.357253
-0.361257
-0.365169
-0.368985
-0.372703
-0.37632
-0.379833
-0.38324
-0.386539
-0.389726
-0.3928
-0.395759
-0.398601
-0.401323
-0.403926
-0.406407
-0.408764
-0.410998
-0.413107
-0.298684
-0.303533
-0.308208
-0.31282
-0.317384
-0.321883
-0.326311
-0.330663
-0.334938
-0.339133
-0.343245
-0.347271
-0.351208
-0.355052
-0.358803
-0.362456
-0.366009
-0.36946
-0.372807
-0.376047
-0.379178
-0.382198
-0.385105
-0.387898
-0.390574
-0.393133
-0.395572
-0.397892
-0.40009
-0.402166
-0.293884
-0.298685
-0.303378
-0.308001
-0.31256
-0.317048
-0.321461
-0.325795
-0.330048
-0.334217
-0.3383
-0.342293
-0.346194
-0.350001
-0.353711
-0.357323
-0.360833
-0.364239
-0.367541
-0.370735
-0.373821
-0.376795
-0.379658
-0.382407
-0.385042
-0.38756
-0.389961
-0.392244
-0.394409
-0.396453
0.640615
0.640321
0.639557
0.638365
0.636654
0.634357
0.631362
0.627539
0.622724
0.616717
0.609271
0.600083
0.58878
0.574905
0.557892
0.537039
0.51147
0.480098
0.441549
0.394115
0.335599
0.263308
0.173593
0.0622687
-0.0773285
-0.25115
-0.474102
-0.751302
-1.12563
-1.60795
0.626903
0.626531
0.62568
0.624309
0.622354
0.61974
0.616357
0.612069
0.606708
0.600068
0.591896
0.581882
0.569647
0.554726
0.536544
0.514395
0.487402
0.454477
0.414257
0.365056
0.304725
0.230633
0.139285
0.0266384
-0.113477
-0.286727
-0.506153
-0.776378
-1.13144
-1.56241
0.612538
0.61217
0.611297
0.609821
0.607694
0.604841
0.601152
0.596489
0.590685
0.583531
0.574774
0.564103
0.55114
0.535424
0.516387
0.493333
0.465405
0.431544
0.390436
0.340461
0.279584
0.205325
0.114453
0.00327301
-0.133696
-0.301255
-0.510388
-0.763224
-1.08642
-1.45728
0.597451
0.597058
0.596121
0.594503
0.592166
0.589036
0.585
0.57992
0.573627
0.565911
0.556517
0.545136
0.53139
0.514821
0.49487
0.470855
0.441937
0.407094
0.365064
0.314305
0.252899
0.178538
0.0882633
-0.0212551
-0.154825
-0.31643
-0.515233
-0.751247
-1.04774
-1.37511
0.581639
0.581208
0.580188
0.578414
0.575851
0.572425
0.568025
0.562509
0.555708
0.54741
0.537361
0.52525
0.510703
0.493266
0.472389
0.447403
0.417497
0.381681
0.33875
0.287243
0.225367
0.150981
0.0613999
-0.0463573
-0.176473
-0.332236
-0.521318
-0.742325
-1.01693
-1.31055
0.565101
0.564632
0.563528
0.561598
0.55881
0.555091
0.550328
0.544382
0.537079
0.528211
0.517521
0.504702
0.489385
0.471121
0.449374
0.423493
0.392694
0.356032
0.312364
0.260317
0.19823
0.124142
0.0356437
-0.0698978
-0.196073
-0.345542
-0.524725
-0.731206
-0.98497
-1.24889
0.547835
0.54733
0.54614
0.544056
0.541046
0.537038
0.531921
0.525552
0.517762
0.50834
0.497034
0.48354
0.467496
0.448463
0.425921
0.399242
0.367678
0.33033
0.286128
0.233797
0.171814
0.0984118
0.0114583
-0.0913296
-0.21298
-0.35558
-0.524436
-0.716397
-0.949401
-1.18662
0.529844
0.529302
0.528026
0.52579
0.522561
0.518271
0.512806
0.506027
0.497764
0.487811
0.475917
0.461787
0.445065
0.425328
0.402074
0.374703
0.342506
0.304642
0.260114
0.207755
0.14619
0.0738456
-0.0111313
-0.110683
-0.227312
-0.362592
-0.52083
-0.698448
-0.911161
-1.12448
0.511138
0.510561
0.509199
0.506815
0.503373
0.498807
0.493007
0.485834
0.47712
0.466662
0.454218
0.439497
0.422157
0.40179
0.377918
0.349973
0.31729
0.279088
0.234453
0.182329
0.121492
0.0505639
-0.0320365
-0.127927
-0.239128
-0.366771
-0.514265
-0.677906
-0.87112
-1.06287
0.491739
0.491126
0.489681
0.487154
0.483507
0.478678
0.472559
0.465012
0.455875
0.444948
0.431997
0.416742
0.398854
0.377945
0.353562
0.325175
0.292165
0.253818
0.209307
0.157688
0.0978888
0.0287262
-0.0511241
-0.142976
-0.248416
-0.368206
-0.504958
-0.65507
-0.829699
-1.00171
0.471677
0.471029
0.469504
0.466841
0.463001
0.457925
0.451507
0.443614
0.434087
0.422734
0.40933
0.393606
0.37525
0.353898
0.329124
0.300438
0.267275
0.228986
0.184834
0.133992
0.0755361
0.00846925
-0.068291
-0.155782
-0.255206
-0.367021
-0.493147
-0.630227
-0.787286
-0.941105
0.450993
0.450313
0.448713
0.445925
0.441904
0.4366
0.429909
0.421702
0.411825
0.400097
0.3863
0.370183
0.35145
0.329763
0.304728
0.275897
0.24276
0.204738
0.161184
0.111385
0.0545625
-0.0101057
-0.0834799
-0.16635
-0.259585
-0.363403
-0.479131
-0.603744
-0.744356
-0.881402
0.429744
0.429034
0.427365
0.424462
0.42028
0.41477
0.407835
0.399352
0.389173
0.377126
0.363007
0.346578
0.327568
0.305663
0.280505
0.25169
0.218763
0.181217
0.138496
0.0899945
0.0350714
-0.026931
-0.0966746
-0.174733
-0.261693
-0.357588
-0.463256
-0.576032
-0.701402
-0.823054
0.407999
0.407263
0.405533
0.402529
0.398204
0.392516
0.385372
0.376655
0.366226
0.353924
0.339558
0.322909
0.303728
0.281728
0.25659
0.227955
0.195423
0.158559
0.116893
0.0699242
0.0171387
-0.0419732
-0.107898
-0.181026
-0.261712
-0.349848
-0.445888
-0.547523
-0.658894
-0.766519
0.385845
0.385085
0.383303
0.380214
0.375769
0.369932
0.362618
0.353715
0.343094
0.330606
0.316075
0.299302
0.28006
0.258095
0.233122
0.204829
0.172873
0.136887
0.0964811
0.0512556
0.000809777
-0.0552343
-0.117214
-0.185364
-0.259857
-0.340483
-0.427404
-0.518645
-0.617268
-0.712216
0.363385
0.362605
0.36078
0.357623
0.353085
0.347132
0.339688
0.330651
0.3199
0.307299
0.292689
0.275891
0.256703
0.2349
0.210237
0.182444
0.151235
0.116307
0.0773464
0.0340431
-0.0139015
-0.066752
-0.12472
-0.187917
-0.256374
-0.329812
-0.408182
-0.489813
-0.576917
-0.660501
0.340739
0.339945
0.338088
0.334882
0.330275
0.324243
0.316715
0.307597
0.296781
0.284143
0.269542
0.252819
0.233798
0.212284
0.188068
0.160925
0.130619
0.0969086
0.0595509
0.0183137
-0.0270126
-0.0765967
-0.130549
-0.188884
-0.251528
-0.31816
-0.388591
-0.461415
-0.538189
-0.611665
0.318048
0.317244
0.315367
0.312131
0.307486
0.30141
0.293844
0.284702
0.273886
0.261288
0.246784
0.230234
0.211489
0.190383
0.166743
0.140384
0.111121
0.0787637
0.0431337
0.00406733
-0.0385699
-0.0848685
-0.134859
-0.188483
-0.245595
-0.305854
-0.368981
-0.433805
-0.501382
-0.565932
0.295473
0.294664
0.292778
0.289533
0.284877
0.278796
0.271238
0.262127
0.251377
0.238894
0.22457
0.208288
0.189921
0.169333
0.146383
0.120927
0.0928195
0.0619228
0.0281109
-0.0087209
-0.0486456
-0.0916914
-0.137828
-0.186946
-0.238854
-0.293206
-0.349677
-0.407295
-0.466743
-0.52346
0.273193
0.272384
0.270501
0.267266
0.262628
0.256579
0.249074
0.240048
0.229427
0.217129
0.203064
0.187135
0.169238
0.149264
0.127102
0.102642
0.0757799
0.0464184
0.0144779
-0.0200979
-0.0573327
-0.0972072
-0.139647
-0.18451
-0.231577
-0.280511
-0.330972
-0.382155
-0.434467
-0.484355
0.251409
0.250605
0.248736
0.24553
0.240937
0.234954
0.227545
0.218655
0.208219
0.19617
0.182434
0.166932
0.149583
0.130301
0.109003
0.0856108
0.0600517
0.0322662
0.00221223
-0.0301279
-0.0647399
-0.10157
-0.140513
-0.181406
-0.224023
-0.268041
-0.313125
-0.358609
-0.404702
-0.448672
0.230342
0.229548
0.227704
0.224544
0.220021
0.214136
0.206861
0.198149
0.187947
0.176202
0.162853
0.147839
0.131097
0.112565
0.0921837
0.0699007
0.0456721
0.0194683
-0.00872245
-0.0388877
-0.0709853
-0.104936
-0.140619
-0.17786
-0.216432
-0.256039
-0.296356
-0.33684
-0.377555
-0.416429
0.210237
0.209456
0.207645
0.204547
0.200114
0.194353
0.187242
0.178745
0.168818
0.157418
0.144499
0.130016
0.113922
0.096174
0.0767347
0.0555732
0.0326694
0.00801716
-0.0183713
-0.0464611
-0.0761904
-0.107465
-0.140152
-0.174078
-0.209024
-0.244716
-0.280856
-0.316993
-0.353097
-0.387618
0.191358
0.190594
0.188823
0.185797
0.181471
0.175853
0.168931
0.160674
0.151048
0.140021
0.127558
0.113628
0.0981993
0.081245
0.0627447
0.0426858
0.0210669
-0.0020992
-0.0267827
-0.0529328
-0.0804744
-0.109304
-0.139286
-0.170251
-0.201992
-0.234259
-0.266782
-0.299185
-0.331376
-0.36221
0.173997
0.173251
0.171524
0.168578
0.164368
0.158906
0.152185
0.144181
0.13487
0.124225
0.112226
0.0988496
0.0840783
0.0678987
0.050304
0.0312965
0.0108891
-0.0108916
-0.0340028
-0.0583831
-0.0839491
-0.110593
-0.138182
-0.166551
-0.195509
-0.22483
-0.254269
-0.283511
-0.312424
-0.340175
0.15847
0.157744
0.156063
0.153198
0.149107
0.143803
0.137285
0.129534
0.120533
0.110263
0.0987116
0.0858659
0.071718
0.0562652
0.039512
0.0214714
0.00216742
-0.0183633
-0.0400692
-0.062882
-0.0867144
-0.111458
-0.136982
-0.163133
-0.189731
-0.216573
-0.243437
-0.270058
-0.296278
-0.321497
0.14513
0.144423
0.142787
0.14
0.136022
0.130868
0.124541
0.117027
0.108314
0.0983902
0.0872484
0.0748841
0.0612971
0.0464928
0.0304841
0.0132922
-0.00505104
-0.0245021
-0.045004
-0.0664842
-0.0888539
-0.112006
-0.135815
-0.160134
-0.184799
-0.209624
-0.234407
-0.25892
-0.282991
-0.306188
0.134371
0.13368
0.132083
0.129365
0.125486
0.120464
0.114302
0.106992
0.0985262
0.0888969
0.0781021
0.0661427
0.0530243
0.0387585
0.0233638
0.00686734
-0.0106939
-0.0292719
-0.0488061
-0.0692222
-0.0904313
-0.112328
-0.134792
-0.157685
-0.180852
-0.204122
-0.227311
-0.250215
-0.27266
-0.294326
0.126643
0.125965
0.124397
0.121732
0.117929
0.113005
0.106969
0.0998136
0.0915329
0.0821238
0.0715871
0.0599277
0.0471548
0.0332839
0.0183374
0.00234615
-0.0146498
-0.0325997
-0.0514413
-0.0710995
-0.0914857
-0.112497
-0.134017
-0.155912
-0.178037
-0.200229
-0.222317
-0.244114
-0.265441
-0.286049
0.122469
0.121797
0.120246
0.117611
0.113851
0.108983
0.103016
0.095947
0.0877695
0.0784825
0.0680887
0.0565945
0.0440116
0.0303571
0.0156554
-6.08546e-05
-0.0167501
-0.0343603
-0.0528284
-0.0720792
-0.0920247
-0.112563
-0.13358
-0.154946
-0.176519
-0.198144
-0.219654
-0.240871
-0.261621
-0.281692
0.895038
0.895369
0.896326
0.898059
0.900487
0.903628
0.907466
0.911994
0.917198
0.923065
0.929574
0.936699
0.944401
0.952631
0.961318
0.970365
0.979639
0.988955
0.998069
1.00663
1.01419
1.02006
1.02344
1.02282
1.0167
1.00094
0.971715
0.914631
0.813149
0.61987
0.887076
0.887381
0.888259
0.889885
0.892169
0.895128
0.898743
0.903004
0.907894
0.913395
0.919479
0.926113
0.933253
0.940836
0.948782
0.956979
0.965276
0.973468
0.981282
0.988339
0.994143
0.997968
0.998909
0.995454
0.985797
0.96611
0.931401
0.869386
0.758439
0.56262
0.879058
0.879336
0.880136
0.881655
0.883794
0.88657
0.889962
0.893955
0.89853
0.903661
0.909317
0.915458
0.92203
0.928961
0.936159
0.943496
0.950804
0.957857
0.964353
0.969882
0.973898
0.97564
0.974089
0.967739
0.954454
0.930738
0.890407
0.823306
0.702654
0.504088
0.870987
0.871239
0.87196
0.873373
0.875367
0.87796
0.881127
0.884852
0.889109
0.893869
0.899095
0.904739
0.910738
0.917012
0.923454
0.929922
0.936229
0.942129
0.947288
0.951266
0.953463
0.953084
0.94899
0.939684
0.92269
0.894848
0.848759
0.776438
0.645848
0.444367
0.862867
0.863093
0.863735
0.865041
0.86689
0.8693
0.872243
0.875698
0.879636
0.884024
0.888817
0.89396
0.899383
0.904994
0.910672
0.916263
0.921559
0.92629
0.930094
0.932498
0.932847
0.930309
0.923623
0.911302
0.890519
0.858461
0.80648
0.728819
0.588062
0.383532
0.8547
0.854899
0.855465
0.856664
0.858368
0.860595
0.863313
0.866498
0.870116
0.874129
0.878487
0.883127
0.887969
0.892912
0.897821
0.902525
0.906798
0.910347
0.912777
0.913584
0.912056
0.907322
0.897998
0.882603
0.857954
0.821595
0.763591
0.680486
0.529332
0.321649
0.846488
0.846662
0.847151
0.848245
0.849805
0.851849
0.854341
0.857255
0.860553
0.864191
0.868111
0.872245
0.876503
0.880771
0.884904
0.888714
0.891954
0.894306
0.895345
0.894533
0.891098
0.884133
0.872125
0.853598
0.82501
0.784269
0.720115
0.631474
0.469697
0.258789
0.838235
0.838385
0.838798
0.839787
0.841203
0.843065
0.845332
0.847975
0.850952
0.854212
0.857694
0.861318
0.864988
0.868579
0.871929
0.874836
0.877032
0.878175
0.877805
0.875351
0.869982
0.860749
0.846012
0.8243
0.7917
0.7465
0.676075
0.58182
0.409197
0.195021
0.829944
0.830069
0.830409
0.831294
0.832568
0.834247
0.83629
0.838662
0.841317
0.844199
0.847239
0.850353
0.853432
0.856339
0.858901
0.860897
0.862038
0.861958
0.860164
0.856046
0.848716
0.83718
0.81967
0.79472
0.758039
0.708307
0.631494
0.531556
0.347873
0.130414
0.821617
0.821719
0.821987
0.822769
0.823901
0.8254
0.827218
0.829319
0.831652
0.834155
0.836754
0.839354
0.841838
0.844058
0.845826
0.846903
0.84698
0.845664
0.842427
0.836624
0.827306
0.813434
0.793109
0.764867
0.724041
0.669705
0.586396
0.480714
0.285765
0.0650347
0.813257
0.813337
0.813535
0.814216
0.815208
0.816527
0.818122
0.819952
0.821963
0.824086
0.826241
0.828326
0.830212
0.831741
0.832709
0.83286
0.831862
0.829297
0.824603
0.817094
0.805761
0.78952
0.766339
0.734754
0.68972
0.63071
0.540805
0.429322
0.222917
-0.00105286
0.804868
0.804927
0.805057
0.805639
0.806492
0.807632
0.809004
0.810565
0.812253
0.813997
0.815707
0.817274
0.81856
0.819393
0.819556
0.818774
0.816692
0.812866
0.806697
0.797462
0.784089
0.765445
0.739368
0.704389
0.65509
0.591336
0.494747
0.377405
0.159373
-0.0677894
0.796452
0.796491
0.796556
0.79704
0.797757
0.798719
0.79987
0.801162
0.802528
0.803891
0.805156
0.806204
0.806887
0.807021
0.806373
0.80465
0.801475
0.796376
0.788717
0.777736
0.762297
0.741217
0.712206
0.673783
0.620164
0.551596
0.448247
0.324983
0.0951809
-0.135121
0.788011
0.788032
0.788035
0.788424
0.789006
0.789793
0.790724
0.791747
0.792792
0.793775
0.794593
0.79512
0.795198
0.794629
0.793165
0.790496
0.786218
0.779834
0.77067
0.757922
0.740393
0.716844
0.684863
0.642945
0.584957
0.5115
0.401332
0.272071
0.0303938
-0.203002
0.779549
0.779553
0.779498
0.779794
0.780243
0.780856
0.781569
0.782325
0.783049
0.783651
0.784023
0.784029
0.783498
0.782223
0.779939
0.776315
0.770927
0.763245
0.752561
0.738026
0.718383
0.692334
0.657346
0.611882
0.549482
0.471058
0.354031
0.218678
-0.034929
-0.271398
0.771069
0.771057
0.770947
0.771153
0.771472
0.771914
0.77241
0.7729
0.773304
0.773526
0.773451
0.772933
0.771793
0.769808
0.766699
0.762115
0.755607
0.746617
0.734398
0.718057
0.696276
0.667694
0.629666
0.580604
0.513752
0.430277
0.306374
0.164803
-0.100719
-0.340291
0.762573
0.762549
0.762387
0.762505
0.762697
0.762969
0.76325
0.763475
0.76356
0.763403
0.762881
0.761839
0.760088
0.75739
0.753452
0.747901
0.740265
0.729955
0.716186
0.69802
0.674077
0.642932
0.601828
0.549118
0.477779
0.389163
0.258391
0.110441
-0.166898
-0.409684
0.754064
0.754029
0.75382
0.753854
0.753921
0.754026
0.754094
0.754056
0.753824
0.753288
0.752318
0.750752
0.748387
0.744974
0.740202
0.733679
0.724906
0.713265
0.697932
0.677921
0.651793
0.618053
0.573842
0.51743
0.441575
0.347721
0.210115
0.0555753
-0.23337
-0.479605
0.745544
0.745501
0.74525
0.745202
0.745148
0.745089
0.744946
0.744647
0.744098
0.743184
0.741767
0.739675
0.736696
0.732565
0.726955
0.719453
0.709536
0.696553
0.679641
0.657767
0.629432
0.593064
0.545714
0.485548
0.405151
0.305954
0.161577
0.000183533
-0.300027
-0.550121
0.737016
0.736968
0.736679
0.736554
0.736382
0.736161
0.735809
0.735251
0.734387
0.733096
0.731232
0.728615
0.725019
0.720168
0.713716
0.70523
0.694161
0.679825
0.66132
0.637564
0.606998
0.567972
0.517451
0.453478
0.368517
0.263866
0.112807
-0.055765
-0.366737
-0.621341
0.728482
0.728432
0.728111
0.727912
0.727625
0.727246
0.726688
0.725873
0.724695
0.723028
0.720718
0.717574
0.713361
0.707788
0.70049
0.691015
0.678785
0.663086
0.642975
0.617318
0.584498
0.542782
0.489059
0.421226
0.33168
0.22146
0.0638333
-0.112305
-0.433354
-0.693437
0.719945
0.719897
0.719548
0.719279
0.718882
0.718347
0.717586
0.716516
0.715026
0.712985
0.710229
0.706559
0.701728
0.69543
0.687283
0.676813
0.663415
0.646342
0.62461
0.597034
0.561937
0.5175
0.460543
0.388797
0.294646
0.178742
0.0146786
-0.169473
-0.49971
-0.76665
0.711406
0.711364
0.710994
0.710659
0.710155
0.709468
0.708508
0.707185
0.705385
0.702971
0.69977
0.695574
0.690124
0.683099
0.6741
0.662629
0.648057
0.629598
0.606233
0.576718
0.539321
0.492133
0.431909
0.356199
0.257421
0.135719
-0.0346401
-0.227296
-0.565628
-0.841299
0.702868
0.702837
0.702452
0.702056
0.701449
0.700614
0.699456
0.697883
0.695776
0.692989
0.689345
0.684623
0.678553
0.6708
0.660945
0.64847
0.632715
0.612862
0.587849
0.556377
0.516658
0.466687
0.403163
0.323439
0.22001
0.092403
-0.0841145
-0.285787
-0.630922
-0.917796
0.694332
0.694317
0.693924
0.693471
0.692766
0.691785
0.690432
0.688612
0.686199
0.683042
0.678955
0.673707
0.667017
0.658534
0.647821
0.634335
0.617391
0.596133
0.569458
0.536012
0.493946
0.441162
0.374304
0.290515
0.182406
0.0487975
-0.133758
-0.344948
-0.695442
-0.996648
0.685801
0.685807
0.685412
0.684905
0.684105
0.682981
0.681436
0.67937
0.676653
0.673127
0.668597
0.662823
0.655511
0.646295
0.634719
0.620217
0.602075
0.579402
0.55105
0.515609
0.471173
0.415544
0.345317
0.257417
0.144594
0.0049013
-0.183607
-0.404761
-0.75911
-1.07848
0.677278
0.677311
0.676923
0.676368
0.675478
0.674216
0.672483
0.670175
0.667157
0.663264
0.658293
0.651995
0.644062
0.634112
0.621672
0.606151
0.586805
0.562707
0.532666
0.495213
0.448387
0.389885
0.316258
0.224211
0.106647
-0.0391734
-0.233568
-0.46498
-0.821719
-1.16379
0.668769
0.668847
0.668484
0.667898
0.666932
0.665546
0.663639
0.661102
0.657796
0.65355
0.648152
0.641343
0.632802
0.622132
0.60884
0.592311
0.571772
0.546257
0.514531
0.475067
0.425841
0.364453
0.287405
0.191185
0.0688666
-0.0830691
-0.283251
-0.524887
-0.882473
-1.25218
0.660274
0.66041
0.660092
0.659487
0.658458
0.656959
0.654888
0.652133
0.64855
0.64396
0.638145
0.630834
0.621694
0.610313
0.596176
0.578643
0.556912
0.529975
0.496552
0.455051
0.403386
0.339049
0.258492
0.157985
0.0307695
-0.127419
-0.333537
-0.585403
-0.942806
-1.34578
0.651744
0.651849
0.651491
0.650781
0.649603
0.647905
0.645582
0.642518
0.63856
0.633525
0.627183
0.619252
0.609385
0.597151
0.582016
0.563313
0.540207
0.511651
0.47632
0.432558
0.378215
0.310677
0.226332
0.121215
-0.0113456
-0.176409
-0.389676
-0.653133
-1.01429
-1.45857
1.09661
1.09736
1.09968
1.10377
1.10958
1.11715
1.12652
1.13776
1.15093
1.16611
1.18341
1.20294
1.22482
1.24918
1.27618
1.30597
1.3387
1.37451
1.41351
1.45573
1.5011
1.54929
1.59963
1.65053
1.69998
1.74319
1.77592
1.77614
1.75993
1.40786
1.09127
1.09199
1.09429
1.09832
1.10403
1.11147
1.12069
1.13174
1.14469
1.15961
1.17661
1.19579
1.21726
1.24117
1.26765
1.29685
1.32891
1.36397
1.40213
1.4434
1.48771
1.53463
1.58346
1.63233
1.679
1.7175
1.74452
1.73096
1.7174
1.36527
1.08586
1.0866
1.08891
1.0929
1.09854
1.10588
1.11495
1.12582
1.13854
1.15319
1.16987
1.18867
1.20972
1.23314
1.25906
1.28764
1.319
1.35328
1.39057
1.43089
1.47419
1.52012
1.56813
1.61661
1.664
1.70432
1.73693
1.72681
1.73649
1.40118
1.08034
1.08109
1.0834
1.08736
1.09293
1.10016
1.10909
1.11978
1.13228
1.14668
1.16305
1.18151
1.20217
1.22514
1.25056
1.27857
1.30931
1.34289
1.37941
1.41891
1.46135
1.50643
1.55375
1.60184
1.64974
1.69122
1.72841
1.72055
1.74603
1.4224
1.07471
1.07547
1.07777
1.08168
1.08717
1.0943
1.10309
1.11359
1.12588
1.14001
1.15609
1.17421
1.19447
1.217
1.24192
1.26937
1.29948
1.33237
1.36814
1.40682
1.44838
1.49255
1.53903
1.58638
1.63408
1.67535
1.71484
1.7062
1.73967
1.42864
1.06897
1.06974
1.07203
1.07589
1.0813
1.08831
1.09695
1.10727
1.11933
1.13321
1.14898
1.16674
1.1866
1.20867
1.23308
1.25996
1.28943
1.32161
1.35659
1.39441
1.43506
1.47826
1.52381
1.57025
1.61749
1.65816
1.69929
1.68966
1.72828
1.43173
1.06314
1.0639
1.06618
1.06998
1.07531
1.0822
1.09069
1.10082
1.11265
1.12626
1.14172
1.15913
1.17858
1.20018
1.22407
1.25036
1.27918
1.31063
1.34481
1.38174
1.42145
1.46364
1.50821
1.55368
1.60037
1.64035
1.68286
1.67285
1.71476
1.43227
1.05719
1.05795
1.06021
1.06396
1.0692
1.07597
1.0843
1.09424
1.10585
1.11918
1.13432
1.15136
1.1704
1.19154
1.21489
1.24059
1.26873
1.29944
1.3328
1.36884
1.40757
1.44873
1.49227
1.53669
1.58272
1.62188
1.66529
1.65518
1.69832
1.42883
1.05115
1.05191
1.05414
1.05783
1.06298
1.06963
1.0778
1.08754
1.09891
1.11196
1.12678
1.14345
1.16207
1.18273
1.20555
1.23063
1.25811
1.28806
1.32058
1.3557
1.39344
1.43352
1.47598
1.51926
1.56448
1.60264
1.64643
1.6363
1.67887
1.42143
1.045
1.04575
1.04796
1.05159
1.05665
1.06316
1.07117
1.08071
1.09184
1.10461
1.11911
1.1354
1.15359
1.17376
1.19603
1.2205
1.24729
1.27647
1.30814
1.34231
1.37903
1.41799
1.45931
1.50139
1.54563
1.58266
1.62629
1.61622
1.65686
1.41049
1.03876
1.0395
1.04168
1.04524
1.0502
1.05658
1.06442
1.07375
1.08464
1.09713
1.11129
1.1272
1.14496
1.16464
1.18635
1.2102
1.23628
1.26468
1.29548
1.32868
1.36434
1.40216
1.44228
1.48306
1.52619
1.56196
1.60495
1.59496
1.63263
1.39629
1.03241
1.03314
1.03528
1.03878
1.04363
1.04988
1.05755
1.06668
1.07731
1.08951
1.10334
1.11886
1.13617
1.15536
1.1765
1.19971
1.22508
1.25268
1.28259
1.31481
1.34938
1.386
1.42487
1.46429
1.50615
1.54056
1.58246
1.57249
1.60636
1.37899
1.02596
1.02668
1.02879
1.03221
1.03696
1.04307
1.05056
1.05948
1.06986
1.08176
1.09525
1.11038
1.12724
1.14592
1.16649
1.18906
1.21369
1.24048
1.26948
1.30069
1.33414
1.36953
1.40709
1.44506
1.48551
1.51845
1.55884
1.54879
1.5782
1.35878
1.01942
1.02013
1.02219
1.02554
1.03018
1.03615
1.04346
1.05216
1.06229
1.07389
1.08703
1.10176
1.11817
1.13633
1.15632
1.17822
1.20212
1.22808
1.25615
1.28632
1.31863
1.35274
1.38892
1.42538
1.46427
1.49562
1.53413
1.52383
1.54826
1.33583
1.01278
1.01347
1.01549
1.01876
1.02329
1.02912
1.03625
1.04473
1.05459
1.06589
1.07867
1.093
1.10895
1.12659
1.14598
1.16722
1.19037
1.21547
1.2426
1.2717
1.30283
1.33563
1.37037
1.40525
1.44244
1.47209
1.50836
1.4976
1.51663
1.31028
1.00605
1.00672
1.00869
1.01188
1.0163
1.02197
1.02892
1.03718
1.04678
1.05776
1.07019
1.08411
1.09959
1.11669
1.13549
1.15605
1.17843
1.20267
1.22883
1.25685
1.28676
1.3182
1.35144
1.38466
1.42001
1.44784
1.48157
1.47008
1.48336
1.28225
0.999219
0.999879
1.0018
1.0049
1.00921
1.01473
1.02149
1.02952
1.03885
1.04952
1.06158
1.07509
1.09009
1.10666
1.12484
1.14471
1.16631
1.18967
1.21484
1.24174
1.27041
1.30045
1.33212
1.36361
1.39699
1.42287
1.45378
1.44129
1.44853
1.25185
0.992302
0.992943
0.994809
0.997828
1.00201
1.00738
1.01395
1.02174
1.0308
1.04115
1.05285
1.06593
1.08046
1.09647
1.11404
1.1332
1.15401
1.17648
1.20064
1.2264
1.25378
1.28238
1.31242
1.3421
1.37338
1.39719
1.42502
1.41122
1.41215
1.21917
0.985295
0.985917
0.987725
0.990656
0.994717
0.999925
1.0063
1.01386
1.02264
1.03267
1.044
1.05665
1.07069
1.08615
1.10308
1.12154
1.14154
1.16309
1.18622
1.21082
1.23688
1.26399
1.29235
1.32014
1.34919
1.37079
1.39531
1.3799
1.37428
1.18431
0.978201
0.978802
0.980551
0.983391
0.987326
0.992375
0.99855
1.00587
1.01437
1.02408
1.03502
1.04725
1.06079
1.07569
1.09198
1.10971
1.12889
1.14952
1.17159
1.195
1.21971
1.24529
1.27189
1.29773
1.32443
1.34368
1.36468
1.34732
1.33493
1.14733
0.971022
0.971601
0.973288
0.976035
0.979843
0.984728
0.990702
0.997786
1.006
1.01537
1.02594
1.03772
1.05076
1.06509
1.08074
1.09773
1.11608
1.13576
1.15676
1.17895
1.20227
1.22628
1.25106
1.27487
1.2991
1.31586
1.33313
1.31353
1.29415
1.10831
0.963759
0.964317
0.965938
0.96859
0.972268
0.976988
0.982758
0.989598
0.997525
1.00656
1.01674
1.02808
1.04061
1.05436
1.06936
1.0856
1.1031
1.12182
1.14173
1.16267
1.18457
1.20696
1.22986
1.25156
1.27322
1.28733
1.30069
1.27854
1.25194
1.06731
0.956415
0.95695
0.958504
0.96106
0.964605
0.969157
0.974721
0.981313
0.98895
0.99765
1.00743
1.01833
1.03034
1.04351
1.05784
1.07332
1.08996
1.1077
1.12649
1.14616
1.16661
1.18733
1.2083
1.22781
1.24678
1.25811
1.26738
1.24237
1.20835
1.0244
0.948993
0.949504
0.950988
0.953446
0.956857
0.961239
0.966594
0.972936
0.980278
0.988635
0.998024
1.00846
1.01996
1.03253
1.04619
1.0609
1.07667
1.09341
1.11106
1.12944
1.14839
1.16741
1.18637
1.20363
1.2198
1.22821
1.23322
1.20506
1.16339
0.979632
0.941494
0.941981
0.943394
0.945751
0.949027
0.953236
0.95838
0.96447
0.971514
0.979525
0.988514
0.998491
1.00947
1.02144
1.03441
1.04835
1.06322
1.07895
1.09545
1.1125
1.12992
1.14719
1.1641
1.17902
1.19229
1.19764
1.19821
1.16663
1.1171
0.933082
0.933922
0.934383
0.935723
0.937979
0.941117
0.945151
0.950083
0.955917
0.962661
0.970322
0.978907
0.98842
0.998863
1.01023
1.0225
1.03565
1.04963
1.06433
1.07964
1.09534
1.11121
1.12668
1.14147
1.15398
1.16426
1.16641
1.16239
1.12713
1.0695
0.884807
0.926278
0.926714
0.927979
0.930133
0.933131
0.936989
0.941705
0.947282
0.953723
0.961031
0.969208
0.978252
0.988157
0.99891
1.01048
1.02283
1.03589
1.04955
1.06366
1.07799
1.09226
1.10589
1.11851
1.12854
1.13572
1.13453
1.12577
1.08658
1.02063
0.834871
0.918565
0.918975
0.920165
0.922214
0.925071
0.928752
0.933251
0.938568
0.944704
0.951656
0.959421
0.967991
0.977354
0.987485
0.998349
1.00989
1.02202
1.03462
1.04751
1.06043
1.07307
1.08483
1.09522
1.10269
1.10668
1.10203
1.08838
1.04501
0.970528
0.783338
0.910785
0.911169
0.912282
0.914227
0.916942
0.920444
0.924724
0.929779
0.935607
0.9422
0.949549
0.957642
0.966456
0.97596
0.986106
0.996824
1.00802
1.01953
1.03119
1.04268
1.05366
1.06349
1.0716
1.07644
1.07716
1.06892
1.05022
1.00247
0.919214
0.730272
0.902942
0.9033
0.904335
0.906174
0.908746
0.912068
0.916127
0.92092
0.926437
0.932668
0.939599
0.947209
0.95547
0.96434
0.973761
0.983648
0.993886
1.00431
1.0147
1.02474
1.03403
1.0419
1.04767
1.04981
1.04716
1.03521
1.01132
0.958991
0.866733
0.675745
1.22856
1.22845
1.22817
1.22768
1.22696
1.22599
1.22473
1.22315
1.2212
1.21882
1.21595
1.21253
1.20847
1.20368
1.19808
1.19157
1.18402
1.17534
1.1654
1.15407
1.14124
1.12677
1.11054
1.09242
1.07232
1.05012
1.02575
0.99914
0.970257
0.939112
1.22934
1.22925
1.22901
1.22859
1.22796
1.2271
1.22599
1.22457
1.22281
1.22065
1.21802
1.21485
1.21106
1.20656
1.20126
1.19505
1.18781
1.17942
1.16977
1.15871
1.14612
1.13186
1.11579
1.09778
1.07771
1.05546
1.03096
1.00412
0.974915
0.94335
1.23069
1.23063
1.23046
1.23016
1.2297
1.22906
1.22821
1.22711
1.22571
1.22394
1.22175
1.21906
1.21578
1.21182
1.20708
1.20144
1.19477
1.18696
1.17786
1.16733
1.15521
1.14135
1.1256
1.1078
1.08782
1.06551
1.04078
1.01352
0.983673
0.951239
1.23236
1.23234
1.23227
1.23213
1.23191
1.23158
1.2311
1.23043
1.22953
1.22833
1.22676
1.22474
1.22218
1.21899
1.21505
1.21023
1.2044
1.19743
1.18914
1.17937
1.16796
1.15472
1.13947
1.12202
1.1022
1.07984
1.05481
1.02698
0.996272
0.96264
1.23409
1.23412
1.23417
1.23424
1.23432
1.23436
1.23434
1.23422
1.23394
1.23344
1.23265
1.23149
1.22985
1.22763
1.22471
1.22095
1.21621
1.21032
1.2031
1.19437
1.18391
1.17151
1.15696
1.14003
1.12049
1.09815
1.07281
1.04431
1.01252
0.977344
1.23565
1.23574
1.23594
1.23625
1.23666
1.23715
1.23767
1.23818
1.23863
1.23896
1.23909
1.23893
1.23838
1.23733
1.23564
1.23317
1.22975
1.2252
1.21931
1.21187
1.20263
1.19134
1.17772
1.16152
1.14243
1.12021
1.09459
1.06536
1.03234
0.995311
1.23684
1.237
1.23735
1.23793
1.23872
1.2397
1.24082
1.24204
1.24331
1.24457
1.24573
1.24672
1.24741
1.2477
1.24743
1.24646
1.24459
1.24163
1.23734
1.23146
1.22372
1.21381
1.20141
1.18618
1.16776
1.14582
1.12002
1.09004
1.05569
1.0165
1.23749
1.23772
1.23824
1.23911
1.2403
1.24181
1.24357
1.24556
1.24772
1.24999
1.25229
1.25453
1.2566
1.25837
1.2597
1.26042
1.26032
1.25918
1.25674
1.25271
1.24677
1.23855
1.22767
1.21371
1.19622
1.17478
1.14894
1.11828
1.08253
1.0409
1.23747
1.23778
1.23847
1.23963
1.24126
1.24331
1.24575
1.24855
1.25165
1.25499
1.25849
1.26207
1.26562
1.26901
1.27208
1.27465
1.27652
1.27743
1.2771
1.2752
1.27136
1.26515
1.25612
1.24376
1.22753
1.20686
1.1812
1.14998
1.11284
1.06849
1.23668
1.23707
1.23794
1.23941
1.24147
1.24408
1.24722
1.25085
1.25491
1.25936
1.26412
1.26911
1.27421
1.2793
1.28423
1.28881
1.29281
1.29597
1.29798
1.29848
1.29704
1.29319
1.28637
1.27597
1.26135
1.2418
1.21659
1.18497
1.14652
1.09917
1.23508
1.23554
1.23659
1.23836
1.24086
1.24404
1.24787
1.25233
1.25737
1.26295
1.26899
1.27541
1.28212
1.28898
1.29585
1.30253
1.30881
1.31439
1.31896
1.3221
1.32336
1.32219
1.31795
1.30992
1.29731
1.27924
1.25482
1.22306
1.18345
1.13281
1.23263
1.23317
1.23439
1.23646
1.23938
1.24311
1.24764
1.25292
1.25893
1.26562
1.27294
1.28081
1.28913
1.2978
1.30666
1.31553
1.32418
1.33232
1.33961
1.34563
1.34986
1.35169
1.35039
1.34513
1.33495
1.31881
1.29555
1.26397
1.22341
1.16915
1.22935
1.22995
1.23134
1.2337
1.23703
1.2413
1.24648
1.25256
1.25952
1.2673
1.27587
1.28517
1.2951
1.30557
1.31643
1.32752
1.3386
1.34939
1.35955
1.36862
1.37605
1.38118
1.38318
1.3811
1.37381
1.36003
1.33838
1.30733
1.26613
1.20787
1.22525
1.22592
1.22747
1.2301
1.23382
1.23859
1.24441
1.25125
1.2591
1.26794
1.27772
1.28839
1.2999
1.31213
1.32497
1.33827
1.3518
1.3653
1.3784
1.39065
1.40149
1.41017
1.41581
1.4173
1.41334
1.40242
1.38282
1.35274
1.31124
1.24853
1.22039
1.22112
1.22281
1.2257
1.22978
1.23503
1.24143
1.24899
1.25769
1.26752
1.27844
1.29043
1.30343
1.31737
1.33214
1.3476
1.36355
1.37975
1.39583
1.41135
1.42572
1.43817
1.44773
1.45318
1.453
1.44542
1.42836
1.39971
1.35832
1.29061
1.21482
1.21561
1.21743
1.22055
1.22497
1.23065
1.2376
1.24581
1.2553
1.26604
1.27804
1.29126
1.30568
1.32123
1.33784
1.35538
1.37368
1.39252
1.41156
1.43037
1.44836
1.46473
1.47845
1.48818
1.49221
1.48846
1.47445
1.44777
1.4069
1.33351
1.20862
1.20945
1.21139
1.21473
1.21945
1.22552
1.23296
1.24178
1.25197
1.26356
1.27654
1.29089
1.30662
1.32368
1.342
1.36151
1.38206
1.40344
1.42537
1.44742
1.46903
1.48941
1.50747
1.52176
1.5304
1.53098
1.52052
1.49641
1.45644
1.37658
1.20186
1.20274
1.20478
1.2083
1.21329
1.21972
1.22759
1.23694
1.24778
1.26012
1.27398
1.28937
1.30629
1.32472
1.34463
1.36596
1.38861
1.4124
1.43707
1.46227
1.48745
1.51183
1.53432
1.55341
1.56701
1.57239
1.56603
1.54513
1.50642
1.41908
1.19462
1.19553
1.19767
1.20136
1.20658
1.21331
1.22157
1.23139
1.24279
1.2558
1.27044
1.28675
1.30473
1.3244
1.34575
1.36874
1.39331
1.41932
1.44657
1.47475
1.50335
1.53167
1.55862
1.58264
1.6015
1.61214
1.61043
1.59345
1.55628
1.46024
1.18699
1.18793
1.19015
1.19397
1.1994
1.20639
1.21498
1.22521
1.23709
1.25068
1.266
1.28311
1.30202
1.32278
1.3454
1.36988
1.39618
1.42421
1.45382
1.48475
1.51659
1.54867
1.57999
1.60899
1.63335
1.64968
1.65319
1.64086
1.60549
1.49929
1.17903
1.17999
1.18228
1.18623
1.19182
1.19903
1.20791
1.21847
1.23077
1.24485
1.26075
1.27854
1.29826
1.31996
1.34369
1.36946
1.39728
1.4271
1.45882
1.49225
1.52705
1.56266
1.59817
1.63209
1.66207
1.68446
1.69376
1.68685
1.65352
1.53548
1.17083
1.17181
1.17415
1.1782
1.18393
1.19132
1.20042
1.21127
1.22391
1.23839
1.25478
1.27314
1.29354
1.31604
1.3407
1.36758
1.39671
1.42807
1.46164
1.49727
1.53471
1.57353
1.61294
1.65159
1.6872
1.71593
1.73159
1.73081
1.69981
1.56808
1.16244
1.16344
1.16582
1.16996
1.17579
1.18334
1.19262
1.20369
1.2166
1.23142
1.2482
1.26702
1.28797
1.31113
1.33657
1.36437
1.39459
1.42726
1.46238
1.49989
1.53962
1.58126
1.62419
1.66725
1.70833
1.74356
1.76607
1.77208
1.74379
1.59627
1.15395
1.15495
1.15737
1.16157
1.16749
1.17514
1.18457
1.19581
1.20894
1.224
1.24109
1.26028
1.28167
1.30535
1.33141
1.35996
1.39106
1.42479
1.46119
1.50025
1.54189
1.58591
1.63188
1.6789
1.72512
1.76682
1.79656
1.80989
1.78479
1.61914
1.1454
1.14641
1.14885
1.1531
1.15908
1.16681
1.17634
1.18771
1.20099
1.21624
1.23356
1.25302
1.27474
1.29882
1.32536
1.35448
1.38628
1.42084
1.45825
1.49853
1.54168
1.58761
1.63608
1.68645
1.73728
1.78514
1.8223
1.8433
1.82204
1.63573
1.13684
1.13786
1.14032
1.1446
1.15062
1.1584
1.16799
1.17945
1.19283
1.20821
1.22568
1.24534
1.26729
1.29165
1.31854
1.34808
1.38039
1.41558
1.45373
1.49493
1.5392
1.58656
1.63691
1.68991
1.74455
1.79791
1.84224
1.87082
1.85418
1.64487
1.12833
1.12934
1.13182
1.13611
1.14216
1.14996
1.15959
1.17109
1.18452
1.19998
1.21754
1.23731
1.25941
1.28396
1.31108
1.34091
1.37357
1.40918
1.44786
1.48968
1.53473
1.58304
1.63467
1.68946
1.7469
1.80465
1.85536
1.89074
1.87943
1.64542
1.1199
1.12091
1.12341
1.12772
1.13377
1.14159
1.15123
1.16274
1.1762
1.19168
1.20928
1.22911
1.25129
1.27593
1.30319
1.33319
1.36606
1.40194
1.44093
1.48314
1.52863
1.57748
1.6298
1.68564
1.74497
1.80613
1.86273
1.90425
1.89945
1.6406
1.1116
1.11263
1.11516
1.11949
1.12555
1.13337
1.14301
1.15451
1.16796
1.18344
1.20104
1.22088
1.24307
1.26774
1.29503
1.32509
1.35804
1.39402
1.43314
1.47547
1.5211
1.57007
1.62258
1.67889
1.73959
1.80393
1.86723
1.91608
1.92238
1.64593
1.10343
1.10442
1.10694
1.11124
1.11725
1.12502
1.13459
1.14603
1.1594
1.17479
1.19229
1.21202
1.2341
1.25867
1.28586
1.31581
1.34866
1.38455
1.42357
1.46578
1.51122
1.55987
1.61181
1.66712
1.72648
1.78924
1.85279
1.90049
1.91958
1.63607
0.918033
0.909421
0.900702
0.891857
0.882876
0.87376
0.864514
0.85514
0.845642
0.836022
0.826284
0.81643
0.806465
0.796393
0.786218
0.775943
0.765573
0.755114
0.744569
0.733943
0.723242
0.712472
0.701636
0.690741
0.679793
0.668797
0.65776
0.646687
0.635584
0.624458
0.922025
0.913342
0.904535
0.895605
0.886532
0.877314
0.867952
0.858452
0.848815
0.839044
0.829143
0.819114
0.808962
0.79869
0.788303
0.777804
0.7672
0.756494
0.745692
0.734799
0.723821
0.712764
0.701633
0.690436
0.679178
0.667866
0.656507
0.645108
0.633675
0.622217
0.92929
0.920307
0.911178
0.901941
0.892558
0.883018
0.873322
0.863477
0.853485
0.84335
0.833074
0.822662
0.812117
0.801444
0.790647
0.77973
0.7687
0.757561
0.746318
0.734979
0.723547
0.712031
0.700435
0.688768
0.677036
0.665245
0.653404
0.641519
0.629598
0.617649
0.939892
0.930455
0.920826
0.911117
0.901267
0.891243
0.881049
0.870694
0.86018
0.84951
0.838688
0.827717
0.816602
0.805347
0.793957
0.782436
0.770791
0.759026
0.747148
0.735162
0.723076
0.710895
0.698628
0.686281
0.673861
0.661377
0.648835
0.636245
0.623614
0.610951
0.953571
0.9435
0.933176
0.922816
0.912321
0.901637
0.890766
0.879718
0.868499
0.857112
0.845559
0.833845
0.821973
0.809949
0.797777
0.785463
0.773013
0.760432
0.747726
0.734902
0.721968
0.70893
0.695795
0.682572
0.669269
0.655893
0.642453
0.628958
0.615417
0.601838
0.9704
0.959534
0.948324
0.937139
0.925831
0.914315
0.902591
0.890674
0.878572
0.866285
0.853818
0.841173
0.828357
0.815373
0.802226
0.788923
0.775469
0.761871
0.748134
0.734267
0.720276
0.706169
0.691953
0.677639
0.663233
0.648744
0.634182
0.619557
0.604877
0.590152
0.990378
0.978552
0.966253
0.954058
0.94176
0.929231
0.916469
0.903496
0.89032
0.876942
0.863365
0.849593
0.83563
0.821483
0.807155
0.792654
0.777985
0.763154
0.74817
0.733038
0.717767
0.702365
0.68684
0.671202
0.655459
0.639621
0.623698
0.607699
0.591635
0.575516
1.0136
1.00065
0.987058
0.973663
0.960195
0.946467
0.932478
0.918254
0.903805
0.889133
0.874241
0.859131
0.84381
0.828282
0.812552
0.796628
0.780514
0.764219
0.747749
0.731111
0.714316
0.69737
0.680283
0.663065
0.645724
0.628272
0.610718
0.593074
0.57535
0.557558
1.04014
1.02593
1.01081
0.996024
0.981199
0.96608
0.950662
0.934982
0.919051
0.902871
0.886444
0.869772
0.852862
0.835718
0.818347
0.800754
0.782946
0.764931
0.746715
0.728308
0.709718
0.690954
0.672025
0.652942
0.633715
0.614355
0.594874
0.575282
0.555591
0.535815
1.07009
1.05449
1.03764
1.02125
1.00487
0.988165
0.971111
0.953759
0.936126
0.91821
0.900013
0.881539
0.862793
0.843781
0.824507
0.80498
0.785205
0.76519
0.744945
0.724476
0.703795
0.682909
0.661831
0.64057
0.619138
0.597547
0.57581
0.553938
0.531945
0.509844
1.10356
1.08648
1.06765
1.04945
1.03133
1.01283
0.993922
0.974674
0.955105
0.935213
0.914999
0.894465
0.873619
0.852465
0.83101
0.80926
0.787224
0.764909
0.742325
0.719481
0.696387
0.673054
0.649494
0.625719
0.601741
0.577575
0.553234
0.528733
0.504087
0.479311
1.14067
1.12206
1.10101
1.08078
1.06072
1.04021
1.01923
0.997856
0.97611
0.953991
0.931499
0.908638
0.885413
0.861832
0.837901
0.813628
0.789021
0.76409
0.738846
0.713299
0.687462
0.661347
0.634968
0.608339
0.581477
0.554398
0.527118
0.499656
0.472029
0.444258
1.18155
1.16145
1.13792
1.11543
1.09322
1.07051
1.04723
1.02349
0.999322
0.974724
0.949693
0.924235
0.898355
0.872062
0.845364
0.81827
0.790792
0.762941
0.734729
0.706171
0.677282
0.648078
0.618578
0.5888
0.558765
0.528493
0.498007
0.467331
0.43649
0.405507
1.2264
1.20491
1.17863
1.15363
1.12908
1.10396
1.07817
1.05185
1.02503
0.997723
0.969916
0.941616
0.912835
0.88358
0.853864
0.823699
0.793098
0.762078
0.730656
0.69885
0.666682
0.634175
0.601351
0.568238
0.534862
0.501253
0.467441
0.43346
0.399342
0.365122
1.27536
1.25271
1.22339
1.19563
1.16858
1.14089
1.11241
1.08333
1.0537
1.02351
0.992753
0.961445
0.929597
0.897222
0.864334
0.83095
0.797091
0.762777
0.728033
0.692885
0.657361
0.621492
0.585312
0.548856
0.512162
0.475269
0.438219
0.401055
0.363824
0.326571
1.3285
1.30498
1.27236
1.24167
1.21202
1.18167
1.15043
1.11852
1.08601
1.05288
1.01914
0.984793
0.949861
0.914358
0.878306
0.841727
0.804646
0.767093
0.729101
0.690703
0.651938
0.612847
0.573474
0.533865
0.49407
0.454141
0.414131
0.374098
0.334099
0.294191
1.3856
1.36163
1.32554
1.29187
1.25965
1.22669
1.19276
1.15812
1.12284
1.08691
1.05033
1.01311
0.975265
0.936822
0.897805
0.858241
0.818162
0.777607
0.736615
0.695229
0.653498
0.611472
0.569207
0.526761
0.484195
0.441572
0.39896
0.356427
0.314046
0.271882
1.44609
1.42216
1.38262
1.3461
1.31156
1.27625
1.2399
1.20283
1.16511
1.12671
1.08763
1.04787
1.00747
0.966434
0.924799
0.882596
0.839863
0.796645
0.752987
0.708944
0.66457
0.619928
0.575083
0.530103
0.48506
0.440032
0.395095
0.350332
0.305827
0.261658
1.50888
1.48556
1.44285
1.40391
1.36747
1.33027
1.29199
1.25298
1.2133
1.17291
1.13179
1.08995
1.04741
1.00419
0.960324
0.915847
0.870802
0.825239
0.779213
0.732783
0.686015
0.638979
0.59175
0.544407
0.497035
0.449719
0.402552
0.355626
0.309039
0.26288
1.57234
1.55021
1.50491
1.46421
1.42652
1.38803
1.34841
1.30804
1.26694
1.22505
1.18235
1.13885
1.09455
1.04949
1.0037
0.957226
0.910109
0.862406
0.814181
0.765502
0.716441
0.66708
0.617502
0.567798
0.518062
0.468395
0.418899
0.369681
0.32085
0.272507
1.63431
1.61392
1.56687
1.52523
1.48696
1.44779
1.40741
1.3662
1.32414
1.28115
1.23722
1.19235
1.14656
1.09988
1.05234
1.004
0.954914
0.90514
0.85475
0.803821
0.752436
0.700683
0.648659
0.596465
0.544206
0.491994
0.439946
0.388182
0.336823
0.285984
1.69226
1.67403
1.62617
1.58442
1.54615
1.5068
1.46611
1.42442
1.38169
1.33786
1.29289
1.2468
1.19963
1.1514
1.10216
1.05198
1.00091
0.949031
0.896414
0.843147
0.789323
0.73504
0.680403
0.625527
0.570528
0.515531
0.460665
0.406063
0.351863
0.298187
1.74351
1.72765
1.67988
1.63866
1.60078
1.56155
1.52079
1.47881
1.43555
1.39094
1.34499
1.29771
1.24915
1.19936
1.14838
1.0963
1.04317
0.989088
0.93413
0.878394
0.821982
0.765002
0.707572
0.649813
0.591858
0.533842
0.475908
0.418203
0.360875
0.304062
1.78541
1.77192
1.72492
1.68462
1.64728
1.60828
1.56749
1.52522
1.48139
1.43598
1.38898
1.34045
1.29043
1.23899
1.18618
1.13208
1.07678
1.02037
0.962933
0.904581
0.845425
0.785583
0.725183
0.66436
0.603256
0.542021
0.480809
0.419781
0.3591
0.298913
1.81555
1.80424
1.75836
1.71906
1.68217
1.64328
1.60236
1.55967
1.51516
1.46881
1.42066
1.37075
1.31915
1.26592
1.21114
1.1549
1.09728
1.03839
0.97832
0.917194
0.85513
0.79226
0.728721
0.664661
0.600236
0.535607
0.470942
0.406416
0.342205
0.278468
1.8319
1.82248
1.77785
1.73936
1.70267
1.66364
1.62235
1.57902
1.53361
1.48613
1.43662
1.38514
1.33177
1.27657
1.21963
1.16105
1.10092
1.03935
0.976457
0.912361
0.847195
0.781104
0.714237
0.646755
0.578827
0.510629
0.442343
0.374157
0.306261
0.238826
1.83179
1.82416
1.7808
1.74283
1.70594
1.66641
1.62438
1.58007
1.53344
1.48453
1.43339
1.38009
1.32469
1.26729
1.20797
1.14683
1.08397
1.01952
0.953593
0.88633
0.817872
0.748375
0.678003
0.606931
0.53534
0.463422
0.391373
0.319398
0.247701
0.176463
1.8115
1.80421
1.76143
1.72345
1.68601
1.64578
1.60291
1.55756
1.50971
1.45936
1.40659
1.35145
1.29401
1.23436
1.1726
1.10883
1.04316
0.975723
0.906648
0.836084
0.76419
0.691136
0.617101
0.542277
0.466864
0.39107
0.315111
0.239209
0.163587
0.0884418
1.78639
1.77578
1.73172
1.69268
1.65395
1.61248
1.56832
1.52151
1.47197
1.41972
1.3648
1.30727
1.2472
1.18468
1.11982
1.05272
0.983516
0.912347
0.839363
0.764727
0.688618
0.611223
0.532744
0.453393
0.373392
0.292972
0.212368
0.131828
0.0515941
-0.0281187
1.7598
1.74473
1.70003
1.6589
1.61664
1.57145
1.52353
1.47287
1.41945
1.36326
1.30433
1.24272
1.17848
1.11171
1.0425
0.970961
0.897235
0.821462
0.743802
0.664427
0.583525
0.501296
0.417953
0.33372
0.248831
0.163528
0.0780597
-0.00731649
-0.0923441
-0.176801
0.613315
0.602161
0.591003
0.579847
0.5687
0.557567
0.546457
0.535374
0.524326
0.513319
0.502359
0.491453
0.480607
0.469827
0.459119
0.448489
0.437943
0.427487
0.417126
0.406866
0.396712
0.38667
0.376743
0.366938
0.357258
0.347709
0.338293
0.329016
0.319878
0.310882
0.610739
0.59925
0.587756
0.576265
0.564785
0.553323
0.541887
0.530483
0.519119
0.507802
0.49654
0.48534
0.474208
0.463151
0.452177
0.441291
0.430501
0.419811
0.409229
0.39876
0.388409
0.378181
0.368082
0.358117
0.348289
0.338603
0.329063
0.319674
0.310434
0.301333
0.60568
0.593697
0.58171
0.569726
0.557752
0.545797
0.53387
0.521977
0.510126
0.498326
0.486584
0.474907
0.463304
0.451781
0.440345
0.429003
0.417763
0.406631
0.395612
0.384714
0.373942
0.363301
0.352797
0.342435
0.33222
0.322156
0.312248
0.3025
0.292909
0.283443
0.598264
0.585561
0.572852
0.560144
0.547447
0.53477
0.52212
0.509507
0.496939
0.484425
0.471973
0.459592
0.447289
0.435073
0.422952
0.410932
0.399022
0.387228
0.375558
0.364018
0.352615
0.341353
0.33024
0.319281
0.30848
0.297843
0.287374
0.277081
0.266951
0.25693
0.588231
0.574605
0.560968
0.547332
0.533704
0.520095
0.506514
0.492971
0.479473
0.466032
0.452656
0.439355
0.426136
0.413009
0.399983
0.387065
0.374264
0.361587
0.349043
0.336638
0.32438
0.312275
0.30033
0.28855
0.276941
0.265509
0.254261
0.243203
0.232316
0.221524
0.575392
0.560608
0.545808
0.531004
0.516205
0.501423
0.486666
0.471947
0.457273
0.442657
0.428108
0.413636
0.399251
0.384961
0.370778
0.35671
0.342767
0.328956
0.315286
0.301767
0.288405
0.275209
0.262185
0.249342
0.236685
0.224221
0.211958
0.199903
0.188024
0.176262
0.559353
0.543157
0.526938
0.510707
0.494477
0.478257
0.46206
0.445896
0.429777
0.413714
0.397717
0.381798
0.365968
0.350237
0.334616
0.319116
0.303746
0.288516
0.273436
0.258516
0.243765
0.229192
0.214806
0.200615
0.186628
0.172852
0.159299
0.145967
0.132802
0.119861
0.539709
0.521814
0.503886
0.485936
0.467977
0.450021
0.43208
0.414166
0.396292
0.37847
0.360712
0.34303
0.325436
0.307942
0.29056
0.273302
0.256179
0.239202
0.222383
0.205732
0.189261
0.172979
0.156898
0.141027
0.125377
0.10996
0.0947906
0.0798399
0.0650059
0.0506898
0.515965
0.496054
0.476094
0.456099
0.436082
0.416056
0.396036
0.376034
0.356064
0.33614
0.316274
0.296482
0.276775
0.257167
0.237672
0.218302
0.199071
0.179991
0.161075
0.142336
0.123786
0.105437
0.0873013
0.0693906
0.051717
0.0342991
0.0171535
0.000195759
-0.0167851
-0.0326207
0.48765
0.465375
0.443035
0.420644
0.398217
0.375769
0.353315
0.330871
0.308451
0.286071
0.263747
0.241493
0.219325
0.197258
0.175307
0.153487
0.131813
0.1103
0.0889614
0.0678119
0.0468655
0.026136
0.00563689
-0.0146194
-0.0346194
-0.0543365
-0.073748
-0.0930471
-0.112648
-0.12997
0.454421
0.429434
0.404366
0.379234
0.354057
0.328852
0.303637
0.278429
0.253247
0.22811
0.203034
0.17804
0.153144
0.128365
0.10372
0.0792275
0.0549042
0.0307672
0.00683302
-0.0168821
-0.0403626
-0.0635931
-0.0865593
-0.109249
-0.131647
-0.153715
-0.175426
-0.197149
-0.21962
-0.238015
0.416361
0.38836
0.360276
0.33213
0.303944
0.275742
0.247544
0.219375
0.191257
0.163213
0.135266
0.107439
0.0797535
0.0522328
0.0248982
-0.00222902
-0.0291283
-0.0557799
-0.0821648
-0.108265
-0.134064
-0.159544
-0.184693
-0.2095
-0.233949
-0.257987
-0.28158
-0.305364
-0.330483
-0.348992
0.374409
0.343225
0.311984
0.280713
0.249441
0.218199
0.187017
0.155923
0.124948
0.0941225
0.0634751
0.0330349
0.0028301
-0.0271121
-0.0567655
-0.0861051
-0.115107
-0.14375
-0.172014
-0.19988
-0.227332
-0.254356
-0.280941
-0.30708
-0.332763
-0.357909
-0.38249
-0.407497
-0.434473
-0.451648
0.33083
0.296514
0.262208
0.227951
0.19378
0.159736
0.125857
0.0921823
0.0587508
0.0255996
-0.00723473
-0.0397172
-0.0718145
-0.103495
-0.13473
-0.165494
-0.195761
-0.225512
-0.254729
-0.283398
-0.311506
-0.339047
-0.366014
-0.392412
-0.418229
-0.443353
-0.467768
-0.492875
-0.520462
-0.5347
0.289333
0.252179
0.215152
0.1783
0.141673
0.10532
0.0692916
0.0336341
-0.00160573
-0.0363838
-0.0706584
-0.104391
-0.137546
-0.170091
-0.202
-0.233249
-0.263819
-0.293696
-0.32287
-0.351336
-0.379092
-0.406138
-0.432478
-0.458123
-0.483052
-0.507105
-0.530282
-0.554381
-0.581143
-0.591128
0.254422
0.21488
0.175619
0.136695
0.0981684
0.0600995
0.0225454
-0.0144393
-0.0508032
-0.0864985
-0.121482
-0.155716
-0.189167
-0.221809
-0.253622
-0.28459
-0.314706
-0.343968
-0.372377
-0.39994
-0.426664
-0.452556
-0.477622
-0.501874
-0.525261
-0.547555
-0.568776
-0.591031
-0.615697
-0.620699
0.229993
0.188488
0.14743
0.106882
0.0669141
0.0275943
-0.0110142
-0.0488523
-0.0858665
-0.122009
-0.15724
-0.191525
-0.224841
-0.257169
-0.288501
-0.318835
-0.348177
-0.376539
-0.403933
-0.430377
-0.455881
-0.48045
-0.504085
-0.526777
-0.548432
-0.568736
-0.587738
-0.607769
-0.629624
-0.629594
0.217888
0.17465
0.132011
0.0900438
0.0488258
0.00843142
-0.0310714
-0.0696218
-0.107166
-0.143661
-0.17907
-0.213369
-0.246543
-0.278587
-0.309506
-0.339312
-0.368023
-0.395662
-0.42225
-0.447805
-0.472336
-0.495834
-0.518282
-0.539645
-0.55977
-0.578261
-0.595224
-0.613223
-0.632413
-0.62794
0.21722
0.172214
0.127934
0.0844603
0.0418793
0.000270876
-0.0402937
-0.0797525
-0.118054
-0.155158
-0.191035
-0.225671
-0.259059
-0.291209
-0.322135
-0.351861
-0.380414
-0.407822
-0.434107
-0.459283
-0.483344
-0.506266
-0.528011
-0.548522
-0.567594
-0.584756
-0.600235
-0.616954
-0.634538
-0.626669
0.224735
0.177706
0.1315
0.0862062
0.0419187
-0.00127673
-0.0433056
-0.0841048
-0.123624
-0.161827
-0.198691
-0.234208
-0.26838
-0.301225
-0.332764
-0.363029
-0.392047
-0.419847
-0.446445
-0.471846
-0.496029
-0.518955
-0.540576
-0.560832
-0.579484
-0.596003
-0.610789
-0.62735
-0.644975
-0.634906
0.235757
0.186335
0.137804
0.0902624
0.0438133
-0.00145176
-0.0454539
-0.0881284
-0.129425
-0.169309
-0.207761
-0.244776
-0.280363
-0.31454
-0.347334
-0.378773
-0.408885
-0.43769
-0.4652
-0.491408
-0.516286
-0.539785
-0.561869
-0.582499
-0.601425
-0.618056
-0.632998
-0.650583
-0.669983
-0.658707
0.245143
0.19294
0.141671
0.0914464
0.0423767
-0.0054393
-0.0519178
-0.0969905
-0.140605
-0.182726
-0.223334
-0.262425
-0.300005
-0.336093
-0.370711
-0.403885
-0.435636
-0.465978
-0.494916
-0.522438
-0.548514
-0.573102
-0.59619
-0.617787
-0.637647
-0.655093
-0.670928
-0.690527
-0.713145
-0.701258
0.247882
0.19256
0.138199
0.0849193
0.03284
-0.0179322
-0.0673074
-0.115212
-0.16159
-0.206401
-0.249625
-0.29125
-0.331283
-0.369734
-0.406622
-0.441964
-0.475776
-0.508067
-0.538838
-0.568079
-0.595768
-0.621874
-0.646424
-0.66949
-0.690837
-0.709661
-0.726923
-0.749216
-0.776075
-0.763792
0.23935
0.180655
0.122938
0.0663279
0.0109562
-0.0430634
-0.0956333
-0.146674
-0.196122
-0.243934
-0.290081
-0.334549
-0.377334
-0.418443
-0.457887
-0.495677
-0.531824
-0.566334
-0.599211
-0.630453
-0.660049
-0.687988
-0.714333
-0.739231
-0.762463
-0.783054
-0.802055
-0.827405
-0.859119
-0.846359
0.215345
0.1531
0.0918475
0.0317317
-0.0271077
-0.0845479
-0.140483
-0.194825
-0.247506
-0.298471
-0.347687
-0.395132
-0.440797
-0.48468
-0.526787
-0.567126
-0.605705
-0.642534
-0.677621
-0.71098
-0.742615
-0.772536
-0.80084
-0.827749
-0.85307
-0.875626
-0.896454
-0.924884
-0.961597
-0.947948
0.172004
0.106078
0.0411706
-0.0225618
-0.0849687
-0.145917
-0.205292
-0.262997
-0.318953
-0.3731
-0.425396
-0.47581
-0.524328
-0.570943
-0.615655
-0.658472
-0.699404
-0.738465
-0.775678
-0.81107
-0.844671
-0.876507
-0.906697
-0.935525
-0.962849
-0.987271
-1.00964
-1.04057
-1.08167
-1.06634
0.10585
0.0361656
-0.0324587
-0.0998536
-0.165857
-0.230324
-0.293129
-0.354167
-0.413348
-0.470605
-0.525885
-0.579152
-0.630383
-0.679568
-0.726704
-0.771799
-0.814867
-0.855928
-0.895015
-0.932171
-0.967441
-1.00086
-1.03254
-1.06278
-1.09152
-1.11721
-1.14026
-1.17223
-1.21638
-1.19919
0.0139528
-0.0595497
-0.131923
-0.202982
-0.272549
-0.340466
-0.406595
-0.470818
-0.533034
-0.593165
-0.651149
-0.706941
-0.760512
-0.811845
-0.860935
-0.907788
-0.952421
-0.994859
-1.03514
-1.07331
-1.10943
-1.14355
-1.17574
-1.20632
-1.2354
-1.26159
-1.28482
-1.31683
-1.36372
-1.34815
-0.107114
-0.18503
-0.261713
-0.336958
-0.41057
-0.482376
-0.552222
-0.619976
-0.685523
-0.74877
-0.809644
-0.868087
-0.924058
-0.977533
-1.0285
-1.07695
-1.12291
-1.16639
-1.20743
-1.24609
-1.28243
-1.31656
-1.34857
-1.37876
-1.40754
-1.43427
-1.45865
-1.49048
-1.53789
-1.52566
-0.260493
-0.34303
-0.424262
-0.503972
-0.581958
-0.65804
-0.732059
-0.803872
-0.873361
-0.940426
-1.00498
-1.06697
-1.12635
-1.18308
-1.23715
-1.28855
-1.33729
-1.3834
-1.42691
-1.46786
-1.50632
-1.54237
-1.57609
-1.60761
-1.63714
-1.66454
-1.68924
-1.71458
-1.74072
-1.70556
0.284163
0.242872
0.204583
0.169924
0.139421
0.113453
0.0921969
0.0755941
0.0633497
0.0549708
0.0498204
0.0471777
0.046302
0.0464952
0.0471536
0.047799
0.0480914
0.0478245
0.0469074
0.0453405
0.0431897
0.0405604
0.0375768
0.0343655
0.0310448
0.0277176
0.0244687
0.0213637
0.0184501
0.0157593
0.0133085
0.0111028
0.0091383
0.00740158
0.00587713
0.00453408
0.00335861
0.00228609
0.00134462
0.00036333
0.27388
0.232301
0.194087
0.159626
0.129465
0.104034
0.0835085
0.0677754
0.0564808
0.0490793
0.0448874
0.0431437
0.0430764
0.0439687
0.0452095
0.0463237
0.0469816
0.0469909
0.0462769
0.0448563
0.0428094
0.0402533
0.0373217
0.0341487
0.0308571
0.0275534
0.0243245
0.0212373
0.0183397
0.0156638
0.0132267
0.0110335
0.00908051
0.00735421
0.00583929
0.00450441
0.00333687
0.0022705
0.00133718
0.000359493
0.254313
0.212162
0.174135
0.14009
0.110616
0.0862576
0.0671659
0.0531228
0.0436582
0.038126
0.0357547
0.0357073
0.0371555
0.0393499
0.0416695
0.0436469
0.0449733
0.0454852
0.0451394
0.0439827
0.0421219
0.0396969
0.0368587
0.0337539
0.0305147
0.0272534
0.0240607
0.0210055
0.0181373
0.0154885
0.0130766
0.0109064
0.00897453
0.00726736
0.00576971
0.00444998
0.00329674
0.00224243
0.00132232
0.000353371
0.225424
0.182631
0.14504
0.111733
0.0833906
0.0607251
0.0438365
0.0323367
0.0255847
0.0227904
0.0230563
0.0254393
0.0290361
0.033058
0.0368762
0.040041
0.042279
0.0434706
0.0436183
0.0428126
0.0411985
0.0389464
0.036231
0.0332165
0.0300469
0.0268423
0.0236984
0.0206869
0.0178591
0.0152475
0.01287
0.0107316
0.00882879
0.00714788
0.00567396
0.0043752
0.00324149
0.00220397
0.00130138
0.000345495
0.186906
0.143536
0.106771
0.0746419
0.0480056
0.0277855
0.0139751
0.00594355
0.00282683
0.00364885
0.00734918
0.0128536
0.0191728
0.0254794
0.0311471
0.03576
0.0390966
0.0410977
0.0418271
0.0414316
0.0401034
0.0380509
0.0354775
0.0325676
0.0294794
0.026342
0.0232565
0.0202981
0.0175191
0.0149529
0.0126175
0.0105179
0.00865072
0.00700187
0.00555696
0.00428392
0.00317402
0.00215706
0.00127556
0.000336245
0.13809
0.0944198
0.0589897
0.0286264
0.00445778
-0.0123852
-0.0221039
-0.0256431
-0.0241373
-0.0187916
-0.0108647
-0.00158137
0.00798098
0.0169674
0.0247726
0.0310342
0.0356035
0.0385009
0.0398666
0.0399146
0.038893
0.0370535
0.0346317
0.0318344
0.0288347
0.0257715
0.0227516
0.019853
0.0171297
0.0146154
0.0123283
0.0102732
0.00844679
0.00683472
0.00542307
0.00417951
0.00309679
0.00210345
0.00124582
0.000325971
0.0783666
0.0348269
0.00123504
-0.02663
-0.0473299
-0.0596603
-0.064132
-0.0620518
-0.0548653
-0.044056
-0.0311163
-0.0174311
-0.00415666
0.00784433
0.0180127
0.0260668
0.0319549
0.0357961
0.0378221
0.0383248
0.0376145
0.0359904
0.033722
0.0310397
0.028132
0.0251474
0.0221978
0.0193641
0.0167016
0.0142444
0.0120104
0.0100043
0.0082227
0.00665111
0.00527604
0.0040649
0.00301196
0.00204468
0.001213
0.000314973
0.00767344
-0.0353175
-0.0668507
-0.0913482
-0.1073
-0.113803
-0.111772
-0.102869
-0.0888931
-0.0716671
-0.0529486
-0.0342829
-0.0168864
-0.00160003
0.0110964
0.0210332
0.0282815
0.0330794
0.0357639
0.0367137
0.0363063
0.0348907
0.0327715
0.0302026
0.0273876
0.0244834
0.0216071
0.0188421
0.0162441
0.0138477
0.0116706
0.00971695
0.00798336
0.00645509
0.00511909
0.00394262
0.00292143
0.00198207
0.00117783
0.000303496
-0.0726326
-0.115095
-0.145031
-0.165199
-0.174904
-0.174223
-0.164451
-0.147525
-0.125662
-0.101102
-0.0758943
-0.051737
-0.0298799
-0.0111062
0.00422184
0.0160802
0.0246899
0.0304274
0.0337471
0.0351212
0.0349981
0.0337775
0.0317989
0.0293388
0.0266146
0.0237913
0.0209899
0.0182958
0.0157652
0.0134325
0.0113148
0.00941625
0.00773299
0.00625012
0.00495501
0.00381486
0.0028268
0.00191673
0.00114093
0.000291744
-0.158875
-0.201915
-0.231705
-0.246594
-0.248625
-0.239664
-0.221136
-0.195143
-0.164431
-0.131746
-0.0994541
-0.0693963
-0.0428305
-0.0204444
-0.00244355
0.0113271
0.0212639
0.0278985
0.0318125
0.0335768
0.033712
0.0326683
0.0308186
0.0284606
0.025824
0.0230806
0.0203548
0.017733
0.0152716
0.0130044
0.0109482
0.00910651
0.0074752
0.00603916
0.00478619
0.00368348
0.00272947
0.00184963
0.00110283
0.000279882
-0.24475
-0.29117
-0.323063
-0.33196
-0.325544
-0.307912
-0.28012
-0.244407
-0.204206
-0.162859
-0.123079
-0.0868602
-0.0554513
-0.0294132
-0.00876145
0.00686731
0.0180659
0.0255343
0.0299888
0.0321012
0.0324639
0.0315759
0.0298417
0.0275777
0.0250245
0.0223594
0.0197089
0.0171601
0.014769
0.0125686
0.0105751
0.00879139
0.00721304
0.00582472
0.00461464
0.00355005
0.00263057
0.00178157
0.00106399
0.000268043
-0.322394
-0.376698
-0.412802
-0.415589
-0.401318
-0.375725
-0.338948
-0.293516
-0.243719
-0.193564
-0.14617
-0.103725
-0.0674752
-0.0378396
-0.0146216
0.00276976
0.0151386
0.0233621
0.0282941
0.0307072
0.031264
0.0305093
0.0288762
0.0266977
0.0242233
0.0216342
0.0190583
0.0165826
0.0142622
0.0121292
0.0101991
0.00847399
0.0069491
0.00560892
0.00444205
0.00341589
0.00253109
0.0017132
0.00102477
0.000256338
-0.384744
-0.452061
-0.493013
-0.490644
-0.470858
-0.439188
-0.394629
-0.340323
-0.281502
-0.222884
-0.168096
-0.119595
-0.0786606
-0.0455795
-0.019941
-0.000918742
0.0125082
0.0213965
0.0267375
0.0294017
0.0301182
0.0294742
0.0279279
0.0258264
0.0234259
0.0209103
0.018408
0.0160049
0.0137552
0.0116898
0.00982327
0.00815689
0.00668553
0.00539352
0.00426982
0.00328208
0.00243183
0.0016451
0.00098552
0.00024485
-0.427853
-0.512127
-0.556373
-0.551192
-0.52956
-0.494467
-0.444154
-0.382654
-0.31606
-0.24984
-0.188246
-0.134106
-0.0887992
-0.0525203
-0.024662
-0.00417107
0.0101863
0.0196424
0.0253213
0.0281868
0.0290293
0.0284741
0.0270009
0.0249682
0.0226369
0.0201923
0.017762
0.0154308
0.0132514
0.0112534
0.00945012
0.00784221
0.00642409
0.00517999
0.00409913
0.00314955
0.00233348
0.00157771
0.000946499
0.000233645
-0.45175
-0.554383
-0.598707
-0.594207
-0.574504
-0.538714
-0.485141
-0.418694
-0.346097
-0.273568
-0.206084
-0.146949
-0.0977272
-0.0585827
-0.0287517
-0.00697736
0.0081728
0.0180965
0.0240425
0.0270608
0.0279974
0.0275105
0.0260979
0.0241264
0.0218598
0.0194835
0.0171238
0.0148635
0.0127536
0.0108223
0.00908175
0.00753173
0.00616626
0.0049695
0.00393092
0.00301901
0.00223657
0.00151141
0.000907937
0.000222774
-0.459831
-0.579682
-0.620501
-0.620292
-0.605002
-0.570666
-0.516289
-0.447289
-0.370699
-0.29343
-0.221211
-0.1579
-0.105333
-0.0637214
-0.0321996
-0.00934254
0.00645793
0.0167496
0.0228943
0.02602
0.0270212
0.0265841
0.0252206
0.0233033
0.0210974
0.0187868
0.0164959
0.0143054
0.0122641
0.0103985
0.00871983
0.00722686
0.00591322
0.00476304
0.00376598
0.00289108
0.00214155
0.00144651
0.000870019
0.000212268
-0.457746
-0.59212
-0.626352
-0.632778
-0.622332
-0.5907
-0.537471
-0.468047
-0.389429
-0.309073
-0.233395
-0.16683
-0.111562
-0.0679253
-0.0350155
-0.0112836
0.00502499
0.0155881
0.0218676
0.0250588
0.0260981
0.0256943
0.0243699
0.0225008
0.0203518
0.0181046
0.0158808
0.0137586
0.0117846
0.0099837
0.00836573
0.00692875
0.00566591
0.00456136
0.00360491
0.00276621
0.00204878
0.00138322
0.000832894
0.000202153
-0.452303
-0.597793
-0.622771
-0.636016
-0.628968
-0.600389
-0.549483
-0.48125
-0.402311
-0.320439
-0.242577
-0.173711
-0.116414
-0.0712139
-0.0372261
-0.0128266
0.0038524
0.0145964
0.0209519
0.0241712
0.0252253
0.0248405
0.0235465
0.0217203
0.0196247
0.0174385
0.0152801
0.0132246
0.0113166
0.00957904
0.00802051
0.00663828
0.00542508
0.00436507
0.00344818
0.00264477
0.00195852
0.00132174
0.000796683
0.000192441
-0.45026
-0.60286
-0.615804
-0.633975
-0.62779
-0.601886
-0.553677
-0.48767
-0.409742
-0.327718
-0.248851
-0.178604
-0.119941
-0.0736332
-0.0388716
-0.0140042
0.00291563
0.0137573
0.020136
0.0233507
0.0243994
0.0240214
0.0227504
0.0209625
0.0189173
0.0167899
0.0146951
0.0127048
0.0108613
0.00918552
0.00768501
0.00635616
0.00519128
0.00417461
0.00329615
0.00252702
0.00187098
0.0012622
0.00076148
0.000183137
-0.457148
-0.611963
-0.609788
-0.62968
-0.621549
-0.597421
-0.551636
-0.488361
-0.412369
-0.331288
-0.252435
-0.181641
-0.122233
-0.0752492
-0.0400015
-0.0148528
0.00218891
0.0130535
0.0194092
0.022591
0.0236173
0.0232359
0.0219816
0.020228
0.0182306
0.01616
0.0141269
0.0122002
0.0104194
0.00880389
0.00735984
0.00608288
0.00496494
0.00399031
0.00314907
0.00241317
0.00178632
0.00120468
0.000727356
0.000174242
-0.476648
-0.627753
-0.607332
-0.625274
-0.612597
-0.58901
-0.544949
-0.484491
-0.410974
-0.331642
-0.253628
-0.183008
-0.123408
-0.0761415
-0.0406708
-0.0154107
0.00164652
0.0124683
0.0187611
0.021886
0.0228757
0.0224825
0.0212399
0.0195174
0.0175653
0.0155494
0.0135763
0.0117113
0.0099916
0.00843467
0.00704543
0.00581881
0.00474632
0.0038124
0.00300713
0.00230334
0.00170462
0.00114926
0.000694361
0.000165752
-0.510779
-0.651327
-0.609874
-0.62224
-0.602793
-0.578336
-0.535078
-0.477208
-0.406381
-0.329326
-0.252778
-0.18292
-0.123601
-0.0763975
-0.0409369
-0.0157155
0.00126392
0.0119863
0.0181823
0.0212304
0.0221719
0.02176
0.0205249
0.0188306
0.0169217
0.0149587
0.0130438
0.0112388
0.00957833
0.0080782
0.00674209
0.00556417
0.00453562
0.00364101
0.00287042
0.00219761
0.00162595
0.00109596
0.000662532
0.000157657
-0.560516
-0.682923
-0.61818
-0.621574
-0.593508
-0.566737
-0.523295
-0.46757
-0.399391
-0.324899
-0.250247
-0.181607
-0.122956
-0.0761066
-0.0408563
-0.0158029
0.00101884
0.0115937
0.0176648
0.0206197
0.0215035
0.0210674
0.0198365
0.018168
0.0163003
0.0143884
0.0125298
0.0107829
0.00917988
0.00773474
0.00644998
0.00531911
0.00433293
0.00347621
0.002739
0.00209602
0.00155033
0.00104479
0.000631889
0.000149949
-0.626112
-0.72223
-0.632467
-0.62381
-0.58563
-0.55521
-0.510647
-0.456506
-0.390747
-0.318899
-0.246398
-0.179298
-0.121615
-0.0753564
-0.0404822
-0.0157051
0.000892055
0.0112793
0.0172021
0.0200504
0.0208689
0.0204042
0.0191745
0.0175297
0.0157014
0.0138387
0.0120346
0.010344
0.00879643
0.00740442
0.00616922
0.00508367
0.0041383
0.00331802
0.00261288
0.00199856
0.00147779
0.000995754
0.000602444
0.000142614
-0.706712
-0.76816
-0.652195
-0.628848
-0.579453
-0.544302
-0.49784
-0.444718
-0.381059
-0.311791
-0.241557
-0.176208
-0.119712
-0.0742281
-0.0398641
-0.0154525
0.000864519
0.0110311
0.0167864
0.0195174
0.0202647
0.0197679
0.0185373
0.0169146
0.0151241
0.013309
0.0115577
0.00992152
0.00842769
0.00708698
0.00589958
0.0048577
0.00395157
0.00316634
0.00249198
0.00190516
0.00140826
0.000948812
0.000574189
0.000135638
-0.800997
-0.819461
-0.676393
-0.636117
-0.574743
-0.534079
-0.485156
-0.432575
-0.370704
-0.303891
-0.235958
-0.172497
-0.117352
-0.0727912
-0.0390499
-0.0150801
0.000909422
0.0108279
0.0164012
0.019008
0.019681
0.0191512
0.0179193
0.0163183
0.0145651
0.0127967
0.011097
0.00951397
0.00807235
0.00678141
0.0056403
0.00464059
0.0037723
0.00302081
0.00237604
0.00181566
0.00134164
0.000903888
0.000547092
0.000128997
-0.912636
-0.878679
-0.706305
-0.646465
-0.572212
-0.525245
-0.4733
-0.420715
-0.360214
-0.295601
-0.229883
-0.168347
-0.114649
-0.0711155
-0.0380817
-0.0146131
0.00101201
0.0106617
0.0160426
0.0185206
0.019118
0.0185549
0.0173217
0.0157422
0.0140256
0.012303
0.0106536
0.0091221
0.00773104
0.00648819
0.0053917
0.00443258
0.00360065
0.00288155
0.00226514
0.00173008
0.00127794
0.000860979
0.000521158
0.000122684
-1.05603
-0.955491
-0.748118
-0.664759
-0.576016
-0.521477
-0.465555
-0.411928
-0.351799
-0.28853
-0.224407
-0.164408
-0.11194
-0.069325
-0.0369504
-0.0139685
0.00128745
0.0106535
0.015823
0.0181528
0.0186569
0.0180451
0.0167977
0.0152286
0.0135391
0.0118541
0.0102479
0.00876181
0.00741595
0.00621654
0.00516068
0.00423873
0.00344025
0.0027511
0.00216101
0.00164957
0.00121788
0.000820488
0.000496595
0.000116787
-1.23286
-1.04924
-0.800914
-0.691958
-0.587854
-0.525122
-0.464614
-0.408981
-0.347978
-0.284706
-0.220967
-0.16155
-0.109638
-0.0675089
-0.035549
-0.0129438
0.00196529
0.0110202
0.0159288
0.0180563
0.0184172
0.0177145
0.0164184
0.0148321
0.0131475
0.0114819
0.00990411
0.00845126
0.00714061
0.00597646
0.00495451
0.00406424
0.00329478
0.00263199
0.00206534
0.00157518
0.00116212
0.00078276
0.000473576
0.000111382
-1.35844
-1.10146
-0.818889
-0.69465
-0.580054
-0.513069
-0.450447
-0.395118
-0.335484
-0.27438
-0.212952
-0.155734
-0.105659
-0.0649704
-0.0340765
-0.0122394
0.00213315
0.0108251
0.0155018
0.0174938
0.0177889
0.0170688
0.0157879
0.0142374
0.0126007
0.0109894
0.00946785
0.0080704
0.00681249
0.00569737
0.00472006
0.00386972
0.0031355
0.00250374
0.00196389
0.00149742
0.00110453
0.00074426
0.00045032
0.000105682
-1.28202
-1.02782
-0.737863
-0.620453
-0.507136
-0.443609
-0.383907
-0.334604
-0.283877
-0.233884
-0.183924
-0.137169
-0.0956149
-0.0611814
-0.0343685
-0.0148295
-0.00146712
0.00702652
0.0119429
0.0143597
0.0151194
0.0148337
0.0139323
0.0127038
0.0113376
0.0099529
0.00862125
0.00738275
0.00625764
0.00525316
0.00436756
0.00359276
0.00292036
0.00233911
0.00183991
0.00140689
0.00104022
0.00070307
0.000426437
9.87474e-05
-1.24839
-1.01509
-0.715806
-0.602537
-0.48761
-0.424955
-0.364969
-0.316707
-0.267524
-0.219872
-0.172524
-0.128465
-0.0893819
-0.0570418
-0.0318522
-0.0134846
-0.000909669
0.00708627
0.0117083
0.0139648
0.0146496
0.0143421
0.0134511
0.012252
0.0109254
0.00958506
0.00829875
0.00710425
0.0060204
0.00505368
0.00420191
0.00345689
0.00281034
0.00225146
0.00177124
0.00135472
0.00100181
0.000677514
0.000411045
9.47073e-05
-1.2366
-1.02125
-0.709666
-0.599536
-0.482163
-0.420438
-0.360156
-0.312426
-0.263281
-0.21568
-0.168282
-0.124359
-0.0856116
-0.0538068
-0.0292531
-0.0115357
0.000449367
0.00795343
0.0121945
0.014174
0.0146698
0.0142421
0.0132812
0.0120473
0.0107092
0.00937221
0.00809822
0.00692099
0.00585676
0.00491038
0.0040785
0.00335221
0.00272288
0.00217971
0.00171345
0.00130965
0.00096788
0.000654458
0.00039687
9.12718e-05
-1.22606
-1.02447
-0.701312
-0.594197
-0.474465
-0.413701
-0.353288
-0.306387
-0.257751
-0.210749
-0.163805
-0.120398
-0.0822151
-0.0510466
-0.0271383
-0.0100262
0.0014387
0.00852583
0.0124549
0.0142152
0.0145677
0.0140542
0.0130488
0.0117982
0.0104618
0.00913741
0.00788233
0.00672704
0.00568573
0.00476198
0.00395161
0.00324514
0.0026338
0.00210687
0.00165493
0.00126411
0.000933655
0.000631249
0.000382615
8.78731e-05
-1.21718
-1.02518
-0.691587
-0.587187
-0.465106
-0.405113
-0.344436
-0.298318
-0.250356
-0.204308
-0.158275
-0.11583
-0.0785765
-0.0482944
-0.0251732
-0.0087248
0.00221492
0.008908
0.0125581
0.0141324
0.0143702
0.0137938
0.0127614
0.0115075
0.0101826
0.00887842
0.00764805
0.00651914
0.00550419
0.00460575
0.00381894
0.00313388
0.00254173
0.00203194
0.001595
0.00121765
0.000898858
0.000607739
0.000368211
8.44773e-05
-1.21116
-1.02493
-0.682281
-0.580191
-0.455862
-0.396518
-0.33551
-0.29009
-0.242762
-0.197679
-0.152606
-0.111183
-0.0749122
-0.0455543
-0.0232411
-0.00746409
0.00295149
0.00925585
0.0126337
0.0140282
0.0141566
0.0135213
0.0124648
0.0112098
0.00989802
0.00861528
0.00741053
0.00630872
0.00532069
0.00444801
0.00368514
0.00302178
0.00244904
0.00195658
0.00153477
0.001171
0.000863947
0.000584181
0.000353786
8.11357e-05
-1.20784
-1.02377
-0.673616
-0.573321
-0.446923
-0.388121
-0.326779
-0.282011
-0.235303
-0.191178
-0.147063
-0.106655
-0.0713507
-0.0428975
-0.0213727
-0.00624997
0.00365503
0.00958091
0.012694
0.013914
0.0139365
0.0132448
0.0121659
0.0109107
0.00961267
0.00835169
0.00717276
0.00609815
0.00513709
0.00429022
0.0035513
0.00290965
0.00235633
0.0018812
0.00147452
0.00112433
0.000829036
0.000560639
0.000339368
7.78598e-05
-1.20687
-1.02166
-0.665588
-0.566474
-0.438218
-0.379817
-0.318136
-0.273966
-0.227872
-0.184718
-0.141591
-0.102219
-0.0678904
-0.0403374
-0.0195886
-0.0051046
0.00430534
0.00986635
0.0127257
0.0137797
0.0137026
0.0129588
0.0118605
0.0106073
0.00932434
0.00808605
0.00693357
0.0058866
0.0049528
0.00413193
0.00341712
0.00279727
0.00226344
0.0018057
0.00141419
0.00107762
0.000794101
0.000537099
0.000324953
7.46447e-05
-1.20798
-1.01868
-0.658261
-0.559656
-0.429785
-0.371618
-0.309599
-0.265956
-0.220462
-0.178281
-0.136168
-0.097858
-0.0645206
-0.0378696
-0.017889
-0.00403042
0.00489904
0.0101088
0.0127258
0.0136228
0.0134527
0.0126617
0.0115474
0.0102984
0.00903221
0.00781773
0.00669248
0.00567367
0.00476751
0.00397294
0.00328244
0.00268453
0.0021703
0.00173003
0.00135375
0.00103083
0.000759126
0.000513552
0.000310535
7.14862e-05
-1.21088
-1.01498
-0.651693
-0.552901
-0.421683
-0.363569
-0.301226
-0.258036
-0.213123
-0.171905
-0.130819
-0.0935847
-0.0612462
-0.0354945
-0.0162719
-0.00302482
0.00543871
0.0103103
0.012696
0.0134445
0.0131877
0.0123541
0.011227
0.00998445
0.00873649
0.00754685
0.00644956
0.00545943
0.00458127
0.00381326
0.00314728
0.00257145
0.00207691
0.00165419
0.00129319
0.00098397
0.000724111
0.000489999
0.000296116
6.83824e-05
-1.21534
-1.0107
-0.645911
-0.546235
-0.41395
-0.355701
-0.293056
-0.250245
-0.205896
-0.165621
-0.125568
-0.0894135
-0.0580749
-0.0332151
-0.0147377
-0.00208677
0.00592583
0.0104726
0.0126376
0.0132457
0.0129085
0.0120366
0.0108996
0.00966564
0.00843737
0.00727357
0.00620493
0.00524395
0.00439414
0.00365294
0.00301166
0.00245803
0.00198329
0.00157819
0.00123253
0.000937037
0.000689058
0.00046644
0.000281695
6.53311e-05
-1.22114
-1.006
-0.640931
-0.53969
-0.406619
-0.348035
-0.285121
-0.242611
-0.198809
-0.159453
-0.120432
-0.0853546
-0.0550124
-0.0310339
-0.0132871
-0.00121611
0.00636093
0.0105961
0.0125511
0.0130271
0.0126152
0.0117093
0.0105655
0.0093421
0.00813492
0.00699792
0.00595862
0.00502726
0.00420613
0.00349199
0.0028756
0.0023443
0.00188944
0.00150204
0.00117175
0.000890029
0.000653974
0.000442871
0.000267273
6.23352e-05
-1.22813
-1.00104
-0.636758
-0.533302
-0.399717
-0.340593
-0.277445
-0.235158
-0.191887
-0.153419
-0.115423
-0.0814163
-0.0520631
-0.0289527
-0.0119206
-0.000412509
0.00674462
0.0106814
0.0124371
0.0127889
0.0123082
0.0113724
0.0102247
0.00901395
0.00782923
0.00671999
0.00571067
0.00480941
0.00401726
0.00333045
0.00273911
0.00223027
0.00179537
0.00142574
0.00111087
0.000842945
0.000618857
0.000419289
0.000252847
5.93919e-05
-1.23618
-0.995989
-0.633392
-0.527111
-0.393266
-0.333397
-0.270055
-0.227908
-0.185152
-0.147538
-0.110555
-0.077606
-0.0492309
-0.026973
-0.0106383
0.000324497
0.00707758
0.0107294
0.0122961
0.0125315
0.0119878
0.0110263
0.00987752
0.0086813
0.00752038
0.00643984
0.00546113
0.00459043
0.00382755
0.00316832
0.0026022
0.00211594
0.00170143
0.00134913
0.00105022
0.000796189
0.000583622
0.000395636
0.00023824
5.65905e-05
-1.24519
-0.990982
-0.630828
-0.521161
-0.387288
-0.326468
-0.26297
-0.220883
-0.178624
-0.141825
-0.10584
-0.0739314
-0.046519
-0.0250964
-0.00944132
0.000995031
0.00736038
0.0107402
0.0121289
0.0122556
0.011655
0.0106711
0.00952364
0.00834363
0.00720828
0.00615708
0.00520994
0.00437051
0.0036371
0.0030058
0.0024643
0.00200108
0.0016069
0.00127259
0.000989362
0.000749335
0.0005487
0.000372081
0.000223732
5.3682e-05
-1.2551
-0.986161
-0.629062
-0.5155
-0.381801
-0.319829
-0.256212
-0.214102
-0.172323
-0.136296
-0.101288
-0.0703979
-0.0439315
-0.0233241
-0.00832815
0.0016002
0.00759393
0.0107154
0.0119353
0.0119614
0.011309
0.0103068
0.00916359
0.00800184
0.00689292
0.00587227
0.00495697
0.00414917
0.00344591
0.00284249
0.00232631
0.00188603
0.00151217
0.0011959
0.000928411
0.000702421
0.000513735
0.000348523
0.000209223
5.08091e-05
-1.26588
-0.981655
-0.628093
-0.510173
-0.376823
-0.313502
-0.249798
-0.207583
-0.166264
-0.130964
-0.0969096
-0.0670116
-0.0414706
-0.0216568
-0.00729933
0.00214023
0.00777867
0.0106549
0.0117164
0.0116493
0.0109504
0.00993382
0.00879747
0.00765581
0.00657458
0.00558535
0.00470252
0.00392676
0.00325397
0.00267862
0.00218794
0.00177069
0.00141725
0.00111907
0.000867369
0.00065545
0.000478731
0.000324965
0.000194716
4.79696e-05
-1.27751
-0.977579
-0.627919
-0.505231
-0.372368
-0.307511
-0.243747
-0.201344
-0.160464
-0.125842
-0.0927127
-0.0637775
-0.0391391
-0.0200951
-0.00635474
0.00261565
0.00791524
0.0105595
0.0114726
0.0113197
0.0105796
0.00955232
0.00842541
0.00730563
0.00625332
0.00529636
0.00444661
0.00370329
0.00306126
0.00251419
0.00204919
0.00165506
0.00132214
0.00104212
0.00080624
0.000608422
0.000443696
0.000301402
0.000180209
4.51663e-05
-1.29
-0.974039
-0.628543
-0.50072
-0.368453
-0.301879
-0.238075
-0.195402
-0.154937
-0.120941
-0.0887058
-0.0607004
-0.036939
-0.0186398
-0.00549415
0.00302705
0.0080043
0.0104296
0.0112043
0.0109728
0.0101968
0.0091625
0.00804757
0.00695139
0.00592921
0.00500535
0.00418927
0.0034788
0.00286782
0.00234924
0.00191006
0.00153917
0.00122684
0.000965039
0.000745025
0.000561334
0.000408629
0.000277832
0.000165703
4.2396e-05
-1.30337
-0.971131
-0.62997
-0.496689
-0.365091
-0.296632
-0.232797
-0.189773
-0.149695
-0.116271
-0.0848961
-0.0577846
-0.0348723
-0.0172913
-0.00471739
0.00337493
0.00804642
0.010266
0.010912
0.0106092
0.00980224
0.00876451
0.00766404
0.00659318
0.00560229
0.00471236
0.00393051
0.00325329
0.00267364
0.00218377
0.00177058
0.00142303
0.00113136
0.000887836
0.000683727
0.00051419
0.000373531
0.000254255
0.000151197
3.96559e-05
-1.31763
-0.968941
-0.632209
-0.493183
-0.362296
-0.291794
-0.227929
-0.184473
-0.144751
-0.111844
-0.0812906
-0.0550342
-0.0329409
-0.0160502
-0.00402418
0.00365983
0.00804218
0.0100689
0.0105961
0.010229
0.00939619
0.00835853
0.00727493
0.00623106
0.00527264
0.00441742
0.00367038
0.0030268
0.00247875
0.00201779
0.00163074
0.00130663
0.00103571
0.000810515
0.000622348
0.000466991
0.000338403
0.000230671
0.000136692
3.6943e-05
-1.33282
-0.967547
-0.635272
-0.490247
-0.360083
-0.287388
-0.223485
-0.179518
-0.140118
-0.107669
-0.0778955
-0.0524528
-0.0311462
-0.0149167
-0.00341425
0.00388229
0.00799216
0.0098391
0.0102571
0.00983256
0.00897884
0.00794472
0.00688037
0.00586513
0.00494029
0.00412058
0.00340889
0.00279934
0.00228316
0.00185132
0.00149055
0.00118998
0.000939884
0.000733078
0.000560889
0.000419737
0.000303244
0.000207079
0.000122187
3.42544e-05
-1.34899
-0.967018
-0.639173
-0.487923
-0.358466
-0.283441
-0.219478
-0.174923
-0.135804
-0.103755
-0.0747168
-0.0500439
-0.0294899
-0.0138912
-0.00288728
0.00404285
0.00789692
0.00957694
0.00989522
0.00942023
0.00855042
0.00752321
0.00648044
0.00549544
0.00460531
0.00382187
0.00314608
0.00257093
0.00208688
0.00168437
0.00135003
0.0010731
0.000843892
0.000655528
0.000499353
0.00037243
0.000268056
0.000183479
0.000107682
3.15871e-05
-1.36616
-0.96742
-0.643929
-0.486252
-0.357459
-0.279975
-0.215922
-0.170703
-0.131822
-0.100111
-0.0717598
-0.0478108
-0.027973
-0.0129738
-0.00244293
0.00414202
0.00775699
0.00928291
0.00951095
0.00899227
0.00811113
0.00709416
0.00607526
0.00512207
0.00426773
0.00352132
0.00288196
0.00234159
0.00188994
0.00151695
0.00120917
0.000955982
0.000747738
0.000577868
0.000437742
0.000325071
0.000232837
0.00015987
9.31768e-05
2.89381e-05
-1.38439
-0.968808
-0.649557
-0.485273
-0.357076
-0.277014
-0.212829
-0.166872
-0.128179
-0.0967441
-0.0690295
-0.0457563
-0.0265968
-0.0121648
-0.00208084
0.00418032
0.00757291
0.00895748
0.00910462
0.00854894
0.00766117
0.00665771
0.00566493
0.0047451
0.00392762
0.00321899
0.00261657
0.00211134
0.00169235
0.00134907
0.001068
0.000838639
0.000651425
0.000500101
0.000376057
0.00027766
0.000197589
0.000136252
7.86718e-05
2.63042e-05
-1.40371
-0.971237
-0.656078
-0.485021
-0.35733
-0.274582
-0.210211
-0.163444
-0.124885
-0.0936627
-0.0665305
-0.0438833
-0.0253624
-0.0114643
-0.00180066
0.00415825
0.00734516
0.00860107
0.00867657
0.00809051
0.00720072
0.00621398
0.00524952
0.00436458
0.00358501
0.00291489
0.00234993
0.00188021
0.00149412
0.00118075
0.000926513
0.000721075
0.00055496
0.000422231
0.000314302
0.000230198
0.000162312
0.000112624
6.41665e-05
2.36824e-05
-1.42417
-0.97475
-0.663509
-0.485531
-0.358234
-0.272699
-0.208078
-0.160431
-0.121948
-0.0908738
-0.0642672
-0.0421945
-0.0242707
-0.0108723
-0.00160202
0.00407631
0.00707424
0.00821409
0.00822711
0.0076172
0.00672996
0.00576312
0.00482915
0.00398058
0.00323996
0.00260906
0.00208206
0.0016482
0.00129527
0.00101198
0.000784721
0.000603297
0.000458347
0.000344262
0.000252477
0.000182686
0.000127006
8.89845e-05
4.9661e-05
2.10698e-05
-1.44579
-0.979391
-0.671871
-0.486834
-0.359801
-0.271387
-0.20644
-0.157847
-0.119374
-0.0883838
-0.0622434
-0.0406921
-0.0233224
-0.010389
-0.00148456
0.00393497
0.0067606
0.00779693
0.00775656
0.00712925
0.00624905
0.00530522
0.00440388
0.00359315
0.0028925
0.00230153
0.00181299
0.00141533
0.0010958
0.000842787
0.000642632
0.000485309
0.000361588
0.000266194
0.000190584
0.000135126
9.16712e-05
6.53339e-05
3.5155e-05
1.8463e-05
-1.46861
-0.985199
-0.681184
-0.488961
-0.362043
-0.270666
-0.205307
-0.155701
-0.117172
-0.0861991
-0.0604627
-0.0393785
-0.0225185
-0.0100144
-0.0014479
0.00373469
0.00640469
0.00734995
0.00726519
0.00662687
0.00575816
0.00484041
0.0039738
0.00320237
0.00254269
0.00199234
0.00154274
0.00118162
0.000895745
0.000673174
0.000500254
0.000367115
0.00026469
0.000188031
0.000128624
8.75196e-05
5.6306e-05
4.16714e-05
2.06503e-05
1.58569e-05
-1.4927
-0.992227
-0.691478
-0.491948
-0.364978
-0.270559
-0.204691
-0.154009
-0.115348
-0.084327
-0.0589299
-0.0382568
-0.0218603
-0.00974882
-0.00149183
0.00347592
0.006007
0.00687362
0.0067534
0.00611038
0.00525753
0.00436888
0.00353905
0.00280833
0.00219059
0.00168155
0.00127137
0.000947117
0.000695129
0.000503164
0.000357603
0.000248723
0.000167663
0.000109779
6.66015e-05
3.9874e-05
2.09103e-05
1.79967e-05
6.14909e-06
1.3246e-05
)
;
boundaryField
{
inlet
{
type freestreamPressure;
freestreamValue uniform 0;
supersonic false;
value nonuniform List<scalar>
120
(
0.640615
0.626903
0.612538
0.597451
0.581639
0.565101
0.547835
0.529844
0.511138
0.491739
0.471677
0.450993
0.429744
0.407999
0.385845
0.363385
0.340739
0.318048
0.295473
0.273193
0.251409
0.230342
0.210237
0.191358
0.173997
0.15847
0.14513
0.134371
0.126643
0.122469
0.895038
0.887076
0.879058
0.870987
0.862867
0.8547
0.846488
0.838235
0.829944
0.821617
0.813257
0.804868
0.796452
0.788011
0.779549
0.771069
0.762573
0.754064
0.745544
0.737016
0.728482
0.719945
0.711406
0.702868
0.694332
0.685801
0.677278
0.668769
0.660274
0.651744
1.09661
1.09127
1.08586
1.08034
1.07471
1.06897
1.06314
1.05719
1.05115
1.045
1.03876
1.03241
1.02596
1.01942
1.01278
1.00605
0.999219
0.992302
0.985295
0.978201
0.971022
0.963759
0.956415
0.948993
0.941494
0.933922
0.926278
0.918565
0.910785
0.902942
1.22856
1.22934
1.23069
1.23236
1.23409
1.23565
1.23684
1.23749
1.23747
1.23668
1.23508
1.23263
1.22935
1.22525
1.22039
1.21482
1.20862
1.20186
1.19462
1.18699
1.17903
1.17083
1.16244
1.15395
1.1454
1.13684
1.12833
1.1199
1.1116
1.10343
)
;
}
outlet
{
type freestreamPressure;
freestreamValue uniform 0;
supersonic false;
value nonuniform List<scalar>
120
(
-8.31122e-11
-8.78658e-11
-9.21325e-11
-9.65944e-11
-1.01121e-10
-1.05574e-10
-1.09891e-10
-1.14017e-10
-1.17879e-10
-1.21388e-10
-1.24445e-10
-1.26936e-10
-1.28735e-10
-1.29707e-10
-1.29704e-10
-1.28576e-10
-1.26174e-10
-1.22357e-10
-1.17006e-10
-1.10038e-10
-1.01421e-10
-9.12023e-11
-7.95274e-11
-6.66692e-11
-5.30529e-11
-3.92762e-11
-2.61212e-11
-1.45485e-11
-5.6648e-12
-6.64124e-13
1.12653e-11
8.50051e-12
5.68519e-12
2.86978e-12
5.02867e-14
-2.77718e-12
-5.61415e-12
-8.46197e-12
-1.1322e-11
-1.41956e-11
-1.70839e-11
-1.99878e-11
-2.29083e-11
-2.58462e-11
-2.87967e-11
-3.17608e-11
-3.50239e-11
-3.81068e-11
-4.12152e-11
-4.43486e-11
-4.75012e-11
-5.06731e-11
-5.38637e-11
-5.70724e-11
-6.03005e-11
-6.355e-11
-6.68075e-11
-7.00246e-11
-7.32328e-11
-7.69339e-11
9.99559e-11
9.62762e-11
9.31545e-11
9.00298e-11
8.68672e-11
8.37198e-11
8.0602e-11
7.7511e-11
7.4445e-11
7.14041e-11
6.83882e-11
6.54025e-11
6.24465e-11
5.96154e-11
5.66493e-11
5.37005e-11
5.07682e-11
4.78572e-11
4.49659e-11
4.20931e-11
3.92372e-11
3.6397e-11
3.35707e-11
3.07567e-11
2.79534e-11
2.51591e-11
2.23722e-11
1.95907e-11
1.68106e-11
1.40277e-11
7.83446e-13
6.67145e-12
1.70934e-11
3.06058e-11
4.58825e-11
6.17906e-11
7.74273e-11
9.21205e-11
1.05408e-10
1.17008e-10
1.26783e-10
1.34709e-10
1.40844e-10
1.453e-10
1.48226e-10
1.49787e-10
1.50153e-10
1.49494e-10
1.47967e-10
1.45722e-10
1.42891e-10
1.39592e-10
1.35931e-10
1.31997e-10
1.27866e-10
1.23594e-10
1.19242e-10
1.14963e-10
1.109e-10
1.0629e-10
)
;
}
top
{
type symmetryPlane;
}
bottom
{
type symmetryPlane;
}
cylinder
{
type zeroGradient;
}
frontandback
{
type empty;
}
}
// ************************************************************************* //
| [
"danieler@login3.stampede2.tacc.utexas.edu"
] | danieler@login3.stampede2.tacc.utexas.edu | |
b814edb1a7527cf5507501a1e7039b6879b2d5cc | 03b354385e5ea77e16d563acc6933d2d09bb59c9 | /test/resize/resize_impl_test.cpp | af05f6cdda9c8df96823e4923de7f39c2f9ed72e | [
"WTFPL"
] | permissive | sekrit-twc/zimg | 4588c673a7ec6d0a6dea271c157ffda5e996c658 | 71431815950664f1e11b9ee4e5d4ba23d6d997f1 | refs/heads/master | 2023-08-04T10:15:09.605309 | 2023-07-26T01:19:51 | 2023-07-26T01:20:12 | 23,723,043 | 366 | 82 | WTFPL | 2023-07-24T14:31:08 | 2014-09-06T00:53:50 | C++ | UTF-8 | C++ | false | false | 8,702 | cpp | #include <cmath>
#include "common/cpuinfo.h"
#include "common/pixel.h"
#include "graphengine/filter.h"
#include "resize/filter.h"
#include "resize/resize_impl.h"
#include "gtest/gtest.h"
#include "graphengine/filter_validation.h"
namespace {
void test_case(const zimg::PixelFormat &format, bool horizontal, double scale_factor, double shift, double subwidth_factor, const char * const *expected_sha1)
{
const unsigned src_w = 640;
const unsigned src_h = 480;
const zimg::resize::PointFilter point{};
const zimg::resize::BilinearFilter bilinear{};
const zimg::resize::Spline36Filter spline36{};
const zimg::resize::LanczosFilter lanczos4{ 4 };
const zimg::resize::Filter *resample_filters[] = { &point, &bilinear, &spline36, &lanczos4 };
unsigned sha1_idx = 0;
for (const zimg::resize::Filter *resample_filter : resample_filters) {
SCOPED_TRACE(resample_filter->support());
auto filter = zimg::resize::ResizeImplBuilder{ src_w, src_h, format.type }
.set_horizontal(horizontal)
.set_dst_dim(static_cast<unsigned>(std::lrint(scale_factor * (horizontal ? src_w : src_h))))
.set_depth(format.depth)
.set_filter(resample_filter)
.set_shift(shift)
.set_subwidth(subwidth_factor * (horizontal ? src_w : src_h))
.create();
ASSERT_TRUE(filter);
graphengine::FilterValidation(filter.get(), { src_w, src_h, zimg::pixel_size(format.type) })
.set_input_pixel_format({ format.depth, zimg::pixel_is_float(format.type), format.chroma })
.set_output_pixel_format({ format.depth, zimg::pixel_is_float(format.type), format.chroma })
.set_sha1(0, expected_sha1[sha1_idx++])
.run();
}
}
} // namespace
TEST(ResizeImplTest, test_nop)
{
static const char *expected_sha1_u16[] = {
"8ba35ed1784cb6d7903a9092abefb3d9afd7a683",
"8ba35ed1784cb6d7903a9092abefb3d9afd7a683",
"8ba35ed1784cb6d7903a9092abefb3d9afd7a683",
"8ba35ed1784cb6d7903a9092abefb3d9afd7a683"
};
static const char *expected_sha1_f32[] = {
"483b6bdf608afbf1fba6bbca9657a8ca3822eef1",
"483b6bdf608afbf1fba6bbca9657a8ca3822eef1",
"483b6bdf608afbf1fba6bbca9657a8ca3822eef1",
"483b6bdf608afbf1fba6bbca9657a8ca3822eef1"
};
{
SCOPED_TRACE("word-h");
test_case(zimg::PixelType::WORD, true, 1.0, 0.0, 1.0, expected_sha1_u16);
}
{
SCOPED_TRACE("word-v");
test_case(zimg::PixelType::WORD, false, 1.0, 0.0, 1.0, expected_sha1_u16);
}
{
SCOPED_TRACE("float-h");
test_case(zimg::PixelType::FLOAT, true, 1.0, 0.0, 1.0, expected_sha1_f32);
}
{
SCOPED_TRACE("float-v");
test_case(zimg::PixelType::FLOAT, false, 1.0, 0.0, 1.0, expected_sha1_f32);
}
}
TEST(ResizeImplTest, test_horizontal_up)
{
static const char *expected_sha1_u16[] = {
"9f37efd7adc0570ad9bab87abedea0e83601a207",
"c9f3368bc3a15079abd56df2dd6f0be7f8d92fba",
"2fc694f3e219a1089af15470b426544bbcb38833",
"5d3097e5fc7a7d59f463058f5464aab335176560"
};
static const char *expected_sha1_f32[] = {
"982dbdbb4c8b4d35f4f77fd9107b6a7f306b0a0a",
"13930fc807841314134711dc02097ae51a33dd89",
"a7e24724ab081d7075b229d5aec98369fe8b21f4",
"c0c934c797bec140747421c465ec77d67e3132a6"
};
{
SCOPED_TRACE("word");
test_case(zimg::PixelType::WORD, true, 2.1, 0.0, 1.0, expected_sha1_u16);
}
{
SCOPED_TRACE("float");
test_case(zimg::PixelType::FLOAT, true, 2.1, 0.0, 1.0, expected_sha1_f32);
}
}
TEST(ResizeImplTest, test_horizontal_down)
{
static const char *expected_sha1_u16[] = {
"71c866436f2df395111d43ac1f10fc0dcfd4bd11",
"2ed0eda0e5fdcdb416703344ae190c82a96dfa3f",
"2df4b623345cbc1f50a0829c6697d4c1be9254c6",
"7e915933acfd1c757b5fe93bba226ff78a0c9d9c"
};
static const char *expected_sha1_f32[] = {
"0f09d60179f3b4771dd800c9650dd3acee2b6360",
"0e9af71cb7067663207e6e1ab07a338ecb3db596",
"9559036ba9cb649af0f679520ac652871a5f3b94",
"7cb55ec9b5894c48aabb373ca98026202b5b7be9"
};
{
SCOPED_TRACE("word");
test_case(zimg::PixelType::WORD, true, 1.0 / 2.1, 0.0, 1.0, expected_sha1_u16);
}
{
SCOPED_TRACE("float");
test_case(zimg::PixelType::FLOAT, true, 1.0 / 2.1, 0.0, 1.0, expected_sha1_f32);
}
}
TEST(ResizeImplTest, test_vertical_up)
{
static const char *expected_sha1_u16[] = {
"0ceeec49fef9ff273d1159701b9e2496b0fbb6de",
"dea6c6833de29cd297e9d8dfddcfb7602deb3e2e",
"05d2c85e9f83f36fa54af9e472013c2cb9eb3d7d",
"4d1436afa4de24c26fc12f07dfc1881c5ea20045"
};
static const char *expected_sha1_f32[] = {
"c080343cb22d40e31be08cdada3985099a3bff5c",
"6bd2b845598bc297b7d2dc7ca9c136a40377573d",
"9ccaf807b5a6c88b484dc8187c0fe1108521438d",
"378824fb29098507c59c19c5565d983d9e96a95d"
};
{
SCOPED_TRACE("word");
test_case(zimg::PixelType::WORD, false, 2.1, 0.0, 1.0, expected_sha1_u16);
}
{
SCOPED_TRACE("float");
test_case(zimg::PixelType::FLOAT, false, 2.1, 0.0, 1.0, expected_sha1_f32);
}
}
TEST(ResizeImplTest, test_vertical_down)
{
static const char *expected_sha1_u16[] = {
"abe8cf7a2949798936156d05153c3f736a991d72",
"c7670c929410997adc96615169141ea00829fe65",
"a787c9c11e037a637524150fbe3af5fc90b750b4",
"c6d55c942d03c72ec6f88ff81ee6d70d20d49809"
};
static const char *expected_sha1_f32[] = {
"211cf4deb08dedf90674641baea1f8338da319cd",
"b72f929d4250aa2ff071d4937d2942f90f573b58",
"94d06430d3adc570b65df0de5cf3662e60308a0d",
"7f4266dc8d82d343f24e5370e1fb8f714a0a05d1"
};
{
SCOPED_TRACE("word");
test_case(zimg::PixelType::WORD, false, 1.0 / 2.1, 0.0, 1.0, expected_sha1_u16);
}
{
SCOPED_TRACE("float");
test_case(zimg::PixelType::FLOAT, false, 1.0 / 2.1, 0.0, 1.0, expected_sha1_f32);
}
}
TEST(ResizeImplTest, test_horizontal_padding_bits)
{
zimg::PixelFormat format = zimg::PixelType::WORD;
format.depth = 7;
static const char *expected_sha1_up[] = {
"347ce215408bd64c243e869022a416731ee18800",
"09714bcb863ab71b0820ef50dc2c1590c4c19e85",
"88f23bea4409ec09e11246b142b3ed2dab30a1f9",
"d6eb428faecfe36823e81ad2b72d0a1e69662297"
};
static const char *expected_sha1_down[] = {
"d8c79763c48ba719a2e5ed3465234eebbc628efa",
"50b5ac4f91b969cab79acdf6008fa386b54d0369",
"2a836efb2e60c321d3e1c1983f6b814ea2141f27",
"b5486824a4575bec849cfffec16eceee03c337cb"
};
{
SCOPED_TRACE("up");
test_case(format, true, 2.1, 0.0, 1.0, expected_sha1_up);
}
{
SCOPED_TRACE("down");
test_case(format, true, 1.0 / 2.1, 0.0, 1.0, expected_sha1_down);
}
}
TEST(ResizeImplTest, test_vertical_padding_bits)
{
zimg::PixelFormat format = zimg::PixelType::WORD;
format.depth = 7;
static const char *expected_sha1_up[] = {
"0824364bbd7c22b89b309827709fd2b08a73af7e",
"0a47cfac7a03c958449f27cd1bc8432eeb281b68",
"13dc90a9fad168d60f3bbdd5e3196fb8a2fc1e26",
"da37648e741402a0d9159edc598012ca0ac85d89"
};
static const char *expected_sha1_down[] = {
"d3b1bbeb2c99182738e87e18ecf47bb4cbf4c80a",
"4cb76e447e5b17ac43749c3bb2a32fd486321fe1",
"665f43f90c5e253afc9e89134020274cb47829dd",
"5572cee34dd9d08e3d292c9f0e9be7f1645e9f84"
};
{
SCOPED_TRACE("up");
test_case(format, false, 2.1, 0.0, 1.0, expected_sha1_up);
}
{
SCOPED_TRACE("down");
test_case(format, false, 1.0 / 2.1, 0.0, 1.0, expected_sha1_down);
}
}
TEST(ResizeImplTest, test_horizontal_shift)
{
const double shift = 3.3;
const double subwidth_factor = 0.75;
static const char *expected_sha1_up[] = {
"2bb7dd3279f287f104e095f76153ea02e585d761",
"c7d57dd2ca4044f3371d62e3ffc4f83754e87ac9",
"af402fba042a6e9ca47337424bce547f576a99b3",
"9a764c13e5bb7d05efb6da0aceea01d9ec425fe3"
};
static const char *expected_sha1_down[] = {
"7c644bacfb8559df29f7f26f22c5fbcf86e0071d",
"d27f31b72dee7166e29e645995c1993988e6a5f7",
"008ddf68e679777cdb45fc812f9084914fed28d4",
"de7941b240b2869fba9b618a4408e5e3180c7696"
};
{
SCOPED_TRACE("up");
test_case(zimg::PixelType::FLOAT, false, 2.1, shift, subwidth_factor, expected_sha1_up);
}
{
SCOPED_TRACE("down");
test_case(zimg::PixelType::FLOAT, false, 1.0 / 2.1, shift, subwidth_factor, expected_sha1_down);
}
}
TEST(ResizeImplTest, test_vertical_shift)
{
const double shift = -3.3;
const double subwidth_factor = 1.05;
static const char *expected_sha1_up[] = {
"3946bc1fb25485db67b58bf44cfba6725785f1c3",
"e240ce8b14c6ffab60cdb1fe9f923f03862dc499",
"bef00c22c2aaa7b9bd36ea26a66f5e49dbf66c45",
"74db6b4f83e1fa7ecc7557763e0fe8b3e70839a5"
};
static const char *expected_sha1_down[] = {
"0a4fed4d808564de9837b7b7525974a8d1d80994",
"fdc144f85a6a2bf270f57376167160a3f320ce33",
"bdcca5438cae8a2809445ddff66016755e2dfe88",
"6237a961d5836dc6e03f67eeaa9a218203844f26"
};
{
SCOPED_TRACE("up");
test_case(zimg::PixelType::FLOAT, false, 2.1, shift, subwidth_factor, expected_sha1_up);
}
{
SCOPED_TRACE("down");
test_case(zimg::PixelType::FLOAT, false, 1.0 / 2.1, shift, subwidth_factor, expected_sha1_down);
}
}
| [
"noreply@example.com"
] | noreply@example.com |
b2eb678b8a85da5ed0fdce23576f214a686b7b5f | bffbf5f470459f62ab2e5bc85d5d166c15915b10 | /test/lxtest/tstregex.cpp | a044324ac264a0a11ee53d8005a0ca2031a67b4f | [] | no_license | jeppeter/clibs | b94198228f55965ab0a27c50f56b54f329122b39 | 796d83010173059ebc645e781227cd57f9e80adc | refs/heads/master | 2023-09-03T16:18:57.319591 | 2023-08-30T05:21:03 | 2023-08-30T05:21:03 | 79,635,224 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 8,537 | cpp |
int regexec_handler(int argc, char* argv[], pextargs_state_t parsestate, void* popt)
{
void* preg = NULL;
pargs_options_t pargs = (pargs_options_t) popt;
int argcnt = 0;
int i, j, retlen;
int *pstartpos = NULL, *pendpos = NULL;
int possize = 0;
int ret;
char* pcurstr = NULL;
char* pmatchstr = NULL;
size_t matchsize = 0;
size_t matchlen = 0;
int handled = 0;
argc = argc;
argv = argv;
init_log_verbose(pargs);
if (parsestate->leftargs != NULL) {
while (parsestate->leftargs[argcnt] != NULL) {
argcnt ++;
}
}
if (argcnt < 2) {
ret = -EINVAL;
ERROR_INFO("arg must restr instr...");
goto out;
}
ret = regex_compile(parsestate->leftargs[0], REGEX_NONE, &preg);
if (ret < 0) {
GETERRNO(ret);
ERROR_INFO("can not compile [%s]", parsestate->leftargs[0]);
goto out;
}
for (i = 1; i < argcnt; i++) {
pcurstr = parsestate->leftargs[i];
handled = 0;
try_again:
ret = regex_exec(preg, pcurstr, &pstartpos, &pendpos, &possize);
if (ret < 0) {
GETERRNO(ret);
ERROR_INFO("can not exec [%s] for [%s] error[%d]", pcurstr, parsestate->leftargs[0], ret);
goto out;
}
retlen = ret;
if (retlen > 0) {
fprintf(stdout, "[%s] find [%s]\n", parsestate->leftargs[0], pcurstr);
for (j = 0; j < retlen; j++) {
matchlen = (size_t)(pendpos[j] - pstartpos[j]);
if (matchlen >= matchsize || pmatchstr == NULL) {
if (pmatchstr) {
free(pmatchstr);
}
pmatchstr = NULL;
matchsize = (matchlen + 3);
pmatchstr = (char*) malloc(matchsize);
if (pmatchstr == NULL) {
GETERRNO(ret);
ERROR_INFO("alloc %d error[%d]", matchsize, ret);
goto out;
}
}
memset(pmatchstr, 0 , matchsize);
memcpy(pmatchstr, &(pcurstr[pstartpos[j]]), matchlen);
fprintf(stdout, " [%03d] %s\n", j, pmatchstr);
}
/*we move to the next to find*/
pcurstr = &(pcurstr[pendpos[0]]);
fprintf(stdout, " left[%s]\n", pcurstr);
handled ++;
goto try_again;
} else {
if (handled == 0) {
fprintf(stdout, "[%s] not find in [%s]\n", parsestate->leftargs[0], pcurstr);
}
}
}
ret = 0;
out:
if (pmatchstr != NULL) {
free(pmatchstr);
}
pmatchstr = NULL;
matchsize = 0;
regex_exec(NULL, NULL, &pstartpos, &pendpos, &possize);
regex_compile(NULL, REGEX_NONE, &preg);
SETERRNO(ret);
return ret;
}
int iregexec_handler(int argc, char* argv[], pextargs_state_t parsestate, void* popt)
{
void* preg = NULL;
pargs_options_t pargs = (pargs_options_t) popt;
int argcnt = 0;
int i, j, retlen;
int *pstartpos = NULL, *pendpos = NULL;
int possize = 0;
int ret;
char* pcurstr = NULL;
char* pmatchstr = NULL;
size_t matchsize = 0;
size_t matchlen = 0;
int handled = 0;
char** pplines=NULL;
int lsize=0,llen=0;
argc = argc;
argv = argv;
init_log_verbose(pargs);
if (parsestate->leftargs != NULL) {
while (parsestate->leftargs[argcnt] != NULL) {
argcnt ++;
}
}
if (argcnt < 2 && pargs->m_input == NULL) {
ret = -EINVAL;
ERROR_INFO("arg must restr instr...");
goto out;
}
ret = regex_compile(parsestate->leftargs[0], REGEX_IGNORE_CASE, &preg);
if (ret < 0) {
GETERRNO(ret);
ERROR_INFO("can not compile [%s]", parsestate->leftargs[0]);
goto out;
}
if (argcnt >= 2) {
for (i = 1; i < argcnt; i++) {
pcurstr = parsestate->leftargs[i];
handled = 0;
try_again:
ret = regex_exec(preg, pcurstr, &pstartpos, &pendpos, &possize);
if (ret < 0) {
GETERRNO(ret);
ERROR_INFO("can not exec [%s] for [%s] error[%d]", pcurstr, parsestate->leftargs[0], ret);
goto out;
}
retlen = ret;
if (retlen > 0) {
fprintf(stdout, "[%s] find [%s]\n", parsestate->leftargs[0], pcurstr);
for (j = 0; j < retlen; j++) {
matchlen = (size_t)(pendpos[j] - pstartpos[j]);
if (matchlen >= matchsize || pmatchstr == NULL) {
if (pmatchstr) {
free(pmatchstr);
}
pmatchstr = NULL;
matchsize = (matchlen + 3);
pmatchstr = (char*) malloc(matchsize);
if (pmatchstr == NULL) {
GETERRNO(ret);
ERROR_INFO("alloc %d error[%d]", matchsize, ret);
goto out;
}
}
memset(pmatchstr, 0 , matchsize);
memcpy(pmatchstr, &(pcurstr[pstartpos[j]]), matchlen);
fprintf(stdout, " [%03d] %s\n", j, pmatchstr);
}
/*we move to the next to find*/
pcurstr = &(pcurstr[pendpos[0]]);
fprintf(stdout, " left[%s]\n", pcurstr);
handled ++;
goto try_again;
} else {
if (handled == 0) {
fprintf(stdout, "[%s] not find in [%s]\n", parsestate->leftargs[0], pcurstr);
}
}
}
} else {
ret = read_file_lines(pargs->m_input, &pplines,&lsize);
if (ret < 0) {
GETERRNO(ret);
fprintf(stderr, "can not read [%s] error[%d]\n", pargs->m_input, ret);
goto out;
}
llen = ret;
for (i=0;i<llen;i++) {
pcurstr = pplines[i];
handled = 0;
file_try_again:
ret = regex_exec(preg, pcurstr, &pstartpos, &pendpos, &possize);
if (ret < 0) {
GETERRNO(ret);
ERROR_INFO("can not exec [%s] for [%s] error[%d]", pcurstr, parsestate->leftargs[0], ret);
goto out;
}
retlen = ret;
if (retlen > 0) {
fprintf(stdout, "[%s] find [%s]\n", parsestate->leftargs[0], pcurstr);
for (j = 0; j < retlen; j++) {
matchlen = (size_t)(pendpos[j] - pstartpos[j]);
if (matchlen >= matchsize || pmatchstr == NULL) {
if (pmatchstr) {
free(pmatchstr);
}
pmatchstr = NULL;
matchsize = (matchlen + 3);
pmatchstr = (char*) malloc(matchsize);
if (pmatchstr == NULL) {
GETERRNO(ret);
ERROR_INFO("alloc %d error[%d]", matchsize, ret);
goto out;
}
}
memset(pmatchstr, 0 , matchsize);
memcpy(pmatchstr, &(pcurstr[pstartpos[j]]), matchlen);
fprintf(stdout, " [%03d] %s\n", j, pmatchstr);
}
/*we move to the next to find*/
pcurstr = &(pcurstr[pendpos[0]]);
fprintf(stdout, " left[%s]\n", pcurstr);
handled ++;
goto file_try_again;
} else {
if (handled == 0) {
fprintf(stdout, "[%s] not find in [%s]\n", parsestate->leftargs[0], pcurstr);
}
}
}
}
ret = 0;
out:
if (pmatchstr != NULL) {
free(pmatchstr);
}
pmatchstr = NULL;
matchsize = 0;
read_file_lines(NULL,&pplines,&lsize);
regex_exec(NULL, NULL, &pstartpos, &pendpos, &possize);
regex_compile(NULL, REGEX_NONE, &preg);
SETERRNO(ret);
return ret;
}
| [
"jeppeter@gmail.com"
] | jeppeter@gmail.com |
91f22c3fc694186cd8eee5ee86dbfd3fd915e06f | 1af0bc3634313da229fcf7015abec43981b4162a | /hundredandbelow/80test.cpp | 4b0471c57e58cc86e04cba217111771ded5df9c5 | [] | no_license | errai-/euler | b2996e227ede830e8c56252bcce08a92538464df | 054c391d3aee6bcb9ba4dbf24f4ec6cb5b8b55c3 | refs/heads/master | 2022-06-18T09:02:54.573903 | 2018-05-14T08:21:48 | 2018-05-14T08:21:48 | 85,503,541 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 517 | cpp | #include "LongNumbers.h"
#include <iostream>
#include "80.h"
using std::cout;
using std::endl;
int main(void){
uint64_t totalSum = 0;
for (int i = 2; i != 100; ++i){
if ( i==4 ) continue;
if ( i==9 ) continue;
if ( i==16 ) continue;
if ( i==25 ) continue;
if ( i==36 ) continue;
if ( i==49 ) continue;
if ( i==64 ) continue;
if ( i==81 ) continue;
if ( i==100 ) continue;
Number ses(i);
totalSum += ses.sumDecimals();
}
cout << totalSum << endl;
return 0;
}
| [
"hannu.siikonen@aalto.fi"
] | hannu.siikonen@aalto.fi |
5748c21ecfc66f3257f67447c0189cd0c6aaf98d | 1a9379ee4ca2c5c85ee0d9ba247edd0ea1ca06f0 | /Leetcode/Trees/binary-tree-zigzag-level-order-traversal.cpp | 37e8eed971d5ea149117945fa7ae3e76783a9886 | [] | no_license | prajwal714/DSA-Coding-Practice | 29c257c4ec2053743bec3dddcfdb46639b5b05cc | fc8ccaa3feedf62102736feb39eb2cc79b5c0a5b | refs/heads/master | 2023-09-05T01:28:19.940625 | 2021-10-01T09:53:07 | 2021-10-01T09:53:07 | 203,861,890 | 14 | 5 | null | 2021-10-01T09:53:08 | 2019-08-22T19:44:16 | C++ | UTF-8 | C++ | false | false | 2,848 | cpp | /**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
//this is the wrong implementation, we cannot reverse the vector its not a true zig zag traversal
// class Solution {
// public:
// vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
// vector<vector<int>> res;
// queue<TreeNode*> q;
// int k=0;
// if(root==NULL)
// return res;
// q.push(root);
// while(!q.empty())
// {
// int size=q.size();
// vector<int> level;
// while(size--)
// {
// TreeNode* temp=q.front();
// q.pop();
// if(temp->left)
// q.push(temp->left);
// if(temp->right)
// q.push(temp->right);
// level.push_back(temp->val);
// }
// k++;
// //we can also sun a for loop and push from the back or from the front instead of reversing the vector
// if(k%2==0)
// reverse(level.begin(), level.end());
// res.push_back(level);
// }
// return res;
// }
// };
class Solution
{
public:
vector<vector<int> > zigzagLevelOrder(TreeNode *root)
{
if (root == NULL)
return {};
deque<TreeNode *> q;
q.push_back(root);
bool l2r = true;
vector<vector<int> > res;
while (!q.empty())
{
int size = q.size();
vector<int> level;
while (size--)
{
TreeNode *temp;
if (l2r)
//when left->right pop_back and push_front (left child, right child)
{
temp = q.back();
q.pop_back();
if (temp->left)
q.push_front(temp->left);
if (temp->right)
q.push_front(temp->right);
}
else
//when right->left pop_front and push_back(right child, left child)
{
temp = q.front();
q.pop_front();
if (temp->right)
q.push_back(temp->right);
if (temp->left)
q.push_back(temp->left);
}
level.push_back(temp->val);
}
l2r = !l2r;
res.push_back(level);
}
return res;
}
}; | [
"prajwal714singh@gmail.com"
] | prajwal714singh@gmail.com |
f1bc65e263929daba1ca07a5d0026d26e05f7a78 | 8b4380ee3652b833ead269d83f372860ee979c78 | /src/scriptinterface.cpp | cfaebf27a9451d5467534d5293f505efbe7ca7d9 | [] | no_license | Cameleopardus/Symphony-Engine | 429dba0706dceed60ef5179b5485dcefe751d28c | cd3569b4c8d0adb61e5466a0b6af55292f907dc7 | refs/heads/master | 2021-01-10T18:29:35.365172 | 2012-06-12T04:42:19 | 2012-06-12T04:42:19 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 506 | cpp | #include "scriptinterface.h"
ScriptInterface::ScriptInterface()
{
Lua = luaL_newstate();
luaL_openlibs(Lua);
luaopen_table(Lua);
luaopen_io(Lua);
luaopen_string(Lua);
luaopen_math(Lua);
}
ScriptInterface::~ScriptInterface()
{
ScriptInterface::CloseLuaState(Lua);
}
void ScriptInterface::CloseLuaState(lua_State *LSTATE)
{
lua_close(LSTATE);
}
void ScriptInterface::RegisterLuaFunction(lua_State *LSTATE, const char *NAME, lua_CFunction FUNC)
{
lua_register(LSTATE,NAME,FUNC);
}
| [
"rooster@birdhouse.(none)"
] | rooster@birdhouse.(none) |
512d427bd3d9154c2a3ffba23cc0b28db4407a71 | f1485462d58193b53ec1a32920a53d48641e5693 | /chapter01/8-australian_voting/australian_voting.cpp | 4f592330b42fb9209ba7e909f901fe824e6a0970 | [] | no_license | ZaynAliShan/uva | 286993c64f360316f4a525043271054e2fd00ce6 | 285f72960402b96ff0e2aed86aa0892a3dd18cb3 | refs/heads/master | 2022-03-13T18:20:55.000634 | 2013-03-09T18:46:10 | 2013-03-09T18:46:10 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 366 | cpp | #include <iostream>
using namespace std;
void check_results();
int main()
{
int num_cases;
cin >> num_cases;
for (int case_num = 0; case_num < num_cases; case_num++)
check_results();
return 0;
}
void check_results()
{
int num_candidates;
cin >> num_candidates;
cout << "Number of candidates: " << num_candidates << endl;
}
| [
"janno.poldma@gmail.com"
] | janno.poldma@gmail.com |
42164f0ed0561ec94c8d850ddc3cea3e58f6d24a | 2a0bbe40f4eb1cc9f50c539566e7e9c0d8a4b337 | /common/audio/V2/speech_driver/SpeechMessengerCCCI.cpp | 47334d5d3daa14086c37305a3e1f5ce5a46ba54a | [] | no_license | lewonchik/android_hardware_mediatek-1 | fb5fe18ebae4b372a562683f0f2bb2df5cb487d8 | 8e86c4e63154b0b1d724f6405655672422d3985d | refs/heads/master | 2021-01-22T15:22:54.999343 | 2014-09-29T02:09:54 | 2014-09-29T02:09:54 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 61,015 | cpp | #define LOG_TAG "SpeechMessengerCCCI"
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/rtpm_prio.h>
#include <sys/prctl.h>
#include <cutils/properties.h>
#include "SpeechMessengerCCCI.h"
#include "SpeechDriverLAD.h"
#include "SpeechBGSPlayer.h"
#include "SpeechPcm2way.h"
#include "SpeechVMRecorder.h"
#include "AudioMTKStreamInManager.h"
#include "AudioResourceManager.h"
//#include "hardware/ccci_intf.h"
#ifndef sph_msleep
#define sph_msleep(ms) usleep((ms)*1000)
#endif
namespace android
{
/** CCCI driver & ioctl */
static const char CCCI_PCM_RX_DEV[NUM_MODEM][32] = {"/dev/ccci_pcm_rx", "/dev/ccci2_pcm_rx", "/dev/ccci5_pcm_rx"};
static const char CCCI_PCM_TX_DEV[NUM_MODEM][32] = {"/dev/ccci_pcm_tx", "/dev/ccci2_pcm_tx", "/dev/ccci5_pcm_tx"};
/** CCCI ioctl */
#define CCCI_IOC_MAGIC 'C'
#define CCCI_IOC_GET_MODEM_STATE _IOR(CCCI_IOC_MAGIC, 1, unsigned int)
#define CCCI_IOC_SHARE_MEMORY_SIZE _IOR(CCCI_IOC_MAGIC, 3, unsigned int)
/** CCCI modem status */
static const char MODEM_STATUS_NOT_RUN = '0'; // Boot stage 0 -> Means MD Does NOT run
static const char MODEM_STATUS_NOT_READY = '1'; // Boot stage 1 -> Means MD begin to run, but not ready
static const char MODEM_STATUS_READY = '2'; // Boot stage 2 -> Means MD is ready
static const char MODEM_STATUS_EXCEPTION = '3'; // MD exception -> Means EE occur
/** Property keys*/
static const char PROPERTY_KEY_MODEM_STATUS[NUM_MODEM][PROPERTY_KEY_MAX] = {"af.modem_1.status", "af.modem_2.status", "af.modem_5.status"};
/** CCCI channel No */
static const uint8_t CCCI_M2A_CHANNEL = 4;
static const uint8_t CCCI_A2M_CHANNEL = 5;
/** CCCI magic number */
static const uint32_t CCCI_MAILBOX_MAGIC_NUMBER = 0xFFFFFFFF;
SpeechMessengerCCCI::SpeechMessengerCCCI(modem_index_t modem_index, SpeechDriverLAD *pLad)
: mModemIndex(modem_index), mLad(pLad)
{
CCCIEnable = false;
fHdlRead = -1;
fHdlWrite = -1;
mA2MShareBufLen = 0;
mM2AShareBufLen = 0;
mA2MShareBufBase = NULL;
mM2AShareBufBase = NULL;
mA2MShareBufEnd = NULL;
mM2AShareBufEnd = NULL;
//initial the message queue
memset((void *)pQueue, 0, sizeof(pQueue));
iQRead = 0;
iQWrite = 0;
mWaitAckMessageID = 0;
//initial modem side modem status
char property_value[PROPERTY_VALUE_MAX];
property_get(PROPERTY_KEY_MODEM_STATUS[mModemIndex], property_value, "0"); //"0": default all off
mModemSideModemStatus = atoi(property_value);
ResetSpeechParamAckCount();
mIsModemResetDuringPhoneCall = false;
}
status_t SpeechMessengerCCCI::Initial()
{
// Open CCCI and get handler
char dev_node_read[32], dev_node_write[32];
switch(mModemIndex)
{
case MODEM_1:
snprintf(dev_node_read, 32, "%s", ccci_get_node_name(USR_AUDIO_RX, MD_SYS1));
snprintf(dev_node_write, 32, "%s", ccci_get_node_name(USR_AUDIO_TX, MD_SYS1));
break;
case MODEM_2:
snprintf(dev_node_read, 32, "%s", ccci_get_node_name(USR_AUDIO_RX, MD_SYS2));
snprintf(dev_node_write, 32, "%s", ccci_get_node_name(USR_AUDIO_TX, MD_SYS2));
break;
case MODEM_EXTERNAL:
snprintf(dev_node_read, 32, "%s", ccci_get_node_name(USR_AUDIO_RX, MD_SYS5));
snprintf(dev_node_write, 32, "%s", ccci_get_node_name(USR_AUDIO_TX, MD_SYS5));
break;
}
ALOGD("SpeechMessengerCCCI_ : initial(), dev_node_read=%s, dev_node_write=%s", dev_node_read, dev_node_write);
fHdlRead = open(dev_node_read, O_RDWR);
fHdlWrite = open(dev_node_write, O_RDWR);
if (fHdlRead < 0 || fHdlWrite < 0)
{
ALOGE("%s() fail to open %s or %s", __FUNCTION__, dev_node_read, dev_node_write);
return UNKNOWN_ERROR;
}
// Get total share buffer length & base address
uint32_t share_buf_length;
char *share_buf_address;
::ioctl(fHdlRead, CCCI_IOC_PCM_LEN, &share_buf_length);
ALOGD("SpeechMessengerCCCI_ : initial(), ioctl share_buf_length=%d", share_buf_length);
share_buf_address = (char *)mmap(NULL, share_buf_length, PROT_READ | PROT_WRITE, MAP_SHARED, fHdlRead, 0);
ALOGD("%s(), ShareBufAdd:0x%p, ShareBufLen:%u", __FUNCTION__, share_buf_address, share_buf_length);
mA2MShareBufLen = share_buf_length >> 1; // a2m buffer lengh should be half of share_buf_length
mM2AShareBufLen = share_buf_length >> 1; // m2a buffer lengh should be half of share_buf_length
mA2MShareBufBase = share_buf_address;
mM2AShareBufBase = share_buf_address + mA2MShareBufLen;
mA2MShareBufEnd = mA2MShareBufBase + mA2MShareBufLen;
mM2AShareBufEnd = mM2AShareBufBase + mM2AShareBufLen;
/* create the CCCI event reading thread */
CCCIEnable = true;
return CreateReadingThread();
}
status_t SpeechMessengerCCCI::Deinitial()
{
CCCIEnable = false;
mA2MShareBufLen = 0;
mM2AShareBufLen = 0;
mA2MShareBufBase = NULL;
mM2AShareBufBase = NULL;
mA2MShareBufEnd = NULL;
mM2AShareBufEnd = NULL;
if (fHdlRead >= 0) { close(fHdlRead); }
if (fHdlWrite >= 0) { close(fHdlWrite); }
return NO_ERROR;
}
SpeechMessengerCCCI::~SpeechMessengerCCCI()
{
ALOGD("%s()", __FUNCTION__);
}
/** Create CCCI message */
ccci_buff_t SpeechMessengerCCCI::InitCcciMailbox(uint16_t id, uint16_t param_16bit, uint32_t param_32bit)
{
ccci_buff_t ccci_buff;
ccci_buff.magic = CCCI_MAILBOX_MAGIC_NUMBER;
ccci_buff.message = (id << 16) | param_16bit;
ccci_buff.channel = CCCI_A2M_CHANNEL;
ccci_buff.reserved = param_32bit;
return ccci_buff;
}
/** Get CCCI message's ID */
uint16_t SpeechMessengerCCCI::GetMessageID(const ccci_buff_t &ccci_buff)
{
return (ccci_buff.message) >> 16;
}
/** Get CCCI message's parameters */
uint16_t SpeechMessengerCCCI::GetMessageParam(const ccci_buff_t &ccci_buff)
{
return (ccci_buff.message) & 0xFFFF;
}
uint16_t SpeechMessengerCCCI::GetMessageLength(const ccci_buff_t &ccci_buff)
{
return (ccci_buff.message) & 0xFFFF; //GetMessageParam(ccci_buff);
}
uint16_t SpeechMessengerCCCI::GetMessageOffset(const ccci_buff_t &ccci_buff)
{
return (ccci_buff.reserved) & 0xFFFF;
}
char SpeechMessengerCCCI::GetModemCurrentStatus()
{
unsigned int status = (unsigned int)MODEM_STATUS_NOT_RUN;
int retval = ::ioctl(fHdlRead, CCCI_IOC_GET_MD_STATE, &status);
//ALOGD("SpeechMessengerCCCI_ : GetModemCurrentStatus(), modem status=%c", (char)status);
if (retval < 0)
{
ALOGE("%s() ioctl _IOR(CCCI_IOC_GET_MD_STATEt) fail!! retval = %d", __FUNCTION__, retval);
status = MODEM_STATUS_EXCEPTION;
}
return status;
}
bool SpeechMessengerCCCI::CheckModemIsReady()
{
return (GetModemCurrentStatus() == MODEM_STATUS_READY);
}
status_t SpeechMessengerCCCI::WaitUntilModemReady()
{
char status = 0;
uint32_t trycnt = 0;
const uint32_t kMaxTryCnt = 100; // total 10 sec
do
{
status = GetModemCurrentStatus();
if (status == MODEM_STATUS_READY)
{
ALOGD("%s(): Modem ready", __FUNCTION__);
break;
}
else
{
ALOGW("Wait CCCI open #%d times, modem current status = %c", ++trycnt, status);
sph_msleep(100);
if (trycnt == kMaxTryCnt) { break; }
}
}
while (1);
return (trycnt < kMaxTryCnt) ? NO_ERROR : TIMED_OUT;
}
int32_t SpeechMessengerCCCI::SendMessage(const ccci_buff_t &ccci_buff)
{
// check if already initialized
if (fHdlWrite < 0)
{
if (Initial() != NO_ERROR) { return UNKNOWN_ERROR; }
}
// check if need ack
const uint16_t message_id = GetMessageID(ccci_buff);
const bool b_need_ack = (JudgeAckOfMsg(message_id) == MESSAGE_NEED_ACK) ? true : false;
// check modem status during phone call
char modem_status = GetModemCurrentStatus();
if (modem_status != MODEM_STATUS_READY)
{
ALOGE("%s(), modem_status(%c) != MODEM_STATUS_READY", __FUNCTION__, modem_status);
mIsModemResetDuringPhoneCall = true;
ResetSpeechParamAckCount();
}
// Do not send any on/off message when mIsModemResetDuringPhoneCall is true
if (mIsModemResetDuringPhoneCall == true && IsModemFunctionOnOffMessage(message_id) == true)
{
ALOGE("%s(), mIsModemResetDuringPhoneCall == true, drop on/off message: 0x%x", __FUNCTION__, ccci_buff.message);
SendMsgFailErrorHandling(ccci_buff);
// clean mIsModemResetDuringPhoneCall when phone call/loopback stop
if (message_id == MSG_A2M_SPH_OFF)
{
ALOGD("%s(), Phone call stop. Set mIsModemResetDuringPhoneCall = false", __FUNCTION__);
mIsModemResetDuringPhoneCall = false;
}
else if (message_id == MSG_A2M_SET_ACOUSTIC_LOOPBACK)
{
const bool loopback_on = GetMessageParam(ccci_buff) & 0x1;
if (loopback_on == false)
{
ALOGD("%s(), loopback stop. Set mIsModemResetDuringPhoneCall = false", __FUNCTION__);
mIsModemResetDuringPhoneCall = false;
}
}
return UNKNOWN_ERROR;
}
// save ack info before write to avoid race condition with CCCIReadThread
if (b_need_ack == true)
{
mWaitAckMessageID = message_id;
}
// send message
int i = 0;
int write_length = 0;
status_t ret = UNKNOWN_ERROR;
for (i = 0; i < 150; i++) // try 150 times for every 2 ms if sent message fail
{
write_length = write(fHdlWrite, (void *)&ccci_buff, CCCI_BUF_HEADER_SIZE);
if (write_length == CCCI_BUF_HEADER_SIZE)
{
ret = NO_ERROR;
break;
}
else
{
modem_status = GetModemCurrentStatus();
ALOGW("%s(), message: 0x%x, try: #%d, write_length: %d, errno: %d, modem status: %c",
__FUNCTION__, ccci_buff.message, i, write_length, errno, modem_status);
if (errno == 3 || modem_status != MODEM_STATUS_READY) // md reset cause ccci message fail
{
ALOGE("%s(), MD RESET SKIP MESSAGE: 0x%x", __FUNCTION__, ccci_buff.message);
// if modem reset during phone call, raise mIsModemResetDuringPhoneCall
if (message_id != MSG_A2M_SPH_OFF && message_id != MSG_A2M_SET_ACOUSTIC_LOOPBACK)
{
mIsModemResetDuringPhoneCall = true;
}
ResetSpeechParamAckCount();
break;
}
sph_msleep(2);
}
}
// error handling for ack message
if (ret != NO_ERROR && b_need_ack == true)
{
mWaitAckMessageID = 0;
SendMsgFailErrorHandling(ccci_buff);
}
return ret;
}
status_t SpeechMessengerCCCI::ReadMessage(ccci_buff_t &ccci_buff)
{
/* check if already initialized */
if (fHdlRead < 0)
{
if (Initial() != NO_ERROR) { return UNKNOWN_ERROR; }
}
/* read message */
int read_length = read(fHdlRead, (void *)&ccci_buff, CCCI_BUF_HEADER_SIZE);
if (read_length != CCCI_BUF_HEADER_SIZE && GetModemCurrentStatus() != MODEM_STATUS_READY)
{
ALOGE("%s() fail, read_length: %d, modem current status: %c", __FUNCTION__, read_length, GetModemCurrentStatus());
return UNKNOWN_ERROR;
}
return NO_ERROR;
}
uint32_t SpeechMessengerCCCI::GetQueueCount() const
{
int32_t count = (iQWrite - iQRead);
if (count < 0) { count += CCCI_MAX_QUEUE_NUM; }
return count;
}
bool SpeechMessengerCCCI::CheckOffsetAndLength(const ccci_buff_t &ccci_buff)
{
uint16_t message_id = GetMessageID(ccci_buff);
uint16_t length = GetMessageLength(ccci_buff);
uint16_t offset = GetMessageOffset(ccci_buff);
if (offset > mM2AShareBufLen || length > mM2AShareBufLen)
{
ALOGE("%s(), message_id = 0x%x, length(0x%x), offset(0x%x), mM2AShareBufLen(0x%x)", __FUNCTION__, message_id, length, offset, mM2AShareBufLen);
ASSERT(offset > mM2AShareBufLen || length > mM2AShareBufLen);
return false;
}
else
{
return true;
}
}
ccci_message_ack_t SpeechMessengerCCCI::JudgeAckOfMsg(const uint16_t message_id)
{
ccci_message_ack_t ack;
switch (message_id)
{
case MSG_A2M_SET_SPH_MODE:
case MSG_A2M_SPH_ON:
case MSG_A2M_SPH_OFF:
#ifdef SPEECH_PCM_VM_SUPPORT
case MSG_A2M_PCM_REC_ON:
case MSG_A2M_VM_REC_ON:
case MSG_A2M_PCM_REC_OFF:
case MSG_A2M_VM_REC_OFF:
#else
case MSG_A2M_RECORD_ON:
case MSG_A2M_RECORD_OFF:
#endif
case MSG_A2M_BGSND_ON:
case MSG_A2M_BGSND_OFF:
case MSG_A2M_PNW_ON:
case MSG_A2M_PNW_OFF:
case MSG_A2M_DMNR_RECPLAY_ON:
case MSG_A2M_DMNR_RECPLAY_OFF:
case MSG_A2M_DMNR_REC_ONLY_ON:
case MSG_A2M_DMNR_REC_ONLY_OFF:
case MSG_A2M_CTM_ON:
case MSG_A2M_CTM_OFF:
case MSG_A2M_SET_ACOUSTIC_LOOPBACK:
case MSG_A2M_EM_NB:
case MSG_A2M_EM_DMNR:
case MSG_A2M_EM_WB:
//#if defined(MTK_VIBSPK_SUPPORT)
case MSG_A2M_VIBSPK_PARAMETER:
//#endif
case MSG_A2M_NXP_SMARTPA_PARAMETER:
ack = MESSAGE_NEED_ACK;
break;
default:
ack = MESSAGE_BYPASS_ACK;
}
return ack;
}
bool SpeechMessengerCCCI::IsModemFunctionOnOffMessage(const uint16_t message_id)
{
bool bIsModemFunctionOnOffMessage = false;
switch (message_id)
{
case MSG_A2M_SPH_ON:
case MSG_A2M_SPH_OFF:
#ifdef SPEECH_PCM_VM_SUPPORT
case MSG_A2M_PCM_REC_ON:
case MSG_A2M_VM_REC_ON:
case MSG_A2M_PCM_REC_OFF:
case MSG_A2M_VM_REC_OFF:
#else
case MSG_A2M_RECORD_ON:
case MSG_A2M_RECORD_OFF:
#endif
case MSG_A2M_BGSND_ON:
case MSG_A2M_BGSND_OFF:
case MSG_A2M_PNW_ON:
case MSG_A2M_PNW_OFF:
case MSG_A2M_DMNR_RECPLAY_ON:
case MSG_A2M_DMNR_RECPLAY_OFF:
case MSG_A2M_DMNR_REC_ONLY_ON:
case MSG_A2M_DMNR_REC_ONLY_OFF:
case MSG_A2M_CTM_ON:
case MSG_A2M_CTM_OFF:
case MSG_A2M_SET_ACOUSTIC_LOOPBACK:
bIsModemFunctionOnOffMessage = true;
break;
default:
bIsModemFunctionOnOffMessage = false;
}
return bIsModemFunctionOnOffMessage;
}
status_t SpeechMessengerCCCI::SendMessageInQueue(ccci_buff_t ccci_buff)
{
mCCCIMessageQueueMutex.lock();
uint32_t count = GetQueueCount();
ASSERT(count < (CCCI_MAX_QUEUE_NUM - 1)); // check queue full
ccci_message_ack_t ack_type = JudgeAckOfMsg(GetMessageID(ccci_buff));
if (ack_type == MESSAGE_NEED_ACK)
ALOGD("%s(), mModemIndex = %d, need ack message: 0x%x, reserved param: 0x%x",
__FUNCTION__, mModemIndex, ccci_buff.message, ccci_buff.reserved);
status_t ret = NO_ERROR;
if (count == 0) // queue is empty
{
if (ack_type == MESSAGE_BYPASS_ACK) // no need ack, send directly, don't care ret value
{
ret = SendMessage(ccci_buff);
}
else // need ack, en-queue and send message
{
pQueue[iQWrite].ccci_buff = ccci_buff;
pQueue[iQWrite].ack_type = ack_type;
iQWrite++;
if (iQWrite == CCCI_MAX_QUEUE_NUM) { iQWrite -= CCCI_MAX_QUEUE_NUM; }
ret = SendMessage(ccci_buff);
if (ret != NO_ERROR) // skip this fail CCCI message
{
iQRead++;
if (iQRead == CCCI_MAX_QUEUE_NUM) { iQRead -= CCCI_MAX_QUEUE_NUM; }
}
}
}
else // queue is not empty, must queue the element
{
pQueue[iQWrite].ccci_buff = ccci_buff;
pQueue[iQWrite].ack_type = ack_type;
iQWrite++;
if (iQWrite == CCCI_MAX_QUEUE_NUM) { iQWrite -= CCCI_MAX_QUEUE_NUM; }
ALOGD("%s(), Send message(0x%x) to queue, count(%u)", __FUNCTION__, ccci_buff.message, GetQueueCount());
}
mCCCIMessageQueueMutex.unlock();
return ret;
}
status_t SpeechMessengerCCCI::ConsumeMessageInQueue()
{
mCCCIMessageQueueMutex.lock();
uint32_t count = GetQueueCount();
if (count > 10)
{
ALOGW("%s(), queue count: %u", __FUNCTION__, count);
}
if (count == 0)
{
ALOGW("%s(), no message in queue", __FUNCTION__);
mCCCIMessageQueueMutex.unlock();
return UNKNOWN_ERROR;
}
status_t ret = NO_ERROR;
while (1)
{
// when entering this function, the first message in queue must be a message waiting for ack
// so we increment index, consuming the first message in queue
iQRead++;
if (iQRead == CCCI_MAX_QUEUE_NUM) { iQRead -= CCCI_MAX_QUEUE_NUM; }
// check if empty
if (iQRead == iQWrite)
{
ret = NO_ERROR;
break;
}
// update count
count = GetQueueCount();
// send message
if (pQueue[iQRead].ack_type == MESSAGE_BYPASS_ACK) // no need ack, send directly, don't care ret value
{
ALOGD("%s(), no need ack message: 0x%x, count: %u", __FUNCTION__, pQueue[iQRead].ccci_buff.message, count);
ret = SendMessage(pQueue[iQRead].ccci_buff);
}
else if (pQueue[iQRead].ack_type == MESSAGE_NEED_ACK)
{
ALOGD("%s(), need ack message: 0x%x, count: %u", __FUNCTION__, pQueue[iQRead].ccci_buff.message, count);
ret = SendMessage(pQueue[iQRead].ccci_buff);
if (ret == NO_ERROR) // Send CCCI message success and wait for ack
{
break;
}
}
else if (pQueue[iQRead].ack_type == MESSAGE_CANCELED) // the cancelled message, ignore it
{
ALOGD("%s(), cancel on-off-on message: 0x%x, count: %u", __FUNCTION__, pQueue[iQRead].ccci_buff.message, count);
ret = NO_ERROR;
}
}
mCCCIMessageQueueMutex.unlock();
return ret;
}
bool SpeechMessengerCCCI::MDReset_CheckMessageInQueue()
{
mCCCIMessageQueueMutex.lock();
uint32_t count = GetQueueCount();
ALOGD("%s(), queue count: %u", __FUNCTION__, count);
bool ret = true;
while (1)
{
// Modem already reset.
// Check every CCCI message in queue.
// These messages that are sent before modem reset, don't send to modem.
// But AP side need to do related action to make AP side in the correct state.
// check if empty
if (iQRead == iQWrite)
{
ALOGD("%s(), check message done", __FUNCTION__);
ret = true;
break;
}
// Need ack message. But modem reset, so simulate that the modem send back ack msg.
if (JudgeAckOfMsg(GetMessageID(pQueue[iQRead].ccci_buff)) == MESSAGE_NEED_ACK)
{
SendMsgFailErrorHandling(pQueue[iQRead].ccci_buff);
}
iQRead++;
if (iQRead == CCCI_MAX_QUEUE_NUM) { iQRead -= CCCI_MAX_QUEUE_NUM; }
}
mCCCIMessageQueueMutex.unlock();
return ret;
}
void SpeechMessengerCCCI::MDReset_FlushMessageInQueue()
{
mCCCIMessageQueueMutex.lock();
int32 count = GetQueueCount();
ALOGD("%s(), queue count: %u", __FUNCTION__, count);
if (count != 0)
{
ALOGE("%s(), queue is not empty!!", __FUNCTION__);
iQWrite = 0;
iQRead = 0;
}
mCCCIMessageQueueMutex.unlock();
}
status_t SpeechMessengerCCCI::CreateReadingThread()
{
int ret = pthread_create(&hReadThread, NULL, SpeechMessengerCCCI::CCCIReadThread, (void *)this);
if (ret != 0)
{
ALOGE("%s() create thread fail!!", __FUNCTION__);
return UNKNOWN_ERROR;
}
return NO_ERROR;
}
void *SpeechMessengerCCCI::CCCIReadThread(void *arg)
{
prctl(PR_SET_NAME, (unsigned long)__FUNCTION__, 0, 0, 0);
SpeechMessengerCCCI *pCCCI = (SpeechMessengerCCCI *)arg;
// force to set priority
struct sched_param sched_p;
sched_getparam(0, &sched_p);
sched_p.sched_priority = RTPM_PRIO_AUDIO_CCCI_THREAD;
if (0 != sched_setscheduler(0, SCHED_RR, &sched_p))
{
ALOGE("[%s] failed, errno: %d", __FUNCTION__, errno);
}
else
{
sched_p.sched_priority = RTPM_PRIO_AUDIO_CCCI_THREAD;
sched_getparam(0, &sched_p);
ALOGD("sched_setscheduler ok, priority: %d", sched_p.sched_priority);
}
ALOGD("%s(), pid: %d, tid: %d", __FUNCTION__, getpid(), gettid());
// Handle CCCI Message From Modems
while (pCCCI->CCCIEnable)
{
/// read message
ccci_buff_t ccci_buff;
memset((void *)&ccci_buff, 0, sizeof(ccci_buff));
status_t ret = pCCCI->ReadMessage(ccci_buff);
if (ret != NO_ERROR)
{
sph_msleep(10);
continue;
}
/// handle message
uint16_t m2a_message_id = pCCCI->GetMessageID(ccci_buff);
ALOGV("%s(), m2a_message_id = 0x%x", __FUNCTION__, m2a_message_id);
switch (m2a_message_id)
{
case MSG_M2A_SET_SPH_MODE_ACK: // ack of MSG_A2M_SET_SPH_MODE
{
// Do nothing... just leave a log
ALOGD("--SetSpeechMode Ack done(0x%x)", ccci_buff.message);
break;
}
/* Speech */
case MSG_M2A_SPH_ON_ACK: // ack of MSG_A2M_SPH_ON
{
phone_call_mode_t phone_call_mode = (phone_call_mode_t)pCCCI->GetMessageParam(ccci_buff);
if (phone_call_mode == RAT_3G324M_MODE)
{
pCCCI->SetModemSideModemStatus(VT_STATUS_MASK);
}
else
{
pCCCI->SetModemSideModemStatus(SPEECH_STATUS_MASK);
}
// dump speech enhancement parameter in modem log
pCCCI->mLad->ModemDumpSpeechParam();
pCCCI->mLad->Signal();
ALOGD("--SpeechOn Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_SPH_OFF_ACK: // ack of MSG_A2M_SPH_OFF
{
if (pCCCI->GetModemSideModemStatus(VT_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(VT_STATUS_MASK);
}
else if (pCCCI->GetModemSideModemStatus(SPEECH_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(SPEECH_STATUS_MASK);
}
else
{
ALOGE("--SpeechOff Ack is not paired!!");
}
pCCCI->mLad->Signal();
ALOGD("--SpeechOff Ack done(0x%x)", ccci_buff.message);
break;
}
/* Record */
#ifdef SPEECH_PCM_VM_SUPPORT
case MSG_M2A_PCM_REC_ON_ACK: // ack of MSG_A2M_PCM_REC_ON
{
pCCCI->SetModemSideModemStatus(RECORD_STATUS_MASK);
ALOGD("--RecordOn Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_VM_REC_ON_ACK: // ack of MSG_A2M_VM_REC_ON
{
pCCCI->SetModemSideModemStatus(VM_RECORD_STATUS_MASK);
ALOGD("--VMRecordOn Ack done(0x%x)", ccci_buff.message);
break;
}
#else
case MSG_M2A_RECORD_ON_ACK: // ack of MSG_A2M_RECORD_ON
{
pCCCI->SetModemSideModemStatus(RECORD_STATUS_MASK);
ALOGD("--RecordOn Ack done(0x%x)", ccci_buff.message);
break;
}
#endif
#ifdef SPEECH_PCM_VM_SUPPORT
case MSG_M2A_PCM_REC_DATA_NOTIFY: // meaning that we are recording, modem have some data
{
ASSERT(pCCCI->GetModemSideModemStatus(RECORD_STATUS_MASK) == true);
AudioResourceManager::getInstance()->EnableAudioLock(AudioResourceManagerInterface::AUDIO_STREAMINMANAGERCLIENT_LOCK, AUDIO_LOCK_TIMEOUT_VALUE_MS);
if (pCCCI->mLad->GetApSideModemStatus(RECORD_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_REC_DATA_NOTIFY(0x%x) after AP side trun off record!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_REC_DATA_NOTIFY(0x%x), data_length: %d", ccci_buff.message, pCCCI->GetMessageLength(ccci_buff) - CCCI_SHARE_BUFF_HEADER_LEN);
SpeechVMRecorder *pSpeechVMRecorder = SpeechVMRecorder::GetInstance();
// Phone record
AudioMTKStreamInManager::getInstance()->CopyBufferToClientIncall(pCCCI->GetM2AUplinkRingBuffer(ccci_buff));
if (pCCCI->mLad->GetApSideModemStatus(RECORD_STATUS_MASK) == true)
{
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_PCM_REC_DATA_READ_ACK, 0, 0));
}
}
AudioResourceManager::getInstance()->DisableAudioLock(AudioResourceManagerInterface::AUDIO_STREAMINMANAGERCLIENT_LOCK);
break;
}
case MSG_M2A_VM_REC_DATA_NOTIFY: // meaning that we are recording, modem have some data
{
ASSERT(pCCCI->GetModemSideModemStatus(VM_RECORD_STATUS_MASK) == true);
if (pCCCI->mLad->GetApSideModemStatus(VM_RECORD_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_REC_DATA_NOTIFY(0x%x) after AP side trun off record!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_REC_DATA_NOTIFY(0x%x), data_length: %d", ccci_buff.message, pCCCI->GetMessageLength(ccci_buff) - CCCI_SHARE_BUFF_HEADER_LEN);
SpeechVMRecorder *pSpeechVMRecorder = SpeechVMRecorder::GetInstance();
// VM
pSpeechVMRecorder->CopyBufferToVM(pCCCI->GetM2AUplinkRingBuffer(ccci_buff));
if (pCCCI->mLad->GetApSideModemStatus(VM_RECORD_STATUS_MASK) == true)
{
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_VM_REC_DATA_READ_ACK, 0, 0));
}
}
break;
}
#else
case MSG_M2A_REC_DATA_NOTIFY: // meaning that we are recording, modem have some data
{
ASSERT(pCCCI->GetModemSideModemStatus(RECORD_STATUS_MASK) == true);
AudioResourceManager::getInstance()->EnableAudioLock(AudioResourceManagerInterface::AUDIO_STREAMINMANAGERCLIENT_LOCK, AUDIO_LOCK_TIMEOUT_VALUE_MS);
if (pCCCI->mLad->GetApSideModemStatus(RECORD_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_REC_DATA_NOTIFY(0x%x) after AP side trun off record!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_REC_DATA_NOTIFY(0x%x), data_length: %d", ccci_buff.message, pCCCI->GetMessageLength(ccci_buff) - CCCI_SHARE_BUFF_HEADER_LEN);
SpeechVMRecorder *pSpeechVMRecorder = SpeechVMRecorder::GetInstance();
if (pSpeechVMRecorder->GetVMRecordStatus() == true) // VM
{
pSpeechVMRecorder->CopyBufferToVM(pCCCI->GetM2AUplinkRingBuffer(ccci_buff));
}
else // Phone record
{
AudioMTKStreamInManager::getInstance()->CopyBufferToClientIncall(pCCCI->GetM2AUplinkRingBuffer(ccci_buff));
}
if (pCCCI->mLad->GetApSideModemStatus(RECORD_STATUS_MASK) == true)
{
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_REC_DATA_READ_ACK, 0, 0));
}
}
AudioResourceManager::getInstance()->DisableAudioLock(AudioResourceManagerInterface::AUDIO_STREAMINMANAGERCLIENT_LOCK);
break;
}
#endif
#ifdef SPEECH_PCM_VM_SUPPORT
case MSG_M2A_PCM_REC_OFF_ACK: // ack of MSG_A2M_PCM_REC_OFF
{
if (pCCCI->GetModemSideModemStatus(RECORD_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(RECORD_STATUS_MASK);
}
else
{
ALOGE("--RecordOff Ack is not paired!!");
}
ALOGD("--RecordOff Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_VM_REC_OFF_ACK: // ack of MSG_A2M_VM_REC_OFF
{
if (pCCCI->GetModemSideModemStatus(VM_RECORD_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(VM_RECORD_STATUS_MASK);
}
else
{
ALOGE("--VMRecordOff Ack is not paired!!");
}
ALOGD("--VMRecordOff Ack done(0x%x)", ccci_buff.message);
break;
}
#else
case MSG_M2A_RECORD_OFF_ACK: // ack of MSG_A2M_RECORD_OFF
{
if (pCCCI->GetModemSideModemStatus(RECORD_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(RECORD_STATUS_MASK);
}
else
{
ALOGE("--RecordOff Ack is not paired!!");
}
ALOGD("--RecordOff Ack done(0x%x)", ccci_buff.message);
break;
}
#endif
/* Background sound */
case MSG_M2A_BGSND_ON_ACK: // ack of MSG_A2M_BGSND_ON
{
pCCCI->SetModemSideModemStatus(BGS_STATUS_MASK);
ALOGD("--BGSoundOn Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_BGSND_DATA_REQUEST: // modem request bgs data to play
{
ASSERT(pCCCI->GetModemSideModemStatus(BGS_STATUS_MASK) == true);
BGSPlayer *pBGSPlayer = BGSPlayer::GetInstance();
pBGSPlayer->mBGSMutex.lock(); // avoid AudioMTKStreamOut::standby() destroy BGSPlayBuffer during MSG_M2A_BGSND_DATA_REQUEST
if (pCCCI->mLad->GetApSideModemStatus(BGS_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_BGSND_DATA_REQUEST(0x%x) after AP side trun off BGS!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_BGSND_DATA_REQUEST(0x%x), num_data_request: %d", ccci_buff.message, pCCCI->GetMessageParam(ccci_buff));
// parse size of data request
uint16_t num_data_request = pCCCI->GetMessageParam(ccci_buff);
uint32_t max_buf_length = A2M_SHARED_BUFFER_BGS_DATA_SIZE;
if (num_data_request > max_buf_length) { num_data_request = max_buf_length; }
// get bgs share buffer address
uint16_t offset = A2M_SHARED_BUFFER_BGS_DATA_BASE;
char *p_header_address = pCCCI->GetA2MShareBufBase() + offset;
char *p_data_address = p_header_address + CCCI_SHARE_BUFF_HEADER_LEN;
// fill playback data
uint16_t data_length = pBGSPlayer->PutDataToSpeaker(p_data_address, num_data_request);
// fill header info
pCCCI->SetShareBufHeader((uint16_t *)p_header_address,
CCCI_A2M_SHARE_BUFF_HEADER_SYNC,
SHARE_BUFF_DATA_TYPE_CCCI_BGS_TYPE,
data_length);
// send data notify to modem side
const uint16_t message_length = CCCI_SHARE_BUFF_HEADER_LEN + data_length;
if (pCCCI->mLad->GetApSideModemStatus(BGS_STATUS_MASK) == true)
{
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_BGSND_DATA_NOTIFY, message_length, offset));
}
}
pBGSPlayer->mBGSMutex.unlock();
break;
}
case MSG_M2A_BGSND_OFF_ACK: // ack of MSG_A2M_BGSND_OFF
{
if (pCCCI->GetModemSideModemStatus(BGS_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(BGS_STATUS_MASK);
}
else
{
ALOGE("--BGSoundOff Ack is not paired!!");
}
ALOGD("--BGSoundOff Ack done(0x%x)", ccci_buff.message);
break;
}
/* PCM2Way */
case MSG_M2A_PNW_ON_ACK: // ack of MSG_A2M_PNW_ON
case MSG_M2A_DMNR_RECPLAY_ON_ACK: // ack of MSG_A2M_DMNR_RECPLAY_ON
case MSG_M2A_DMNR_REC_ONLY_ON_ACK: // ack of MSG_A2M_DMNR_REC_ONLY_ON
{
pCCCI->SetModemSideModemStatus(P2W_STATUS_MASK);
ALOGD("--PCM2WayOn Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_PNW_UL_DATA_NOTIFY: // Get Microphone data from Modem
{
ASSERT(pCCCI->GetModemSideModemStatus(P2W_STATUS_MASK) == true);
Record2Way *pRecord2Way = Record2Way::GetInstance();
if (pCCCI->mLad->GetApSideModemStatus(P2W_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_PNW_UL_DATA_NOTIFY(0x%x) after AP side trun off PCM2Way!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_PNW_UL_DATA_NOTIFY(0x%x), data_length:%d", ccci_buff.message, pCCCI->GetMessageLength(ccci_buff) - CCCI_SHARE_BUFF_HEADER_LEN);
pRecord2Way->GetDataFromMicrophone(pCCCI->GetM2AUplinkRingBuffer(ccci_buff));
if (pCCCI->mLad->GetApSideModemStatus(P2W_STATUS_MASK) == true)
{
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_PNW_UL_DATA_READ_ACK, 0, 0));
}
}
#if 0 // PCM2WAY: UL -> DL Loopback
// Used for debug and Speech DVT
uint16_t size_bytes = 320;
char buffer[320];
pRecord2Way->Read(buffer, size_bytes);
Play2Way::GetInstance()->Write(buffer, size_bytes);
#endif
break;
}
case MSG_M2A_PNW_DL_DATA_REQUEST: // Put Data to modem and play
{
ASSERT(pCCCI->GetModemSideModemStatus(P2W_STATUS_MASK) == true);
if (pCCCI->mLad->GetApSideModemStatus(P2W_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_PNW_DL_DATA_REQUEST(0x%x) after AP side trun off PCM2Way!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_PNW_DL_DATA_REQUEST(0x%x), num_data_request: %d", ccci_buff.message, pCCCI->GetMessageParam(ccci_buff));
// parse size of data request
uint16_t num_data_request = pCCCI->GetMessageParam(ccci_buff);
uint32_t max_buf_length = PCM2WAY_PLAY_BUFFER_WB_LEN;
if (num_data_request > max_buf_length) { num_data_request = max_buf_length; }
// get pcm2way share buffer address
uint16_t offset = A2M_SHARED_BUFFER_P2W_DL_DATA_BASE;
char *p_header_address = pCCCI->GetA2MShareBufBase() + offset;
char *p_data_address = p_header_address + CCCI_SHARE_BUFF_HEADER_LEN;
// fill playback data
Play2Way *pPlay2Way = Play2Way::GetInstance();
const uint16_t data_length = pPlay2Way->PutDataToSpeaker(p_data_address, num_data_request);
// fill header info
pCCCI->SetShareBufHeader((uint16_t *)p_header_address,
CCCI_A2M_SHARE_BUFF_HEADER_SYNC,
SHARE_BUFF_DATA_TYPE_PCM_FillSpk,
data_length);
// send data notify to modem side
const uint16_t message_length = CCCI_SHARE_BUFF_HEADER_LEN + data_length;
if (pCCCI->mLad->GetApSideModemStatus(P2W_STATUS_MASK) == true)
{
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_PNW_DL_DATA_NOTIFY, message_length, offset));
}
}
break;
}
case MSG_M2A_PNW_OFF_ACK: // ack of MSG_A2M_PNW_OFF
case MSG_M2A_DMNR_RECPLAY_OFF_ACK: // ack of MSG_A2M_DMNR_RECPLAY_OFF
case MSG_M2A_DMNR_REC_ONLY_OFF_ACK: // ack of MSG_A2M_DMNR_REC_ONLY_OFF
{
if (pCCCI->GetModemSideModemStatus(P2W_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(P2W_STATUS_MASK);
}
else
{
ALOGE("--PCM2WayOff Ack is not paired!!");
}
ALOGD("--PCM2WayOff Ack done(0x%x)", ccci_buff.message);
break;
}
/* TTY */
case MSG_M2A_CTM_ON_ACK: // ack of MSG_A2M_CTM_ON
{
pCCCI->SetModemSideModemStatus(TTY_STATUS_MASK);
ALOGD("--TtyCtmOn Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_CTM_DEBUG_DATA_NOTIFY:
{
if (pCCCI->mLad->GetApSideModemStatus(TTY_STATUS_MASK) == false)
{
ALOGW("MSG_M2A_CTM_DEBUG_DATA_NOTIFY(0x%x) after AP side trun off TTY!! Drop it.", ccci_buff.message);
}
else
{
SLOGV("MSG_M2A_CTM_DEBUG_DATA_NOTIFY(0x%x), data_length: %d", ccci_buff.message, pCCCI->GetMessageLength(ccci_buff) - CCCI_SHARE_BUFF_HEADER_LEN);
SpeechVMRecorder *pSpeechVMRecorder = SpeechVMRecorder::GetInstance();
int i = 4, j;
if (pCCCI->GetM2AShareBufSyncWord(ccci_buff) == CCCI_M2A_SHARE_BUFF_HEADER_SYNC)
{
while (i)
{
int data_type = pCCCI->GetM2AShareBufDataType(ccci_buff);
if (data_type == SHARE_BUFF_DATA_TYPE_CCCI_CTM_UL_IN)
{
pSpeechVMRecorder->GetCtmDebugDataFromModem(pCCCI->GetM2ACtmRingBuffer(ccci_buff), pSpeechVMRecorder->pCtmDumpFileUlIn);
}
else if (data_type == SHARE_BUFF_DATA_TYPE_CCCI_CTM_DL_IN)
{
pSpeechVMRecorder->GetCtmDebugDataFromModem(pCCCI->GetM2ACtmRingBuffer(ccci_buff), pSpeechVMRecorder->pCtmDumpFileDlIn);
}
else if (data_type == SHARE_BUFF_DATA_TYPE_CCCI_CTM_UL_OUT)
{
pSpeechVMRecorder->GetCtmDebugDataFromModem(pCCCI->GetM2ACtmRingBuffer(ccci_buff), pSpeechVMRecorder->pCtmDumpFileUlOut);
}
else if (data_type == SHARE_BUFF_DATA_TYPE_CCCI_CTM_DL_OUT)
{
pSpeechVMRecorder->GetCtmDebugDataFromModem(pCCCI->GetM2ACtmRingBuffer(ccci_buff), pSpeechVMRecorder->pCtmDumpFileDlOut);
}
j = pCCCI->GetM2AShareBufDataLength(ccci_buff) + CCCI_SHARE_BUFF_HEADER_LEN;
ccci_buff.reserved += j;
if (ccci_buff.reserved > pCCCI->mM2AShareBufLen) { ccci_buff.reserved -= pCCCI->mM2AShareBufLen; }
i--;
}
}
pCCCI->SendMessage(pCCCI->InitCcciMailbox(MSG_A2M_CTM_DEBUG_DATA_READ_ACK, 0, 0));
}
break;
}
case MSG_M2A_CTM_OFF_ACK: // ack of MSG_A2M_CTM_OFF
{
if (pCCCI->GetModemSideModemStatus(TTY_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(TTY_STATUS_MASK);
}
else
{
ALOGE("--TtyCtmOff Ack is not paired!!");
}
ALOGD("--TtyCtmOff Ack done(0x%x)", ccci_buff.message);
break;
}
/* Loopback */
case MSG_M2A_SET_ACOUSTIC_LOOPBACK_ACK: // ack of MSG_A2M_SET_ACOUSTIC_LOOPBACK
{
const bool loopback_on = pCCCI->GetMessageParam(ccci_buff) & 0x1;
if (loopback_on == true) // loopback on
{
pCCCI->SetModemSideModemStatus(LOOPBACK_STATUS_MASK);
// dump speech enhancement parameter in modem log
pCCCI->mLad->ModemDumpSpeechParam();
}
else // loopback off
{
if (pCCCI->GetModemSideModemStatus(LOOPBACK_STATUS_MASK) == true)
{
pCCCI->ResetModemSideModemStatus(LOOPBACK_STATUS_MASK);
}
else
{
ALOGE("--SetAcousticLoopback Ack is not paired!!");
}
}
pCCCI->mLad->Signal();
ALOGD("--SetAcousticLoopback Ack done(0x%x)", ccci_buff.message);
break;
}
/* Speech Enhancement parameters */
case MSG_M2A_EM_NB_ACK: // ack of MSG_A2M_EM_NB
{
pCCCI->AddSpeechParamAckCount(NB_SPEECH_PARAM);
pCCCI->A2MBufUnLock();
ALOGD("--SetNBSpeechParameters Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_EM_DMNR_ACK: // ack of MSG_A2M_EM_DMNR
{
pCCCI->AddSpeechParamAckCount(DMNR_SPEECH_PARAM);
pCCCI->A2MBufUnLock();
ALOGD("--SetDualMicSpeechParameters Ack done(0x%x)", ccci_buff.message);
break;
}
case MSG_M2A_EM_WB_ACK: // ack of MSG_A2M_EM_WB
{
pCCCI->AddSpeechParamAckCount(WB_SPEECH_PARAM);
pCCCI->A2MBufUnLock();
ALOGD("--SetWBSpeechParameters Ack done(0x%x)", ccci_buff.message);
break;
}
/* Modem Reset */
case MSG_M2A_EM_DATA_REQUEST: // Modem reset. Requset for all EM data(NB/DMNR/WB)
{
ALOGW("..[MD Reset Notify(MSG_M2A_EM_DATA_REQUEST: 0x%x)]..", ccci_buff.message);
// Clean mWaitAckMessageID to avoid the queue receiving the wrong ack
pCCCI->mWaitAckMessageID = 0;
// close analog downlink path when modem reset during phone call
if (pCCCI->mLad->GetApSideModemStatus(SPEECH_STATUS_MASK) == true ||
pCCCI->mLad->GetApSideModemStatus(VT_STATUS_MASK) == true)
{
AudioResourceManager::getInstance()->StopOutputDevice();
}
pCCCI->mIsModemResetDuringPhoneCall = false;
// Create Send Sph Para Thread
pCCCI->CreateSendSphParaThread();
break;
}
//#if defined(MTK_VIBSPK_SUPPORT)
case MSG_M2A_VIBSPK_PARAMETER_ACK: // ack of MSG_M2A_VIBSPK_PARAMETER
{
pCCCI->A2MBufUnLock();
ALOGD("--SetVibSpkParam Ack done(0x%x)", ccci_buff.message);
break;
}
//#endif
case MSG_M2A_NXP_SMARTPA_PARAMETER_ACK: {
pCCCI->A2MBufUnLock();
ALOGD("--SetNxpSmartpaParam Ack done(0x%x)", ccci_buff.message);
break;
}
default:
{
ALOGD("Read modem message(0x%x), don't care. (or no such message)", ccci_buff.message);
sph_msleep(10);
break;
}
}
/// If AP side is waiting for this ack, then consume message queue
uint16_t a2m_message_id_of_m2a_ack = m2a_message_id & 0x7FFF; // 0xAF** -> 0x2F**
if (pCCCI->JudgeAckOfMsg(a2m_message_id_of_m2a_ack) == MESSAGE_NEED_ACK)
{
if (a2m_message_id_of_m2a_ack == pCCCI->mWaitAckMessageID)
{
pCCCI->mWaitAckMessageID = 0; // reset
pCCCI->ConsumeMessageInQueue();
}
else
{
ALOGW("Message(0x%x) might double ack!! The current mWaitAckMessageID is 0x%x", ccci_buff.message, pCCCI->mWaitAckMessageID);
}
}
}
pthread_exit(NULL);
return 0;
}
status_t SpeechMessengerCCCI::CreateSendSphParaThread()
{
int ret = pthread_create(&hSendSphThread, NULL, SpeechMessengerCCCI::SendSphParaThread, (void *)this);
if (ret != 0)
{
ALOGE("%s() create thread fail!!", __FUNCTION__);
return UNKNOWN_ERROR;
}
return NO_ERROR;
}
void *SpeechMessengerCCCI::SendSphParaThread(void *arg)
{
prctl(PR_SET_NAME, (unsigned long)__FUNCTION__, 0, 0, 0);
// force to set priority
struct sched_param sched_p;
sched_getparam(0, &sched_p);
sched_p.sched_priority = RTPM_PRIO_AUDIO_CCCI_THREAD;
if (0 != sched_setscheduler(0, SCHED_RR, &sched_p))
{
ALOGE("[%s] failed, errno: %d", __FUNCTION__, errno);
}
else
{
sched_p.sched_priority = RTPM_PRIO_AUDIO_CCCI_THREAD;
sched_getparam(0, &sched_p);
ALOGD("sched_setscheduler ok, priority: %d", sched_p.sched_priority);
}
ALOGD("%s(), pid: %d, tid: %d", __FUNCTION__, getpid(), gettid());
SpeechMessengerCCCI *pCCCI = (SpeechMessengerCCCI *)arg;
// Get SpeechParamLock
if (pCCCI->SpeechParamLock() == false)
{
ALOGE("%s() fail to get SpeechParamLock!!", __FUNCTION__);
return 0;
}
// Check the first message in queue. If need ack, take action.
pCCCI->MDReset_CheckMessageInQueue();
// Modem reset, flush all CCCI queue first. Don't care for the CCCI queue.
pCCCI->MDReset_FlushMessageInQueue();
// Send speech parameters to modem side
pCCCI->ResetSpeechParamAckCount();
pCCCI->mLad->SetAllSpeechEnhancementInfoToModem();
// Release SpeechParamLock
pCCCI->SpeechParamUnLock();
pthread_exit(NULL);
return 0;
}
bool SpeechMessengerCCCI::A2MBufLock()
{
const uint32_t kA2MBufLockTimeout = 3000; // 3 sec
int rc = mA2MShareBufMutex.lock_timeout(kA2MBufLockTimeout);
ALOGD("%s()", __FUNCTION__);
if (rc != 0)
{
ALOGE("%s(), Cannot get Lock!! Timeout : %u msec", __FUNCTION__, kA2MBufLockTimeout);
return false;
}
return true;
}
void SpeechMessengerCCCI::A2MBufUnLock()
{
mA2MShareBufMutex.unlock();
ALOGD("%s()", __FUNCTION__);
}
bool SpeechMessengerCCCI::SpeechParamLock()
{
const uint32_t kSphParamLockTimeout = 10000; // 10 sec
ALOGD("%s()", __FUNCTION__);
int rc = mSetSpeechParamMutex.lock_timeout(kSphParamLockTimeout);
if (rc != 0)
{
ALOGE("%s(), Cannot get Lock!! Timeout : %u msec", __FUNCTION__, kSphParamLockTimeout);
return false;
}
return true;
}
void SpeechMessengerCCCI::SpeechParamUnLock()
{
ALOGD("%s()", __FUNCTION__);
mSetSpeechParamMutex.unlock();
}
void SpeechMessengerCCCI::ResetSpeechParamAckCount()
{
memset(&mSpeechParamAckCount, 0, sizeof(mSpeechParamAckCount));
ALOGD("%s(), NB(%u)/DMNR(%u)/WB(%u)", __FUNCTION__,
mSpeechParamAckCount[NB_SPEECH_PARAM],
mSpeechParamAckCount[DMNR_SPEECH_PARAM],
mSpeechParamAckCount[WB_SPEECH_PARAM]);
}
void SpeechMessengerCCCI::AddSpeechParamAckCount(speech_param_ack_t type)
{
if (type >= NUM_SPEECH_PARAM_ACK_TYPE || type < 0)
{
ALOGE("%s(), no such type: %d", __FUNCTION__, type);
}
else
{
if (mSpeechParamAckCount[type] < 0xFFFFFFFF) //prevent overflow
{
mSpeechParamAckCount[type]++;
}
ALOGD("%s(%d), NB(%u)/DMNR(%u)/WB(%u)", __FUNCTION__, type,
mSpeechParamAckCount[NB_SPEECH_PARAM],
mSpeechParamAckCount[DMNR_SPEECH_PARAM],
mSpeechParamAckCount[WB_SPEECH_PARAM]);
}
}
bool SpeechMessengerCCCI::CheckSpeechParamAckAllArrival()
{
bool ret = true;
// Get SpeechParamLock
if (SpeechParamLock() == false)
{
ALOGE("%s() fail to get SpeechParamLock!!", __FUNCTION__);
return false;
}
if (mSpeechParamAckCount[NB_SPEECH_PARAM] == 0) { ret = false; }
#if defined(MTK_DUAL_MIC_SUPPORT)
if (mSpeechParamAckCount[DMNR_SPEECH_PARAM] == 0) { ret = false; }
#endif
#if defined(MTK_WB_SPEECH_SUPPORT)
if (mSpeechParamAckCount[WB_SPEECH_PARAM] == 0) { ret = false; }
#endif
if (ret == true)
{
ALOGD("%s() Pass", __FUNCTION__);
}
else
{
ALOGE("%s() Fail, NB(%u)/DMNR(%u)/WB(%u)", __FUNCTION__,
mSpeechParamAckCount[NB_SPEECH_PARAM],
mSpeechParamAckCount[DMNR_SPEECH_PARAM],
mSpeechParamAckCount[WB_SPEECH_PARAM]);
// Send speech parameters to modem side again
mLad->SetAllSpeechEnhancementInfoToModem();
}
// Release SpeechParamLock
SpeechParamUnLock();
return ret;
}
/** Do error handling here */
void SpeechMessengerCCCI::SendMsgFailErrorHandling(const ccci_buff_t &ccci_buff)
{
ALOGE("%s(), message: 0x%x", __FUNCTION__, ccci_buff.message);
switch (GetMessageID(ccci_buff))
{
case MSG_A2M_SET_SPH_MODE:
{
// Do nothing...
break;
}
case MSG_A2M_SPH_ON:
{
phone_call_mode_t phone_call_mode = (phone_call_mode_t)GetMessageParam(ccci_buff);
if (phone_call_mode == RAT_3G324M_MODE)
{
SetModemSideModemStatus(VT_STATUS_MASK);
}
else
{
SetModemSideModemStatus(SPEECH_STATUS_MASK);
}
mLad->Signal();
break;
}
case MSG_A2M_SPH_OFF:
{
if (GetModemSideModemStatus(VT_STATUS_MASK) == true)
{
ResetModemSideModemStatus(VT_STATUS_MASK);
}
else if (GetModemSideModemStatus(SPEECH_STATUS_MASK) == true)
{
ResetModemSideModemStatus(SPEECH_STATUS_MASK);
}
else
{
ALOGE("--SpeechOff Ack is not paired!!");
}
mLad->Signal();
break;
}
#ifdef SPEECH_PCM_VM_SUPPORT
case MSG_A2M_PCM_REC_ON:
{
SetModemSideModemStatus(RECORD_STATUS_MASK);
break;
}
case MSG_A2M_PCM_REC_OFF:
{
if (GetModemSideModemStatus(RECORD_STATUS_MASK) == true)
{
ResetModemSideModemStatus(RECORD_STATUS_MASK);
}
else
{
ALOGE("--RecordOff Ack is not paired!!");
}
break;
}
case MSG_A2M_VM_REC_ON:
{
SetModemSideModemStatus(VM_RECORD_STATUS_MASK);
break;
}
case MSG_A2M_VM_REC_OFF:
{
if (GetModemSideModemStatus(VM_RECORD_STATUS_MASK) == true)
{
ResetModemSideModemStatus(VM_RECORD_STATUS_MASK);
}
else
{
ALOGE("--VMRecordOff Ack is not paired!!");
}
break;
}
#else
case MSG_A2M_RECORD_ON:
{
SetModemSideModemStatus(RECORD_STATUS_MASK);
break;
}
case MSG_A2M_RECORD_OFF:
{
if (GetModemSideModemStatus(RECORD_STATUS_MASK) == true)
{
ResetModemSideModemStatus(RECORD_STATUS_MASK);
}
else
{
ALOGE("--RecordOff Ack is not paired!!");
}
break;
}
#endif
case MSG_A2M_BGSND_ON:
{
SetModemSideModemStatus(BGS_STATUS_MASK);
break;
}
case MSG_A2M_BGSND_OFF:
{
if (GetModemSideModemStatus(BGS_STATUS_MASK) == true)
{
ResetModemSideModemStatus(BGS_STATUS_MASK);
}
else
{
ALOGE("--BGSoundOff Ack is not paired!!");
}
break;
}
case MSG_A2M_PNW_ON:
case MSG_A2M_DMNR_RECPLAY_ON:
case MSG_A2M_DMNR_REC_ONLY_ON:
{
SetModemSideModemStatus(P2W_STATUS_MASK);
break;
}
case MSG_A2M_PNW_OFF:
case MSG_A2M_DMNR_RECPLAY_OFF:
case MSG_A2M_DMNR_REC_ONLY_OFF:
{
if (GetModemSideModemStatus(P2W_STATUS_MASK) == true)
{
ResetModemSideModemStatus(P2W_STATUS_MASK);
}
else
{
ALOGE("--PCM2WayOff Ack is not paired!!");
}
break;
}
case MSG_A2M_CTM_ON:
{
SetModemSideModemStatus(TTY_STATUS_MASK);
break;
}
case MSG_A2M_CTM_OFF:
{
if (GetModemSideModemStatus(TTY_STATUS_MASK) == true)
{
ResetModemSideModemStatus(TTY_STATUS_MASK);
}
else
{
ALOGE("--TtyCtmOff Ack is not paired!!");
}
break;
}
case MSG_A2M_SET_ACOUSTIC_LOOPBACK:
{
const bool loopback_on = GetMessageParam(ccci_buff) & 0x1;
if (loopback_on == true) // loopback on
{
SetModemSideModemStatus(LOOPBACK_STATUS_MASK);
}
else // loopback off
{
if (GetModemSideModemStatus(LOOPBACK_STATUS_MASK) == true)
{
ResetModemSideModemStatus(LOOPBACK_STATUS_MASK);
}
else
{
ALOGE("--SetAcousticLoopback Ack is not paired!!");
}
}
mLad->Signal();
break;
}
case MSG_A2M_EM_NB:
case MSG_A2M_EM_WB:
case MSG_A2M_EM_DMNR:
{
A2MBufUnLock();
break;
}
default:
{
ALOGW("%s(), message: 0x%x, ack don't care", __FUNCTION__, ccci_buff.message);
}
}
}
RingBuf SpeechMessengerCCCI::GetM2AUplinkRingBuffer(const ccci_buff_t &ccci_buff)
{
// check MD side data msg format
CheckOffsetAndLength(ccci_buff);
RingBuf ul_ring_buf;
ul_ring_buf.bufLen = mM2AShareBufLen;
ul_ring_buf.pBufBase = mM2AShareBufBase;
ul_ring_buf.pRead = ul_ring_buf.pBufBase + GetMessageOffset(ccci_buff);
if (ul_ring_buf.pRead >= mM2AShareBufEnd) { ul_ring_buf.pRead -= ul_ring_buf.bufLen; }
ul_ring_buf.pWrite = ul_ring_buf.pRead + GetMessageLength(ccci_buff);
if (ul_ring_buf.pWrite >= mM2AShareBufEnd) { ul_ring_buf.pWrite -= ul_ring_buf.bufLen; }
// share buffer header
char *p_sync_word = ul_ring_buf.pRead + 0; // 0 * size(unsigned short)
char *p_data_type = ul_ring_buf.pRead + 2; // 1 * size(unsigned short)
char *p_data_len = ul_ring_buf.pRead + 4; // 2 * size(unsigned short)
if (p_data_type >= mM2AShareBufEnd) { p_data_type -= ul_ring_buf.bufLen; }
if (p_data_len >= mM2AShareBufEnd) { p_data_len -= ul_ring_buf.bufLen; }
SLOGV("CCCI get uplink data from modem. message = 0x%x, sync = 0x%x, type = 0x%x, data_len = %d",
ccci_buff.message, *(uint16_t *)p_sync_word, *(uint16_t *)p_data_type, *(uint16_t *)p_data_len);
ASSERT(*(uint16_t *)p_sync_word == CCCI_M2A_SHARE_BUFF_HEADER_SYNC);
ul_ring_buf.pRead += CCCI_SHARE_BUFF_HEADER_LEN;
if (ul_ring_buf.pRead >= mM2AShareBufEnd) { ul_ring_buf.pRead -= ul_ring_buf.bufLen; }
#if 0
uint16_t count = *(uint16_t *)p_data_len;
if (ul_ring_buf.pRead <= ul_ring_buf.pWrite)
{
fwrite((void *)ul_ring_buf.pRead, sizeof(char), count, mLad->fp);
}
else
{
char *end = ul_ring_buf.pBufBase + ul_ring_buf.bufLen;
int r2e = end - ul_ring_buf.pRead;
if (count <= r2e)
{
fwrite((void *)ul_ring_buf.pRead, sizeof(char), count, mLad->fp);
}
else
{
fwrite((void *)ul_ring_buf.pRead, sizeof(char), r2e, mLad->fp);
fwrite((void *)ul_ring_buf.pBufBase, sizeof(char), count - r2e, mLad->fp);
}
}
#endif
return ul_ring_buf;
}
RingBuf SpeechMessengerCCCI::GetM2ACtmRingBuffer(const ccci_buff_t &ccci_buff)
{
// check MD side data msg format
CheckOffsetAndLength(ccci_buff);
RingBuf ul_ring_buf;
ul_ring_buf.bufLen = mM2AShareBufLen;
ul_ring_buf.pBufBase = mM2AShareBufBase;
ul_ring_buf.pRead = ul_ring_buf.pBufBase + GetMessageOffset(ccci_buff);
if (ul_ring_buf.pRead >= mM2AShareBufEnd) { ul_ring_buf.pRead -= ul_ring_buf.bufLen; }
// share buffer header
char *p_sync_word = ul_ring_buf.pRead + 0; // 0 * size(unsigned short)
char *p_data_type = ul_ring_buf.pRead + 2; // 1 * size(unsigned short)
char *p_data_len = ul_ring_buf.pRead + 4; // 2 * size(unsigned short)
if (p_data_type >= mM2AShareBufEnd) { p_data_type -= ul_ring_buf.bufLen; }
if (p_data_len >= mM2AShareBufEnd) { p_data_len -= ul_ring_buf.bufLen; }
SLOGV("CCCI get uplink data from modem. message = 0x%x, sync = 0x%x, type = 0x%x, data_len = %d",
ccci_buff.message, *(uint16_t *)p_sync_word, *(uint16_t *)p_data_type, *(uint16_t *)p_data_len);
ASSERT(*(uint16_t *)p_sync_word == CCCI_M2A_SHARE_BUFF_HEADER_SYNC);
ul_ring_buf.pRead += CCCI_SHARE_BUFF_HEADER_LEN;
if (ul_ring_buf.pRead >= mM2AShareBufEnd) { ul_ring_buf.pRead -= ul_ring_buf.bufLen; }
ul_ring_buf.pWrite = ul_ring_buf.pRead + GetM2AShareBufDataLength(ccci_buff);
if (ul_ring_buf.pWrite >= mM2AShareBufEnd) { ul_ring_buf.pWrite -= ul_ring_buf.bufLen; }
return ul_ring_buf;
}
uint16_t SpeechMessengerCCCI::GetM2AShareBufSyncWord(const ccci_buff_t &ccci_buff)
{
char *p_sync_word = GetM2AShareBufBase() + GetMessageOffset(ccci_buff) + 0; // 0 * size(unsigned short)
if (p_sync_word >= mM2AShareBufEnd) { p_sync_word -= mM2AShareBufLen; }
SLOGV("%s(), sync = 0x%x", __FUNCTION__, *(uint16_t *)p_sync_word);
return *(uint16_t *)p_sync_word;
}
uint16_t SpeechMessengerCCCI::GetM2AShareBufDataType(const ccci_buff_t &ccci_buff)
{
char *p_data_type = GetM2AShareBufBase() + GetMessageOffset(ccci_buff) + 2; // 1 * size(unsigned short)
if (p_data_type >= mM2AShareBufEnd) { p_data_type -= mM2AShareBufLen; }
SLOGV("%s(), type = 0x%x", __FUNCTION__, *(uint16_t *)p_data_type);
return *(uint16_t *)p_data_type;
}
uint16_t SpeechMessengerCCCI::GetM2AShareBufDataLength(const ccci_buff_t &ccci_buff)
{
char *p_data_len = GetM2AShareBufBase() + GetMessageOffset(ccci_buff) + 4; // 2 * size(unsigned short)
if (p_data_len >= mM2AShareBufEnd) { p_data_len -= mM2AShareBufLen; }
SLOGV("%s(), data_len = %d", __FUNCTION__, *(uint16_t *)p_data_len);
return *(uint16_t *)p_data_len;
}
bool SpeechMessengerCCCI::GetModemSideModemStatus(const modem_status_mask_t modem_status_mask) const
{
return ((mModemSideModemStatus & modem_status_mask) > 0);
}
void SpeechMessengerCCCI::SetModemSideModemStatus(const modem_status_mask_t modem_status_mask)
{
mModemSideModemStatus |= modem_status_mask;
// save mModemSideModemStatus in property to avoid medieserver die
char property_value[PROPERTY_VALUE_MAX];
sprintf(property_value, "%u", mModemSideModemStatus);
property_set(PROPERTY_KEY_MODEM_STATUS[mModemIndex], property_value);
}
void SpeechMessengerCCCI::ResetModemSideModemStatus(const modem_status_mask_t modem_status_mask)
{
mModemSideModemStatus &= (~modem_status_mask);
// save mModemSideModemStatus in property to avoid medieserver die
char property_value[PROPERTY_VALUE_MAX];
sprintf(property_value, "%u", mModemSideModemStatus);
property_set(PROPERTY_KEY_MODEM_STATUS[mModemIndex], property_value);
}
} // end of namespace android
| [
"idontknw.wang@gmail.com"
] | idontknw.wang@gmail.com |
40cbcc8ae05de72234725a3264c1beead351aeb0 | 51973d4f0b22d6b82416ab4c8e36ebf79d5efede | /hpctoolkit/src/tool/hpcrun/cct/cct_dump.h | d68d1a42ca2f56ba486fb84afbf0865c592dd9fd | [] | no_license | proywm/ccprof_hpctoolkit_deps | a18df3c3701c41216d74dca54f957e634ac7c2ed | 62d86832ecbe41b5d7a9fb5254eb2b202982b4ed | refs/heads/master | 2023-03-29T21:41:21.412066 | 2021-04-08T17:11:19 | 2021-04-08T17:11:19 | 355,986,924 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 2,969 | h | // -*-Mode: C++;-*- // technically C99
// * BeginRiceCopyright *****************************************************
//
// $HeadURL$
// $Id$
//
// --------------------------------------------------------------------------
// Part of HPCToolkit (hpctoolkit.org)
//
// Information about sources of support for research and development of
// HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
// --------------------------------------------------------------------------
//
// Copyright ((c)) 2002-2017, Rice University
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Rice University (RICE) nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// This software is provided by RICE and contributors "as is" and any
// express or implied warranties, including, but not limited to, the
// implied warranties of merchantability and fitness for a particular
// purpose are disclaimed. In no event shall RICE or contributors be
// liable for any direct, indirect, incidental, special, exemplary, or
// consequential damages (including, but not limited to, procurement of
// substitute goods or services; loss of use, data, or profits; or
// business interruption) however caused and on any theory of liability,
// whether in contract, strict liability, or tort (including negligence
// or otherwise) arising in any way out of the use of this software, even
// if advised of the possibility of such damage.
//
// ******************************************************* EndRiceCopyright *
#ifndef CCT_DUMP_H
#define CCT_DUMP_H
#ifndef _FLG
#define _FLG CCT
#endif
#include <stdint.h>
#include <cct/cct.h>
#include <messages/messages.h>
#define TLIM 1
#ifndef TLIM
#define TL(E) E
#define TLS(S) S
#else
#include <hpcrun/thread_data.h>
#define TL(E) ((TD_GET(id) == TLIM) && (E))
#define TLS(S) if (TD_GET(id) == TLIM) S
#endif
#define TF(_FLG, ...) TMSG(_FLG, __VA_ARGS__)
static void
l_dump(cct_node_t* node, cct_op_arg_t arg, size_t level)
{
char p[level+1];
if (! node) return;
memset(&p[0], ' ', level);
p[level] = '\0';
int32_t id = hpcrun_cct_persistent_id(node);
cct_addr_t* adr = hpcrun_cct_addr(node);
TF(_FLG, "%s[%d: (%d, %p)]", &p[0], id,
adr->ip_norm.lm_id, adr->ip_norm.lm_ip);
}
static void
dump_cct(cct_node_t* cct)
{
hpcrun_cct_walk_node_1st(cct, l_dump, NULL);
}
#endif // CCT_DUMP_H
| [
"proy@email.wm.edu"
] | proy@email.wm.edu |
79d79548d8f81ff328ac7c8f4c6c83e525d84e40 | 2f9c494c11bd9557dd290b5b72746a835439fe2e | /POJ/uestczhangchao/1002/3273651_WA.cpp | 18827748b165fe6cd1b88b3effbe1fe9f5dfe186 | [] | no_license | aktiger/C-CPP | 57d6321044dc1f9088e179bef3e1f8f5f43a0e66 | 4cec3a56e6572b7025d7cc40103aa2e6622a5154 | refs/heads/master | 2021-01-02T09:08:20.316019 | 2018-07-13T06:28:38 | 2018-07-13T06:28:38 | 5,459,529 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 996 | cpp | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int flag=0;
vector<int> intvec;
char ss,c;
int N,temp;
cin>>N;
c = cin.get();
for(int i=0;i<N;i++)
{
temp=0;
while((ss=cin.get())!='\n')
{
if (ss>='0' && ss<='9')
{
temp=temp*10+(ss-'0');
}
else if(ss>='A' && ss<'Q')
{
temp=temp*10+(ss-'A')/3+2;
}
else if(ss>'Q' && ss<'Z')
{
temp=temp*10+(ss-'Q')/3+7;
}
}
intvec.push_back(temp);
}
sort(intvec.begin(),intvec.end());
int count,tmp;
unsigned int it=0;
for(it=0;it<intvec.size();it++)
{
count=1;
tmp=intvec[it];
if(it>=intvec.size())
{
break;
}
while(it+1<intvec.size() && intvec[it]==intvec[it+1])
{
count++;
it++;
}
if(count>1)
{
if(!flag) flag=1;
cout.width(3);
cout<<tmp/10000;
cout<<"-";
cout.width(4);
cout<<tmp%10000;
cout<<" "<<count<<endl;
count=1;
}
}
if(!flag)
cout<<"No duplicates."<<endl;
return 0;
} | [
"uestczhangchao@gmail.com"
] | uestczhangchao@gmail.com |
2a1b0874fdf89c1d30864373404b5436050101cb | 9feadb0cf03115738eb0bda9e6ab259e965072a9 | /Threading/Threading-build-desktop/debug/moc_modbus_rtu.cpp | 84ee97a7adac5e4a15e136ded6f8c13248d2a804 | [] | no_license | nowhard/uUSO_CONFIG_QT | 080a67cab31d1962866441cc981692088d3c8c4e | af287780570f90b56bc64e04241ad301f1f750d4 | refs/heads/master | 2020-03-31T00:26:23.402904 | 2013-12-10T06:37:03 | 2013-12-10T06:37:03 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,599 | cpp | /****************************************************************************
** Meta object code from reading C++ file 'modbus_rtu.h'
**
** Created: Tue 18. Oct 13:57:49 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../../Threading/modbus_rtu.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'modbus_rtu.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 62
#error "This file was generated using the moc from 4.7.0. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_Modbus_RTU[] = {
// content:
5, // revision
0, // classname
0, 0, // classinfo
11, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
10, // signalCount
// signals: signature, parameters, type, tag, flags
15, 12, 11, 11, 0x05,
28, 12, 11, 11, 0x05,
47, 12, 11, 11, 0x05,
65, 11, 11, 11, 0x05,
83, 11, 11, 11, 0x05,
101, 11, 11, 11, 0x05,
130, 124, 11, 11, 0x05,
155, 151, 11, 11, 0x05,
184, 174, 11, 11, 0x05,
223, 215, 11, 11, 0x05,
// slots: signature, parameters, type, tag, flags
262, 253, 11, 11, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_Modbus_RTU[] = {
"Modbus_RTU\0\0OK\0CRC_OK(bool)\0"
"WRITE_REG_OK(bool)\0READ_REG_OK(bool)\0"
"UNCNOWN_COMMAND()\0NOT_IMPLEMENTED()\0"
"DEVICE_NOT_CONNECTED()\0point\0"
"CALIBRATE_OK(quint8)\0reg\0IsRead(QByteArray)\0"
"reg,value\0IsRead(MB_Register,QByteArray)\0"
"request\0WriteToOut_Thread(QByteArray)\0"
"response\0ResponseHandling(QByteArray)\0"
};
const QMetaObject Modbus_RTU::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_Modbus_RTU,
qt_meta_data_Modbus_RTU, 0 }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &Modbus_RTU::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *Modbus_RTU::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *Modbus_RTU::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_Modbus_RTU))
return static_cast<void*>(const_cast< Modbus_RTU*>(this));
return QObject::qt_metacast(_clname);
}
int Modbus_RTU::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: CRC_OK((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 1: WRITE_REG_OK((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 2: READ_REG_OK((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 3: UNCNOWN_COMMAND(); break;
case 4: NOT_IMPLEMENTED(); break;
case 5: DEVICE_NOT_CONNECTED(); break;
case 6: CALIBRATE_OK((*reinterpret_cast< quint8(*)>(_a[1]))); break;
case 7: IsRead((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
case 8: IsRead((*reinterpret_cast< MB_Register(*)>(_a[1])),(*reinterpret_cast< QByteArray(*)>(_a[2]))); break;
case 9: WriteToOut_Thread((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
case 10: ResponseHandling((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
default: ;
}
_id -= 11;
}
return _id;
}
// SIGNAL 0
void Modbus_RTU::CRC_OK(bool _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
// SIGNAL 1
void Modbus_RTU::WRITE_REG_OK(bool _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 1, _a);
}
// SIGNAL 2
void Modbus_RTU::READ_REG_OK(bool _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 2, _a);
}
// SIGNAL 3
void Modbus_RTU::UNCNOWN_COMMAND()
{
QMetaObject::activate(this, &staticMetaObject, 3, 0);
}
// SIGNAL 4
void Modbus_RTU::NOT_IMPLEMENTED()
{
QMetaObject::activate(this, &staticMetaObject, 4, 0);
}
// SIGNAL 5
void Modbus_RTU::DEVICE_NOT_CONNECTED()
{
QMetaObject::activate(this, &staticMetaObject, 5, 0);
}
// SIGNAL 6
void Modbus_RTU::CALIBRATE_OK(quint8 _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 6, _a);
}
// SIGNAL 7
void Modbus_RTU::IsRead(QByteArray _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 7, _a);
}
// SIGNAL 8
void Modbus_RTU::IsRead(MB_Register _t1, QByteArray _t2)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)) };
QMetaObject::activate(this, &staticMetaObject, 8, _a);
}
// SIGNAL 9
void Modbus_RTU::WriteToOut_Thread(QByteArray _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 9, _a);
}
QT_END_MOC_NAMESPACE
| [
"nowhard@mail.ru"
] | nowhard@mail.ru |
4c7abfa60e34fea266be39f9228248bf924941b7 | 623205b559afa3df6cf4079f7da3fef65cd31912 | /subprojects/amrex/Src/EB/AMReX_EBFluxRegister.cpp | aaeb255d18f046f552b28eb8280897e0ad54d689 | [
"BSD-2-Clause"
] | permissive | jmusser304/BoltzmannMFX | 3591e1b4ca4982d702d23dc3cf785bb7ad1cbfd3 | 7919dca5381bef208b8a77ea9b1776b66ab4abd7 | refs/heads/main | 2023-03-09T17:30:57.455267 | 2021-03-01T19:59:53 | 2021-03-01T19:59:53 | 343,540,966 | 0 | 0 | null | 2021-03-01T20:01:29 | 2021-03-01T20:01:28 | null | UTF-8 | C++ | false | false | 12,557 | cpp |
#include <AMReX_EBFluxRegister.H>
#include <AMReX_EBFluxRegister_C.H>
#include <AMReX_EBFArrayBox.H>
#ifdef AMREX_USE_OMP
#include <omp.h>
#endif
#ifdef BL_NO_FORT
namespace {
amrex::Real amrex_reredistribution_threshold = 1.e-14;
}
extern "C" {
void amrex_eb_disable_reredistribution () { amrex_reredistribution_threshold = 1.e10; }
amrex::Real amrex_eb_get_reredistribution_threshold () { return amrex_reredistribution_threshold; }
}
#endif
namespace amrex {
EBFluxRegister::EBFluxRegister (const BoxArray& fba, const BoxArray& cba,
const DistributionMapping& fdm, const DistributionMapping& cdm,
const Geometry& fgeom, const Geometry& cgeom,
const IntVect& ref_ratio, int fine_lev, int nvar)
: YAFluxRegister(fba,cba,fdm,cdm,fgeom,cgeom,ref_ratio,fine_lev,nvar)
{
defineExtra(fba, fdm);
}
void
EBFluxRegister::define (const BoxArray& fba, const BoxArray& cba,
const DistributionMapping& fdm, const DistributionMapping& cdm,
const Geometry& fgeom, const Geometry& cgeom,
const IntVect& ref_ratio, int fine_lev, int nvar)
{
YAFluxRegister::define(fba,cba,fdm,cdm,fgeom,cgeom,ref_ratio,fine_lev,nvar);
defineExtra(fba, fdm);
}
void
EBFluxRegister::defineExtra (const BoxArray& fba, const DistributionMapping& fdm)
{
BoxArray cfba = fba;
cfba.coarsen(m_ratio);
m_cfp_inside_mask.define(cfba, fdm, 1, 0, MFInfo(),DefaultFabFactory<IArrayBox>());
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(m_cfp_inside_mask); mfi.isValid(); ++mfi)
{
const Box& ifabbox = mfi.fabbox();
auto const& ifab = m_cfp_inside_mask.array(mfi);
AMREX_HOST_DEVICE_PARALLEL_FOR_3D(ifabbox, i, j, k,
{
ifab(i,j,k) = 0;
});
const int li = mfi.LocalIndex();
const auto& cfp_fabs = m_cfp_fab[li];
for (const FArrayBox* cfp : cfp_fabs)
{
const Box& bx = amrex::grow(cfp->box(), 1);
const Box& ibx = bx & ifabbox;
AMREX_HOST_DEVICE_PARALLEL_FOR_3D(ibx, i, j, k,
{
ifab(i,j,k) = 1; // cells just inside crse/fine boundary
});
}
}
}
void
EBFluxRegister::CrseAdd (const MFIter& mfi,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& flux,
const Real* dx, Real dt,
const FArrayBox& volfrac,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& areafrac,
RunOn runon)
{
BL_ASSERT(m_crse_data.nComp() == flux[0]->nComp());
if (m_crse_fab_flag[mfi.LocalIndex()] == crse_cell) {
return; // this coarse fab is not close to fine fabs.
}
Array4<Real> const& fab = m_crse_data.array(mfi);
const Box& bx = mfi.tilebox();
Array4<int const> const& amrflag = m_crse_flag.array(mfi);
AMREX_D_TERM(Real dtdx = dt/dx[0];,
Real dtdy = dt/dx[1];,
Real dtdz = dt/dx[2];);
AMREX_D_TERM(Array4<Real const> const& fx = flux[0]->const_array();,
Array4<Real const> const& fy = flux[1]->const_array();,
Array4<Real const> const& fz = flux[2]->const_array(););
AMREX_D_TERM(Array4<Real const> const& apx = areafrac[0]->const_array();,
Array4<Real const> const& apy = areafrac[1]->const_array();,
Array4<Real const> const& apz = areafrac[2]->const_array(););
Array4<Real const> const& vfrac = volfrac.const_array();
AMREX_HOST_DEVICE_FOR_3D_FLAG(runon, bx, i, j, k,
{
eb_flux_reg_crseadd_va(i,j,k,fab,amrflag,AMREX_D_DECL(fx,fy,fz),
vfrac,AMREX_D_DECL(apx,apy,apz),
AMREX_D_DECL(dtdx,dtdy,dtdz));
});
}
void
EBFluxRegister::FineAdd (const MFIter& mfi,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& a_flux,
const Real* dx, Real dt,
const FArrayBox& volfrac,
const std::array<FArrayBox const*, AMREX_SPACEDIM>& areafrac,
const FArrayBox& dm,
RunOn runon)
{
BL_ASSERT(m_cfpatch.nComp() == a_flux[0]->nComp());
const int li = mfi.LocalIndex();
Vector<FArrayBox*>& cfp_fabs = m_cfp_fab[li];
if (cfp_fabs.empty()) return;
const int nc = m_cfpatch.nComp();
const Box& tbx = mfi.tilebox();
BL_ASSERT(tbx.cellCentered());
const Box& cbx = amrex::coarsen(tbx, m_ratio);
AMREX_D_TERM(Array4<Real const> const& fx = a_flux[0]->const_array();,
Array4<Real const> const& fy = a_flux[1]->const_array();,
Array4<Real const> const& fz = a_flux[2]->const_array(););
Array4<Real const> const& vfrac = volfrac.const_array();
AMREX_D_TERM(Array4<Real const> const& apx = areafrac[0]->const_array();,
Array4<Real const> const& apy = areafrac[1]->const_array();,
Array4<Real const> const& apz = areafrac[2]->const_array(););
Dim3 ratio = m_ratio.dim3();
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
{
Real fac = dt/dx[idim];
const Box& lobx = amrex::adjCellLo(cbx, idim);
const Box& hibx = amrex::adjCellHi(cbx, idim);
for (FArrayBox* cfp : cfp_fabs)
{
Array4<Real> const& cfa = cfp->array();
const Box& lobx_is = lobx & cfp->box();
if (lobx_is.ok()) {
if (idim == 0)
{
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon,lobx_is,nc,i,j,k,n,
{
eb_flux_reg_fineadd_va_xlo(i,j,k,n, cfa, fx, vfrac, apx, fac, ratio);
});
}
#if (AMREX_SPACEDIM >= 2)
else if (idim == 1)
{
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon,lobx_is,nc,i,j,k,n,
{
eb_flux_reg_fineadd_va_ylo(i,j,k,n, cfa, fy, vfrac, apy, fac, ratio);
});
}
#if (AMREX_SPACEDIM == 3)
else
{
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon,lobx_is,nc,i,j,k,n,
{
eb_flux_reg_fineadd_va_zlo(i,j,k,n, cfa, fz, vfrac, apz, fac, ratio);
});
}
#endif
#endif
}
const Box& hibx_is = hibx & cfp->box();
if (hibx_is.ok()) {
if (idim == 0)
{
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon,hibx_is,nc,i,j,k,n,
{
eb_flux_reg_fineadd_va_xhi(i,j,k,n, cfa, fx, vfrac, apx, fac, ratio);
});
}
#if (AMREX_SPACEDIM >= 2)
else if (idim == 1)
{
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon,hibx_is,nc,i,j,k,n,
{
eb_flux_reg_fineadd_va_yhi(i,j,k,n, cfa, fy, vfrac, apy, fac, ratio);
});
}
#if (AMREX_SPACEDIM == 3)
else
{
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon,hibx_is,nc,i,j,k,n,
{
eb_flux_reg_fineadd_va_zhi(i,j,k,n, cfa, fz, vfrac, apz, fac, ratio);
});
}
#endif
#endif
}
}
}
Real threshold = amrex_eb_get_reredistribution_threshold()*(AMREX_D_TERM(ratio.x,*ratio.y,*ratio.z));
const Box& tbxg1 = amrex::grow(tbx,1);
const Box& cbxg1 = amrex::grow(cbx,1);
Array4<Real const> const& dma = dm.const_array();
for (FArrayBox* cfp : cfp_fabs)
{
const Box& wbx = cbxg1 & cfp->box();
if (wbx.ok())
{
Array4<Real> const& cfa = cfp->array();
AMREX_HOST_DEVICE_FOR_4D_FLAG(runon, wbx, nc, i, j, k, n,
{
eb_flux_reg_fineadd_dm(i,j,k,n,tbxg1, cfa, dma, vfrac, ratio, threshold);
});
}
}
}
void
EBFluxRegister::Reflux (MultiFab& crse_state, const amrex::MultiFab& crse_vfrac,
MultiFab& fine_state, const amrex::MultiFab& /*fine_vfrac*/)
{
if (!m_cfp_mask.empty())
{
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(m_cfpatch); mfi.isValid(); ++mfi)
{
Array4<Real> const& cfa = m_cfpatch.array(mfi);
Array4<Real const> const& m = m_cfp_mask.const_array(mfi);
const Box& bx = mfi.fabbox();
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx,m_ncomp,i,j,k,n,
{
cfa(i,j,k,n) *= m(i,j,k);
});
}
}
m_crse_data.ParallelCopy(m_cfpatch, m_crse_geom.periodicity(), FabArrayBase::ADD);
{
MultiFab grown_crse_data(m_crse_data.boxArray(), m_crse_data.DistributionMap(),
m_ncomp, 1, MFInfo(), FArrayBoxFactory());
MultiFab::Copy(grown_crse_data, m_crse_data, 0, 0, m_ncomp, 0);
grown_crse_data.FillBoundary(m_crse_geom.periodicity());
m_crse_data.setVal(0.0);
auto const& factory = dynamic_cast<EBFArrayBoxFactory const&>(crse_state.Factory());
auto const& flags = factory.getMultiEBCellFlagFab();
const Box& gdomain = m_crse_geom.growPeriodicDomain(1);
MFItInfo info;
if (Gpu::notInLaunchRegion()) info.EnableTiling().SetDynamic(true);
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(m_crse_data, info); mfi.isValid(); ++mfi)
{
if (m_crse_fab_flag[mfi.LocalIndex()] == fine_cell) // fab has crse/fine cells
{
const Box& bx = mfi.tilebox();
const auto& ebflag = flags[mfi];
if (ebflag.getType(bx) != FabType::covered) {
const Box& bxg1 = amrex::grow(bx,1) & gdomain;
Array4<Real> const& dfab = m_crse_data.array(mfi);
Array4<Real const> const& sfab = grown_crse_data.const_array(mfi);
if (ebflag.getType(bxg1) == FabType::regular)
{
// no re-reflux or re-re-redistribution
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, m_ncomp, i, j, k, n,
{
dfab(i,j,k,n) += sfab(i,j,k,n);
});
}
else
{
Array4<int const> const& amrflag = m_crse_flag.const_array(mfi);
Array4<EBCellFlag const> const& ebflagarr = ebflag.const_array();
Array4<Real const> const& cvol = crse_vfrac.const_array(mfi);
AMREX_HOST_DEVICE_FOR_4D(bxg1, m_ncomp, i, j, k, n,
{
eb_rereflux_from_crse(i,j,k,n,bx,dfab,sfab,amrflag,ebflagarr,cvol);
});
}
}
}
}
}
MultiFab::Add(crse_state, m_crse_data, 0, 0, m_ncomp, 0);
// The fine-covered cells of m_crse_data contain the data that should go to the fine level
BoxArray ba = fine_state.boxArray();
ba.coarsen(m_ratio);
MultiFab cf(ba, fine_state.DistributionMap(), m_ncomp, 0, MFInfo(), FArrayBoxFactory());
cf.ParallelCopy(m_crse_data);
auto const& factory = dynamic_cast<EBFArrayBoxFactory const&>(fine_state.Factory());
auto const& flags = factory.getMultiEBCellFlagFab();
Dim3 ratio = m_ratio.dim3();
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(cf,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const Box& cbx = mfi.tilebox();
const Box& fbx = amrex::refine(cbx, m_ratio);
const auto& ebflag = flags[mfi];
if (ebflag.getType(fbx) != FabType::covered)
{
Array4<Real> const& d = fine_state.array(mfi);
Array4<Real const> const& s = cf.const_array(mfi);
Array4<int const> const& m = m_cfp_inside_mask.const_array(mfi);
AMREX_HOST_DEVICE_FOR_4D(fbx,m_ncomp,i,j,k,n,
{
eb_rereflux_to_fine(i,j,k,n,d,s,m,ratio);
});
}
}
}
}
| [
"asalmgren@lbl.gov"
] | asalmgren@lbl.gov |
ab835de34774e74b4fa4e999c8cfa660032460c2 | 1e9fbdb90fa4fd3d2c97fc8a45541461ce8ec67f | /src/2016.SeaBattle/Novosad/BattleShip/View.cpp | a1c95fd97e08d66aee6118e1ebb744fc9cba542e | [] | no_license | vnobis-univ/sonarcube-test | 715168684fdd3547240db032d8ccc4d9680fff6f | f917ef2722144107cb12435021dd02574d149e39 | refs/heads/master | 2020-03-29T11:49:25.879413 | 2018-09-24T12:29:56 | 2018-09-24T12:29:56 | 149,872,507 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 243 | cpp | #include "View.h"
#include <Windows.h>
View::View()
{
}
void View::clean()
{
system("cls");
HWND hwnd = GetConsoleWindow();
RECT thisRect;
GetWindowRect(hwnd, &thisRect);
RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
}
| [
"nobisvitaliy@gmail.com"
] | nobisvitaliy@gmail.com |
77b3c711c59d88caa20344f3379d66c722b0e40c | cc3fee60ec8bd68d3d9d2940ba64745e0ff0aa93 | /src/cryptopp/validat0.cpp | 3c2e0cf55900c63617ff09fd76297492d2f1ddc8 | [
"MIT",
"GPL-3.0-only",
"BSL-1.0",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | TheLindaProjectInc/Metrix | e73e39d57b9b77ce691ed1500c39dc570e102f46 | 1612283b7f808b76207cd7a9896694fce396f1b5 | refs/heads/master | 2023-08-11T21:29:47.204066 | 2023-07-30T20:33:15 | 2023-07-30T20:33:15 | 144,792,184 | 30 | 15 | MIT | 2023-07-20T15:26:35 | 2018-08-15T01:50:20 | C++ | UTF-8 | C++ | false | false | 95,798 | cpp | // validat0.cpp - written and placed in the public domain by Wei Dai and Jeffrey Walton
// Routines in this source file are only tested in Debug builds
#include "pch.h"
#include "secblock.h"
#include "integer.h"
#include "zdeflate.h"
#include "filters.h"
#include "hex.h"
#include "asn.h"
#include <iostream>
#include <iomanip>
#include "validate.h"
// Aggressive stack checking with VS2005 SP1 and above.
#if (CRYPTOPP_MSC_VERSION >= 1410)
# pragma strict_gs_check (on)
#endif
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
USING_NAMESPACE(CryptoPP)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
struct ASN1_TestTuple
{
int disposition;
int identifier;
const char* name;
const char* data;
size_t len;
};
bool RunASN1TestSet(const ASN1_TestTuple asnTuples[], size_t count)
{
bool pass=true, fail;
// Disposition
enum {REJECT=3, ACCEPT=4};
for(size_t i=0; i<count; i++)
{
const ASN1_TestTuple & thisTest = asnTuples[i];
ArraySource as1((const byte*)thisTest.data, thisTest.len, true);
ArraySource as2((const byte*)thisTest.data, thisTest.len, true);
SecByteBlock unused1;
std::string unused2;
unsigned int unused3;
word32 unused4;
word64 unused5;
// Reporting
std::string val;
HexEncoder encoder(new StringSink(val));
encoder.Put((const byte*)thisTest.data, thisTest.len);
encoder.MessageEnd();
try
{
int tag = thisTest.identifier;
switch (tag)
{
case BIT_STRING:
BERDecodeBitString(as1, unused1, unused3);
break;
case OCTET_STRING:
BERDecodeOctetString(as1, unused1);
break;
case INTEGER:
BERDecodeUnsigned(as1, unused4);
BERDecodeUnsigned<word64>(as2, unused5, byte(INTEGER), 0, W64LIT(0xffffffffffffffff));
break;
case UTF8_STRING: case PRINTABLE_STRING: case IA5_STRING:
BERDecodeTextString(as1, unused2, (byte)tag);
break;
default:
BERGeneralDecoder(as1, (byte)tag);
break;
}
fail = !(thisTest.disposition == ACCEPT);
}
catch(const Exception&)
{
fail = !(thisTest.disposition == REJECT);
}
std::cout << (fail ? "FAILED: " : "passed: ") << (thisTest.disposition == ACCEPT ? "accept " : "reject ");
std::cout << asnTuples[i].name << " " << val << "\n";
pass = !fail && pass;
}
return pass;
}
bool TestASN1Parse()
{
std::cout << "\nTesting ASN.1 parser...\n\n";
bool pass = true;
// Disposition
enum {REJECT=3, ACCEPT=4};
// All the types Crypto++ recognizes.
// "C" is one content octet with value 0x43.
static const ASN1_TestTuple bitStrings[] =
{
// The first "\x00" content octet is the "initial octet" representing unused bits. In the
// primitive encoding form, there may be zero, one or more contents after the initial octet.
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x01" "\x00", 3}, // definite length, short form, initial octet, zero subsequent octets
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x01" "\x08", 3}, // definite length, short form, initial octet, zero subsequent octets
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x02" "\x00" "C", 4}, // definite length, short form, expected subsequent octets
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x02" "\x08" "C", 4}, // too many unused bits
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x7F" "\x00" "C", 4}, // runt or underrun
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x81\x01" "\x00", 4}, // definite length, long form, initial octet, zero subsequent octets
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x81\x01" "\x08", 4}, // definite length, long form, initial octet, zero subsequent octets
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x81\x02" "\x00" "C", 5}, // definite length, long form
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x81\x02" "\x08" "C", 5}, // too many unused bits
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x81\xff" "\x00" "C", 5}, // runt or underrun
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x82\x00\x02" "\x00" "C", 6}, // definite length, long form
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x82\x00\x02" "\x08" "C", 6}, // too many unused bits
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x82\xff\xff" "\x00" "C", 6}, // runt or underrun
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x83\x00\x00\x02" "\x00" "C", 7}, // definite length, long form
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x83\x00\x00\x02" "\x08" "C", 7}, // too many unused bits
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x83\xff\xff\xff" "\x00" "C", 7}, // runt or underrun
{ACCEPT, BIT_STRING, "BIT_STRING", "\x03\x84\x00\x00\x00\x02" "\x00" "C", 8}, // definite length, long form
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x84\x00\x00\x00\x02" "\x08" "C", 8}, // too many unused bits
{REJECT, BIT_STRING, "BIT_STRING", "\x03\x84\xff\xff\xff\xff" "\x00" "C", 8}, // <== Issue 346; requires large allocation
};
pass = RunASN1TestSet(bitStrings, COUNTOF(bitStrings)) && pass;
static const ASN1_TestTuple octetStrings[] =
{
// In the primitive encoding form, there may be zero, one or more contents.
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x00", 2}, // definite length, short form, zero content octets
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x01" "C", 3}, // definite length, short form, expected content octets
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x02" "C", 3}, // runt or underrun
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x7F" "C", 3}, // runt or underrun
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x81\x00", 3}, // definite length, long form, zero content octets
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x81\x01" "C", 4}, // definite length, long form, expected content octets
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x81\x02" "C", 4}, // runt or underrun
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x81\xff" "C", 4}, // runt or underrun
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x82\x00\x00", 4}, // definite length, long form, zero content octets
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x82\x00\x01" "C", 5}, // definite length, long form, expected content octets
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x82\x00\x02" "C", 5}, // runt or underrun
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x82\xff\xff" "C", 5}, // runt or underrun
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x83\x00\x00\x00", 5}, // definite length, long form, zero content octets
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x83\x00\x00\x01" "C", 6}, // definite length, long form, expected content octets
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x83\x00\x00\x02" "C", 6}, // runt or underrun
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x83\xff\xff\xff" "C", 6}, // runt or underrun
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x84\x00\x00\x00\x00", 6}, // definite length, long form, zero content octets
{ACCEPT, OCTET_STRING, "OCTET_STRING", "\x04\x84\x00\x00\x00\x01" "C", 7}, // definite length, long form, expected content octets
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x84\x00\x00\x00\x02" "C", 7}, // runt or underrun
{REJECT, OCTET_STRING, "OCTET_STRING", "\x04\x84\xff\xff\xff\xff" "C", 7}, // <== Issue 346; requires large allocation
};
pass = RunASN1TestSet(octetStrings, COUNTOF(octetStrings)) && pass;
static const ASN1_TestTuple utf8Strings[] =
{
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x00", 2}, // definite length, short form, zero content octets
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x01" "C", 3}, // definite length, short form, expected content octets
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x02" "C", 3}, // runt or underrun
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x7F" "C", 3}, // runt or underrun
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x81\x00", 3}, // definite length, long form, zero content octets
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x81\x01" "C", 4}, // definite length, long form, expected content octets
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x81\x02" "C", 4}, // runt or underrun
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x81\xff" "C", 4}, // runt or underrun
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x82\x00\x00", 4}, // definite length, long form, zero content octets
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x82\x00\x01" "C", 5}, // definite length, long form, expected content octets
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x82\x00\x02" "C", 5}, // runt or underrun
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x82\xff\xff" "C", 5}, // runt or underrun
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x83\x00\x00\x00", 5}, // definite length, long form, zero content octets
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x83\x00\x00\x01" "C", 6}, // definite length, long form, expected content octets
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x83\x00\x00\x02" "C", 6}, // runt or underrun
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x83\xff\xff\xff" "C", 6}, // runt or underrun
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x84\x00\x00\x00\x00", 6}, // definite length, long form, zero content octets
{ACCEPT, UTF8_STRING, "UTF8_STRING", "\x0c\x84\x00\x00\x00\x01" "C", 7}, // definite length, long form, expected content octets
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x84\x00\x00\x00\x02" "C", 7}, // runt or underrun
{REJECT, UTF8_STRING, "UTF8_STRING", "\x0c\x84\xff\xff\xff\xff" "C", 7}, // <== Issue 346; requires large allocation
};
pass = RunASN1TestSet(utf8Strings, COUNTOF(utf8Strings)) && pass;
static const ASN1_TestTuple printableStrings[] =
{
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x00", 2}, // definite length, short form, zero content octets
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x01" "C", 3}, // definite length, short form, expected content octets
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x02" "C", 3}, // runt or underrun
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x7F" "C", 3}, // runt or underrun
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x81\x00", 3}, // definite length, long form, zero content octets
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x81\x01" "C", 4}, // definite length, long form, expected content octets
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x81\x02" "C", 4}, // runt or underrun
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x81\xff" "C", 4}, // runt or underrun
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x82\x00\x00", 4}, // definite length, long form, zero content octets
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x82\x00\x01" "C", 5}, // definite length, long form, expected content octets
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x82\x00\x02" "C", 5}, // runt or underrun
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x82\xff\xff" "C", 5}, // runt or underrun
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x83\x00\x00\x00", 5}, // definite length, long form, zero content octets
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x83\x00\x00\x01" "C", 6}, // definite length, long form, expected content octets
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x83\x00\x00\x02" "C", 6}, // runt or underrun
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x83\xff\xff\xff" "C", 6}, // runt or underrun
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x84\x00\x00\x00\x00", 6}, // definite length, long form, zero content octets
{ACCEPT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x84\x00\x00\x00\x01" "C", 7}, // definite length, long form, expected content octets
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x84\x00\x00\x00\x02" "C", 7}, // runt or underrun
{REJECT, PRINTABLE_STRING, "PRINTABLE_STRING", "\x13\x84\xff\xff\xff\xff" "C", 7}, // <== Issue 346; requires large allocation
};
pass = RunASN1TestSet(printableStrings, COUNTOF(printableStrings)) && pass;
static const ASN1_TestTuple ia5Strings[] =
{
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x00", 2}, // definite length, short form, zero content octets
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x01" "C", 3}, // definite length, short form, expected content octets
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x02" "C", 3}, // runt or underrun
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x7F" "C", 3}, // runt or underrun
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x81\x00", 3}, // definite length, long form, zero content octets
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x81\x01" "C", 4}, // definite length, long form, expected content octets
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x81\x02" "C", 4}, // runt or underrun
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x81\xff" "C", 4}, // runt or underrun
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x82\x00\x00", 4}, // definite length, long form, zero content octets
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x82\x00\x01" "C", 5}, // definite length, long form, expected content octets
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x82\x00\x02" "C", 5}, // runt or underrun
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x82\xff\xff" "C", 5}, // runt or underrun
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x83\x00\x00\x00", 5}, // definite length, long form, zero content octets
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x83\x00\x00\x01" "C", 6}, // definite length, long form, expected content octets
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x83\x00\x00\x02" "C", 6}, // runt or underrun
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x83\xff\xff\xff" "C", 6}, // runt or underrun
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x84\x00\x00\x00\x00", 6}, // definite length, long form, zero content octets
{ACCEPT, IA5_STRING, "IA5_STRING", "\x16\x84\x00\x00\x00\x01" "C", 7}, // definite length, long form, expected content octets
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x84\x00\x00\x00\x02" "C", 7}, // runt or underrun
{REJECT, IA5_STRING, "IA5_STRING", "\x16\x84\xff\xff\xff\xff" "C", 7}, // <== Issue 346; requires large allocation
};
pass = RunASN1TestSet(ia5Strings, COUNTOF(ia5Strings)) && pass;
static const ASN1_TestTuple integerValues[] =
{
// 8.3.1 The encoding of an integer value shall be primitive. The contents octets shall consist of one or more octets.
{REJECT, INTEGER, "INTEGER", "\x02\x00", 2}, // definite length, short form, zero content octets
{ACCEPT, INTEGER, "INTEGER", "\x02\x01" "C", 3}, // definite length, short form, expected content octets
{REJECT, INTEGER, "INTEGER", "\x02\x02" "C", 3}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x7F" "C", 3}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x81\x00", 3}, // definite length, long form, zero content octets
{ACCEPT, INTEGER, "INTEGER", "\x02\x81\x01" "C", 4}, // definite length, long form, expected content octets
{REJECT, INTEGER, "INTEGER", "\x02\x81\x02" "C", 4}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x81\xff" "C", 4}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x82\x00\x00", 4}, // definite length, long form, zero content octets
{ACCEPT, INTEGER, "INTEGER", "\x02\x82\x00\x01" "C", 5}, // definite length, long form, expected content octets
{REJECT, INTEGER, "INTEGER", "\x02\x82\x00\x02" "C", 5}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x82\xff\xff" "C", 5}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x83\x00\x00\x00", 5}, // definite length, long form, zero content octets
{ACCEPT, INTEGER, "INTEGER", "\x02\x83\x00\x00\x01" "C", 6}, // definite length, long form, expected content octets
{REJECT, INTEGER, "INTEGER", "\x02\x83\x00\x00\x02" "C", 6}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x83\xff\xff\xff" "C", 6}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x84\x00\x00\x00\x00", 6}, // definite length, long form, zero content octets
{ACCEPT, INTEGER, "INTEGER", "\x02\x84\x00\x00\x00\x01" "C", 7}, // definite length, long form, expected content octets
{REJECT, INTEGER, "INTEGER", "\x02\x84\x00\x00\x00\x02" "C", 7}, // runt or underrun
{REJECT, INTEGER, "INTEGER", "\x02\x84\xff\xff\xff\xff" "C", 7}, // <== Issue 346; requires large allocation
};
pass = RunASN1TestSet(integerValues, COUNTOF(integerValues)) && pass;
return pass;
}
#endif
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
bool TestSecBlock()
{
std::cout << "\nTesting SecBlock...\n\n";
bool pass1=true, pass2=true, pass3=true, pass4=true, pass5=true, pass6=true, pass7=true, temp=false;
//********** Zeroized block **********//
{
// NULL ptr with a size means to create a new SecBlock with all elements zero'd
SecByteBlock z1(NULL, 256);
temp = true;
for (size_t i = 0; i < z1.size(); i++)
temp &= (z1[i] == 0);
pass1 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Zeroized byte array" << std::endl;
SecBlock<word32> z2(NULL, 256);
temp = true;
for (size_t i = 0; i < z2.size(); i++)
temp &= (z2[i] == 0);
pass1 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Zeroized word32 array" << std::endl;
SecBlock<word64> z3(NULL, 256);
temp = true;
for (size_t i = 0; i < z3.size(); i++)
temp &= (z3[i] == 0);
pass1 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Zeroized word64 array" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
SecBlock<word128> z4(NULL, 256);
temp = true;
for (size_t i = 0; i < z4.size(); i++)
temp &= (z4[i] == 0);
pass1 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Zeroized word128 array" << std::endl;
#endif
}
//********** Assign **********//
try
{
SecByteBlock a, b;
temp = true;
a.Assign((const byte*)"a", 1);
b.Assign((const byte*)"b", 1);
temp &= (a.SizeInBytes() == 1);
temp &= (b.SizeInBytes() == 1);
temp &= (a[0] == 'a');
temp &= (b[0] == 'b');
a.Assign((const byte*)"ab", 2);
b.Assign((const byte*)"cd", 2);
temp &= (a.SizeInBytes() == 2);
temp &= (b.SizeInBytes() == 2);
temp &= (a[0] == 'a' && a[1] == 'b');
temp &= (b[0] == 'c' && b[1] == 'd');
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass2 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Assign byte" << std::endl;
try
{
SecBlock<word32> a, b;
temp = true;
word32 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
temp &= (a.SizeInBytes() == 4);
temp &= (b.SizeInBytes() == 4);
temp &= (a[0] == 1);
temp &= (b[0] == 2);
word32 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
temp &= (a.SizeInBytes() == 8);
temp &= (b.SizeInBytes() == 8);
temp &= (a[0] == 1 && a[1] == 2);
temp &= (b[0] == 3 && b[1] == 4);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass2 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Assign word32" << std::endl;
try
{
SecBlock<word64> a, b;
temp = true;
word64 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
temp &= (a.SizeInBytes() == 8);
temp &= (b.SizeInBytes() == 8);
temp &= (a[0] == 1);
temp &= (b[0] == 2);
word64 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
temp &= (a.SizeInBytes() == 16);
temp &= (b.SizeInBytes() == 16);
temp &= (a[0] == 1 && a[1] == 2);
temp &= (b[0] == 3 && b[1] == 4);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass2 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Assign word64" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
{
SecBlock<word128> a, b;
temp = true;
word128 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
temp &= (a.SizeInBytes() == 16);
temp &= (b.SizeInBytes() == 16);
temp &= (a[0] == 1);
temp &= (b[0] == 2);
word128 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
temp &= (a.SizeInBytes() == 32);
temp &= (b.SizeInBytes() == 32);
temp &= (a[0] == 1 && a[1] == 2);
temp &= (b[0] == 3 && b[1] == 4);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass2 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Assign word128" << std::endl;
#endif
//********** Append **********//
try
{
SecByteBlock a, b;
temp = true;
a.Assign((const byte*)"a", 1);
b.Assign((const byte*)"b", 1);
a += b;
temp &= (a.SizeInBytes() == 2);
temp &= (a[0] == 'a' && a[1] == 'b');
a.Assign((const byte*)"ab", 2);
b.Assign((const byte*)"cd", 2);
a += b;
temp &= (a.SizeInBytes() == 4);
temp &= (a[0] == 'a' && a[1] == 'b' && a[2] == 'c' && a[3] == 'd');
a.Assign((const byte*)"a", 1);
a += a;
temp &= (a.SizeInBytes() == 2);
temp &= (a[0] == 'a' && a[1] == 'a');
a.Assign((const byte*)"ab", 2);
a += a;
temp &= (a.SizeInBytes() == 4);
temp &= (a[0] == 'a' && a[1] == 'b' && a[2] == 'a' && a[3] == 'b');
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass3 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Append byte" << std::endl;
try
{
SecBlock<word32> a, b;
temp = true;
const word32 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
a += b;
temp &= (a.SizeInBytes() == 8);
temp &= (a[0] == 1 && a[1] == 2);
const word32 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
a += b;
temp &= (a.SizeInBytes() == 16);
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4);
a.Assign(one, 1);
a += a;
temp &= (a.SizeInBytes() == 8);
temp &= (a[0] == 1 && a[1] == 1);
a.Assign(three, 2);
a += a;
temp &= (a.SizeInBytes() == 16);
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass3 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Append word32" << std::endl;
try
{
SecBlock<word64> a, b;
temp = true;
const word64 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
a += b;
temp &= (a.SizeInBytes() == 16);
temp &= (a[0] == 1 && a[1] == 2);
const word64 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
a += b;
temp &= (a.SizeInBytes() == 32);
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4);
a.Assign(one, 1);
a += a;
temp &= (a.SizeInBytes() == 16);
temp &= (a[0] == 1 && a[1] == 1);
a.Assign(three, 2);
a += a;
temp &= (a.SizeInBytes() == 32);
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass3 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Append word64" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
{
SecBlock<word128> a, b;
temp = true;
const word128 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
a += b;
temp &= (a.SizeInBytes() == 32);
temp &= (a[0] == 1 && a[1] == 2);
const word128 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
a += b;
temp &= (a.SizeInBytes() == 64);
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4);
a.Assign(one, 1);
a += a;
temp &= (a.SizeInBytes() == 32);
temp &= (a[0] == 1 && a[1] == 1);
a.Assign(three, 2);
a += a;
temp &= (a.SizeInBytes() == 64);
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass3 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Append word128" << std::endl;
#endif
//********** Concatenate **********//
// byte
try
{
SecByteBlock a, b, c;
temp = true;
a.Assign((const byte*)"a", 1);
b.Assign((const byte*)"b", 1);
c = a + b;
temp &= (a[0] == 'a');
temp &= (b[0] == 'b');
temp &= (c.SizeInBytes() == 2);
temp &= (c[0] == 'a' && c[1] == 'b');
a.Assign((const byte*)"ab", 2);
b.Assign((const byte*)"cd", 2);
c = a + b;
temp &= (a[0] == 'a' && a[1] == 'b');
temp &= (b[0] == 'c' && b[1] == 'd');
temp &= (c.SizeInBytes() == 4);
temp &= (c[0] == 'a' && c[1] == 'b' && c[2] == 'c' && c[3] == 'd');
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass4 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Concatenate byte" << std::endl;
// word32
try
{
SecBlock<word32> a, b, c;
temp = true;
const word32 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
c = a + b;
temp &= (a[0] == 1);
temp &= (b[0] == 2);
temp &= (c.SizeInBytes() == 8);
temp &= (c[0] == 1 && c[1] == 2);
const word32 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
c = a + b;
temp &= (a[0] == 1 && a[1] == 2);
temp &= (b[0] == 3 && b[1] == 4);
temp &= (c.SizeInBytes() == 16);
temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass4 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Concatenate word32" << std::endl;
// word64
try
{
SecBlock<word64> a, b, c;
temp = true;
const word64 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
c = a + b;
temp &= (a[0] == 1);
temp &= (b[0] == 2);
temp &= (c.SizeInBytes() == 16);
temp &= (c[0] == 1 && c[1] == 2);
const word64 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
c = a + b;
temp &= (a[0] == 1 && a[1] == 2);
temp &= (b[0] == 3 && b[1] == 4);
temp &= (c.SizeInBytes() == 32);
temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass4 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Concatenate word64" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
{
SecBlock<word128> a, b, c;
temp = true;
const word128 one[1] = {1}, two[1] = {2};
a.Assign(one, 1);
b.Assign(two, 1);
c = a + b;
temp &= (a[0] == 1);
temp &= (b[0] == 2);
temp &= (c.SizeInBytes() == 32);
temp &= (c[0] == 1 && c[1] == 2);
const word128 three[2] = {1,2}, four[2] = {3,4};
a.Assign(three, 2);
b.Assign(four, 2);
c = a + b;
temp &= (a[0] == 1 && a[1] == 2);
temp &= (b[0] == 3 && b[1] == 4);
temp &= (c.SizeInBytes() == 64);
temp &= (c[0] == 1 && c[1] == 2 && c[2] == 3 && c[3] == 4);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass4 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Concatenate word128" << std::endl;
#endif
//********** Equality **********//
// byte
try
{
static const byte str1[] = "abcdefghijklmnopqrstuvwxyz";
static const byte str2[] = "zyxwvutsrqponmlkjihgfedcba";
static const byte str3[] = "0123456789";
temp = true;
SecByteBlock a,b;
a.Assign(str1, COUNTOF(str1));
b.Assign(str1, COUNTOF(str1));
temp &= (a.operator==(b));
a.Assign(str3, COUNTOF(str3));
b.Assign(str3, COUNTOF(str3));
temp &= (a == b);
a.Assign(str1, COUNTOF(str1));
b.Assign(str2, COUNTOF(str2));
temp &= (a.operator!=(b));
a.Assign(str1, COUNTOF(str1));
b.Assign(str3, COUNTOF(str3));
temp &= (a != b);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass5 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Equality byte" << std::endl;
// word32
try
{
static const word32 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
static const word32 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2};
static const word32 str3[] = {0,1,2,3,4,5,6,7,8,9};
temp = true;
SecBlock<word32> a,b;
a.Assign(str1, COUNTOF(str1));
b.Assign(str1, COUNTOF(str1));
temp &= (a.operator==(b));
a.Assign(str3, COUNTOF(str3));
b.Assign(str3, COUNTOF(str3));
temp &= (a == b);
a.Assign(str1, COUNTOF(str1));
b.Assign(str2, COUNTOF(str2));
temp &= (a.operator!=(b));
a.Assign(str1, COUNTOF(str1));
b.Assign(str3, COUNTOF(str3));
temp &= (a != b);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass5 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Equality word32" << std::endl;
// word64
try
{
static const word64 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
static const word64 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2};
static const word64 str3[] = {0,1,2,3,4,5,6,7,8,9};
temp = true;
SecBlock<word64> a,b;
a.Assign(str1, COUNTOF(str1));
b.Assign(str1, COUNTOF(str1));
temp &= (a.operator==(b));
a.Assign(str3, COUNTOF(str3));
b.Assign(str3, COUNTOF(str3));
temp &= (a == b);
a.Assign(str1, COUNTOF(str1));
b.Assign(str2, COUNTOF(str2));
temp &= (a.operator!=(b));
a.Assign(str1, COUNTOF(str1));
b.Assign(str3, COUNTOF(str3));
temp &= (a != b);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass5 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Equality word64" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
// word128
try
{
static const word128 str1[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
static const word128 str2[] = {97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2};
static const word128 str3[] = {0,1,2,3,4,5,6,7,8,9};
temp = true;
SecBlock<word128> a,b;
a.Assign(str1, COUNTOF(str1));
b.Assign(str1, COUNTOF(str1));
temp &= (a.operator==(b));
a.Assign(str3, COUNTOF(str3));
b.Assign(str3, COUNTOF(str3));
temp &= (a == b);
a.Assign(str1, COUNTOF(str1));
b.Assign(str2, COUNTOF(str2));
temp &= (a.operator!=(b));
a.Assign(str1, COUNTOF(str1));
b.Assign(str3, COUNTOF(str3));
temp &= (a != b);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
pass5 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Equality word128" << std::endl;
#endif
//********** Allocator Size/Overflow **********//
try
{
temp = false;
AllocatorBase<word32> A;
const size_t max = A.max_size();
SecBlock<word32> t(max+1);
}
catch(const Exception& /*ex*/)
{
temp = true;
}
catch(const std::exception& /*ex*/)
{
temp = true;
}
pass6 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Overflow word32" << std::endl;
try
{
temp = false;
AllocatorBase<word64> A;
const size_t max = A.max_size();
SecBlock<word64> t(max+1);
}
catch(const Exception& /*ex*/)
{
temp = true;
}
catch(const std::exception& /*ex*/)
{
temp = true;
}
pass6 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Overflow word64" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
try
{
temp = false;
AllocatorBase<word128> A;
const size_t max = A.max_size();
SecBlock<word128> t(max+1);
}
catch(const Exception& /*ex*/)
{
temp = true;
}
catch(const std::exception& /*ex*/)
{
temp = true;
}
pass6 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " Overflow word128" << std::endl;
#endif
//********** FixedSizeAllocatorWithCleanup and Grow **********//
// byte
try
{
static const unsigned int SIZE = 8;
SecBlockWithHint<byte, SIZE> block(SIZE);
memset(block, 0xaa, block.SizeInBytes());
temp = true;
block.CleanGrow(SIZE*2);
temp &= (block.size() == SIZE*2);
for (size_t i = 0; i < block.size()/2; i++)
temp &= (block[i] == 0xaa);
for (size_t i = block.size()/2; i < block.size(); i++)
temp &= (block[i] == 0);
block.CleanNew(SIZE*4);
temp &= (block.size() == SIZE*4);
for (size_t i = 0; i < block.size(); i++)
temp &= (block[i] == 0);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
catch(const std::exception& /*ex*/)
{
temp = false;
}
pass7 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " FixedSizeAllocator Grow with byte" << std::endl;
// word32
try
{
static const unsigned int SIZE = 8;
SecBlockWithHint<word32, SIZE> block(SIZE);
memset(block, 0xaa, block.SizeInBytes());
temp = true;
block.CleanGrow(SIZE*2);
temp &= (block.size() == SIZE*2);
for (size_t i = 0; i < block.size()/2; i++)
temp &= (block[i] == 0xaaaaaaaa);
for (size_t i = block.size()/2; i < block.size(); i++)
temp &= (block[i] == 0);
block.CleanNew(SIZE*4);
temp &= (block.size() == SIZE*4);
for (size_t i = 0; i < block.size(); i++)
temp &= (block[i] == 0);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
catch(const std::exception& /*ex*/)
{
temp = false;
}
pass7 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " FixedSizeAllocator Grow with word32" << std::endl;
// word64
try
{
static const unsigned int SIZE = 8;
SecBlockWithHint<word64, SIZE> block(SIZE);
memset(block, 0xaa, block.SizeInBytes());
temp = true;
block.CleanGrow(SIZE*2);
temp &= (block.size() == SIZE*2);
for (size_t i = 0; i < block.size()/2; i++)
temp &= (block[i] == W64LIT(0xaaaaaaaaaaaaaaaa));
for (size_t i = block.size()/2; i < block.size(); i++)
temp &= (block[i] == 0);
block.CleanNew(SIZE*4);
temp &= (block.size() == SIZE*4);
for (size_t i = 0; i < block.size(); i++)
temp &= (block[i] == 0);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
catch(const std::exception& /*ex*/)
{
temp = false;
}
pass7 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " FixedSizeAllocator Grow with word64" << std::endl;
#if defined(CRYPTOPP_WORD128_AVAILABLE)
// word128
try
{
static const unsigned int SIZE = 8;
SecBlock<word128, AllocatorWithCleanup<word128, true> > block(SIZE);
memset(block, 0xaa, block.SizeInBytes());
temp = true;
block.CleanGrow(SIZE*2);
temp &= (block.size() == SIZE*2);
for (size_t i = 0; i < block.size()/2; i++)
temp &= (block[i] == (((word128)W64LIT(0xaaaaaaaaaaaaaaaa) << 64U) | W64LIT(0xaaaaaaaaaaaaaaaa)));
for (size_t i = block.size()/2; i < block.size(); i++)
temp &= (block[i] == 0);
block.CleanNew(SIZE*4);
temp &= (block.size() == SIZE*4);
for (size_t i = 0; i < block.size(); i++)
temp &= (block[i] == 0);
}
catch(const Exception& /*ex*/)
{
temp = false;
}
catch(const std::exception& /*ex*/)
{
temp = false;
}
pass7 &= temp;
if (!temp)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " FixedSizeAllocator Grow with word128" << std::endl;
#endif
return pass1 && pass2 && pass3 && pass4 && pass5 && pass6 && pass7;
}
#endif
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
bool TestHuffmanCodes()
{
std::cout << "\nTesting Huffman codes...\n\n";
bool pass=true;
static const size_t nCodes = 30;
const unsigned int codeCounts[nCodes] = {
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const unsigned int maxCodeBits = nCodes >> 1;
unsigned int codeBits[nCodes] = {
~0u, ~0u, ~0u, ~0u, ~0u,
~0u, ~0u, ~0u, ~0u, ~0u,
~0u, ~0u, ~0u, ~0u, ~0u,
};
try
{
HuffmanEncoder::GenerateCodeLengths(codeBits, maxCodeBits, codeCounts, nCodes);
}
catch(const Exception& /*ex*/)
{
pass=false;
}
if (!pass)
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " GenerateCodeLengths" << std::endl;
return pass;
}
#endif
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_IMPORTS)
bool TestIntegerBitops()
{
std::cout << "\nTesting Integer bitops...\n\n";
struct Bitops_TestTuple
{
// m,n are operands; a,o,x are and,or,xor results
const char *m, *n, *a, *o, *x;
};
static const Bitops_TestTuple tests[] = {
{
"0xc2cea8a4", "0xb36e5794", "0x824e0084", "0xf3eeffb4", "0x71a0ff30"
},
{
"0x436eb828", "0x1b375cb4", "0x3261820", "0x5b7ffcbc", "0x5859e49c"
},
{
"0x1e5c0b28", "0x4fded465", "0xe5c0020", "0x5fdedf6d", "0x5182df4d"
},
{
"0xeb71fde7", "0xf7bb47cf", "0xe33145c7", "0xfffbffef", "0x1ccaba28"
},
{
"0xa6b0f01f", "0x8a8ca98", "0xa0c018", "0xaeb8fa9f", "0xae183a87"
},
{
"0xa70bd8b7", "0x5c758cf5", "0x40188b5", "0xff7fdcf7", "0xfb7e5442"
},
{
"0xf91af382", "0x718a9995", "0x710a9180", "0xf99afb97", "0x88906a17"
},
{
"0xbd2a76ad", "0xddd8dfeb", "0x9d0856a9", "0xfdfaffef", "0x60f2a946"
},
{
"0xd4b559cc", "0x91a53295", "0x90a51084", "0xd5b57bdd", "0x45106b59"
},
{
"0x89434e9e", "0xa42fdaf9", "0x80034a98", "0xad6fdeff", "0x2d6c9467"
},
{
"0xb947ac04", "0xd4201e52", "0x90000c00", "0xfd67be56", "0x6d67b256"
},
{
"0xa83945c1", "0x3a9c5dba", "0x28184580", "0xbabd5dfb", "0x92a5187b"
},
{
"0xbca38ffa", "0x881ba9fd", "0x880389f8", "0xbcbbafff", "0x34b82607"
},
{
"0xfcd0b92", "0xeaad8534", "0xa8d0110", "0xefed8fb6", "0xe5608ea6"
},
{
"0x50d160d0", "0x64646f75", "0x40406050", "0x74f56ff5", "0x34b50fa5"
},
{
"0x165ccff8", "0x67d49127", "0x6548120", "0x77dcdfff", "0x71885edf"
},
{
"0x8c4f4bbb7adaacb5", "0x2566b7a909b24aa9", "0x44603a9089208a1", "0xad6fffbb7bfaeebd", "0xa929fc127368e61c"
},
{
"0x6f9ef50aafb31e8d", "0x7a93b2ccd1bbbff2", "0x6a92b00881b31e80", "0x7f9ff7ceffbbbfff", "0x150d47c67e08a17f"
},
{
"0x4c99e967f8de5294", "0x1f4699e0c14e6974", "0xc008960c04e4014", "0x5fdff9e7f9de7bf4", "0x53df708739903be0"
},
{
"0xcc55f5d6d3ea45c", "0x6805b4ddb6390c2f", "0x805145d2438040c", "0x6cc5ffddff3fac7f", "0x64c0eb80db07a873"
},
{
"0x90620d1a012459e7", "0x89d31098ce3fed42", "0x8042001800244942", "0x99f31d9acf3ffde7", "0x19b11d82cf1bb4a5"
},
{
"0xb87d1674e90a935a", "0x75ea466cbb782ac4", "0x30680664a9080240", "0xfdff567cfb7abbde", "0xcd9750185272b99e"
},
{
"0x1f135732240701f0", "0x6aa09a1614bf4dd4", "0xa001212040701d0", "0x7fb3df3634bf4df4", "0x75b3cd2430b84c24"
},
{
"0xc9a88d8300099a31", "0xdc8e91df745169ee", "0xc888818300010820", "0xddae9ddf7459fbff", "0x15261c5c7458f3df"
},
{
"0xc8c828d15228b562", "0x43f86cffa3d15d80", "0x40c828d102001500", "0xcbf86cfff3f9fde2", "0x8b30442ef1f9e8e2"
},
{
"0x41fdc0bc2009563f", "0x59dd1c417e3c07bc", "0x41dd00002008063c", "0x59fddcfd7e3d57bf", "0x1820dcfd5e355183"
},
{
"0x9e2f78600c3a84e7", "0xac69a0e1fe7887b0", "0x8c2920600c3884a0", "0xbe6ff8e1fe7a87f7", "0x3246d881f2420357"
},
{
"0xd424d1d9a955f617", "0x9608f5bde1c4d893", "0x9400d199a144d013", "0xd62cf5fde9d5fe97", "0x422c246448912e84"
},
{
"0x1aa8b60a0627719a", "0x5b26e6aca95f5f60", "0x1a20a60800075100", "0x5baef6aeaf7f7ffa", "0x418e50a6af782efa"
},
{
"0xcf5db499233fac00", "0xf33e7a29c3c33da8", "0xc31c300903032c00", "0xff7ffeb9e3ffbda8", "0x3c63ceb0e0fc91a8"
},
{
"0x6b47c03d576e878d", "0x2032d13574d67da4", "0x2002c03554460584", "0x6b77d13d77feffad", "0x4b75110823b8fa29"
},
{
"0xd47eeb3aefebf074", "0x6d7ba17a42c66b89", "0x447aa13a42c26000", "0xfd7feb7aefeffbfd", "0xb9054a40ad2d9bfd"
},
{
"0x33ad9c5d20b03f5c05535f20a2941c8f4ae0f1f19500759151060dce39e5dfed41ec4f",
"0x277401dc000fde7eda4d60a5698935f7febd8fbe49e5d6f56ca2e7f6118380d3cd655da392df3ba6c1b13dc0119af34cfa1d18a65",
"0x10a9841c002016480453410020041c8640c0312191006411110401082924cfa1418845",
"0x277401dc000fde7eda4d60a5698935f7febfbfffcdf7dff7fde2f7f7f38ba9d3cdf5ffaf9fdf7ba7d9b53de0ddfbff5dfedd1ee6f",
"0x277401dc000fde7eda4d60a5698935f7febeb5678c37ddf69962b2c3e389a9920591f3ac8dc66ba198a42da0cd796d1104c90662a"
},
{
"0xb6ea335c13111216862e370d12fb9c761a6266617f62a1904b0d7944ab3cddc71f11752ad9424b0",
"0xa6b380f048a9cbe45ff4ea824064c831eb03ff875e1e3e",
"0xa62200104028090410d480020044c831e1035285140430",
"0xb6ea335c13111216862e370d12fb9c761a6b7e6f7feabdbe4fff7fecaf3eddc71fb17ffafde3ebe",
"0xb6ea335c13111216862e370d12fb9c7610095e6e7be83d2e0ef237ec8f3a914401a14ad2aca3a8e"
},
{
"0x8fb9486ad1f89ca5b3f6da9f0d5ef9ec328b8cc3e5122afbd8a67bd1b2b4ab5c548b90cf9fe1933a0362922f1e84ef0",
"0x10615f963dffc13718ed1ecdb9cfbef33148befeb91b190dc7e7d28d8821ff248ab26a34e1b89885c643e447c72",
"0x6051901ca58136188d0c4cb9cc32830040a412281b180443c192848800540080820a208138000082030404c70",
"0x8fb9586bdffebdfff3f7daff1fdff9efbefbbdcbfffebbfbd9affff7f2bdab7dffaf9afffff5f3ba9be7d66ffec7ef2",
"0x8fb9580b8e6ea15a72c1c272139340238c78bd8b5bec93e0c1abbc366039237dabaf1a7df5d572829be7546cfac3282"
},
{
"0x10af96443b186faf790279bf3bbe0517d56ffc01e7fec8c88e765d48cc32333390224f4d762d1ba788c50801cba02524cb49",
"0x95d44e7344fb1701bace3ae83affbb6290bf282f7565b9a82c386823f5f213a53eccb2cfe5deb4dd040067a64ada8c1b6828599b96cc70647e7d19dc7dfba393addabe689ffbe1a36642bc9844b81c6c4c2e178",
"0x2c96442b084000000260ad288004028509b800c70640c080144548883032118022094d3608122408c1000181800400c148",
"0x95d44e7344fb1701bace3ae83affbb6290bf282f7565b9a82c386823f5f213a53ecdbaffe5dfb5dffef7f7a7dbfbbffb797d5fffd6de7fecfefdfffdfdffe3b3bffbbe6cffffe3f3fe7abcd8c4bcbe6e5e6eb79",
"0x95d44e7344fb1701bace3ae83affbb6290bf282f7565b9a82c386823f5f213a53ecdb836819d055bfef7f781d12937fb39550f6456d20f88f2f5feb9a97760b09ee3bc4c6b2c8372dc3a30c8c4a4a66e1e62a31"
},
{
"0x5fc77dab8cd9c1da8c91eb7ba9c23ce85375b61bf3b9a8c4e4df7bc917aa8a14e747888c9756a2be2fd2e256e44194ce093a0185594de0dcf8340c45b6af7dbdc7682fbef6313f9f1cb234689d9f1ff603e1273faad89d0fe1ab57fbc7c32d29dce125fafc973754464b55ae5de58a8a5661c2065b95c2c94d7ec34",
"0xd4a9158961d4c11258cd047eda13d6804c16c3a374b7f4115bd835bde0b5",
"0x1080158800548100504504649012c480480081221420641158081495e034",
"0x5fc77dab8cd9c1da8c91eb7ba9c23ce85375b61bf3b9a8c4e4df7bc917aa8a14e747888c9756a2be2fd2e256e44194ce093a0185594de0dcf8340c45b6af7dbdc7682fbef6313f9f1cb234689d9f1ff603e1273faad89d0fe1ab57fbc7cf6fb9dcf73dfefdb7bfd447eff5bf7de5cbee7e77cb7f5b95ffcb5ffecb5",
"0x5fc77dab8cd9c1da8c91eb7ba9c23ce85375b61bf3b9a8c4e4df7bc917aa8a14e747888c9756a2be2fd2e256e44194ce093a0185594de0dcf8340c45b6af7dbdc7682fbef6313f9f1cb234689d9f1ff603e1273faad89d0fe1ab57fbc7ce67b8847738b6edb2bb8401a6f49335e14be66c5689791a807f4a16a0c81"
},
{
"0x52cbea1f4d78445fb8f9267203f0f04bddf65b69b1acb0877143e77317f2d9679cb",
"0x331e156a1e1daa0039926a08ec80c2d7c1500bc435a53ebfc32fa398a3304fcd79d90725528e320add050da666b9de42b8307b",
"0x88421a41684412b839023200f0d00990725128a120a0805042666315e0090304b",
"0x331e156a1e1daa0039926a08ec80c2d7c1552ffeb5f5ffbfc7ffaf9ae7307fcf7dfddf65f69f3acbdd771dbe77b9ff6fbe79fb",
"0x331e156a1e1daa0039926a08ec80c2d7c155277a9451e93b86d42c0ac41070c27d64d840e41528c1d57219981188a16f2e49b0"
},
{
"0xbde7e20f37c3ed822555d36050240dcfb5a9a3867d149cffe78e92b95573cbdde33a8c9495148e04cafa1325aae058b4a98c50f7019de1345de6dce12436bed4b86eca2d",
"0xee480b4096f0c1ac565d623dd53b62dba81c507d3c8e15372396fa49de0ecf074fb0ed1785f00f8094022ff50fc436a7cbd18de8ff317c33ea9bdbd8814a7658fcd1fd10b2ed10eaf7e4c2b8f409df3c36f1f0c986a49805a9ed08bbcd603e2eec9e18",
"0x547a00d1781e0020014022050040406a58981846814107c238a929950014a544038809410108c00caf20000a8e00894280450f00184a01005a0cc0020042014286c8a08",
"0xee480b4096f0c1ac565d623dd53b62dba81c507d3c8e15372396fa49de0ecfbfeff2ef37c7fd8fa5d5d36ff52fcdffb7ebf38ffdffbdfff7ee9bfbddf3cbfffbfeddfd95b6ef14eafff7e7baf459ffbdbef1f7c99fe5bc5deffde9bffffefebeeede3d",
"0xee480b4096f0c1ac565d623dd53b62dba81c507d3c8e15372396fa49de0ecfbaa852e220461d8da5c1d14fa52bc9f91262720b95ebad83d46409628df281abbbc65d6985a66314200df7e71214516b95baa107c81b45ac584f31e99ffbdeea96825435"
},
{
"0x17ed0a1aa80542396e82ab79f6d4dda731d10f9487467fcfa5c8b501fa86488fbe268605c01beb257c9e301a42833d22965ea2ff0eda5f18427481a300a8f9aa81e76d774ea1dbed40268eca094bef627d2c206f6885fc12f71557bfda836",
"0x422340e8ff3b4177efa5f58111fe306aa602d8020164fa34c12acdb3de81e",
"0x2340604e21416540248480014a2062240000020004f810c10045b3da816",
"0x17ed0a1aa80542396e82ab79f6d4dda731d10f9487467fcfa5c8b501fa86488fbe268605c01beb257c9e301a42833d22965ea2ff0eda5f18427481a300a8f9aac3e76dffffbbdbffefa7ffcb19ffff6aff2ef86f69e5fe36f73fdfbfde83e",
"0x17ed0a1aa80542396e82ab79f6d4dda731d10f9487467fcfa5c8b501fa86488fbe268605c01beb257c9e301a42833d22965ea2ff0eda5f18427481a300a8f9aac3c42d9fb19a9a9aaf837b4b18b5df08db2ef86d69e10626363f9a0c04028"
},
{
"0x290796408a0b8baa742b9d466afc4958528f7976fdce50caa83ed63285f58d200e4c65842ea24c3d4a3850a1824b61d25af9d3b41b9e64407a5262a75d9efd08481cfbc339ae26b0755438894b9e2298a35ed9",
"0x4cb6f7935f5cc586320c6ce957f82cff774cde7d4201735a5acd22190fcb1c9c16d1887a",
"0x4012f193141884040008406007580cfd00481c794201220210450018094b1c0010810858",
"0x290796408a0b8baa742b9d466afc4958528f7976fdce50caa83ed63285f58d200e4c65842ea24c3d4a3850a1824b61defeffd3ff5fdfe6727e7eebf7fdbeff7f4cdeffc339ff7efafd76398fcb9ebe9ef3defb",
"0x290796408a0b8baa742b9d466afc4958528f7976fdce50caa83ed63285f58d200e4c65842ea24c3d4a3850a1824b619eec0e40eb475be272763e8bf0a5b2027f04c2868138dd7ceab87621868082be8e72d6a3"
},
{
"0x14e55ecb09d8c6827022df7c713c05a5d882e25782",
"0x2dbdb54cb6341fcea6f67cfaa5186aa0a91b9782e362cbb0dd0ef3cbc130ce0cb2ce7232c0562",
"0x10600e020898048060209c1000200124c002200502",
"0x2dbdb54cb6341fcea6f67cfaa5186aa0a91bdfd7eff2dfbcfd2ff3eff7f7dfccfadffa3ee57e2",
"0x2dbdb54cb6341fcea6f67cfaa5186aa0a91ad9d70fd2563cb529f1e636f7ddcce893fa1ce52e0"
},
{
"0x2b0dfd23fc740e1759697bcba800aa1be7df28c59fe72b9869766ac34ecb4e5d0dbc74c2cbb5f734bb8d38dab59c3f22cdc706c657839580c2793c4c7660606548c048a697db3dfbad82e695c605",
"0x33080f6fd52aeca572f24a98ff19b9e7327c3b951ccfd8c9a6b9bd6f7c940079e4be88178a2a6d5a2b17",
"0x30007249108288030900a00cd0100c612001180004918482620206548800020849a0813880264100205",
"0x2b0dfd23fc740e1759697bcba800aa1be7df28c59fe72b9869766ac34ecb4e5d0dbc74c2fbbdff7fffaffcfff7fe7fbaffdfbfe777ffbf95defffccdf6f9fd6f7cd448fff7ffbdffafaaefdfef17",
"0x2b0dfd23fc740e1759697bcba800aa1be7df28c59fe72b9869766ac34ecb4e5d0dbc74c2f8bdf85b6ea7d47fc76e75ba32debf2165ffae15deb6e485d0d9dd0a345448df7365b5ec27a88bcfed12"
},
{
"0xc0cc21922748d7626df1ab92b4ad4df1861050ca7de74adb92a140",
"0x3531a6880ccc47bc3826056efe912f3db02df9c0b6931e253ab9248f472359fe59218690f6781f35da89b8f1ff45cd5a1db9a414c9d7ec62ff5859a1572b1c1880a99aa74ebe8b12c68e791c11dd6cc0e5ed5",
"0xc40192054091400800898234a948b104004080410542c8020040",
"0x3531a6880ccc47bc3826056efe912f3db02df9c0b6931e253ab9248f472359fe59218690f6781f35da89b8f1ff45cd5a1db9a414c9d7ec6effda59a377af7e3edfbbbbaf4efedf1ae78f7dbfdffdedf9effd5",
"0x3531a6880ccc47bc3826056efe912f3db02df9c0b6931e253ab9248f472359fe59218690f6781f35da89b8f1ff45cd5a1db9a414c9d7ec6ef39a408323a66a3e5fb3238c046a540aa78b75bbcfa9c179cff95"
},
{
"0x68cbb0a526d1fa61003e12401db51090fa4649b00b7be7465d0eb18f74c86157a919",
"0x1ca7d6f9bc3e11d3c365af63bf9499b6c7e9c569da7361f0214b8d",
"0x1610001c111080600641b00019a6464904218a704060010909",
"0x68cbb0a526d1fa7da7fefbfc3fb5d3d3ffef6bbf9ffbf7c7fdcff9df77e9f177eb9d",
"0x68cbb0a526d1fa7da7e8ebfc23a4c3539fe92a0f9fe25181b4cbd85507a99176e294"
},
{
"0x210bef18d384992c5eb72e2b362c7296d9810f5ba9fd25e2d5648989d65095e45d1478f2a83140a0f68033a08fa3d7c392a3dc77e8e6aeba9ed76038e9e7825255fac990bf1098e6f9cba0",
"0xdb48641b3f63e5f1f41ff3b1578c4b190de42379d45cba03c4c6f34b1b14ea930fdff90dca53116710228e45b081fbddc9273a542e6f689642453adb91086bdb99681342113262d67f5517f2691024fe367459b01872549211067798063cc00b16c883b8cd2ffaa6d6116863f204bb23ce26c5bcdaf3e1b816dcf65ca",
"0x21014200d280002452a52800062c309681000113202d25e051640081024081644510008220010000660000208c00914080238c52e8a22c201686202049a20042445ac9803e108064c94180",
"0xdb48641b3f63e5f1f41ff3b1578c4b190de42379d45cba03c4c6f34b1b14ea930fdff90dca53116710228e45b081fbddc9273afeffef78dfd2c5fbfbf3bb6bdfb96d9b52f5baffd67f7d57faf99d65ff7e75d9f79f7ad7961b0f7f9b3e3cfa3f7ef9abbdcf7ffeeeffb9ed77f38ebf7bef27dfbcdbfbf1b99efffefea",
"0xdb48641b3f63e5f1f41ff3b1578c4b190de42379d45cba03c4c6f34b1b14ea930fdff90dca53116710228e45b081fbddc9252aeadfe250dfd080d1a973bb091cb0058b52e488fd04217841baf18d41f7683188f79758d7861b091f9b3c343a366af1a9850a5174cc3db88515f18a255beb039a1043f810b198b36ae6a"
},
{
"0x143143205d76a7287d48be24db8fbfe37c291d82e103aa05cfc172fb920f0e8cc15c47de948b964e39be34a5b8a2610198c0c5b98543e6e727be153cfff0338f229cc22f029e04f766c62988634fee1a0a16880c93e5b10bada4018b6765b54c08f5710344dbfb9e9ad5dd7914cab496b22a6",
"0x2d58b8b513f4bceb8300f8b978e31c163f36155e9678bb0f221ee7cbcf7262b9d53c7a395ea916218fa2478baada74f3e69df63a7be0c9554c07004f9e4d869642bbd63a9fe07138a6aef7ad14c74231cf6401c597f9b6d15c266c42c28613838609bd4f4522c9eb65fc8456acc339c641ac7d7b7bc2c48c8f2",
"0x100201970a308140836045a8638a30c201c82c103220089c1307a100e0804010c0246808a924431a614a4382260011040050005024486060211143a902001208482270014044220c620004107e8120014000c02c080038184018947452048086570004488c31882418c79104a8084800a2",
"0x2d58b8b513f4bcffb343f8fd7ee73c7f7fbe35df9ffffb7f2b1fe7ebcffa67ffd57efbbb5faf9ee1dfe7df9fabde7efbfebdf7bafbe1c9ddccc7b9cfdfefe7b7febffefffff3ff3abeeeffaf9ec7f777cf6d89e7dfffbedb5eae6cd3e7b71bafa609bf6f65b7cdebf5fd8756fffbbfded5fd7d7ffbf6d6beaf6",
"0x2d58b8b513f4bcffb243d8e40e44346b7788318519c758730b03652accd86776144e81ab51a79ae0d3e5991f214c3aca58a95382d981c8cd8cc2b9caddab61b1fcaeeac56fd3fe1a3a6cd8af8ac3b557094d89a6d817acdb4aae60d12737182e22083628209785e3908d87127738a75c9471046fb176523ea54"
},
{
"0x258e988b847b06b73462629161e28517f7b9ad7b5c19a9ad2c07f9a66f33fb2220fddb5a33b9cd5c2d63fd543efa1bef16e26b95484d70d0d7cfce28491ace0a608fb6cf9e97cb88d73c96c9150f9ef53c5e75bd68805fdce891e5935e9428ca67eba1e345148fcf2",
"0x1857c0e26e0476169cf804c8d5a431022cce0da75d7642a2414a900370f201f5073c7e700ff6626fbd8a104182954fa9f23a45474af5456a00e36f6a6c8162afdf7492d387a455dd8506167d5cc24e6861d7b480b1458230",
"0x1812c0a04000121280780040d12430020ccc05a319144082400a900360a000f10624385004d6000d3c880000808440a0003a44414874000800c16c0040816203c56412d2800455cc8106103548420c206092140011408030",
"0x258e988b847b06b73462629161e28517f7bdfd7f7ef9efed6dcff9eeef7bfb3222fdfbda77ffed7e2d77fd543fff3bff56f3eff748ff76f6ffdfef2c593bdefaffafb6dffebfdfdef73eb6ffb7cf9efffdff7dbd78fa5fddf8d1e5f7dfdc2ceee7fffbeb4f14dfef2",
"0x258e988b847b06b73462629161e28517f63cd1757af9eecc45c879eae269b83202313b80466ea9760977545409f53bf04691ac7248b216f62c176f2c51339af0ffac129bea389fde7732a03fb3c788dfc1a93c9050fa1a8130c184f48b580c2ce1f6daab4e00d7ec2"
},
{
"0x328edc02c67d84bf095ac048e50c2dc29cffc08184b11e4da02904be14eccd317e9f6bdd6fe2b8233e8928d65d4ad434ef8a629cae6013bfb3c54be167e16371dc6412b62c2b1213424dfb7d391cea8a7494a28576ce823d8e111994182909efba7dd3533dbbe510dab4ac5ef",
"0x61a1365a1226597896c514f5bb16a064f6ff6982ac91ea568daa43e473aa63867bdb628e92e97ebd4f2091",
"0x4121224210201020968510918a00a04042284100a801c84001884180108a63865911228a92410ca94a0081",
"0x328edc02c67d84bf095ac048e50c2dc29cffc08184b11e4da02904be14eccd317e9f6bdd6fe2b8233e8928d65d4ad434ef8a629cae6013bfb3c54be167e16371dc661ab76dab3277d7cdff7d7f5ffbea76dfeff7feeecb3faf79dbb43e6f3befba7ffff73dfbef97fbf4fe5ff",
"0x328edc02c67d84bf095ac048e50c2dc29cffc08184b11e4da02904be14eccd317e9f6bdd6fe2b8233e8928d65d4ad434ef8a629cae6013bfb3c54be167e16371dc6208a5498a3076d5c4972c76475be072dbcd73eee44b232b79c330266e3349821a6ee51552cb8731605e57e"
},
{
"0x37a92944b67fae733d201c024838975531bc3f748d98089eed38faed40c9463441cf48ac40e98097ce75db2bf0120ef69087a176d31d562cc99137c67e4a659cbb1298ba150aa191ced4089deee7048511de602414936af93cb2cef1b7ee801d9b75d961d33bb2958669b16193abf7b55ccfebac3a490415128dac92",
"0x6fb8d83d986c4604db1b9396493a0a68270806cdbcc3299a049ebe77bd6891258e6313c720fb1b30ae9c4387ba51db3325e15033d9e01d499707c138b4cf4b85032da65e9ce3aabc5effbf7003771476ff71e86f665d2d3e7578dfcbb8f08c1619f609ec147f0",
"0x88c811882c440490030014400a0008000804c51c822900008e2800380001218462008100780320a6184381280181102001102140801c4810004118a4024101022d824a0ce30a3c4801993001161432bb2148660214093a357855c8b8b080041040012810490",
"0x37a92944b67fae733d201c024838975531bc3f748d9efb9feff9feed60cdf7bd79efdbace6ebf097eeffdf3bf9b24ffff7fff7ffd35df63dfdf33ff7ff4aeddcbb7bbdbfb73aff95cffd9e9dfeff74fd13df6cf4bcd37afb7dfbcefbbfefefffff75ff71d77ff79f86fff5f3d3eff7bdfcffefacfb699f759ecdeff2",
"0x37a92944b67fae733d201c024838975531bc3f748d9ef3136ee17c292084f78d78abdb0ce66bf017a2ae171969b2471d77fc77ffc145b01df5e33877cd408c5883693da7a638ff84cde9969c3a7e74f902552cd0acc35823595b00cb1c2b6fe66c75ee109454458b009fd4b3404ca038a07464a4fb289b758c4ceb62"
},
{
"0x1ab020d8beb54c354411f3a5658b5e5e87a896d7049c5eab20a302b6e35ca98364d7edd00eb3e209dcb035fe4b6eeace4e525229bf790c67bae63821e1282712d7c624efa64b3e5ad1a73aeb1033d4cd5949d63183173632445c9f488e74cd",
"0x4d706a200a7a70e0b6eeef2dbdb88779dd50af16e6405c17fd2c2efb5493cf13b730207a009a14ca150042af3e6b7f05230161a10073f87a56afede3c2cfd09857f78d7913cdd966e9a2e6e6e3",
"0x45000000a2a20a002a6e30ca9800451cd500e12e2005c10352c0a6a40824e1212202078000210c21000402826025704200120010052d02212ab0023c0cd5008563181111200404489008664c1",
"0x1ab020d8beb54c354411f3a5658b5e5e87a8dff76ebc5efb70e3b6feef7dbdbbe7fffdd0afb7e649dcb7fdfe6ffffedfcf53f739bf7b0cffbeee3d21e3af3f7bffc727efe7eb3e7bf9ff7eeffdf3d6cfd9d9d7f78f7f37ffdd7effeaeef6ef",
"0x1ab020d8beb54c354411f3a5658b5e5e87a8dba76ebc54d15043b4580c71143be3ae3080a1a5044980a7c8d26595be5d8141e5199f030cfdae2c2d21a3871979a8c307eec7ea3e2929dd6c44fdd0160289d181c60e6e25ff9d3a76ea68922e"
},
{
"0x85993ec08ac960d46bcba87136f24042485c6d3e0a9973e828df60e537860d6bc83dafa7fb292beef466d0a939ab9da2b",
"0x4c9a310b11d6e4b4d29d7ede30fb42161fd6a58792440f416abda6df55913a8a26c35140524de5dd9519c30f19641f4f0863bfefc2ae6c89333dd77d6f688cffcbde281772cee0dac9bb0dd16b6c1d33fa7e39b2e781896dcc2b0aba3abedf1381f9f38eb210f5bd2001ea8453ceb136dc3915fabdc30709db0b1a07ec40be",
"0x811926c08a08601002c8803022a2004040180d1e0889210808d2000420040c6b002d83815b290820700490a1202a8402a",
"0x4c9a310b11d6e4b4d29d7ede30fb42161fd6a58792440f416abda6df55913a8a26c35140524de5dd9519c30f19641f4f0863bfefc2ae6c89333dd77d6f688cffcbde281772cee0dac9bb0dd16b6c1d7bfbfe39bef78dcffdfeaf1bff3ebeff97c7fbf3afb73ef7bdf60ffbfc73debdb7defb7ffabfffef4fff0b9b9ffddabf",
"0x4c9a310b11d6e4b4d29d7ede30fb42161fd6a58792440f416abda6df55913a8a26c35140524de5dd9519c30f19641f4f0863bfefc2ae6c89333dd77d6f688cffcbde281772cee0dac9bb0dd16b6c156a6992311e718ccfd176ac19d51ebafb96472a1327252e7730d60fb9fc33180db506c36a482f7de84fb601899d559a95"
},
{
"0x4d9f3e8aae22123e382e7835d3d9d7e944a5c81cab3415fda40d0ec8fde8a50d8b21b2298f83a65bbdb10d120d302d8db4e9807715be0e",
"0x4dacc1a6f2cecd4179556cbbdfe1cedbc952de5232ff1fe1ae9c0c3bbfcd9087e4ed5bcd1f8c289b1456ef032d888",
"0xa48104308c4c004854008a93414eda4050cc02128a10c0a2180018b8080083c00051001300089b0410070109808",
"0x4d9f3e8aae22123e3cfefc3ffffdfffd57b5dedfbffe1dfdbc9d2fedffeff5ff9be9f2ebbfffff5bffffddbeddf8ef8db5edeef737fe8e",
"0x4d9f3e8aae22123e3cf4b42fbcf53b3d53309ed716ca09101898232ddec754f391c872ea347f7f53c3ffd8aedcc8ef0405acee87276686"
},
{
"0x28d61d5ca1f56b4d3134009f478b17ac208a5b559d9c3726a7a16919e3b12ec6d61a142dc04d834141a9a4",
"0xb444947aba00d50e10326ebea7a2618a10144dde07c15c685d4785eae16d232eb741bc2a09b7cf794a33ed3598803ad61af",
"0xc00104a1e06a041020000445801404008050501c8c160222a16019c2a00a44d610002cc04980010121a4",
"0xb444947aba00d78f71f7eebff7b6f39b501dfdfeb7fbde68fdf7ddfbe37f6b7eb7d1be3b1bffef79eb73fd35d8b43ede9af",
"0xb444947aba00d78371e7a4a1f116b299501db9a6b6bb9e60f8f2dc33221f4954a1d022111b5ba218eb71313140b42ecc80b"
},
{
"0x1b9a0b9c87fa234d05d06e18171cce3f8fc4adf7f75a402c4c5a281f46e714b96badab2184546aa11a7be482616cbb973da00e329628d3e692b69b43d34391884d87fcd64e2339fbb30044a370fffde97a128d1e5",
"0x7d641e556550c3ddb89ee553cbc0d8d92cdaec6519a2ff3bd792e0b309c24cb49056fb219ef4dfb2a72e76ac7df3407a44e55af5689e9c85c87e74d542dfb445f56a0a518c",
"0x78640a55655080008084a001c0405049049ac8201800462a1182a000000248b01052002108608d32212a60a43d30001804c05ac56082108588300440020fb4449520085184",
"0x1b9a0b9c87fa234d05d06e18171cce3fdfc5edf7f75e7dffcdfe7d3ffeef9dbbefafef719e7ffbbd7b7fefb2fd6cfbdf3defbe3bff6dfbeef2f7fbc7df7797ac4fd7ffd6cfebf9ffb7e74df77dfffdff7eb2ad1ed",
"0x1b9a0b9c87fa234d05d06e18171cce38598548a1a2567df7c5b47d23faea992ba6036d701e7b991c6355efb2fd4870de38cfbc2b796528cce051f1840c77962c03d25380c7caf1a734e709f75d04b9b62cb228069"
},
{
"0x142cd4c71f04927a526ca430e542cd9432860",
"0x1337869f6c145daf15b226485ef3c48b8037bf7cb2cc9834153b90f55d4217a5e4a9ea133",
"0x142c90c41804103a106404000500c48022020",
"0x1337869f6c145daf15b226485ef3c48b8037bf7cf6cf9f34977bd2fdfd72f7e7edbdfa973",
"0x1337869f6c145daf15b226485ef3c48b8037ab50660b87308741c299f972f2e7293dd8953"
},
{
"0x4f517f63e95a08284faaf4d4a290c334fc5d039e386727ddbb5d0a6d5fbb5540e97767023d60bedd158ed25051a6c56",
"0x9e2c9c6d2e3be2ad25733871aeba4ba64081294478f936f9c4fc45ada6bb2c098c98f21e709a88995cc3b0cf7e693f8e73f58f8f4735c81e8421182fc15426174f3b6da7b493135c",
"0x4f405a4269120008498a20c400808114cc190096200320c53b5808645318014040110200154020541186d2504120054",
"0x9e2c9c6d2e3be2ad25733871aeba4ba64081294478f936f9c4fd57ffbebfac8b8cfaff5f7abb8cbb5fc7f0ffffef7ffffbf5dfafd7fffd5e8eb77e7fe3d62fffdf7beda7b59b7f5e",
"0x9e2c9c6d2e3be2ad25733871aeba4ba64081294478f936f9c009525b982e8c8b08625d533ab384aa130660f69def4df3a8405f2992ce7d4a8ab66e5fe2822dfa9e638082b1897f0a"
},
{
"0x1713f8f439c07e35b741ec9b0bca80149a7ef129c73c23c34b4515d29dc7dec711007fa395ced70f3bebc6d229edb75bf04231f2414e0a826f3edae4edcf770d59650cc252c6a2eff07fda9baa70938085d1e15144a451d26304d8f3df2406b8eb40f4fae3666780d2e54cd93a5f17439a4d3656dc5d48",
"0x328df4b64b0bd0fbea359666904ea4aa215b03727a70bda853b6cf612b12c3d56ee93b003bd00a7b9c1d6755f580b467deba33bf7f33da4c37fffe79e73e4381ad4bf1306d1b58f5eb276cae813d6f9153d1294c51098d37b3b80154da",
"0x108094864a0310006a219446900e20aa005201603250b00011b241400a0243144ae02900330008610c004244a080b067da9a22301300804021514420411243008843d12004184840e02260260100428140d1284c110188053210005448",
"0x1713f8f439c07e35b741ec9b0bca80149a7ef129c73c23c34b4537dffdf7dfcfd1fbffb797eed74fbfebe7db2bffff7bfdea73f6cf6f2b92effffeedffcf7fdd5b7f9cdf77d7f7eff47fdebbbbffffb3dfddf7fffefdf7fe6385fdfbff346fbbfbf5ffffefeee7bdfff55fd93b5f574b9f7fb7fedd5dda",
"0x1713f8f439c07e35b741ec9b0bca80149a7ef129c73c23c34b45275f697195ccc1fb959603a847419f41e7892a9fcd2b4dea62448e2f2190acebb40dd6cf4cdd531e90df3593576f4418042199cfecb35f9dd6aebaddb6ec208575b82e146ba3b3b51fdd8fc8e6bdbd741f081313464a177a85eedd0992"
},
{
"0x68bc9c8f8257c6c88c0b2d46defc4539748fb906140acbf1a68820d1748bfc13ec84619f2b495d1ce74e0ca441a246497",
"0x2d30db90794c4b611858b19c973ea865904346738291751ba5fccc5cbf02c09876aca6bf23289174f545ad8039e0fbcefe359521dfc9681a7715e672fdc23cc446c7900851d2ed09568729c88bf9653c63f7e229893f31059e8b51924a54968d44e5bb26decae3159ce786d9b3a1454c6d6cb8108d22bd5111d2cc7eddb",
"0x68241c03824200880c0105068a50000854868904040a02d0828000906482d813a004400d2808100c220c0000408046493",
"0x2d30db90794c4b611858b19c973ea865904346738291751ba5fccc5cbf02c09876aca6bf23289174f545ad8039e0fbcefe359521dfc9681a7715e672fdc23cc446c7900851d2ed09568729c88bf9fdbceff7f7efc9bf3b2ddedffdd77b749fbd46f5bbefffeeeb35ddf78ffdb3edc56dff6ff95d9de7ff5db5d3ee7eddf",
"0x2d30db90794c4b611858b19c973ea865904346738291751ba5fccc5cbf02c09876aca6bf23289174f545ad8039e0fbcefe359521dfc9681a7715e672fdc23cc446c7900851d2ed09568729c88b91d9a0ec75b5ef41b33a28d855add77320193442f1b1ed2f6c6b354d930d25a04dc12df247f14d91c5f35db5936e3894c"
},
{
"0x6eef644a36b1e052a413160909a537f81d46b2d330981f507d84737065541b5bb5faebfa8491dcd0347fbe498a501e254b91f6d82d6771a69d0aee5a490e2a44a8ba4f5da963d70b486f36f4a65f372a6a60522cac6e6a01d1a2da8743d5381",
"0x391d108a0ba169bb746b3d5816fa985288c230bdde7e3b8433f8d595b63f08a90448923f30926960cf736be42e377b087e68848af89d80d95122b942b0162153d9d665c0e3508d8a25c8862c0bb7ad4f00e4b1213326f5ce32433df12cb9",
"0x3004000a0a01280130601018127a8050080030098074038003300415003508090408800910800140cb6008a4002250081e688082701800d00020a000a004000380d4408021508482214802240332a406002080002220150a200034310081",
"0x6eeff5db3eb1fa56bfb756bbdda57ff99d6ebef33bddfff3fdc77ffd7d5f7bfbbffaeffba7f3ddf6b67fff7fbe52ff77fb97f6d86deff9fe9d9ffe7bdd2f2b66bdbfdf7ffd6ff70bd8ef7efce6dfbf7afef05e6fbe7f7a6fdde3feb7dfd7fb9",
"0x6eecf59b3e115a443fa450badc245851986e3ef03b45f8b3c5c74cfd3c0f78ab3f6aaf73a762d5f6a273497f3412fd52fb16105065c8f87e909ffc71dd252b26bd87d23bf56de20390cd6a7cc49f8c50be905c67be7d586e8d41feb49cc7f38"
},
{
"0xa210334e6ffbec2fcfa42021075f84222c7",
"0x181b940df674ffa93b3346264fed88e40b8d8f252487bc1f2cb4c3284fa17145d2cd0c77102fc177898e53fb12c40525aeb017a57661a80a268f27b4c78cbb4bae0e96ed0065e32bc7dcb01be9cc4e6bd5db5e453e94855cb2d1d3f86e8218fe55035102fc10901add0eb539089af",
"0x821032440351002c0080000106150000087",
"0x181b940df674ffa93b3346264fed88e40b8d8f252487bc1f2cb4c3284fa17145d2cd0c77102fc177898e53fb12c40525aeb017a57661a80a268f27b4c78cbb4bae0e96ed0065e32bc7dcb01be9cc4e6bd5db5e453e94855cb2d1d3f86ea218ff5f6ffbeeffdfb43afd0fffbd2abef",
"0x181b940df674ffa93b3346264fed88e40b8d8f252487bc1f2cb4c3284fa17145d2cd0c77102fc177898e53fb12c40525aeb017a57661a80a268f27b4c78cbb4bae0e96ed0065e32bc7dcb01be9cc4e6bd5db5e453e94855cb2d1d3f86e2008cd1b6caaeed3df343afc09eabd2ab68"
},
{
"0x2db0666cd0edeeab9e46e5b729521be3ece0714ffeefe18cd1b8b0f17e04c51b0d79fc6d428c22b9af63756",
"0x1c1d5f18453c10d365065465c676fb8b58cb436b88660a0e19c350feb1f6954caf029a43a3e59bb35ce0bdbf80a7b8ff4b4f5d7d133bd244df8813e9695b1a6af9cea293e5da9ce4f8e1035fc8ce4ca62ecbec89e89fe25053e4153899415f61c41fcb412f13b58ac70fb84077831497f",
"0x8906468c0014e888e44a426094009e08ce05043e4052088411820c01e00410b01318845028800318300156",
"0x1c1d5f18453c10d365065465c676fb8b58cb436b88660a0e19c350feb1f6954caf029a43a3e59bb35ce0bdbf80a7b8ff4b4f5d7d133bd244df8813e9695b1a6af9cea293e5ffbce6fcf1efffebde4ee7bfebfe9bebffe2715ffefff99dd1fff1f57fcfc53f1ffdfeef4fbc62ffaf77f7f",
"0x1c1d5f18453c10d365065465c676fb8b58cb436b88660a0e19c350feb1f6954caf029a43a3e59bb35ce0bdbf80a7b8ff4b4f5d7d133bd244df8813e9695b1a6af9cea293e5f72c829431eeb163500a4399e2be920b7302211c1afad91590e7d13561cf84341ecc76aa4d3462ce2c77e29"
},
{
"0x33de1dc3fc5d6eeb5cbca27cc816a3727d1f9188400ea6b2c2799a40f7e611770b45cac7ed49fc0b66a46fcaf2393c0e03741bd08d26308fce62b0c56fbe44cb0949990bc3d4e5919ee1706dce518d6a06e865bdc26e761ef6723241b33583262bc4365103ba49dd17c0",
"0x148a80223564208532d09dd94cf189921325cad8f2a6a32568e36b2007f00866ce0c8e59034cac999f915817492737af76413832e2c4e840627b91b54766a1555e91b87b2692df16c41161184ac9a124d59aad5c06b1a61892cf5c0cd6cc628f764a161f1bdd6546cb51a1510eef5ddfbd",
"0x1121081d84c608910102048c812a222250881080006a00042480800510200240905804005492403262441083220040800601b9085062081444290806b2600cb004011010040c18104c1102d4c0081220080451c00464402867202001311812402c01001010a495d1780",
"0x148a8022356420b7fedddffd5dffebdebfa7fed8f6a7f37d7ff3eb600ff6bae6ff9eceffe75dff9bdfdbdfff49ff3feff66ffaf2fbfcee43767bd1bd6776afdf7eb1fd7fbed6df1fcd996bdbdeedb1bef5faedde57bdee1efaeffdcefefe7eff767a57bf3fdf676fcf77f153beefdddffd",
"0x148a8022356420b6eccd5e25119f62ceaf87b610e405d1587772e3600956baa4b796ceaee55ddb92da5b9ffa00db3cc9d22ef2c0dbf8e6431660413861562e9b3c217d1498d6141f8d886adb9e2c30ba34eac092573ccc1e7aaae1ceb8ba7c79047857ac2e5e436d0f67f052b4a680c87d"
},
{
"0x683d881de1820ee9fbb71ccd74fd10e3a9ce71bd132955b9e9840d9259275498d2fae81b112416f37e9af907c319657d5d81623462b98d93818a23751a2196de6dd7c18e05960",
"0xa9a2ae43423e6c78cc59ceba6601f6d85397527c462767dceeb1ebc6ad425fb2810a2b7525",
"0xa880a002402e24688c104c300601d4d81203422800012018a2314182094046900008205120",
"0x683d881de1820ee9fbb71ccd74fd10e3a9ce71bd132955b9e9840d9259275498d2fafa3bf53437f7ff9efd9febbf657f7d857b7567fdeff7fdceeb7fbe6bd6ffffffd1aeb7d65",
"0x683d881de1820ee9fbb71ccd74fd10e3a9ce71bd132955b9e9840d9259275498d2f07231f5103515b9163c9b28bf056230045b41457defe5fc44c86ba64b42fb96ffd12cb2c45"
},
{
"0xa827c5e2bd4293ed726065b32cac5c18d9df68b18300848f23f98c22fecd6b9fe7ed38a5adedd78f8dfe975d85c171f62b766947d7cd3d2ed3be52b50b792c0d6bb2701e28f22674a092e5ee0ec89bcd52680c6ae673a",
"0x1deac63a0a7ae71db949662f05aafcefed47a6c6dd5819dc82d250d978001903a1f19e1b8b44e76bd5899884bb97121fa13a63c33822314a486d29b59b66f141fd64af3414a3ea6bdca9b4362e704c744e8a12c1ab736636ca3aa9da4b75795f1a",
"0x202040a28c429068606045810c880c00099700018000040921b88402768d48998049382121e813860c328201048000d20b502047140d140ad30042340239080943226004004020202012a52602488388102004428471a",
"0x1deac63a0a7ae71db9496eaf7dfeffffed7ff7e6df5b3bdec7d3ddddfe8b1933a9f9fe3f9bc6efefd7b9fefefb9f5adffd7afbdff977f95e5f7f6bb7fff6fd7dfff6ef3ff5abfaffdee9f6bf2f71eeff6eef5ac9af7fe6fecbbefdfecbf7ff7f3a",
"0x1deac63a0a7ae71db9496cad79f4d73bc47971e0db032b164713dd448e8b0133a9b96c241386c887033066fa681d48c17c429b1cd157e9165f724b02fdf28c3d2eb6420ff188badc4e69628d0971aefb6ced58c8852d86da43867cfccbb3d73820"
},
{
"0x1cc981657c8a20f5c777fc1df0e3cde0b23d434e043732dcaaa0758e009a8d1bf8591ff8db693d676eff2c39645b79c06b510ac22b1b47551eb728aa9404c24f2a6dee6bbdf2276759786f4116d21f4009dd6fb8e277976668bd021effecc797ca23682b97dbdffb93333834b8bb8fb68e922f42e3c00111",
"0x1e52f1e05fbedda88873e9984a7a19bfbfbe9ea43e30588f46317b5cadc8eb02d255875f1dde872476d05dec1164e46c7fcf3fd718fff34a80d4c6e951d10f6ae0225d00e3953e99e",
"0x61010a002b094200063608808400824b2a69ea43a10000644110254014821000015865b0c060124668050200164c4687c823682187db14a801002814181086a60200000221400110",
"0x1cc981657c8a20f5c777fc1df0e3cde0b23d434e043732dcaaa0758e009a8d1bf8591ff8db693d676eff2c39645b79c1ef7f1ec7fbffdfdd9fbfb9aeb7a5dbfffbedee6bfff7aff77b7fffcbdedebf6d2ddd7ff9fffff7676dbddedfffeec7d7fef3fd7b9ffffffb9f7f7eb5bdbbffbe8eb7ff4efbd3e99f",
"0x1cc981657c8a20f5c777fc1df0e3cde0b23d434e043732dcaaa0758e009a8d1bf8591ff8db693d676eff2c39645b79c18e7e14c7d0f69ddd9989b12e33a559b4d18404285ef7af933a6fda8bca5caf6d2c851a493f9fe52105b8dcdfe9a2815036d0955a1824eb539e7f56a1a5ab79188cb7ff4cda93e88f"
},
{
"0xb77c8e0971a4f32bc9539c14b542ed2fa08e87560981cbdca4ccf4f7cc04fe7546a4a7eebe2592d131329fd591f66728a4179e",
"0x2fb77bc1694a8265e74ee9f41672fc681d72ea8eb65ef5807bcba4bc52ef9e381a4e4315a771497e506b734def1ca93dd519fe9e6944dd782380dff70b72798c",
"0x327c080970a08222485180108100ac02a08e0012080101842048745048004c6504a025c4182492410010180180d6670820118c",
"0x2fb77bc1694a8265e74ee9f416f7fcee1d73eeffbfdff79c7fffe6fd7fef9ebf5e4fc3dffff5cdfef7ef77ffff5eadbfffbfff9ef975fffff791fff72bf67f9e",
"0x2fb77bc1694a8265e74ee9f416c580e614034e7d9d97a61c6f7ee6517d4f10bf4c47c2de7bd5858aa7a777b39a5a0d9a3ba7db0cb875efe7f611299023d66e12"
},
{
"0x89a0fbe80f4c622f45f4f7a15d8dc23bff17d939349f39cffa643af024db78243fc46c7948ab14ea12595e8a6cf2196ed4f353d9b1b8834b96fb61073301b99af019f042b2215e8cd5f31cf65123dab47d6b697a",
"0xc2b6f7a999af54a94c156f771b995b528",
"0x22215a8890f108944102d23039012128",
"0x89a0fbe80f4c622f45f4f7a15d8dc23bff17d939349f39cffa643af024db78243fc46c7948ab14ea12595e8a6cf2196ed4f353d9b1b8834b96fb61073301b99af019f04ebb6f7e9ddff75ef6d177fff5fdfffd7a",
"0x89a0fbe80f4c622f45f4f7a15d8dc23bff17d939349f39cffa643af024db78243fc46c7948ab14ea12595e8a6cf2196ed4f353d9b1b8834b96fb61073301b99af019f04e994e24154f06566290752dc5c4fedc52"
},
{
"0x61cc2de53fe06a0381ce0dc4999795469453324c9036484632c257f02dddee71188198ed649bbe9ddae347178970bfbd3f1f28a787ee407a433f8473ba4fb77940227b769c9d555a8a70917ecfd038f80da4c6d5dc7211cc468c69a2275cfc119f145d2887543bbeb24",
"0x117135d192a9645062d1be59a1f8b151692159285e5877a0ae304521ad800f51fbba812d038e053cb79578c70cd34248a2b4026533bb961add83d9362893b74ce01695861c82b6f94f181feb4a957875c74cf1e7fe48dcc5196bf1214cc564f599168bf2fee1a07e617cfac992443fcdb28247",
"0x1c408050b000202018205c4811200420452124800340802200250302051ca71108010cd24008a09402243138960ad983d13208103644000411800402a4f947100223020148554508a1011648dc010900d0004c454421180408c29a20204e4118f04192003541b28204",
"0x117135d192a9645062d7bedbfffbff57e9395de8de59fff9fe794533adc90f75fffbad2d7f8eddfef795f8df8ed74bfbebfdae7573fb971bffd3f9f6aafbffece7b6b7fe5fbbb6fb7f9c1feffffdf9f5d7ecf7efffecfdc79febfb6d6ddde7f59dd6ebf6fee3f5ffe17dfbcdd2cc7fcfbbeb67",
"0x117135d192a9645062d7a29b7fab4f57c91945c88211eed9fa59001289490c357fd9ad087c8cd8e25084f0de82050bf34b69ac5142c30111265028c4a2ebc9a8e7b2a67e5bb91202388c1dccfdfcb1a092e456eee9a421c696eb2b6d2198a3d485d2e33464c3d5b1a0650b8c40cc4a8e096963"
},
{
"0x1af3ce2ba6101f661c52430ae7280e3491d8d044a6621c3ef348c4e6e45fc6dfc91ec46b27214a9ebff52a0922fdebf1e895cd7cc4f428c64b7b3c4711b53f1f04f25b2f63ba70f281f52cb8149509f1ad38156397556eedf9e5c72388364cdba9112913",
"0x5c5811bd255dad9049ec956e6eeaa95895e56e1c5c03cbfe24ae065ac3f528fda51a966771d288dfe3aab7611232e6f6bde10cf0d97620ebde6370ab24dbdecd4d7783c05cc8579517951049f16b26cf1612f6344a669d93ac990a997dfb5180a07a75f6a20dc110fd5547e744cfe0b348cc1786d8c7f587dc83fd9e8fdb9",
"0xa00e02861011200452010885280a201010000426621c10c3088462041dc61708124429240042183c050801205169510095043044f02006434024411130091000925b25000a00a201602098100501502c30046203140cc1786584230834481b89002911",
"0x5c5811bd255dad9049ec956e6eeaa95895e56e1c5c03cbfe24ae07fffff7bafda5fef7e775f2aeffe3ebff7d9f36eef6bde3eff4dd7e6eeffe6ffcbbecdffeff5dffebff5ee8d7bfdfbf1ec9fdffeecf569ef6b7fbe6fd9bfff9fadf7dfbf7bba77f7dfff2cfc159fddf5ff7c5dff9f75eeedf9edcf7fd87fccfff9f9fdbb",
"0x5c5811bd255dad9049ec956e6eeaa95895e56e1c5c03cbfe24ae07f5ff17929ca4ecf7a255e226ad6349fe7c9f36ac909c22e3c455384eae220e8c3ac89d6cbf59de683f0e68c5bac92a0ec0adbcea80549e9283f9a2ec88ff68fad65849a7bb07755de9f0c64059adca5d34c599d9c61e22c81884b5cd04b84e470f9d4aa"
},
{
"0xcd10bb69c381582eff7391a446db73312e738c6978564b350ca88e09cad650ef89dfb4cb00831c41d4739e957fdac00124348c91183da60b8f12dd3e349cad8b8d752fd9ea5613b1a41818032e0a2f2030790009a4fe9cdca54f96402b143e",
"0x7c4f944973a8882522976043833419c2c15b1531af1207b40092dd1e3c123a4cf06370c3111b",
"0x104d140010a888052007404202101180001801200a020030000009043c10180440024003101a",
"0xcd10bb69c381582eff7391a446db73312e738c6978564b350ca88e09cad650ef89dfb4cb00831c41d4739e957fdac00124348c91183da60b8f7edfbe7dffad8bad77bff9ebd737b9e6d95b173faf3f27b47992ddbefe9efeedfff770eb153f",
"0xcd10bb69c381582eff7391a446db73312e738c6978564b350ca88e09cad650ef89dfb4cb00831c41d4739e957fdac00124348c91183da60b8f6e92aa7def0503a857b8b9a9d527a866d943161fa53d27847992d4bac28ee6e9bff530e80525"
},
{
"0x1cdc2579b3f1727c03a0f733c6a1a50025c8b51640ed21fb0e700f873d35c83797a14",
"0xe3e7298d39a9c7cd225125b1a01505e3d9ca63f8b494e4d7218b10e8bddc06984bbbe43e263f30f6a92a9d7",
"0x10042120110162580220f03084a085000100a0144004004b0a600e063d30c02102814",
"0xe3e7298d39a9c7cd225dfdb5f9b7f5f3fdcbe3ffb7d6e5f721afd8fdbfdcefb9fbbff43fa73f35febfbfbd7",
"0xe3e7298d39a9c7cd224df994d9a6f491a5c9c30f8752457221aed85dab9cebb9b0b59431a102053e9ebd3c3"
},
{
"0x3ac7a7062a50d421ec7b732acfeafd988b5fe95661d371a7f2fdb5b9c1d37e304dd3a0dfcb995e9f99e1b86696b54df83fcd4e87764ffe27fbbd785875c31993f20f4628df79cbaeb50c3dfd132e20935f33ee0276c23f445dff5a075a8198907c1e248787fb28c44495d2e2ed677832432eeda5026afb91467cef4b8",
"0x12659e0b26181845981459681797ab57a50c5b4a34882e973f884d99c1e89c0457b99c9445be077039c60cffa057c608594d38423730d3eae76e8a8db6f946877e90bfecde4aaa320128ef3811cd31c3834e66fa7a61d1454778bf82781c091ae5fd348fd903d85116f83f331d84edaa925d1d65b0b30c1b7c6c69da380",
"0x20860306081044000459600287aa5580085b481400021127804d9181c0900410099080458a0150198000b820168408580d0842073043ea276a88081071420112900f44084a280200200c3811012000834e22ea0260c0054458bf0200180118807c14048103d800044015120084652812410c65a002081b104468ca080",
"0x127fdfaf263a58d5b9fc7b7b3fdfebffbd8f5feb76e9fff7bffafdbdf9e9df7e77fddfb4dfff9f7ebfdfedffe6d7f74df97ffd4eb776dffee7ffbffdfefdc79ffff2bfeefedffbfbafbdef3dfddf3fe3935f77fe7a77d37f477dffda7f5e899af5fd3eafdf87fb79d6fcbff3ffedeffab25f3fedb5b36efbfd6e7dff7b8",
"0x125f59ac20324891b9f8221b3d5841aa3d8704a362e9fde6987ab02c78294f7a67f44f349a759e2ea65fed47c6c17345a172f50cb0469c14c09537f5ee8c859eed62b0aaf695d3f9af9de305ecde1fe3101155147817137a032540d87f46888275812aab5e842379d2bcaae1ff698ad2a01e338815b166e0ed2a1535738"
},
{
"0x39d2210d760b098917fd1293f0708ed6ffcd7686a4041e774a0f52e808524d686429da6774dd45dcf69abb4a7a48116d71f8e38074196cddf128b041a28cdc1e12cf755c7",
"0x59d65c9b948dab08f5c3604fb8b4d15085e4ae6ea8e762bbcceb904b3d9b5837977c4c9f2b9e9f3f8c6babd3b5e846ed8bdad898648bc4f8ccbea95d7a9cf5fd694e6b1a176058fbb30257aafa296741ab7181398c43a264a94972c08b4a5c56807a5f06b5b88eb420df822b43c43b400d0",
"0x284221095208080003c41080b0200c529cc5740004001a17400852a000520868202140237081018c42822008484000094058428070190495b008b00082800802000b400c0",
"0x59d65c9b948dab08f5c3604fb8b4d15085e4ae6ea8e762bbcceb904b3d9b5837977c4c9f2b9e9f3f8c6babd3b5f9d6ed8ffedb99ed9ffdfadffef9dffefffdffefee6f1e776a5ffbfb0a57effa6d6fdbef75dd7ddcf7baffeb7b7ad1ef7bfcf7807e5f6efdf9aeb461ff8eff5fd6ff755d7",
"0x59d65c9b948dab08f5c3604fb8b4d15085e4ae6ea8e762bbcceb904b3d9b5837977c4c9f2b9e9f3f8c6babd3b5d194cc86acd391ed9c39ea5f4ed9d3ac63388befea6f04602a57a95b0a05e7924d4e9bcc055c7c50b538dfe3333ad1e63ba4b5000e466a6849a604617d0ef75dd6f435517"
},
{
"0xcf08fe64414998cc59938913e660f0f9b221f459cd8e04126cf902d0b6cea0edc26164b9d84e9ce7dfe058c1fe0fb452848616368c3",
"0x234286d14c1098ea9fd7f83508641ef3288da679fce09dd1359514ebf0dbcdc73b8f7f6171762d3d5df6492591c9386",
"0x4000910810806090d1b02100400c820000247900c094c0208500616099c84618875f6050402c0d145200041000082",
"0xcf08fe644149bbcedfd3cd13feeafffffa35fc7ddfff2c9feef9fef0bfdfb5fdd6ebf4fbddcfbfefffe179f7ff3ffdf6cda797ffbc7",
"0xcf08fe644149bb8edf42c5037e8a6f2e4a14fc3dd37d2c9fca80fe302b1f9578d68a94621589a768a08129b7d332e9a4cda387ffb45"
},
{
"0x343e32e61b86c0c7cc895cf233ea3d5b5ad65435c1f87e034b59788a9af14ffae9249f1f3cfe0789abbe8edc8ce",
"0x63f7afb1dcebc9d65f9d468754ea558119988cb7d85e427003f2c1d9b360d2c75b97c1308ee3a7b5901044c6353e14f3e6b54a2ead64acdf914c6f7b6d4ed3205abdc78aa7bb47d548607b4ffe1db7331aac39c8bc7fcfd62238467352656a3ad04a423",
"0x241e10440b024046c00058b0038a251b42d4402041487e010311188818c00c7ac9040218047202012a3a8048002",
"0x63f7afb1dcebc9d65f9d468754ea558119988cb7d85e427003f2c1d9b360d2c75b97c1308ee3a7b5901044c6353e14f3e6b54a2ead64bcffb3ee7fffedcfdfa95efff7eabffb5fd75c75fbfffe1fff7b7aaebbf9ffffeff6bf3f7eff57edebbededecef",
"0x63f7afb1dcebc9d65f9d468754ea558119988cb7d85e427003f2c1d9b360d2c75b97c1308ee3a7b5901044c6353e14f3e6b54a2ead6498e1a3aa74fdad891fa9064ff4609ae01d031c55bab7801efc6a6226a339f38526f2bd277a8d55ecc1845e96ced"
},
{
"0x981ba5db1da1fe952887e32cd21d51ba024022c8d837ec00f9772a111f87644012cee4a01f66d09ef168ebdfb91232e9e8f65d63ee7e6e050ae9707e7b15df4f8037b0d8d427f32429a45312a24081ed5a9c8ec22358f3621c961349638f30e049d00d513901fe065d5364f4cfca93f14a2b1b",
"0x1ba08accd8474ea8d9dc2f10d3c2c2edcbf9c3a909ab45",
"0x38000c048400c0019002e00514240e4cbc883a1082b01",
"0x981ba5db1da1fe952887e32cd21d51ba024022c8d837ec00f9772a111f87644012cee4a01f66d09ef168ebdfb91232e9e8f65d63ee7e6e050ae9707e7b15df4f8037b0d8d427f32429a45312a24081ed5a9c8ec22358f3621c9613497bafbaecd9d74ff9f9ddff16dfd3e6fdcffbd3f94bab5f",
"0x981ba5db1da1fe952887e32cd21d51ba024022c8d837ec00f9772a111f87644012cee4a01f66d09ef168ebdfb91232e9e8f65d63ee7e6e050ae9707e7b15df4f8037b0d8d427f32429a45312a24081ed5a9c8ec22358f3621c961349782fba2c919743f9e0ddd1168e91a6190433505843805e"
},
{
"0x1d9992a4fce731fe937e70ec9efba437b1efa9e5459e3145f8c9142c6988eca9a61273750bcc1f00a64b32bab5a3a4c89858231f4fedce7a73bcc7285bbd18b328ccc298919f5511e973cd124f7e1c3912d52f4593c676f1c3f87a521",
"0x6e195204da93bdade43f0622217647326502417d70305d050d988",
"0x421810045011a921c412062200300210250001447030410008100",
"0x1d9992a4fce731fe937e70ec9efba437b1efa9e5459e3145f8c9142c6988eca9a61273750bcc1f00a64b32bab5a3a4c89858231f4fedce7a73bcc7285bbd18b328ccee99d39fdf93fdffed3f4f7e3d7f57f76f47d3ff76f1dffd7fda9",
"0x1d9992a4fce731fe937e70ec9efba437b1efa9e5459e3145f8c9142c6988eca9a61273750bcc1f00a64b32bab5a3a4c89858231f4fedce7a73bcc7285bbd18b328ccac81c39b8f8254de292d495c3d4f55e74a47d2bb06c19efd77ca9"
},
{
"0x123b8aaf5660144d596f10574b4c232f267222596831",
"0x10ab460448ce805f18a3c1d64fc8cc0c02b2cd5f860d462e33602f09fd131e5468c86997e5a033729b2a03d3c284ee0111488ea",
"0x1021028c0600144801270012000c2028066000100820",
"0x10ab460448ce805f18a3c1d64fc8cc0c02b2cd5f860d462e33602f09fd133ffceafd6f97e5f5b7f39f7eb7d3f2f6ef2335de8fb",
"0x10ab460448ce805f18a3c1d64fc8cc0c02b2cd5f860d462e33602f09fd123decc23d0f96a175a5839e5eb711f076892334de0db"
},
{
"0x17529608c59c36277d9e89f9b275032e62ab42b4dc006f1943e12b088c36657b02937109db797e2fbb83c984f507841be083c5e36dd04a8b7d3",
"0x1d556659e3b765044e08b1f7879bf057ef",
"0x1814004940304104080810368500a017c3",
"0x17529608c59c36277d9e89f9b275032e62ab42b4dc006f1943e12b088c36657b02937109db797e2fbbd7dfe5ff3ff65be4e3cfff7df9ff8f7ff",
"0x17529608c59c36277d9e89f9b275032e62ab42b4dc006f1943e12b088c36657b02937109db797e2fba569fe16b3cf24ba4634efc15a9f58e03c"
},
{
"0x23ed0547893da2de2673832f9e6d988ce38c44a47495c1e0a714eb2f18ec455157cc20ea9da75cdcb0c4e9afa546efb3650b7e5cb7e659359d17fe79d2d5116bcd6c5cca45e0719d063e7df33f6788e5c6bd77c114340748cf553c5aa4992076953c4904181e24bb7c26a6e895d8b808c70133b52c9ca4a2266c2e2302bf777",
"0x3eaf5dd3cbba83558163fd16469a3d64905ff28ee65c15ff01f4d720b1ad669a893671bb614382f2331985333b0af52cbc0af22e50e4cb39d4ab3ad58127b3c481e692bb22dc0b497690e57e6fc84a87c2e1eb85e6c8bfc253fd497fc88",
"0x20aa1d83489880448123a50646922500105cb286401415170070d20011294408080241a061010232311105230800c42c340010240040cb11140a2091002691040104101a20980800268085582808420102a12884a48026400221003f400",
"0x23ed0547893da2de2673832f9e6d988ce38c44a47495c1e0a714eb2f18ec455157cc3eefddf7dffeb3d5e9effd56efbb7d6ffe5ff7eeff7d9dfffffdd7f5b1efeffeddfe75fb71df86fe7ffbbf77bbeff7bdffcbf63e57eccf7dfcfbbedda177b7fcc9e69abf26ff7f6ff6f8f5feffc8cf87f3f5ef9de6eabfee7fff4bfffff",
"0x23ed0547893da2de2673832f9e6d988ce38c44a47495c1e0a714eb2f18ec455157cc1e45c0749766339168cc5850a929586fee034568bf6988e8ff8d05f5a0c6abf6d5fc345b10de84cc4eeaba54b3ef3391cbcbe61a57ac046ce8f19e4ca15126f8c8e28aa50667776fd07870a6d7c08d86f154c719426a99ae7dde4bc0bff"
},
{
"0x4881b1172db56487aa0b4362479871a57",
"0xd40bc374f241c2bb638ed6dea08d7885135052619d2f58523b3218b57371993a62bea6cfc8abf4abb8e4a96b0a38bbffffdd0bc5e5a6514f0db",
"0x4081210228b16487880b4160061041053",
"0xd40bc374f241c2bb638ed6dea08d7885135052619d2f58523b3218b57371993a62bea6cfc8abf4abb8eca9fb1f3dbfffffff0bc7e7e7d97fadf",
"0xd40bc374f241c2bb638ed6dea08d7885135052619d2f58523b3218b57371993a62bea6cfc8abf4abb8ac28da1d150e9b7877008687e1c93ea8c"
},
{
"0x1e0e22b43b6de9f7ee3000e87eef492f84ee1bcd3f490cdbf35171b174335fe53afa9b752d9b1e1b0bd58d71d35687cb7b74",
"0xac57c7cfa532414e1182c7c499ffa996f7a28187f7f5d7586f0fd6b64e566bff1ff68daa60d7b650cfece99b8e2551941008aaa5ab966c526d584251600baf9f48d6b573e2779363363cea427961c0ac63d9c9abcc30976c3755b739dcbcccfbb7ae06b5deed54c59a5271caaa26134877898f75b065f3c72a8429ab5",
"0x40602140a4429948a30000876c3410b008c0bcc0f0908c0635160914411052518aa82612483181803510451105280421a34",
"0xac57c7cfa532414e1182c7c499ffa996f7a28187f7f5d7586f0fd6b64e566bff1ff68daa60d7b650cfece99b8e2551941008aaa5ab966c526d584251600baf9f48d6b573e2779363363cebe2fb6bc3beffdfffebcc3e97eef7d7ff7ffdbcdfffb7efbfb5dfff57c7bffe73efabb753d9f7e9bffdf8f7fff76afcbfbf5",
"0xac57c7cfa532414e1182c7c499ffa996f7a28187f7f5d7586f0fd6b64e566bff1ff68daa60d7b650cfece99b8e2551941008aaa5ab966c526d584251600baf9f48d6b573e2779363363ceba29b4a831abd46b748cc3e1082c3c74f773d001f0f2763b980c9f64386afac226503914191c6683fc8e8b2eef242f89e1c1"
},
{
"0x46529c1d4b03b4a0efd29ce200ce9564cdc4fa4b53b9b6725e3fffe3454d6e53848fa573858f0bdbcf846d790a5bfc7470d0b8ac1d494804fa7048b869d5e016e389bf93cb959469dca3f4c5e93f8bcb7dbb64bcec19c8d9dbc5f2cecb285d81f5fefe99ff4564662c7cc275a40f0ea519adb2",
"0x1b10fed79bfd5e52ba14eea13cf223bfbeb5f42bd781083545c4306ed5f69250efc19707288aadf9df45b4056a293da0cfae076ee9b08e7a7058ef0a58e67149980cdc60a75825607ec4e531e9d036e71e3df52048853e3",
"0x1010d6c518485a523810e0a13cf0029790a5b4034701080041c4100045a6000086811601280889f91c01100408083d004e82002ca190864a40408c0818a4510888008440075825601ec4440060c004271a00f02040801a2",
"0x46529c1d4b03b4a0efd29ce200ce9564cdc4fa4b53b9b6725e3fffe3f54fef7bbfdfe57ba5cfebdbcfa67ffbeb5ffefd78d0bbfc5d4b4eedff796dbefdddf076ebabff9fffdfd47ffeb3fecdfbffffefffbbe7bfed9ff8fddfe7f6dfcbeddf8bf5fefe9fff4f777ebd7fee75e7df5ea599fff3",
"0x46529c1d4b03b4a0efd29ce200ce9564cdc4fa4b53b9b6725e3fffe2f442832a3b5a405824c1e1c800a65682e104bec908c03bf8410a4ee9a5196db695cc90646b23600e3fced43f7e302ec913dffd25e6b3831be997387c55a2e6574be59b8b807ca89e130b3778b17fac0447d05ca191fe51"
},
{
"0x1c61ea1ba6135d29a669cc258f24a09ce0c6af1fa717",
"0x277557a8f45578e7730c64350cd3fd389bf96320fb3079402e9949062868fda63a6c371adf34952bd8fbf8a361671041556548ecabc7561f3febfcf26290dc819caa54b8eb26a7fb3a593202b2eb9a87fa214342ea4d639c3487882c7b6a03401d0715171c8ec44d45eff0c2571ca3f556d0d986fbeb5ff",
"0x10416008a4005408a60804218a24000c00802f1ea517",
"0x277557a8f45578e7730c64350cd3fd389bf96320fb3079402e9949062868fda63a6c371adf34952bd8fbf8a361671041556548ecabc7561f3febfcf26290dc819caa54b8eb26a7fb3a593202b2eb9a87fa214342ea4d639c3487882c7b6a03401d07d71fbdbee57dd7fff6ded75cf3ff5fdeddeefbfb7ff",
"0x277557a8f45578e7730c64350cd3fd389bf96320fb3079402e9949062868fda63a6c371adf34952bd8fbf8a361671041556548ecabc7561f3febfcf26290dc819caa54b8eb26a7fb3a593202b2eb9a87fa214342ea4d639c3487882c7b6a03401d06d309bd34a5789775965e954451bf5f1ed5ec0a112e8"
},
{
"0x259856f9c56582b4f8056fdbd37332ff6684ad104683782087ef2b965fa2d22153ca880d735c116878afac5b2477b7f",
"0x1518494828299164e2ee455afe73cd24484df0def1e24c01926bdb2566d44e483a04bbdd5aeab159678305b6ade08cb5bc83e0e63a7bd9e2bb016c355f0fd9e94044e8e9dd380c64ea2f83d239d0987a6864dd1a07c9d742",
"0x20105268c4008210c8040e438331122b2004811040811800044e0a945380c20002c8080111080120000d80002415342",
"0x1518494828299164e2ee455afe73cd24484df0def1e24c01926bdb2566d44e483a04bbdd5aeab15967db85ffbdf6dcbfff83f6ffbf7ffbefff696ef55f6fffeb487efaf9fdfa2d66ff3fabd2fff5d97eefeeffdfb7cfff7f",
"0x1518494828299164e2ee455afe73cd24484df0def1e24c01926bdb2566d44e483a04bbdd5aeab15965da80d931b6d49ef303b61b874ceacd4d6926e45b67ee6b483a1a50b8c22146ff132b52eee5596cefee27dfb58eac3d"
},
{
"0xd8526c4a399bb415b422ab254fb7c9a053c1507e3260aac195366c5fed9ff583053547f1b8f54561838e8d5fff273e25",
"0xdc8169197ca1b7f60394685c3438a5b9ff07c0deafe3d68064567be3d9ad3c577600e0d98c4bda37a6ed8175d437cded052bdf221c4c3d76221331061",
"0x4002480a30180400b42028044527882012c14076200008808434205a6c981501013446d010b540218082854221231021",
"0xdc8169197ca1b7f60394685c3dbda7fdff9ffbdfffe3feb274ff7ffbddbd3d57f726eafd9d5bfef7fefdff7df477ddff1fafdf761c7cfdf7fff373e65",
"0xdc8169197ca1b7f60394685c39bd837d5c9e7b9ff4a1fc3230ad0779dc9129509526ea759518bcf258347e2de46499921ea48b740474d5a3dde142e44"
},
{
"0x47ac96c78ee0c7a9906ce5af63d0ad1b0420e1ca783cc6904ee84",
"0x630297e0f122e36f0c5f2f34efbb078c2f4c00e7c16f96cb054",
"0x20028780e002a1000c452f20c0a90304204000600046904a004",
"0x47ef96d7eef1e7ebff6cffaf77ffbf1f8c2fedcafffdef96cfed4",
"0x47cf94506e11e54aff60ba80573f161c880fadca9ffda90685ed0"
},
{
"0x432a40ea48fcb8b8161bc19a26b544f54833bf5e005c7d1c19e8405c5464c8c139fdd9b627865e596c513fc68454827f070310dd7efe80306693ce441c89a74d91db5e27d6ba966aa1e109cc8385bd86a23d127cf609eea4118e0e1d9be83b561dcffb0ec3844d22",
"0x70d78d38ebcadb77733fc709a6d3b76576ca71acd7e3196640d6adc00225142070b943d5624a3a3d4e77a787d8221848ab06c5135",
"0x50c7880002481864410882008011b560744a212482021004401009c002211020402002c0400820214836838540001800a80044120",
"0x432a40ea48fcb8b8161bc19a26b544f54833bf5e005c7d1c19e8405c5464c8c139fdd9b627865e596c513fc68454827f070310df7ffed3befebfff773ffdf7dffdfb7e77febf9eeffff19fec8feffd86a27d527fff9dfff635afafddfffa7b7f9fefff8ef3ec5d37",
"0x432a40ea48fcb8b8161bc19a26b544f54833bf5e005c7d1c19e8405c5464c8c139fdd9b627865e596c513fc68454827f070310da738653beda3e79332f75d7d7fce02870ba1d8ca7dfd09fa88eef6186806c507bfd9dd3f2352dadc97c92432b9fee7f8473e81c17"
},
{
"0x7c4c2d104ca2a5c080fbf1e717e47f848ff9be3555bcff60c07907ade9e334a556157dcd28ebbfd73367defdc4d8f5de60815360394e4de6e7535d356ccb8a2d896157ba65a7e8541a06e604454aef3e8cebfc7aedb48466eb65039cf17c13fcdb1b",
"0x2a73b2854f05d043d4e28e0b2634fd7023aaf3e57e58f213dd0693769",
"0x2a0100804e00404084e2880a2604ac50000262a45018c213c10681309",
"0x7c4c2d104ca2a5c080fbf1e717e47f848ff9be3555bcff60c07907ade9e334a556157dcd28ebbfd73367defdc4d8f5de60815360394e4de6e7535d356ccb8a2d896157ba65a7ef7f3a56f65d457fef3eecfbff7fffb6beefff77e79ff17dd3fdff7b",
"0x7c4c2d104ca2a5c080fbf1e717e47f848ff9be3555bcff60c07907ade9e334a556157dcd28ebbfd73367defdc4d8f5de60815360394e4de6e7535d356ccb8a2d896157ba65a54f6f325216594177a1166c599f353ab6bec9d532e613d041c395ec72"
},
{
"0x3ee957090c3ab10e1c8af669f2093bba430a4322a741522d2ce1d20b07558298627de3dbbbef8828abc64195bad0f9f6acbb734a420d0d8dd330e90d23ab633826a612060eb95070758199006b547b24792d59f97c3191b2dee7a96e",
"0x7e30cfb7abf89648583c2f705f30abb997ded579a0de3172e2b546c920f92fbdf3bf5ffbd5d73620da518e7b4964a44505817d16c7028f4da494135d2589deffbfdb19f6a454f0431cda1884e51f48c67605f9f044e955a4f23da9dfa92af8dfba09ea6adf0390c",
"0x4e102090838a1061808e20122091028020a02228701502d2c415202050500802014424010480000284000949a4041348018114a420d018d42004904218921080600100406205010040091004b005a0478000989782090a28ce0290c",
"0x7e30cfb7abf89648583c2f73ffb5fbb9d7ffd5f9e8ff77ffe2b7ffed30fd3fbff7bf7ffbdfdf36b0ff59afff6ffebdffbff9ff9eff669f5fad9f9f7fefbffeffbfdbd9ffb75ef0d33efe3b86ef7f68e6ff95fff75cf9d5a6f77fbbdfbbffffdffb19fb6fff7b96e",
"0x7e30cfb7abf89648583c2f73b1a5db295475c598687157edc226fd6d105d1d9787aa7d291bca1690af09a7fd6eba99febb79ff9c7b669616099b8c37ee3eea5b9f0bc12b975a6091266c2b068f7e68a69d90fef71cf0c5a2477a1b983bff67487910f1473179062"
},
{
"0x20265b43c9319cd56eac6a02cbf7913ba44b",
"0x995b92e854a8e0d548bfc02e18529b37790f0e4d9aaf36e7abc4a0f1e6d69489215aaa61b5863b1c86b3536b443dc639d1eb3db7789c2cb2f8cad1a74e5168ef33948c81a06fbad3b9ab0b7c84045cd1f77620ef43c7f2088d2901917bec5346a44f679be9491d273dbe5bf6e39095bb411cac63e38626013d671445c",
"0x20261901493010c0462c2802401390310448",
"0x995b92e854a8e0d548bfc02e18529b37790f0e4d9aaf36e7abc4a0f1e6d69489215aaa61b5863b1c86b3536b443dc639d1eb3db7789c2cb2f8cad1a74e5168ef33948c81a06fbad3b9ab0b7c84045cd1f77620ef43c7f2088d2901917bec5346a44f679be9491d273dbe5bf6e7b4bdbb59ddfeebe7a62ebf7d77be45f",
"0x995b92e854a8e0d548bfc02e18529b37790f0e4d9aaf36e7abc4a0f1e6d69489215aaa61b5863b1c86b3536b443dc639d1eb3db7789c2cb2f8cad1a74e5168ef33948c81a06fbad3b9ab0b7c84045cd1f77620ef43c7f2088d2901917bec5346a44f679be9491d273dbe59f48624a92858d1fa8925260abe4474ae017"
},
{
"0x20a92c71c161a786989694109718416d7a291b8f9c71a5a71ee827e003a5a19cf2aa8faeecbfa231c330e2d4c747b75ccc4d43d8c37472b60",
"0xc2ba3ef844b62f020cd6e4b010499c2c28ab3c15ed2ef3114e5b806244e57be1a7d999a21399c1e950977f021c82a906bed39caeec6aa077628421f9d5dfed01b24fe857000e259537fbe07d6a83080080ae927512d4518f9a56f0a40376234855377d8ef40dcb6055bd8d351",
"0x20282071400021809096840092084045000801851471a0250a80000000a480141280018e8816a020033022404507350cc40d4340413400340",
"0xc2ba3ef844b62f020cd6e4b010499c2c28ab3c15ed2ef3114e5b806244e57be1a7d999a21399c1e950977f021c82a906bed39caeecebac77e3e5a7ffdddffd11b75fe97f7a2f3f9fbffbe5ff7eeb2fe083afb3fdf2fedfaffefff2b5c376e3dcd777ffdefc4dcbf8d7fdffb71",
"0xc2ba3ef844b62f020cd6e4b010499c2c28ab3c15ed2ef3114e5b806244e57be1a7d999a21399c1e950977f021c82a906bed39caeccc38c06a3e5867f4d4979112557a93a7a273e1aab8a45da746b2fe0830b33e9e07ede2176e95295c046c19c9270cad2384088b896c9ff831"
},
{
"0xf6b7f399370d10b097b17e514f044d77a8f170148f4837033bb5d425f73a4079e1c7a9c3e69246f902d8c9fd27caad1e93d83578d4af8d3b7b1c02041c44917a22ed56f2562ac1426a356f8d31965e8e367b8929f3907b1dc6e73a8f3a566ca5c4e113e9d2c53770b110df51cf504701ff3fcea5b819b9bfc49f",
"0x61989df2b7097a6a84dc016aec2716d9cac359d2d799d90ec006a66efe3f1fd0851978c4cfe2f64b307b852e23f5dfdc2f63196e1076782a228a46f5f7d4e54afc1ad7abf1f8fef46edaad1706956f95eb95953bd4",
"0x990290097822808c0002c82510d08a8119521400000c40002222ec1612500001404005628401105a8426238109d0006319460032082a020804c4e110e142c41250a110d850c440420117068425900991950094",
"0xf6b7f399370d10b097b17e514f044d77a8f170148f4837033bb5d425f73a4079e1c7a9c3e6f3defdf2ffc9ff6fcefd1ffbfc377eddefcf7bfbdf9bdd1ec497fe6eff7fffd6afd97aeeffefff7bb67f8f3e7bfdffffbf7b1deef77eff3a76eee7f5f7d7eddafd3ff7bbf1ffffff7edfadff3fdfefbdfbbdbfffdf",
"0xf6b7f399370d10b097b17e514f044d77a8f170148f4837033bb5d425f73a4079e1c7a9c3e6f3de64f06fc0874d4e711ff934126e0d654e62a9cb9bdd128497dc4c1369ed86afd83aaefa8d7b7aa6250b18587cf62fbf1804a8f74cf71074e6e33116c70c98392da71ae127af3b3e9dace8395bca2df22c2aff4b"
},
{
"0x31d126e874580b754389fad8b64aaa61cabb4f8eb6904fe7e504341ed903f7daa3e74d4da3afca80b2415672a",
"0x16fb17a0468c0afa6bad456efa4f9baf26860eda9d7c00c2520c8c9b6026fb50df59b8cb74f6d9be861052c5e831158e7ffd98746328ce11f91d9ea22f0803a8b059aea22d1715ca1abeae53a8bc6b8bfb9b6c9d24ae714767",
"0x11100e0745803440288e0189048aa20c0800a8a04904a22c10014008902e51a83c6080da1a6c880024114722",
"0x16fb17a0468c0afa6bad456efa4f9baf26860eda9d7c00c2520c8c9b6026fb50df59b8cb74f6d9be861052c5eb3d17eefffd98f77738dfbdfb7dbea63fabb7f8fb79aefe7f5757cbffbebf7faabe7fdffbbbfcbd2fae75676f",
"0x16fb17a0468c0afa6bad456efa4f9baf26860eda9d7c00c2520c8c9b6026fb50df59b8cb74f6d9be861052c5eb2c07e0f8b818c3371051bc7279340433a3b7505b30aa5c5347568bf72e912e02821f5f21a190352f8a64204d"
},
{
"0xbf1a14e469c234b72d56324d100e016bc38cdf7158e35f230c047585e7b107acc8e222e7f19552541e59316affd90e96ca657b6112f5e8c786dfcff342fc46252fcdab10c632578540dbf6235f164bc5711924c7c6ba9da85ab",
"0x5dd3fb9a3de26cd89eb9517af6bb25678f149f906e8751a0c20d7646d21c17191237022a990e0156541e376986fd6a680c60228e5955df08bae5789c81751cdcafe5a2e72d45b09",
"0x5d5158821d220c001481413006a800620204919042041000000876400214020112210220880600564412026806252a480800020251054008b22158140145101824c582a20d00109",
"0xbf1a14e469c234b72d56324d100e016bc38cdff3fbfb7fe36cdcffbdf7fbf7bfede7aff7ff957ed75ff9f36fffdfde9edf7d7b7712fff9cf87dfdfff77fdc6fd6fedaf70e6be5fd5dfdbfee77f9ecbf57dddafe7e6ffbdedfab",
"0xbf1a14e469c234b72d56324d100e016bc38c82a2a37962c160dceb3cb6cbf117ed85adf36e053cd34ff9f367899fdc8add7c695610df71c987899bed7595c0d845a5a770e4bc0ed09fd34cc6278acab06dc58b22645db0edea2"
},
};
bool opa=true, opo=true, opx=true;
//////////////////// AND ////////////////////
for (size_t i=0; i<COUNTOF(tests); i++)
{
Integer m(tests[i].m), n(tests[i].n), a(tests[i].a);
opa &= ((m & n) == a);
opa &= ((-m & n) == a);
opa &= ((m & -n) == a);
opa &= ((-m & -n) == a);
Integer t(m); t &= n;
opa &= (t == a);
t = n; t &= m;
opa &= (t == a);
opa &= ((m & m) == m);
opa &= ((n & n) == n);
}
if (opa)
std::cout << "passed: ";
else
std::cout << "FAILED: ";
std::cout << "Bitwise AND over 32-bits to 1024-bits" << std::endl;
//////////////////// OR ////////////////////
for (size_t i=0; i<COUNTOF(tests); i++)
{
Integer m(tests[i].m), n(tests[i].n), o(tests[i].o);
opo &= ((m | n) == o);
opo &= ((-m | n) == o);
opo &= ((m | -n) == o);
opo &= ((-m | -n) == o);
Integer t(m); t |= n;
opo &= (t == o);
t = n; t |= m;
opo &= (t == o);
opo &= ((m | m) == m);
opo &= ((n | n) == n);
}
if (opo)
std::cout << "passed: ";
else
std::cout << "FAILED: ";
std::cout << "Bitwise OR over 32-bits to 1024-bits" << std::endl;
//////////////////// XOR ////////////////////
for (size_t i=0; i<COUNTOF(tests); i++)
{
Integer m(tests[i].m), n(tests[i].n), x(tests[i].x);
opx &= ((m ^ n) == x);
opx &= ((-m ^ n) == x);
opx &= ((m ^ -n) == x);
opx &= ((-m ^ -n) == x);
Integer t(m); t ^= n;
opx &= (t == x);
t = n; t ^= m;
opx &= (t == x);
opx &= ((m ^ m) == Integer::Zero());
opx &= ((n ^ n) == Integer::Zero());
}
if (opx)
std::cout << "passed: ";
else
std::cout << "FAILED: ";
std::cout << "Bitwise XOR over 32-bits to 1024-bits" << std::endl;
return opa && opo && opx;
}
#endif
| [
"dstoneham93@gmail.com"
] | dstoneham93@gmail.com |
12e67f9e8ae40522079580c774feaeac15eea98f | 2477757af584a0f08ab9cb32c571ce7b26c9c677 | /IplImage/MSERFeatureDetectionIpl/MSERFeatureDetectionIpl.cpp | 24c36a2f43a13b7f3c24fbf46b9b270c6e9686ad | [] | no_license | Lorna-Liu/OpenCVExamples | 3966b05f79e8215ef66b3dab20ab551ba54a5b5b | 15069e49ee33ea3e06598bc2c260839400d6ab8a | refs/heads/master | 2020-12-24T20:09:43.979696 | 2012-08-08T09:19:18 | 2012-08-08T09:19:18 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,558 | cpp | #include <iostream>
#include "cv.h"
#include "highgui.h"
int main( int argc, char* argv[] )
{
if( argc != 2 )
{
std::cerr << "Usage: " << argv[0] << " <InputImage>" << std::endl;
return EXIT_FAILURE;
}
IplImage* image = cvLoadImage( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
if( !image )
{
std::cerr << "Could not load image file: " << argv[1] << std::endl;
return EXIT_FAILURE;
}
std::vector< std::vector< cv::Point > > featurePoints;
/*
( int _delta, int _min_area, int _max_area,
float _max_variation, float _min_diversity,
int _max_evolution, double _area_threshold,
double _min_margin, int _edge_blur_size );
*/
cv::MSER detector;
detector( image, featurePoints, cv::Mat() );
CvScalar color;
color.val[0] = 255.;
int thickness = -1;
size_t i = 1;
for( std::vector< std::vector< cv::Point > >::const_iterator it = featurePoints.begin();
it != featurePoints.end();
++it, ++i )
{
size_t j = 1;
for( std::vector< cv::Point >::const_iterator pIt = it->begin();
pIt != it->end();
++pIt, ++j )
{
std::cout << "feature point " << i <<" * " << j << std::endl;
std::cout << "position: [ " << pIt->x << ", " << pIt->y << "]" << std::endl;
std::cout << std::endl;
cvCircle( image, *pIt, 10, color, thickness );
}
}
cv::namedWindow( argv[1], CV_WINDOW_NORMAL );
cvShowImage( argv[1], image );
cvReleaseImage( &image );
cv::waitKey(0);
return EXIT_SUCCESS;
}
| [
"arnaudgelas@gmail.com"
] | arnaudgelas@gmail.com |
a5c70434eb7e6c93bf141f92cdebd3a5016b4158 | c259c459094832814e5132714134729cbca90bb3 | /InfoTechExam/26.cpp | 656cb62a6161936e0086eee46e097d21e98452a7 | [] | no_license | VitaliiShinov/InfoTech | 197c409f36ab9973bf28b7e8895661aeec0ddfab | 8ab2911a55217541e5c1282fe4e47a82e3b50dde | refs/heads/master | 2020-06-06T06:37:54.653625 | 2019-06-19T05:55:58 | 2019-06-19T05:55:58 | 192,667,105 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 209 | cpp | int j, i = 10;
j = 2;
4 10 14
j = ++j++ + i++;
// 5
template<class temp>
void mystack<temp>::push(temp b) {
if (top >= size)
throw std::overflow_error("Stack is overflowed");
data[top++] = b;
} | [
"vitalii.shinov@gmail.com"
] | vitalii.shinov@gmail.com |
0e30375a6b642aa4b5d3ad3f8c177f810b6e869b | 8de81b31bdca6f823cb1133cc612f0afb1489dc9 | /bgurls++/include/bigoptimizer_rlsprimal.h | 39d804547297568e20136f8a7583f76c7d6402bf | [] | no_license | elen4/GURLS | 1de8d24faa1e79b1684ffc326e5d32ddb43dc00f | cda80dd0aca5b197e2efbdd840477592ffb91c8d | refs/heads/master | 2020-12-25T15:51:29.668905 | 2013-07-09T19:54:58 | 2013-07-09T19:54:58 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 5,368 | h | /*
* The GURLS Package in C++
*
* Copyright (C) 2011-2013, IIT@MIT Lab
* All rights reserved.
*
* authors: M. Santoro
* email: msantoro@mit.edu
* website: http://cbcl.mit.edu/IIT@MIT/IIT@MIT.html
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
* * Neither the name(s) of the copyright holders nor the names
* of its contributors or of the Massacusetts Institute of
* Technology or of the Italian Institute of Technology may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GURLS_BIGRLSPRIMAL_H_
#define _GURLS_BIGRLSPRIMAL_H_
#include "optmatrix.h"
#include "optfunction.h"
#include "bigoptimization.h"
#include "bigmath.h"
#include "utils.h"
namespace gurls
{
/**
* \ingroup Optimization
* \brief BigRLSPrimal is the sub-class of BigOptimizer that implements RLS with the primal formulation
*/
template <typename T>
class BigRLSPrimal: public BigOptimizer<T>
{
public:
/**
* Computes a classifier for the primal formulation of RLS.
* The regularization parameter is set to the one found in the field paramsel of opt.
* In case of multiclass problems, the regularizers need to be combined with the function specified inthe field singlelambda of opt
*
* \param X input data bigarray
* \param Y labels bigarray
* \param opt options with the following:
* - singlelambda (default)
* - paramsel (settable with the class ParamSelection and its subclasses)
* - files list containing file names for BigArrays
* - tmpfile path of a file used to store and load temporary data
* - memlimit maximum amount memory to be used performing matrix multiplications
*
* BigArray Multiplications are performed in parallel
*
* \return adds to opt the field optimizer which is a list containing the following fields:
* - W = matrix of coefficient vectors of rls estimator for each class
* - C = empty matrix
* - X = empty matrix
*/
GurlsOptionsList* execute(const BigArray<T>& X, const BigArray<T>& Y, const GurlsOptionsList& opt);
};
template <typename T>
GurlsOptionsList* BigRLSPrimal<T>::execute(const BigArray<T>& X, const BigArray<T>& Y, const GurlsOptionsList &opt)
{
int myid;
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
const BigArray<T> *bK, *bXty;
// K = X'*X;
if(!opt.hasOpt("paramsel.XtX"))
bK = matMult_AtB(X, X, opt.getOptAsString("files.XtX_filename"));
else
bK = &opt.getOptValue<OptMatrix<BigArray<T> > >("paramsel.XtX");
// Xty = X'*y;
if(!opt.hasOpt("paramsel.Xty"))
bXty = matMult_AtB(X, Y, opt.getOptAsString("files.Xty_filename"));
else
bXty = &opt.getOptValue<OptMatrix<BigArray<T> > >("paramsel.Xty");
const unsigned long n = X.rows();
const unsigned long d = X.cols();
const unsigned long t = Y.cols();
BigArray<T>* W = new BigArray<T>(opt.getOptAsString("files.optimizer_W_filename"), d, t);
if(myid == 0)
{
gMat2D<T> K, Xty;
bK->getMatrix(0, 0, bK->rows(), bK->cols(), K);
bXty->getMatrix(0, 0, bXty->rows(), bXty->cols(), Xty);
const gMat2D<T> &ll = opt.getOptValue<OptMatrix<gMat2D<T> > >("paramsel.lambdas");
T lambda = opt.getOptAs<OptFunction>("singlelambda")->getValue(ll.getData(), ll.getSize());
gMat2D<T> *W_mat = rls_primal_driver(K.getData(), Xty.getData(), n, d, t, lambda);
W->setMatrix(0,0,*W_mat);
delete W_mat;
}
if(!opt.hasOpt("paramsel.XtX"))
delete bK;
if(!opt.hasOpt("paramsel.Xty"))
delete bXty;
GurlsOptionsList* optimizer = new GurlsOptionsList("optimizer");
optimizer->addOpt("W", new OptMatrix<BigArray<T> >(*W));
BigArray<T>* emptyC = new BigArray<T>();
optimizer->addOpt("C", new OptMatrix<BigArray<T> >(*emptyC));
// cfr.X = [];
BigArray<T>* emptyX = new BigArray<T>();
optimizer->addOpt("X", new OptMatrix<BigArray<T> >(*emptyX));
return optimizer;
}
}
#endif // _GURLS_BIGRLSPRIMAL_H_
| [
"matteo.santoro@gmail.com"
] | matteo.santoro@gmail.com |
e2064acdd5c9e12e9bd4d0567f332e2b919197c1 | 7e5bd27ebdc180ba3c9e1c8bdca9e2dd2e4b476e | /Hardware/EDFNodeTH02_base/EDFNodeTH02_base.ino | 7a4b6e6426de6ee14e31630c88fc01d25b3c2011 | [] | no_license | emmaanuel/EcoPlug | 4b8207ef9f6518e699fd3f1335b00a7b75ce8931 | 796a6b62fb9a7b4bfbe0f5fe02e4915da1cd8081 | refs/heads/master | 2020-04-12T01:29:33.712592 | 2017-02-05T16:10:24 | 2017-02-05T16:10:24 | 35,061,615 | 2 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 7,853 | ino | #include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <ECOCommons.h>
#include <TH02.h>
#include <Wire.h>
#define NODEID 6 //unique for each node on same network
#define GATEWAYID NODE_BASE
#define FREQUENCY RF69_868MHZ
#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define SERIAL_BAUD 1200
#define LED 9 // Leds PIN
#define TH02VCC A2
RFM69 radio;
TH02 sensor(TH02_I2C_ADDR);
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network
/***************** Teleinfo configuration part *******************/
char CaractereRecu = '\0';
char Checksum[32] = "";
char Ligne[32] = "";
char Etiquette[9] = "";
char Donnee[13] = "";
char Trame[512] = "";
int count = 0;
int check[5]; // Checksum by etiquette
int trame_ok = 1; // global trame checksum flag
int finTrame = 0;
char hc_value[10] = "", hp_value[10] = "";
char power_value[10] = "";
char tarif_value[3] = "";
unsigned long lastMillisTemp = millis();
unsigned long lastMillisEDF = millis();
unsigned long lastMinute = 4;
String currentAction = "";
char buff[50];
int tour = 0;
void setup() {
Serial.begin(SERIAL_BAUD);
delay(10);
radio.initialize(FREQUENCY, NODEID, NETWORKID);
#ifdef IS_RFM69HW
radio.setHighPower(); //only for RFM69HW!
#endif
radio.encrypt(ENCRYPTKEY);
uint8_t devID;
Wire.begin();
sensor.getId(&devID);
Blink(LED, 1000);
}
void loop() {
if (Serial.available()>0){
CaractereRecu = Serial.read();
getTeleinfo();
}
checkLocalTemp();
}
void checkLocalTemp() { // Verifie si c'est le moment de mesurer la temperature localement
unsigned long delta = millis() - lastMillisTemp;
if (delta > 60000) { // Toutes les minutes
lastMinute = lastMinute + 1 ;
lastMillisTemp = millis();
if (lastMinute >= 10) { // Toutes les 10go minutes
sendLocalTemp();
lastMinute = 0;
}
}
}
void sendLocalTemp() { // Mesure et envoie la temperature locale
float temp = 0, rh = 0;
digitalWrite(TH02VCC, HIGH);
delay(15);
sensor.startTempConv();
sensor.waitEndConversion();
sensor.getConversionValue();
temp = sensor.getLastRawTemp() / 100.0;
sensor.startRHConv();
sensor.waitEndConversion();
sensor.getConversionValue();
rh = sensor.getConpensatedRH(false) / 100.0;
digitalWrite(TH02VCC, LOW);
char str_temp[6];
char str_rh[6];
dtostrf(temp, 0, 2, str_temp);
dtostrf(rh, 0, 2, str_rh);
sprintf(buff, "T|%s|%s|", str_temp , str_rh);
byte sendSize = strlen(buff);
radio.sendWithRetry(GATEWAYID, buff, sendSize, RFM69Retry, RFM69RetryTimeout);
Blink(LED, 3);
}
void Blink(byte PIN, int DELAY_MS)
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN, HIGH);
delay(DELAY_MS);
digitalWrite(PIN, LOW);
}
/*------------------------------------------------------------------------------*/
/* Test checksum d'un message (Return 1 si checkum ok) */
/*------------------------------------------------------------------------------*/
int checksum_ok(char *etiquette, char *valeur, char checksum)
{
unsigned char sum = 32 ; // Somme des codes ASCII du message + un espace
int i ;
for (i = 0; i < strlen(etiquette); i++) sum = sum + etiquette[i] ;
for (i = 0; i < strlen(valeur); i++) sum = sum + valeur[i] ;
sum = (sum & 63) + 32 ;
if ( sum == checksum) return 1 ; // Return 1 si checkum ok.
return 0 ;
}
/***********************************************
* getTeleinfo
* Decode Teleinfo from serial
* Input : n/a
* Output : n/a
***********************************************/
void getTeleinfo() {
int i;
/* vider les infos de la dernière trame lue */
memset(Ligne, '\0', 32);
memset(Trame, '\0', 512);
int trameComplete = 0;
while (!trameComplete) {
while (CaractereRecu != 0x02) // boucle jusqu'a "Start Text 002" début de la trame
{
if (Serial.available()) {
CaractereRecu = Serial.read() & 0x7F;
}
}
i = 0;
while (CaractereRecu != 0x03) // || !trame_ok ) // Tant qu'on est pas arrivé à "EndText 003" Fin de trame ou que la trame est incomplète
{
if (Serial.available()) {
CaractereRecu = Serial.read() & 0x7F;
Trame[i++] = CaractereRecu;
}
}
finTrame = i;
Trame[i++] = '\0';
lireTrame(Trame);
// on vérifie si on a une trame complète ou non
for (i = 0; i < 5; i++) {
trameComplete += check[i];
}
for (i = 0; i < 5; i++) {
check[i] = 0; // on remet à 0 les check.
}
if (trameComplete < 4) trameComplete = 0; // on a pas les 5 valeurs, il faut lire la trame suivante
else {
trameComplete = 1;
unsigned long delta = millis() - lastMillisEDF;
if (delta > 10000) { // Toutes les 10 s
lastMillisEDF = millis();
sprintf(buff, "P|%s|%s|%s|%s", power_value , tarif_value,hc_value, hp_value );
byte sendSize = strlen(buff);
radio.sendWithRetry(GATEWAYID, buff, sendSize, RFM69Retry, RFM69RetryTimeout);
Blink(LED, 30);
}
}
}
}
void lireTrame(char *trame) {
int i;
int j = 0;
for (i = 0; i < strlen(trame); i++) {
if (trame[i] != 0x0D) { // Tant qu'on est pas au CR, c'est qu'on est sur une ligne du groupe
Ligne[j++] = trame[i];
}
else { //On vient de finir de lire une ligne, on la décode (récupération de l'etiquette + valeur + controle checksum
decodeLigne(Ligne);
memset(Ligne, '\0', 32); // on vide la ligne pour la lecture suivante
j = 0;
}
}
}
int decodeLigne(char *ligne) {
int debutValeur;
int debutChecksum;
// Décomposer en fonction pour lire l'étiquette etc ...
debutValeur = lireEtiquette(ligne);
debutChecksum = lireValeur(ligne, debutValeur);
lireChecksum(ligne, debutValeur + debutChecksum - 1);
if (checksum_ok(Etiquette, Donnee, Checksum[0])) { // si la ligne est correcte (checksum ok) on affecte la valeur à l'étiquette
return affecteEtiquette(Etiquette, Donnee);
}
else return 0;
}
int lireEtiquette(char *ligne) {
int i;
int j = 0;
memset(Etiquette, '\0', 9);
for (i = 1; i < strlen(ligne); i++) {
if (ligne[i] != 0x20) { // Tant qu'on est pas au SP, c'est qu'on est sur l'étiquette
Etiquette[j++] = ligne[i];
}
else { //On vient de finir de lire une etiquette
// Serial.print("Etiquette : ");
// Serial.println(Etiquette);
return j + 2; // on est sur le dernier caractère de l'etiquette, il faut passer l'espace aussi (donc +2) pour arriver à la valeur
}
}
}
int lireValeur(char *ligne, int offset) {
int i;
int j = 0;
memset(Donnee, '\0', 13);
for (i = offset; i < strlen(ligne); i++) {
if (ligne[i] != 0x20) { // Tant qu'on est pas au SP, c'est qu'on est sur l'étiquette
Donnee[j++] = ligne[i];
}
else { //On vient de finir de lire une etiquette
// Serial.print("Valeur : ");
// Serial.println(Donnee);
return j + 2; // on est sur le dernier caractère de la valeur, il faut passer l'espace aussi (donc +2) pour arriver à la valeur
}
}
}
void lireChecksum(char *ligne, int offset) {
int i;
int j = 0;
memset(Checksum, '\0', 32);
for (i = offset; i < strlen(ligne); i++) {
Checksum[j++] = ligne[i];
// Serial.print("Chekcsum : ");
// Serial.println(Checksum);
}
}
int affecteEtiquette(char *etiquette, char *valeur) {
if (strcmp(etiquette, "BASE") == 0) {
sprintf(hc_value, "%s", valeur);
check[0] = 1;
}
else if (strcmp(Etiquette, "IINST") == 0) {
check[2] = 1;
}
else if (strcmp(Etiquette, "PAPP") == 0) {
sprintf(power_value, "%s", valeur);
check[3] = 1;
}
else if (strcmp(Etiquette, "PTEC") == 0) {
sprintf(tarif_value, "%s", valeur);
tarif_value[2] = '\0';
check[4] = 1;
}
else
return 0;
return 1;
}
| [
"emmanuel@iMac-de-Emmanuel.local"
] | emmanuel@iMac-de-Emmanuel.local |
4a83f7f0adccb430d876d422b757f3d61ac793aa | 87752d226647cf42e925c0264a2355d8ea513be2 | /libHistograms/Histogram.cpp | d499f3a7d6d1bd27045a11a19af7e738e9a03dc0 | [] | no_license | AlbertoEAF/BSS | 401d7d5af12d004c0ec6fcc11807e1ec95f97a49 | a683c01acb83a94268380fa6d11a035953ab26b8 | refs/heads/master | 2021-03-27T20:46:14.280319 | 2014-10-02T03:24:33 | 2014-10-02T03:24:33 | 23,039,104 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 10,052 | cpp | #include "HistogramDeclaration.h"
template <class T>
Histogram<T>::Histogram(double bin_dx, double x_min, double x_max, HistogramBounds::Type bounds_type)
: _m(NULL)
{
// Adjust so that they match
size_t bins_x = (x_max-x_min)/bin_dx;
reshape(bins_x, x_min, x_max, bounds_type);
}
// Needs to have a different signature from the other constructor
template <class T> Histogram<T>::Histogram(size_t bins, HistogramBounds::Type bounds_type)
: _m(NULL)
{
_m = new Buffer<T>(bins);
_bins = bins;
_min = 0;
_max = 1;
_dx = 1/(double)bins;
}
template <class T>
Histogram<T>::Histogram(const Histogram &cpy)
: _m(NULL), _dx(cpy._dx), _min(cpy._min), _max(cpy._max), _bins(cpy._bins), _bound_type(cpy._bound_type)
{
_m = new Buffer<T>(*cpy._m);
}
/*
template <class T>
void Histogram<T>::reshape(double bin_dx, double bin_dy, double x_min, double x_max, double y_min, double y_max, HistogramBounds::Type bounds_type)
{
// Histogram bin count must match the histogram area with the bins size, thus a first calculation is done, then the bin sizes are adjusted so that they fit
size_t bins_x = (x_max-x_min)/bin_dx;
size_t bins_y = (y_max-y_min)/bin_dy;
reshape(bins_x, bins_y, x_min, x_max, y_min, y_max, bounds_type);
}
*/
template <class T>
void Histogram<T>::reshape(size_t bins, double min, double max, HistogramBounds::Type bounds_type)
{
Assert (max > min, "Histogram limits are reversed!");
_min = min;
_max = max;
_bins = bins;
_dx = (_max-_min) / (T) _bins;
_bound_type = bounds_type;
// Reallocate if already exists
if (_m)
delete _m;
_m = new Buffer<T>(bins);
}
/// Stretches the histogram area from min to max, resizing the bins. Clears the histogram.
template <class T> void Histogram<T>::stretch(double min, double max)
{
Assert (max > min, "Histogram limits are reversed!");
_min = min;
_max = max;
_dx = (_max-_min) / (T) _bins;
_m->clear();
}
/// Get read-write access to a bin directly by its coordinates
template <class T>
T & Histogram<T>::guarantee_bin(size_t ibin)
{
Guarantee (ibin < _bins, "Out of bounds bin access (%lu) for Histogram(%lu)!", ibin, _bins);
return (*_m)[ibin];
}
/// Faster version of guaranteebin() without out of bounds runtime check.
template <class T>
inline T & Histogram<T>::bin(size_t ibin)
{
Assert (ibin < _bins, "Out of bounds bin access (%lu) for Histogram(%lu)!", ibin, _bins);
return (*_m)[ibin];
}
template <class T>
bool Histogram<T>::get_bin_index(double x, size_t &ibin)
{
Assert ( ! std::isnan(x), "NaN coordinate given to Histogram(%lu)!", _bins);
// add to the boundary bins if the coordinate goes beyond
if (x < _min)
ibin = 0;
else if (x >= _max)
ibin = _bins-1;
else
ibin = (x - _min)/_dx;
if (_bound_type == HistogramBounds::Boundless)
return true;
else
{
if (x < _min || x >= _max)
{
if (_bound_type == HistogramBounds::DiscardBeyondBound)
return false;
else
Guarantee(0, "Out of bounds access (x,y)=(%f) on Bounded Histogram(%lu)!",x,_bins);
}
else
return true;
}
}
template <class T>
double Histogram<T>::get_bin_center(size_t bin)
{
Assert(bin < _bins, "Requested bin(%lu) larger than Histogram(%lu) space.", bin, _bins);
return _min + _dx*(bin+0.5);
}
template <class T>
T & Histogram<T>::operator()(double x)
{
size_t bin_index;
Assert ( ! std::isnan(x), "NaN coordinate given to Histogram(%lu)!", _bins);
// add to the boundary bins if the coordinate goes beyond
if (_bound_type == HistogramBounds::Boundless)
{
if (x < _min)
bin_index = 0;
else if (x >= _max)
bin_index = _bins-1;
else
bin_index = (x - _min)/_dx;
}
else
{
if (x < _min || x >= _max)
{
// Guarantee during runtime that the histogram is not Bounded!
Guarantee (_bound_type == HistogramBounds::DiscardBeyondBound,
"Out of bounds access (x=%g) on Bounded Histogram(%lu)!", x,_bins);
// Return a "virtual bin" with value 0 so that changing it does not change the histogram itself and if it is read yields no counts at all (the value can be changed by the user though). This value will be reset at the next call in the same out of bounds situation on a DiscardBeyondBound Histogram.
_dummy = 0;
return _dummy;
}
else
{
bin_index = (x - _min)/_dx;
}
}
return bin(bin_index);
}
template <class T>
void Histogram<T>::operator += (Histogram<T> &other)
{
static const double eps = 0.000001;
Assert((&other == this) | (other._bins==_bins && std::abs(other._max-_max)<eps && std::abs(other._min-_min)<eps), "Histograms coordinates don't match.");
for (size_t i = 0; i < _bins; ++i)
bin(i) += other.bin(i);
}
template <class T>
void Histogram<T>::operator -= (Histogram<T> &other)
{
static const double eps = 0.000001;
Assert((&other == this) | (other._bins==_bins && std::abs(other._max-_max)<eps && std::abs(other._min-_min)<eps), "Histograms coordinates don't match.");
for (size_t i = 0; i < _bins; ++i)
bin(i) -= other.bin(i);
}
template <class T>
void Histogram<T>::operator *= (Histogram<T> &other)
{
static const double eps = 0.000001;
Assert((&other == this) | (other._bins==_bins && std::abs(other._max-_max)<eps && std::abs(other._min-_min)<eps), "Histograms coordinates don't match.");
for (size_t i = 0; i < _bins; ++i)
bin(i) *= other.bin(i);
}
template <class T>
Histogram<T> & Histogram<T>::operator = (Histogram<T> &other)
{
if (this == &other)
return *this;
static const double eps = 0.000001;
Assert((&other == this) | (other._bins==_bins && std::abs(other._max-_max)<eps && std::abs(other._min-_min)<eps), "Histograms coordinates don't match.");
*_m = *(other._m); // Data copy
return *this;
}
template <class T>
std::ostream &operator << (std::ostream &output, Histogram<T> &hist)
{
output << (*hist._m);
return output; // allows chaining
}
template <class T>
std::istream &operator >> (std::istream &input, Histogram<T> &hist)
{
input >> (*hist._m);
return input; // allows chaining
}
/*
template <class T>
void Histogram<T>::plot(Gnuplot &p, const char * title)
{
// This function cannot blow up the compilation as it is optional
// so it will be guaranteed at runtime without performance penalties.
// It will require including gnuplot_ipp.h before Histogram.h though.
#ifdef GNUPLOT_IPP_H__
p.plot((*_m)(),_bins, title);
#else
Guarantee(0, "Add gnuplot_ipp to the compilation chain and include gnuplot_ipp.h before Histogram.h.");
#endif
}
*/
/*
template <class T>
void Histogram<T>::replot(Gnuplot &p, const char * title)
{
// This function cannot blow up the compilation as it is optional
// so it will be guaranteed at runtime without performance penalties.
// It will require including gnuplot_ipp.h before Histogram.h though.
#ifdef GNUPLOT_IPP_H__
p.replot((*_m)(),_bins, title);
#else
Guarantee(0, "Add gnuplot_ipp to the compilation chain and include gnuplot_ipp.h before Histogram.h.");
#endif
}
*/
template <class T>
void Histogram<T>::smooth_add(T value, double x, double smooth_dx)
{
size_t binx, minbinx, maxbinx;
get_bin_index(x-smooth_dx, minbinx);
get_bin_index(x+smooth_dx, maxbinx);
// Add the values normally inside the smooth region and inside the Histogram
for (binx = minbinx; binx < maxbinx; ++binx)
(*_m)[binx] += value;
// Add the marginals beyond the borders if it is a Boundless histogram
if (_bound_type == HistogramBounds::Boundless)
{
// p = plus; m = minus.
double xp_extra = x+smooth_dx - _max;
double xm_extra = _min - (x-smooth_dx);
// Right side
if (xp_extra > 0)
(*_m)[binx] += xp_extra / _dx; // Proportional to the outside area in bin-counts.
// Left side
if (xm_extra > 0)
(*_m)[0 ] += xm_extra / _dx;
} // end of _bound_type == Boundless
}
/** Creates an odd-sized (centered) buffer kernel that spans 3 times the FWHM (enough precision).
@warn Not realtime-safe! (allocates memory) */
template <class T>
Buffer<T> Histogram<T>::gen_gaussian_kernel(T stddev, bool *success)
{
// Full Width at Half Maximum: FWHM = 2sqrt(2ln2) stddev ~= 2.35482 stddev
T FWHM = 2.35482 * stddev;
// Should be more than enough for precise gaussian blurring (kernel is very close to 0 at such edges)
T length = 3*FWHM;
// Enforce odd-size kernel
size_t size = length / _dx;
if (size > 1)
{
size -= (size % 2 == 0);
Buffer<T> kernel(size);
size_t center = size/2;
T norm_factor = 1 / (stddev * std::sqrt(2*M_PI));
for (size_t i=0; i < center; ++i)
{
T arg = (i*_dx) / stddev;
kernel[center-i] = kernel[center+i] = std::exp(-0.5 * arg*arg) / norm_factor;
}
*success = true;
return kernel;
}
else
{
*success = false;
return Buffer<T>(1,1); // kernel
}
}
/** Requires a Buffer of the same size as the internal storage buffer _m to perform the computations.
This was chosen to allow sharing of a single extra storage layer instead of having one of those per histogram.
OPTIMIZATION!
For now it calculates the convolution to the m layer and then copies it back into the histogram internal data however it could calculate to the m layer and then switch the pointers of both entities. */
template <class T>
void Histogram<T>::kernel_convolution(Buffer<T> &kernel, Buffer<T> &m)
{
Assert(kernel.size()%2, "Kernel is not odd-sized!");
Assert(m.size() == _bins, "Object doesn't have the same number of bins.");
long int kcenter = kernel.size()/2;
long int ksize = kernel.size();
m.clear();
for (long int I=0; I < _bins; ++I)
{
for (long int k = 0; k < ksize; ++k)
{
long int i = (I+kcenter)-k;
if (i < 0 || i >= _bins)
continue;
m[i] += kernel[k] * (*_m)[I];
}
}
(*_m) = m; // Copy avoidable by switching pointers with the external object (potentially dangerous).
}
// Must be included after the class definitions. Harmless for template headers.
#include "HistogramInstantiations.h"
| [
"albertoeafworks@gmail.com"
] | albertoeafworks@gmail.com |
5267dca7796dba6be6e59028ff715b2e278437ac | fb283eceb2ed2996551f49933c27f2c3890abf40 | /dsp/main/value/Contour.cpp | 6837befec9022c14a291c19f629bf31047cab8cf | [
"BSD-3-Clause"
] | permissive | haruneko/vsampler | 25053f7fc563b0005ad896e54654c4c896691eb7 | 6de88b111bbc6a9802b6d0ac5d04a8ddd3f9d03b | refs/heads/master | 2021-01-10T11:32:55.120657 | 2015-10-23T13:57:11 | 2015-10-23T13:57:11 | 36,995,091 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 203 | cpp | /**
* Created by Hal@shurabaP on 2015/08/01.
* This code is under The BSD 3-Clause License.
* See more Licence.txt.
* Copyright (c) 2015 Hal@shurabaP. All rights reserved.
*/
#include "Contour.h"
| [
"harunyann@hotmail.com"
] | harunyann@hotmail.com |
08f6de28e92876bdb3a2b5fc15a8b742c8a08258 | f06659b908a5f33deb149fa8257aa1ce7eb5ed46 | /c++/arreglos/unirDosArreglos.cpp | fa5878bb37c96e012ee1b8cab21096566d318d76 | [] | no_license | otela3/c-_exercise | 649624b69020632d867a56f3dcdb36c110f57b9f | 49b371e7287a487d055be5d1ce806a479ce9f341 | refs/heads/master | 2022-12-29T03:03:09.084729 | 2020-10-03T18:27:18 | 2020-10-03T18:27:18 | 299,768,939 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 594 | cpp | #include <iostream>
using namespace std;
int main(){
int array1[5],array2[5],array3[5],i;
for ( i = 0; i <= 5; i++)
{
cout<<"ingresar los elementos del array1 \n";
cin>>array1[i];
}
for ( i = 0; i <= 5; i++)
{
cout<<"ingresar los elementos del array2 \n";
cin>>array2[i];
}
for ( i = 0; i <= 5; i++)
{array3[i]=array1[i];}
for ( i = 0; i <= 5; i++)
{array3[i+5]=array2[i];}
cout<<"el array unido es : \n";
for ( i = 0; i <= 10; i++)
{cout<<array3[i]<<"\n";}
return 0;
} | [
"mati.otelo.ro@gmail.com"
] | mati.otelo.ro@gmail.com |
2e9d10b030eaf9574af4baffed89086c0a45496e | fa07dbbaf683acdad6992d508711b691b3bf5557 | /src/qt/walletview.cpp | fe291a908bfc8f15d15ebacf8f1281655a2a7d86 | [
"MIT"
] | permissive | eblockcoin7/eBlockCoin | a0adb00d7ce381acc908795ce739faf54b82b8b7 | 4e8a3c618f5a87d25f074897af8d98cc23f7ad4f | refs/heads/master | 2020-04-04T19:04:28.427975 | 2019-05-04T08:39:54 | 2019-05-04T08:39:54 | 156,190,789 | 3 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 16,021 | cpp | // Copyright (c) 2011-2015 The Bitcoin developers
// Copyright (c) 2016-2018 The PIVX developers
// Copyright (c) 2018-2019 The eBlockCoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "walletview.h"
#include "addressbookpage.h"
#include "bip38tooldialog.h"
#include "bitcoingui.h"
#include "blockexplorer.h"
#include "clientmodel.h"
#include "guiutil.h"
#include "masternodeconfig.h"
#include "multisenddialog.h"
#include "multisigdialog.h"
#include "optionsmodel.h"
#include "overviewpage.h"
#include "receivecoinsdialog.h"
#include "privacydialog.h"
#include "sendcoinsdialog.h"
#include "signverifymessagedialog.h"
#include "transactiontablemodel.h"
#include "transactionview.h"
#include "walletmodel.h"
#include "ui_interface.h"
#include <QAction>
#include <QActionGroup>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QProgressDialog>
#include <QPushButton>
#include <QSettings>
#include <QVBoxLayout>
WalletView::WalletView(QWidget* parent) : QStackedWidget(parent),
clientModel(0),
walletModel(0)
{
// Create tabs
overviewPage = new OverviewPage();
explorerWindow = new BlockExplorer(this);
transactionsPage = new QWidget(this);
// Create Header with the same names as the other forms to be CSS-Id compatible
QFrame *frame_Header = new QFrame(transactionsPage);
frame_Header->setObjectName(QStringLiteral("frame_Header"));
QVBoxLayout* verticalLayout_8 = new QVBoxLayout(frame_Header);
verticalLayout_8->setObjectName(QStringLiteral("verticalLayout_8"));
verticalLayout_8->setContentsMargins(0, 0, 0, 0);
QHBoxLayout* horizontalLayout_Header = new QHBoxLayout();
horizontalLayout_Header->setObjectName(QStringLiteral("horizontalLayout_Header"));
QLabel* labelOverviewHeaderLeft = new QLabel(frame_Header);
labelOverviewHeaderLeft->setObjectName(QStringLiteral("labelOverviewHeaderLeft"));
labelOverviewHeaderLeft->setMinimumSize(QSize(464, 60));
labelOverviewHeaderLeft->setMaximumSize(QSize(16777215, 60));
labelOverviewHeaderLeft->setText(tr("HISTORY"));
QFont fontHeaderLeft;
fontHeaderLeft.setPointSize(20);
fontHeaderLeft.setBold(true);
fontHeaderLeft.setWeight(75);
labelOverviewHeaderLeft->setFont(fontHeaderLeft);
horizontalLayout_Header->addWidget(labelOverviewHeaderLeft);
QSpacerItem* horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_Header->addItem(horizontalSpacer_3);
QLabel* labelOverviewHeaderRight = new QLabel(frame_Header);
labelOverviewHeaderRight->setObjectName(QStringLiteral("labelOverviewHeaderRight"));
labelOverviewHeaderRight->setMinimumSize(QSize(464, 60));
labelOverviewHeaderRight->setMaximumSize(QSize(16777215, 60));
labelOverviewHeaderRight->setText(QString());
QFont fontHeaderRight;
fontHeaderRight.setPointSize(14);
labelOverviewHeaderRight->setFont(fontHeaderRight);
labelOverviewHeaderRight->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
horizontalLayout_Header->addWidget(labelOverviewHeaderRight);
horizontalLayout_Header->setStretch(0, 1);
horizontalLayout_Header->setStretch(2, 1);
verticalLayout_8->addLayout(horizontalLayout_Header);
QVBoxLayout* vbox = new QVBoxLayout();
QHBoxLayout* hbox_buttons = new QHBoxLayout();
vbox->addWidget(frame_Header);
transactionView = new TransactionView(this);
vbox->addWidget(transactionView);
QPushButton* exportButton = new QPushButton(tr("&Export"), this);
exportButton->setToolTip(tr("Export the data in the current tab to a file"));
#ifndef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
exportButton->setIcon(QIcon(":/icons/export"));
#endif
hbox_buttons->addStretch();
// Sum of selected transactions
QLabel* transactionSumLabel = new QLabel(); // Label
transactionSumLabel->setObjectName("transactionSumLabel"); // Label ID as CSS-reference
transactionSumLabel->setText(tr("Selected amount:"));
hbox_buttons->addWidget(transactionSumLabel);
transactionSum = new QLabel(); // Amount
transactionSum->setObjectName("transactionSum"); // Label ID as CSS-reference
transactionSum->setMinimumSize(200, 8);
transactionSum->setTextInteractionFlags(Qt::TextSelectableByMouse);
hbox_buttons->addWidget(transactionSum);
hbox_buttons->addWidget(exportButton);
vbox->addLayout(hbox_buttons);
transactionsPage->setLayout(vbox);
privacyPage = new PrivacyDialog();
receiveCoinsPage = new ReceiveCoinsDialog();
sendCoinsPage = new SendCoinsDialog();
addWidget(overviewPage);
addWidget(transactionsPage);
addWidget(privacyPage);
addWidget(receiveCoinsPage);
addWidget(sendCoinsPage);
addWidget(explorerWindow);
QSettings settings;
if (settings.value("fShowMasternodesTab").toBool()) {
masternodeListPage = new MasternodeList();
addWidget(masternodeListPage);
}
// Clicking on a transaction on the overview pre-selects the transaction on the transaction history page
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
// Double-clicking on a transaction on the transaction history page shows details
connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
// Update wallet with sum of selected transactions
connect(transactionView, SIGNAL(trxAmount(QString)), this, SLOT(trxAmount(QString)));
// Clicking on "Export" allows to export the transaction list
connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
// Pass through messages from sendCoinsPage
connect(sendCoinsPage, SIGNAL(message(QString, QString, unsigned int)), this, SIGNAL(message(QString, QString, unsigned int)));
// Pass through messages from transactionView
connect(transactionView, SIGNAL(message(QString, QString, unsigned int)), this, SIGNAL(message(QString, QString, unsigned int)));
}
WalletView::~WalletView()
{
}
void WalletView::setBitcoinGUI(BitcoinGUI* gui)
{
if (gui) {
// Clicking on a transaction on the overview page simply sends you to transaction history page
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
// Receive and report messages
connect(this, SIGNAL(message(QString, QString, unsigned int)), gui, SLOT(message(QString, QString, unsigned int)));
// Pass through encryption status changed signals
connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
// Pass through transaction notifications
connect(this, SIGNAL(incomingTransaction(QString, int, CAmount, QString, QString)), gui, SLOT(incomingTransaction(QString, int, CAmount, QString, QString)));
}
}
void WalletView::setClientModel(ClientModel* clientModel)
{
this->clientModel = clientModel;
overviewPage->setClientModel(clientModel);
sendCoinsPage->setClientModel(clientModel);
QSettings settings;
if (settings.value("fShowMasternodesTab").toBool()) {
masternodeListPage->setClientModel(clientModel);
}
}
void WalletView::setWalletModel(WalletModel* walletModel)
{
this->walletModel = walletModel;
// Put transaction list in tabs
transactionView->setModel(walletModel);
overviewPage->setWalletModel(walletModel);
QSettings settings;
if (settings.value("fShowMasternodesTab").toBool()) {
masternodeListPage->setWalletModel(walletModel);
}
privacyPage->setModel(walletModel);
receiveCoinsPage->setModel(walletModel);
sendCoinsPage->setModel(walletModel);
if (walletModel) {
// Receive and pass through messages from wallet model
connect(walletModel, SIGNAL(message(QString, QString, unsigned int)), this, SIGNAL(message(QString, QString, unsigned int)));
// Handle changes in encryption status
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SIGNAL(encryptionStatusChanged(int)));
updateEncryptionStatus();
// Balloon pop-up for new transaction
connect(walletModel->getTransactionTableModel(), SIGNAL(rowsInserted(QModelIndex, int, int)),
this, SLOT(processNewTransaction(QModelIndex, int, int)));
// Ask for passphrase if needed
connect(walletModel, SIGNAL(requireUnlock(AskPassphraseDialog::Context)), this, SLOT(unlockWallet(AskPassphraseDialog::Context)));
// Show progress dialog
connect(walletModel, SIGNAL(showProgress(QString, int)), this, SLOT(showProgress(QString, int)));
}
}
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
{
// Prevent balloon-spam when initial block download is in progress
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload())
return;
TransactionTableModel* ttm = walletModel->getTransactionTableModel();
if (!ttm || ttm->processingQueuedTransactions())
return;
QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();
qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toULongLong();
QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();
QString address = ttm->index(start, TransactionTableModel::ToAddress, parent).data().toString();
emit incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address);
}
void WalletView::gotoOverviewPage()
{
setCurrentWidget(overviewPage);
// Refresh UI-elements in case coins were locked/unlocked in CoinControl
walletModel->emitBalanceChanged();
}
void WalletView::gotoHistoryPage()
{
setCurrentWidget(transactionsPage);
}
void WalletView::gotoBlockExplorerPage()
{
setCurrentWidget(explorerWindow);
}
void WalletView::gotoMasternodePage()
{
QSettings settings;
if (settings.value("fShowMasternodesTab").toBool()) {
setCurrentWidget(masternodeListPage);
}
}
void WalletView::gotoReceiveCoinsPage()
{
setCurrentWidget(receiveCoinsPage);
}
void WalletView::gotoPrivacyPage()
{
setCurrentWidget(privacyPage);
// Refresh UI-elements in case coins were locked/unlocked in CoinControl
walletModel->emitBalanceChanged();
}
void WalletView::gotoSendCoinsPage(QString addr)
{
setCurrentWidget(sendCoinsPage);
if (!addr.isEmpty())
sendCoinsPage->setAddress(addr);
}
void WalletView::gotoSignMessageTab(QString addr)
{
// calls show() in showTab_SM()
SignVerifyMessageDialog* signVerifyMessageDialog = new SignVerifyMessageDialog(this);
signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
signVerifyMessageDialog->setModel(walletModel);
signVerifyMessageDialog->showTab_SM(true);
if (!addr.isEmpty())
signVerifyMessageDialog->setAddress_SM(addr);
}
void WalletView::gotoVerifyMessageTab(QString addr)
{
// calls show() in showTab_VM()
SignVerifyMessageDialog* signVerifyMessageDialog = new SignVerifyMessageDialog(this);
signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
signVerifyMessageDialog->setModel(walletModel);
signVerifyMessageDialog->showTab_VM(true);
if (!addr.isEmpty())
signVerifyMessageDialog->setAddress_VM(addr);
}
void WalletView::gotoBip38Tool()
{
Bip38ToolDialog* bip38ToolDialog = new Bip38ToolDialog(this);
//bip38ToolDialog->setAttribute(Qt::WA_DeleteOnClose);
bip38ToolDialog->setModel(walletModel);
bip38ToolDialog->showTab_ENC(true);
}
void WalletView::gotoMultiSendDialog()
{
MultiSendDialog* multiSendDialog = new MultiSendDialog(this);
multiSendDialog->setModel(walletModel);
multiSendDialog->show();
}
void WalletView::gotoMultisigDialog(int index)
{
MultisigDialog* multisig = new MultisigDialog(this);
multisig->setModel(walletModel);
multisig->showTab(index);
}
bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)
{
return sendCoinsPage->handlePaymentRequest(recipient);
}
void WalletView::showOutOfSyncWarning(bool fShow)
{
overviewPage->showOutOfSyncWarning(fShow);
privacyPage->showOutOfSyncWarning(fShow);
}
void WalletView::updateEncryptionStatus()
{
emit encryptionStatusChanged(walletModel->getEncryptionStatus());
}
void WalletView::encryptWallet(bool status)
{
if (!walletModel)
return;
AskPassphraseDialog dlg(status ? AskPassphraseDialog::Mode::Encrypt : AskPassphraseDialog::Mode::Decrypt, this,
walletModel, AskPassphraseDialog::Context::Encrypt);
dlg.exec();
updateEncryptionStatus();
}
void WalletView::backupWallet()
{
QString filename = GUIUtil::getSaveFileName(this,
tr("Backup Wallet"), QString(),
tr("Wallet Data (*.dat)"), NULL);
if (filename.isEmpty())
return;
walletModel->backupWallet(filename);
}
void WalletView::changePassphrase()
{
AskPassphraseDialog dlg(AskPassphraseDialog::Mode::ChangePass, this, walletModel, AskPassphraseDialog::Context::ChangePass);
dlg.exec();
}
void WalletView::unlockWallet(AskPassphraseDialog::Context context)
{
if (!walletModel)
return;
// Unlock wallet when requested by wallet model
if (walletModel->getEncryptionStatus() == WalletModel::Locked || walletModel->getEncryptionStatus() == WalletModel::UnlockedForAnonymizationOnly) {
AskPassphraseDialog dlg(AskPassphraseDialog::Mode::UnlockAnonymize, this, walletModel, context);
dlg.exec();
}
}
void WalletView::lockWallet()
{
if (!walletModel)
return;
walletModel->setWalletLocked(true);
}
void WalletView::toggleLockWallet()
{
if (!walletModel)
return;
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
// Unlock the wallet when requested
if (encStatus == walletModel->Locked) {
AskPassphraseDialog dlg(AskPassphraseDialog::Mode::UnlockAnonymize, this, walletModel, AskPassphraseDialog::Context::ToggleLock);
dlg.exec();
}
else if (encStatus == walletModel->Unlocked || encStatus == walletModel->UnlockedForAnonymizationOnly) {
walletModel->setWalletLocked(true);
}
}
void WalletView::usedSendingAddresses()
{
if (!walletModel)
return;
AddressBookPage* dlg = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab, this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setModel(walletModel->getAddressTableModel());
dlg->show();
}
void WalletView::usedReceivingAddresses()
{
if (!walletModel)
return;
AddressBookPage* dlg = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setModel(walletModel->getAddressTableModel());
dlg->show();
}
void WalletView::showProgress(const QString& title, int nProgress)
{
if (nProgress == 0) {
progressDialog = new QProgressDialog(title, "", 0, 100);
progressDialog->setWindowModality(Qt::ApplicationModal);
progressDialog->setMinimumDuration(0);
progressDialog->setCancelButton(0);
progressDialog->setAutoClose(false);
progressDialog->setValue(0);
} else if (nProgress == 100) {
if (progressDialog) {
progressDialog->close();
progressDialog->deleteLater();
}
} else if (progressDialog)
progressDialog->setValue(nProgress);
}
/** Update wallet with the sum of the selected transactions */
void WalletView::trxAmount(QString amount)
{
transactionSum->setText(amount);
}
| [
"44762973+eblockcoin7@users.noreply.github.com"
] | 44762973+eblockcoin7@users.noreply.github.com |
3f97ac94ee8a7d2b85b54cc22b4870498e2db975 | 321b944cbbd890ad930a0cf9e2fa2925aadc973f | /integer/is_unsigned-impl/U8.hxx | fecbbdc9db9f35b01a779069e804ad733c93fd95 | [
"MIT"
] | permissive | blake-sheridan/include-b | 77f55994f9d7f6204f3625eebbb793aa4f6cdaf3 | 16c1712e38f5bc423565e97de6b07eeca6a9223d | refs/heads/master | 2016-09-05T21:54:00.275769 | 2015-02-18T22:47:54 | 2015-02-18T22:47:54 | 30,849,347 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 223 | hxx | #ifndef b_integer_is_unsigned_impl_U8_hxx_
#define b_integer_is_unsigned_impl_U8_hxx_
#include "b/U8.hxx"
#include "b/integer/is_unsigned.hxx"
template <>
static constexpr
bool
b::integer::is_unsigned<U8> = true;
#endif
| [
"blake.m.sheridan@gmail.com"
] | blake.m.sheridan@gmail.com |
a7afea2feb130f0fa51e61e0b779952e48c8356d | 8d0541b1042d200036d4a2132cdb7a5a7861506c | /src/simulator/simulator.hpp | b82a2288bc1cffa5e29e49df867ec5f569a28e23 | [] | no_license | roshanshariff/slam | f0cf448c6b3fb41f7b35c2cbe7c66b351759f647 | c459eb835096bbc8ff315d0c281fa68327ea00c2 | refs/heads/master | 2021-01-18T21:43:40.206451 | 2016-04-26T02:04:44 | 2016-04-26T02:04:44 | 1,692,095 | 3 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 4,044 | hpp | #ifndef _SIMULATOR_HPP
#define _SIMULATOR_HPP
#include <cassert>
#include <cstdio>
#include <functional>
#include <memory>
#include <string>
#include <boost/program_options.hpp>
#include "slam/dataset_impl.hpp"
#include "slam/interfaces.hpp"
#include "slam/slam_result_impl.hpp"
#include "utility/bitree.hpp"
#include "utility/flat_map.hpp"
#include "utility/random.hpp"
#include "utility/utility.hpp"
#include "main.hpp"
template <class ControlModel, class ObservationModel, class Controller,
class Sensor>
class simulator
: public slam::dataset_impl<ControlModel, ObservationModel>,
public slam::slam_result_of_impl<ControlModel, ObservationModel> {
using dataset_impl_type = slam::dataset_impl<ControlModel, ObservationModel>;
using slam_result_impl_type =
slam::slam_result_of_impl<ControlModel, ObservationModel>;
public:
using typename slam_result_impl_type::state_type;
using typename slam_result_impl_type::feature_type;
using typename slam_result_impl_type::trajectory_type;
using typename slam_result_impl_type::feature_map_type;
simulator(boost::program_options::variables_map& options, unsigned int seed,
const typename ControlModel::builder& control_model_builder,
const typename ObservationModel::builder& observation_model_builder,
Controller& controller, const Sensor& sensor);
static boost::program_options::options_description program_options();
virtual auto current_timestep() const -> slam::timestep_type override {
return slam::dataset_impl<ControlModel,
ObservationModel>::current_timestep();
}
};
template <class ControlModel, class ObservationModel, class Controller,
class Sensor>
simulator<ControlModel, ObservationModel, Controller, Sensor>::simulator(
boost::program_options::variables_map& options, unsigned int seed,
const typename ControlModel::builder& control_model_builder,
const typename ObservationModel::builder& observation_model_builder,
Controller& controller, const Sensor& sensor) {
const unsigned int sensor_skip = options["sensor-skip"].as<unsigned int>();
const double dt = options["dt"].as<double>();
random_source random(seed);
{
auto& map = this->get_feature_map();
for (size_t i = 0; i < sensor.num_features(); ++i) {
map.emplace_hint(map.end(), i, sensor.get_feature(i));
}
}
this->set_initial_state(controller.initial_state());
state_type state;
auto current_state = [&]() { return this->get_initial_state() + state; };
auto sense = [&]() {
using namespace std::placeholders;
sensor.template sense<ObservationModel>(
observation_model_builder, random, current_state(),
std::bind(&simulator::add_observation_now, this, _1, _2));
};
sense();
while (!controller.finished()) {
const auto control =
controller.template control<ControlModel>(current_state(), dt);
this->add_control(dt, control);
state += control_model_builder(control, dt).proposal()(random);
this->get_trajectory().push_back_accumulated(state);
if (this->current_timestep() % sensor_skip == 0) sense();
}
}
template <class ControlModel, class ObservationModel, class Controller,
class Sensor>
boost::program_options::options_description
simulator<ControlModel, ObservationModel, Controller,
Sensor>::program_options() {
namespace po = boost::program_options;
po::options_description options("Simulator parameters");
options.add_options() //
("dt", po::value<double>()->default_value(0.25),
"time delta per update, in seconds") //
("sim-seed", po::value<unsigned int>(),
"Seed for control and observation noise") //
("sensor-skip", po::value<unsigned int>()->default_value(8),
"Take sensor readings every n time steps");
return options;
}
extern template class simulator<control_model_type, observation_model_type,
controller_type, sensor_type>;
#endif //_SIMULATOR_HPP
| [
"roshan.shariff@ualberta.ca"
] | roshan.shariff@ualberta.ca |
e4c8fa5facffe1c51b922b49a67651b4127fa4ff | 377a59b189eeb9efe3d8d73a9d144dbbcb72978d | /test/iostreams/set_contents_file.hpp | bfb6c52d24dddfdf1561e33908a3ee4a0b17c13b | [] | no_license | BGCX067/falcon-library-git | 89c92c424436c05c5605d926e588b1e512e8279c | a5ec72f885346d91801fcda1d2a36a901a35145d | refs/heads/master | 2021-01-13T00:56:29.589188 | 2013-09-05T20:57:42 | 2013-09-05T20:57:42 | 48,870,693 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 142 | hpp | #ifndef FALCON_TEST_IOSTREAM_SET_CONTENTS_FILE_HPP
#define FALCON_TEST_IOSTREAM_SET_CONTENTS_FILE_HPP
void set_contents_file_test();
#endif
| [
"jonathan.poelen@gmail.com"
] | jonathan.poelen@gmail.com |
f70d7d932ebbf9e88d2777a5b054e988cbce353a | dcff31a8307ae715658bc32c6805ddd73adca56c | /source/grid_sprites_alphabet.cpp | 05f9e486d64abd22335d00252ce4e0c0fe3f7f61 | [
"Zlib"
] | permissive | Chrscool8/Brick-Game-9999-in-1-for-Switch | 78cc3530091d39e48c659d10a1ee8854828213df | 5f5aa93729ded47d395f7546308b7ce89f035c17 | refs/heads/main | 2023-07-02T23:22:22.660021 | 2021-08-16T19:17:49 | 2021-08-16T19:17:49 | 350,606,782 | 7 | 0 | Zlib | 2021-07-16T01:38:11 | 2021-03-23T06:43:38 | C | UTF-8 | C++ | false | false | 1,121 | cpp | #include <vector>
#include <grid_sprites_alphabet.h>
using namespace std;
vector<vector<bool>> grid_sprite_alphabet_space
{
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 }
};
vector<vector<bool>> grid_sprite_alphabet_c
{
{ 0, 1, 1, 1, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 0, 1, 1, 1, 0 }
};
vector<vector<bool>> grid_sprite_alphabet_e
{
{ 1, 1, 1, 1, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 1, 1, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0 }
};
vector<vector<bool>> grid_sprite_alphabet_l
{
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0 }
};
vector<vector<bool>> grid_sprite_alphabet_m
{
{ 0, 1, 0, 1, 0 },
{ 1, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 }
};
vector<vector<bool>> grid_sprite_alphabet_o
{
{ 0, 1, 1, 0, 0 },
{ 1, 0, 0, 1, 0 },
{ 1, 0, 0, 1, 0 },
{ 1, 0, 0, 1, 0 },
{ 0, 1, 1, 0, 0 }
};
vector<vector<bool>> grid_sprite_alphabet_w
{
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1 },
{ 0, 1, 0, 1, 0 }
};
| [
"ChrisBradel14@gmail.com"
] | ChrisBradel14@gmail.com |
8ce03631417fd5565586569b0fcabbf88d7357c1 | 7291f73d1c7152f84a0fba9589990ac59c17f0bd | /src/plugins/markov/featurelist.cpp | 707ee2114f1518c3330457b4ff6dd9b1a58c8977 | [
"MIT"
] | permissive | eglrp/cloudclean | 28e5be14f0296bbb57c6956e53b447409901cc09 | 4b9496bc3b52143c35f0ad83ee68bbc5e8aa32d5 | refs/heads/master | 2020-03-23T01:25:54.728349 | 2017-01-11T01:45:13 | 2017-01-11T01:45:13 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,008 | cpp | #include "featurelist.h"
#include <QAction>
#include <QCheckBox>
#include <QSlider>
#include <QLabel>
#include <QToolBar>
#include <QVBoxLayout>
#include <QDockWidget>
#include <QApplication>
#include <QMenu>
#include <QMenuBar>
#include <QToolTip>
#include <QStatusBar>
#include <QSpinBox>
#include <QTableView>
#include <QHeaderView>
#include <QTextStream>
#include <QDebug>
FeatureList::FeatureList(QObject *parent) : QAbstractListModel(parent) {
}
FeatureList::~FeatureList(){
}
Qt::ItemFlags FeatureList::flags(const QModelIndex & index) const {
int col = index.column();
if (col == 0) {
return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled
| Qt::ItemIsSelectable;
}
return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
}
int FeatureList::columnCount(const QModelIndex &) const {
return 2;
}
int FeatureList::rowCount(const QModelIndex &) const {
return features_.size();
}
QVariant FeatureList::data(const QModelIndex & index, int role) const {
int row = index.row();
int col = index.column();
if (col == 1) {
switch (role) {
case Qt::EditRole:
case Qt::DisplayRole:
{
QString re;
QTextStream(&re) << features_[row].name_;
return re;
}
}
} else if (col == 0) {
switch (role) {
case Qt::CheckStateRole:
return features_[row].enabled_ ? Qt::Checked : Qt::Unchecked;
}
}
return QVariant();
}
bool FeatureList::setData(const QModelIndex & index, const QVariant & value,
int role) {
int row = index.row();
int col = index.column();
if (role == Qt::CheckStateRole && col == 0) {
features_[row].enabled_ = !features_[row].enabled_;
}
return true;
}
void FeatureList::addFeature(Feature contour){
beginInsertRows(QModelIndex(), features_.size(), features_.size());
features_.push_back(contour);
endInsertRows();
}
| [
"circlingthesun@gmail.com"
] | circlingthesun@gmail.com |
3bf666fc9379a81cfeb9735e0ba9174bcd9732ff | 2fdcf56c5e791dd9a4605a41ef7bc601e2fc9135 | /Info/joc3/main.cpp | acedd0412cdbca17cdb535e06c024aa1b1a856de | [] | no_license | DinuCr/CS | 42cc4a7920fb5a2ac5e1179930169e4d8d71592e | 8d381a622e70dd234d7a978501dcb7cf67e83adc | refs/heads/master | 2020-06-02T14:11:49.223214 | 2020-05-24T01:27:46 | 2020-05-24T01:27:46 | 191,174,654 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 486 | cpp | #include <iostream>
#include <fstream>
using namespace std;
ifstream f("joc3.in");
ofstream g("joc3.out");
int v[5010][2],p,mx,m,n,k,i,nr;
int main()
{
f>>n>>k>>m;
for(i=1;i<=k;i++)
f>>v[i][0]>>v[i][1];
while(n<m)
{
mx=n;
for(i=1;i<=k;i++)
if(n>=v[i][0] && v[i][1]>mx)
{
mx=v[i][1];
p=i;
}
if(mx==n)
break;
n=v[p][1];
v[p][1]=0;
nr++;
}
g<<nr;
}
| [
"cristidinu1999@gmail.com"
] | cristidinu1999@gmail.com |
fec1f80386c48d9038afd340b54df4ab6bc2ac32 | 67fc9e51437e351579fe9d2d349040c25936472a | /wrappers/8.1.1/vtkGeoTerrain2DWrap.cc | 26dfcb3a3e1bbab273d3a0f2cb30fe42c683373a | [] | permissive | axkibe/node-vtk | 51b3207c7a7d3b59a4dd46a51e754984c3302dec | 900ad7b5500f672519da5aa24c99aa5a96466ef3 | refs/heads/master | 2023-03-05T07:45:45.577220 | 2020-03-30T09:31:07 | 2020-03-30T09:31:07 | 48,490,707 | 6 | 0 | BSD-3-Clause | 2022-12-07T20:41:45 | 2015-12-23T12:58:43 | C++ | UTF-8 | C++ | false | false | 7,717 | cc | /* this file has been autogenerated by vtkNodeJsWrap */
/* editing this might proof futile */
#define VTK_WRAPPING_CXX
#define VTK_STREAMS_FWD_ONLY
#include <nan.h>
#include "vtkGeoTerrainWrap.h"
#include "vtkGeoTerrain2DWrap.h"
#include "vtkObjectBaseWrap.h"
#include "vtkAbstractTransformWrap.h"
#include "../../plus/plus.h"
using namespace v8;
extern Nan::Persistent<v8::Object> vtkNodeJsNoWrap;
Nan::Persistent<v8::FunctionTemplate> VtkGeoTerrain2DWrap::ptpl;
VtkGeoTerrain2DWrap::VtkGeoTerrain2DWrap()
{ }
VtkGeoTerrain2DWrap::VtkGeoTerrain2DWrap(vtkSmartPointer<vtkGeoTerrain2D> _native)
{ native = _native; }
VtkGeoTerrain2DWrap::~VtkGeoTerrain2DWrap()
{ }
void VtkGeoTerrain2DWrap::Init(v8::Local<v8::Object> exports)
{
Nan::SetAccessor(exports, Nan::New("vtkGeoTerrain2D").ToLocalChecked(), ConstructorGetter);
Nan::SetAccessor(exports, Nan::New("GeoTerrain2D").ToLocalChecked(), ConstructorGetter);
}
void VtkGeoTerrain2DWrap::ConstructorGetter(
v8::Local<v8::String> property,
const Nan::PropertyCallbackInfo<v8::Value>& info)
{
InitPtpl();
info.GetReturnValue().Set(Nan::New(ptpl)->GetFunction());
}
void VtkGeoTerrain2DWrap::InitPtpl()
{
if (!ptpl.IsEmpty()) return;
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
VtkGeoTerrainWrap::InitPtpl( );
tpl->Inherit(Nan::New<FunctionTemplate>(VtkGeoTerrainWrap::ptpl));
tpl->SetClassName(Nan::New("VtkGeoTerrain2DWrap").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Nan::SetPrototypeMethod(tpl, "GetLocationTolerance", GetLocationTolerance);
Nan::SetPrototypeMethod(tpl, "getLocationTolerance", GetLocationTolerance);
Nan::SetPrototypeMethod(tpl, "GetTextureTolerance", GetTextureTolerance);
Nan::SetPrototypeMethod(tpl, "getTextureTolerance", GetTextureTolerance);
Nan::SetPrototypeMethod(tpl, "GetTransform", GetTransform);
Nan::SetPrototypeMethod(tpl, "getTransform", GetTransform);
Nan::SetPrototypeMethod(tpl, "NewInstance", NewInstance);
Nan::SetPrototypeMethod(tpl, "newInstance", NewInstance);
Nan::SetPrototypeMethod(tpl, "SafeDownCast", SafeDownCast);
Nan::SetPrototypeMethod(tpl, "safeDownCast", SafeDownCast);
Nan::SetPrototypeMethod(tpl, "SetLocationTolerance", SetLocationTolerance);
Nan::SetPrototypeMethod(tpl, "setLocationTolerance", SetLocationTolerance);
Nan::SetPrototypeMethod(tpl, "SetTextureTolerance", SetTextureTolerance);
Nan::SetPrototypeMethod(tpl, "setTextureTolerance", SetTextureTolerance);
#ifdef VTK_NODE_PLUS_VTKGEOTERRAIN2DWRAP_INITPTPL
VTK_NODE_PLUS_VTKGEOTERRAIN2DWRAP_INITPTPL
#endif
ptpl.Reset( tpl );
}
void VtkGeoTerrain2DWrap::New(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
if(!info.IsConstructCall())
{
Nan::ThrowError("Constructor not called in a construct call.");
return;
}
if(info.Length() == 0)
{
vtkSmartPointer<vtkGeoTerrain2D> native = vtkSmartPointer<vtkGeoTerrain2D>::New();
VtkGeoTerrain2DWrap* obj = new VtkGeoTerrain2DWrap(native);
obj->Wrap(info.This());
}
else
{
if(info[0]->ToObject() != vtkNodeJsNoWrap )
{
Nan::ThrowError("Parameter Error");
return;
}
}
info.GetReturnValue().Set(info.This());
}
void VtkGeoTerrain2DWrap::GetLocationTolerance(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
double r;
if(info.Length() != 0)
{
Nan::ThrowError("Too many parameters.");
return;
}
r = native->GetLocationTolerance();
info.GetReturnValue().Set(Nan::New(r));
}
void VtkGeoTerrain2DWrap::GetTextureTolerance(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
double r;
if(info.Length() != 0)
{
Nan::ThrowError("Too many parameters.");
return;
}
r = native->GetTextureTolerance();
info.GetReturnValue().Set(Nan::New(r));
}
void VtkGeoTerrain2DWrap::GetTransform(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
vtkAbstractTransform * r;
if(info.Length() != 0)
{
Nan::ThrowError("Too many parameters.");
return;
}
r = native->GetTransform();
VtkAbstractTransformWrap::InitPtpl();
v8::Local<v8::Value> argv[1] =
{ Nan::New(vtkNodeJsNoWrap) };
v8::Local<v8::Function> cons =
Nan::New<v8::FunctionTemplate>(VtkAbstractTransformWrap::ptpl)->GetFunction();
v8::Local<v8::Object> wo = cons->NewInstance(1, argv);
VtkAbstractTransformWrap *w = new VtkAbstractTransformWrap();
w->native = r;
w->Wrap(wo);
info.GetReturnValue().Set(wo);
}
void VtkGeoTerrain2DWrap::NewInstance(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
vtkGeoTerrain2D * r;
if(info.Length() != 0)
{
Nan::ThrowError("Too many parameters.");
return;
}
r = native->NewInstance();
VtkGeoTerrain2DWrap::InitPtpl();
v8::Local<v8::Value> argv[1] =
{ Nan::New(vtkNodeJsNoWrap) };
v8::Local<v8::Function> cons =
Nan::New<v8::FunctionTemplate>(VtkGeoTerrain2DWrap::ptpl)->GetFunction();
v8::Local<v8::Object> wo = cons->NewInstance(1, argv);
VtkGeoTerrain2DWrap *w = new VtkGeoTerrain2DWrap();
w->native = r;
w->Wrap(wo);
info.GetReturnValue().Set(wo);
}
void VtkGeoTerrain2DWrap::SafeDownCast(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
if(info.Length() > 0 && info[0]->IsObject() && (Nan::New(VtkObjectBaseWrap::ptpl))->HasInstance(info[0]))
{
VtkObjectBaseWrap *a0 = ObjectWrap::Unwrap<VtkObjectBaseWrap>(info[0]->ToObject());
vtkGeoTerrain2D * r;
if(info.Length() != 1)
{
Nan::ThrowError("Too many parameters.");
return;
}
r = native->SafeDownCast(
(vtkObjectBase *) a0->native.GetPointer()
);
VtkGeoTerrain2DWrap::InitPtpl();
v8::Local<v8::Value> argv[1] =
{ Nan::New(vtkNodeJsNoWrap) };
v8::Local<v8::Function> cons =
Nan::New<v8::FunctionTemplate>(VtkGeoTerrain2DWrap::ptpl)->GetFunction();
v8::Local<v8::Object> wo = cons->NewInstance(1, argv);
VtkGeoTerrain2DWrap *w = new VtkGeoTerrain2DWrap();
w->native = r;
w->Wrap(wo);
info.GetReturnValue().Set(wo);
return;
}
Nan::ThrowError("Parameter mismatch");
}
void VtkGeoTerrain2DWrap::SetLocationTolerance(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
if(info.Length() > 0 && info[0]->IsNumber())
{
if(info.Length() != 1)
{
Nan::ThrowError("Too many parameters.");
return;
}
native->SetLocationTolerance(
info[0]->NumberValue()
);
return;
}
Nan::ThrowError("Parameter mismatch");
}
void VtkGeoTerrain2DWrap::SetTextureTolerance(const Nan::FunctionCallbackInfo<v8::Value>& info)
{
VtkGeoTerrain2DWrap *wrapper = ObjectWrap::Unwrap<VtkGeoTerrain2DWrap>(info.Holder());
vtkGeoTerrain2D *native = (vtkGeoTerrain2D *)wrapper->native.GetPointer();
if(info.Length() > 0 && info[0]->IsNumber())
{
if(info.Length() != 1)
{
Nan::ThrowError("Too many parameters.");
return;
}
native->SetTextureTolerance(
info[0]->NumberValue()
);
return;
}
Nan::ThrowError("Parameter mismatch");
}
| [
"axkibe@gmail.com"
] | axkibe@gmail.com |
301391d818b38ab2a46a46cef2fdd4f1352942b6 | 0e094662e0bed090ededc719abe16a7a7daf39dd | /Server/ReadvWritev.cpp | 5e18c3d71b5fecd9e0a31d2edada00380f320d81 | [] | no_license | xinghen1995/ThinkInCPlus | 5ee33d25b2988919bac02be63a3dcc1b28ca927d | a881f6ccb50bcbb36aecea0c100b3571c3208a57 | refs/heads/master | 2021-06-25T15:06:01.102993 | 2021-03-16T15:58:05 | 2021-03-16T15:58:05 | 215,588,105 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 2,869 | cpp | /* #include <sys/uio.h>
* ssize_t readv(int fd, const struct iovec *vector, int count);
* ssize_t writev(int fd, const struct iovec *vector, int count);
*/
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#define BUFFER_SIZE 1024
static const char *status_line[2] = { "200 OK", "500 Internal server error" };
int main(int argc, char *argv[])
{
if (argc <= 3)
{
printf("usage: %s ip_address port_number filename\n", basename(argv[0]));
return 1;
}
const char *ip = argv[1];
int port = atoi(argv[2]);
const char *filename = argv[3];
struct sockaddr_in serv_addr;
bzero(&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
inet_pton(AF_INET, ip, &serv_addr.sin_addr);
serv_addr.sin_port = htons(port);
int sockfd = socket(PF_INET, SOCK_STREAM, 0);
assert(sockfd >= 0);
int ret = bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
assert(ret != -1);
ret = listen(sockfd, 5);
assert(ret != -1);
struct sockaddr_in cli_addr;
socklen_t cli_addrlen = sizeof(cli_addr);
int connfd = accept(sockfd, (struct sockaddr*)&cli_addr, &cli_addrlen);
if (connfd < 0)
{
printf("errno is %d\n", errno);
}
else
{
char header_buf[BUFFER_SIZE];
memset(header_buf, '\0', BUFFER_SIZE);
char *file_buf;
struct stat file_stat;
bool valid = true;
int len = 0;
/* 目标文件不存在 */
if (stat(filename, &file_stat) < 0)
{
valid = false;
}
else
{
if (S_ISDIR(file_stat.st_mode))
{
valid = false;
}
else if (file_stat.st_mode & S_IROTH)
{
int fd = open(filename, O_RDONLY);
file_buf = new char[file_stat.st_size + 1];
memset(file_buf, '\0', file_stat.st_size + 1);
if (read(fd, file_buf, file_stat.st_size) < 0)
{
valid = false;
}
}
else
{
valid = false;
}
}
if (valid)
{
ret = snprintf(header_buf, BUFFER_SIZE - 1, "%s %s\r\n",
"HTTP1.1", status_line[0]);
len += ret;
ret = snprintf(header_buf + len, BUFFER_SIZE - 1 - len,
"Content-Length: %ld\r\n", file_stat.st_size);
len += ret;
ret = snprintf(header_buf + len, BUFFER_SIZE - 1 - len,
"%s", "\r\n");
struct iovec iv[2];
iv[0].iov_base = header_buf;
iv[0].iov_len = strlen(header_buf);
iv[1].iov_base = file_buf;
iv[1].iov_len = file_stat.st_size;
ret = writev(connfd, iv, 2);
}
else
{
ret = snprintf(header_buf, BUFFER_SIZE - 1, "%s %s\r\n",
"HTTP/1.1", status_line[1]);
len += ret;
ret = snprintf(header_buf + len, BUFFER_SIZE - 1 - len, "%s", "\r\n");
send(connfd, header_buf, sizeof(header_buf), 0);
}
close(connfd);
delete []file_buf;
}
close(sockfd);
return 0;
}
| [
"1097382820@qq.com"
] | 1097382820@qq.com |
170f35039f7f97f65e8bf025a0b6e099a5ecab1a | 2db94860142aafab6384432454d53c26961000c9 | /src/proxy_server/proxy_server.cpp | 58855a1d969826f5a467b796deb3b50623140186 | [
"BSD-2-Clause"
] | permissive | PetrPPetrov/gkm-world | beaef1cd0e4a194378e4f4105d7d230e454cffc8 | 7c24d1646e04b439733a7eb603c9a00526b39f4c | refs/heads/master | 2021-11-12T19:53:19.418391 | 2021-09-15T20:15:06 | 2021-09-15T20:15:06 | 224,483,703 | 2 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 15,638 | cpp | // Copyright 2018-2020 Petr Petrovich Petrov. All rights reserved.
// License: https://github.com/PetrPPetrov/gkm-world/blob/master/LICENSE
#include <iostream>
#include <fstream>
#include <memory>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp>
#include "gkm_world/protocol.h"
#include "gkm_world/logger.h"
#include "gkm_world/configuration_reader.h"
#include "proxy_server.h"
ProxyServer::ProxyServer(const std::string& cfg_file_name_) :
cfg_file_name(cfg_file_name_), signals(io_service, SIGINT, SIGTERM) {
setApplicationType(Packet::EApplicationType::ProxyServer);
std::ifstream config_file(cfg_file_name);
ConfigurationReader config_reader;
config_reader.addParameter("proxy_server_port_number", port_number);
config_reader.addParameter("balancer_server_ip", balancer_server_ip);
config_reader.addParameter("balancer_server_port_number", balancer_server_port_number);
config_reader.addParameter("log_min_severity", minimum_level);
config_reader.addParameter("log_to_screen", log_to_screen);
config_reader.addParameter("log_to_file", log_to_file);
config_reader.addParameter("registered_users_file_name", registered_users_file_name);
config_reader.read(config_file);
balancer_server_end_point = boost::asio::ip::udp::endpoint(IpAddress::from_string(balancer_server_ip), balancer_server_port_number);
proxy_server_end_point = boost::asio::ip::udp::endpoint(IpAddress(), port_number);
socket = boost::asio::ip::udp::socket(io_service, proxy_server_end_point);
}
ProxyServer::~ProxyServer() {
saveRegisteredUsers(registered_users_file_name);
}
bool ProxyServer::start() {
Logger::setLoggingToScreen(log_to_screen);
Logger::setLoggingToFile(log_to_file, "proxy_server_" + std::to_string(port_number) + ".log");
Logger::setMinimumLevel(minimum_level);
Logger::registerThisThread();
LOG_INFO << "Proxy Server is starting...";
try {
dumpParameters();
startImpl();
} catch (boost::system::system_error& error) {
LOG_FATAL << "boost::system::system_error: " << error.what();
return false;
} catch (const std::exception& exception) {
LOG_FATAL << "std::exception: " << exception.what();
return false;
} catch (...) {
LOG_FATAL << "Unknown error";
return false;
}
return true;
}
void ProxyServer::dumpParameters() {
LOG_INFO << "configuration_file_name " << cfg_file_name;
LOG_INFO << "balancer_server_ip " << balancer_server_ip;
LOG_INFO << "balancer_server_port_number " << balancer_server_port_number;
LOG_INFO << "proxy_server_ip " << proxy_server_end_point.address();
LOG_INFO << "proxy_server_port_number " << proxy_server_end_point.port();
LOG_INFO << "log_min_severity " << getText(minimum_level);
LOG_INFO << "log_to_screen " << log_to_screen;
LOG_INFO << "log_to_file " << log_to_file;
LOG_INFO << "registered_users_file_name " << registered_users_file_name;
}
void ProxyServer::startImpl() {
using namespace boost::placeholders;
loadRegisteredUsers(registered_users_file_name);
doReceive();
signals.async_wait(boost::bind(&ProxyServer::onQuit, this, _1, _2));
setReceiveHandler(Packet::EType::Login, boost::bind(&ProxyServer::onLogin, this, _1));
setReceiveHandler(Packet::EType::Logout, boost::bind(&ProxyServer::onLogout, this, _1));
setReceiveHandler(Packet::EType::LogoutInternalAnswer, boost::bind(&ProxyServer::onLogoutInternalAnswer, this, _1));
setReceiveHandler(Packet::EType::InitializePosition, boost::bind(&ProxyServer::onInitializePosition, this, _1));
setReceiveHandler(Packet::EType::InitializePositionInternalAnswer, boost::bind(&ProxyServer::onInitializePositionInternalAnswer, this, _1));
setReceiveHandler(Packet::EType::UnitAction, boost::bind(&ProxyServer::onUnitAction, this, _1));
setReceiveHandler(Packet::EType::UnitActionInternalAnswer, boost::bind(&ProxyServer::onUnitActionInternalAnswer, this, _1));
setReceiveHandler(Packet::EType::RegisterProxyAnswer, boost::bind(&ProxyServer::onRegisterProxyAnswer, this, _1));
auto register_proxy = createPacket<Packet::RegisterProxy>();
guaranteedSendTo(register_proxy, balancer_server_end_point, boost::bind(&Transport::logError, this, _1, _2));
io_service.run();
}
void ProxyServer::onQuit(const boost::system::error_code& error, int sig_number) {
if (!error) {
saveRegisteredUsers(registered_users_file_name);
} else {
LOG_ERROR << "users were not saved in the file";
}
onQuitSignal(error, sig_number);
}
bool ProxyServer::onLogin(size_t received_bytes) {
LOG_DEBUG << "onLogin";
const auto packet = getReceiveBufferAs<Packet::Login>();
std::string login = packet->login.str();
std::string password = packet->password.str();
std::string full_name = packet->full_name.str();
LOG_DEBUG << "end_point: " << remote_end_point;
LOG_DEBUG << "password: " << login;
LOG_DEBUG << "login: " << password;
LOG_DEBUG << "full_name: " << full_name;
auto fit_login_it = login_to_user_info.find(login);
UserInfo::Ptr cur_user;
if (fit_login_it != login_to_user_info.end()) {
LOG_DEBUG << "existing user";
cur_user = fit_login_it->second;
if (password != cur_user->password) {
LOG_DEBUG << "authorization failure";
auto answer = createPacket<Packet::LoginAnswer>(packet->packet_number);
answer->success = false;
standardSend(answer);
return true;
} else {
LOG_DEBUG << "authorization OK";
}
} else {
LOG_DEBUG << "new user";
UserInfo::Ptr new_user = std::make_shared<UserInfo>();
new_user->login = login;
new_user->password = password;
new_user->full_name = full_name;
login_to_user_info.emplace(login, new_user);
cur_user = new_user;
}
if (!cur_user->online) {
LOG_DEBUG << "user is logging";
IndexType new_token;
UserOnlineInfo* allocated_user_online_info = token_to_unit_info.allocate(new_token);
online_user_count++;
LOG_DEBUG << "generated new token " << new_token;
cur_user->unit_token = new_token;
cur_user->online = true;
UserOnlineInfo* user_online_info = new(allocated_user_online_info) UserOnlineInfo(cur_user.get());
user_online_info->user_end_point = remote_end_point;
} else {
#ifdef _DEBUG
LOG_DEBUG << "user is already online";
#endif
}
auto answer = createPacket<Packet::LoginAnswer>(packet->packet_number);
answer->success = true;
answer->unit_token = cur_user->unit_token;
standardSend(answer);
return true;
}
bool ProxyServer::onLogout(size_t received_bytes) {
LOG_DEBUG << "onLogout";
const auto packet = getReceiveBufferAs<Packet::Logout>();
LOG_DEBUG << "end point: " << remote_end_point;
IndexType unit_token = packet->unit_token;
UserOnlineInfo* user_online_info = token_to_unit_info.find(unit_token);
if (!user_online_info) {
LOG_ERROR << "user does not exist";
return true;
}
if (user_online_info->user_end_point != remote_end_point) {
LOG_ERROR << "user sent incorrect token " << unit_token << " ip: " << user_online_info->user_end_point << " and it should be ip: " << remote_end_point;
return true;
}
auto request = createPacket<Packet::LogoutInternal>();
request->unit_token = user_online_info->user_info->unit_token;
request->client_packet_number = packet->packet_number;
standardSendTo(request, user_online_info->node_server_end_point);
return true;
}
bool ProxyServer::onLogoutInternalAnswer(size_t received_bytes) {
LOG_DEBUG << "onLogoutInternalAnswer";
if (!validateInternalServer(remote_end_point)) {
LOG_WARNING << "internal server token validation error";
return true;
}
const auto packet = getReceiveBufferAs<Packet::LogoutInternalAnswer>();
IndexType unit_token = packet->unit_token;
UserOnlineInfo* user_online_info = token_to_unit_info.find(unit_token);
if (!user_online_info) {
LOG_ERROR << "user does not exist";
return true;
}
user_online_info->user_info->online = false;
user_online_info->user_info->unit_token = 0;
user_online_info->in_game = false;
user_online_info->user_info = nullptr;
boost::asio::ip::udp::endpoint user_end_point = user_online_info->user_end_point;
token_to_unit_info.deallocate(unit_token);
online_user_count--;
auto answer = createPacket<Packet::LogoutAnswer>(packet->client_packet_number);
answer->success = true;
standardSendTo(answer, user_end_point);
return true;
}
bool ProxyServer::onInitializePosition(size_t received_bytes) {
LOG_DEBUG << "onInitializePosition";
const auto packet = getReceiveBufferAs<Packet::InitializePosition>();
IndexType unit_token = packet->unit_location.unit_token;
UserOnlineInfo* user_online_info = token_to_unit_info.find(unit_token);
if (!user_online_info) {
LOG_ERROR << "user does not exist";
return true;
}
if (user_online_info->user_end_point != remote_end_point) {
LOG_ERROR << "unit sent incorrect token " << unit_token << " ip: " << user_online_info->user_end_point << " and it should be ip: " << remote_end_point;
return true;
}
if (!user_online_info->in_game) {
auto request = createPacket<Packet::InitializePositionInternal>();
request->client_packet_number = packet->packet_number;
request->proxy_packet_number = request->packet_number;
request->unit_location = packet->unit_location;
request->proxy_server_address = socket.local_endpoint().address().TO_V().to_bytes();
request->proxy_server_port_number = port_number;
standardSendTo(request, balancer_server_end_point);
return true;
}
auto answer = createPacket<Packet::InitializePositionAnswer>(packet->packet_number);
answer->success = true;
answer->corrected_location = packet->unit_location;
standardSend(answer);
return true;
}
bool ProxyServer::onInitializePositionInternalAnswer(size_t received_bytes) {
LOG_DEBUG << "onInitializePositionInternalAnswer";
if (!validateInternalServer(remote_end_point)) {
LOG_WARNING << "internal server token validation error";
return true;
}
const auto packet = getReceiveBufferAs<Packet::InitializePositionInternalAnswer>();
IndexType unit_token = packet->corrected_location.unit_token;
UserOnlineInfo* user_online_info = token_to_unit_info.find(unit_token);
if (!user_online_info) {
LOG_ERROR << "user does not exist";
return true;
}
if (!user_online_info->user_info->online) {
LOG_ERROR << "user is not online or is already in game";
return true;
}
if (user_online_info->in_game) {
LOG_ERROR << "user is already in game";
return true;
}
user_online_info->in_game = true;
user_online_info->node_server_end_point = boost::asio::ip::udp::endpoint(IpAddress(packet->node_server_address), packet->node_server_port_number);
if (user_online_info->node_server_end_point.address().is_loopback()) {
user_online_info->node_server_end_point = boost::asio::ip::udp::endpoint(remote_end_point.address().TO_V(), packet->node_server_port_number);
}
auto answer = createPacket<Packet::InitializePositionAnswer>(packet->client_packet_number);
answer->success = packet->success;
answer->corrected_location = packet->corrected_location;
standardSendTo(answer, user_online_info->user_end_point);
return true;
}
bool ProxyServer::onUnitAction(size_t received_bytes) {
LOG_DEBUG << "onUnitAction";
const auto packet = getReceiveBufferAs<Packet::UnitAction>();
IndexType unit_token = packet->unit_token;
UserOnlineInfo* user_online_info = token_to_unit_info.find(unit_token);
if (!user_online_info) {
LOG_ERROR << "user does not exist";
return true;
}
if (user_online_info->user_end_point != remote_end_point) {
LOG_ERROR << "user sent incorrect token " << unit_token << " ip: " << user_online_info->user_end_point << " and it should be ip: " << remote_end_point;
return true;
}
if (!user_online_info->in_game) {
LOG_ERROR << "user is not in game";
return true;
}
auto request = createPacket<Packet::UnitActionInternal>();
request->unit_token = user_online_info->user_info->unit_token;
request->keyboard_state = packet->keyboard_state;
request->client_packet_number = packet->packet_number;
standardSendTo(request, user_online_info->node_server_end_point);
return true;
}
bool ProxyServer::onUnitActionInternalAnswer(size_t received_bytes) {
LOG_DEBUG << "onUserActionInternalAnswer";
if (!validateInternalServer(remote_end_point)) {
LOG_WARNING << "fake internal server detected";
return true;
}
const auto packet = getReceiveBufferAs<Packet::UnitActionInternalAnswer>();
IndexType unit_token = packet->unit_location.unit_token;
UserOnlineInfo* user_online_info = token_to_unit_info.find(unit_token);
if (!user_online_info) {
LOG_ERROR << "user does not exist";
return true;
}
if (!user_online_info->in_game) {
LOG_ERROR << "user is not in game";
return true;
}
auto answer = createPacket<Packet::UnitActionAnswer>(packet->client_packet_number);
answer->unit_location = packet->unit_location;
answer->other_unit_count = packet->other_unit_count;
if (answer->other_unit_count >= Packet::MAX_UNIT_COUNT_IN_PACKET) {
answer->other_unit_count = Packet::MAX_UNIT_COUNT_IN_PACKET;
}
for (std::uint16_t i = 0; i < answer->other_unit_count; ++i) {
answer->other_unit[i] = packet->other_unit[i];
}
standardSendTo(answer, user_online_info->user_end_point);
return true;
}
bool ProxyServer::onRegisterProxyAnswer(size_t received_bytes) {
LOG_DEBUG << "onRegisterProxyAnswer";
if (!validateInternalServer(remote_end_point)) {
LOG_WARNING << "fake internal server detected";
return true;
}
const auto packet = getReceiveBufferAs<Packet::RegisterProxyAnswer>();
proxy_token = packet->proxy_token;
setApplicationToken(proxy_token);
LOG_DEBUG << "proxy_token " << proxy_token;
return true;
}
bool ProxyServer::validateInternalServer(const boost::asio::ip::udp::endpoint& end_point) const {
// TODO:
return true;
}
void ProxyServer::loadRegisteredUsers(const std::string& file_name) {
LOG_DEBUG << "loading users from " << file_name << "...";
std::ifstream registered_users(file_name);
while (!registered_users.bad() && !registered_users.eof()) {
UserInfo::Ptr new_user = std::make_shared<UserInfo>();
registered_users >> *new_user;
if (new_user->login.empty() || new_user->password.empty() || new_user->full_name.empty()) {
break;
}
login_to_user_info.insert_or_assign(new_user->login, new_user);
}
LOG_DEBUG << "users are loaded!";
}
void ProxyServer::saveRegisteredUsers(const std::string& file_name) const {
LOG_DEBUG << "saving users to " << file_name << "...";
std::ofstream registered_users(file_name);
for (auto cur_user : login_to_user_info) {
registered_users << *cur_user.second.get();
}
LOG_DEBUG << "users are saved!";
}
| [
"petr@gkmsoft.ru"
] | petr@gkmsoft.ru |
8676b9d118cd1597a7f847a1b1876fedb01328a6 | 9eb2245869dcc3abd3a28c6064396542869dab60 | /benchspec/CPU/510.parest_r/build/build_base_mytest-64.0000/source/dofs/dof_tools.cc | 00d0b8326addd88bd2bc5746781c21e24faf09e6 | [] | no_license | lapnd/CPU2017 | 882b18d50bd88e0a87500484a9d6678143e58582 | 42dac4b76117b1ba4a08e41b54ad9cfd3db50317 | refs/heads/master | 2023-03-23T23:34:58.350363 | 2021-03-24T10:01:03 | 2021-03-24T10:01:03 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 217,003 | cc | //---------------------------------------------------------------------------
// $Id: dof_tools.cc 18724 2009-04-23 23:06:37Z bangerth $
// Version: $Name$
//
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#include <base/multithread_info.h>
#include <base/thread_management.h>
#include <base/quadrature_lib.h>
#include <base/table.h>
#include <base/template_constraints.h>
#include <base/utilities.h>
#include <lac/sparsity_pattern.h>
#include <lac/compressed_sparsity_pattern.h>
#include <lac/compressed_set_sparsity_pattern.h>
#include <lac/compressed_simple_sparsity_pattern.h>
#include <lac/trilinos_sparsity_pattern.h>
#include <lac/block_sparsity_pattern.h>
#include <lac/vector.h>
#include <lac/constraint_matrix.h>
#include <grid/tria.h>
#include <grid/tria_iterator.h>
#include <grid/intergrid_map.h>
#include <grid/grid_tools.h>
#include <dofs/dof_handler.h>
#include <dofs/dof_accessor.h>
#include <fe/fe.h>
#include <fe/fe_values.h>
#include <fe/fe_tools.h>
#include <hp/fe_collection.h>
#include <dofs/dof_tools.h>
#include <numerics/vectors.h>
#include <multigrid/mg_dof_handler.h>
#include <multigrid/mg_dof_accessor.h>
#include <algorithm>
#include <numeric>
DEAL_II_NAMESPACE_OPEN
//TODO: convert many more of the instantiations at the bottom of this file to the .inst.in mechanism
//#define WOLFGANG
template <class DH, class SparsityPattern>
void
DoFTools::make_sparsity_pattern (const DH &dof,
SparsityPattern &sparsity,
const ConstraintMatrix &constraints,
const bool keep_constrained_dofs)
{
const unsigned int n_dofs = dof.n_dofs();
Assert (sparsity.n_rows() == n_dofs,
ExcDimensionMismatch (sparsity.n_rows(), n_dofs));
Assert (sparsity.n_cols() == n_dofs,
ExcDimensionMismatch (sparsity.n_cols(), n_dofs));
std::vector<unsigned int> dofs_on_this_cell;
dofs_on_this_cell.reserve (max_dofs_per_cell(dof));
typename DH::active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
// In case we work with a distributed
// sparsity pattern of Trilinos type, we
// only have to do the work if the
// current cell is owned by the calling
// processor. Otherwise, just continue.
//
// TODO: here, we should actually check
// the communicator of the sparsity
// pattern, not MPI_COMM_WORLD as the
// Utilities function does!
for (; cell!=endc; ++cell)
#ifdef DEAL_II_USE_TRILINOS
if ((types_are_equal<SparsityPattern,TrilinosWrappers::SparsityPattern>::value
||
types_are_equal<SparsityPattern,TrilinosWrappers::BlockSparsityPattern>::value)
&&
cell->subdomain_id() !=
Utilities::Trilinos::get_this_mpi_process(Utilities::Trilinos::comm_world()))
continue;
else
#endif
{
const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell;
dofs_on_this_cell.resize (dofs_per_cell);
cell->get_dof_indices (dofs_on_this_cell);
// make sparsity pattern for this
// cell. if no constraints pattern was
// given, then the following call acts
// as if simply no constraints existed
constraints.add_entries_local_to_global (dofs_on_this_cell,
sparsity,
keep_constrained_dofs);
}
}
template <class DH, class SparsityPattern>
void
DoFTools::make_sparsity_pattern (
const DH &dof,
const Table<2,Coupling> &couplings,
SparsityPattern &sparsity,
const ConstraintMatrix &constraints,
const bool keep_constrained_dofs)
{
const unsigned int n_dofs = dof.n_dofs();
Assert (sparsity.n_rows() == n_dofs,
ExcDimensionMismatch (sparsity.n_rows(), n_dofs));
Assert (sparsity.n_cols() == n_dofs,
ExcDimensionMismatch (sparsity.n_cols(), n_dofs));
Assert (couplings.n_rows() == dof.get_fe().n_components(),
ExcDimensionMismatch(couplings.n_rows(), dof.get_fe().n_components()));
Assert (couplings.n_cols() == dof.get_fe().n_components(),
ExcDimensionMismatch(couplings.n_cols(), dof.get_fe().n_components()));
const hp::FECollection<DH::dimension,DH::space_dimension> fe_collection (dof.get_fe());
// first, for each finite element, build a
// mask for each dof, not like the one
// given which represents components. make
// sure we do the right thing also with
// respect to non-primitive shape
// functions, which takes some additional
// thought
std::vector<Table<2,bool> > dof_mask(fe_collection.size());
// check whether the table of couplings
// contains only true arguments, i.e., we
// do not exclude any index. that is the
// easy case, since we don't have to set
// up the tables
bool need_dof_mask = false;
for (unsigned int i=0; i<couplings.n_rows(); ++i)
for (unsigned int j=0; j<couplings.n_cols(); ++j)
if (couplings[i][j] == none)
need_dof_mask = true;
if (need_dof_mask == true)
for (unsigned int f=0; f<fe_collection.size(); ++f)
{
const unsigned int dofs_per_cell = fe_collection[f].dofs_per_cell;
dof_mask[f].reinit (dofs_per_cell, dofs_per_cell);
for (unsigned int i=0; i<dofs_per_cell; ++i)
for (unsigned int j=0; j<dofs_per_cell; ++j)
if (fe_collection[f].is_primitive(i) &&
fe_collection[f].is_primitive(j))
dof_mask[f][i][j]
= (couplings(fe_collection[f].system_to_component_index(i).first,
fe_collection[f].system_to_component_index(j).first) != none);
else
{
const unsigned int first_nonzero_comp_i
= (std::find (fe_collection[f].get_nonzero_components(i).begin(),
fe_collection[f].get_nonzero_components(i).end(),
true)
-
fe_collection[f].get_nonzero_components(i).begin());
const unsigned int first_nonzero_comp_j
= (std::find (fe_collection[f].get_nonzero_components(j).begin(),
fe_collection[f].get_nonzero_components(j).end(),
true)
-
fe_collection[f].get_nonzero_components(j).begin());
Assert (first_nonzero_comp_i < fe_collection[f].n_components(),
ExcInternalError());
Assert (first_nonzero_comp_j < fe_collection[f].n_components(),
ExcInternalError());
dof_mask[f][i][j]
= (couplings(first_nonzero_comp_i,first_nonzero_comp_j) != none);
}
}
std::vector<unsigned int> dofs_on_this_cell(fe_collection.max_dofs_per_cell());
typename DH::active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
// In case we work with a distributed
// sparsity pattern of Trilinos type, we
// only have to do the work if the
// current cell is owned by the calling
// processor. Otherwise, just continue.
for (; cell!=endc; ++cell)
#ifdef DEAL_II_USE_TRILINOS
if ((types_are_equal<SparsityPattern,TrilinosWrappers::SparsityPattern>::value
||
types_are_equal<SparsityPattern,TrilinosWrappers::BlockSparsityPattern>::value)
&&
cell->subdomain_id() !=
Utilities::Trilinos::get_this_mpi_process(Utilities::Trilinos::comm_world()))
continue;
else
#endif
{
const unsigned int fe_index
= cell->active_fe_index();
const unsigned int dofs_per_cell
= fe_collection[fe_index].dofs_per_cell;
dofs_on_this_cell.resize (dofs_per_cell);
cell->get_dof_indices (dofs_on_this_cell);
// make sparsity pattern for this
// cell. if no constraints pattern was
// given, then the following call acts
// as if simply no constraints existed
constraints.add_entries_local_to_global (dofs_on_this_cell,
sparsity,
keep_constrained_dofs,
dof_mask[fe_index]);
}
}
template <class DH, class SparsityPattern>
void
DoFTools::make_sparsity_pattern (
const DH &dof_row,
const DH &dof_col,
SparsityPattern &sparsity)
{
const unsigned int n_dofs_row = dof_row.n_dofs();
const unsigned int n_dofs_col = dof_col.n_dofs();
Assert (sparsity.n_rows() == n_dofs_row,
ExcDimensionMismatch (sparsity.n_rows(), n_dofs_row));
Assert (sparsity.n_cols() == n_dofs_col,
ExcDimensionMismatch (sparsity.n_cols(), n_dofs_col));
const std::list<std::pair<typename DH::cell_iterator,
typename DH::cell_iterator> >
cell_list
= GridTools::get_finest_common_cells (dof_row, dof_col);
typename std::list<std::pair<typename DH::cell_iterator,
typename DH::cell_iterator> >
::const_iterator
cell_iter = cell_list.begin();
for (; cell_iter!=cell_list.end(); ++cell_iter)
{
const typename DH::cell_iterator cell_row = cell_iter->first;
const typename DH::cell_iterator cell_col = cell_iter->second;
if (!cell_row->has_children() && !cell_col->has_children())
{
const unsigned int dofs_per_cell_row =
cell_row->get_fe().dofs_per_cell;
const unsigned int dofs_per_cell_col =
cell_col->get_fe().dofs_per_cell;
std::vector<unsigned int>
local_dof_indices_row(dofs_per_cell_row);
std::vector<unsigned int>
local_dof_indices_col(dofs_per_cell_col);
cell_row->get_dof_indices (local_dof_indices_row);
cell_col->get_dof_indices (local_dof_indices_col);
for (unsigned int i=0; i<dofs_per_cell_row; ++i)
sparsity.add_entries (local_dof_indices_row[i],
local_dof_indices_col.begin(),
local_dof_indices_col.end());
}
else if (cell_row->has_children())
{
const std::vector<typename DH::active_cell_iterator >
child_cells = GridTools::get_active_child_cells<DH> (cell_row);
for (unsigned int i=0; i<child_cells.size(); i++)
{
const typename DH::active_cell_iterator
cell_row_child = child_cells[i];
const unsigned int dofs_per_cell_row =
cell_row_child->get_fe().dofs_per_cell;
const unsigned int dofs_per_cell_col =
cell_col->get_fe().dofs_per_cell;
std::vector<unsigned int>
local_dof_indices_row(dofs_per_cell_row);
std::vector<unsigned int>
local_dof_indices_col(dofs_per_cell_col);
cell_row_child->get_dof_indices (local_dof_indices_row);
cell_col->get_dof_indices (local_dof_indices_col);
for (unsigned int i=0; i<dofs_per_cell_row; ++i)
sparsity.add_entries (local_dof_indices_row[i],
local_dof_indices_col.begin(),
local_dof_indices_col.end());
}
}
else
{
std::vector<typename DH::active_cell_iterator>
child_cells = GridTools::get_active_child_cells<DH> (cell_col);
for (unsigned int i=0; i<child_cells.size(); i++)
{
const typename DH::active_cell_iterator
cell_col_child = child_cells[i];
const unsigned int dofs_per_cell_row =
cell_row->get_fe().dofs_per_cell;
const unsigned int dofs_per_cell_col =
cell_col_child->get_fe().dofs_per_cell;
std::vector<unsigned int>
local_dof_indices_row(dofs_per_cell_row);
std::vector<unsigned int>
local_dof_indices_col(dofs_per_cell_col);
cell_row->get_dof_indices (local_dof_indices_row);
cell_col_child->get_dof_indices (local_dof_indices_col);
for (unsigned int i=0; i<dofs_per_cell_row; ++i)
sparsity.add_entries (local_dof_indices_row[i],
local_dof_indices_col.begin(),
local_dof_indices_col.end());
}
}
}
}
#if deal_II_dimension == 1
template <class DH, class SparsityPattern>
void
DoFTools::make_boundary_sparsity_pattern (
const DH &dof_handler,
const typename FunctionMap<DH::space_dimension>::type &function_map,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity)
{
// first check left, the right
// boundary point
for (unsigned int direction=0; direction<2; ++direction)
{
// if this boundary is not
// requested, then go on with next one
if (function_map.find(direction) ==
function_map.end())
continue;
// find active cell at that
// boundary: first go to
// left/right, then to children
typename DH::cell_iterator cell = dof_handler.begin(0);
while (!cell->at_boundary(direction))
cell = cell->neighbor(direction);
while (!cell->active())
cell = cell->child(direction);
const unsigned int dofs_per_vertex = cell->get_fe().dofs_per_vertex;
std::vector<unsigned int> boundary_dof_boundary_indices (dofs_per_vertex);
// next get boundary mapped dof
// indices of boundary dofs
for (unsigned int i=0; i<dofs_per_vertex; ++i)
boundary_dof_boundary_indices[i]
= dof_to_boundary_mapping[cell->vertex_dof_index(direction,i)];
for (unsigned int i=0; i<dofs_per_vertex; ++i)
sparsity.add_entries (boundary_dof_boundary_indices[i],
boundary_dof_boundary_indices.begin(),
boundary_dof_boundary_indices.end());
};
}
template <class DH, class SparsityPattern>
void DoFTools::make_boundary_sparsity_pattern (
const DH &dof_handler,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity)
{
// there are only 2 boundary
// indicators in 1d, so it is no
// performance problem to call the
// other function
typename DH::FunctionMap boundary_indicators;
boundary_indicators[0] = 0;
boundary_indicators[1] = 0;
make_boundary_sparsity_pattern<DH, SparsityPattern> (dof_handler,
boundary_indicators,
dof_to_boundary_mapping,
sparsity);
}
#else
template <class DH, class SparsityPattern>
void
DoFTools::make_boundary_sparsity_pattern (
const DH &dof,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity)
{
const unsigned int n_dofs = dof.n_dofs();
AssertDimension (dof_to_boundary_mapping.size(), n_dofs);
AssertDimension (sparsity.n_rows(), dof.n_boundary_dofs());
AssertDimension (sparsity.n_cols(), dof.n_boundary_dofs());
#ifdef DEBUG
if (sparsity.n_rows() != 0)
{
unsigned int max_element = 0;
for (std::vector<unsigned int>::const_iterator i=dof_to_boundary_mapping.begin();
i!=dof_to_boundary_mapping.end(); ++i)
if ((*i != DH::invalid_dof_index) &&
(*i > max_element))
max_element = *i;
AssertDimension (max_element, sparsity.n_rows()-1);
};
#endif
std::vector<unsigned int> dofs_on_this_face;
dofs_on_this_face.reserve (max_dofs_per_face(dof));
// loop over all faces to check
// whether they are at a
// boundary. note that we need not
// take special care of single
// lines (using
// @p{cell->has_boundary_lines}),
// since we do not support
// boundaries of dimension dim-2,
// and so every boundary line is
// also part of a boundary face.
typename DH::active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
for (; cell!=endc; ++cell)
for (unsigned int f=0; f<GeometryInfo<DH::dimension>::faces_per_cell; ++f)
if (cell->at_boundary(f))
{
const unsigned int dofs_per_face = cell->get_fe().dofs_per_face;
dofs_on_this_face.resize (dofs_per_face);
cell->face(f)->get_dof_indices (dofs_on_this_face,
cell->active_fe_index());
// make sparsity pattern for this cell
for (unsigned int i=0; i<dofs_per_face; ++i)
for (unsigned int j=0; j<dofs_per_face; ++j)
sparsity.add (dof_to_boundary_mapping[dofs_on_this_face[i]],
dof_to_boundary_mapping[dofs_on_this_face[j]]);
}
}
template <class DH, class SparsityPattern>
void DoFTools::make_boundary_sparsity_pattern (
const DH &dof,
const typename FunctionMap<DH::space_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity)
{
const unsigned int n_dofs = dof.n_dofs();
AssertDimension (dof_to_boundary_mapping.size(), n_dofs);
Assert (boundary_indicators.find(255) == boundary_indicators.end(),
typename DH::ExcInvalidBoundaryIndicator());
Assert (sparsity.n_rows() == dof.n_boundary_dofs (boundary_indicators),
ExcDimensionMismatch (sparsity.n_rows(), dof.n_boundary_dofs (boundary_indicators)));
Assert (sparsity.n_cols() == dof.n_boundary_dofs (boundary_indicators),
ExcDimensionMismatch (sparsity.n_cols(), dof.n_boundary_dofs (boundary_indicators)));
#ifdef DEBUG
if (sparsity.n_rows() != 0)
{
unsigned int max_element = 0;
for (std::vector<unsigned int>::const_iterator i=dof_to_boundary_mapping.begin();
i!=dof_to_boundary_mapping.end(); ++i)
if ((*i != DH::invalid_dof_index) &&
(*i > max_element))
max_element = *i;
AssertDimension (max_element, sparsity.n_rows()-1);
};
#endif
std::vector<unsigned int> dofs_on_this_face;
dofs_on_this_face.reserve (max_dofs_per_face(dof));
typename DH::active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
for (; cell!=endc; ++cell)
for (unsigned int f=0; f<GeometryInfo<DH::dimension>::faces_per_cell; ++f)
if (boundary_indicators.find(cell->face(f)->boundary_indicator()) !=
boundary_indicators.end())
{
const unsigned int dofs_per_face = cell->get_fe().dofs_per_face;
dofs_on_this_face.resize (dofs_per_face);
cell->face(f)->get_dof_indices (dofs_on_this_face,
cell->active_fe_index());
// make sparsity pattern for this cell
for (unsigned int i=0; i<dofs_per_face; ++i)
for (unsigned int j=0; j<dofs_per_face; ++j)
sparsity.add (dof_to_boundary_mapping[dofs_on_this_face[i]],
dof_to_boundary_mapping[dofs_on_this_face[j]]);
}
}
#endif
#if deal_II_dimension != 1
template <class DH, class SparsityPattern>
void
DoFTools::make_flux_sparsity_pattern (
const DH &dof,
SparsityPattern &sparsity)
{
const unsigned int n_dofs = dof.n_dofs();
Assert (sparsity.n_rows() == n_dofs,
ExcDimensionMismatch (sparsity.n_rows(), n_dofs));
Assert (sparsity.n_cols() == n_dofs,
ExcDimensionMismatch (sparsity.n_cols(), n_dofs));
std::vector<unsigned int> dofs_on_this_cell;
std::vector<unsigned int> dofs_on_other_cell;
dofs_on_this_cell.reserve (max_dofs_per_cell(dof));
dofs_on_other_cell.reserve (max_dofs_per_cell(dof));
typename DH::active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
// Clear user flags because we will
// need them. But first we save
// them and make sure that we
// restore them later such that at
// the end of this function the
// Triangulation will be in the
// same state as it was at the
// beginning of this function.
std::vector<bool> user_flags;
dof.get_tria().save_user_flags(user_flags);
const_cast<Triangulation<DH::dimension> &>(dof.get_tria()).clear_user_flags ();
for (; cell!=endc; ++cell)
{
const unsigned int n_dofs_on_this_cell = cell->get_fe().dofs_per_cell;
dofs_on_this_cell.resize (n_dofs_on_this_cell);
cell->get_dof_indices (dofs_on_this_cell);
// make sparsity pattern for this cell
for (unsigned int i=0; i<n_dofs_on_this_cell; ++i)
for (unsigned int j=0; j<n_dofs_on_this_cell; ++j)
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
// Loop over all interior neighbors
for (unsigned int face = 0;
face < GeometryInfo<DH::dimension>::faces_per_cell;
++face)
{
typename DH::face_iterator cell_face = cell->face(face);
if (cell_face->user_flag_set ())
continue;
if (! cell_face->at_boundary() )
{
typename DH::cell_iterator neighbor = cell->neighbor(face);
const unsigned int neighbor_face
= cell->neighbor_face_no(face);
if (cell_face->has_children())
{
for (unsigned int sub_nr = 0;
sub_nr != cell_face->number_of_children();
++sub_nr)
{
const typename DH::cell_iterator
sub_neighbor
= cell->neighbor_child_on_subface (face, sub_nr);
const unsigned int n_dofs_on_neighbor
= sub_neighbor->get_fe().dofs_per_cell;
dofs_on_other_cell.resize (n_dofs_on_neighbor);
sub_neighbor->get_dof_indices (dofs_on_other_cell);
for (unsigned int i=0; i<n_dofs_on_this_cell; ++i)
sparsity.add_entries (dofs_on_this_cell[i],
dofs_on_other_cell.begin(),
dofs_on_other_cell.end());
for (unsigned int j=0; j<n_dofs_on_neighbor; ++j)
sparsity.add_entries (dofs_on_other_cell[j],
dofs_on_this_cell.begin(),
dofs_on_this_cell.end());
sub_neighbor->face(neighbor_face)->set_user_flag ();
}
}
else
{
// Refinement edges are
// taken care of by
// coarser cells
if (cell->neighbor_is_coarser(face))
continue;
const unsigned int n_dofs_on_neighbor
= neighbor->get_fe().dofs_per_cell;
dofs_on_other_cell.resize (n_dofs_on_neighbor);
neighbor->get_dof_indices (dofs_on_other_cell);
for (unsigned int i=0; i<n_dofs_on_this_cell; ++i)
sparsity.add_entries (dofs_on_this_cell[i],
dofs_on_other_cell.begin(),
dofs_on_other_cell.end());
for (unsigned int j=0; j<n_dofs_on_neighbor; ++j)
sparsity.add_entries (dofs_on_other_cell[j],
dofs_on_this_cell.begin(),
dofs_on_this_cell.end());
neighbor->face(neighbor_face)->set_user_flag ();
}
}
}
}
// finally restore the user flags
const_cast<Triangulation<DH::dimension> &>(dof.get_tria()).load_user_flags(user_flags);
}
#else // deal_II_dimension == 1
template <class DH, class SparsityPattern>
void
DoFTools::make_flux_sparsity_pattern (
const DH &dof,
SparsityPattern &sparsity)
{
typedef typename DH::cell_iterator cell_iterator;
typedef typename DH::active_cell_iterator active_cell_iterator;
std::vector<unsigned int> local_dof_indices;
std::vector<unsigned int> neighbor_dof_indices;
local_dof_indices.reserve (max_dofs_per_cell(dof));
neighbor_dof_indices.reserve (max_dofs_per_cell(dof));
active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
for (; cell!=endc; ++cell)
{
// first do couplings of dofs
// locally on this cell
const unsigned int n_dofs_on_this_cell = cell->get_fe().dofs_per_cell;
local_dof_indices.resize (n_dofs_on_this_cell);
cell->get_dof_indices (local_dof_indices);
for (unsigned int i=0; i<n_dofs_on_this_cell; ++i)
sparsity.add_entries (local_dof_indices[i],
local_dof_indices.begin(),
local_dof_indices.end());
// then do the same for the up
// to 2 neighbors
for (unsigned int nb=0; nb<2; ++nb)
if (! cell->at_boundary(nb))
{
// find active neighbor
cell_iterator neighbor = cell->neighbor(nb);
while (neighbor->has_children())
neighbor = neighbor->child(nb==0 ? 1 : 0);
// get dofs on it
const unsigned int n_dofs_on_neighbor
= neighbor->get_fe().dofs_per_cell;
neighbor_dof_indices.resize (n_dofs_on_neighbor);
neighbor->get_dof_indices (neighbor_dof_indices);
// compute couplings
for (unsigned int i=0; i<n_dofs_on_this_cell; ++i)
sparsity.add_entries (local_dof_indices[i],
neighbor_dof_indices.begin(),
neighbor_dof_indices.end());
};
};
}
#endif
template <int dim, int spacedim>
Table<2,DoFTools::Coupling>
DoFTools::dof_couplings_from_component_couplings
(const FiniteElement<dim,spacedim> &fe,
const Table<2,Coupling> &component_couplings)
{
Assert(component_couplings.n_rows() == fe.n_components(),
ExcDimensionMismatch(component_couplings.n_rows(),
fe.n_components()));
Assert(component_couplings.n_cols() == fe.n_components(),
ExcDimensionMismatch(component_couplings.n_cols(),
fe.n_components()));
const unsigned int n_dofs = fe.dofs_per_cell;
Table<2,DoFTools::Coupling> dof_couplings (n_dofs, n_dofs);
for (unsigned int i=0; i<n_dofs; ++i)
{
const unsigned int ii
= (fe.is_primitive(i) ?
fe.system_to_component_index(i).first
:
(std::find (fe.get_nonzero_components(i).begin(),
fe.get_nonzero_components(i).end(),
true)
-
fe.get_nonzero_components(i).begin())
);
Assert (ii < fe.n_components(), ExcInternalError());
for (unsigned int j=0; j<n_dofs; ++j)
{
const unsigned int jj
= (fe.is_primitive(j) ?
fe.system_to_component_index(j).first
:
(std::find (fe.get_nonzero_components(j).begin(),
fe.get_nonzero_components(j).end(),
true)
-
fe.get_nonzero_components(j).begin())
);
Assert (jj < fe.n_components(), ExcInternalError());
dof_couplings(i,j) = component_couplings(ii,jj);
}
}
return dof_couplings;
}
// TODO: look whether one can employ collective add operations in sparsity
// pattern in this function.
template <class DH, class SparsityPattern>
void
DoFTools::make_flux_sparsity_pattern (
const DH &dof,
SparsityPattern &sparsity,
const Table<2,Coupling> &int_mask,
const Table<2,Coupling> &flux_mask)
{
const unsigned int n_dofs = dof.n_dofs();
const FiniteElement<DH::dimension> &fe = dof.get_fe();
const unsigned int n_comp = fe.n_components();
Assert (sparsity.n_rows() == n_dofs,
ExcDimensionMismatch (sparsity.n_rows(), n_dofs));
Assert (sparsity.n_cols() == n_dofs,
ExcDimensionMismatch (sparsity.n_cols(), n_dofs));
Assert (int_mask.n_rows() == n_comp,
ExcDimensionMismatch (int_mask.n_rows(), n_comp));
Assert (int_mask.n_cols() == n_comp,
ExcDimensionMismatch (int_mask.n_cols(), n_comp));
Assert (flux_mask.n_rows() == n_comp,
ExcDimensionMismatch (flux_mask.n_rows(), n_comp));
Assert (flux_mask.n_cols() == n_comp,
ExcDimensionMismatch (flux_mask.n_cols(), n_comp));
const unsigned int total_dofs = fe.dofs_per_cell;
std::vector<unsigned int> dofs_on_this_cell(total_dofs);
std::vector<unsigned int> dofs_on_other_cell(total_dofs);
Table<2,bool> support_on_face(
total_dofs, GeometryInfo<DH::dimension>::faces_per_cell);
typename DH::active_cell_iterator cell = dof.begin_active(),
endc = dof.end();
const Table<2,Coupling>
int_dof_mask = dof_couplings_from_component_couplings(fe, int_mask),
flux_dof_mask = dof_couplings_from_component_couplings(fe, flux_mask);
for (unsigned int i=0; i<total_dofs; ++i)
for (unsigned int f=0; f<GeometryInfo<DH::dimension>::faces_per_cell;++f)
support_on_face(i,f) = fe.has_support_on_face(i,f);
// Clear user flags because we will
// need them. But first we save
// them and make sure that we
// restore them later such that at
// the end of this function the
// Triangulation will be in the
// same state as it was at the
// beginning of this function.
std::vector<bool> user_flags;
dof.get_tria().save_user_flags(user_flags);
const_cast<Triangulation<DH::dimension> &>(dof.get_tria()).clear_user_flags ();
for (; cell!=endc; ++cell)
{
cell->get_dof_indices (dofs_on_this_cell);
// make sparsity pattern for this cell
for (unsigned int i=0; i<total_dofs; ++i)
for (unsigned int j=0; j<total_dofs; ++j)
if (int_dof_mask(i,j) != none)
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
// Loop over all interior neighbors
for (unsigned int face = 0;
face < GeometryInfo<DH::dimension>::faces_per_cell;
++face)
{
const typename DH::face_iterator
cell_face = cell->face(face);
if (cell_face->user_flag_set ())
continue;
if (cell->at_boundary (face) )
{
for (unsigned int i=0; i<total_dofs; ++i)
{
const bool i_non_zero_i = support_on_face (i, face);
for (unsigned int j=0; j<total_dofs; ++j)
{
const bool j_non_zero_i = support_on_face (j, face);
if (flux_dof_mask(i,j) == always)
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
if (flux_dof_mask(i,j) == nonzero
&& i_non_zero_i && j_non_zero_i)
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
}
}
}
else
{
typename DH::cell_iterator
neighbor = cell->neighbor(face);
// Refinement edges are taken care of
// by coarser cells
if (cell->neighbor_is_coarser(face))
continue;
typename DH::face_iterator cell_face = cell->face(face);
const unsigned int
neighbor_face = cell->neighbor_of_neighbor(face);
if (cell_face->has_children())
{
for (unsigned int sub_nr = 0;
sub_nr != cell_face->n_children();
++sub_nr)
{
const typename DH::cell_iterator
sub_neighbor
= cell->neighbor_child_on_subface (face, sub_nr);
sub_neighbor->get_dof_indices (dofs_on_other_cell);
for (unsigned int i=0; i<total_dofs; ++i)
{
const bool i_non_zero_i = support_on_face (i, face);
const bool i_non_zero_e = support_on_face (i, neighbor_face);
for (unsigned int j=0; j<total_dofs; ++j)
{
const bool j_non_zero_i = support_on_face (j, face);
const bool j_non_zero_e =support_on_face (j, neighbor_face);
if (flux_dof_mask(i,j) == always)
{
sparsity.add (dofs_on_this_cell[i],
dofs_on_other_cell[j]);
sparsity.add (dofs_on_other_cell[i],
dofs_on_this_cell[j]);
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
sparsity.add (dofs_on_other_cell[i],
dofs_on_other_cell[j]);
}
if (flux_dof_mask(i,j) == nonzero)
{
if (i_non_zero_i && j_non_zero_e)
sparsity.add (dofs_on_this_cell[i],
dofs_on_other_cell[j]);
if (i_non_zero_e && j_non_zero_i)
sparsity.add (dofs_on_other_cell[i],
dofs_on_this_cell[j]);
if (i_non_zero_i && j_non_zero_i)
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
if (i_non_zero_e && j_non_zero_e)
sparsity.add (dofs_on_other_cell[i],
dofs_on_other_cell[j]);
}
if (flux_dof_mask(j,i) == always)
{
sparsity.add (dofs_on_this_cell[j],
dofs_on_other_cell[i]);
sparsity.add (dofs_on_other_cell[j],
dofs_on_this_cell[i]);
sparsity.add (dofs_on_this_cell[j],
dofs_on_this_cell[i]);
sparsity.add (dofs_on_other_cell[j],
dofs_on_other_cell[i]);
}
if (flux_dof_mask(j,i) == nonzero)
{
if (j_non_zero_i && i_non_zero_e)
sparsity.add (dofs_on_this_cell[j],
dofs_on_other_cell[i]);
if (j_non_zero_e && i_non_zero_i)
sparsity.add (dofs_on_other_cell[j],
dofs_on_this_cell[i]);
if (j_non_zero_i && i_non_zero_i)
sparsity.add (dofs_on_this_cell[j],
dofs_on_this_cell[i]);
if (j_non_zero_e && i_non_zero_e)
sparsity.add (dofs_on_other_cell[j],
dofs_on_other_cell[i]);
}
}
}
sub_neighbor->face(neighbor_face)->set_user_flag ();
}
}
else
{
neighbor->get_dof_indices (dofs_on_other_cell);
for (unsigned int i=0; i<total_dofs; ++i)
{
const bool i_non_zero_i = support_on_face (i, face);
const bool i_non_zero_e = support_on_face (i, neighbor_face);
for (unsigned int j=0; j<total_dofs; ++j)
{
const bool j_non_zero_i = support_on_face (j, face);
const bool j_non_zero_e = support_on_face (j, neighbor_face);
if (flux_dof_mask(i,j) == always)
{
sparsity.add (dofs_on_this_cell[i],
dofs_on_other_cell[j]);
sparsity.add (dofs_on_other_cell[i],
dofs_on_this_cell[j]);
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
sparsity.add (dofs_on_other_cell[i],
dofs_on_other_cell[j]);
}
if (flux_dof_mask(i,j) == nonzero)
{
if (i_non_zero_i && j_non_zero_e)
sparsity.add (dofs_on_this_cell[i],
dofs_on_other_cell[j]);
if (i_non_zero_e && j_non_zero_i)
sparsity.add (dofs_on_other_cell[i],
dofs_on_this_cell[j]);
if (i_non_zero_i && j_non_zero_i)
sparsity.add (dofs_on_this_cell[i],
dofs_on_this_cell[j]);
if (i_non_zero_e && j_non_zero_e)
sparsity.add (dofs_on_other_cell[i],
dofs_on_other_cell[j]);
}
if (flux_dof_mask(j,i) == always)
{
sparsity.add (dofs_on_this_cell[j],
dofs_on_other_cell[i]);
sparsity.add (dofs_on_other_cell[j],
dofs_on_this_cell[i]);
sparsity.add (dofs_on_this_cell[j],
dofs_on_this_cell[i]);
sparsity.add (dofs_on_other_cell[j],
dofs_on_other_cell[i]);
}
if (flux_dof_mask(j,i) == nonzero)
{
if (j_non_zero_i && i_non_zero_e)
sparsity.add (dofs_on_this_cell[j],
dofs_on_other_cell[i]);
if (j_non_zero_e && i_non_zero_i)
sparsity.add (dofs_on_other_cell[j],
dofs_on_this_cell[i]);
if (j_non_zero_i && i_non_zero_i)
sparsity.add (dofs_on_this_cell[j],
dofs_on_this_cell[i]);
if (j_non_zero_e && i_non_zero_e)
sparsity.add (dofs_on_other_cell[j],
dofs_on_other_cell[i]);
}
}
}
neighbor->face(neighbor_face)->set_user_flag ();
}
}
}
}
// finally restore the user flags
const_cast<Triangulation<DH::dimension> &>(dof.get_tria()).load_user_flags(user_flags);
}
namespace internal
{
namespace DoFTools
{
namespace
{
inline
bool
check_master_dof_list (const FullMatrix<double> &face_interpolation_matrix,
const std::vector<unsigned int> &master_dof_list)
{
const unsigned int N = master_dof_list.size();
FullMatrix<double> tmp (N,N);
for (unsigned int i=0; i<N; ++i)
for (unsigned int j=0; j<N; ++j)
tmp(i,j) = face_interpolation_matrix (master_dof_list[i], j);
// then use the algorithm
// from
// FullMatrix::gauss_jordan
// on this matrix to find out
// whether it is
// singular. the algorithm
// there does piviting and at
// the end swaps rows back
// into their proper order --
// we omit this step here,
// since we don't care about
// the inverse matrix, all we
// care about is whether the
// matrix is regular or
// singular
// first get an estimate of the
// size of the elements of this
// matrix, for later checks whether
// the pivot element is large
// enough, or whether we have to
// fear that the matrix is not
// regular
double diagonal_sum = 0;
for (unsigned int i=0; i<N; ++i)
diagonal_sum += std::fabs(tmp(i,i));
const double typical_diagonal_element = diagonal_sum/N;
// initialize the array that holds
// the permutations that we find
// during pivot search
std::vector<unsigned int> p(N);
for (unsigned int i=0; i<N; ++i)
p[i] = i;
for (unsigned int j=0; j<N; ++j)
{
// pivot search: search that
// part of the line on and
// right of the diagonal for
// the largest element
double max = std::fabs(tmp(j,j));
unsigned int r = j;
for (unsigned int i=j+1; i<N; ++i)
{
if (std::fabs(tmp(i,j)) > max)
{
max = std::fabs(tmp(i,j));
r = i;
}
}
// check whether the
// pivot is too small. if
// that is the case, then
// the matrix is singular
// and we shouldn't use
// this set of master
// dofs
if (max < 1.e-12*typical_diagonal_element)
return false;
// row interchange
if (r>j)
{
for (unsigned int k=0; k<N; ++k)
std::swap (tmp(j,k), tmp(r,k));
std::swap (p[j], p[r]);
}
// transformation
const double hr = 1./tmp(j,j);
tmp(j,j) = hr;
for (unsigned int k=0; k<N; ++k)
{
if (k==j) continue;
for (unsigned int i=0; i<N; ++i)
{
if (i==j) continue;
tmp(i,k) -= tmp(i,j)*tmp(j,k)*hr;
}
}
for (unsigned int i=0; i<N; ++i)
{
tmp(i,j) *= hr;
tmp(j,i) *= -hr;
}
tmp(j,j) = hr;
}
// everything went fine, so
// we can accept this set of
// master dofs (at least as
// far as they have already
// been collected)
return true;
}
/**
* When restricting, on a face, the
* degrees of freedom of fe1 to the
* space described by fe2 (for example
* for the complex case described in
* the @ref hp_paper "hp paper"), we have to select
* fe2.dofs_per_face out of the
* fe1.dofs_per_face face DoFs as the
* master DoFs, and the rest become
* slave dofs. This function selects
* which ones will be masters, and
* which ones will be slaves.
*
* The function assumes that
* master_dofs already has size
* fe1.dofs_per_face. After the
* function, exactly fe2.dofs_per_face
* entries will be true.
*
* The function is a bit
* complicated since it has to
* figure out a set a DoFs so
* that the corresponding rows
* in the face interpolation
* matrix are all linearly
* independent. we have a good
* heuristic (see the function
* body) for selecting these
* rows, but there are cases
* where this fails and we have
* to pick them
* differently. what we do is
* to run the heuristic and
* then go back to determine
* whether we have a set of
* rows with full row rank. if
* this isn't the case, go back
* and select dofs differently
*/
template <int dim, int spacedim>
void
select_master_dofs_for_face_restriction (const FiniteElement<dim,spacedim> &fe1,
const FiniteElement<dim,spacedim> &fe2,
const FullMatrix<double> &face_interpolation_matrix,
std::vector<bool> &master_dof_mask)
{
Assert (fe1.dofs_per_face >= fe2.dofs_per_face,
ExcInternalError());
AssertDimension (master_dof_mask.size(), fe1.dofs_per_face);
Assert (fe2.dofs_per_vertex <= fe1.dofs_per_vertex,
ExcInternalError());
Assert (fe2.dofs_per_line <= fe1.dofs_per_line,
ExcInternalError());
Assert ((dim < 3)
||
(fe2.dofs_per_quad <= fe1.dofs_per_quad),
ExcInternalError());
// the idea here is to designate as
// many DoFs in fe1 per object
// (vertex, line, quad) as master as
// there are such dofs in fe2
// (indices are int, because we want
// to avoid the 'unsigned int < 0 is
// always false warning for the cases
// at the bottom in 1d and 2d)
//
// as mentioned in the paper, it is
// not always easy to find a set of
// master dofs that produces an
// invertible matrix. to this end, we
// check in each step whether the
// matrix is still invertible and
// simply discard this dof if the
// matrix is not invertible anymore.
//
// the cases where we did have
// trouble in the past were with
// adding more quad dofs when Q3 and
// Q4 elements meet at a refined face
// in 3d (see the hp/crash_12 test
// that tests that we can do exactly
// this, and failed before we had
// code to compensate for this
// case). the other case are system
// elements: if we have say a Q1Q2 vs
// a Q2Q3 element, then we can't just
// take all master dofs on a line
// from a single base element, since
// the shape functions of that base
// element are independent of that of
// the other one. this latter case
// shows up when running
// hp/hp_constraints_q_system_06
std::vector<unsigned int> master_dof_list;
unsigned int index = 0;
for (int v=0;
v<static_cast<signed int>(GeometryInfo<dim>::vertices_per_face);
++v)
{
unsigned int dofs_added = 0;
unsigned int i = 0;
while (dofs_added < fe2.dofs_per_vertex)
{
// make sure that we
// were able to find
// a set of master
// dofs and that the
// code down below
// didn't just reject
// all our efforts
Assert (i < fe1.dofs_per_vertex,
ExcInternalError());
// tentatively push
// this vertex dof
master_dof_list.push_back (index+i);
// then see what
// happens. if it
// succeeds, fine
if (check_master_dof_list (face_interpolation_matrix,
master_dof_list)
== true)
++dofs_added;
else
// well, it
// didn't. simply
// pop that dof
// from the list
// again and try
// with the next
// dof
master_dof_list.pop_back ();
// forward counter by
// one
++i;
}
index += fe1.dofs_per_vertex;
}
for (int l=0;
l<static_cast<signed int>(GeometryInfo<dim>::lines_per_face);
++l)
{
// same algorithm as above
unsigned int dofs_added = 0;
unsigned int i = 0;
while (dofs_added < fe2.dofs_per_line)
{
Assert (i < fe1.dofs_per_line,
ExcInternalError());
master_dof_list.push_back (index+i);
if (check_master_dof_list (face_interpolation_matrix,
master_dof_list)
== true)
++dofs_added;
else
master_dof_list.pop_back ();
++i;
}
index += fe1.dofs_per_line;
}
for (int q=0;
q<static_cast<signed int>(GeometryInfo<dim>::quads_per_face);
++q)
{
// same algorithm as above
unsigned int dofs_added = 0;
unsigned int i = 0;
while (dofs_added < fe2.dofs_per_quad)
{
Assert (i < fe1.dofs_per_quad,
ExcInternalError());
master_dof_list.push_back (index+i);
if (check_master_dof_list (face_interpolation_matrix,
master_dof_list)
== true)
++dofs_added;
else
master_dof_list.pop_back ();
++i;
}
index += fe1.dofs_per_quad;
}
AssertDimension (index, fe1.dofs_per_face);
AssertDimension (master_dof_list.size(), fe2.dofs_per_face);
// finally copy the list into the
// mask
std::fill (master_dof_mask.begin(), master_dof_mask.end(), false);
for (std::vector<unsigned int>::const_iterator i=master_dof_list.begin();
i!=master_dof_list.end(); ++i)
master_dof_mask[*i] = true;
}
/**
* Make sure that the mask exists that
* determines which dofs will be the
* masters on refined faces where an
* fe1 and a fe2 meet.
*/
template <int dim, int spacedim>
void
ensure_existence_of_master_dof_mask (const FiniteElement<dim,spacedim> &fe1,
const FiniteElement<dim,spacedim> &fe2,
const FullMatrix<double> &face_interpolation_matrix,
std_cxx1x::shared_ptr<std::vector<bool> > &master_dof_mask)
{
if (master_dof_mask == 0)
{
master_dof_mask = std_cxx1x::shared_ptr<std::vector<bool> >
(new std::vector<bool> (fe1.dofs_per_face));
select_master_dofs_for_face_restriction (fe1,
fe2,
face_interpolation_matrix,
*master_dof_mask);
}
}
/**
* Make sure that the given @p
* face_interpolation_matrix
* pointer points to a valid
* matrix. If the pointer is zero
* beforehand, create an entry
* with the correct data. If it
* is nonzero, don't touch it.
*/
template <int dim, int spacedim>
void
ensure_existence_of_face_matrix (const FiniteElement<dim,spacedim> &fe1,
const FiniteElement<dim,spacedim> &fe2,
std_cxx1x::shared_ptr<FullMatrix<double> > &matrix)
{
if (matrix == 0)
{
matrix = std_cxx1x::shared_ptr<FullMatrix<double> >
(new FullMatrix<double> (fe2.dofs_per_face,
fe1.dofs_per_face));
fe1.get_face_interpolation_matrix (fe2,
*matrix);
}
}
/**
* Same, but for subface
* interpolation matrices.
*/
template <int dim, int spacedim>
void
ensure_existence_of_subface_matrix (const FiniteElement<dim,spacedim> &fe1,
const FiniteElement<dim,spacedim> &fe2,
const unsigned int subface,
std_cxx1x::shared_ptr<FullMatrix<double> > &matrix)
{
if (matrix == 0)
{
matrix = std_cxx1x::shared_ptr<FullMatrix<double> >
(new FullMatrix<double> (fe2.dofs_per_face,
fe1.dofs_per_face));
fe1.get_subface_interpolation_matrix (fe2,
subface,
*matrix);
}
}
/**
* Given the face interpolation
* matrix between two elements,
* split it into its master and
* slave parts and invert the
* master part as explained in
* the @ref hp_paper "hp paper".
*/
#ifdef DEAL_II_ANON_NAMESPACE_BUG
static
#endif
void
ensure_existence_of_split_face_matrix (const FullMatrix<double> &face_interpolation_matrix,
const std::vector<bool> &master_dof_mask,
std_cxx1x::shared_ptr<std::pair<FullMatrix<double>,FullMatrix<double> > > &split_matrix)
{
AssertDimension (master_dof_mask.size(), face_interpolation_matrix.m());
Assert (std::count (master_dof_mask.begin(), master_dof_mask.end(), true) ==
static_cast<signed int>(face_interpolation_matrix.n()),
ExcInternalError());
if (split_matrix == 0)
{
split_matrix
= std_cxx1x::shared_ptr<std::pair<FullMatrix<double>,FullMatrix<double> > >
(new std::pair<FullMatrix<double>,FullMatrix<double> >());
const unsigned int n_master_dofs = face_interpolation_matrix.n();
const unsigned int n_dofs = face_interpolation_matrix.m();
Assert (n_master_dofs <= n_dofs, ExcInternalError());
// copy and invert the master
// component, copy the slave
// component
split_matrix->first.reinit (n_master_dofs, n_master_dofs);
split_matrix->second.reinit (n_dofs-n_master_dofs, n_master_dofs);
unsigned int nth_master_dof = 0,
nth_slave_dof = 0;
for (unsigned int i=0; i<n_dofs; ++i)
if (master_dof_mask[i] == true)
{
for (unsigned int j=0; j<n_master_dofs; ++j)
split_matrix->first(nth_master_dof,j)
= face_interpolation_matrix(i,j);
++nth_master_dof;
}
else
{
for (unsigned int j=0; j<n_master_dofs; ++j)
split_matrix->second(nth_slave_dof,j)
= face_interpolation_matrix(i,j);
++nth_slave_dof;
}
AssertDimension (nth_master_dof, n_master_dofs);
AssertDimension (nth_slave_dof, n_dofs-n_master_dofs);
//TODO[WB]: We should make sure very small entries are removed after inversion
split_matrix->first.gauss_jordan ();
}
}
// a template that can
// determine statically whether
// a given DoFHandler class
// supports different finite
// element elements
template <typename>
struct DoFHandlerSupportsDifferentFEs
{
static const bool value = true;
};
template <int dim, int spacedim>
struct DoFHandlerSupportsDifferentFEs< dealii::DoFHandler<dim,spacedim> >
{
static const bool value = false;
};
template <int dim, int spacedim>
struct DoFHandlerSupportsDifferentFEs< dealii::MGDoFHandler<dim,spacedim> >
{
static const bool value = false;
};
/**
* A function that returns how
* many different finite
* elements a dof handler
* uses. This is one for non-hp
* DoFHandlers and
* dof_handler.get_fe().size()
* for the hp-versions.
*/
template <int dim, int spacedim>
unsigned int
n_finite_elements (const dealii::hp::DoFHandler<dim,spacedim> &dof_handler)
{
return dof_handler.get_fe().size();
}
template <class DH>
unsigned int
n_finite_elements (const DH &)
{
return 1;
}
/**
* For a given face belonging
* to an active cell that
* borders to a more refined
* cell, return the fe_index of
* the most dominating finite
* element used on any of the
* face's subfaces.
*/
template <int dim, typename face_iterator>
unsigned int
get_most_dominating_subface_fe_index (const face_iterator &face)
{
const unsigned int spacedim=dim;
unsigned int dominating_subface_no = 0;
for (; dominating_subface_no<face->n_children();
++dominating_subface_no)
{
// each of the subfaces
// can have only a single
// fe_index associated
// with them, since there
// is no cell on the
// other side
Assert (face->child(dominating_subface_no)
->n_active_fe_indices()
== 1,
ExcInternalError());
const FiniteElement<dim,spacedim> &
this_subface_fe = (face->child(dominating_subface_no)
->get_fe (face->child(dominating_subface_no)
->nth_active_fe_index(0)));
FiniteElementDomination::Domination
domination = FiniteElementDomination::either_element_can_dominate;
for (unsigned int sf=0; sf<face->n_children(); ++sf)
if (sf != dominating_subface_no)
{
const FiniteElement<dim,spacedim> &
that_subface_fe = (face->child(sf)
->get_fe (face->child(sf)
->nth_active_fe_index(0)));
domination = domination &
this_subface_fe.compare_for_face_domination(that_subface_fe);
}
// see if the element
// on this subface is
// able to dominate
// the ones on all
// other subfaces,
// and if so take it
if ((domination == FiniteElementDomination::this_element_dominates)
||
(domination == FiniteElementDomination::either_element_can_dominate))
break;
}
// check that we have
// found one such subface
Assert (dominating_subface_no < face->n_children(),
ExcNotImplemented());
// return the finite element
// index used on it. note
// that only a single fe can
// be active on such subfaces
return face->child (dominating_subface_no)->nth_active_fe_index(0);
}
/**
* Copy constraints into a constraint
* matrix object.
*
* This function removes zero
* constraints and those, which
* constrain a DoF which was
* already eliminated in one of
* the previous steps of the hp
* hanging node procedure.
*
* It also suppresses very small
* entries in the constraint matrix to
* avoid making the sparsity pattern
* fuller than necessary.
*/
#ifdef DEAL_II_ANON_NAMESPACE_BUG
static
#endif
void
filter_constraints (const std::vector<unsigned int> &master_dofs,
const std::vector<unsigned int> &slave_dofs,
const FullMatrix<double> &face_constraints,
ConstraintMatrix &constraints)
{
Assert (face_constraints.n () == master_dofs.size (),
ExcDimensionMismatch(master_dofs.size (),
face_constraints.n()));
Assert (face_constraints.m () == slave_dofs.size (),
ExcDimensionMismatch(slave_dofs.size (),
face_constraints.m()));
const unsigned int n_master_dofs = master_dofs.size ();
const unsigned int n_slave_dofs = slave_dofs.size ();
for (unsigned int row=0; row!=n_slave_dofs; ++row)
if (constraints.is_constrained (slave_dofs[row]) == false)
{
bool constraint_already_satisfied = false;
// Check if we have an identity
// constraint, which is already
// satisfied by unification of
// the corresponding global dof
// indices
for (unsigned int i=0; i<n_master_dofs; ++i)
if (face_constraints (row,i) == 1.0)
if (master_dofs[i] == slave_dofs[row])
{
constraint_already_satisfied = true;
break;
}
if (constraint_already_satisfied == false)
{
// add up the absolute
// values of all
// constraints in this line
// to get a measure of
// their absolute size
double abs_sum = 0;
for (unsigned int i=0; i<n_master_dofs; ++i)
abs_sum += std::abs (face_constraints(row,i));
// then enter those
// constraints that are
// larger than
// 1e-14*abs_sum. everything
// else probably originated
// from inexact inversion
// of matrices and similar
// effects. having those
// constraints in here will
// only lead to problems
// because it makes
// sparsity patterns fuller
// than necessary without
// producing any
// significant effect
constraints.add_line (slave_dofs[row]);
for (unsigned int i=0; i<n_master_dofs; ++i)
if ((face_constraints(row,i) != 0)
&&
(std::fabs(face_constraints(row,i)) >= 1e-14*abs_sum))
{
#ifdef WOLFGANG
std::cout << " " << slave_dofs[row]
<< " -> " << face_constraints (row,i) << " * "
<< master_dofs[i]
<< std::endl;
#endif
constraints.add_entry (slave_dofs[row],
master_dofs[i],
face_constraints (row,i));
}
constraints.set_inhomogeneity (slave_dofs[row], 0.);
}
}
}
}
#if deal_II_dimension == 1
static
void
make_hp_hanging_node_constraints (const dealii::DoFHandler<1> &,
ConstraintMatrix &)
{
// nothing to do for regular
// dof handlers in 1d
}
static
void
make_oldstyle_hanging_node_constraints (const dealii::DoFHandler<1> &,
ConstraintMatrix &,
dealii::internal::int2type<1>)
{
// nothing to do for regular
// dof handlers in 1d
}
static
void
make_hp_hanging_node_constraints (const dealii::MGDoFHandler<1> &,
ConstraintMatrix &)
{
// nothing to do for regular
// dof handlers in 1d
}
static
void
make_oldstyle_hanging_node_constraints (const dealii::MGDoFHandler<1> &,
ConstraintMatrix &,
dealii::internal::int2type<1>)
{
// nothing to do for regular
// dof handlers in 1d
}
static
void
make_hp_hanging_node_constraints (const dealii::hp::DoFHandler<1> &/*dof_handler*/,
ConstraintMatrix &/*constraints*/)
{
// we may have to compute
// constraints for
// vertices. gotta think about
// that a bit more
//TODO[WB]: think about what to do here...
}
static
void
make_oldstyle_hanging_node_constraints (const dealii::hp::DoFHandler<1> &/*dof_handler*/,
ConstraintMatrix &/*constraints*/,
dealii::internal::int2type<1>)
{
// we may have to compute
// constraints for
// vertices. gotta think about
// that a bit more
//TODO[WB]: think about what to do here...
}
#endif
#if deal_II_dimension == 2
template <class DH>
static
void
make_oldstyle_hanging_node_constraints (const DH &dof_handler,
ConstraintMatrix &constraints,
dealii::internal::int2type<2>)
{
const unsigned int dim = 2;
const unsigned int spacedim = DH::space_dimension;
std::vector<unsigned int> dofs_on_mother;
std::vector<unsigned int> dofs_on_children;
// loop over all lines; only on
// lines there can be constraints.
// We do so by looping over all
// active cells and checking
// whether any of the faces are
// refined which can only be from
// the neighboring cell because
// this one is active. In that
// case, the face is subject to
// constraints
//
// note that even though we may
// visit a face twice if the
// neighboring cells are equally
// refined, we can only visit each
// face with hanging nodes once
typename DH::active_cell_iterator cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
if (cell->face(face)->has_children())
{
// so now we've found a
// face of an active
// cell that has
// children. that means
// that there are
// hanging nodes here.
// in any case, faces
// can have at most two
// active fe indices,
// but here the face
// can have only one
// (namely the same as
// that from the cell
// we're sitting on),
// and each of the
// children can have
// only one as
// well. check this
Assert (cell->face(face)->n_active_fe_indices() == 1,
ExcInternalError());
Assert (cell->face(face)->fe_index_is_active(cell->active_fe_index())
== true,
ExcInternalError());
for (unsigned int c=0; c<cell->face(face)->n_children(); ++c)
Assert (cell->face(face)->child(c)->n_active_fe_indices() == 1,
ExcInternalError());
// right now, all that
// is implemented is
// the case that both
// sides use the same
// fe
for (unsigned int c=0; c<cell->face(face)->n_children(); ++c)
Assert (cell->face(face)->child(c)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcNotImplemented());
// ok, start up the work
const FiniteElement<dim,spacedim> &fe = cell->get_fe();
const unsigned int fe_index = cell->active_fe_index();
const unsigned int
n_dofs_on_mother = 2*fe.dofs_per_vertex + fe.dofs_per_line,
n_dofs_on_children = fe.dofs_per_vertex + 2*fe.dofs_per_line;
dofs_on_mother.resize (n_dofs_on_mother);
dofs_on_children.resize (n_dofs_on_children);
Assert(n_dofs_on_mother == fe.constraints().n(),
ExcDimensionMismatch(n_dofs_on_mother,
fe.constraints().n()));
Assert(n_dofs_on_children == fe.constraints().m(),
ExcDimensionMismatch(n_dofs_on_children,
fe.constraints().m()));
const typename DH::line_iterator this_face = cell->face(face);
// fill the dofs indices. Use same
// enumeration scheme as in
// @p{FiniteElement::constraints()}
unsigned int next_index = 0;
for (unsigned int vertex=0; vertex<2; ++vertex)
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
dofs_on_mother[next_index++] = this_face->vertex_dof_index(vertex,dof,
fe_index);
for (unsigned int dof=0; dof!=fe.dofs_per_line; ++dof)
dofs_on_mother[next_index++] = this_face->dof_index(dof, fe_index);
AssertDimension (next_index, dofs_on_mother.size());
next_index = 0;
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
dofs_on_children[next_index++]
= this_face->child(0)->vertex_dof_index(1,dof,fe_index);
for (unsigned int child=0; child<2; ++child)
for (unsigned int dof=0; dof!=fe.dofs_per_line; ++dof)
dofs_on_children[next_index++]
= this_face->child(child)->dof_index(dof, fe_index);
AssertDimension (next_index, dofs_on_children.size());
// for each row in the constraint
// matrix for this line:
for (unsigned int row=0; row!=dofs_on_children.size(); ++row)
{
constraints.add_line (dofs_on_children[row]);
for (unsigned int i=0; i!=dofs_on_mother.size(); ++i)
constraints.add_entry (dofs_on_children[row],
dofs_on_mother[i],
fe.constraints()(row,i));
constraints.set_inhomogeneity (dofs_on_children[row], 0.);
}
}
else
{
// this face has no
// children, but it
// could still be that
// it is shared by two
// cells that use a
// different fe index
Assert (cell->face(face)->n_active_fe_indices() == 1,
ExcNotImplemented());
Assert (cell->face(face)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcInternalError());
}
}
#endif
#if deal_II_dimension == 3
template <class DH>
static
void
make_oldstyle_hanging_node_constraints (const DH &dof_handler,
ConstraintMatrix &constraints,
dealii::internal::int2type<3>)
{
const unsigned int dim = 3;
std::vector<unsigned int> dofs_on_mother;
std::vector<unsigned int> dofs_on_children;
// loop over all quads; only on
// quads there can be constraints.
// We do so by looping over all
// active cells and checking
// whether any of the faces are
// refined which can only be from
// the neighboring cell because
// this one is active. In that
// case, the face is subject to
// constraints
//
// note that even though we may
// visit a face twice if the
// neighboring cells are equally
// refined, we can only visit each
// face with hanging nodes once
typename DH::active_cell_iterator cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
if (cell->face(face)->has_children())
{
// first of all, make sure that
// we treat a case which is
// possible, i.e. either no dofs
// on the face at all or no
// anisotropic refinement
if (cell->get_fe().dofs_per_face == 0)
continue;
Assert(cell->face(face)->refinement_case()==RefinementCase<dim-1>::isotropic_refinement,
ExcNotImplemented());
// so now we've found a
// face of an active
// cell that has
// children. that means
// that there are
// hanging nodes here.
// in any case, faces
// can have at most two
// active fe indices,
// but here the face
// can have only one
// (namely the same as
// that from the cell
// we're sitting on),
// and each of the
// children can have
// only one as
// well. check this
AssertDimension (cell->face(face)->n_active_fe_indices(), 1);
Assert (cell->face(face)->fe_index_is_active(cell->active_fe_index())
== true,
ExcInternalError());
for (unsigned int c=0; c<cell->face(face)->n_children(); ++c)
AssertDimension (cell->face(face)->child(c)->n_active_fe_indices(), 1);
// right now, all that
// is implemented is
// the case that both
// sides use the same
// fe, and not only
// that but also that
// all lines bounding
// this face and the
// children have the
// same fe
for (unsigned int c=0; c<cell->face(face)->n_children(); ++c)
{
Assert (cell->face(face)->child(c)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcNotImplemented());
for (unsigned int e=0; e<4; ++e)
{
Assert (cell->face(face)->child(c)->line(e)
->n_active_fe_indices() == 1,
ExcNotImplemented());
Assert (cell->face(face)->child(c)->line(e)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcNotImplemented());
}
}
for (unsigned int e=0; e<4; ++e)
{
Assert (cell->face(face)->line(e)
->n_active_fe_indices() == 1,
ExcNotImplemented());
Assert (cell->face(face)->line(e)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcNotImplemented());
}
// ok, start up the work
const FiniteElement<dim> &fe = cell->get_fe();
const unsigned int fe_index = cell->active_fe_index();
const unsigned int
n_dofs_on_mother = (4*fe.dofs_per_vertex+
4*fe.dofs_per_line+
fe.dofs_per_quad),
n_dofs_on_children = (5*fe.dofs_per_vertex+
12*fe.dofs_per_line+
4*fe.dofs_per_quad);
//TODO[TL]: think about this and the following in case of anisotropic refinement
dofs_on_mother.resize (n_dofs_on_mother);
dofs_on_children.resize (n_dofs_on_children);
Assert(n_dofs_on_mother == fe.constraints().n(),
ExcDimensionMismatch(n_dofs_on_mother,
fe.constraints().n()));
Assert(n_dofs_on_children == fe.constraints().m(),
ExcDimensionMismatch(n_dofs_on_children,
fe.constraints().m()));
const typename DH::face_iterator this_face = cell->face(face);
// fill the dofs indices. Use same
// enumeration scheme as in
// @p{FiniteElement::constraints()}
unsigned int next_index = 0;
for (unsigned int vertex=0; vertex<4; ++vertex)
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
dofs_on_mother[next_index++] = this_face->vertex_dof_index(vertex,dof,
fe_index);
for (unsigned int line=0; line<4; ++line)
for (unsigned int dof=0; dof!=fe.dofs_per_line; ++dof)
dofs_on_mother[next_index++]
= this_face->line(line)->dof_index(dof, fe_index);
for (unsigned int dof=0; dof!=fe.dofs_per_quad; ++dof)
dofs_on_mother[next_index++] = this_face->dof_index(dof, fe_index);
AssertDimension (next_index, dofs_on_mother.size());
next_index = 0;
// assert some consistency
// assumptions
//TODO[TL]: think about this in case of anisotropic refinement
Assert (dof_handler.get_tria().get_anisotropic_refinement_flag() ||
((this_face->child(0)->vertex_index(3) ==
this_face->child(1)->vertex_index(2)) &&
(this_face->child(0)->vertex_index(3) ==
this_face->child(2)->vertex_index(1)) &&
(this_face->child(0)->vertex_index(3) ==
this_face->child(3)->vertex_index(0))),
ExcInternalError());
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
dofs_on_children[next_index++]
= this_face->child(0)->vertex_dof_index(3,dof);
// dof numbers on the centers of
// the lines bounding this face
for (unsigned int line=0; line<4; ++line)
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
dofs_on_children[next_index++]
= this_face->line(line)->child(0)->vertex_dof_index(1,dof, fe_index);
// next the dofs on the lines interior
// to the face; the order of these
// lines is laid down in the
// FiniteElement class documentation
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
dofs_on_children[next_index++]
= this_face->child(0)->line(1)->dof_index(dof, fe_index);
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
dofs_on_children[next_index++]
= this_face->child(2)->line(1)->dof_index(dof, fe_index);
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
dofs_on_children[next_index++]
= this_face->child(0)->line(3)->dof_index(dof, fe_index);
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
dofs_on_children[next_index++]
= this_face->child(1)->line(3)->dof_index(dof, fe_index);
// dofs on the bordering lines
for (unsigned int line=0; line<4; ++line)
for (unsigned int child=0; child<2; ++child)
for (unsigned int dof=0; dof!=fe.dofs_per_line; ++dof)
dofs_on_children[next_index++]
= this_face->line(line)->child(child)->dof_index(dof, fe_index);
// finally, for the dofs interior
// to the four child faces
for (unsigned int child=0; child<4; ++child)
for (unsigned int dof=0; dof!=fe.dofs_per_quad; ++dof)
dofs_on_children[next_index++]
= this_face->child(child)->dof_index(dof, fe_index);
AssertDimension (next_index, dofs_on_children.size());
// for each row in the constraint
// matrix for this line:
for (unsigned int row=0; row!=dofs_on_children.size(); ++row)
{
constraints.add_line (dofs_on_children[row]);
for (unsigned int i=0; i!=dofs_on_mother.size(); ++i)
constraints.add_entry (dofs_on_children[row],
dofs_on_mother[i],
fe.constraints()(row,i));
constraints.set_inhomogeneity(dofs_on_children[row], 0.);
}
}
else
{
// this face has no
// children, but it
// could still be that
// it is shared by two
// cells that use a
// different fe index
Assert (cell->face(face)->n_active_fe_indices() == 1,
ExcNotImplemented());
Assert (cell->face(face)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcInternalError());
}
}
#endif
template <class DH>
static
void
make_hp_hanging_node_constraints (const DH &dof_handler,
ConstraintMatrix &constraints)
{
// note: this function is going
// to be hard to understand if
// you haven't read the hp
// paper. however, we try to
// follow the notation laid out
// there, so go read the paper
// before you try to understand
// what is going on here
const unsigned int dim = DH::dimension;
const unsigned int spacedim = DH::space_dimension;
// a matrix to be used for
// constraints below. declared
// here and simply resized down
// below to avoid permanent
// re-allocation of memory
FullMatrix<double> constraint_matrix;
// similarly have arrays that
// will hold master and slave
// dof numbers, as well as a
// scratch array needed for the
// complicated case below
std::vector<unsigned int> master_dofs;
std::vector<unsigned int> slave_dofs;
std::vector<unsigned int> scratch_dofs;
// caches for the face and
// subface interpolation
// matrices between different
// (or the same) finite
// elements. we compute them
// only once, namely the first
// time they are needed, and
// then just reuse them
Table<2,std_cxx1x::shared_ptr<FullMatrix<double> > >
face_interpolation_matrices (n_finite_elements (dof_handler),
n_finite_elements (dof_handler));
Table<3,std_cxx1x::shared_ptr<FullMatrix<double> > >
subface_interpolation_matrices (n_finite_elements (dof_handler),
n_finite_elements (dof_handler),
GeometryInfo<dim>::max_children_per_face);
// similarly have a cache for
// the matrices that are split
// into their master and slave
// parts, and for which the
// master part is
// inverted. these two matrices
// are derived from the face
// interpolation matrix as
// described in the @ref hp_paper "hp paper"
Table<2,std_cxx1x::shared_ptr<std::pair<FullMatrix<double>,FullMatrix<double> > > >
split_face_interpolation_matrices (n_finite_elements (dof_handler),
n_finite_elements (dof_handler));
// finally, for each pair of finite
// elements, have a mask that states
// which of the degrees of freedom on
// the coarse side of a refined face
// will act as master dofs.
Table<2,std_cxx1x::shared_ptr<std::vector<bool> > >
master_dof_masks (n_finite_elements (dof_handler),
n_finite_elements (dof_handler));
// loop over all faces
//
// note that even though we may
// visit a face twice if the
// neighboring cells are equally
// refined, we can only visit each
// face with hanging nodes once
typename DH::active_cell_iterator cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
if (cell->face(face)->has_children())
{
// first of all, make sure that
// we treat a case which is
// possible, i.e. either no dofs
// on the face at all or no
// anisotropic refinement
if (cell->get_fe().dofs_per_face == 0)
continue;
Assert(cell->face(face)->refinement_case()==RefinementCase<dim-1>::isotropic_refinement,
ExcNotImplemented());
// so now we've found a
// face of an active
// cell that has
// children. that means
// that there are
// hanging nodes here.
// in any case, faces
// can have at most two
// sets of active fe
// indices, but here
// the face can have
// only one (namely the
// same as that from
// the cell we're
// sitting on), and
// each of the children
// can have only one as
// well. check this
Assert (cell->face(face)->n_active_fe_indices() == 1,
ExcInternalError());
Assert (cell->face(face)->fe_index_is_active(cell->active_fe_index())
== true,
ExcInternalError());
for (unsigned int c=0; c<cell->face(face)->n_children(); ++c)
Assert (cell->face(face)->child(c)->n_active_fe_indices() == 1,
ExcInternalError());
// first find out
// whether we can
// constrain each of
// the subfaces to the
// mother face. in the
// lingo of the hp
// paper, this would be
// the simple
// case. note that we
// can short-circuit
// this decision if the
// dof_handler doesn't
// support hp at all
FiniteElementDomination::Domination
mother_face_dominates = FiniteElementDomination::either_element_can_dominate;
if (DoFHandlerSupportsDifferentFEs<DH>::value == true)
for (unsigned int c=0; c<cell->face(face)->number_of_children(); ++c)
mother_face_dominates = mother_face_dominates &
(cell->get_fe().compare_for_face_domination
(cell->neighbor_child_on_subface (face, c)->get_fe()));
switch (mother_face_dominates)
{
case FiniteElementDomination::this_element_dominates:
case FiniteElementDomination::either_element_can_dominate:
{
// Case 1 (the
// simple case
// and the only
// case that can
// happen for
// non-hp
// DoFHandlers):
// The coarse
// element
// dominates the
// elements on
// the subfaces
// (or they are
// all the same)
master_dofs.resize (cell->get_fe().dofs_per_face);
cell->face(face)->get_dof_indices (master_dofs,
cell->active_fe_index ());
// Now create constraint matrix for
// the subfaces and assemble it.
for (unsigned int c=0; c<cell->face(face)->n_children(); ++c)
{
const typename DH::active_face_iterator
subface = cell->face(face)->child(c);
Assert (subface->n_active_fe_indices() == 1,
ExcInternalError());
const unsigned int
subface_fe_index = subface->nth_active_fe_index(0);
// Same procedure as for the
// mother cell. Extract the face
// DoFs from the cell DoFs.
slave_dofs.resize (subface->get_fe(subface_fe_index)
.dofs_per_face);
subface->get_dof_indices (slave_dofs, subface_fe_index);
// Now create the
// element constraint
// for this subface.
//
// As a side remark,
// one may wonder the
// following:
// neighbor_child is
// clearly computed
// correctly,
// i.e. taking into
// account
// face_orientation
// (just look at the
// implementation of
// that
// function). however,
// we don't care about
// this here, when we
// ask for
// subface_interpolation
// on subface c. the
// question rather is:
// do we have to
// translate 'c' here
// as well?
//
// the answer is in
// fact 'no'. if one
// does that, results
// are wrong:
// constraints are
// added twice for the
// same pair of nodes
// but with differing
// weights. in
// addition, one can
// look at the
// deal.II/project_*_03
// tests that look at
// exactly this case:
// there, we have a
// mesh with at least
// one
// face_orientation==false
// and hanging nodes,
// and the results of
// those tests show
// that the result of
// projection verifies
// the approximation
// properties of a
// finite element onto
// that mesh
ensure_existence_of_subface_matrix
(cell->get_fe(),
subface->get_fe(subface_fe_index),
c,
subface_interpolation_matrices
[cell->active_fe_index()][subface_fe_index][c]);
// Add constraints to global constraint
// matrix.
#ifdef WOLFGANG
std::cout << "Constraints for cell=" << cell
<< ", face=" << face
<< ", subface=" << c
<< std::endl;
#endif
filter_constraints (master_dofs,
slave_dofs,
*(subface_interpolation_matrices
[cell->active_fe_index()][subface_fe_index][c]),
constraints);
}
break;
}
case FiniteElementDomination::other_element_dominates:
case FiniteElementDomination::neither_element_dominates:
{
// Case 2 (the "complex"
// case): at least one
// (the neither_... case)
// of the finer elements
// or all of them (the
// other_... case) is
// dominating. See the hp
// paper for a way how to
// deal with this
// situation
//
// since this is
// something that
// can only
// happen for hp
// dof handlers,
// add a check
// here...
Assert (DoFHandlerSupportsDifferentFEs<DH>::value == true,
ExcInternalError());
// we first have
// to find the
// finite element
// that is able
// to generate a
// space that all
// the other ones
// can be
// constrained to
const unsigned int dominating_fe_index
= get_most_dominating_subface_fe_index<dim> (cell->face(face));
const FiniteElement<dim,spacedim> &dominating_fe
= dof_handler.get_fe()[dominating_fe_index];
// check also
// that it is
// able to
// constrain the
// mother
// face. it
// should be, or
// we wouldn't
// have gotten
// into the
// branch for the
// 'complex' case
Assert ((dominating_fe.compare_for_face_domination
(cell->face(face)->get_fe(cell->face(face)->nth_active_fe_index(0)))
== FiniteElementDomination::this_element_dominates)
||
(dominating_fe.compare_for_face_domination
(cell->face(face)->get_fe(cell->face(face)->nth_active_fe_index(0)))
== FiniteElementDomination::either_element_can_dominate),
ExcInternalError());
// first get the
// interpolation matrix
// from the mother to the
// virtual dofs
Assert (dominating_fe.dofs_per_face <=
cell->get_fe().dofs_per_face,
ExcInternalError());
ensure_existence_of_face_matrix
(dominating_fe,
cell->get_fe(),
face_interpolation_matrices
[dominating_fe_index][cell->active_fe_index()]);
// split this matrix into
// master and slave
// components. invert the
// master component
ensure_existence_of_master_dof_mask
(cell->get_fe(),
dominating_fe,
(*face_interpolation_matrices
[dominating_fe_index]
[cell->active_fe_index()]),
master_dof_masks
[dominating_fe_index]
[cell->active_fe_index()]);
ensure_existence_of_split_face_matrix
(*face_interpolation_matrices
[dominating_fe_index][cell->active_fe_index()],
(*master_dof_masks
[dominating_fe_index][cell->active_fe_index()]),
split_face_interpolation_matrices
[dominating_fe_index][cell->active_fe_index()]);
const FullMatrix<double> &restrict_mother_to_virtual_master_inv
= (split_face_interpolation_matrices
[dominating_fe_index][cell->active_fe_index()]->first);
const FullMatrix<double> &restrict_mother_to_virtual_slave
= (split_face_interpolation_matrices
[dominating_fe_index][cell->active_fe_index()]->second);
// now compute
// the constraint
// matrix as the
// product
// between the
// inverse matrix
// and the slave
// part
constraint_matrix.reinit (cell->get_fe().dofs_per_face -
dominating_fe.dofs_per_face,
dominating_fe.dofs_per_face);
restrict_mother_to_virtual_slave
.mmult (constraint_matrix,
restrict_mother_to_virtual_master_inv);
// then figure
// out the global
// numbers of
// master and
// slave dofs and
// apply
// constraints
scratch_dofs.resize (cell->get_fe().dofs_per_face);
cell->face(face)->get_dof_indices (scratch_dofs,
cell->active_fe_index ());
// split dofs into master
// and slave components
master_dofs.clear ();
slave_dofs.clear ();
for (unsigned int i=0; i<cell->get_fe().dofs_per_face; ++i)
if ((*master_dof_masks
[dominating_fe_index][cell->active_fe_index()])[i] == true)
master_dofs.push_back (scratch_dofs[i]);
else
slave_dofs.push_back (scratch_dofs[i]);
AssertDimension (master_dofs.size(), dominating_fe.dofs_per_face);
AssertDimension (slave_dofs.size(),
cell->get_fe().dofs_per_face - dominating_fe.dofs_per_face);
#ifdef WOLFGANG
std::cout << "Constraints for cell=" << cell
<< ", face=" << face
<< " (complicated case, mother)"
<< std::endl;
#endif
filter_constraints (master_dofs,
slave_dofs,
constraint_matrix,
constraints);
// next we have to
// deal with the
// subfaces. do as
// discussed in the
// paper
for (unsigned int sf=0;
sf<cell->face(face)->n_children(); ++sf)
{
Assert (cell->face(face)->child(sf)
->n_active_fe_indices() == 1,
ExcInternalError());
const unsigned int subface_fe_index
= cell->face(face)->child(sf)->nth_active_fe_index(0);
const FiniteElement<dim,spacedim> &subface_fe
= dof_handler.get_fe()[subface_fe_index];
// first get the
// interpolation
// matrix from the
// subface to the
// virtual dofs
Assert (dominating_fe.dofs_per_face <=
subface_fe.dofs_per_face,
ExcInternalError());
ensure_existence_of_subface_matrix
(dominating_fe,
subface_fe,
sf,
subface_interpolation_matrices
[dominating_fe_index][subface_fe_index][sf]);
const FullMatrix<double> &restrict_subface_to_virtual
= *(subface_interpolation_matrices
[dominating_fe_index][subface_fe_index][sf]);
constraint_matrix.reinit (subface_fe.dofs_per_face,
dominating_fe.dofs_per_face);
restrict_subface_to_virtual
.mmult (constraint_matrix,
restrict_mother_to_virtual_master_inv);
slave_dofs.resize (subface_fe.dofs_per_face);
cell->face(face)->child(sf)->get_dof_indices (slave_dofs,
subface_fe_index);
#ifdef WOLFGANG
std::cout << "Constraints for cell=" << cell
<< ", face=" << face
<< ", subface=" << sf
<< " (complicated case, children)"
<< std::endl;
#endif
filter_constraints (master_dofs,
slave_dofs,
constraint_matrix,
constraints);
}
break;
}
default:
// we shouldn't get here
Assert (false, ExcInternalError());
}
}
else
{
// this face has no
// children, but it
// could still be that
// it is shared by two
// cells that use a
// different fe index
Assert (cell->face(face)
->fe_index_is_active(cell->active_fe_index()) == true,
ExcInternalError());
// Only if there is
// a neighbor with
// a different
// active_fe_index
// and the same h-level,
// some action has
// to be taken.
if ((DoFHandlerSupportsDifferentFEs<DH>::value == true)
&&
!cell->face(face)->at_boundary ()
&&
(cell->neighbor(face)->active_fe_index () !=
cell->active_fe_index ())
&&
(!cell->face(face)->has_children() &&
!cell->neighbor_is_coarser(face) ))
{
const typename DH::cell_iterator neighbor = cell->neighbor (face);
// see which side of the
// face we have to
// constrain
switch (cell->get_fe().compare_for_face_domination (neighbor->get_fe ()))
{
case FiniteElementDomination::this_element_dominates:
{
// Get DoFs on
// dominating and
// dominated side of
// the face
master_dofs.resize (cell->get_fe().dofs_per_face);
cell->face(face)->get_dof_indices (master_dofs,
cell->active_fe_index ());
slave_dofs.resize (neighbor->get_fe().dofs_per_face);
cell->face(face)->get_dof_indices (slave_dofs,
neighbor->active_fe_index ());
// make sure
// the element
// constraints
// for this
// face are
// available
ensure_existence_of_face_matrix
(cell->get_fe(),
neighbor->get_fe(),
face_interpolation_matrices
[cell->active_fe_index()][neighbor->active_fe_index()]);
// Add constraints to global constraint
// matrix.
#ifdef WOLFGANG
std::cout << "p-constraints for cell=" << cell
<< ", face=" << face << std::endl;
#endif
filter_constraints (master_dofs,
slave_dofs,
*(face_interpolation_matrices
[cell->active_fe_index()]
[neighbor->active_fe_index()]),
constraints);
break;
}
case FiniteElementDomination::other_element_dominates:
{
// we don't do anything
// here since we will
// come back to this
// face from the other
// cell, at which time
// we will fall into
// the first case
// clause above
break;
}
case FiniteElementDomination::either_element_can_dominate:
{
// it appears as if
// neither element has
// any constraints on
// its neighbor. this
// may be because
// neither element has
// any DoFs on faces at
// all. or that the two
// elements are
// actually the same,
// although they happen
// to run under
// different fe_indices
// (this is what
// happens in
// hp/hp_hanging_nodes_01
// for example).
//
// another possibility
// is what happens in
// crash_13. there, we
// have
// FESystem(FE_Q(1),FE_DGQ(0))
// vs. FESystem(FE_Q(1),FE_DGQ(1)).
// neither of them
// dominates the
// other. the point is
// that it doesn't
// matter, since
// hopefully for this
// case, both sides'
// dofs should have
// been unified.
//
// make sure this is
// actually true. this
// actually only
// matters, of course,
// if either of the two
// finite elements
// actually do have
// dofs on the face
if ((cell->get_fe().dofs_per_face != 0)
||
(cell->neighbor(face)->get_fe().dofs_per_face != 0))
{
Assert (cell->get_fe().dofs_per_face
==
cell->neighbor(face)->get_fe().dofs_per_face,
ExcNotImplemented());
// (ab)use the master
// and slave dofs
// arrays for a
// moment here
master_dofs.resize (cell->get_fe().dofs_per_face);
cell->face(face)
->get_dof_indices (master_dofs,
cell->active_fe_index ());
slave_dofs.resize (cell->neighbor(face)->get_fe().dofs_per_face);
cell->face(face)
->get_dof_indices (slave_dofs,
cell->neighbor(face)->active_fe_index ());
for (unsigned int i=0; i<cell->get_fe().dofs_per_face; ++i)
AssertDimension (master_dofs[i], slave_dofs[i]);
}
break;
}
case FiniteElementDomination::neither_element_dominates:
{
// we don't presently
// know what exactly to
// do here. it isn't quite
// clear what exactly we
// would have to do
// here. sit tight until
// someone trips over the
// following statement
// and see what exactly
// is going on
Assert (false, ExcNotImplemented());
break;
}
default:
// we shouldn't get
// here
Assert (false, ExcInternalError());
}
}
}
}
}
}
template <class DH>
void
DoFTools::make_hanging_node_constraints (const DH &dof_handler,
ConstraintMatrix &constraints)
{
// Decide whether to use the
// new or old make_hanging_node_constraints
// function. If all the FiniteElement
// or all elements in a FECollection support
// the new face constraint matrix, the
// new code will be used.
// Otherwise, the old implementation is used
// for the moment.
if (dof_handler.get_fe().hp_constraints_are_implemented ())
internal::DoFTools::
make_hp_hanging_node_constraints (dof_handler,
constraints);
else
internal::DoFTools::
make_oldstyle_hanging_node_constraints (dof_handler,
constraints,
dealii::internal::int2type<DH::dimension>());
}
template <class DH, typename Number>
void DoFTools::distribute_cell_to_dof_vector (
const DH &dof_handler,
const Vector<Number> &cell_data,
Vector<double> &dof_data,
const unsigned int component)
{
const Triangulation<DH::dimension> &tria = dof_handler.get_tria();
Assert (cell_data.size()==tria.n_active_cells(),
ExcWrongSize (cell_data.size(), tria.n_active_cells()));
Assert (dof_data.size()==dof_handler.n_dofs(),
ExcWrongSize (dof_data.size(), dof_handler.n_dofs()));
Assert (component < n_components(dof_handler),
ExcInvalidComponent(component, n_components(dof_handler)));
Assert (fe_is_primitive(dof_handler) == true,
ExcFENotPrimitive());
// store a flag whether we should care
// about different components. this is
// just a simplification, we could ask
// for this at every single place
// equally well
const bool consider_components = (n_components(dof_handler) != 1);
// zero out the components that we
// will touch
if (consider_components == false)
dof_data = 0;
else
{
std::vector<bool> component_dofs (dof_handler.n_dofs());
std::vector<bool> component_mask (dof_handler.get_fe().n_components(),
false);
component_mask[component] = true;
DoFTools::extract_dofs (dof_handler, component_mask, component_dofs);
for (unsigned int i=0; i<dof_data.size(); ++i)
dof_data(i) = 0;
}
// count how often we have added a value
// in the sum for each dof
std::vector<unsigned char> touch_count (dof_handler.n_dofs(), 0);
typename DH::active_cell_iterator cell = dof_handler.begin_active(),
endc = dof_handler.end();
std::vector<unsigned int> dof_indices;
dof_indices.reserve (max_dofs_per_cell(dof_handler));
for (unsigned int present_cell = 0; cell!=endc; ++cell, ++present_cell)
{
const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell;
dof_indices.resize (dofs_per_cell);
cell->get_dof_indices (dof_indices);
for (unsigned int i=0; i<dofs_per_cell; ++i)
// consider this dof only if it
// is the right component. if there
// is only one component, short cut
// the test
if (!consider_components ||
(cell->get_fe().system_to_component_index(i).first == component))
{
// sum up contribution of the
// present_cell to this dof
dof_data(dof_indices[i]) += cell_data(present_cell);
// note that we added another
// summand
++touch_count[dof_indices[i]];
}
}
// compute the mean value on all the
// dofs by dividing with the number
// of summands.
for (unsigned int i=0; i<dof_handler.n_dofs(); ++i)
{
// assert that each dof was used
// at least once. this needs not be
// the case if the vector has more than
// one component
Assert (consider_components || (touch_count[i]!=0),
ExcInternalError());
if (touch_count[i] != 0)
dof_data(i) /= touch_count[i];
}
}
template <int dim, int spacedim>
void
DoFTools::extract_dofs (
const DoFHandler<dim,spacedim> &dof,
const std::vector<bool> &component_select,
std::vector<bool> &selected_dofs,
const bool count_by_blocks)
{
const FiniteElement<dim,spacedim> &fe = dof.get_fe();
if (count_by_blocks == true)
{
Assert(component_select.size() == fe.n_blocks(),
ExcDimensionMismatch(component_select.size(), fe.n_blocks()));
}
else
{
Assert(component_select.size() == n_components(dof),
ExcDimensionMismatch(component_select.size(), n_components(dof)));
}
Assert(selected_dofs.size() == dof.n_dofs(),
ExcDimensionMismatch(selected_dofs.size(), dof.n_dofs()));
// two special cases: no component
// is selected, and all components
// are selected; both rather
// stupid, but easy to catch
if (std::count (component_select.begin(), component_select.end(), true)
== 0)
{
std::fill_n (selected_dofs.begin(), dof.n_dofs(), false);
return;
};
if (std::count (component_select.begin(), component_select.end(), true)
== static_cast<signed int>(component_select.size()))
{
std::fill_n (selected_dofs.begin(), dof.n_dofs(), true);
return;
};
// preset all values by false
std::fill_n (selected_dofs.begin(), dof.n_dofs(), false);
// next set up a table for the
// degrees of freedom on each of
// the cells whether it is
// something interesting or not
std::vector<bool> local_selected_dofs (fe.dofs_per_cell, false);
for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
if (count_by_blocks == true)
local_selected_dofs[i]
= component_select[fe.system_to_block_index(i).first];
else
if (fe.is_primitive(i))
local_selected_dofs[i]
= component_select[fe.system_to_component_index(i).first];
else
// if this shape function is
// not primitive, then we have
// to work harder. we have to
// find out whether _any_ of
// the vector components of
// this element is selected or
// not
//
// to do so, get the first and
// last vector components of
// the base element to which
// the local dof with index i
// belongs
{
unsigned int first_comp = 0;
const unsigned int this_base = fe.system_to_base_index(i).first.first;
const unsigned int this_multiplicity
= fe.system_to_base_index(i).first.second;
for (unsigned int b=0; b<this_base; ++b)
first_comp += fe.base_element(b).n_components() *
fe.element_multiplicity(b);
for (unsigned int m=0; m<this_multiplicity; ++m)
first_comp += fe.base_element(this_base).n_components();
const unsigned int end_comp = first_comp +
fe.base_element(this_base).n_components();
Assert (first_comp < fe.n_components(), ExcInternalError());
Assert (end_comp <= fe.n_components(), ExcInternalError());
// now check whether any of
// the components in between
// is set
for (unsigned int c=first_comp; c<end_comp; ++c)
if (component_select[c] == true)
{
local_selected_dofs[i] = true;
break;
}
}
// then loop over all cells and do
// the work
std::vector<unsigned int> indices(fe.dofs_per_cell);
typename DoFHandler<dim,spacedim>::active_cell_iterator c;
for (c=dof.begin_active(); c!=dof.end(); ++ c)
{
c->get_dof_indices(indices);
for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
selected_dofs[indices[i]] = local_selected_dofs[i];
}
}
template <int dim, int spacedim>
void
DoFTools::extract_dofs (
const hp::DoFHandler<dim,spacedim> &/*dof*/,
const std::vector<bool> &/*component_select*/,
std::vector<bool> &/*selected_dofs*/,
const bool /*count_by_blocks*/)
{
//TODO[WB]: implement this function
Assert (false, ExcNotImplemented());
/*
const FiniteElement<dim,spacedim> &fe = dof.get_fe();
if (count_by_blocks == true)
{
Assert(component_select.size() == fe.n_blocks(),
ExcDimensionMismatch(component_select.size(), fe.n_blocks()));
}
else
{
Assert(component_select.size() == n_components(dof),
ExcDimensionMismatch(component_select.size(), n_components(dof)));
}
Assert(selected_dofs.size() == dof.n_dofs(),
ExcDimensionMismatch(selected_dofs.size(), dof.n_dofs()));
// two special cases: no component
// is selected, and all components
// are selected; both rather
// stupid, but easy to catch
if (std::count (component_select.begin(), component_select.end(), true)
== 0)
{
std::fill_n (selected_dofs.begin(), dof.n_dofs(), false);
return;
};
if (std::count (component_select.begin(), component_select.end(), true)
== static_cast<signed int>(component_select.size()))
{
std::fill_n (selected_dofs.begin(), dof.n_dofs(), true);
return;
};
// preset all values by false
std::fill_n (selected_dofs.begin(), dof.n_dofs(), false);
// next set up a table for the
// degrees of freedom on each of
// the cells whether it is
// something interesting or not
std::vector<bool> local_selected_dofs (fe.dofs_per_cell, false);
for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
if (count_by_blocks == true)
local_selected_dofs[i]
= component_select[fe.system_to_block_index(i).first];
else
if (fe.is_primitive(i))
local_selected_dofs[i]
= component_select[fe.system_to_component_index(i).first];
else
// if this shape function is
// not primitive, then we have
// to work harder. we have to
// find out whether _any_ of
// the vector components of
// this element is selected or
// not
//
// to do so, get the first and
// last vector components of
// the base element to which
// the local dof with index i
// belongs
{
unsigned int first_comp = 0;
const unsigned int this_base = fe.system_to_base_index(i).first.first;
const unsigned int this_multiplicity
= fe.system_to_base_index(i).first.second;
for (unsigned int b=0; b<this_base; ++b)
first_comp += fe.base_element(b).n_components() *
fe.element_multiplicity(b);
for (unsigned int m=0; m<this_multiplicity; ++m)
first_comp += fe.base_element(this_base).n_components();
const unsigned int end_comp = first_comp +
fe.base_element(this_base).n_components();
Assert (first_comp < fe.n_components(), ExcInternalError());
Assert (end_comp <= fe.n_components(), ExcInternalError());
// now check whether any of
// the components in between
// is set
for (unsigned int c=first_comp; c<end_comp; ++c)
if (component_select[c] == true)
{
local_selected_dofs[i] = true;
break;
}
}
// then loop over all cells and do
// the work
std::vector<unsigned int> indices(fe.dofs_per_cell);
typename DoFHandler<dim,spacedim>::active_cell_iterator c;
for (c=dof.begin_active(); c!=dof.end(); ++ c)
{
c->get_dof_indices(indices);
for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
selected_dofs[indices[i]] = local_selected_dofs[i];
}
*/
}
template<int dim, int spacedim>
void
DoFTools::extract_level_dofs(
const unsigned int level,
const MGDoFHandler<dim,spacedim> &dof,
const std::vector<bool> &component_select,
std::vector<bool> &selected_dofs,
const bool count_by_blocks)
{
const FiniteElement<dim,spacedim>& fe = dof.get_fe();
if (count_by_blocks == true)
{
Assert(component_select.size() == fe.n_blocks(),
ExcDimensionMismatch(component_select.size(), fe.n_blocks()));
}
else
{
Assert(component_select.size() == fe.n_components(),
ExcDimensionMismatch(component_select.size(), fe.n_components()));
}
Assert(selected_dofs.size() == dof.n_dofs(level),
ExcDimensionMismatch(selected_dofs.size(), dof.n_dofs(level)));
// two special cases: no component
// is selected, and all components
// are selected, both rather
// stupid, but easy to catch
if (std::count (component_select.begin(), component_select.end(), true)
== 0)
{
std::fill_n (selected_dofs.begin(), dof.n_dofs(level), false);
return;
};
if (std::count (component_select.begin(), component_select.end(), true)
== static_cast<signed int>(component_select.size()))
{
std::fill_n (selected_dofs.begin(), dof.n_dofs(level), true);
return;
};
// preset all values by false
std::fill_n (selected_dofs.begin(), dof.n_dofs(level), false);
// next set up a table for the
// degrees of freedom on each of
// the cells whether it is
// something interesting or not
std::vector<bool> local_selected_dofs (fe.dofs_per_cell, false);
for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
if (count_by_blocks == true)
local_selected_dofs[i]
= component_select[fe.system_to_block_index(i).first];
else
if (fe.is_primitive(i))
local_selected_dofs[i]
= component_select[fe.system_to_component_index(i).first];
else
// if this shape function is
// not primitive, then we have
// to work harder. we have to
// find out whether _any_ of
// the vector components of
// this element is selected or
// not
//
// to do so, get the first and
// last vector components of
// the base element to which
// the local dof with index i
// belongs
{
unsigned int first_comp = 0;
const unsigned int this_base = fe.system_to_base_index(i).first.first;
const unsigned int this_multiplicity
= fe.system_to_base_index(i).first.second;
for (unsigned int b=0; b<this_base; ++b)
first_comp += fe.base_element(b).n_components() *
fe.element_multiplicity(b);
for (unsigned int m=0; m<this_multiplicity; ++m)
first_comp += fe.base_element(this_base).n_components();
const unsigned int end_comp = first_comp +
fe.base_element(this_base).n_components();
Assert (first_comp < fe.n_components(), ExcInternalError());
Assert (end_comp <= fe.n_components(), ExcInternalError());
// now check whether any of
// the components in between
// is set
for (unsigned int c=first_comp; c<end_comp; ++c)
if (component_select[c] == true)
{
local_selected_dofs[i] = true;
break;
}
}
// then loop over all cells and do
// work
std::vector<unsigned int> indices(fe.dofs_per_cell);
typename MGDoFHandler<dim,spacedim>::cell_iterator c;
for (c = dof.begin(level) ; c != dof.end(level) ; ++ c)
{
c->get_mg_dof_indices(indices);
for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
selected_dofs[indices[i]] = local_selected_dofs[i];
}
}
#if deal_II_dimension != 1
template <class DH>
void
DoFTools::extract_boundary_dofs (const DH &dof_handler,
const std::vector<bool> &component_select,
std::vector<bool> &selected_dofs,
const std::set<unsigned char> &boundary_indicators)
{
Assert (component_select.size() == n_components(dof_handler),
ExcWrongSize (component_select.size(),
n_components(dof_handler)));
Assert (boundary_indicators.find (255) == boundary_indicators.end(),
ExcInvalidBoundaryIndicator());
const unsigned int dim=DH::dimension;
// let's see whether we have to
// check for certain boundary
// indicators or whether we can
// accept all
const bool check_boundary_indicator = (boundary_indicators.size() != 0);
// also see whether we have to
// check whether a certain vector
// component is selected, or all
const bool check_vector_component
= (component_select != std::vector<bool>(component_select.size(),
true));
// clear and reset array by default
// values
selected_dofs.clear ();
selected_dofs.resize (dof_handler.n_dofs(), false);
std::vector<unsigned int> face_dof_indices;
face_dof_indices.reserve (max_dofs_per_face(dof_handler));
// now loop over all cells and
// check whether their faces are at
// the boundary. note that we need
// not take special care of single
// lines being at the boundary
// (using
// @p{cell->has_boundary_lines}),
// since we do not support
// boundaries of dimension dim-2,
// and so every isolated boundary
// line is also part of a boundary
// face which we will be visiting
// sooner or later
for (typename DH::active_cell_iterator cell=dof_handler.begin_active();
cell!=dof_handler.end(); ++cell)
for (unsigned int face=0;
face<GeometryInfo<DH::dimension>::faces_per_cell; ++face)
if (cell->at_boundary(face))
if (! check_boundary_indicator ||
(boundary_indicators.find (cell->face(face)->boundary_indicator())
!= boundary_indicators.end()))
{
const FiniteElement<DH::dimension> &fe = cell->get_fe();
const unsigned int dofs_per_face = fe.dofs_per_face;
face_dof_indices.resize (dofs_per_face);
cell->face(face)->get_dof_indices (face_dof_indices,
cell->active_fe_index());
for (unsigned int i=0; i<fe.dofs_per_face; ++i)
if (!check_vector_component)
selected_dofs[face_dof_indices[i]] = true;
else
// check for
// component is
// required. somewhat
// tricky as usual
// for the case that
// the shape function
// is non-primitive,
// but use usual
// convention (see
// docs)
{
// first get at the
// cell-global
// number of a face
// dof, to ask the
// fe certain
// questions
const unsigned int cell_index
= (dim == 1 ?
i
:
(dim == 2 ?
(i<2*fe.dofs_per_vertex ? i : i+2*fe.dofs_per_vertex)
:
(dim == 3 ?
(i<4*fe.dofs_per_vertex ?
i
:
(i<4*fe.dofs_per_vertex+4*fe.dofs_per_line ?
i+4*fe.dofs_per_vertex
:
i+4*fe.dofs_per_vertex+8*fe.dofs_per_line))
:
numbers::invalid_unsigned_int)));
if (fe.is_primitive (cell_index))
selected_dofs[face_dof_indices[i]]
= (component_select[fe.face_system_to_component_index(i).first]
== true);
else // not primitive
{
const unsigned int first_nonzero_comp
= (std::find (fe.get_nonzero_components(cell_index).begin(),
fe.get_nonzero_components(cell_index).end(),
true)
-
fe.get_nonzero_components(cell_index).begin());
Assert (first_nonzero_comp < fe.n_components(),
ExcInternalError());
selected_dofs[face_dof_indices[i]]
= (component_select[first_nonzero_comp]
== true);
}
}
}
}
#else // 1d
template <class DH>
void
DoFTools::extract_boundary_dofs (const DH &dof_handler,
const std::vector<bool> &component_select,
std::vector<bool> &selected_dofs,
const std::set<unsigned char> &boundary_indicators)
{
Assert (component_select.size() == n_components(dof_handler),
ExcWrongSize (component_select.size(),
n_components(dof_handler)));
// clear and reset array by default
// values
selected_dofs.clear ();
selected_dofs.resize (dof_handler.n_dofs(), false);
// let's see whether we have to
// check for certain boundary
// indicators or whether we can
// accept all
const bool check_left_vertex = ((boundary_indicators.size() == 0) ||
(boundary_indicators.find(0) !=
boundary_indicators.end()));
const bool check_right_vertex = ((boundary_indicators.size() == 0) ||
(boundary_indicators.find(1) !=
boundary_indicators.end()));
// see whether we have to check
// whether a certain vector
// component is selected, or all
const bool check_vector_component
= (component_select != std::vector<bool>(component_select.size(),
true));
// loop over coarse grid cells
for (typename DH::cell_iterator cell=dof_handler.begin(0);
cell!=dof_handler.end(0); ++cell)
{
const FiniteElement<1> &fe = cell->get_fe();
// check left-most vertex
if (check_left_vertex)
if (cell->neighbor(0) == dof_handler.end())
{
// In 1D the number of DoFs
// on the faces should be
// equal to the number of DoFs
// on the vertices.
AssertDimension (fe.dofs_per_face, fe.dofs_per_vertex);
for (unsigned int i=0; i<fe.dofs_per_face; ++i)
if (!check_vector_component)
selected_dofs[cell->vertex_dof_index(0,i)] = true;
else
// check
// component. make sure
// we don't ask the
// wrong question
// (leading to an
// exception) in case
// the shape function
// is non-primitive. note
// that the face dof
// index i is also the
// cell dof index of a
// corresponding dof in 1d
{
const unsigned int component =
(fe.is_primitive(i) ?
fe.face_system_to_component_index(i).first :
(std::find (fe.get_nonzero_components(i).begin(),
fe.get_nonzero_components(i).end(),
true)
-
fe.get_nonzero_components(i).begin()));
Assert (component < fe.n_components(),
ExcInternalError());
if (component_select[component] == true)
selected_dofs[cell->vertex_dof_index(0,i)] = true;
}
}
// check right-most
// vertex. same procedure here
// as above
if (check_right_vertex)
if (cell->neighbor(1) == dof_handler.end())
{
AssertDimension (fe.dofs_per_face, fe.dofs_per_vertex);
for (unsigned int i=0; i<fe.dofs_per_face; ++i)
if (!check_vector_component)
selected_dofs[cell->vertex_dof_index(1,i)] = true;
else
{
const unsigned int component =
(fe.is_primitive(i) ?
fe.face_system_to_component_index(i).first :
(std::find (fe.get_nonzero_components(i).begin(),
fe.get_nonzero_components(i).end(),
true)
-
fe.get_nonzero_components(i).begin()));
Assert (component < fe.n_components(),
ExcInternalError());
if (component_select[component] == true)
selected_dofs[cell->vertex_dof_index(1,i)] = true;
}
}
}
}
#endif
namespace internal
{
namespace DoFTools
{
template <int spacedim>
void extract_hanging_node_dofs (const dealii::DoFHandler<1,spacedim> &dof_handler,
std::vector<bool> &selected_dofs)
{
Assert(selected_dofs.size() == dof_handler.n_dofs(),
ExcDimensionMismatch(selected_dofs.size(), dof_handler.n_dofs()));
// preset all values by false
std::fill_n (selected_dofs.begin(), dof_handler.n_dofs(), false);
// there are no hanging nodes in 1d
}
template <int spacedim>
void extract_hanging_node_dofs (const dealii::DoFHandler<2,spacedim> &dof_handler,
std::vector<bool> &selected_dofs)
{
const unsigned int dim = 2;
Assert(selected_dofs.size() == dof_handler.n_dofs(),
ExcDimensionMismatch(selected_dofs.size(), dof_handler.n_dofs()));
// preset all values by false
std::fill_n (selected_dofs.begin(), dof_handler.n_dofs(), false);
const FiniteElement<dim,spacedim> &fe = dof_handler.get_fe();
// this function is similar to the
// make_sparsity_pattern function,
// see there for more information
typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
if (cell->face(face)->has_children())
{
const typename dealii::DoFHandler<dim,spacedim>::line_iterator
line = cell->face(face);
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
selected_dofs[line->child(0)->vertex_dof_index(1,dof)] = true;
for (unsigned int child=0; child<2; ++child)
for (unsigned int dof=0; dof!=fe.dofs_per_line; ++dof)
selected_dofs[line->child(child)->dof_index(dof)] = true;
}
}
template <int spacedim>
void extract_hanging_node_dofs (const dealii::DoFHandler<3,spacedim> &dof_handler,
std::vector<bool> &selected_dofs)
{
const unsigned int dim = 3;
Assert(selected_dofs.size() == dof_handler.n_dofs(),
ExcDimensionMismatch(selected_dofs.size(), dof_handler.n_dofs()));
// preset all values by false
std::fill_n (selected_dofs.begin(), dof_handler.n_dofs(), false);
const FiniteElement<dim,spacedim> &fe = dof_handler.get_fe();
// this function is similar to the
// make_sparsity_pattern function,
// see there for more information
typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
if (cell->face(f)->has_children())
{
const typename dealii::DoFHandler<dim,spacedim>::face_iterator
face = cell->face(f);
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
selected_dofs[face->child(0)->vertex_dof_index(2,dof)] = true;
// dof numbers on the centers of
// the lines bounding this face
for (unsigned int line=0; line<4; ++line)
for (unsigned int dof=0; dof!=fe.dofs_per_vertex; ++dof)
selected_dofs[face->line(line)->child(0)->vertex_dof_index(1,dof)] = true;
// next the dofs on the lines interior
// to the face; the order of these
// lines is laid down in the
// FiniteElement class documentation
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
selected_dofs[face->child(0)->line(1)->dof_index(dof)] = true;
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
selected_dofs[face->child(1)->line(2)->dof_index(dof)] = true;
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
selected_dofs[face->child(2)->line(3)->dof_index(dof)] = true;
for (unsigned int dof=0; dof<fe.dofs_per_line; ++dof)
selected_dofs[face->child(3)->line(0)->dof_index(dof)] = true;
// dofs on the bordering lines
for (unsigned int line=0; line<4; ++line)
for (unsigned int child=0; child<2; ++child)
for (unsigned int dof=0; dof!=fe.dofs_per_line; ++dof)
selected_dofs[face->line(line)->child(child)->dof_index(dof)] = true;
// finally, for the dofs interior
// to the four child faces
for (unsigned int child=0; child<4; ++child)
for (unsigned int dof=0; dof!=fe.dofs_per_quad; ++dof)
selected_dofs[face->child(child)->dof_index(dof)] = true;
}
}
}
}
template <int dim, int spacedim>
void
DoFTools::
extract_hanging_node_dofs (const DoFHandler<dim,spacedim> &dof_handler,
std::vector<bool> &selected_dofs)
{
internal::DoFTools::extract_hanging_node_dofs (dof_handler,
selected_dofs);
}
template <class DH>
void
DoFTools::extract_subdomain_dofs (const DH &dof_handler,
const unsigned int subdomain_id,
std::vector<bool> &selected_dofs)
{
Assert(selected_dofs.size() == dof_handler.n_dofs(),
ExcDimensionMismatch(selected_dofs.size(), dof_handler.n_dofs()));
// preset all values by false
std::fill_n (selected_dofs.begin(), dof_handler.n_dofs(), false);
std::vector<unsigned int> local_dof_indices;
local_dof_indices.reserve (max_dofs_per_cell(dof_handler));
// this function is similar to the
// make_sparsity_pattern function,
// see there for more information
typename DH::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
if (cell->subdomain_id() == subdomain_id)
{
const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell;
local_dof_indices.resize (dofs_per_cell);
cell->get_dof_indices (local_dof_indices);
for (unsigned int i=0; i<dofs_per_cell; ++i)
selected_dofs[local_dof_indices[i]] = true;
};
}
template <class DH>
void
DoFTools::extract_constant_modes (const DH &dof_handler,
const std::vector<bool> &component_select,
std::vector<std::vector<bool> > &constant_modes)
{
const unsigned int n_components = dof_handler.get_fe().n_components();
Assert (n_components == component_select.size(),
ExcDimensionMismatch(n_components,
component_select.size()));
// First count the number of dofs
// in the current component.
unsigned int n_components_selected = 0;
std::vector<unsigned int> component_list (n_components, 0);
for (unsigned int d=0; d<n_components; ++d)
{
component_list[d] = component_select[d];
n_components_selected += component_select[d];
}
std::vector<unsigned int> dofs_per_block(2);
count_dofs_per_block(dof_handler, dofs_per_block, component_list);
const unsigned int n_u = dofs_per_block[1];
std::vector<bool> selection_dof_list (dof_handler.n_dofs(), false);
std::vector<bool> temporary_dof_list (dof_handler.n_dofs(), false);
extract_dofs (dof_handler, component_select, selection_dof_list);
constant_modes.resize (n_components_selected, std::vector<bool>(n_u, false));
for (unsigned int component=0, component_used=0;
component < n_components; ++component, ++component_used)
if (component_select[component])
{
std::vector<bool> selection_mask (n_components, false);
selection_mask[component] = true;
extract_dofs (dof_handler, selection_mask, temporary_dof_list);
unsigned int counter = 0;
for (unsigned int i=0; i<dof_handler.n_dofs(); ++i)
{
if (selection_dof_list[i])
{
if (temporary_dof_list[i])
constant_modes [component][counter] = true;
else
constant_modes [component][counter] = false;
++counter;
}
}
}
}
template <class DH>
void
DoFTools::get_active_fe_indices (const DH &dof_handler,
std::vector<unsigned int> &active_fe_indices)
{
Assert (active_fe_indices.size() == dof_handler.get_tria().n_active_cells(),
ExcWrongSize (active_fe_indices.size(),
dof_handler.get_tria().n_active_cells()));
typename DH::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (unsigned int index=0; cell!=endc; ++cell, ++index)
active_fe_indices[index] = cell->active_fe_index();
}
template <class DH>
void
DoFTools::get_subdomain_association (const DH &dof_handler,
std::vector<unsigned int> &subdomain_association)
{
Assert(subdomain_association.size() == dof_handler.n_dofs(),
ExcDimensionMismatch(subdomain_association.size(),
dof_handler.n_dofs()));
// preset all values by an invalid value
std::fill_n (subdomain_association.begin(), dof_handler.n_dofs(),
numbers::invalid_unsigned_int);
std::vector<unsigned int> local_dof_indices;
local_dof_indices.reserve (max_dofs_per_cell(dof_handler));
// pseudo-randomly assign variables
// which lie on the interface
// between subdomains to each of
// the two or more
bool coin_flip = true;
// loop over all cells and record
// which subdomain a DoF belongs
// to. toss a coin in case it is on
// an interface
typename DH::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
{
const unsigned int subdomain_id = cell->subdomain_id();
const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell;
local_dof_indices.resize (dofs_per_cell);
cell->get_dof_indices (local_dof_indices);
// set subdomain ids. if dofs
// already have their values
// set then they must be on
// partition interfaces. in
// that case randomly assign
// them to either the previous
// association or the current
// one, where we take "random"
// to be "once this way once
// that way"
for (unsigned int i=0; i<dofs_per_cell; ++i)
if (subdomain_association[local_dof_indices[i]] ==
numbers::invalid_unsigned_int)
subdomain_association[local_dof_indices[i]] = subdomain_id;
else
{
if (coin_flip == true)
subdomain_association[local_dof_indices[i]] = subdomain_id;
coin_flip = !coin_flip;
}
}
Assert (std::find (subdomain_association.begin(),
subdomain_association.end(),
numbers::invalid_unsigned_int)
== subdomain_association.end(),
ExcInternalError());
}
template <class DH>
unsigned int
DoFTools::count_dofs_with_subdomain_association (const DH &dof_handler,
const unsigned int subdomain)
{
// in debug mode, make sure that there are
// some cells at least with this subdomain
// id
#ifdef DEBUG
{
bool found = false;
for (typename Triangulation<DH::dimension, DH::space_dimension>::active_cell_iterator
cell=dof_handler.get_tria().begin_active();
cell!=dof_handler.get_tria().end(); ++cell)
if (cell->subdomain_id() == subdomain)
{
found = true;
break;
}
Assert (found == true,
ExcMessage ("There are no cells for the given subdomain!"));
}
#endif
std::vector<unsigned int> subdomain_association (dof_handler.n_dofs());
get_subdomain_association (dof_handler, subdomain_association);
return std::count (subdomain_association.begin(),
subdomain_association.end(),
subdomain);
}
template <class DH>
void
DoFTools::count_dofs_with_subdomain_association (const DH &dof_handler,
const unsigned int subdomain,
std::vector<unsigned int> &n_dofs_on_subdomain)
{
Assert (n_dofs_on_subdomain.size() == dof_handler.get_fe().n_components(),
ExcDimensionMismatch (n_dofs_on_subdomain.size(),
dof_handler.get_fe().n_components()));
std::fill (n_dofs_on_subdomain.begin(), n_dofs_on_subdomain.end(), 0);
// in debug mode, make sure that there are
// some cells at least with this subdomain
// id
#ifdef DEBUG
{
bool found = false;
for (typename Triangulation<DH::dimension,DH::space_dimension>::active_cell_iterator
cell=dof_handler.get_tria().begin_active();
cell!=dof_handler.get_tria().end(); ++cell)
if (cell->subdomain_id() == subdomain)
{
found = true;
break;
}
Assert (found == true,
ExcMessage ("There are no cells for the given subdomain!"));
}
#endif
std::vector<unsigned int> subdomain_association (dof_handler.n_dofs());
get_subdomain_association (dof_handler, subdomain_association);
std::vector<bool> component_association (dof_handler.n_dofs());
for (unsigned int c=0; c<dof_handler.get_fe().n_components(); ++c)
{
std::vector<bool> component_mask (dof_handler.get_fe().n_components(), false);
component_mask[c] = true;
extract_dofs (dof_handler, component_mask, component_association);
for (unsigned int i=0; i<dof_handler.n_dofs(); ++i)
if ((subdomain_association[i] == subdomain) &&
(component_association[i] == true))
++n_dofs_on_subdomain[c];
}
}
template <int dim, int spacedim>
void
DoFTools::count_dofs_per_component (
const DoFHandler<dim,spacedim>& dof_handler,
std::vector<unsigned int>& dofs_per_component,
bool only_once,
std::vector<unsigned int> target_component)
{
const FiniteElement<dim,spacedim>& fe = dof_handler.get_fe();
std::fill (dofs_per_component.begin(), dofs_per_component.end(), 0U);
// If the empty vector was given as
// default argument, set up this
// vector as identity.
if (target_component.size()==0)
{
target_component.resize(fe.n_components());
for (unsigned int i=0; i<fe.n_components(); ++i)
target_component[i] = i;
}
else
Assert (target_component.size()==fe.n_components(),
ExcDimensionMismatch(target_component.size(),
fe.n_components()));
const unsigned int max_component
= *std::max_element (target_component.begin(),
target_component.end());
const unsigned int n_target_components = max_component + 1;
const unsigned int n_components = fe.n_components();
AssertDimension (dofs_per_component.size(), n_target_components);
// special case for only one
// component. treat this first
// since it does not require any
// computations
if (n_components == 1)
{
dofs_per_component[0] = dof_handler.n_dofs();
return;
}
// otherwise determine the number
// of dofs in each component
// separately. do so in parallel
std::vector<std::vector<bool> >
dofs_in_component (n_components,
std::vector<bool>(dof_handler.n_dofs(), false));
std::vector<std::vector<bool> >
component_select (n_components,
std::vector<bool>(n_components, false));
Threads::ThreadGroup<> threads;
for (unsigned int i=0; i<n_components; ++i)
{
void (*fun_ptr) (const DoFHandler<dim,spacedim> &,
const std::vector<bool> &,
std::vector<bool> &,
bool)
= &DoFTools::template extract_dofs<dim>;
component_select[i][i] = true;
threads += Threads::spawn (fun_ptr)(dof_handler, component_select[i],
dofs_in_component[i], false);
};
threads.join_all ();
// next count what we got
unsigned int component = 0;
for (unsigned int b=0;b<fe.n_base_elements();++b)
{
const FiniteElement<dim,spacedim>& base = fe.base_element(b);
// Dimension of base element
unsigned int d = base.n_components();
for (unsigned int m=0;m<fe.element_multiplicity(b);++m)
{
for (unsigned int dd=0;dd<d;++dd)
{
if (base.is_primitive() || (!only_once || dd==0))
dofs_per_component[target_component[component]]
+= std::count(dofs_in_component[component].begin(),
dofs_in_component[component].end(),
true);
++component;
}
}
}
// finally sanity check. this is
// only valid if the finite element
// is actually primitive, so
// exclude other elements from this
Assert (!dof_handler.get_fe().is_primitive()
||
(std::accumulate (dofs_per_component.begin(),
dofs_per_component.end(), 0U)
== dof_handler.n_dofs()),
ExcInternalError());
}
template <int dim, int spacedim>
void
DoFTools::count_dofs_per_block (
const DoFHandler<dim,spacedim>& dof_handler,
std::vector<unsigned int>& dofs_per_block,
std::vector<unsigned int> target_block)
{
const FiniteElement<dim,spacedim>& fe = dof_handler.get_fe();
std::fill (dofs_per_block.begin(), dofs_per_block.end(), 0U);
// If the empty vector was given as
// default argument, set up this
// vector as identity.
if (target_block.size()==0)
{
target_block.resize(fe.n_blocks());
for (unsigned int i=0; i<fe.n_blocks(); ++i)
target_block[i] = i;
}
else
Assert (target_block.size()==fe.n_blocks(),
ExcDimensionMismatch(target_block.size(),
fe.n_blocks()));
const unsigned int max_block
= *std::max_element (target_block.begin(),
target_block.end());
const unsigned int n_target_blocks = max_block + 1;
const unsigned int n_blocks = fe.n_blocks();
AssertDimension (dofs_per_block.size(), n_target_blocks);
// special case for only one
// block. treat this first
// since it does not require any
// computations
if (n_blocks == 1)
{
dofs_per_block[0] = dof_handler.n_dofs();
return;
}
// otherwise determine the number
// of dofs in each block
// separately. do so in parallel
std::vector<std::vector<bool> >
dofs_in_block (n_blocks, std::vector<bool>(dof_handler.n_dofs(), false));
std::vector<std::vector<bool> >
block_select (n_blocks, std::vector<bool>(n_blocks, false));
Threads::ThreadGroup<> threads;
for (unsigned int i=0; i<n_blocks; ++i)
{
void (*fun_ptr) (const DoFHandler<dim,spacedim> &,
const std::vector<bool> &,
std::vector<bool> &,
bool)
= &DoFTools::template extract_dofs<dim>;
block_select[i][i] = true;
threads += Threads::spawn (fun_ptr)(dof_handler, block_select[i],
dofs_in_block[i], true);
};
threads.join_all ();
// next count what we got
for (unsigned int block=0;block<fe.n_blocks();++block)
dofs_per_block[target_block[block]]
+= std::count(dofs_in_block[block].begin(),
dofs_in_block[block].end(),
true);
}
template <int dim, int spacedim>
void
DoFTools::count_dofs_per_component (
const DoFHandler<dim,spacedim>& dof_handler,
std::vector<unsigned int>& dofs_per_component,
std::vector<unsigned int> target_component)
{
count_dofs_per_component (dof_handler, dofs_per_component, false, target_component);
}
namespace internal
{
namespace
{
/**
* This is a function that is
* called by the _2 function and
* that operates on a range of
* cells only. It is used to
* split up the whole range of
* cells into chunks which are
* then worked on in parallel, if
* multithreading is available.
*/
template <int dim, int spacedim>
void
compute_intergrid_weights_3 (
const dealii::DoFHandler<dim,spacedim> &coarse_grid,
const unsigned int coarse_component,
const InterGridMap<dealii::DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
const std::vector<Vector<double> > ¶meter_dofs,
const std::vector<int> &weight_mapping,
std::vector<std::map<unsigned int, float> > &weights,
const typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator &begin,
const typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator &end)
{
// aliases to the finite elements
// used by the dof handlers:
const FiniteElement<dim,spacedim> &coarse_fe = coarse_grid.get_fe();
// for each cell on the parameter grid:
// find out which degrees of freedom on the
// fine grid correspond in which way to
// the degrees of freedom on the parameter
// grid
//
// since for continuous FEs some
// dofs exist on more than one
// cell, we have to track which
// ones were already visited. the
// problem is that if we visit a
// dof first on one cell and
// compute its weight with respect
// to some global dofs to be
// non-zero, and later visit the
// dof again on another cell and
// (since we are on another cell)
// recompute the weights with
// respect to the same dofs as
// above to be zero now, we have to
// preserve them. we therefore
// overwrite all weights if they
// are nonzero and do not enforce
// zero weights since that might be
// only due to the fact that we are
// on another cell.
//
// example:
// coarse grid
// | | |
// *-----*-----*
// | cell|cell |
// | 1 | 2 |
// | | |
// 0-----1-----*
//
// fine grid
// | | | | |
// *--*--*--*--*
// | | | | |
// *--*--*--*--*
// | | | | |
// *--x--y--*--*
//
// when on cell 1, we compute the
// weights of dof 'x' to be 1/2
// from parameter dofs 0 and 1,
// respectively. however, when
// later we are on cell 2, we again
// compute the prolongation of
// shape function 1 restricted to
// cell 2 to the globla grid and
// find that the weight of global
// dof 'x' now is zero. however, we
// should not overwrite the old
// value.
//
// we therefore always only set
// nonzero values. why adding up is
// not useful: dof 'y' would get
// weight 1 from parameter dof 1 on
// both cells 1 and 2, but the
// correct weight is nevertheless
// only 1.
// vector to hold the representation of
// a single degree of freedom on the
// coarse grid (for the selected fe)
// on the fine grid
const unsigned int n_fine_dofs = weight_mapping.size();
Vector<double> global_parameter_representation (n_fine_dofs);
typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator cell;
std::vector<unsigned int> parameter_dof_indices (coarse_fe.dofs_per_cell);
for (cell=begin; cell!=end; ++cell)
{
// get the global indices of the
// parameter dofs on this parameter
// grid cell
cell->get_dof_indices (parameter_dof_indices);
// loop over all dofs on this
// cell and check whether they
// are interesting for us
for (unsigned int local_dof=0;
local_dof<coarse_fe.dofs_per_cell;
++local_dof)
if (coarse_fe.system_to_component_index(local_dof).first
==
coarse_component)
{
// the how-many-th
// parameter is this on
// this cell?
const unsigned int local_parameter_dof
= coarse_fe.system_to_component_index(local_dof).second;
global_parameter_representation = 0;
// distribute the representation of
// @p{local_parameter_dof} on the
// parameter grid cell @p{cell} to
// the global data space
coarse_to_fine_grid_map[cell]->
set_dof_values_by_interpolation (parameter_dofs[local_parameter_dof],
global_parameter_representation);
// now that we've got the global
// representation of each parameter
// dof, we've only got to clobber the
// non-zero entries in that vector and
// store the result
//
// what we have learned: if entry @p{i}
// of the global vector holds the value
// @p{v[i]}, then this is the weight with
// which the present dof contributes
// to @p{i}. there may be several such
// @p{i}s and their weights' sum should
// be one. Then, @p{v[i]} should be
// equal to @p{\sum_j w_{ij} p[j]} with
// @p{p[j]} be the values of the degrees
// of freedom on the coarse grid. we
// can thus compute constraints which
// link the degrees of freedom @p{v[i]}
// on the fine grid to those on the
// coarse grid, @p{p[j]}. Now to use
// these as real constraints, rather
// than as additional equations, we
// have to identify representants
// among the @p{i} for each @p{j}. this will
// be done by simply taking the first
// @p{i} for which @p{w_{ij}==1}.
//
// guard modification of
// the weights array by a
// Mutex. since it should
// happen rather rarely
// that there are several
// threads operating on
// different intergrid
// weights, have only one
// mutex for all of them
static Threads::ThreadMutex mutex;
Threads::ThreadMutex::ScopedLock lock (mutex);
for (unsigned int i=0; i<global_parameter_representation.size(); ++i)
// set this weight if it belongs
// to a parameter dof.
if (weight_mapping[i] != -1)
{
// only overwrite old
// value if not by
// zero
if (global_parameter_representation(i) != 0)
{
const unsigned int wi = parameter_dof_indices[local_dof],
wj = weight_mapping[i];
weights[wi][wj] = global_parameter_representation(i);
};
}
else
Assert (global_parameter_representation(i) == 0,
ExcInternalError());
}
}
}
/**
* This is a helper function that
* is used in the computation of
* integrid constraints. See the
* function for a thorough
* description of how it works.
*/
template <int dim, int spacedim>
void
compute_intergrid_weights_2 (
const dealii::DoFHandler<dim,spacedim> &coarse_grid,
const unsigned int coarse_component,
const InterGridMap<dealii::DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
const std::vector<Vector<double> > ¶meter_dofs,
const std::vector<int> &weight_mapping,
std::vector<std::map<unsigned int,float> > &weights)
{
// simply distribute the range of
// cells to different threads
typedef typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator active_cell_iterator;
std::vector<std::pair<active_cell_iterator,active_cell_iterator> >
cell_intervals = Threads::split_range<active_cell_iterator> (coarse_grid.begin_active(),
coarse_grid.end(),
multithread_info.n_default_threads);
Threads::ThreadGroup<> threads;
void (*fun_ptr) (const dealii::DoFHandler<dim,spacedim> &,
const unsigned int ,
const InterGridMap<dealii::DoFHandler<dim,spacedim> > &,
const std::vector<Vector<double> > &,
const std::vector<int> &,
std::vector<std::map<unsigned int, float> > &,
const typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator &,
const typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator &)
= &compute_intergrid_weights_3<dim>;
for (unsigned int i=0; i<multithread_info.n_default_threads; ++i)
threads += Threads::spawn (fun_ptr)(coarse_grid, coarse_component,
coarse_to_fine_grid_map, parameter_dofs,
weight_mapping, weights,
cell_intervals[i].first,
cell_intervals[i].second);
// wait for the threads to finish
threads.join_all ();
}
/**
* This is a helper function that
* is used in the computation of
* integrid constraints. See the
* function for a thorough
* description of how it works.
*/
template <int dim, int spacedim>
unsigned int
compute_intergrid_weights_1 (
const dealii::DoFHandler<dim,spacedim> &coarse_grid,
const unsigned int coarse_component,
const dealii::DoFHandler<dim,spacedim> &fine_grid,
const unsigned int fine_component,
const InterGridMap<dealii::DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
std::vector<std::map<unsigned int, float> > &weights,
std::vector<int> &weight_mapping)
{
// aliases to the finite elements
// used by the dof handlers:
const FiniteElement<dim,spacedim> &coarse_fe = coarse_grid.get_fe(),
&fine_fe = fine_grid.get_fe();
// global numbers of dofs
const unsigned int n_coarse_dofs = coarse_grid.n_dofs(),
n_fine_dofs = fine_grid.n_dofs();
// local numbers of dofs
const unsigned int fine_dofs_per_cell = fine_fe.dofs_per_cell;
// alias the number of dofs per
// cell belonging to the
// coarse_component which is to be
// the restriction of the fine
// grid:
const unsigned int coarse_dofs_per_cell_component
= coarse_fe.base_element(coarse_fe.component_to_base_index(coarse_component).first).dofs_per_cell;
// Try to find out whether the
// grids stem from the same coarse
// grid. This is a rather crude
// test, but better than nothing
Assert (coarse_grid.get_tria().n_cells(0) == fine_grid.get_tria().n_cells(0),
dealii::DoFTools::ExcGridsDontMatch());
// check whether the map correlates
// the right objects
Assert (&coarse_to_fine_grid_map.get_source_grid() == &coarse_grid,
dealii::DoFTools::ExcGridsDontMatch ());
Assert (&coarse_to_fine_grid_map.get_destination_grid() == &fine_grid,
dealii::DoFTools::ExcGridsDontMatch ());
// check whether component numbers
// are valid
Assert (coarse_component < coarse_fe.n_components(),
dealii::DoFTools::ExcInvalidComponent (coarse_component, coarse_fe.n_components()));
Assert (fine_component < fine_fe.n_components(),
dealii::DoFTools::ExcInvalidComponent (fine_component, fine_fe.n_components()));
// check whether respective finite
// elements are equal
Assert (coarse_fe.base_element (coarse_fe.component_to_base_index(coarse_component).first)
==
fine_fe.base_element (fine_fe.component_to_base_index(fine_component).first),
dealii::DoFTools::ExcFiniteElementsDontMatch());
#ifdef DEBUG
// if in debug mode, check whether
// the coarse grid is indeed
// coarser everywhere than the fine
// grid
for (typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator
cell=coarse_grid.begin_active();
cell != coarse_grid.end(); ++cell)
Assert (cell->level() <= coarse_to_fine_grid_map[cell]->level(),
dealii::DoFTools::ExcGridNotCoarser());
#endif
/*
* From here on: the term `parameter' refers to the selected component
* on the coarse grid and its analogon on the fine grid. The naming of
* variables containing this term is due to the fact that
* `selected_component' is longer, but also due to the fact that the
* code of this function was initially written for a program where the
* component which we wanted to match between grids was actually the
* `parameter' variable.
*
* Likewise, the terms `parameter grid' and `state grid' refer to the
* coarse and fine grids, respectively.
*
* Changing the names of variables would in principle be a good idea,
* but would not make things simpler and would be another source of
* errors. If anyone feels like doing so: patches would be welcome!
*/
// set up vectors of cell-local
// data; each vector represents one
// degree of freedom of the
// coarse-grid variable in the
// fine-grid element
std::vector<Vector<double> > parameter_dofs (coarse_dofs_per_cell_component,
Vector<double>(fine_dofs_per_cell));
// for each coarse dof: find its
// position within the fine element
// and set this value to one in the
// respective vector (all other values
// are zero by construction)
for (unsigned int local_coarse_dof=0;
local_coarse_dof<coarse_dofs_per_cell_component;
++local_coarse_dof)
for (unsigned int fine_dof=0; fine_dof<fine_fe.dofs_per_cell; ++fine_dof)
if (fine_fe.system_to_component_index(fine_dof)
==
std::make_pair (fine_component, local_coarse_dof))
{
parameter_dofs[local_coarse_dof](fine_dof) = 1.;
break;
};
// find out how many DoFs there are
// on the grids belonging to the
// components we want to match
unsigned int n_parameters_on_fine_grid=0;
if (true)
{
// have a flag for each dof on
// the fine grid and set it
// to true if this is an
// interesting dof. finally count
// how many true's there
std::vector<bool> dof_is_interesting (fine_grid.n_dofs(), false);
std::vector<unsigned int> local_dof_indices (fine_fe.dofs_per_cell);
for (typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator
cell=fine_grid.begin_active();
cell!=fine_grid.end(); ++cell)
{
cell->get_dof_indices (local_dof_indices);
for (unsigned int i=0; i<fine_fe.dofs_per_cell; ++i)
if (fine_fe.system_to_component_index(i).first == fine_component)
dof_is_interesting[local_dof_indices[i]] = true;
};
n_parameters_on_fine_grid = std::count (dof_is_interesting.begin(),
dof_is_interesting.end(),
true);
};
// set up the weights mapping
weights.clear ();
weights.resize (n_coarse_dofs);
weight_mapping.clear ();
weight_mapping.resize (n_fine_dofs, -1);
if (true)
{
std::vector<unsigned int> local_dof_indices(fine_fe.dofs_per_cell);
unsigned int next_free_index=0;
for (typename dealii::DoFHandler<dim,spacedim>::active_cell_iterator
cell=fine_grid.begin_active();
cell != fine_grid.end(); ++cell)
{
cell->get_dof_indices (local_dof_indices);
for (unsigned int i=0; i<fine_fe.dofs_per_cell; ++i)
// if this DoF is a
// parameter dof and has
// not yet been numbered,
// then do so
if ((fine_fe.system_to_component_index(i).first == fine_component) &&
(weight_mapping[local_dof_indices[i]] == -1))
{
weight_mapping[local_dof_indices[i]] = next_free_index;
++next_free_index;
};
};
Assert (next_free_index == n_parameters_on_fine_grid,
ExcInternalError());
};
// for each cell on the parameter grid:
// find out which degrees of freedom on the
// fine grid correspond in which way to
// the degrees of freedom on the parameter
// grid
//
// do this in a separate function
// to allow for multithreading
// there. see this function also if
// you want to read more
// information on the algorithm
// used.
compute_intergrid_weights_2 (coarse_grid, coarse_component,
coarse_to_fine_grid_map, parameter_dofs,
weight_mapping, weights);
// ok, now we have all weights for each
// dof on the fine grid. if in debug
// mode lets see if everything went smooth,
// i.e. each dof has sum of weights one
//
// in other words this means that
// if the sum of all shape
// functions on the parameter grid
// is one (which is always the
// case), then the representation
// on the state grid should be as
// well (division of unity)
//
// if the parameter grid has more
// than one component, then the
// respective dofs of the other
// components have sum of weights
// zero, of course. we do not
// explicitly ask which component
// a dof belongs to, but this at
// least tests some errors
#ifdef DEBUG
for (unsigned int col=0; col<n_parameters_on_fine_grid; ++col)
{
double sum=0;
for (unsigned int row=0; row<n_coarse_dofs; ++row)
if (weights[row].find(col) != weights[row].end())
sum += weights[row][col];
Assert ((std::fabs(sum-1) < 1.e-12) ||
((coarse_fe.n_components()>1) && (sum==0)), ExcInternalError());
};
#endif
return n_parameters_on_fine_grid;
}
}
}
template <int dim, int spacedim>
void
DoFTools::compute_intergrid_constraints (
const DoFHandler<dim,spacedim> &coarse_grid,
const unsigned int coarse_component,
const DoFHandler<dim,spacedim> &fine_grid,
const unsigned int fine_component,
const InterGridMap<DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
ConstraintMatrix &constraints)
{
// store the weights with which a dof
// on the parameter grid contributes
// to a dof on the fine grid. see the
// long doc below for more info
//
// allocate as many rows as there are
// parameter dofs on the coarse grid
// and as many columns as there are
// parameter dofs on the fine grid.
//
// weight_mapping is used to map the
// global (fine grid) parameter dof
// indices to the columns
//
// in the original implementation,
// the weights array was actually
// of FullMatrix<double> type. this
// wasted huge amounts of memory,
// but was fast. nonetheless, since
// the memory consumption was
// quadratic in the number of
// degrees of freedom, this was not
// very practical, so we now use a
// vector of rows of the matrix,
// and in each row a vector of
// pairs (colnum,value). this seems
// like the best tradeoff between
// memory and speed, as it is now
// linear in memory and still fast
// enough.
//
// to save some memory and since
// the weights are usually
// (negative) powers of 2, we
// choose the value type of the
// matrix to be @p{float} rather
// than @p{double}.
std::vector<std::map<unsigned int, float> > weights;
// this is this mapping. there is one
// entry for each dof on the fine grid;
// if it is a parameter dof, then its
// value is the column in weights for
// that parameter dof, if it is any
// other dof, then its value is -1,
// indicating an error
std::vector<int> weight_mapping;
const unsigned int n_parameters_on_fine_grid
= internal::compute_intergrid_weights_1 (coarse_grid, coarse_component,
fine_grid, fine_component,
coarse_to_fine_grid_map,
weights, weight_mapping);
// global numbers of dofs
const unsigned int n_coarse_dofs = coarse_grid.n_dofs(),
n_fine_dofs = fine_grid.n_dofs();
// get an array in which we store
// which dof on the coarse grid is
// a parameter and which is not
std::vector<bool> coarse_dof_is_parameter (coarse_grid.n_dofs());
if (true)
{
std::vector<bool> mask (coarse_grid.get_fe().n_components(),
false);
mask[coarse_component] = true;
extract_dofs (coarse_grid, mask, coarse_dof_is_parameter);
};
// now we know that the weights in
// each row constitute a
// constraint. enter this into the
// constraints object
//
// first task: for each parameter
// dof on the parameter grid, find
// a representant on the fine,
// global grid. this is possible
// since we use conforming finite
// element. we take this
// representant to be the first
// element in this row with weight
// identical to one. the
// representant will become an
// unconstrained degree of freedom,
// while all others will be
// constrained to this dof (and
// possibly others)
std::vector<int> representants(n_coarse_dofs, -1);
for (unsigned int parameter_dof=0; parameter_dof<n_coarse_dofs;
++parameter_dof)
if (coarse_dof_is_parameter[parameter_dof] == true)
{
// if this is the line of a
// parameter dof on the
// coarse grid, then it
// should have at least one
// dependent node on the fine
// grid
Assert (weights[parameter_dof].size() > 0, ExcInternalError());
// find the column where the
// representant is mentioned
std::map<unsigned int,float>::const_iterator i = weights[parameter_dof].begin();
for (; i!=weights[parameter_dof].end(); ++i)
if (i->second == 1)
break;
Assert (i!=weights[parameter_dof].end(), ExcInternalError());
const unsigned int column = i->first;
// now we know in which column of
// weights the representant is, but
// we don't know its global index. get
// it using the inverse operation of
// the weight_mapping
unsigned int global_dof=0;
for (; global_dof<weight_mapping.size(); ++global_dof)
if (weight_mapping[global_dof] == static_cast<int>(column))
break;
Assert (global_dof < weight_mapping.size(), ExcInternalError());
// now enter the representants global
// index into our list
representants[parameter_dof] = global_dof;
}
else
{
// consistency check: if this
// is no parameter dof on the
// coarse grid, then the
// respective row must be
// empty!
Assert (weights[parameter_dof].size() == 0, ExcInternalError());
};
// note for people that want to
// optimize this function: the
// largest part of the computing
// time is spent in the following,
// rather innocent block of
// code. basically, it must be the
// ConstraintMatrix::add_entry call
// which takes the bulk of the
// time, but it is not known to the
// author how to make it faster...
std::vector<std::pair<unsigned int,double> > constraint_line;
for (unsigned int global_dof=0; global_dof<n_fine_dofs; ++global_dof)
if (weight_mapping[global_dof] != -1)
// this global dof is a parameter
// dof, so it may carry a constraint
// note that for each global dof,
// the sum of weights shall be one,
// so we can find out whether this
// dof is constrained in the following
// way: if the only weight in this row
// is a one, and the representant for
// the parameter dof of the line in
// which this one is is the present
// dof, then we consider this dof
// to be unconstrained. otherwise,
// all other dofs are constrained
{
const unsigned int col = weight_mapping[global_dof];
Assert (col < n_parameters_on_fine_grid, ExcInternalError());
unsigned int first_used_row=0;
{
Assert (weights.size() > 0, ExcInternalError());
std::map<unsigned int,float>::const_iterator
col_entry = weights[0].end();
for (; first_used_row<n_coarse_dofs; ++first_used_row)
{
col_entry = weights[first_used_row].find(col);
if (col_entry != weights[first_used_row].end())
break;
}
Assert (col_entry != weights[first_used_row].end(), ExcInternalError());
if ((col_entry->second == 1) &&
(representants[first_used_row] == static_cast<int>(global_dof)))
// dof unconstrained or
// constrained to itself
// (in case this cell is
// mapped to itself, rather
// than to children of
// itself)
continue;
}
// otherwise enter all constraints
constraints.add_line (global_dof);
constraint_line.clear ();
for (unsigned int row=first_used_row; row<n_coarse_dofs; ++row)
{
const std::map<unsigned int,float>::const_iterator
j = weights[row].find(col);
if ((j != weights[row].end()) && (j->second != 0))
constraint_line.push_back (std::make_pair(representants[row],
j->second));
};
constraints.add_entries (global_dof, constraint_line);
};
}
template <int dim, int spacedim>
void
DoFTools::
compute_intergrid_transfer_representation (
const DoFHandler<dim,spacedim> &coarse_grid,
const unsigned int coarse_component,
const DoFHandler<dim,spacedim> &fine_grid,
const unsigned int fine_component,
const InterGridMap<DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
std::vector<std::map<unsigned int, float> > &transfer_representation)
{
// store the weights with which a dof
// on the parameter grid contributes
// to a dof on the fine grid. see the
// long doc below for more info
//
// allocate as many rows as there are
// parameter dofs on the coarse grid
// and as many columns as there are
// parameter dofs on the fine grid.
//
// weight_mapping is used to map the
// global (fine grid) parameter dof
// indices to the columns
//
// in the original implementation,
// the weights array was actually
// of FullMatrix<double> type. this
// wasted huge amounts of memory,
// but was fast. nonetheless, since
// the memory consumption was
// quadratic in the number of
// degrees of freedom, this was not
// very practical, so we now use a
// vector of rows of the matrix,
// and in each row a vector of
// pairs (colnum,value). this seems
// like the best tradeoff between
// memory and speed, as it is now
// linear in memory and still fast
// enough.
//
// to save some memory and since
// the weights are usually
// (negative) powers of 2, we
// choose the value type of the
// matrix to be @p{float} rather
// than @p{double}.
std::vector<std::map<unsigned int, float> > weights;
// this is this mapping. there is one
// entry for each dof on the fine grid;
// if it is a parameter dof, then its
// value is the column in weights for
// that parameter dof, if it is any
// other dof, then its value is -1,
// indicating an error
std::vector<int> weight_mapping;
internal::compute_intergrid_weights_1 (coarse_grid, coarse_component,
fine_grid, fine_component,
coarse_to_fine_grid_map,
weights, weight_mapping);
// now compute the requested
// representation
const unsigned int n_global_parm_dofs
= std::count_if (weight_mapping.begin(), weight_mapping.end(),
std::bind2nd (std::not_equal_to<int> (), -1));
// first construct the inverse
// mapping of weight_mapping
std::vector<unsigned int> inverse_weight_mapping (n_global_parm_dofs,
DoFHandler<dim,spacedim>::invalid_dof_index);
for (unsigned int i=0; i<weight_mapping.size(); ++i)
{
const unsigned int parameter_dof = weight_mapping[i];
// if this global dof is a
// parameter
if (parameter_dof != numbers::invalid_unsigned_int)
{
Assert (parameter_dof < n_global_parm_dofs, ExcInternalError());
Assert ((inverse_weight_mapping[parameter_dof] == DoFHandler<dim,spacedim>::invalid_dof_index),
ExcInternalError());
inverse_weight_mapping[parameter_dof] = i;
};
};
// next copy over weights array
// and replace respective
// numbers
const unsigned int n_rows = weight_mapping.size();
transfer_representation.clear ();
transfer_representation.resize (n_rows);
const unsigned int n_coarse_dofs = coarse_grid.n_dofs();
for (unsigned int i=0; i<n_coarse_dofs; ++i)
{
std::map<unsigned int, float>::const_iterator j = weights[i].begin();
for (; j!=weights[i].end(); ++j)
{
const unsigned int p = inverse_weight_mapping[j->first];
Assert (p<n_rows, ExcInternalError());
transfer_representation[p][i] = j->second;
};
};
}
#if deal_II_dimension == 1
template <class DH>
void DoFTools::map_dof_to_boundary_indices (
const DH &dof_handler,
const std::set<unsigned char> &boundary_indicators,
std::vector<unsigned int> &mapping)
{
Assert (&dof_handler.get_fe() != 0, ExcNoFESelected());
mapping.clear ();
mapping.insert (mapping.end(), dof_handler.n_dofs(),
DH::invalid_dof_index);
unsigned int next_free_index = 0;
// first check left, the right
// boundary point
for (unsigned int direction=0; direction<2; ++direction)
{
// if this boundary is not
// requested, then go on with next one
if (boundary_indicators.find(direction) ==
boundary_indicators.end())
continue;
// find active cell at that
// boundary: first go to
// left/right, then to children
typename DH::cell_iterator cell = dof_handler.begin(0);
while (!cell->at_boundary(direction))
cell = cell->neighbor(direction);
while (!cell->active())
cell = cell->child(direction);
// next enumerate these degrees
// of freedom
for (unsigned int i=0; i<cell->get_fe().dofs_per_vertex; ++i)
mapping[cell->vertex_dof_index(direction,i)] = next_free_index++;
};
}
template <>
void
DoFTools::map_dof_to_boundary_indices (const DoFHandler<1> &dof_handler,
std::vector<unsigned int> &mapping)
{
Assert (&dof_handler.get_fe() != 0, ExcNoFESelected());
// in 1d, there are only 2 boundary
// indicators, so enumerate them
// and pass on to the other
// function
std::set<unsigned char> boundary_indicators;
boundary_indicators.insert (0U);
boundary_indicators.insert (1U);
map_dof_to_boundary_indices<DoFHandler<1> > (dof_handler, boundary_indicators, mapping);
}
#else
template <class DH>
void
DoFTools::map_dof_to_boundary_indices (const DH &dof_handler,
std::vector<unsigned int> &mapping)
{
Assert (&dof_handler.get_fe() != 0, ExcNoFESelected());
mapping.clear ();
mapping.insert (mapping.end(), dof_handler.n_dofs(),
DH::invalid_dof_index);
std::vector<unsigned int> dofs_on_face;
dofs_on_face.reserve (max_dofs_per_face(dof_handler));
unsigned int next_boundary_index = 0;
// now loop over all cells and
// check whether their faces are at
// the boundary. note that we need
// not take special care of single
// lines being at the boundary
// (using
// @p{cell->has_boundary_lines}),
// since we do not support
// boundaries of dimension dim-2,
// and so every isolated boundary
// line is also part of a boundary
// face which we will be visiting
// sooner or later
typename DH::active_cell_iterator cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int f=0; f<GeometryInfo<DH::dimension>::faces_per_cell; ++f)
if (cell->at_boundary(f))
{
const unsigned int dofs_per_face = cell->get_fe().dofs_per_face;
dofs_on_face.resize (dofs_per_face);
cell->face(f)->get_dof_indices (dofs_on_face,
cell->active_fe_index());
for (unsigned int i=0; i<dofs_per_face; ++i)
if (mapping[dofs_on_face[i]] == DH::invalid_dof_index)
mapping[dofs_on_face[i]] = next_boundary_index++;
}
AssertDimension (next_boundary_index, dof_handler.n_boundary_dofs());
}
template <class DH>
void DoFTools::map_dof_to_boundary_indices (
const DH &dof_handler,
const std::set<unsigned char> &boundary_indicators,
std::vector<unsigned int> &mapping)
{
Assert (&dof_handler.get_fe() != 0, ExcNoFESelected());
Assert (boundary_indicators.find (255) == boundary_indicators.end(),
ExcInvalidBoundaryIndicator());
mapping.clear ();
mapping.insert (mapping.end(), dof_handler.n_dofs(),
DH::invalid_dof_index);
// return if there is nothing to do
if (boundary_indicators.size() == 0)
return;
std::vector<unsigned int> dofs_on_face;
dofs_on_face.reserve (max_dofs_per_face(dof_handler));
unsigned int next_boundary_index = 0;
typename DH::active_cell_iterator cell = dof_handler.begin_active(),
endc = dof_handler.end();
for (; cell!=endc; ++cell)
for (unsigned int f=0; f<GeometryInfo<DH::dimension>::faces_per_cell; ++f)
if (boundary_indicators.find (cell->face(f)->boundary_indicator()) !=
boundary_indicators.end())
{
const unsigned int dofs_per_face = cell->get_fe().dofs_per_face;
dofs_on_face.resize (dofs_per_face);
cell->face(f)->get_dof_indices (dofs_on_face, cell->active_fe_index());
for (unsigned int i=0; i<dofs_per_face; ++i)
if (mapping[dofs_on_face[i]] == DH::invalid_dof_index)
mapping[dofs_on_face[i]] = next_boundary_index++;
}
AssertDimension (next_boundary_index, dof_handler.n_boundary_dofs (boundary_indicators));
}
#endif
template <int dim, int spacedim>
void
DoFTools::map_dofs_to_support_points (const Mapping<dim,spacedim> &mapping,
const DoFHandler<dim,spacedim> &dof_handler,
std::vector<Point<spacedim> > &support_points)
{
const unsigned int dofs_per_cell = dof_handler.get_fe().dofs_per_cell;
// check whether fe has support
// points
Assert (dof_handler.get_fe().has_support_points(),
ExcFEHasNoSupportPoints());
Assert (support_points.size() == dof_handler.n_dofs(),
ExcWrongSize (support_points.size(), dof_handler.n_dofs()));
// now loop over all cells and
// enquire the support points on
// each of these. use a dummy
// quadrature formula where the
// quadrature points are located at
// the unit support points to
// enquire the location of the
// support points in real space
//
// the weights of the quadrature
// rule are set to invalid values
// by the used constructor.
Quadrature<dim> q_dummy(dof_handler.get_fe().get_unit_support_points());
FEValues<dim,spacedim> fe_values (mapping, dof_handler.get_fe(),
q_dummy, update_quadrature_points);
typename DoFHandler<dim,spacedim>::active_cell_iterator
cell = dof_handler.begin_active(),
endc = dof_handler.end();
std::vector<unsigned int> local_dof_indices (dofs_per_cell);
for (; cell!=endc; ++cell)
{
fe_values.reinit (cell);
cell->get_dof_indices (local_dof_indices);
const std::vector<Point<spacedim> > & points
= fe_values.get_quadrature_points ();
for (unsigned int i=0; i<dofs_per_cell; ++i)
support_points[local_dof_indices[i]] = points[i];
};
}
template<int dim, int spacedim>
void
DoFTools::convert_couplings_to_blocks (
const DoFHandler<dim,spacedim>& dof_handler,
const Table<2, Coupling>& table,
std::vector<Table<2,Coupling> >& tables_by_block)
{
const FiniteElement<dim,spacedim>& fe = dof_handler.get_fe();
const unsigned int nb = fe.n_blocks();
tables_by_block.resize(1);
tables_by_block[0].reinit(nb, nb);
tables_by_block[0].fill(none);
for (unsigned int i=0;i<fe.n_components();++i)
{
const unsigned int ib = fe.component_to_block_index(i);
for (unsigned int j=0;j<fe.n_components();++j)
{
const unsigned int jb = fe.component_to_block_index(j);
tables_by_block[0](ib,jb) |= table(i,j);
}
}
}
template<int dim, int spacedim>
void
DoFTools::convert_couplings_to_blocks (
const hp::DoFHandler<dim,spacedim>& dof_handler,
const Table<2, Coupling>& table,
std::vector<Table<2,Coupling> >& tables_by_block)
{
const hp::FECollection<dim>& fe_collection = dof_handler.get_fe();
tables_by_block.resize(fe_collection.size());
for (unsigned int f=0;f<fe_collection.size();++f)
{
const FiniteElement<dim,spacedim>& fe = fe_collection[f];
const unsigned int nb = fe.n_blocks();
tables_by_block[f].reinit(nb, nb);
tables_by_block[f].fill(none);
for (unsigned int i=0;i<fe.n_components();++i)
{
const unsigned int ib = fe.component_to_block_index(i);
for (unsigned int j=0;j<fe.n_components();++j)
{
const unsigned int jb = fe.component_to_block_index(j);
tables_by_block[f](ib,jb) |= table(i,j);
}
}
}
}
#if deal_II_dimension == 1
template <int dim, int spacedim, template <int,int> class DH>
void
DoFTools::make_zero_boundary_constraints (const DH<dim, spacedim> &dof,
ConstraintMatrix &zero_boundary_constraints,
const std::vector<bool> &component_mask_)
{
Assert ((component_mask_.size() == 0) ||
(component_mask_.size() == dof.get_fe().n_components()),
ExcMessage ("The number of components in the mask has to be either "
"zero or equal to the number of components in the finite "
"element."));
// check for boundary cells in both
// directions to secure indicators
// for the entire boundary, i.e. 0
// is left boundary and 1 is right
// boundary
for (unsigned int direction = 0; direction < 2; ++direction)
{
// first find the outermost active
// cell by traversing the coarse
// grid to its end and then looking
// for the children
typename DH<dim,spacedim>::cell_iterator outermost_cell = dof.begin(0);
while (outermost_cell->neighbor(direction).state() == IteratorState::valid)
outermost_cell = outermost_cell->neighbor(direction);
while (outermost_cell->has_children())
outermost_cell = outermost_cell->child(direction);
// then get the FE corresponding to
// this cell
const FiniteElement<dim,spacedim> &fe = outermost_cell->get_fe();
// set the component mask to either
// the original value or a vector
// of trues
const std::vector<bool> component_mask ((component_mask_.size() == 0) ?
std::vector<bool> (fe.n_components(), true) :
component_mask_);
Assert (std::count(component_mask.begin(), component_mask.end(), true) > 0,
VectorTools::ExcNoComponentSelected());
// cast zero boundary constraints
// onto a matrix if component_mask
// == true
for (unsigned int i=0; i<fe.dofs_per_vertex; ++i)
if (component_mask[fe.face_system_to_component_index(i).first])
zero_boundary_constraints.add_line (outermost_cell->vertex_dof_index (direction, i));
}
}
#else
template <int dim, int spacedim, template <int,int> class DH>
void
DoFTools::make_zero_boundary_constraints (const DH<dim, spacedim> &dof,
ConstraintMatrix &zero_boundary_constraints,
const std::vector<bool> &component_mask_)
{
Assert ((component_mask_.size() == 0) ||
(component_mask_.size() == dof.get_fe().n_components()),
ExcMessage ("The number of components in the mask has to be either "
"zero or equal to the number of components in the finite "
"element."));
const unsigned int n_components = DoFTools::n_components(dof);
const bool fe_is_system = (n_components != 1);
// set the component mask to either
// the original value or a vector
// of trues
const std::vector<bool> component_mask ((component_mask_.size() == 0) ?
std::vector<bool> (n_components, true) :
component_mask_);
Assert (std::count(component_mask.begin(), component_mask.end(), true) > 0,
VectorTools::ExcNoComponentSelected());
// a field to store the indices
std::vector<unsigned int> face_dofs;
face_dofs.reserve (DoFTools::max_dofs_per_face(dof));
typename DH<dim,spacedim>::active_cell_iterator
cell = dof.begin_active(),
endc = dof.end();
for (; cell!=endc; ++cell)
for (unsigned int face_no = 0; face_no < GeometryInfo<dim>::faces_per_cell;
++face_no)
{
const FiniteElement<dim,spacedim> &fe = cell->get_fe();
// we can presently deal only with
// primitive elements for boundary
// values. make sure that all shape
// functions that are non-zero for
// the components we are interested
// in, are in fact primitive
for (unsigned int i=0; i<cell->get_fe().dofs_per_cell; ++i)
{
const std::vector<bool> &nonzero_component_array
= cell->get_fe().get_nonzero_components (i);
for (unsigned int c=0; c<n_components; ++c)
if ((nonzero_component_array[c] == true)
&&
(component_mask[c] == true))
Assert (cell->get_fe().is_primitive (i),
ExcMessage ("This function can only deal with requested boundary "
"values that correspond to primitive (scalar) base "
"elements"));
}
typename DH<dim,spacedim>::face_iterator face = cell->face(face_no);
if (face->boundary_indicator () == 0)
// face is of the right component
{
// get indices and physical
// location on this face
face_dofs.resize (fe.dofs_per_face);
face->get_dof_indices (face_dofs, cell->active_fe_index());
if (fe_is_system)
{
// enter those dofs into the list
// that match the component
// signature.
for (unsigned int i=0; i<face_dofs.size(); ++i)
{
unsigned int component;
if (fe.is_primitive())
component = fe.face_system_to_component_index(i).first;
else
{
// non-primitive case. make sure
// that this particular shape
// function _is_ primitive, and
// get at it's component. use
// usual trick to transfer face
// dof index to cell dof index
const unsigned int cell_i
= (dim == 1 ?
i
:
(dim == 2 ?
(i<2*fe.dofs_per_vertex ? i : i+2*fe.dofs_per_vertex)
:
(dim == 3 ?
(i<4*fe.dofs_per_vertex ?
i
:
(i<4*fe.dofs_per_vertex+4*fe.dofs_per_line ?
i+4*fe.dofs_per_vertex
:
i+4*fe.dofs_per_vertex+8*fe.dofs_per_line))
:
numbers::invalid_unsigned_int)));
Assert (cell_i < fe.dofs_per_cell, ExcInternalError());
// make sure that if this is not a
// primitive shape function, then
// all the corresponding
// components in the mask are not
// set
if (!fe.is_primitive(cell_i))
for (unsigned int c=0; c<n_components; ++c)
if (fe.get_nonzero_components(cell_i)[c])
Assert (component_mask[c] == false,
FETools::ExcFENotPrimitive());
// pick the first possibly of more
// than one non-zero component. if
// the shape function is
// non-primitive, then we will
// ignore the result in the
// following anyway, otherwise
// there's only one non-zero
// component which we will use
component = (std::find (fe.get_nonzero_components(cell_i).begin(),
fe.get_nonzero_components(cell_i).end(),
true)
-
fe.get_nonzero_components(cell_i).begin());
}
// cast zero boundary constraints onto
// a matrix
for (unsigned int i=0; i<fe.dofs_per_vertex; ++i)
if (component_mask[fe.face_system_to_component_index(i).first])
zero_boundary_constraints.add_line (face_dofs[i]);
}
}
else
{
// get the one component that this
// function has and cast zero
// boundary constraints onto a
// matrix
for (unsigned int i=0; i<fe.dofs_per_face; ++i)
if (component_mask[fe.face_system_to_component_index(i).first])
zero_boundary_constraints.add_line (face_dofs[i]);
}
}
}
}
#endif
// explicit instantiations
#include "../dofs/dof_tools.inst"
// #if deal_II_dimension > 1
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,SparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
SparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,CompressedSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
CompressedSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,CompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
CompressedSetSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,CompressedSimpleSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
CompressedSimpleSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockCompressedSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockCompressedSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockCompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockCompressedSetSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockCompressedSimpleSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockCompressedSimpleSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,SparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
SparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,CompressedSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
CompressedSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,CompressedSetSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
CompressedSetSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,CompressedSimpleSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
CompressedSimpleSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockCompressedSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockCompressedSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockCompressedSetSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockCompressedSetSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockCompressedSimpleSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const std::vector<unsigned int> &,
BlockCompressedSimpleSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,SparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,CompressedSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,CompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSetSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,CompressedSimpleSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSimpleSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockCompressedSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockCompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSetSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension>,BlockCompressedSimpleSparsityPattern>
(const DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSimpleSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,SparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,CompressedSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,CompressedSetSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSetSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,CompressedSimpleSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSimpleSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockCompressedSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockCompressedSetSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSetSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension>,BlockCompressedSimpleSparsityPattern>
(const hp::DoFHandler<deal_II_dimension>& dof,
const FunctionMap<deal_II_dimension>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSimpleSparsityPattern &sparsity);
template
void
DoFTools::distribute_cell_to_dof_vector<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &dof_handler,
const Vector<float> &cell_data,
Vector<double> &dof_data,
const unsigned int component);
template
void
DoFTools::distribute_cell_to_dof_vector<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &dof_handler,
const Vector<double> &cell_data,
Vector<double> &dof_data,
const unsigned int component);
template
void
DoFTools::distribute_cell_to_dof_vector<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &dof_handler,
const Vector<float> &cell_data,
Vector<double> &dof_data,
const unsigned int component);
template
void
DoFTools::distribute_cell_to_dof_vector<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &dof_handler,
const Vector<double> &cell_data,
Vector<double> &dof_data,
const unsigned int component);
template void DoFTools::extract_dofs<deal_II_dimension>
(const DoFHandler<deal_II_dimension>&,
const std::vector<bool>&, std::vector<bool>&, bool);
template void DoFTools::extract_dofs<deal_II_dimension>
(const hp::DoFHandler<deal_II_dimension>&,
const std::vector<bool>&, std::vector<bool>&, bool);
template void DoFTools::extract_level_dofs<deal_II_dimension>
(const unsigned int level, const MGDoFHandler<deal_II_dimension>&,
const std::vector<bool>&, std::vector<bool>&, bool);
template
void
DoFTools::extract_boundary_dofs<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &,
const std::vector<bool> &,
std::vector<bool> &,
const std::set<unsigned char> &);
template
void
DoFTools::extract_boundary_dofs<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &,
const std::vector<bool> &,
std::vector<bool> &,
const std::set<unsigned char> &);
template
void
DoFTools::extract_hanging_node_dofs
(const DoFHandler<deal_II_dimension> &dof_handler,
std::vector<bool> &selected_dofs);
template
void
DoFTools::extract_subdomain_dofs<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &dof_handler,
const unsigned int subdomain_id,
std::vector<bool> &selected_dofs);
template
void
DoFTools::extract_subdomain_dofs<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &dof_handler,
const unsigned int subdomain_id,
std::vector<bool> &selected_dofs);
template
void
DoFTools::extract_constant_modes<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &dof_handler,
const std::vector<bool> &selected_components,
std::vector<std::vector<bool> > &constant_modes);
template
void
DoFTools::get_active_fe_indices<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &dof_handler,
std::vector<unsigned int> &active_fe_indices);
template
void
DoFTools::get_active_fe_indices<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &dof_handler,
std::vector<unsigned int> &active_fe_indices);
template
void
DoFTools::get_subdomain_association<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &dof_handler,
std::vector<unsigned int> &subdomain_association);
template
void
DoFTools::get_subdomain_association<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &dof_handler,
std::vector<unsigned int> &subdomain_association);
template
unsigned int
DoFTools::count_dofs_with_subdomain_association<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &,
const unsigned int);
template
void
DoFTools::count_dofs_with_subdomain_association<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &,
const unsigned int,
std::vector<unsigned int> &);
template
unsigned int
DoFTools::count_dofs_with_subdomain_association<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &,
const unsigned int);
template
void
DoFTools::count_dofs_with_subdomain_association<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &,
const unsigned int,
std::vector<unsigned int> &);
template
unsigned int
DoFTools::count_dofs_with_subdomain_association<MGDoFHandler<deal_II_dimension> >
(const MGDoFHandler<deal_II_dimension> &,
const unsigned int);
template
void
DoFTools::count_dofs_with_subdomain_association<MGDoFHandler<deal_II_dimension> >
(const MGDoFHandler<deal_II_dimension> &,
const unsigned int,
std::vector<unsigned int> &);
template
void
DoFTools::count_dofs_per_component<deal_II_dimension> (
const DoFHandler<deal_II_dimension>&,
std::vector<unsigned int>&, bool, std::vector<unsigned int>);
template
void
DoFTools::count_dofs_per_block<deal_II_dimension> (
const DoFHandler<deal_II_dimension>&,
std::vector<unsigned int>&, std::vector<unsigned int>);
template
void
DoFTools::count_dofs_per_component<deal_II_dimension> (
const DoFHandler<deal_II_dimension>&,
std::vector<unsigned int>&, std::vector<unsigned int>);
template
void
DoFTools::compute_intergrid_constraints<deal_II_dimension> (
const DoFHandler<deal_II_dimension> &, const unsigned int,
const DoFHandler<deal_II_dimension> &, const unsigned int,
const InterGridMap<DoFHandler<deal_II_dimension> > &,
ConstraintMatrix&);
template
void
DoFTools::compute_intergrid_transfer_representation<deal_II_dimension>
(const DoFHandler<deal_II_dimension> &, const unsigned int,
const DoFHandler<deal_II_dimension> &, const unsigned int,
const InterGridMap<DoFHandler<deal_II_dimension> > &,
std::vector<std::map<unsigned int, float> > &);
template
void
DoFTools::map_dof_to_boundary_indices<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &,
const std::set<unsigned char> &,
std::vector<unsigned int> &);
#if deal_II_dimension != 1
template
void
DoFTools::map_dof_to_boundary_indices<DoFHandler<deal_II_dimension> >
(const DoFHandler<deal_II_dimension> &,
std::vector<unsigned int> &);
#endif
template
void
DoFTools::map_dof_to_boundary_indices<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &,
const std::set<unsigned char> &,
std::vector<unsigned int> &);
#if deal_II_dimension != 1
template
void
DoFTools::map_dof_to_boundary_indices<hp::DoFHandler<deal_II_dimension> >
(const hp::DoFHandler<deal_II_dimension> &,
std::vector<unsigned int> &);
#endif
template
void
DoFTools::map_dofs_to_support_points<deal_II_dimension>
(const Mapping<deal_II_dimension,deal_II_dimension>&,
const DoFHandler<deal_II_dimension>&,
std::vector<Point<deal_II_dimension> >&);
#if deal_II_dimension != 3
template
void
DoFTools::map_dofs_to_support_points<deal_II_dimension,deal_II_dimension+1>
(const Mapping<deal_II_dimension,deal_II_dimension+1>&,
const DoFHandler<deal_II_dimension, deal_II_dimension+1>&,
std::vector<Point<deal_II_dimension+1> >&);
#endif
template
void
DoFTools::convert_couplings_to_blocks (
const DoFHandler<deal_II_dimension>&, const Table<2, Coupling>&,
std::vector<Table<2,Coupling> >&);
template
void
DoFTools::convert_couplings_to_blocks (
const hp::DoFHandler<deal_II_dimension>&, const Table<2, Coupling>&,
std::vector<Table<2,Coupling> >&);
template
void
DoFTools::make_zero_boundary_constraints
(const DoFHandler<deal_II_dimension> &,
ConstraintMatrix &,
const std::vector<bool> &);
template
void
DoFTools::make_zero_boundary_constraints
(const hp::DoFHandler<deal_II_dimension> &,
ConstraintMatrix &,
const std::vector<bool> &);
#if deal_II_dimension < 3
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,SparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const std::vector<unsigned int> &,
SparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const std::vector<unsigned int> &,
CompressedSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const std::vector<unsigned int> &,
CompressedSetSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const std::vector<unsigned int> &,
BlockSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const std::vector<unsigned int> &,
BlockCompressedSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const std::vector<unsigned int> &,
BlockCompressedSetSparsityPattern &);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,SparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const std::vector<unsigned int> &,
// SparsityPattern &);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const std::vector<unsigned int> &,
// CompressedSparsityPattern &);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSetSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const std::vector<unsigned int> &,
// CompressedSetSparsityPattern &);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const std::vector<unsigned int> &,
// BlockSparsityPattern &);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const std::vector<unsigned int> &,
// BlockCompressedSparsityPattern &);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSetSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const std::vector<unsigned int> &,
// BlockCompressedSetSparsityPattern &);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,SparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
SparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
CompressedSetSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSparsityPattern &sparsity);
template void
DoFTools::make_boundary_sparsity_pattern<DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSetSparsityPattern>
(const DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
const std::vector<unsigned int> &dof_to_boundary_mapping,
BlockCompressedSetSparsityPattern &sparsity);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,SparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
// const std::vector<unsigned int> &dof_to_boundary_mapping,
// SparsityPattern &sparsity);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
// const std::vector<unsigned int> &dof_to_boundary_mapping,
// CompressedSparsityPattern &sparsity);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,CompressedSetSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
// const std::vector<unsigned int> &dof_to_boundary_mapping,
// CompressedSetSparsityPattern &sparsity);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
// const std::vector<unsigned int> &dof_to_boundary_mapping,
// BlockSparsityPattern &sparsity);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
// const std::vector<unsigned int> &dof_to_boundary_mapping,
// BlockCompressedSparsityPattern &sparsity);
// template void
// DoFTools::make_boundary_sparsity_pattern<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>,BlockCompressedSetSparsityPattern>
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1>& dof,
// const FunctionMap<deal_II_dimension+1>::type &boundary_indicators,
// const std::vector<unsigned int> &dof_to_boundary_mapping,
// BlockCompressedSetSparsityPattern &sparsity);
template
void
DoFTools::map_dof_to_boundary_indices<DoFHandler<deal_II_dimension,deal_II_dimension+1> >
(const DoFHandler<deal_II_dimension,deal_II_dimension+1> &,
const std::set<unsigned char> &,
std::vector<unsigned int> &);
#if deal_II_dimension != 1
template
void
DoFTools::map_dof_to_boundary_indices<DoFHandler<deal_II_dimension,deal_II_dimension+1> >
(const DoFHandler<deal_II_dimension,deal_II_dimension+1> &,
std::vector<unsigned int> &);
#endif
template
void
DoFTools::extract_hanging_node_dofs
(const DoFHandler<deal_II_dimension,deal_II_dimension+1> &dof_handler,
std::vector<bool> &selected_dofs);
// template
// void
// DoFTools::map_dof_to_boundary_indices<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1> >
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1> &,
// const std::set<unsigned char> &,
// std::vector<unsigned int> &);
// #if deal_II_dimension != 1
// template
// void
// DoFTools::map_dof_to_boundary_indices<hp::DoFHandler<deal_II_dimension,deal_II_dimension+1> >
// (const hp::DoFHandler<deal_II_dimension,deal_II_dimension+1> &,
// std::vector<unsigned int> &);
// #endif
#endif
DEAL_II_NAMESPACE_CLOSE
| [
"abelardojarab@gmail.com"
] | abelardojarab@gmail.com |
9869f3077175be9878a92c4a3f56c938efcdc0c2 | 81daa915e21dec0e9f625f106465a8b31f803f22 | /Code_Windows_VisualStudio2017/FreedomFighter/FreedomFighter/Enemy_Easy.h | cbcc9d9d4da54efe39019dbabb4c1f2dec59685d | [] | no_license | FarjadAhmed/FreedomFighter-2DGame-SDL2.0 | 8a811d42711360f550ecd25d86b10f6d277c9c6b | 73e07eb4cb42c6c6485c982240777ee7d23b8644 | refs/heads/master | 2022-11-06T19:55:53.965326 | 2020-06-15T18:27:18 | 2020-06-15T18:27:18 | 276,013,059 | 0 | 0 | null | 2020-06-30T06:09:29 | 2020-06-30T06:09:28 | null | UTF-8 | C++ | false | false | 286 | h | #pragma once
#include"Unit.h"
class Enemy_Easy:public Unit
{
public:
Enemy_Easy(LTexture* image, float x, float y);
Enemy_Easy();
virtual ~Enemy_Easy();
virtual void Move(int playerX, int PlayerY);
virtual void Render(long int& frame, SDL_Renderer* gRenderer);
};
| [
"wasimtalal@gmail.com"
] | wasimtalal@gmail.com |
b0ae5b109a1a2779ea78efd9f0bea8b5ad9226c0 | ae1c91ff826dacc63898c9cd9163eb0ba285ad95 | /src/responsibilitychain.cpp | 852bc2dc221accd772ff2e64adaed9fedde178da | [] | no_license | yuanyuewandou/DesignPatternsCppDemo | aafff90f994bc60293c1cdb20468273a94bc8f60 | d486e809af7d5acb38037d42772b634714457173 | refs/heads/master | 2023-03-16T22:23:45.271540 | 2021-03-11T15:19:01 | 2021-03-11T15:19:01 | 336,832,438 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 3,431 | cpp | /* 小鱼号的代码日志
* 设计模式
* 职责链模式
* 使用多个对象都有机会处理请求
* 从而避免请求的发送和接受之间的耦合关系
* 将这个对象连成一条链,并沿着这条链传递该请求
* 知道有一个对象处理它为止
* 实例:
* 学校采购金额审批流程
* < 3000 系主任审批
* 3000 - 5000 学院主任审批
* 5000 - 30000 副校长审批
* 30000 - 30000000 校长审批
* > 30000000 都没办法审批
*/
#include<iostream>
#include<string>
using namespace std;
///请求类
class PurchaseRequeset
{
public:
PurchaseRequeset(int price)
{
m_price = price;
}
int getPrice()
{
return m_price;
}
private:
int m_price; //审批金额
};
///请求的处理者
class Approver
{
public:
Approver(string name)
{
m_name = name;
}
void setNextApprover(Approver* nextApprover)
{
m_nextApprover = nextApprover;
}
///处理请求
virtual void processRequest(PurchaseRequeset req)
{
cout << "can not process Requese" << endl;
}
protected:
Approver* m_nextApprover; ///下一个处理者
string m_name;
};
///系主任 级别的处理者
class DepartmentApprover : public Approver
{
public:
DepartmentApprover(string name) :
Approver(name)
{
}
void processRequest(PurchaseRequeset req)
{
int price = req.getPrice();
if(price < 3000)
{
cout << "name:" << m_name << " process request $:" << price << endl;
}
else
{
cout << "name:" << m_name << " can not process request" << endl;
m_nextApprover->processRequest(req);
}
}
};
///学院主任 级别的处理者
class CollegeApprover : public Approver
{
public:
CollegeApprover(string name) :
Approver(name)
{
}
void processRequest(PurchaseRequeset req)
{
int price = req.getPrice();
if(price > 3000 && price < 5000)
{
cout << "name:" << m_name << " process request $:" << price << endl;
}
else
{
cout << "name:" << m_name << " can not process request" << endl;
m_nextApprover->processRequest(req);
}
}
};
///副校长 级别的处理者
class ViceSchoolMasterApprover : public Approver
{
public:
ViceSchoolMasterApprover(string name) :
Approver(name)
{
}
void processRequest(PurchaseRequeset req)
{
int price = req.getPrice();
if(price > 5000 && price < 30000)
{
cout << "name:" << m_name << " process request $:" << price << endl;
}
else
{
cout << "name:" << m_name << " can not process request" << endl;
m_nextApprover->processRequest(req);
}
}
};
///校长 级别的处理者
class SchoolMasterApprover : public Approver
{
public:
SchoolMasterApprover(string name) :
Approver(name)
{
}
void processRequest(PurchaseRequeset req)
{
int price = req.getPrice();
if(price > 30000 && price < 30000000)
{
cout << "name:" << m_name << " process request $:" << price << endl;
}
else
{
cout << "name:" << m_name << " can not process request" << endl;
m_nextApprover->processRequest(req);
}
}
};
| [
"646210828@qq.com"
] | 646210828@qq.com |
feb9080b25395de5f0deb5b296859387b56d497f | 7af36e07a65a5688e04067a81a20a4528ee5279d | /2023/2February/7_Min_Beauty.cpp | 719890ab79eb2adb1ebae5ea2da55284c7e9208f | [] | no_license | Stenardt-9002/CODECHEF-CONTEST | 211e029991e19fa8fb5d2c1cb612ce60edcd5ec0 | e95f66e9128e972433b000b2891f3a1b7a4b824d | refs/heads/master | 2023-03-17T15:30:15.955832 | 2023-02-09T09:42:17 | 2023-02-09T09:42:17 | 228,833,496 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,948 | cpp |
// https://www.codechef.com/COOK144C/problems/MINBEAUTY
#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds ;
typedef vector<int> vi ;
typedef vector<vi> vii ;
const int mod1 = (1e9+7);
const long long int mod2 = 1e18 ;
#define mii map<int,int>
#define msi map<string,int>
#define musi unordered_map<string,int>
typedef long long int lld;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// tuple <char, int, float> geek ;
// get<0>(geek)
// pair<int, char> PAIR1;
// PAIR1.first ;
void print_tack(stack<int> a)
{
cout<<endl<<endl ;
while (a.empty()==false)
{
cout<<a.top()<<endl ;
a.pop() ;
}
cout<<endl<<endl ;
}
// https://www.delftstack.com/howto/cpp/cpp-split-string-by-space/#:~:text=in%20C%2B%2B.-,Use%20std%3A%3Astring%3A%3Afind%20and%20std%3A%3Astring,value%20or%20a%20single%20character.
void processLine_cpp()
{
string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
"Sed laoreet sem leo, in posuere orci elementum.";
string space_delimiter = " ";
vector<string> words{};
size_t pos = 0;
while ((pos = text.find(space_delimiter)) != string::npos) {
words.push_back(text.substr(0, pos));
text.erase(0, pos + space_delimiter.length());
}
words.push_back(text);
}
int function1(int n , string input)
{
vector<int> hash_1(26,0);
for(auto c : input)
if(hash_1[c-'a']++==1)
return n-2;
return -1;
}
int main(int argc, char const *argv[])
{
fastIO
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif
int testcases=1 ;
cin>>testcases;
while (testcases--)
{
int n ;
cin>> n;
vector<lld> input(n,0) ;
for (int i = 0; i < n; i++)
cin>>input[i];
long long int nas = INT_MAX ;
sort(input.begin() , input.end());
for (int i = 0; i < n-2; i++)
{
for (int j = i+1; j < n-1; j++)
{
lld ele_to_find = 2*input[j]-input[i];
auto low1 = std::lower_bound(input.begin()+j+1 , input.end() , ele_to_find);
// auto low2 = std::upper_bound(input.begin()+j+1 , input.end() , ele_to_find);
int index1 = low1-input.begin() ;
int index2 = low1-input.begin()-1 ;
if(index2>=0 && index2!=j)
nas = min(nas , abs(input[index2]+input[i]-2*input[j]));
nas = min(nas , abs(input[index1]+input[i]-2*input[j]));
// nas = min(nas , abs(input[index1]+input[i]-2*input[j]) , abs(input[index2]+input[i]-2*input[j]) );
}
}
cout<<nas<<endl ;
}
return 0;
}
| [
"esd17i014@iiitdm.ac.in"
] | esd17i014@iiitdm.ac.in |
d489db5179aeb455f61ca2f19b5ca8887f4f1aea | f40bef40a82602ca0e5e852468e3bac888861714 | /src/shared/state/MobileElement.h | c281a760551b310a0d0be9415eb8952648f4fd44 | [] | no_license | pomb95/buguetnoel | 88cb4545836f5ab6f71e12b8d2e20d9262b1acca | 127c7be6617e54c94c2177e85339646f10d56f7f | refs/heads/master | 2021-09-04T19:28:59.507211 | 2018-01-21T18:49:23 | 2018-01-21T18:49:23 | 104,056,653 | 0 | 1 | null | null | null | null | UTF-8 | C++ | false | false | 414 | h | // Generated by dia2code
#ifndef STATE__MOBILEELEMENT__H
#define STATE__MOBILEELEMENT__H
#include <state/Element.h>
namespace state {
class Element;
}
#include "Element.h"
namespace state {
/// class MobileElement -
class MobileElement : public state::Element {
// Operations
public:
MobileElement ();
~MobileElement ();
void getStatus ();
// Setters and Getters
};
};
#endif
| [
"paul.buguet@ensea.fr"
] | paul.buguet@ensea.fr |
8e931a603308557de489853aa8549a9a87bb555c | 97de35bc9399b80c7e422d4bc62be08295e23f72 | /Engine/Lang/AST/ASTNodeBase.hpp | ad4eb7d84682d98632e5b094bb3cb8d455accb77 | [
"BSD-3-Clause"
] | permissive | GabyForceQ/PolluxEngine | 9c5a1bea7fbcad88439c0cfcca35fac929893bf4 | 2dbc84ed1d434f1b6d794f775f315758f0e8cc49 | refs/heads/master | 2022-12-11T04:27:09.047423 | 2020-08-08T13:50:24 | 2020-08-08T13:50:24 | 265,338,012 | 3 | 0 | BSD-3-Clause | 2020-08-08T13:50:25 | 2020-05-19T19:01:53 | C++ | UTF-8 | C++ | false | false | 831 | hpp | /*****************************************************************************************************************************
* Copyright 2020 Gabriel Gheorghe. All rights reserved.
* This code is licensed under the BSD 3-Clause "New" or "Revised" License
* License url: https://github.com/GabyForceQ/PolluxEngine/blob/master/LICENSE
*****************************************************************************************************************************/
#pragma once
#include "IASTNodeVisitor.hpp"
#include "ASTNodeKind.hpp"
#include "../Tokenizer/Token.hpp"
#include "../../Core/OOP/Type.hpp"
namespace Pollux::Lang
{
class ASTNodeBase : public Core::Type
{
public:
explicit ASTNodeBase(Token token) noexcept;
virtual void Accept(IASTNodeVisitor* pVisitor) = 0;
Token token;
std::string content;
};
} | [
"knoppy273@live.com"
] | knoppy273@live.com |
f345f56162cbb4acc19e03155486d78e0b726cd8 | 037d518773420f21d74079ee492827212ba6e434 | /blazetest/src/mathtest/smatsmatschur/SCaDCa.cpp | 239c102d61b2f9a458b015031b4220b8ff1e37c1 | [
"BSD-3-Clause"
] | permissive | chkob/forked-blaze | 8d228f3e8d1f305a9cf43ceaba9d5fcd603ecca8 | b0ce91c821608e498b3c861e956951afc55c31eb | refs/heads/master | 2021-09-05T11:52:03.715469 | 2018-01-27T02:31:51 | 2018-01-27T02:31:51 | 112,014,398 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 4,186 | cpp | //=================================================================================================
/*!
// \file src/mathtest/smatsmatschur/SCaDCa.cpp
// \brief Source file for the SCaDCa sparse matrix/sparse matrix Schur product math test
//
// Copyright (C) 2012-2018 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cstdlib>
#include <iostream>
#include <blaze/math/CompressedMatrix.h>
#include <blaze/math/DiagonalMatrix.h>
#include <blaze/math/SymmetricMatrix.h>
#include <blazetest/mathtest/Creator.h>
#include <blazetest/mathtest/smatsmatschur/OperationTest.h>
#include <blazetest/system/MathTest.h>
//=================================================================================================
//
// MAIN FUNCTION
//
//=================================================================================================
//*************************************************************************************************
int main()
{
std::cout << " Running 'SCaDCa'..." << std::endl;
using blazetest::mathtest::TypeA;
try
{
// Matrix type definitions
typedef blaze::SymmetricMatrix< blaze::CompressedMatrix<TypeA> > SCa;
typedef blaze::DiagonalMatrix< blaze::CompressedMatrix<TypeA> > DCa;
// Creator type definitions
typedef blazetest::Creator<SCa> CSCa;
typedef blazetest::Creator<DCa> CDCa;
// Running tests with small matrices
for( size_t i=0UL; i<=6UL; ++i ) {
for( size_t j=0UL; j<=i*i; ++j ) {
for( size_t k=0UL; k<=i; ++k ) {
RUN_SMATSMATSCHUR_OPERATION_TEST( CSCa( i, j ), CDCa( i, k ) );
}
}
}
// Running tests with large matrices
RUN_SMATSMATSCHUR_OPERATION_TEST( CSCa( 67UL, 7UL ), CDCa( 67UL, 13UL ) );
RUN_SMATSMATSCHUR_OPERATION_TEST( CSCa( 128UL, 16UL ), CDCa( 128UL, 8UL ) );
}
catch( std::exception& ex ) {
std::cerr << "\n\n ERROR DETECTED during sparse matrix/sparse matrix Schur product:\n"
<< ex.what() << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
//*************************************************************************************************
| [
"klaus.iglberger@gmail.com"
] | klaus.iglberger@gmail.com |
1fb917fd28b86c32841bd1341d80510c8b3fe386 | 7b2321fc78754db7782b297840724ebabd7bd423 | /heap/heap.cpp | c3a75079a1808a5e93ecb8283693894ea39c28c3 | [] | no_license | joshu0991/MidtermReviewCS310 | dd09829ba33ceadc1841b6e95dd136b761bb3b4d | 03df16c191d5ac9f0dc5ee4568c979ac2ecaeea8 | refs/heads/master | 2020-05-20T15:55:56.731070 | 2015-03-05T16:00:35 | 2015-03-05T16:00:35 | 31,524,561 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,792 | cpp | /*
* heap.cpp
*
* Created on: Mar 4, 2015
*/
#include <iostream>
const int size = 12;
static int A[size] = {0, 3, 1, 1, 6, 3, 2, 10, 3, 16, 19, 4};
int left(int i)
{
return (2*i)+1;
}
int right(int i)
{
return (2*i)+2;
}
//a leaf of a value less than the size of the array
//and larger than the center of the array
bool isLeaf(int i)
{
if(i >= (size/2) && i <= size)
{
return true;
}
return false;
}
void maxHeapify(int i)
{
//if it isn't a leaf it may need to be swapped
if(!isLeaf(i))
{
//if the value is less than it's right or left child
if(A[i] < A[left(i)] || A[i] < A[right(i)])
{
//if the left child is smaller
if(A[left(i)] > A[right(i)])
{
//swap the left child with the index
std::cout << "Swapping " << A[i] << " and " << A[left(i)] << std::endl;
int a = A[i];
A[i] = A[left(i)];
A[left(i)] = a;
//and run maxHeapify in it. This will push the value to
//it's lowest point and order all things below the parent
maxHeapify(left(i));
}
else
{
//else swap with the right child since it is larger
std::cout << "Swapping " << A[i] << " and " << A[right(i)] << std::endl;
int a = A[i];
A[i] = A[right(i)];
A[right(i)] = a;
//run maxheap on that value. This will push the value to it's lowest position
maxHeapify(right(i));
}
}
}
}
bool buildHeap()
{
//need to run for each node that is not a leaf
for(int i = (size/2); i >= 0; i--)
{
maxHeapify(i);
}
return true;
}
int main()
{
std::cout << "before: " << std::endl;
for(int i = 0; i < size; i++)
{
std::cout << A[i] << ", ";
}
std::cout << std::endl;
buildHeap();
std::cout << "After: " << std::endl;
for(int i = 0; i < size; i++)
{
std::cout << A[i] << ",";
}
std::cout << std::endl;
return 0;
}
| [
"joshualilly@me.com"
] | joshualilly@me.com |
cd06753ff07d441660a88e56b00a8a545afb70bf | 69740a5b14d963b51ac0b8d956c205d3b7879353 | /contrib/CCF/CCF/IDL2/SemanticGraph/IntExpression.cpp | 7cf453c2ec682c728941f01e1a2fe1aa040af1aa | [] | no_license | SEDS/OASIS | eba334ae59e69fc66d1e355fedb5ad5583b40695 | ddf365eea9874fa5938072fea1fad5b41c27f3e9 | refs/heads/master | 2020-12-24T15:51:12.761878 | 2013-12-03T20:30:21 | 2013-12-03T20:30:21 | 13,195,236 | 4 | 3 | null | 2015-10-24T09:40:39 | 2013-09-29T15:58:55 | C++ | UTF-8 | C++ | false | false | 10,616 | cpp | // file : CCF/IDL2/SemanticGraph/IntExpression.cpp
// author : Boris Kolpackov <boris@kolpackov.net>
// cvs-id : $Id: IntExpression.cpp 74499 2006-09-22 10:02:37Z boris $
#include "CCF/IDL2/SemanticGraph/IntExpression.hpp"
namespace CCF
{
namespace IDL2
{
namespace SemanticGraph
{
using Introspection::TypeInfo;
using Introspection::Access;
// IntExpression
//
namespace
{
TypeInfo
int_expression_init_ ()
{
TypeInfo ti (typeid (IntExpression));
ti.add_base (Access::PUBLIC, true, Expression::static_type_info ());
return ti;
}
TypeInfo int_expression_ (int_expression_init_ ());
}
TypeInfo const& IntExpression::
static_type_info () { return int_expression_; }
IntExpression::
~IntExpression ()
{
}
// IntLiteral
//
namespace
{
TypeInfo
int_literal_init_ ()
{
TypeInfo ti (typeid (IntLiteral));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_literal_ (int_literal_init_ ());
}
TypeInfo const& IntLiteral::
static_type_info () { return int_literal_; }
// IntConst
//
namespace
{
TypeInfo
int_const_init_ ()
{
TypeInfo ti (typeid (IntConst));
ti.add_base (Access::PUBLIC, true, Const::static_type_info ());
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_const_ (int_const_init_ ());
}
TypeInfo const& IntConst::
static_type_info () { return int_const_; }
// NEG
//
namespace
{
TypeInfo
int_negates_init_ ()
{
TypeInfo ti (typeid (IntNegates));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_negates_ (int_negates_init_ ());
}
TypeInfo const& IntNegates::
static_type_info () { return int_negates_; }
namespace
{
TypeInfo
int_neg_init_ ()
{
TypeInfo ti (typeid (IntNeg));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_neg_ (int_neg_init_ ());
}
TypeInfo const& IntNeg::
static_type_info () { return int_neg_; }
// COM
//
namespace
{
TypeInfo
int_complements_init_ ()
{
TypeInfo ti (typeid (IntComplements));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_complements_ (int_complements_init_ ());
}
TypeInfo const& IntComplements::
static_type_info () { return int_complements_; }
namespace
{
TypeInfo
int_com_init_ ()
{
TypeInfo ti (typeid (IntCom));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_com_ (int_com_init_ ());
}
TypeInfo const& IntCom::
static_type_info () { return int_com_; }
// MUL
//
namespace
{
TypeInfo
int_multiplies_init_ ()
{
TypeInfo ti (typeid (IntMultiplies));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_multiplies_ (int_multiplies_init_ ());
}
TypeInfo const& IntMultiplies::
static_type_info () { return int_multiplies_; }
namespace
{
TypeInfo
int_mul_init_ ()
{
TypeInfo ti (typeid (IntMul));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_mul_ (int_mul_init_ ());
}
TypeInfo const& IntMul::
static_type_info () { return int_mul_; }
// DIV
//
namespace
{
TypeInfo
int_divides_init_ ()
{
TypeInfo ti (typeid (IntDivides));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_divides_ (int_divides_init_ ());
}
TypeInfo const& IntDivides::
static_type_info () { return int_divides_; }
namespace
{
TypeInfo
int_div_init_ ()
{
TypeInfo ti (typeid (IntDiv));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_div_ (int_div_init_ ());
}
TypeInfo const& IntDiv::
static_type_info () { return int_div_; }
namespace
{
TypeInfo
int_rem_init_ ()
{
TypeInfo ti (typeid (IntRem));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_rem_ (int_rem_init_ ());
}
TypeInfo const& IntRem::
static_type_info () { return int_rem_; }
// ADD
//
namespace
{
TypeInfo
int_adds_init_ ()
{
TypeInfo ti (typeid (IntAdds));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_adds_ (int_adds_init_ ());
}
TypeInfo const& IntAdds::
static_type_info () { return int_adds_; }
namespace
{
TypeInfo
int_add_init_ ()
{
TypeInfo ti (typeid (IntAdd));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_add_ (int_add_init_ ());
}
TypeInfo const& IntAdd::
static_type_info () { return int_add_; }
// SUB
//
namespace
{
TypeInfo
int_subtracts_init_ ()
{
TypeInfo ti (typeid (IntSubtracts));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_subtracts_ (int_subtracts_init_ ());
}
TypeInfo const& IntSubtracts::
static_type_info () { return int_subtracts_; }
namespace
{
TypeInfo
int_sub_init_ ()
{
TypeInfo ti (typeid (IntSub));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_sub_ (int_sub_init_ ());
}
TypeInfo const& IntSub::
static_type_info () { return int_sub_; }
// RSH & LSH
//
namespace
{
TypeInfo
int_shifts_init_ ()
{
TypeInfo ti (typeid (IntShifts));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_shifts_ (int_shifts_init_ ());
}
TypeInfo const& IntShifts::
static_type_info () { return int_shifts_; }
namespace
{
TypeInfo
int_rsh_init_ ()
{
TypeInfo ti (typeid (IntRsh));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_rsh_ (int_rsh_init_ ());
}
TypeInfo const& IntRsh::
static_type_info () { return int_rsh_; }
namespace
{
TypeInfo
int_lsh_init_ ()
{
TypeInfo ti (typeid (IntLsh));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_lsh_ (int_lsh_init_ ());
}
TypeInfo const& IntLsh::
static_type_info () { return int_lsh_; }
// AND
//
namespace
{
TypeInfo
int_conjuncts_init_ ()
{
TypeInfo ti (typeid (IntConjuncts));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_conjuncts_ (int_conjuncts_init_ ());
}
TypeInfo const& IntConjuncts::
static_type_info () { return int_conjuncts_; }
namespace
{
TypeInfo
int_and_init_ ()
{
TypeInfo ti (typeid (IntAnd));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_and_ (int_and_init_ ());
}
TypeInfo const& IntAnd::
static_type_info () { return int_and_; }
// XOR
//
namespace
{
TypeInfo
int_exclusively_disjuncts_init_ ()
{
TypeInfo ti (typeid (IntExclusivelyDisjuncts));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_exclusively_disjuncts_ (
int_exclusively_disjuncts_init_ ());
}
TypeInfo const& IntExclusivelyDisjuncts::
static_type_info () { return int_exclusively_disjuncts_; }
namespace
{
TypeInfo
int_xor_init_ ()
{
TypeInfo ti (typeid (IntXor));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_xor_ (int_xor_init_ ());
}
TypeInfo const& IntXor::
static_type_info () { return int_xor_; }
// OR
//
namespace
{
TypeInfo
int_inclusively_disjuncts_init_ ()
{
TypeInfo ti (typeid (IntInclusivelyDisjuncts));
ti.add_base (Access::PUBLIC, true, Edge::static_type_info ());
return ti;
}
TypeInfo int_inclusively_disjuncts_ (
int_inclusively_disjuncts_init_ ());
}
TypeInfo const& IntInclusivelyDisjuncts::
static_type_info () { return int_inclusively_disjuncts_; }
namespace
{
TypeInfo
int_or_init_ ()
{
TypeInfo ti (typeid (IntOr));
ti.add_base (
Access::PUBLIC, true, IntExpression::static_type_info ());
return ti;
}
TypeInfo int_or_ (int_or_init_ ());
}
TypeInfo const& IntOr::
static_type_info () { return int_or_; }
}
}
}
| [
"hillj@cs.iupui.edu"
] | hillj@cs.iupui.edu |
266bb12b12f28ec9de109b384cd353d82f7229d8 | 9cdacac72822a75a8ef56d487656c3126b834251 | /LinearSystem/Include/HardConstraintSLS.h | 04bcd11607333e05758fad3bcfe11061a3999d87 | [] | no_license | HoLyK38/OpenMesh_Parameterization | cdd890181a57a41f17a4e4f7b3b393591888856a | 462b0d53efe6ec77644aee1f407eef4cf748e93c | refs/heads/master | 2020-04-26T01:50:01.506610 | 2012-05-30T19:01:39 | 2012-05-30T19:01:39 | 4,288,142 | 3 | 0 | null | null | null | null | BIG5 | C++ | false | false | 1,830 | h | #ifndef _HARD_CONSTRAINT_SPARSE_LINEAR_SYSTEM_H_
#define _HARD_CONSTRAINT_SPARSE_LINEAR_SYSTEM_H_
#include "SparseLinearSystem.h"
namespace LinearSystemLib
{
/// ConType : constraint 的 type, ex : Vi = pi, 其中 pi 是 Point3f Type.
template < class ConType >
class ConstraintContainer : public map< unsigned int, ConType const* >
{
public:
unsigned int Index( const const_iterator& cit ) const { return cit->first; }
unsigned int Index( const iterator& it ) const { return it->first; }
const ConType* Value( const_iterator& cit ) const { return cit->second; }
ConType const*& Value( iterator& cit ) { return cit->second; }
};
template < class ConType, class Extractor >
class HardConstraintSLSBuilder;
template < class ConType >
class HardConstraintSLS : public SparseLinearSystem
{
template < class ConType, class Extractor >
friend class HardConstraintSLSBuilder;
private:
// 不支援 copy constructor.
HardConstraintSLS( const HardConstraintSLS& );
public:
HardConstraintSLS( unsigned int dim = 0 )
: SparseLinearSystem( 0, 0, dim )
{}
const ConstraintContainer<ConType>& Constraints() const
{
return mc_Constraints;
}
protected:
void setConstraints( const ConstraintContainer<ConType>& cons )
{
mc_Constraints.erase( mc_Constraints.begin(), mc_Constraints.end() );
mc_Constraints.insert( cons.begin(), cons.end() );
}
void setConstraint( unsigned int index, ConType const* value )
{
ConstraintContainer<ConType>::iterator it = mc_Constraints.find( index );
if( it != mc_Constraints.end() )
mc_Constraints.Value(it) = value;
else
mc_Constraints.insert( make_pair(index, value) );
}
private:
ConstraintContainer<ConType> mc_Constraints;
};
}
#endif | [
"k387259@yahoo.com.tw"
] | k387259@yahoo.com.tw |
a119874a36c48332225cf40ba8edecc64e9b9121 | 86ff33b8bd1a7ac02c2d52ac176d785f4ddf9dcd | /hic.cpp | ef47805a8099e6fb3725598da8db8b552c3e8fc3 | [
"MIT"
] | permissive | lacademic/hifiasm | 513d7abb6c37f625e754ee35652380b3aa5e1ebf | 11430d6a3bcf0844b8da05b8faae007905172a5d | refs/heads/master | 2023-04-13T02:28:15.682943 | 2021-04-25T18:50:36 | 2021-04-25T18:50:36 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 486,219 | cpp | #define __STDC_LIMIT_MACROS
#include "float.h"
#include <math.h>
#include "hic.h"
#include "htab.h"
#include "assert.h"
#include "Overlaps.h"
#include "Hash_Table.h"
#include "Correct.h"
#include "Purge_Dups.h"
#include "rcut.h"
#include "khashl.h"
#include "kthread.h"
#include "ksort.h"
#include "kseq.h" // FASTA/Q parser
#include "kdq.h"
KSEQ_INIT(gzFile, gzread)
KDQ_INIT(uint64_t)
#define OFFSET_RATE 0.000000001
#define OFFSET_SECOND_RATE 0.0000000001
#define SCALL 10000
#define OFFSET_RATE_MAX_W 6.90675477865*SCALL
#define OFFSET_RATE_MIN_W 4.0000003e-10*SCALL
#define HIC_COUNTER_BITS 12
#define HIC_MAX_COUNT ((1<<HIC_COUNTER_BITS)-1)
#define HIC_KEY_MODE ((uint64_t)(((uint64_t)-1)-HIC_MAX_COUNT))
#define HIC_R_E_RATE 0.01
const unsigned char b2rc[5] = {'T', 'G', 'C', 'A', 'N'};
#define hic_ct_eq(a, b) ((a)>>HIC_COUNTER_BITS == (b)>>HIC_COUNTER_BITS)
#define hic_ct_hash(a) ((a)>>HIC_COUNTER_BITS)
KHASHL_MAP_INIT(static klib_unused, hc_pt_t, hc_pt, uint64_t, uint64_t, hic_ct_hash, hic_ct_eq)
#define u_trans_m_key(a) (((uint64_t)((a).qn)<<32) | ((uint64_t)((a).tn)))
KRADIX_SORT_INIT(u_trans_m, u_trans_t, u_trans_m_key, 8)
#define u_trans_occ_key(a) ((a).occ)
KRADIX_SORT_INIT(u_trans_occ, u_trans_t, u_trans_occ_key, member_size(u_trans_t, occ))
typedef struct{
kvec_t(char) name;
kvec_t(uint64_t) name_Len;
kvec_t(char) r;
kvec_t(uint64_t) r_Len;
uint64_t idx;
} reads_t;
typedef struct{
kvec_t(uint8_t) vis;
kvec_t(uint64_t) x;
kvec_t(uint64_t) dis;
uint64_t uID_mode, uID_shift, tmp_v, tmp_d;
}pdq;
typedef struct{
kvec_t(hc_edge_warp) rGraph;
kvec_t(uint64_t) order;
pdq pq;
kvec_t(uint8_t) rGraphSet;
kvec_t(uint8_t) rGraphVis;
kvec_t(uint8_t) utgVis;
kvec_t(uint8_t) bmerVis;
kdq_t(uint64_t) *q;
kvec_t(uint32_t) parent;
kvec_t(double) p_weight;
const uint64_t* enzymes;
uint64_t uID_mode, uID_shift, n, src, dest, n_e, c_e;
int p_mer, a_mer, b_mer;
} min_cut_t;
typedef struct{
kvec_t(uint32_t) a;
uint32_t h[2];
uint8_t full_bub;
int status[2];
double weight[2], weight_convex;
}partition_warp;
typedef struct{
size_t n, m;
partition_warp* a;
uint32_t* index;
}G_partition;
typedef struct{
kvec_t(uint8_t) vis;
double weight;
long long bid, uid, chainID;
}block_phase_type;
typedef struct{
uint64_t n;
uint8_t* lock;
uint32_t* hap;
uint32_t m[3];
uint32_t label, label_add, label_shift;
hc_links* link;
G_partition g_p;
G_partition group_g_p;
kvec_t(double) label_buffer;
block_phase_type b;
}H_partition;
typedef struct {
uint32_t p; // the optimal parent vertex
uint32_t d; // the shortest distance from the initial vertex
uint32_t nc; // max count of reads, no matter positive or negative
double nh, w[2];
uint32_t uc, ac; // used vertex/allowed vertex
uint32_t r:31, s:1; // r: the number of remaining incoming arc; s: state
//s: state, s=0, this edge has not been visited, otherwise, s=1
} bub_p_t;
typedef struct {
///all information for each node
bub_p_t *a;
kvec_t(uint32_t) S; // set of vertices without parents, nodes with all incoming edges visited
kvec_t(uint32_t) T; // set of tips
kvec_t(uint32_t) b; // visited vertices
kvec_t(uint32_t) e; // visited edges/arcs
uint32_t exist_hap_label;
} bub_p_t_warp;
typedef struct {
hc_pt_t *h;
uint64_t n;
uint64_t *a;
khint_t end;///end of total idx
} hc_pt1_t;
typedef struct {
ma_ug_t* ug;
asg_t* read_g;
///hc_links* link;
trans_chain* t_ch;
uint64_t uID_bits;
uint64_t uID_mode;
uint64_t pos_bits;
uint64_t pos_mode;
uint64_t rev_mode;
uint64_t k;
uint64_t hap_cnt;
uint64_t pre;
uint64_t tot;
uint64_t tot_pos;
uint64_t up_bound;
hc_pt1_t* idx_buf;
long double a, b, frac, max_d;
} ha_ug_index;
typedef struct { // data structure for each step in kt_pipeline()
uint64_t key, pos;
} ch_buf_t;
typedef struct {
kvec_t(uint64_t) a;
} kvec_cnt;
typedef struct {
kvec_t(ch_buf_t) a;
} kvec_pos;
typedef struct { // global data structure for kt_pipeline()
int is_cnt;
uint64_t buf_bytes;
ha_ug_index *h;
kvec_cnt* cnt;
kvec_pos* buf;
uint64_t n_thread;
} pldat_t;
typedef struct {
uint64_t *a, id;
uint16_t occ1, occ2;
} pe_hit_hap;
typedef struct {
pe_hit_hap* a;
size_t n, m;
uint64_t n_u;
} kvec_pe_hit_hap;
typedef struct {
uint64_t s, e, id, len;
} pe_hit;
typedef struct {
kvec_t(pe_hit) a;
kvec_t(uint64_t) idx;
kvec_t(uint64_t) occ;
} kvec_pe_hit;
typedef struct {
kvec_t(hc_edge) a;
}kvec_hc_edge;
#define pe_hit_an1_key(x) ((x).s)
KRADIX_SORT_INIT(pe_hit_an1, pe_hit, pe_hit_an1_key, member_size(pe_hit, s))
#define pe_hit_an2_key(x) ((x).e)
KRADIX_SORT_INIT(pe_hit_an2, pe_hit, pe_hit_an2_key, member_size(pe_hit, e))
#define pe_hit_an1_idx_key(x) ((x).s<<1)
KRADIX_SORT_INIT(pe_hit_idx_an1, pe_hit, pe_hit_an1_idx_key, member_size(pe_hit, s))
#define pe_hit_an2_idx_key(x) ((x).e<<1)
KRADIX_SORT_INIT(pe_hit_idx_an2, pe_hit, pe_hit_an2_idx_key, member_size(pe_hit, e))
#define generic_key(x) (x)
KRADIX_SORT_INIT(hc64, uint64_t, generic_key, 8)
KRADIX_SORT_INIT(u32, uint32_t, generic_key, 4)
#define g_partition_key(x) (((x)>>1)+((x)<<63))
KRADIX_SORT_INIT(g_partition, uint64_t, g_partition_key, 8)
#define get_pe_s(x) ((x).a[0])
#define get_pe_e(x) ((x).a[(x).occ1])
KRADIX_SORT_INIT(pe_an1, pe_hit_hap, get_pe_s, 8)
KRADIX_SORT_INIT(pe_an2, pe_hit_hap, get_pe_e, 8)
#define pe_occ_key_1(x) ((x).occ1)
KRADIX_SORT_INIT(pe_occ1, pe_hit_hap, pe_occ_key_1, member_size(pe_hit_hap, occ1))
#define pe_occ_key_2(x) ((x).occ2)
KRADIX_SORT_INIT(pe_occ2, pe_hit_hap, pe_occ_key_2, member_size(pe_hit_hap, occ2))
#define pe_occ_key_t(x) (((uint64_t)((x).occ1))+((uint64_t)((x).occ2)))
KRADIX_SORT_INIT(pe_occ_t, pe_hit_hap, pe_occ_key_t, 8)
#define asg_arc_key(a) ((a).ul)
KRADIX_SORT_INIT(asg_e, asg_arc_t, asg_arc_key, 8)
typedef struct { // global data structure for kt_pipeline()
const ha_ug_index* idx;
kseq_t *ks1, *ks2;
int64_t chunk_size;
uint64_t n_thread;
uint64_t total_base;
uint64_t total_pair;
kvec_pe_hit hits;
///kvec_pe_hit_hap hits;
trans_chain* t_ch;
} sldat_t;
typedef struct {
uint64_t ref;
uint64_t off_cnt;
} s_hit;
typedef struct {
kvec_t(s_hit) a;
} kvec_vote;
typedef struct { // data structure for each step in kt_pipeline()
const ha_ug_index* idx;
int n, m, sum_len;
uint64_t *len, id;
char **seq;
ch_buf_t *buf;
kvec_vote* pos_buf;
pe_hit* pos;
///pe_hit_hap* pos;
trans_chain* t_ch;
} stepdat_t;
#define generic_key(x) (x)
KRADIX_SORT_INIT(b64, uint64_t, generic_key, 8)
#define ch_buf_t_key(a) ((a).key)
KRADIX_SORT_INIT(ch_buf, ch_buf_t, ch_buf_t_key, member_size(ch_buf_t, key))
#define hc_pos_key(x) ((x)<<1)
KRADIX_SORT_INIT(hc_pos, uint64_t, hc_pos_key, 8)
#define hc_s_hit_an1_key(a) ((a).ref)
KRADIX_SORT_INIT(hc_s_hit_an1, s_hit, hc_s_hit_an1_key, 8)
#define hc_s_hit_an2_key(a) ((uint32_t)(a).off_cnt)
KRADIX_SORT_INIT(hc_s_hit_an2, s_hit, hc_s_hit_an2_key, 8)
#define hc_s_hit_off_cnt_key(a) ((a).off_cnt)
KRADIX_SORT_INIT(hc_s_hit_off_cnt, s_hit, hc_s_hit_off_cnt_key, 8)
#define hc_edge_key_u(a) ((a).uID)
KRADIX_SORT_INIT(hc_edge_u, hc_edge, hc_edge_key_u, 4)
#define hc_edge_key_d(a) ((a).dis)
KRADIX_SORT_INIT(hc_edge_d, hc_edge, hc_edge_key_d, member_size(hc_edge, dis))
typedef struct {
kvec_t(kvec_t_u64_warp) matrix;
uint64_t uID_shift, dis_mode;
} MT;
typedef struct{
uint64_t beg, end, dis, cnt_0, cnt_1;
} trans_p_t;
typedef struct{
trans_p_t* a;
size_t n, m;
uint64_t max, med;
} trans_idx;
reads_t R1, R2;
ha_ug_index* ug_index;
void print_debug_bubble_graph(bubble_type* bub, ma_ug_t* ug, const char *fn);
void build_bub_graph(ma_ug_t* ug, bubble_type* bub);
void init_ha_ug_index_opt(ha_ug_index* idx, ma_ug_t *ug, int k, pldat_t* p)
{
uint64_t i, n;
for (idx->uID_bits=1; (uint64_t)(1<<idx->uID_bits)<(uint64_t)ug->u.n; idx->uID_bits++);
idx->pos_bits = 64 - idx->uID_bits - 1;
idx->uID_mode = (((uint64_t)-1) << (64-idx->uID_bits))>>1;
idx->pos_mode = ((uint64_t)-1) >> (64-idx->pos_bits);
idx->rev_mode = ((uint64_t)1) << 63;
idx->ug = ug;
idx->k = k;
idx->pre = HIC_COUNTER_BITS;
idx->tot = 1 << idx->pre;
idx->tot_pos = 0;
///idx->up_bound = 1;
idx->up_bound = asm_opt.hap_occ;
CALLOC(idx->idx_buf, idx->tot);
for (i = 0; i < idx->tot; i++)
{
idx->idx_buf[i].h = hc_pt_init();
}
for (i = n = 0; i < ug->u.n; i++)
{
n += ug->u.a[i].len;
}
n = n << 3;
p->h = idx;
p->buf_bytes = n>>7;
CALLOC(p->cnt, idx->tot);
CALLOC(p->buf, idx->tot);
for (i = 0; i < idx->tot; i++)
{
kv_init(p->cnt[i].a);
kv_init(p->buf[i].a);
}
p->n_thread = asm_opt.thread_num;
}
inline uint64_t get_k_direction(uint64_t x[4])
{
if(x[1] != x[3])
{
return x[1] < x[3]? 0 : 1;
}
else if(x[0] != x[2])
{
return x[0] < x[2]? 0 : 1;
}
else
{
return (uint64_t)-1;
}
}
inline uint64_t hc_hash_long(uint64_t x[4], uint64_t* skip, uint64_t k)
{
///compare forward k-mer and reverse complementary strand
(*skip) = get_k_direction(x);
if((*skip) == (uint64_t)-1) return (*skip);
if (k <= 32) return ((x[(*skip)<<1|0]<<32)|(x[(*skip)<<1|1]));
return yak_hash64_64(x[(*skip)<<1|0]) + yak_hash64_64(x[(*skip)<<1|1]);
}
inline uint64_t get_hc_pt1_count(ha_ug_index* index, uint64_t key, uint64_t** pos_list)
{
uint64_t bucket_mask = (1ULL<<index->pre) - 1;
hc_pt1_t* h = &(index->idx_buf[key & bucket_mask]);
uint64_t beg;
khint_t k;
k = hc_pt_get(h->h, key);
if (k == kh_end(h->h))
{
return 0;
}
beg = kh_val(h->h, k);
if(pos_list) *pos_list = h->a + beg;
if((kh_key(h->h, k)&HIC_MAX_COUNT)<HIC_MAX_COUNT) return kh_key(h->h, k)&HIC_MAX_COUNT;
if(k == h->end) return h->n - beg;
for (k++; k != kh_end(h->h); ++k)
{
if (kh_exist(h->h, k))
{
return kh_val(h->h, k) - beg;
}
}
return h->n - beg;
}
void test_hc_pt1(char* seq, uint64_t len, uint64_t uID, ha_ug_index* idx)
{
uint64_t i, l, k, pos, *pos_list = NULL, cnt;
uint64_t x[4], mask = (1ULL<<idx->k) - 1, shift = idx->k - 1, hash, skip;
for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < len; ++i) {
int c = seq_nt4_table[(uint8_t)seq[i]];
///c = 00, 01, 10, 11
if (c < 4) { // not an "N" base
///x[0] & x[1] are the forward k-mer
///x[2] & x[3] are the reverse complementary k-mer
x[0] = (x[0] << 1 | (c&1)) & mask;
x[1] = (x[1] << 1 | (c>>1)) & mask;
x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1)) << shift;
x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
if (++l >= idx->k)
{
hash = hc_hash_long(x, &skip, idx->k);
if(skip == (uint64_t)-1) continue;
pos = (skip << 63) | ((uID << (64-idx->uID_bits))>>1) | (i & idx->pos_mode);
cnt = get_hc_pt1_count(idx, hash, &pos_list);
if(cnt == 0) fprintf(stderr, "ERROR cnt, uID: %lu\n", uID);
for (k = 0; k < cnt; k++)
{
if(pos_list[k]==pos)
{
pos_list[k] = (uint64_t)-1;
break;
}
}
if(k == cnt) fprintf(stderr, "ERROR k\n");
}
} else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
}
}
void test_unitig_index(ha_ug_index* idx, ma_ug_t *ug)
{
double index_time = yak_realtime();
uint32_t i, j;
ma_utg_t *u = NULL;
hc_pt1_t *h = NULL;
idx->ug = ug;
for (i = 0; i < idx->ug->u.n; i++)
{
u = &(idx->ug->u.a[i]);
if(u->m == 0) continue;
test_hc_pt1(u->s, u->len, i, idx);
}
for (i = 0; i < idx->tot; i++)
{
h = &(idx->idx_buf[i]);
for (j = 0; j < h->n; j++)
{
if(h->a[j] != (uint64_t)-1)
{
fprintf(stderr, "ERROR j\n");
}
}
}
fprintf(stderr, "[M::%s::%.3f] ==> Test has been passed\n", __func__, yak_realtime()-index_time);
}
void hc_pt_t_gen_single(hc_pt1_t* pt, uint64_t* up_bound)
{
khint_t k;
uint64_t c;
if(up_bound)
{
for (k = 0; k != kh_end(pt->h); ++k) {
if (kh_exist(pt->h, k)) {
if(kh_val(pt->h, k) > (*up_bound))
{
kh_val(pt->h, k) = 0;
kh_key(pt->h, k) = (kh_key(pt->h, k)&HIC_KEY_MODE)|
(kh_val(pt->h, k)<HIC_MAX_COUNT?kh_val(pt->h, k):HIC_MAX_COUNT);
}
}
}
}
for (k = 0, pt->n = 0; k != kh_end(pt->h); ++k) {
if (kh_exist(pt->h, k)) {
c = kh_val(pt->h, k);
kh_val(pt->h, k) = pt->n;
pt->n += c;
pt->end = k;
}
}
CALLOC(pt->a, pt->n);
}
int write_hc_pt_index(ha_ug_index* idx, char* file_name)
{
char* gfa_name = (char*)malloc(strlen(file_name)+25);
sprintf(gfa_name, "%s.hic.tlb.bin", file_name);
FILE* fp = fopen(gfa_name, "w");
if (!fp) {
free(gfa_name);
return 0;
}
fwrite(&idx->uID_bits, sizeof(idx->uID_bits), 1, fp);
fwrite(&idx->uID_mode, sizeof(idx->uID_mode), 1, fp);
fwrite(&idx->pos_bits, sizeof(idx->pos_bits), 1, fp);
fwrite(&idx->pos_mode, sizeof(idx->pos_mode), 1, fp);
fwrite(&idx->rev_mode, sizeof(idx->rev_mode), 1, fp);
fwrite(&idx->k, sizeof(idx->k), 1, fp);
fwrite(&idx->pre, sizeof(idx->pre), 1, fp);
fwrite(&idx->tot, sizeof(idx->tot), 1, fp);
fwrite(&idx->tot_pos, sizeof(idx->tot_pos), 1, fp);
uint64_t i = 0;
for (i = 0; i < idx->tot; i++)
{
fwrite(&idx->idx_buf[i].n, sizeof(idx->idx_buf[i].n), 1, fp);
fwrite(&idx->idx_buf[i].end, sizeof(idx->idx_buf[i].end), 1, fp);
fwrite(idx->idx_buf[i].a, sizeof(uint64_t), idx->idx_buf[i].n, fp);
hc_pt_save(idx->idx_buf[i].h, fp);
}
fprintf(stderr, "[M::%s] Index has been written.\n", __func__);
free(gfa_name);
fclose(fp);
return 1;
}
int load_hc_pt_index(ha_ug_index** r_idx, char* file_name)
{
uint64_t flag = 0;
// double index_time = yak_realtime();
char* gfa_name = (char*)malloc(strlen(file_name)+25);
sprintf(gfa_name, "%s.hic.tlb.bin", file_name);
FILE* fp = fopen(gfa_name, "r");
if (!fp) {
free(gfa_name);
return 0;
}
ha_ug_index* idx = NULL; CALLOC(idx, 1);
flag += fread(&idx->uID_bits, sizeof(idx->uID_bits), 1, fp);
flag += fread(&idx->uID_mode, sizeof(idx->uID_mode), 1, fp);
flag += fread(&idx->pos_bits, sizeof(idx->pos_bits), 1, fp);
flag += fread(&idx->pos_mode, sizeof(idx->pos_mode), 1, fp);
flag += fread(&idx->rev_mode, sizeof(idx->rev_mode), 1, fp);
flag += fread(&idx->k, sizeof(idx->k), 1, fp);
flag += fread(&idx->pre, sizeof(idx->pre), 1, fp);
flag += fread(&idx->tot, sizeof(idx->tot), 1, fp);
flag += fread(&idx->tot_pos, sizeof(idx->tot_pos), 1, fp);
MALLOC(idx->idx_buf, idx->tot);
uint64_t i = 0;
for (i = 0; i < idx->tot; i++)
{
flag += fread(&idx->idx_buf[i].n, sizeof(idx->idx_buf[i].n), 1, fp);
flag += fread(&idx->idx_buf[i].end, sizeof(idx->idx_buf[i].end), 1, fp);
MALLOC(idx->idx_buf[i].a, idx->idx_buf[i].n);
flag += fread(idx->idx_buf[i].a, sizeof(uint64_t), idx->idx_buf[i].n, fp);
hc_pt_load(&(idx->idx_buf[i].h), fp);
}
(*r_idx) = idx;
free(gfa_name);
fclose(fp);
// fprintf(stderr, "[M::%s::%.3f] ==> HiC index has been loaded\n", __func__, yak_realtime()-index_time);
return 1;
}
static void worker_for_sort(void *data, long i, int tid) // callback for kt_for()
{
pldat_t *pl = (pldat_t*)data;
hc_pt1_t *h = &(pl->h->idx_buf[i]);
khint_t k;
uint64_t beg, cnt = 0;
uint64_t* pos_list;
for (k = 0; k != kh_end(h->h); ++k) {
if (kh_exist(h->h, k)) {
beg = kh_val(h->h, k);
pos_list = h->a + beg;
if((kh_key(h->h, k)&HIC_MAX_COUNT)<HIC_MAX_COUNT)
{
cnt = kh_key(h->h, k)&HIC_MAX_COUNT;
}
else if(k == h->end)
{
cnt = h->n - beg;
}
else
{
for (k++; k != kh_end(h->h); ++k)
{
if (kh_exist(h->h, k))
{
cnt = kh_val(h->h, k) - beg;
break;
}
}
}
if(cnt > 0) radix_sort_hc_pos(pos_list, pos_list+cnt);
}
}
}
void hc_pt_t_gen(ha_ug_index* idx, pldat_t* pl)
{
if(pl == NULL)
{
uint64_t i;
for (i = 0; i < idx->tot; i++)
{
hc_pt_t_gen_single(&(idx->idx_buf[i]), &(idx->up_bound));
}
}
else
{
kt_for(pl->n_thread, worker_for_sort, pl, pl->h->tot);
}
}
static void worker_for(void *data, long i, int tid) // callback for kt_for()
{
pldat_t *pl = (pldat_t*)data;
hc_pt1_t *h = &(pl->h->idx_buf[i]);
uint64_t m = 0, beg, end, occ;
khint_t key;
int absent;
if(pl->is_cnt)
{
uint64_t* cnt = NULL;
if(pl->cnt[i].a.n > 2) radix_sort_b64(pl->cnt[i].a.a, pl->cnt[i].a.a + pl->cnt[i].a.n);
cnt = pl->cnt[i].a.a;
occ = pl->cnt[i].a.n;
for (m = beg = end = 0; m < occ; m++)
{
if(cnt[beg] == cnt[m])
{
end = m;
}
else
{
key = hc_pt_put(h->h, cnt[beg], &absent);
if(absent) kh_val(h->h, key) = 0;
kh_val(h->h, key) += (end - beg + 1);
kh_key(h->h, key) = (kh_key(h->h, key)&HIC_KEY_MODE)|
(kh_val(h->h, key)<HIC_MAX_COUNT?kh_val(h->h, key):HIC_MAX_COUNT);
beg = end = m;
}
}
if(occ > 0)
{
key = hc_pt_put(h->h, cnt[beg], &absent);
if(absent) kh_val(h->h, key) = 0;
kh_val(h->h, key) += (end - beg + 1);
kh_key(h->h, key) = (kh_key(h->h, key)&HIC_KEY_MODE)|
(kh_val(h->h, key)<HIC_MAX_COUNT?kh_val(h->h, key):HIC_MAX_COUNT);
}
pl->cnt[i].a.n = 0;
}
if(!pl->is_cnt)
{
ch_buf_t* pos = NULL;
uint64_t num, *pos_list = NULL, k, k_n, pos_k;
if(pl->buf[i].a.n > 2) radix_sort_ch_buf(pl->buf[i].a.a, pl->buf[i].a.a + pl->buf[i].a.n);
pos = pl->buf[i].a.a;
occ = pl->buf[i].a.n;
for (m = beg = end = 0; m < occ; m++)
{
if(pos[beg].key == pos[m].key)
{
end = m;
}
else
{
num = get_hc_pt1_count(pl->h, pos[beg].key, &pos_list);
if(num > 0)
{
k_n=(end-beg+1);pos_k=pos_list[num-1];pos_list[num-1]+=k_n;
for (k = 0; k < k_n; k++)
{
pos_list[pos_k+k] = pos[beg+k].pos;
}
}
beg = end = m;
}
}
if(occ > 0)
{
num = get_hc_pt1_count(pl->h, pos[beg].key, &pos_list);
if(num > 0)
{
k_n=(end-beg+1);pos_k=pos_list[num-1];pos_list[num-1]+=k_n;
for (k = 0; k < k_n; k++)
{
pos_list[pos_k+k] = pos[beg+k].pos;
}
}
}
pl->buf[i].a.n = 0;
}
}
void parallel_count_hc_pt1(pldat_t* pl)
{
uint64_t i, l = 0, uID, num_pos = 0, pos_thre;
uint64_t x[4], mask = (1ULL<<pl->h->k) - 1, shift = pl->h->k - 1, hash, pos, skip, bucket_mask = (1ULL<<pl->h->pre) - 1;
ma_utg_t *u = NULL;
ch_buf_t k_pos;
if(pl->is_cnt) l = ((pl->buf_bytes>>3)/pl->h->tot) + 1, pos_thre = pl->buf_bytes>>3;
if(!pl->is_cnt) l = ((pl->buf_bytes>>4)/pl->h->tot) + 1, pos_thre = pl->buf_bytes>>4;
for (i = 0; i < pl->h->tot; i++)
{
if(pl->is_cnt)
{
kv_resize(uint64_t, pl->cnt[i].a, l);
pl->cnt[i].a.n = 0;
}
if(!pl->is_cnt)
{
kv_resize(ch_buf_t, pl->buf[i].a, l);
pl->buf[i].a.n = 0;
}
}
for (uID = 0; uID < pl->h->ug->u.n; uID++)
{
u = &(pl->h->ug->u.a[uID]);
if(u->m == 0) continue;
for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < u->len; ++i) {
int c = seq_nt4_table[(uint8_t)u->s[i]];
///c = 00, 01, 10, 11
if (c < 4) { // not an "N" base
///x[0] & x[1] are the forward k-mer
///x[2] & x[3] are the reverse complementary k-mer
x[0] = (x[0] << 1 | (c&1)) & mask;
x[1] = (x[1] << 1 | (c>>1)) & mask;
x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1)) << shift;
x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
if (++l >= pl->h->k)
{
hash = hc_hash_long(x, &skip, pl->h->k);
if(skip == (uint64_t)-1) continue;
if(pl->is_cnt)
{
kv_push(uint64_t, pl->cnt[hash & bucket_mask].a, hash);
}
else
{
pos = (skip << 63) | ((uID << (64-pl->h->uID_bits))>>1) | (i & pl->h->pos_mode);
k_pos.key = hash; k_pos.pos = pos;
kv_push(ch_buf_t, pl->buf[hash & bucket_mask].a, k_pos);
}
num_pos++;
if(num_pos >= pos_thre)
{
num_pos = 0;
kt_for(pl->n_thread, worker_for, pl, pl->h->tot);
}
}
} else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
}
}
if(num_pos > 0) kt_for(pl->n_thread, worker_for, pl, pl->h->tot);
for (i = 0; i < pl->h->tot; i++)
{
if(pl->cnt[i].a.m > 0) kv_destroy(pl->cnt[i].a), kv_init(pl->cnt[i].a);
if(pl->buf[i].a.m > 0) kv_destroy(pl->buf[i].a), kv_init(pl->buf[i].a);
}
}
ha_ug_index* build_unitig_index(ma_ug_t *ug, int k)
{
ha_ug_index* idx = NULL; CALLOC(idx, 1);
pldat_t pl; pl.h = idx; pl.is_cnt = 1;
double index_time = yak_realtime(), beg_time;
init_ha_ug_index_opt(idx, ug, k, &pl);
beg_time = yak_realtime();
pl.is_cnt = 1;
parallel_count_hc_pt1(&pl);
fprintf(stderr, "[M::%s::%.3f] ==> Counting\n", __func__, yak_realtime()-beg_time);
beg_time = yak_realtime();
hc_pt_t_gen(pl.h, NULL);
fprintf(stderr, "[M::%s::%.3f] ==> Memory allocating\n", __func__, yak_realtime()-beg_time);
beg_time = yak_realtime();
pl.is_cnt = 0;
parallel_count_hc_pt1(&pl);
fprintf(stderr, "[M::%s::%.3f] ==> Filling pos\n", __func__, yak_realtime()-beg_time);
beg_time = yak_realtime();
hc_pt_t_gen(pl.h, &pl);
fprintf(stderr, "[M::%s::%.3f] ==> Sorting pos\n", __func__, yak_realtime()-beg_time);
fprintf(stderr, "[M::%s::%.3f] ==> HiC index has been built\n", __func__, yak_realtime()-index_time);
return idx;
}
void destory_hc_pt_index(ha_ug_index* idx)
{
if(idx->idx_buf)
{
uint64_t i = 0;
for (i = 0; i < idx->tot; i++)
{
if(idx->idx_buf[i].a) free(idx->idx_buf[i].a);
if(idx->idx_buf[i].h) hc_pt_destroy(idx->idx_buf[i].h);
}
free(idx->idx_buf);
}
}
inline void interpret_pos(const ha_ug_index* idx, s_hit *p, uint64_t* rev, uint64_t* uID,
uint64_t* ref_p, uint64_t* self_p, uint64_t* exact_len, uint64_t* total_len)
{
(*rev) = p->ref>>63;
(*uID) = (p->ref << 1) >> (64 - idx->uID_bits);
(*self_p) = (uint32_t)p->off_cnt;
///(*exact_len) = p->off_cnt >> 32;
(*exact_len) = (p->off_cnt>>32) & ((uint64_t)65535);
if(total_len != NULL)
{
///(*exact_len) = (p->off_cnt>>32) & ((uint64_t)65535);
(*total_len) = (p->off_cnt>>48) + (*exact_len);
}
if((p->ref & idx->pos_mode)>>(idx->pos_bits - 1))
{
(*ref_p) = (*self_p) - (p->ref&(idx->pos_mode>>1));
}
else
{
(*ref_p) = (*self_p) + (p->ref&(idx->pos_mode));
}
}
inline uint64_t check_exact_match(char* a, long long a_beg, long long a_total, char* b, long long b_beg,
long long b_total, long long Len, uint64_t rev, uint64_t dir)
{
long long i = 0;
if(rev == 0)
{
if(dir == 0)
{
for (i = 0; i < Len && a_beg < a_total && b_beg < b_total; i++)
{
if(a[a_beg++] != b[b_beg++]) return i;
}
}
else
{
for (i = 0; i < Len && a_beg >= 0 && b_beg >= 0; i++)
{
if(a[a_beg--] != b[b_beg--]) return i;
}
}
}
else
{
if(dir == 0)
{
for (i = 0; i < Len && a_beg < a_total && b_beg < b_total; i++)
{
if(a[a_beg] != b2rc[seq_nt4_table[(uint8_t)b[b_total - b_beg - 1]]]) return i;
a_beg++; b_beg++;
}
}
else
{
for (i = 0; i < Len && a_beg >= 0 && b_beg >= 0; i++)
{
if(a[a_beg] != b2rc[seq_nt4_table[(uint8_t)b[b_total - b_beg - 1]]]) return i;
a_beg--; b_beg--;
}
}
}
return i;
}
uint64_t debug_hash_value(char *r, uint64_t end, uint64_t k_mer)
{
uint64_t i;
uint64_t x[4], mask = (1ULL<<k_mer) - 1, shift = k_mer - 1, skip;
for (i = end + 1 - k_mer, x[0] = x[1] = x[2] = x[3] = 0; i <= end; i++)
{
int c = seq_nt4_table[(uint8_t)r[i]];
///c = 00, 01, 10, 11
if (c < 4) { // not an "N" base
///x[0] & x[1] are the forward k-mer
///x[2] & x[3] are the reverse complementary k-mer
x[0] = (x[0] << 1 | (c&1)) & mask;
x[1] = (x[1] << 1 | (c>>1)) & mask;
x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1)) << shift;
x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
}
}
return hc_hash_long(x, &skip, k_mer);
}
inline uint64_t collect_votes(s_hit* a, uint64_t n)
{
if(n == 0) return 0;
if(n == 1) return (a[0].off_cnt>>32); //seed length, is right
long long i = 0;
uint64_t cur_beg, cur_end, beg, end, ovlp = 0, tLen = 0;
cur_end = (uint32_t)a[n-1].off_cnt;
cur_beg = cur_end + 1 - (a[n-1].off_cnt>>32);
if(n >= 2)
{
for (i = n - 2; i >= 0; i--)
{
end = (uint32_t)a[i].off_cnt;
beg = end + 1 - (a[i].off_cnt>>32);
if(MAX(cur_beg, beg) <= MIN(cur_end, end))
{
cur_beg = MIN(cur_beg, beg);
///cur_end = MAX(cur_end, end);
}
else
{
ovlp += (cur_end + 1 - cur_beg);
cur_beg = beg;
cur_end = end;
}
}
}
ovlp += (cur_end + 1 - cur_beg);
tLen = (uint32_t)a[n-1].off_cnt + 1 - cur_beg;
tLen = tLen - ovlp;
tLen = tLen << 16;
return ovlp | tLen;
}
inline void compress_mapped_pos(const ha_ug_index* idx, kvec_vote* buf, uint64_t buf_iter, uint64_t max_i, uint64_t thres)
{
if(buf_iter >= buf->a.n)
{
buf->a.n = buf_iter;
return;
}
uint64_t rev, uID, ref_p, self_p, eLen, tLen, i, max_beg, max_end, cur_beg, cur_end, ovlp, max_eLen;
uint64_t secondLen = 0, second_i = (uint64_t)-1;
interpret_pos((ha_ug_index*)idx, &buf->a.a[max_i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
max_end = self_p;
max_beg = self_p + 1 - tLen;
max_eLen = eLen;
for (i = buf_iter; i < buf->a.n; i++)
{
if(i == max_i) continue;
interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
cur_end = self_p;
cur_beg = self_p + 1 - tLen;
if(MAX(cur_beg, max_beg) <= MIN(cur_end, max_end))
{
ovlp = MIN(cur_end, max_end) - MAX(cur_beg, max_beg) + 1;
if(ovlp > thres)
{
if(eLen >= max_eLen * 0.8)
{
buf->a.n = buf_iter;
return;
}
continue;
}
}
if(secondLen < eLen) secondLen = eLen, second_i = i;
}
if(second_i == (uint64_t)-1)
{
buf->a.a[buf_iter] = buf->a.a[max_i];
buf->a.n = buf_iter + 1;
}
else
{
buf->a.a[buf_iter] = buf->a.a[MIN(max_i, second_i)];
buf->a.a[buf_iter+1] = buf->a.a[MAX(max_i, second_i)];
buf->a.n = buf_iter + 2;
}
}
inline void print_pos_list(const ha_ug_index* idx, s_hit *l, uint64_t occ, uint64_t rid, uint64_t r1)
{
if(rid == 33045391 || rid == 4239289 || rid == 5267597 || rid == 34474764 || rid == 35016489
|| rid == 36002255 || rid == 37811694 || rid == 46805824)
{
uint64_t i, rev, uID, ref_p, self_p, cnt;
for (i = 0; i < occ; i++)
{
interpret_pos(idx, &l[i], &rev, &uID, &ref_p, &self_p, &cnt, NULL);
fprintf(stderr, "(r%lu) rid: %lu, i: %lu, rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu\n",
r1, rid, i, rev, uID, ref_p, self_p);
}
}
}
uint64_t get_longest_hit(char *r, uint64_t len, uint64_t k_mer, uint64_t self_p, uint64_t self_rev, kvec_vote* buf, const ha_ug_index* idx,
uint64_t *pos_list, uint64_t cnt, uint64_t* c_sfx)
{
uint64_t max_p, map_p_occ, i, j, m, rev, ref_p, u_len, uID, k_len;
s_hit *p = NULL;
///each k-mer at different unitigs
///rev:uID:pos
if(c_sfx) (*c_sfx) = (uint64_t)-1;
for (j = 0; j < cnt; j++)
{
///get
kv_pushp(s_hit, buf->a, &p);
rev = (pos_list[j]>>63) != self_rev;
ref_p = pos_list[j] & idx->pos_mode;
uID = (pos_list[j] << 1) >> (64 - idx->uID_bits);
u_len = idx->ug->u.a[uID].len;
if(rev) ref_p = u_len - 1 - (ref_p + 1 - k_mer);
p->off_cnt = self_p | ((uint64_t)k_mer << 32); ///high bits should be the legnth
p->ref = ref_p >= self_p? (ref_p-self_p)
: (self_p-ref_p) + ((uint64_t)1 << (idx->pos_bits - 1));
p->ref = (rev << 63)|(pos_list[j] & idx->uID_mode)|(p->ref&idx->pos_mode);
///extend
k_len = check_exact_match(r, self_p + 1, len, idx->ug->u.a[uID].s, ref_p + 1, u_len, len, rev, 0);
if(c_sfx && cnt == idx->hap_cnt && k_len < (*c_sfx)) (*c_sfx) = k_len;
p->off_cnt += ((uint64_t)k_len << 32) + k_len;
if(self_p >= k_mer && ref_p >= k_mer)
{
k_len = check_exact_match(r, self_p - k_mer, len, idx->ug->u.a[uID].s,
ref_p - k_mer, u_len, len, rev, 1);
p->off_cnt += ((uint64_t)k_len << 32);
}
// if(cnt > 0) fprintf(stderr, "inner j: %lu, rev: %lu, uID: %lu, ref_p: %lu, self_p: %u, len: %lu\n", j, rev, uID, ref_p, (uint32_t)p->off_cnt, p->off_cnt>>32);
}
p = buf->a.a + buf->a.n - cnt;
if(cnt > 1) radix_sort_hc_s_hit_off_cnt(p, p + cnt);
max_p = map_p_occ = 0;
for (j = 1, i = 0; j <= cnt; ++j)
{
if(j == cnt || p[j].off_cnt != p[i].off_cnt)
{
if((max_p>>32) < (p[i].off_cnt>>32))
{
max_p = p[i].off_cnt;
map_p_occ = j - i;
}
else if(((max_p>>32) == (p[i].off_cnt>>32)) && ((j - i) > map_p_occ))
{
max_p = p[i].off_cnt;
map_p_occ = j - i;
}
i = j;///must
}
}
buf->a.n -= cnt;
for (j = m = 0; j < cnt; j++)
{
if(p[j].off_cnt == max_p)
{
p[m] = p[j];
m++;
}
}
cnt = m;
buf->a.n += cnt;
// if(cnt > 0) fprintf(stderr, "max_p_offset: %u, max_p_len: %lu, map_p_occ: %lu\n", (uint32_t)max_p, max_p>>32, map_p_occ);
return max_p;
}
#define is_update_hit(mL, mR, cL, cR) (((mL)<(cL))||((mL)==(cL)&&(mR)<(cR)))
inline void compress_mapped_pos_advance(const ha_ug_index* idx, kvec_vote* buf, uint64_t buf_iter, uint64_t ovlp_thre)
{
if(buf_iter >= buf->a.n)
{
buf->a.n = buf_iter;
return;
}
s_hit *p = NULL;
uint64_t rev, uID, ref_p, self_p, eLen, tLen, i, j, cnt;
uint64_t max_beg = 0, max_end = 0, max_i, max_occ, cur_beg, cur_end, ovlp;
uint64_t second_i = (uint64_t)-1, second_occ;
uint64_t max_eLen, sec_eLen;
double max_eRate, sec_eRate, eRate;
p = buf->a.a + buf_iter;
cnt = buf->a.n - buf_iter;
if(cnt > 1) radix_sort_hc_s_hit_off_cnt(p, p + cnt); ///buf save all hits, here sort by offset in reads
max_eLen = 0; max_i = (uint64_t)-1; max_occ = 0; max_eRate = -1;
for (j = 1, i = 0; j <= cnt; ++j)
{
if(j == cnt || p[j].off_cnt != p[i].off_cnt)
{
///occ = j - i;
interpret_pos((ha_ug_index*)idx, &p[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
eRate = (double)(eLen)/(double)(tLen);
if(is_update_hit(max_eLen, max_eRate, eLen, eRate))
{
max_eLen = eLen; max_eRate = eRate;
max_end = self_p; max_beg = self_p + 1 - tLen;
max_i = i; max_occ = j - i;
}
// fprintf(stderr, "\n++++++[%lu, %lu] uID: %lu, ref_p: %lu, self_p: %lu, eLen: %lu, tLen: %lu, max_i: %lu\n",
// i, j, uID, ref_p, self_p, eLen, tLen, max_i);
i = j;///must
}
}
sec_eLen = 0; second_i = (uint64_t)-1; second_occ = 0; sec_eRate = -1;
for (j = 1, i = 0; j <= cnt; ++j)
{
if(j == cnt || p[j].off_cnt != p[i].off_cnt)
{
if(i != max_i)
{
interpret_pos((ha_ug_index*)idx, &p[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
eRate = (double)(eLen)/(double)(tLen);
cur_end = self_p;
cur_beg = self_p + 1 - tLen;
// fprintf(stderr, "\n----[%lu, %lu] uID: %lu, ref_p: %lu, self_p: %lu, eLen: %lu, tLen: %lu, max_i: %lu\n",
// i, j, uID, ref_p, self_p, eLen, tLen, max_i);
// fprintf(stderr, "max_beg: %lu, max_end: %lu, cur_beg: %lu, cur_end: %lu\n",
// max_beg, max_end, cur_beg, cur_end);
///overlap with max interval
if(MAX(cur_beg, max_beg) <= MIN(cur_end, max_end))
{
ovlp = MIN(cur_end, max_end) - MAX(cur_beg, max_beg) + 1;
/*******************************for debug************************************/
if(ovlp == MIN(max_end+1-max_end, tLen))///for non-unique k-mer
{
i = j;///must
continue;///fully contain
}
if(ovlp > ((max_end+1-max_end)*0.8) && eLen > (max_eLen*0.8))///best is not unique
{
buf->a.n = buf_iter;
return;
}
if(ovlp > ((max_end+1-max_end)*0.15) + 1)
{
i = j;///must
continue;///fully contain
}
// if(ovlp > (MIN((max_end+1-max_end), (cur_end+1-cur_end))*0.15) + 1)
// {
// if(eLen > (max_eLen*0.8))///best is not unique
// {
// buf->a.n = buf_iter;
// return;
// }
// i = j;///must
// continue;
// }
/*******************************for debug************************************/
}
if(is_update_hit(sec_eLen, sec_eRate, eLen, eRate))
{
sec_eLen = eLen; sec_eRate = eRate;
second_i = i; second_occ = j - i;
}
}
i = j;///must
}
}
// fprintf(stderr, "max_i: %lu, max_occ: %lu, second_i: %lu, second_occ: %lu\n",
// max_i, max_occ, second_i, second_occ);
if(second_i == (uint64_t)-1)
{
i = 0;
for (j = max_i; j < max_i + max_occ; j++, i++) p[i] = p[j];
}
else ///be carful about overwritten
{
i = 0;
if(max_i <= second_i)
{
for (j = max_i; j < max_i + max_occ; j++, i++) p[i] = p[j];
for (j = second_i; j < second_i + second_occ; j++, i++) p[i] = p[j];
}
else
{
for (j = second_i; j < second_i + second_occ; j++, i++) p[i] = p[j];
for (j = max_i; j < max_i + max_occ; j++, i++) p[i] = p[j];
}
}
buf->a.n = buf_iter + max_occ + second_occ;
}
void get_alignment(char *r, uint64_t len, uint64_t k_mer, kvec_vote* buf, const ha_ug_index* idx, uint64_t buf_iter, uint64_t rid)
{
uint64_t i, j, k, l = 0, k_len, c_sfx, m, skip, *pos_list = NULL, cnt, rev, self_p, ref_p, uID;
uint64_t x[4], mask = (1ULL<<k_mer) - 1, shift = k_mer - 1, hash;
///buf->a.n = 0;
for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < len; ++i) {
int c = seq_nt4_table[(uint8_t)r[i]];
///c = 00, 01, 10, 11
if (c < 4) { // not an "N" base
///x[0] & x[1] are the forward k-mer
///x[2] & x[3] are the reverse complementary k-mer
x[0] = (x[0] << 1 | (c&1)) & mask;
x[1] = (x[1] << 1 | (c>>1)) & mask;
x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1)) << shift;
x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
if (++l >= k_mer)
{
hash = hc_hash_long(x, &skip, k_mer);
if(skip == (uint64_t)-1) continue;
cnt = get_hc_pt1_count((ha_ug_index*)idx, hash, &pos_list);
if(cnt > idx->hap_cnt || cnt <= 0) continue;
if(cnt > 1)
{
for (j = 0; j < cnt; j++)
{
uID = (pos_list[j] << 1) >> (64 - idx->uID_bits);
for (k = j + 1; k < cnt; k++)
{
if(uID == ((pos_list[k] << 1) >> (64 - idx->uID_bits))) break;
}
if(k < cnt) break;
}
if(j < cnt) continue;
}
// if(cnt > 0) fprintf(stderr, "+i: %lu, l: %lu, cnt: %lu\n", i, l, cnt);
get_longest_hit(r, len, k_mer, i, skip, buf, idx, pos_list, cnt, &c_sfx);
// if(cnt > 0) fprintf(stderr, "c_sfx: %lu\n", c_sfx);
if(c_sfx != (uint64_t)-1)
{
k_len = c_sfx;
if((k_len + 1) >= k_mer)
{
l = 0, x[0] = x[1] = x[2] = x[3] = 0;
i = i + k_len - (k_mer - 1);
}
else
{
///l = i - (i + k_len - (k_mer - 1));
l = k_mer - k_len - 1;
}
}
// if(cnt > 0) fprintf(stderr, "-i: %lu, l: %lu\n", i, l);
}
} else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
}
if(buf->a.n - buf_iter == 0) return;
if(buf->a.n - buf_iter > 1) radix_sort_hc_s_hit_an1(buf->a.a + buf_iter, buf->a.a + buf->a.n);
uint64_t cur_ref_p, thres = (len * HIC_R_E_RATE) + 1, index_beg, ovlp;
i = m = buf_iter;
while (i < buf->a.n)
{
interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &cnt, NULL);
///fprintf(stderr, "after-i: %lu, uID: %lu, ref_p: %lu, self_p: %lu\n", i, uID, ref_p, self_p);
cur_ref_p = buf->a.a[i].ref;
index_beg = i;
///ref>>(idx->pos_bits-1) = (rev:1):(uID:uID-bits):(ref_pos>=self_pos:1)
while ((i < buf->a.n) &&
((buf->a.a[i].ref>>(idx->pos_bits-1)) == (cur_ref_p>>(idx->pos_bits-1))) &&
(buf->a.a[i].ref - cur_ref_p <= thres))
{
i++;
}
if(i - index_beg > 1)
{
radix_sort_hc_s_hit_an2(buf->a.a + index_beg, buf->a.a + i);//sort by self_p
}
ovlp = collect_votes(buf->a.a + index_beg, i - index_beg);
///fprintf(stderr, "i-1: %lu, self_p: %u\n", i-1, (uint32_t)buf->a.a[i - 1].off_cnt);
buf->a.a[m] = buf->a.a[i - 1];
buf->a.a[m].off_cnt = (buf->a.a[m].off_cnt << 32)>>32;
buf->a.a[m].off_cnt += ((uint64_t)ovlp<<32);
///fprintf(stderr, "m: %lu, self_p: %u\n", m, (uint32_t)buf->a.a[m].off_cnt);
m++;
}
buf->a.n = m;
/*******************************for debug************************************/
// for (i = buf_iter; i < buf->a.n; i++)
// {
// uint64_t eLen, tLen;
// interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// if(maxLen < eLen) fprintf(stderr, "ERROR1\n");
// if(i == max_i && maxLen != eLen) fprintf(stderr, "ERROR2\n");
// }
/*******************************for debug************************************/
///select the best alignment at [buf_iter, m)
/*******************************for debug************************************/
// fprintf(stderr, "len1:%lu, max_i: %lu\n", buf->a.n - buf_iter, max_i);
// for (i = buf_iter; i < buf->a.n; i++)
// {
// uint64_t eLen, tLen;
// interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "(%lu) rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu, eLen: %lu, tLen: %lu\n",
// i, rev, uID, ref_p, self_p, eLen, tLen);
// }
/*******************************for debug************************************/
compress_mapped_pos_advance(idx, buf, buf_iter, (k_mer * 0.1) > 0? (k_mer * 0.1) : 1);
/*******************************for debug************************************/
// fprintf(stderr, "len2:%lu, max_i: %lu\n", buf->a.n - buf_iter, max_i);
// for (i = buf_iter; i < buf->a.n; i++)
// {
// uint64_t eLen, tLen;
// interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "(%lu) rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu, eLen: %lu, tLen: %lu\n",
// i, rev, uID, ref_p, self_p, eLen, tLen);
// }
// if(buf->a.n != m) fprintf(stderr, "Changed\n");
// fprintf(stderr, "\n");
/*******************************for debug************************************/
}
inline void compress_mapped_pos_debug(const ha_ug_index* idx, kvec_vote* buf, uint64_t buf_iter, uint64_t max_i, uint64_t thres)
{
if(buf_iter >= buf->a.n)
{
buf->a.n = buf_iter;
return;
}
uint64_t rev, uID, ref_p, self_p, eLen, tLen, i, max_beg, max_end, cur_beg, cur_end, ovlp, max_eLen;
uint64_t secondLen = 0, second_i = (uint64_t)-1;
interpret_pos((ha_ug_index*)idx, &buf->a.a[max_i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
max_end = self_p;
max_beg = self_p + 1 - tLen;
max_eLen = eLen;
for (i = buf_iter; i < buf->a.n; i++)
{
if(i == max_i) continue;
interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
cur_end = self_p;
cur_beg = self_p + 1 - tLen;
if(MAX(cur_beg, max_beg) <= MIN(cur_end, max_end))
{
ovlp = MIN(cur_end, max_end) - MAX(cur_beg, max_beg) + 1;
if(ovlp > thres)
{
if(eLen >= max_eLen * 0.8)
{
buf->a.n = buf_iter;
return;
}
continue;
}
}
if(secondLen < eLen) secondLen = eLen, second_i = i;
}
if(second_i == (uint64_t)-1)
{
buf->a.a[buf_iter] = buf->a.a[max_i];
buf->a.n = buf_iter + 1;
}
else
{
buf->a.a[buf_iter] = buf->a.a[MIN(max_i, second_i)];
buf->a.a[buf_iter+1] = buf->a.a[MAX(max_i, second_i)];
buf->a.n = buf_iter + 2;
}
}
void get_alignment_debug(char *r, uint64_t len, uint64_t k_mer, kvec_vote* buf, const ha_ug_index* idx, uint64_t buf_iter, uint64_t rid)
{
uint64_t i, j, l = 0, m, skip, *pos_list = NULL, cnt, rev, self_p, ref_p, uID;
uint64_t x[4], mask = (1ULL<<k_mer) - 1, shift = k_mer - 1, hash;
/****************************may have bugs********************************/
/**
///buf->a.n = 0;
uint64_t k_len, c_sfx, k;
for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < len; ++i) {
int c = seq_nt4_table[(uint8_t)r[i]];
///c = 00, 01, 10, 11
if (c < 4) { // not an "N" base
///x[0] & x[1] are the forward k-mer
///x[2] & x[3] are the reverse complementary k-mer
x[0] = (x[0] << 1 | (c&1)) & mask;
x[1] = (x[1] << 1 | (c>>1)) & mask;
x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1)) << shift;
x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
if (++l >= k_mer)
{
hash = hc_hash_long(x, &skip, k_mer);
if(skip == (uint64_t)-1) continue;
cnt = get_hc_pt1_count((ha_ug_index*)idx, hash, &pos_list);
if(cnt > idx->hap_cnt || cnt <= 0) continue;
if(cnt > 1)
{
for (j = 0; j < cnt; j++)
{
uID = (pos_list[j] << 1) >> (64 - idx->uID_bits);
for (k = j + 1; k < cnt; k++)
{
if(uID == ((pos_list[k] << 1) >> (64 - idx->uID_bits))) break;
}
if(k < cnt) break;
}
if(j < cnt) continue;
}
// if(cnt > 0) fprintf(stderr, "+i: %lu, l: %lu, cnt: %lu\n", i, l, cnt);
get_longest_hit(r, len, k_mer, i, skip, buf, idx, pos_list, cnt, &c_sfx);
// if(cnt > 0) fprintf(stderr, "c_sfx: %lu\n", c_sfx);
if(c_sfx != (uint64_t)-1)
{
k_len = c_sfx;
if((k_len + 1) >= k_mer)
{
l = 0, x[0] = x[1] = x[2] = x[3] = 0;
i = i + k_len - (k_mer - 1);
}
else
{
///l = i - (i + k_len - (k_mer - 1));
l = k_mer - k_len - 1;
}
}
// if(cnt > 0) fprintf(stderr, "-i: %lu, l: %lu\n", i, l);
}
} else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
}
**/
s_hit *p = NULL; uint64_t u_len;
///buf->a.n = 0;
for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < len; ++i) {
int c = seq_nt4_table[(uint8_t)r[i]];
///c = 00, 01, 10, 11
if (c < 4) { // not an "N" base
///x[0] & x[1] are the forward k-mer
///x[2] & x[3] are the reverse complementary k-mer
x[0] = (x[0] << 1 | (c&1)) & mask;
x[1] = (x[1] << 1 | (c>>1)) & mask;
x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1)) << shift;
x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
if (++l >= k_mer)
{
hash = hc_hash_long(x, &skip, k_mer);
if(skip == (uint64_t)-1) continue;
/*******************************for debug************************************/
// if(debug_hash_value(r, i, k_mer) != hash)
// {
// fprintf(stderr, "ERROR\n");
// }
/*******************************for debug************************************/
cnt = get_hc_pt1_count((ha_ug_index*)idx, hash, &pos_list);
if(cnt > idx->hap_cnt) continue;
if(cnt != 1) continue; ///might be able to be disabled in future
for (j = 0; j < cnt; j++)
{
kv_pushp(s_hit, buf->a, &p);
rev = (pos_list[j]>>63) != skip;
self_p = i;
ref_p = pos_list[j] & idx->pos_mode;
uID = (pos_list[j] << 1) >> (64 - idx->uID_bits);
u_len = idx->ug->u.a[uID].len;
if(rev) ref_p = u_len - 1 - (ref_p + 1 - k_mer);
p->off_cnt = self_p | ((uint64_t)k_mer << 32); ///high bits should be the legnth
p->ref = ref_p >= self_p? (ref_p-self_p)
: (self_p-ref_p) + ((uint64_t)1 << (idx->pos_bits - 1));
p->ref = (rev << 63)|(pos_list[j] & idx->uID_mode)|(p->ref&idx->pos_mode);
/*******************************for debug************************************/
// if(check_exact_match(r, i + 1 - k_mer, len,
// idx->ug->u.a[uID].s, ref_p + 1 - k_mer, u_len, k_mer, rev, 0) != k_mer
// ||
// check_exact_match(r, i, len,
// idx->ug->u.a[uID].s, ref_p, u_len, k_mer, rev, 1) != k_mer)
// {
// fprintf(stderr, "ERROR\n");
// }
/*******************************for debug************************************/
}
if(cnt == 1)
{
///uint64_t debug_right = 0, debug_left = 0, debug_len;
j = check_exact_match(r, self_p + 1, len, idx->ug->u.a[uID].s, ref_p + 1, u_len, len, rev, 0);
///debug_right = j;
///if(j == 0) continue;
if((j + 1) >= k_mer)
{
l = 0, x[0] = x[1] = x[2] = x[3] = 0;
i = i + j - (k_mer - 1);
}
else
{
///l = i - (i + j - (k_mer - 1));
l = k_mer - j -1;
}
buf->a.a[buf->a.n-1].off_cnt += ((uint64_t)j << 32) + j;
if(self_p >= k_mer && ref_p >= k_mer)
{
j = check_exact_match(r, self_p - k_mer, len, idx->ug->u.a[uID].s,
ref_p - k_mer, u_len, len, rev, 1);
buf->a.a[buf->a.n-1].off_cnt += ((uint64_t)j << 32);
///debug_left = j;
}
// debug_len = check_exact_match(r, self_p + debug_right, len, idx->ug->u.a[uID].s,
// ref_p + debug_right, u_len, len, rev, 1);
// if(debug_len!= (debug_left + debug_right + k_mer))
// {
// fprintf(stderr, "debug_len: %lu, debug_left: %lu, debug_right: %lu\n",
// debug_len, debug_left, debug_right);
// }
}
}
} else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
}
/****************************may have bugs********************************/
if(buf->a.n - buf_iter == 0) return;
if(buf->a.n - buf_iter > 1) radix_sort_hc_s_hit_an1(buf->a.a + buf_iter, buf->a.a + buf->a.n);
uint64_t cur_ref_p, thres = (len * HIC_R_E_RATE) + 1, index_beg, ovlp;
/****************************may have bugs********************************/
uint64_t maxLen = 0, max_i = (uint64_t)-1;
/****************************may have bugs********************************/
i = m = buf_iter;
while (i < buf->a.n)
{
interpret_pos(idx, &buf->a.a[i], &rev, &uID, &ref_p, &self_p, &cnt, NULL);
cur_ref_p = buf->a.a[i].ref;
index_beg = i;
while ((i < buf->a.n) &&
((buf->a.a[i].ref>>(idx->pos_bits-1)) == (cur_ref_p>>(idx->pos_bits-1))) &&
(buf->a.a[i].ref - cur_ref_p <= thres))
{
i++;
}
if(i - index_beg > 1)
{
radix_sort_hc_s_hit_an2(buf->a.a + index_beg, buf->a.a + i);//sort by self_p
}
ovlp = collect_votes(buf->a.a + index_beg, i - index_beg);
buf->a.a[m] = buf->a.a[i - 1];
buf->a.a[m].off_cnt = (buf->a.a[m].off_cnt << 32)>>32;
buf->a.a[m].off_cnt += ((uint64_t)ovlp<<32);
m++;
/****************************may have bugs********************************/
if(maxLen < (ovlp&((uint64_t)65535))) maxLen = (ovlp&((uint64_t)65535)), max_i = m;
/****************************may have bugs********************************/
}
buf->a.n = m;
/****************************may have bugs********************************/
///compress_mapped_pos_advance(idx, buf, buf_iter, (k_mer * 0.1) > 0? (k_mer * 0.1) : 1);
compress_mapped_pos_debug(idx, buf, buf_iter, max_i, thres);
/****************************may have bugs********************************/
}
inline int is_unreliable_hits(long long rev, long long ref_p, long long tLen, uint64_t uID, trans_chain* t_ch)
{
uint64_t i;
long long p_beg, p_end;
bed_in* p = NULL;
if(rev)
{
p_end = ref_p;
p_beg = p_end + 1 - tLen;
}
else
{
p_beg = ref_p;
p_end = p_beg + tLen - 1;
}
if(p_beg < 0) p_beg = 0;
if(p_end < 0) p_end = 0;
p = &(t_ch->bed.a[uID]);
for (i = 0; i < p->n; i++)
{
if(inter_interval(p_beg, p_end, p->a[i].beg, p->a[i].end, NULL, NULL)) break;
}
if(p->n > 0 && i < p->n) return 1;
return 0;
}
void get_5_3_list(ha_ug_index* idx, s_hit* p, uint64_t cnt, s_hit** l5, uint64_t* l5_occ,
s_hit** l3, uint64_t* l3_occ)
{
(*l5) = (*l3) = NULL;
(*l5_occ) = (*l3_occ) = 0;
uint64_t i, j, rev, uID, ref_p, self_p, eLen, tLen, cur_beg, num;
uint64_t beg_5 = (uint64_t)-1;
for (j = 1, i = 0, num = 0; j <= cnt; ++j)
{
if(j == cnt || p[j].off_cnt != p[i].off_cnt)
{
interpret_pos((ha_ug_index*)idx, &p[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
///cur_end = self_p;
cur_beg = self_p + 1 - tLen;
num++;
if(cur_beg <= beg_5)
{
(*l3_occ) = (*l5_occ); (*l3) = (*l5);
beg_5 = cur_beg; (*l5_occ) = j - i; (*l5) = p + i;
}
else
{
(*l3_occ) = j - i; (*l3) = p + i;
}
i = j;///must
}
}
///if(num > 2) fprintf(stderr, "ERROR: get_5_3_list\n");
}
inline void set_pe_pos_hap(ha_ug_index* idx, s_hit *l1, uint64_t occ1, s_hit *l2, uint64_t occ2,
pe_hit_hap* x, uint64_t rid, trans_chain *t_ch)
{
if(occ1 == 0 || occ2 == 0) return;
uint64_t rev, uID, ref_p, self_p, eLen, tLen, i, is_unreliable = 0;
s_hit *l1_5 = NULL, *l1_3 = NULL, *l2_5 = NULL, *l2_3 = NULL;
uint64_t l1_5_occ = 0, l1_3_occ = 0, l2_5_occ = 0, l2_3_occ = 0;
/***************************for debug******************************/
// fprintf(stderr, "\nrid: %lu, occ1: %lu, occ2: %lu\n", rid, occ1, occ2);
// for (i = 0; i < occ1; i++)
// {
// interpret_pos(idx, &l1[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "***-1-rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu\n",
// rev, uID, ref_p, self_p);
// }
// for (i = 0; i < occ2; i++)
// {
// interpret_pos(idx, &l2[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "***-2-rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu\n",
// rev, uID, ref_p, self_p);
// }
/***************************for debug******************************/
get_5_3_list(idx, l1, occ1, &l1_5, &l1_5_occ, &l1_3, &l1_3_occ);
get_5_3_list(idx, l2, occ2, &l2_5, &l2_5_occ, &l2_3, &l2_3_occ);
if(l1_5_occ == 0 || l2_5_occ == 0) return;
x->id = rid;
MALLOC(x->a, l1_5_occ + l2_5_occ);
x->occ1 = 0;
for (i = 0; i < l1_5_occ; i++)
{
interpret_pos(idx, &l1_5[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
if(ref_p < self_p) continue;
ref_p -= self_p;
if(rev) ref_p = idx->ug->u.a[uID].len - 1 - ref_p;
if(t_ch && (is_unreliable_hits(rev, ref_p, tLen, uID, t_ch)))
{
is_unreliable = 1;
continue;
}
x->a[x->occ1++] = (rev<<63) | ((uID << (64-idx->uID_bits))>>1) | (ref_p & idx->pos_mode);
}
x->occ2 = x->occ1;
for (i = 0; i < l2_5_occ; i++)
{
interpret_pos(idx, &l2_5[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
if(ref_p < self_p) continue;
ref_p -= self_p;
if(rev) ref_p = idx->ug->u.a[uID].len - 1 - ref_p;
if(t_ch && (is_unreliable_hits(rev, ref_p, tLen, uID, t_ch)))
{
is_unreliable = 1;
continue;
}
x->a[x->occ2++] = (rev<<63) | ((uID << (64-idx->uID_bits))>>1) | (ref_p & idx->pos_mode);
}
x->occ2 -= x->occ1;
if(x->occ1 == 0 || x->occ2 == 0 || is_unreliable)
{
free(x->a); x->occ1 = x->occ2 = 0; x->a = NULL; x->id = (uint64_t)-1;
return;
}
if(x->occ1 > 1) radix_sort_hc64(x->a, x->a + x->occ1);
if(x->occ2 > 1) radix_sort_hc64(x->a + x->occ1, x->a + x->occ1 + x->occ2);
/***************************for debug******************************/
// fprintf(stderr, "-------------saved: x->occ1: %u, x->occ2: %u-------------\n", x->occ1, x->occ2);
// for (i = 0; i < x->occ1; i++)
// {
// fprintf(stderr, "###-1-rev: %lu, uID: %lu, ref_p: %lu\n",
// x->a[i]>>63, (x->a[i]<<1)>>(64-idx->uID_bits), x->a[i] & idx->pos_mode);
// }
// for (i = 0; i < x->occ2; i++)
// {
// fprintf(stderr, "###-2-rev: %lu, uID: %lu, ref_p: %lu\n",
// x->a[i+x->occ1]>>63, (x->a[i+x->occ1]<<1)>>(64-idx->uID_bits), x->a[i+x->occ1] & idx->pos_mode);
// }
// fprintf(stderr, "-------------get_pe_s-rev: %lu, uID: %lu, ref_p: %lu-------------\n",
// get_pe_s(*x)>>63, (get_pe_s(*x)<<1)>>(64-idx->uID_bits), get_pe_s(*x) & idx->pos_mode);
// fprintf(stderr, "-------------get_pe_e-rev: %lu, uID: %lu, ref_p: %lu-------------\n",
// get_pe_e(*x)>>63, (get_pe_e(*x)<<1)>>(64-idx->uID_bits), get_pe_e(*x) & idx->pos_mode);
/***************************for debug******************************/
}
inline void set_pe_pos(ha_ug_index* idx, s_hit *l1, uint64_t occ1, s_hit *l2, uint64_t occ2,
pe_hit* x, uint64_t rid, trans_chain* t_ch)
{
if(occ1 == 0 || occ2 == 0) return;
uint64_t rev, uID, ref_p, self_p, eLen, tLen, i, is_unreliable = 0;
s_hit *l1_5 = NULL, *l1_3 = NULL, *l2_5 = NULL, *l2_3 = NULL;
uint64_t l1_5_occ = 0, l1_3_occ = 0, l2_5_occ = 0, l2_3_occ = 0;
/***************************for debug******************************/
// fprintf(stderr, "\nrid: %lu, occ1: %lu, occ2: %lu\n", rid, occ1, occ2);
// for (i = 0; i < occ1; i++)
// {
// interpret_pos(idx, &l1[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "***-1-rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu\n",
// rev, uID, ref_p, self_p);
// }
// for (i = 0; i < occ2; i++)
// {
// interpret_pos(idx, &l2[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "***-2-rev: %lu, uID: %lu, ref_p: %lu, self_p: %lu\n",
// rev, uID, ref_p, self_p);
// }
/***************************for debug******************************/
get_5_3_list(idx, l1, occ1, &l1_5, &l1_5_occ, &l1_3, &l1_3_occ);
get_5_3_list(idx, l2, occ2, &l2_5, &l2_5_occ, &l2_3, &l2_3_occ);
if(l1_5_occ == 0 || l2_5_occ == 0) return;
x->id = rid; x->len = 0;
///if(l1_5_occ != 1 || l2_5_occ != 1) fprintf(stderr, "ERROR\n");
for (i = 0; i < l1_5_occ; i++)
{
interpret_pos(idx, &l1_5[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
if((ref_p + 1) < tLen) continue;
ref_p = ref_p + 1 - tLen;
if(rev) ref_p = idx->ug->u.a[uID].len - 1 - ref_p;
if(t_ch && (is_unreliable_hits(rev, ref_p, tLen, uID, t_ch)))
{
is_unreliable = 1;
continue;
}
x->s = (rev<<63) | ((uID << (64-idx->uID_bits))>>1) | (ref_p & idx->pos_mode);
x->len = tLen; x->len <<= 32;
}
for (i = 0; i < l2_5_occ; i++)
{
interpret_pos(idx, &l2_5[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
if((ref_p + 1) < tLen) continue;
ref_p = ref_p + 1 - tLen;
if(rev) ref_p = idx->ug->u.a[uID].len - 1 - ref_p;
if(t_ch && (is_unreliable_hits(rev, ref_p, tLen, uID, t_ch)))
{
is_unreliable = 1;
continue;
}
x->e = (rev<<63) | ((uID << (64-idx->uID_bits))>>1) | (ref_p & idx->pos_mode);
x->len |= tLen;
}
if(is_unreliable || x->s == (uint64_t)-1 || x->e == (uint64_t)-1)
{
x->id = x->s = x->e = x->len = (uint64_t)-1;
return;
}
/****************************may have bugs********************************/
// for (i = 0; i < l1_3_occ; i++)
// {
// interpret_pos(idx, &l1_3[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// if(uID != ((x->s << 1) >> (64 - idx->uID_bits)) &&
// uID != ((x->e << 1) >> (64 - idx->uID_bits)))
// {
// x->id = x->s = x->e = x->len = (uint64_t)-1;
// return;
// }
// }
// for (i = 0; i < l2_3_occ; i++)
// {
// interpret_pos(idx, &l2_3[i], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// if(uID != ((x->s << 1) >> (64 - idx->uID_bits)) &&
// uID != ((x->e << 1) >> (64 - idx->uID_bits)))
// {
// x->id = x->s = x->e = x->len = (uint64_t)-1;
// return;
// }
// }
/****************************may have bugs********************************/
/***************************for debug******************************/
// fprintf(stderr, "-------------saved: x->occ1: %u, x->occ2: %u-------------\n", x->occ1, x->occ2);
// for (i = 0; i < x->occ1; i++)
// {
// fprintf(stderr, "###-1-rev: %lu, uID: %lu, ref_p: %lu\n",
// x->a[i]>>63, (x->a[i]<<1)>>(64-idx->uID_bits), x->a[i] & idx->pos_mode);
// }
// for (i = 0; i < x->occ2; i++)
// {
// fprintf(stderr, "###-2-rev: %lu, uID: %lu, ref_p: %lu\n",
// x->a[i+x->occ1]>>63, (x->a[i+x->occ1]<<1)>>(64-idx->uID_bits), x->a[i+x->occ1] & idx->pos_mode);
// }
// fprintf(stderr, "-------------get_pe_s-rev: %lu, uID: %lu, ref_p: %lu-------------\n",
// get_pe_s(*x)>>63, (get_pe_s(*x)<<1)>>(64-idx->uID_bits), get_pe_s(*x) & idx->pos_mode);
// fprintf(stderr, "-------------get_pe_e-rev: %lu, uID: %lu, ref_p: %lu-------------\n",
// get_pe_e(*x)>>63, (get_pe_e(*x)<<1)>>(64-idx->uID_bits), get_pe_e(*x) & idx->pos_mode);
/***************************for debug******************************/
}
uint64_t if_debug_read(uint64_t rid)
{
if(rid == 1169718 || rid == 2665829 || rid == 4239289)
{
return 1;
}
return 0;
}
static void worker_for_alignment(void *data, long i, int tid) // callback for kt_for()
{
stepdat_t *s = (stepdat_t*)data;
///s->pos[i].id = (uint64_t)-1; s->pos[i].occ1 = s->pos[i].occ2 = 0; s->pos[i].a = NULL;
s->pos[i].id = s->pos[i].s = s->pos[i].e = s->pos[i].len = (uint64_t)-1;
/*******************************for debug************************************/
// if(!if_debug_read(s->id+i)) return;
// fprintf(stderr, "work-rid: %lu\n", (uint64_t)(s->id+i));
/*******************************for debug************************************/
uint64_t len1 = s->len[i]>>32, len2 = (uint32_t)s->len[i], occ1, occ2;
char *r1 = s->seq[i], *r2 = s->seq[i] + len1;
// fprintf(stderr, "**********R1**********\n");
s->pos_buf[tid].a.n = 0;
get_alignment(r1, len1, s->idx->k, &s->pos_buf[tid], s->idx, 0, s->id+i);
occ1 = s->pos_buf[tid].a.n;
if(occ1 == 0) return;
// fprintf(stderr, "**********R2**********\n");
get_alignment(r2, len2, s->idx->k, &s->pos_buf[tid], s->idx, occ1, s->id+i);
occ2 = s->pos_buf[tid].a.n - occ1;
if(occ2 == 0) return;
set_pe_pos((ha_ug_index*)s->idx, s->pos_buf[tid].a.a, occ1, s->pos_buf[tid].a.a + occ1, occ2, &(s->pos[i]), s->id+i, s->t_ch);
/*******************************for debug************************************/
// if(memcmp(r1, R1.r.a + R1.r_Len.a[s->id+i], len1) != 0)
// {
// fprintf(stderr, "haha1\n");
// }
// if(memcmp(r2, R2.r.a + R2.r_Len.a[s->id+i], len2) != 0)
// {
// fprintf(stderr, "haha2\n");
// }
// uint64_t j, rev, uID, ref_p, self_p, eLen, tLen;
// char dir[2] = {'+', '-'};
// fprintf(stderr, "(R1) %.*s\n", (int)(R1.name_Len.a[s->id + i + 1] - R1.name_Len.a[s->id+i]),
// R1.name.a + R1.name_Len.a[s->id+i]);
// for (j = 0; j < occ1; j++)
// {
// interpret_pos(s->idx, &s->pos_buf[tid].a.a[j], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "utg%.6lu\t%c\t%lu\t%lu-%lu\n", uID+1, dir[rev], ref_p, self_p + 1 - tLen, self_p);
// }
// fprintf(stderr, "(R2) %.*s\n", (int)(R2.name_Len.a[s->id + i + 1] - R2.name_Len.a[s->id+i]),
// R2.name.a + R2.name_Len.a[s->id+i]);
// for (j = 0; j < occ2; j++)
// {
// interpret_pos(s->idx, &s->pos_buf[tid].a.a[j+occ1], &rev, &uID, &ref_p, &self_p, &eLen, &tLen);
// fprintf(stderr, "utg%.6lu\t%c\t%lu\t%lu-%lu\n", uID+1, dir[rev], ref_p, self_p + 1 - tLen, self_p);
// }
// fprintf(stderr, "\n");
/*******************************for debug************************************/
}
static void *worker_pipeline(void *data, int step, void *in) // callback for kt_pipeline()
{
sldat_t *p = (sldat_t*)data;
///uint64_t total_base = 0, total_pair = 0;
if (step == 0) { // step 1: read a block of sequences
int ret1, ret2;
uint64_t l1, l2;
stepdat_t *s;
CALLOC(s, 1);
s->idx = p->idx; s->id = p->total_pair; s->t_ch = p->t_ch;
while (((ret1 = kseq_read(p->ks1)) >= 0)&&((ret2 = kseq_read(p->ks2)) >= 0))
{
if (p->ks1->seq.l < p->idx->k || p->ks2->seq.l < p->idx->k) continue;
if (s->n == s->m) {
s->m = s->m < 16? 16 : s->m + (s->n>>1);
REALLOC(s->len, s->m);
REALLOC(s->seq, s->m);
}
l1 = p->ks1->seq.l; l2 = p->ks2->seq.l;
MALLOC(s->seq[s->n], l1+l2);
s->sum_len += l1+l2;
memcpy(s->seq[s->n], p->ks1->seq.s, l1);
memcpy(s->seq[s->n]+l1, p->ks2->seq.s, l2);
s->len[s->n++] = (uint64_t)(l1<<32)|(uint64_t)l2;
if (s->sum_len >= p->chunk_size) break;
}
p->total_pair += s->n;
if (s->sum_len == 0) free(s);
else return s;
}
else if (step == 1) { // step 2: alignment
stepdat_t *s = (stepdat_t*)in;
CALLOC(s->pos_buf, p->n_thread);
CALLOC(s->pos, s->n);
int i;
kt_for(p->n_thread, worker_for_alignment, s, s->n);
for (i = 0; i < s->n; ++i) {
free(s->seq[i]);
p->total_base += (s->len[i]>>32) + (uint32_t)s->len[i];
}
free(s->seq); free(s->len);
for (i = 0; i < (int)p->n_thread; ++i) {
free(s->pos_buf[i].a.a);
}
free(s->pos_buf);
return s;
}
else if (step == 2) { // step 3: dump
stepdat_t *s = (stepdat_t*)in;
int i;
for (i = 0; i < s->n; ++i) {
// if(s->pos[i].a == NULL) continue;
// kv_push(pe_hit_hap, p->hits, s->pos[i]);
if(s->pos[i].s == (uint64_t)-1) continue;
kv_push(pe_hit, p->hits.a, s->pos[i]);
}
free(s->pos);
free(s);
}
return 0;
}
int load_reads(reads_t* x, const enzyme *fn1, const enzyme *fn2)
{
kv_init(x->name);
kv_init(x->name_Len);
kv_init(x->r);
kv_init(x->r_Len);
int ret;
uint64_t name_tot, base_total;
int i;
name_tot = base_total = 0;
for (i = 0; i < fn1->n && i < fn2->n; i++)
{
gzFile fp;
if ((fp = gzopen(fn1->a[i], "r")) == 0)
{
kv_destroy(x->name);
kv_destroy(x->name_Len);
kv_destroy(x->r);
kv_destroy(x->r_Len);
return 0;
}
kseq_t *ks;
ks = kseq_init(fp);
while (((ret = kseq_read(ks)) >= 0))
{
kv_push(uint64_t, x->name_Len, name_tot);
kv_resize(char, x->name, name_tot + ks->name.l);
memcpy(x->name.a + name_tot, ks->name.s, ks->name.l);
name_tot += ks->name.l;
kv_push(uint64_t, x->r_Len, base_total);
kv_resize(char, x->r, base_total + ks->seq.l);
memcpy(x->r.a + base_total, ks->seq.s, ks->seq.l);
base_total += ks->seq.l;
}
kseq_destroy(ks);
gzclose(fp);
}
kv_push(uint64_t, x->name_Len, name_tot);
kv_push(uint64_t, x->r_Len, base_total);
x->idx = 0;
return 1;
}
void test_reads(reads_t* x, const char *fn)
{
gzFile fp;
kseq_t *ks;
int ret, i = 0;
if ((fp = gzopen(fn, "r")) == 0) return;
ks = kseq_init(fp);
while (((ret = kseq_read(ks)) >= 0))
{
if(memcmp(ks->name.s, x->name.a + x->name_Len.a[i], ks->name.l) != 0)
{
fprintf(stderr, "ERROR222: i: %d, len: %lu\n", i, x->name_Len.a[i]);
}
i++;
}
kseq_destroy(ks);
gzclose(fp);
}
void destory_reads(reads_t* x)
{
kv_destroy(x->name);
kv_destroy(x->name_Len);
kv_destroy(x->r);
kv_destroy(x->r_Len);
}
void print_hits(ha_ug_index* idx, kvec_pe_hit* hits, const enzyme *fn1, const enzyme *fn2)
{
uint64_t k, shif = 64 - idx->uID_bits;
reads_t r1;
load_reads(&r1, fn1, fn2);
char dir[2] = {'+', '-'};
for (k = 0; k < hits->a.n; ++k)
{
fprintf(stderr, "%.*s\t%c\ts-utg%.6dl\t%lu\t%c\te-utg%.6dl\t%lu\ti:%lu\n",
(int)(r1.name_Len.a[hits->a.a[k].id + 1] - r1.name_Len.a[hits->a.a[k].id]),
r1.name.a + r1.name_Len.a[hits->a.a[k].id],
dir[hits->a.a[k].s>>63], (int)((hits->a.a[k].s<<1)>>shif)+1, hits->a.a[k].s&idx->pos_mode,
dir[hits->a.a[k].e>>63], (int)((hits->a.a[k].e<<1)>>shif)+1, hits->a.a[k].e&idx->pos_mode,
hits->a.a[k].id);
}
destory_reads(&r1);
}
inline void swap_pe_hit_hap(pe_hit_hap* x, pe_hit_hap* y)
{
pe_hit_hap tmp;
tmp = (*x); (*x) = (*y); (*y) = tmp;
}
void dedup_hits(kvec_pe_hit* hits)
{
double index_time = yak_realtime();
uint64_t k, l, m = 0, cur;
radix_sort_pe_hit_an1(hits->a.a, hits->a.a + hits->a.n);
for (k = 1, l = 0; k <= hits->a.n; ++k)
{
if (k == hits->a.n || hits->a.a[k].s != hits->a.a[l].s)
{
if (k - l > 1) radix_sort_pe_hit_an2(hits->a.a + l, hits->a.a + k);
cur = (uint64_t)-1;
while (l < k)
{
if(hits->a.a[l].e != cur)
{
cur = hits->a.a[l].e;
hits->a.a[m++] = hits->a.a[l];
}
l++;
}
l = k;
}
}
hits->a.n = m;
fprintf(stderr, "[M::%s::%.3f] ==> Dedup\n", __func__, yak_realtime()-index_time);
}
void sort_hits(kvec_pe_hit* hits)
{
double index_time = yak_realtime();
uint64_t k, l;
radix_sort_pe_hit_an1(hits->a.a, hits->a.a + hits->a.n);
for (k = 1, l = 0; k <= hits->a.n; ++k)
{
if (k == hits->a.n || (hits->a.a[k].s<<1) != (hits->a.a[l].s<<1))
{
if (k - l > 1) radix_sort_pe_hit_an2(hits->a.a + l, hits->a.a + k);
l = k;
}
}
fprintf(stderr, "[M::%s::%.3f] ==> Sort\n", __func__, yak_realtime()-index_time);
}
void destory_bubbles(bubble_type* bub)
{
if(bub->index) free(bub->index);
kv_destroy(bub->list);
kv_destroy(bub->num);
kv_destroy(bub->pathLen);
kv_destroy(bub->b_s_idx);
kv_destroy(bub->chain_weight);
asg_destroy(bub->b_g);
ma_ug_destroy(bub->b_ug);
}
void get_bubbles(bubble_type* bub, uint64_t id, uint32_t* beg, uint32_t* sink, uint32_t** a, uint32_t* n, uint64_t* pathBase)
{
if(a) (*a) = bub->list.a + bub->num.a[id] + 2;
if(n) (*n) = bub->num.a[id+1] - bub->num.a[id] - 2;
if(beg) (*beg) = bub->list.a[bub->num.a[id]];
if(sink) (*sink) = bub->list.a[bub->num.a[id] + 1];
if(pathBase) (*pathBase) = bub->pathLen.a[id];
}
void dfs_bubble_broken(asg_t *g, kvec_t_u32_warp* stack, kvec_t_u32_warp* result, uint8_t* vis_flag,
uint32_t vis_flag_n, uint32_t v_d, uint32_t beg_d, uint32_t sink_d)
{
memset(vis_flag, 0, vis_flag_n);
asg_arc_t *acur = NULL;
uint32_t cur, ncur, i, p_beg = (uint32_t)-1, p_sink = (uint32_t)-1, v;
stack->a.n = result->a.n = 0;
v = v_d;
if(v != (beg_d^1) && v != (sink_d^1)) kv_push(uint32_t, stack->a, v);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
vis_flag[cur] = 1;
if((v>>1) != (cur>>1)) kv_push(uint32_t, result->a, cur>>1);
ncur = asg_arc_n(g, cur);
acur = asg_arc_a(g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(vis_flag[acur[i].v]) continue;
if((acur[i].v>>1) == (beg_d>>1) || (acur[i].v>>1) == (sink_d>>1))
{
if((acur[i].v>>1) == (beg_d>>1)) p_beg = acur[i].v;
if((acur[i].v>>1) == (sink_d>>1)) p_sink = acur[i].v;
continue;
}
kv_push(uint32_t, stack->a, acur[i].v);
}
}
memset(vis_flag, 0, vis_flag_n);
v ^= 1;
if(v != (beg_d^1) && v != (sink_d^1)) kv_push(uint32_t, stack->a, v);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
vis_flag[cur] = 1;
if((v>>1) != (cur>>1)) kv_push(uint32_t, result->a, cur>>1);
ncur = asg_arc_n(g, cur);
acur = asg_arc_a(g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(vis_flag[acur[i].v]) continue;
if((acur[i].v>>1) == (beg_d>>1) || (acur[i].v>>1) == (sink_d>>1))
{
if((acur[i].v>>1) == (beg_d>>1)) p_beg = acur[i].v;
if((acur[i].v>>1) == (sink_d>>1)) p_sink = acur[i].v;
continue;
}
kv_push(uint32_t, stack->a, acur[i].v);
}
}
if(p_beg != (uint32_t)-1) kv_push(uint32_t, result->a, beg_d>>1);
if(p_sink != (uint32_t)-1) kv_push(uint32_t, result->a, sink_d>>1);
}
void dfs_bubble(asg_t *g, kvec_t_u32_warp* stack, kvec_t_u32_warp* result, uint32_t v, uint32_t beg, uint32_t sink)
{
asg_arc_t *acur = NULL;
uint32_t cur, ncur, i;
stack->a.n = result->a.n = 0;
v = v << 1;
kv_push(uint32_t, stack->a, v);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if((v>>1) != (cur>>1)) kv_push(uint32_t, result->a, cur>>1);
ncur = asg_arc_n(g, cur);
acur = asg_arc_a(g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if((acur[i].v>>1) == beg || (acur[i].v>>1) == sink) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
v = v + 1;
kv_push(uint32_t, stack->a, v);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if((v>>1) != (cur>>1)) kv_push(uint32_t, result->a, cur>>1);
ncur = asg_arc_n(g, cur);
acur = asg_arc_a(g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if((acur[i].v>>1) == beg || (acur[i].v>>1) == sink) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
}
uint32_t get_unitig_het_arb(ma_ug_t* ug, uint32_t uid, uint8_t *r_het_flag, kv_u_trans_t *ref, uint32_t m_het_occ,
uint32_t m_het_label, uint32_t p_het_label, uint32_t n_het_label)
{
if(ref && u_trans_n(*ref, uid) > 0) return m_het_label;
ma_utg_t *u = &(ug->u.a[uid]);
uint32_t k, rId;
uint32_t het_occ, hom_occ;
for (k = 0, het_occ = hom_occ = 0; k < u->n; k++)
{
rId = u->a[k]>>33;
if((r_het_flag[rId] & P_HET)) return m_het_label;
if((r_het_flag[rId] & C_HET) || (r_het_flag[rId] & P_HET))
{
het_occ++;
}
else
{
hom_occ++;
}
}
if((het_occ+hom_occ) == 0) return n_het_label; ///hom
if((het_occ > ((het_occ+hom_occ)*0.8)) && ((het_occ+hom_occ) > m_het_occ)) return m_het_label; ///must het
if(het_occ >= hom_occ) return p_het_label; ///potential het
return n_het_label; ///hom
}
void update_bub_b_s_idx(bubble_type* bub);
void identify_bubbles(ma_ug_t* ug, bubble_type* bub, uint8_t *r_het_flag, kv_u_trans_t *ref)
{
asg_cleanup(ug->g);
if (!ug->g->is_symm) asg_symm(ug->g);
uint32_t v, n_vtx = ug->g->n_seq * 2, i, k, mode = (((uint32_t)-1)<<2);
uint32_t beg, sink, n, *a, n_occ;
uint64_t pathLen;
bub->ug = ug;
bub->b_bub = bub->b_end_bub = bub->tangle_bub = bub->cross_bub = bub->mess_bub = 0;
if(bub->round_id == 0)
{
buf_t b; memset(&b, 0, sizeof(buf_t)); b.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));
uint64_t tLen = get_bub_pop_max_dist_advance(ug->g, &b);
kv_init(bub->list); kv_init(bub->num); kv_init(bub->pathLen);
kv_init(bub->b_s_idx); kv_malloc(bub->b_s_idx, ug->g->n_seq);
bub->b_ug = NULL; kv_init(bub->chain_weight);
bub->b_s_idx.n = ug->g->n_seq;
memset(bub->b_s_idx.a, -1, bub->b_s_idx.n * sizeof(uint64_t));
CALLOC(bub->index, n_vtx);
for (i = 0; i < ug->g->n_seq; i++) ug->g->seq[i].c = 0;
for (v = 0; v < n_vtx; ++v)
{
if(ug->g->seq[v>>1].del) continue;
if(asg_arc_n(ug->g, v) < 2) continue;
if((bub->index[v]&(uint32_t)3) != 0) continue;
if(asg_bub_pop1_primary_trio(ug->g, NULL, v, tLen, &b, (uint32_t)-1, (uint32_t)-1, 0, NULL, NULL, NULL, 0, 0))
{
//beg is v, end is b.S.a[0]
//note b.b include end, does not include beg
for (i = 0; i < b.b.n; i++)
{
if(b.b.a[i]==v || b.b.a[i]==b.S.a[0]) continue;
bub->index[b.b.a[i]] &= mode; bub->index[b.b.a[i]] += 1;
bub->index[b.b.a[i]^1] &= mode; bub->index[b.b.a[i]^1] += 1;
}
bub->index[v] &= mode; bub->index[v] += 2;
bub->index[b.S.a[0]^1] &= mode; bub->index[b.S.a[0]^1] += 3;
}
}
kvec_t_u32_warp stack, result;
kv_init(stack.a); kv_init(result.a);
for (v = 0; v < n_vtx; ++v)
{
if((bub->index[v]&(uint32_t)3) !=2) continue;
if(asg_bub_pop1_primary_trio(ug->g, NULL, v, tLen, &b, (uint32_t)-1, (uint32_t)-1, 0, &pathLen, NULL, NULL, 0, 0))
{
//note b.b include end, does not include beg
i = b.b.n + 1;
if(b.b.n == 2 || b.b.n == 3 || b.b.n == 5)
{
for (i = 0; i < b.b.n; i++)
{
if(b.b.a[i]==v || b.b.a[i]==b.S.a[0]) continue;
dfs_bubble(ug->g, &stack, &result, b.b.a[i]>>1, v>>1, b.S.a[0]>>1);
if((result.a.n + 3) != b.b.n && (result.a.n + 2) != b.b.n) break;
}
}
if(i == b.b.n)
{
kv_push(uint32_t, bub->num, v);
}
else
{
kv_push(uint32_t, bub->num, v + (1<<31));
}
}
}
kv_destroy(stack.a); kv_destroy(result.a);
radix_sort_u32(bub->num.a, bub->num.a + bub->num.n);
bub->s_bub = 0;
for (k = 0; k < bub->num.n; k++)
{
if((bub->num.a[k]>>31) == 0) bub->s_bub++;
v = (bub->num.a[k]<<1)>>1;
bub->num.a[k] = bub->list.n;
if(asg_bub_pop1_primary_trio(ug->g, NULL, v, tLen, &b, (uint32_t)-1, (uint32_t)-1, 0, &pathLen, NULL, NULL, 0, 0))
{
kv_push(uint64_t, bub->pathLen, pathLen);
//beg is v, end is b.S.a[0]
kv_push(uint32_t, bub->list, v);
kv_push(uint32_t, bub->list, b.S.a[0]^1);
//note b.b include end, does not include beg
for (i = 0; i < b.b.n; i++)
{
if(b.b.a[i]==v || b.b.a[i]==b.S.a[0]) continue;
kv_push(uint32_t, bub->list, b.b.a[i]);
}
}
}
kv_push(uint32_t, bub->num, bub->list.n);
free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
bub->f_bub = bub->num.n - 1; ///bub->s_bub = bub->num.n - 1;
for (i = 0; i < ug->g->n_seq; i++)
{
bub->index[i] = get_unitig_het_arb(ug, i, r_het_flag, ref, 20, M_het(*bub), P_het(*bub), (uint32_t)-1);
}
for (i = 0; i < bub->f_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, &pathLen);
for (v = n_occ = 0; v < n; v++)
{
bub->index[(a[v]>>1)] = i;
n_occ += ug->u.a[a[v]>>1].n;
}
// if((pathLen*2) >= ug->g->seq[beg>>1].len && (pathLen*2) >= ug->g->seq[sink>>1].len)
// {
// bub->index[(beg>>1)] = (uint32_t)-1;
// bub->index[(sink>>1)] = (uint32_t)-1;
// }
if(n_occ > 3)
{
if(bub->index[(beg>>1)] != M_het(*bub)) bub->index[(beg>>1)] = (uint32_t)-1;
if(bub->index[(sink>>1)] != M_het(*bub)) bub->index[(sink>>1)] = (uint32_t)-1;
}
v = beg>>1;
if(bub->b_s_idx.a[v] == (uint64_t)-1)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
else if((bub->b_s_idx.a[v] & 0xffffffff00000000) == 0xffffffff00000000)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
v = sink>>1;
if(bub->b_s_idx.a[v] == (uint64_t)-1)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
else if((bub->b_s_idx.a[v] & 0xffffffff00000000) == 0xffffffff00000000)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
}
for (i = 0; i < ug->g->n_seq; i++)
{
if(bub->index[i] == M_het(*bub)) bub->index[i] = P_het(*bub);
}
}
else
{
bub->num.n = bub->f_bub + 1;
bub->pathLen.n = bub->f_bub;
bub->list.n = bub->num.a[bub->num.n-1];
update_bub_b_s_idx(bub);
bub->check_het = 0;
asg_destroy(bub->b_g); bub->b_g = NULL;
ma_ug_destroy(bub->b_ug); bub->b_ug = NULL;
kv_destroy(bub->chain_weight); kv_init(bub->chain_weight);
}
bub->b_g = NULL;
bub->b_ug = NULL;
build_bub_graph(ug, bub);
// fprintf(stderr, "-bub->index[18759]: %u, bub->num.n: %u\n", (uint32_t)bub->index[18759], bub->num.n);
}
void print_bubbles(ma_ug_t* ug, bubble_type* bub, kvec_pe_hit* hits, hc_links* link, ha_ug_index* idx)
{
uint64_t tLen, t_utg, i, k;
uint32_t beg, sink, n, *a;
for (i = 0, tLen = 0; i < bub->ug->u.n; i++) tLen += bub->ug->u.a[i].len;
fprintf(stderr, "[M::%s] # unitigs: %lu, # bases: %lu\n", __func__, bub->ug->u.n, tLen);
for (i = 0, tLen = 0, t_utg = 0; i < bub->f_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
t_utg += n;
for (k = 0; k < n; k++)
{
tLen +=bub->ug->u.a[(a[k]>>1)].len;
}
}
fprintf(stderr, "[M::%s] # bubbles: %lu, # unitigs: %lu, # bases: %lu\n", __func__,
Get_bub_num(*bub), t_utg, tLen);
for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
{
if(IF_BUB(i, *bub))
{
t_utg++;
tLen +=bub->ug->u.a[i].len;
}
}
fprintf(stderr, "[M::%s] # bubbles: %lu, # unitigs: %lu, # bases: %lu\n", __func__,
Get_bub_num(*bub), t_utg, tLen);
for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
{
if(IF_HET(i, *bub))
{
t_utg++;
tLen +=bub->ug->u.a[i].len;
}
}
fprintf(stderr, "[M::%s] # het unitigs: %lu, # het bases: %lu\n", __func__, t_utg, tLen);
uint8_t* flag; CALLOC(flag, ug->g->n_seq);
uint64_t s_uid, e_uid, shif = 64 - idx->uID_bits;
if(hits)
{
for (k = 0; k < hits->a.n; ++k)
{
s_uid = ((hits->a.a[k].s<<1)>>shif);
e_uid = ((hits->a.a[k].e<<1)>>shif);
if(bub->index[s_uid] == (uint32_t)-1 || bub->index[e_uid] == (uint32_t)-1) continue;
if(IF_BUB(s_uid, *bub) && IF_BUB(e_uid, *bub))
{
flag[s_uid] |= 1;
flag[e_uid] |= 1;
continue;
}
if(IF_HET(s_uid, *bub) && IF_HET(e_uid, *bub))
{
flag[s_uid] |= 4;
flag[e_uid] |= 4;
continue;
}
if(IF_BUB(s_uid, *bub)) flag[s_uid] |= 2, flag[e_uid] |= 2;
if(IF_BUB(e_uid, *bub)) flag[e_uid] |= 2, flag[s_uid] |= 2;
}
}
else if(link)
{
for (i = 0; i < link->a.n; i++)
{
for (k = 0; k < link->a.a[i].e.n; ++k)
{
if(link->a.a[i].e.a[k].del) continue;
s_uid = i;
e_uid = link->a.a[i].e.a[k].uID;
if(bub->index[s_uid] == (uint32_t)-1 || bub->index[e_uid] == (uint32_t)-1) continue;
if(IF_BUB(s_uid, *bub) && IF_BUB(e_uid, *bub))
{
flag[s_uid] |= 1;
flag[e_uid] |= 1;
continue;
}
if(IF_HET(s_uid, *bub) && IF_HET(e_uid, *bub))
{
flag[s_uid] |= 4;
flag[e_uid] |= 4;
continue;
}
if(IF_BUB(s_uid, *bub)) flag[s_uid] |= 2, flag[e_uid] |= 2;
if(IF_BUB(e_uid, *bub)) flag[e_uid] |= 2, flag[s_uid] |= 2;
}
}
}
for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
{
if(flag[i] & (uint32_t)1)
{
t_utg++;
tLen +=bub->ug->u.a[i].len;
}
}
fprintf(stderr, "[M::%s] # bubble-chained unitigs: %lu, # bubble-chained bases: %lu\n",
__func__, t_utg, tLen);
for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
{
if((flag[i] & (uint32_t)1) || (flag[i] & (uint32_t)2))
{
t_utg++;
tLen +=bub->ug->u.a[i].len;
}
}
fprintf(stderr, "[M::%s] # (bubble && het)-chained unitigs: %lu, # (bubble && het)-chained bases: %lu\n",
__func__, t_utg, tLen);
for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
{
if((flag[i] & (uint32_t)1) || (flag[i] & (uint32_t)2) || (flag[i] & (uint32_t)4))
{
t_utg++;
tLen +=bub->ug->u.a[i].len;
}
}
fprintf(stderr, "[M::%s] # (bubble || het)-chained unitigs: %lu, # (bubble || het)-chained bases: %lu\n",
__func__, t_utg, tLen);
free(flag);
fprintf(stderr, "************bubble utgs************\n");
uint64_t pathLen;
for (i = 0, tLen = 0, t_utg = 0; i < bub->f_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, &pathLen);
t_utg += n;
fprintf(stderr, "(full-%lu)\tbeg:utg%.6u\tsink:utg%.6u\tpathLen:%lu\t%s\n",
i, (beg>>1)+1, (sink>>1)+1, pathLen, i < bub->s_bub? "s-bub":(i<bub->f_bub?"f-bub":"b-bub"));
for (k = 0; k < n; k++)
{
tLen +=bub->ug->u.a[(a[k]>>1)].len;
fprintf(stderr, "utg%.6u,", (a[k]>>1)+1);
}
fprintf(stderr, "\n");
///if(i < bub->s_bub && (n != 4 && n != 2 && n != 1)) fprintf(stderr, "weird\n");
}
for (i = bub->f_bub, tLen = 0, t_utg = 0; i < bub->f_bub + bub->b_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, &pathLen);
t_utg += n;
fprintf(stderr, "(broken-%lu)\tbeg:utg%.6u\tsink:utg%.6u\tpathLen:%lu\t%s\n",
i, (beg>>1)+1, (sink>>1)+1, pathLen, i < bub->s_bub? "s-bub":(i<bub->f_bub?"f-bub":"b-bub"));
for (k = 0; k < n; k++)
{
tLen +=bub->ug->u.a[(a[k]>>1)].len;
fprintf(stderr, "utg%.6u,", (a[k]>>1)+1);
}
fprintf(stderr, "\n");
}
// fprintf(stderr, "************het utgs************\n");
// for (i = 0; i < ug->g->n_seq; i++)
// {
// if(IF_HET(i, *bub)) fprintf(stderr, "utg%.6lu\n", i+1);
// }
// fprintf(stderr, "************het utgs************\n");
}
hc_edge* push_hc_edge(hc_linkeage* x, uint64_t uID, double weight, int dir, uint64_t* d)
{
uint64_t k, n;
hc_edge* a = NULL;
hc_edge* p = NULL;
if(dir == 0)
{
a = x->e.a;
n = x->e.n;
}
else
{
a = x->f.a;
n = x->f.n;
}
for (k = 0; k < n; k++)
{
if(a[k].del) continue;
if(a[k].uID == uID)
{
a[k].weight += weight;
if(d) a[k].dis = (*d);
return &(a[k]);
}
}
if(dir == 0)
{
kv_pushp(hc_edge, x->e, &p);
}
else
{
kv_pushp(hc_edge, x->f, &p);
}
///p->del = p->enzyme = 0;
p->del = 0;
p->uID = uID;
p->weight = weight;
if(d) p->dis = (*d);
return p;
}
long long get_enzyme_occ_debug(char* t, long long tlen, char* p, long long plen)
{
long long s = 0, j, occ = 0;
while(s <= (tlen - plen))
{
j = plen-1;
while(j >= 0)
{
if(seq_nt4_table[(uint8_t)t[s+j]] >= 4) break;
if((p[j] != t[s+j]) && seq_nt4_table[(uint8_t)p[j]] < 4) break;
j--;
}
if (j < 0) occ++;
s++;
}
return occ;
}
int check_exact_match(char* x, long long xlen, char* y, long long ylen)
{
long long i;
if(xlen != ylen) return 0;
for (i = 0; i < xlen; i++)
{
if(seq_nt4_table[(uint8_t)x[i]] >= 4) return 0;
if((x[i] != y[i]) && seq_nt4_table[(uint8_t)y[i]] < 4) return 0;
}
return 1;
}
long long get_enzyme_occ(char* t, long long tlen, char* p, long long plen)
{
long long i, c, s = 0, j, occ = 0;
int badchar[5]; badchar[0] = badchar[1] = badchar[2] = badchar[3] = badchar[4] = -1;
for (i = 0; i < plen; i++)
{
c = seq_nt4_table[(uint8_t)p[i]];
badchar[c] = i;
if(c == 4) badchar[0] = badchar[1] = badchar[2] = badchar[3] = i;
}
badchar[4] = -1;
while(s <= (tlen - plen))
{
j = plen-1;
while(j >= 0)
{
if(seq_nt4_table[(uint8_t)t[s+j]] >= 4) break;
if((p[j] != t[s+j]) && seq_nt4_table[(uint8_t)p[j]] < 4) break;
j--;
}
if (j < 0)
{
occ++;
///s += (s+m < n)? m-badchar[txt[s+m]] : 1;
s++;
}
else
{
/*******************************for debug************************************/
// long long f, end = s + MAX(1, j - badchar[seq_nt4_table[(uint8_t)t[s+j]]]);
// for (f = s+1; f < end; f++)
// {
// if(check_exact_match(t+f, plen, p, plen))
// {
// fprintf(stderr, "s: %lld, end: %lld, s+j: %lld, t[s+j]: %c, badchar: %d, j: %lld\n",
// s, end, s+j, t[s+j], badchar[seq_nt4_table[(uint8_t)t[s+j]]], j);
// }
// }
/*******************************for debug************************************/
s += MAX(1, j - badchar[seq_nt4_table[(uint8_t)t[s+j]]]);
}
}
return occ;
}
#define pdq_cnt(q) ((q).x.a[0])
void init_pdq(pdq* q, uint64_t utg_num)
{
kv_init(q->x); kv_push(uint64_t, q->x, 0);
kv_malloc(q->dis, utg_num); q->dis.n = utg_num;
kv_malloc(q->vis, utg_num); q->vis.n = utg_num;
uint64_t i;
for (i = 1; (uint64_t)(1<<i) < utg_num; i++);
q->uID_mode = ((uint64_t)-1) >> (64-i);
q->uID_shift = i;
}
void destory_pdq(pdq* q)
{
kv_destroy(q->x);
kv_destroy(q->dis);
kv_destroy(q->vis);
}
void reset_pdq(pdq* q)
{
q->x.n = 1; pdq_cnt(*q) = 0;
memset(q->dis.a, -1, sizeof(uint64_t)*q->dis.n);
memset(q->vis.a, 0, sizeof(uint8_t)*q->vis.n);
}
void swap_pdq(uint64_t* i, uint64_t* j)
{
uint64_t k;
k = (*i);
(*i) = (*j);
(*j) = k;
}
#define weight(q, i) (get_dv_adv((q).x.a[i], (q).uID_mode, (q).uID_shift, &(q).tmp_v, &(q).tmp_d))
uint64_t inline set_dv_adv(uint64_t v, uint64_t dis, uint64_t v_mode, uint64_t v_shift)
{
dis <<= v_shift; dis |= (v&v_mode);
return dis;
}
uint64_t inline get_dv_adv(uint64_t x, uint64_t v_mode, uint64_t v_shift, uint64_t* v, uint64_t* dis)
{
(*v) = x & v_mode;
(*dis) = x >> v_shift;
return (*dis);
}
void push_pdq(pdq* q, uint64_t v, uint64_t dis)
{
kv_push(uint64_t, q->x, set_dv_adv(v, dis, q->uID_mode, q->uID_shift));
pdq_cnt(*q)++;
int c_i = pdq_cnt(*q), p_i = c_i>>1;
while ((p_i > 0) && (weight(*q, c_i) < weight(*q, p_i)))
{
swap_pdq(&(q->x.a[c_i]), &(q->x.a[p_i]));
c_i = p_i;
p_i = c_i >> 1;
}
}
void pop_pdq(pdq* q, uint64_t* min_v, uint64_t* min_dis)
{
(*min_v) = (*min_dis) = (uint64_t)-1;
if(pdq_cnt(*q) == 0) return;
get_dv_adv((*q).x.a[1], (*q).uID_mode, (*q).uID_shift, min_v, min_dis);
/*******************************for debug************************************/
// uint64_t i;
// for (i = 1; i < q->x.n; i++)
// {
// if(weight(*q, i) < (*min_dis)) fprintf(stderr, "ERROR\n");
// }
/*******************************for debug************************************/
///min = q->x.a[1];
swap_pdq(&(q->x.a[1]), &(q->x.a[pdq_cnt(*q)]));
pdq_cnt(*q)--;
q->x.n--;
int c_i = 1, left_i, right_i, min_i, flag = 1;
while(flag == 1)
{
flag = 0;
left_i = c_i << 1;
right_i = left_i + 1;
if(left_i > (int)(pdq_cnt(*q)))
{
break; // both children are null
}
else if(right_i > (int)(pdq_cnt(*q)))
{
min_i = left_i; // right children is null
}
else
{
min_i = (weight(*q, left_i) < weight(*q, right_i))? left_i : right_i;
}
if(weight(*q, c_i) > weight(*q, min_i))
{
swap_pdq(&(q->x.a[c_i]), &(q->x.a[min_i]));
c_i = min_i;
flag = 1;
}
}
}
void get_shortest_path(uint32_t src, pdq* pq, asg_t *sg, uint32_t* pre)
{
uint64_t v, u, i, nv, w;
asg_arc_t *av = NULL;
reset_pdq(pq);
pq->dis.a[src] = 0;
if(pre) pre[src] = (uint32_t)-1;
push_pdq(pq, src, 0);
while (pdq_cnt(*pq) > 0)
{
pop_pdq(pq, &v, &w);
pq->vis.a[v] = 1;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
u = av[i].v;
w = (uint32_t)av[i].ul;
if(pq->vis.a[u] == 0 && pq->dis.a[u] > pq->dis.a[v] + w)
{
pq->dis.a[u] = pq->dis.a[v] + w;
push_pdq(pq, u, pq->dis.a[u]);
if(pre) pre[u] = v;
}
}
}
}
void all_pair_shortest_path(asg_t *sg, hc_links* link, MT* M)
{
hc_linkeage* t = NULL;
pdq pq;
init_pdq(&pq, sg->n_seq<<1);
uint32_t n_vtx = sg->n_seq<<1, v;
uint64_t k, *p = NULL;
for (v = 0; v < n_vtx; ++v)
{
if (sg->seq[v>>1].del) continue;
t = &(link->a.a[v>>1]);
if (t->e.n == 0) continue;
get_shortest_path(v, &pq, sg, NULL);
for (k = 0; k < pq.dis.n; k++)
{
if(pq.dis.a[k] == (uint64_t)-1) continue;
kv_pushp(uint64_t, M->matrix.a[v].a, &p);
(*p) = k << M->uID_shift;
(*p) = (*p) | pq.dis.a[k];
}
}
destory_pdq(&pq);
}
uint64_t LCA_distance(long long d_x, long long d_y, long long xLen, long long yLen, uint8_t* rev)
{
(*rev) = 0;
long long x_beg, x_end, y_beg, y_end, t_beg, t_end;
x_end = d_x; x_beg = x_end - xLen + 1;
y_end = d_y; y_beg = y_end - yLen + 1;
if(x_end >= y_end)
{
t_end = x_end; (*rev) = 0;
t_beg = y_beg;
}
else
{
t_end = y_end; (*rev) = 1;
t_beg = x_beg;
}
return t_end + 1 - t_beg;
}
uint64_t get_LCA_bubble(uint32_t x, uint64_t xLen, uint32_t y, uint64_t yLen, uint8_t* dis, uint64_t n, MT* M, bubble_type* bub, uint64_t* min_rev)
{
uint32_t j, v, k;
uint64_t u, d = (uint64_t)-1, tmp;
uint8_t rev;
uint32_t root[2], a_n, *a;
get_bubbles(bub, bub->index[x>>1], &root[0], &root[1], &a, &a_n, NULL);
root[0] ^= 1; root[1] ^= 1;
if(root[0] > root[1])
{
k = root[0];
root[0] = root[1];
root[1] = k;
}
dis[root[0]] = (uint8_t)-1;
dis[root[1]] = (uint8_t)-1;
v = x;
for (j = 0; j < M->matrix.a[v].a.n; j++)
{
u = M->matrix.a[v].a.a[j] >> M->uID_shift;
d = M->matrix.a[v].a.a[j] & M->dis_mode;
dis[u] = dis[u] >> 4;
}
v = y;
for (j = 0; j < M->matrix.a[v].a.n; j++)
{
u = M->matrix.a[v].a.a[j] >> M->uID_shift;
d = M->matrix.a[v].a.a[j] & M->dis_mode;
dis[u] = dis[u] >> 4;
}
uint64_t x_i = 0, y_i = 0, d_x, d_y, min_d = (uint64_t)-1;
uint32_t min_j = (uint32_t)-1;
(*min_rev) = (uint64_t)-1;
for (k = 0; k < 2; k++)
{
j = root[k];
if(dis[j] != 0)
{
dis[j] = (uint8_t)-1;
continue;
}
for (; x_i < M->matrix.a[x].a.n; x_i++)
{
u = M->matrix.a[x].a.a[x_i] >> M->uID_shift;
d = M->matrix.a[x].a.a[x_i] & M->dis_mode;
if(u == j) break;
}
if(x_i == M->matrix.a[x].a.n && M->matrix.a[x].a.n != 0) fprintf(stderr, "ERROR X\n");
d_x = d;
for (; y_i < M->matrix.a[y].a.n; y_i++)
{
u = M->matrix.a[y].a.a[y_i] >> M->uID_shift;
d = M->matrix.a[y].a.a[y_i] & M->dis_mode;
if(u == j) break;
}
if(y_i == M->matrix.a[y].a.n && M->matrix.a[y].a.n != 0) fprintf(stderr, "ERROR Y\n");
d_y = d;
tmp = LCA_distance(d_x, d_y, xLen, yLen, &rev);
if(tmp < min_d) min_d = tmp, (*min_rev) = rev, min_j = j;
}
if(min_j == x || min_j == y) return (uint64_t)-1;
return min_d;
}
uint64_t get_LCA(uint32_t x, uint64_t xLen, uint32_t y, uint64_t yLen, uint8_t* dis, uint64_t n, MT* M, bubble_type* bub, uint64_t* min_rev)
{
if(IF_BUB(x>>1, *bub) && IF_BUB(y>>1, *bub) && bub->index[x>>1] == bub->index[y>>1])
{
return get_LCA_bubble(x, xLen, y, yLen, dis, n, M, bub, min_rev);
}
else
{
memset(dis, -1, sizeof(uint8_t)*n);
}
uint32_t j, v;
uint64_t u, d = (uint64_t)-1, tmp;
uint8_t rev;
v = x;
for (j = 0; j < M->matrix.a[v].a.n; j++)
{
u = M->matrix.a[v].a.a[j] >> M->uID_shift;
d = M->matrix.a[v].a.a[j] & M->dis_mode;
dis[u] = dis[u] >> 4;
}
v = y;
for (j = 0; j < M->matrix.a[v].a.n; j++)
{
u = M->matrix.a[v].a.a[j] >> M->uID_shift;
d = M->matrix.a[v].a.a[j] & M->dis_mode;
dis[u] = dis[u] >> 4;
}
uint64_t x_i = 0, y_i = 0, d_x, d_y, min_d = (uint64_t)-1;
uint32_t min_j = (uint32_t)-1;
(*min_rev) = (uint64_t)-1;
for (j = 0; j < n; j++)
{
if(dis[j] != 0)
{
dis[j] = (uint8_t)-1;
continue;
}
for (; x_i < M->matrix.a[x].a.n; x_i++)
{
u = M->matrix.a[x].a.a[x_i] >> M->uID_shift;
d = M->matrix.a[x].a.a[x_i] & M->dis_mode;
if(u == j) break;
}
if(x_i == M->matrix.a[x].a.n && M->matrix.a[x].a.n != 0) fprintf(stderr, "ERROR X\n");
d_x = d;
for (; y_i < M->matrix.a[y].a.n; y_i++)
{
u = M->matrix.a[y].a.a[y_i] >> M->uID_shift;
d = M->matrix.a[y].a.a[y_i] & M->dis_mode;
if(u == j) break;
}
if(y_i == M->matrix.a[y].a.n && M->matrix.a[y].a.n != 0) fprintf(stderr, "ERROR Y\n");
d_y = d;
tmp = LCA_distance(d_x, d_y, xLen, yLen, &rev);
if(tmp < min_d) min_d = tmp, (*min_rev) = rev, min_j = j;
}
if(min_j == x || min_j == y) return (uint64_t)-1;
return min_d;
}
typedef struct { // data structure for each step in kt_pipeline()
asg_t *sg;
hc_links* link;
MT* M;
bubble_type* bub;
uint8_t** dis_buf;
} utg_d_t;
static void worker_for_dis(void *data, long i, int tid)
{
utg_d_t* s = (utg_d_t*)data;
hc_links* link = s->link;
MT* M = s->M;
bubble_type* bub = s->bub;
uint8_t* dis_buf = s->dis_buf[tid];
asg_t *sg = s->sg;
hc_linkeage* t = NULL;
uint32_t n_vtx = sg->n_seq<<1, v, u, k, j;
uint64_t d[2], db[2], q_u, min, min_i, min_b, rev[2], min_rev;
if (sg->seq[i].del) return;
t = &(link->a.a[i]);
if (t->e.n == 0) return;
for (k = 0; k < t->e.n; k++)
{
if(t->e.a[k].del) continue;
if(i == t->e.a[k].uID) continue;
u = t->e.a[k].uID;
for (v = ((uint64_t)(i)<<1); v < ((uint64_t)(i+1)<<1); v++)///two directions
{
d[0] = d[1] = db[0] = db[1] = (uint64_t)-1;
for (j = 0; j < M->matrix.a[v].a.n; j++)
{
q_u = M->matrix.a[v].a.a[j] >> M->uID_shift;
if((q_u>>1) == u) d[q_u&1] = (M->matrix.a[v].a.a[j] & M->dis_mode) + sg->seq[q_u>>1].len;
if((q_u>>1) > u) break;///just for speeding up, doesn't affect results
}
min = min_i = min_b = (uint64_t)-1;
if(t->e.a[k].dis != (uint64_t)-1) min = t->e.a[k].dis >> 3;
if(d[0] < min) min = d[0], min_i = 0, min_b = 0;
if(d[1] < min) min = d[1], min_i = 1, min_b = 0;
if(min_i != (uint64_t)-1 && min != (uint64_t)-1)
{
t->e.a[k].dis = min<<1;
t->e.a[k].dis += min_b;
t->e.a[k].dis <<=1;
t->e.a[k].dis += v&1;//s-direction
t->e.a[k].dis <<=1;
t->e.a[k].dis += min_i;//e-direction
}
}
///might be wrong
if(IF_BUB(i, *bub) && IF_BUB(u, *bub)
&& bub->index[i] != bub->index[u] && t->e.a[k].dis != (uint64_t)-1)
{
continue;
}
for (v = ((uint64_t)(i)<<1); v < ((uint64_t)(i+1)<<1); v++)
{
d[0] = d[1] = db[0] = db[1] = (uint64_t)-1;
db[0] = get_LCA(v, sg->seq[v>>1].len, u<<1, sg->seq[u].len,
dis_buf, n_vtx, M, bub, &rev[0]);
db[1] = get_LCA(v, sg->seq[v>>1].len, (u<<1) + 1, sg->seq[u].len,
dis_buf, n_vtx, M, bub, &rev[1]);
min = min_i = min_b = min_rev = (uint64_t)-1;
if(t->e.a[k].dis != (uint64_t)-1) min = t->e.a[k].dis >> 3;
if(db[0] < min) min = db[0], min_i = 0, min_b = 1, min_rev = rev[0];
if(db[1] < min) min = db[1], min_i = 1, min_b = 1, min_rev = rev[1];
if(min_i != (uint64_t)-1 && min != (uint64_t)-1)
{
t->e.a[k].dis = min<<1;
t->e.a[k].dis += min_b;
t->e.a[k].dis <<=1;
t->e.a[k].dis += ((v&1)^min_rev);//s-direction
t->e.a[k].dis <<=1;
t->e.a[k].dis += (min_i^min_rev);//e-direction
}
}
}
}
void fill_utg_distance_multi(asg_t *sg, hc_links* link, MT* M, bubble_type* bub)
{
// double index_time = yak_realtime();
uint32_t i;
utg_d_t s;
s.sg = sg; s.link = link; s.M = M; s.bub = bub;
s.dis_buf = (uint8_t**)malloc(sizeof(uint8_t*)*asm_opt.thread_num);
for (i = 0; i < (uint32_t)asm_opt.thread_num; i++)
{
s.dis_buf[i] = (uint8_t*)malloc(sizeof(uint8_t)*(s.sg->n_seq<<1));
}
kt_for(asm_opt.thread_num, worker_for_dis, &s, s.sg->n_seq);
for (i = 0; i < (uint32_t)asm_opt.thread_num; i++)
{
free(s.dis_buf[i]);
}
free(s.dis_buf);
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
void init_MT(MT* M, uint32_t n_vtx)
{
uint32_t v;
kv_init(M->matrix); kv_malloc(M->matrix, n_vtx); M->matrix.n = n_vtx;
for (v = 0; v < n_vtx; ++v) kv_init(M->matrix.a[v].a);
for (v = 1; (uint64_t)(1<<v) < n_vtx; v++);
M->uID_shift = 64 - v; M->dis_mode = ((uint64_t)-1) >> v;
}
void destory_MT(MT* M)
{
uint32_t v;
for (v = 0; v < M->matrix.n; ++v) kv_destroy(M->matrix.a[v].a);
kv_destroy(M->matrix);
}
int get_trans_ug_arch(uint32_t qn, uint32_t qs, uint32_t qe, uint32_t qLen,
uint32_t tn, uint32_t ts, uint32_t te, uint32_t tLen, uint32_t rev, asg_arc_t* t)
{
ma_hit_t h;
h.qns = qn;
h.qns = h.qns << 32;
h.qns = h.qns | qs;
h.qe = qe;
h.tn = tn;
h.ts = ts;
h.te = te;
h.rev = rev;
h.del = 0;
h.bl = h.el = h.ml = h.no_l_indel = 0;
return ma_hit2arc(&h, qLen, tLen, MAX(qLen, tLen) + 1, 0, 0, t);
}
void update_ug_by_trans(asg_t *sg, kv_u_trans_t *ta)
{
u_trans_t *a = NULL, *p = NULL;
uint32_t i, k, st, occ, n, m;
uint32_t qn, tn, qs, qe, ts, te, rev;
asg_arc_t t, *e = NULL;
long long r_qs, r_qe, r_ts, r_te;
int r;
for (k = occ = 0; k < ta->idx.n; k++)
{
a = u_trans_a(*ta, k);
n = u_trans_n(*ta, k);
for (st = 0, i = 1; i <= n; ++i)
{
if (i == n || a[i].tn != a[st].tn)
{
for (m = st, p = &(a[st]); m < i; m++)
{
if(a[m].nw > p->nw) p = &(a[m]);
}
if(p->f == RC_2)///dis-connected
{
rev = p->rev;
qn = p->qn;
qs = p->qs;
qe = p->qe - 1;
if(rev)
{
tn = p->tn;
ts = sg->seq[tn].len - (p->te - 1) - 1;
te = sg->seq[tn].len - p->ts - 1;
}
else
{
tn = p->tn;
ts = p->ts;
te = p->te - 1;
}
classify_hap_overlap(qs, qe, sg->seq[qn].len, ts, te, sg->seq[tn].len,
&r_qs, &r_qe, &r_ts, &r_te);
qs = r_qs; qe = r_qe + 1;
if(rev)
{
ts = sg->seq[tn].len - r_te - 1;
te = sg->seq[tn].len - r_ts - 1 + 1;
}
else
{
ts = r_ts; te = r_te + 1;
}
r = get_trans_ug_arch(qn, qs, qe, sg->seq[qn].len,
tn, ts, te, sg->seq[tn].len, rev, &t);
if(r >= 0)
{
e = asg_arc_pushp(sg);
*e = t;
occ++;
}
}
st = i;
}
}
}
if(occ > 0)
{
free(sg->idx);
sg->idx = 0;
sg->is_srt = 0;
asg_cleanup(sg);
}
asg_arc_del_trans(sg, asm_opt.gap_fuzz);
}
void push_LCA_edges(long long d_x, long long d_y, long long xLen, long long yLen,
uint32_t v, uint32_t w, uint64_t *e0, uint64_t *e1)
{
long long x_beg, x_end, y_beg, y_end;
uint64_t d, rev;
x_end = d_x; x_beg = x_end - xLen + 1;
y_end = d_y; y_beg = y_end - yLen + 1;
long long ovlp = ((MIN(x_end, y_end) >= MAX(x_beg, y_beg))?
MIN(x_end, y_end) - MAX(x_beg, y_beg) + 1 : 0);
if(ovlp != xLen && ovlp != yLen)
{
d = MAX(x_end, y_end) - MIN(x_beg, y_beg) + 1;
if(x_end >= y_end) rev = 1;
else rev = 0;
(*e0) = d;
(*e0) <<= 1;
(*e0) += 1;
(*e0) <<= 1;
(*e0) += ((v&1)^rev);//s-direction
(*e0) <<= 1;
(*e0) += ((w&1)^rev);//e-direction
rev ^= 1;
(*e1) = d;
(*e1) <<= 1;
(*e1) += 1;
(*e1) <<= 1;
(*e1) += ((w&1)^rev);//s-direction
(*e1) <<= 1;
(*e1) += ((v&1)^rev);//e-direction
}
else
{
if(xLen >= yLen) d = (x_beg + 1) + (y_end - y_beg + 1);
else d = (x_end - x_beg + 1) + (yLen - y_end - 1);
(*e0) = d;
(*e0) <<= 1;
(*e0) += 1;
(*e0) <<= 1;
(*e0) += (v&1);//s-direction
(*e0) <<= 1;
(*e0) += (w&1);//e-direction
if(xLen >= yLen) d = (y_end - y_beg + 1) + (xLen - x_end - 1);
else d = (y_beg + 1) + (x_end - x_beg + 1);
(*e1) = d;
(*e1) <<= 1;
(*e1) += 1;
(*e1) <<= 1;
(*e1) += (w&1);//s-direction
(*e1) <<= 1;
(*e1) += (v&1);//e-direction
}
}
void push_LCA_edges_rev(hc_edge *hx, hc_edge *hy,
long long xLen, long long yLen, long long rLen,
uint32_t v, uint32_t w, uint64_t *e0, uint64_t *e1)
{
long long x_beg, x_end, y_beg, y_end, dx, dy;
uint64_t d, rev;
dx = (hx->dis>>3);
if((hx->dis&(uint64_t)2))
{
x_beg = rLen - dx - 1; x_end = x_beg + xLen - 1;
}
else
{
x_end = dx; x_beg = x_end - xLen + 1;
}
dy = (hy->dis>>3);
if((hy->dis&(uint64_t)2))
{
y_beg = rLen - dy - 1; y_end = y_beg + yLen - 1;
}
else
{
y_end = dy; y_beg = y_end - yLen + 1;
}
long long ovlp = ((MIN(x_end, y_end) >= MAX(x_beg, y_beg))?
MIN(x_end, y_end) - MAX(x_beg, y_beg) + 1 : 0);
if(ovlp != xLen && ovlp != yLen)
{
d = MAX(x_end, y_end) - MIN(x_beg, y_beg) + 1;
if(x_end >= y_end) rev = 1;
else rev = 0;
(*e0) = d;
(*e0) <<= 1;
(*e0) += 1;
(*e0) <<= 1;
(*e0) += ((v&1)^rev);//s-direction
(*e0) <<= 1;
(*e0) += ((w&1)^rev);//e-direction
rev ^= 1;
(*e1) = d;
(*e1) <<= 1;
(*e1) += 1;
(*e1) <<= 1;
(*e1) += ((w&1)^rev);//s-direction
(*e1) <<= 1;
(*e1) += ((v&1)^rev);//e-direction
}
else
{
if(xLen >= yLen) d = (x_beg + 1) + (y_end - y_beg + 1);
else d = (x_end - x_beg + 1) + (yLen - y_end - 1);
(*e0) = d;
(*e0) <<= 1;
(*e0) += 1;
(*e0) <<= 1;
(*e0) += (v&1);//s-direction
(*e0) <<= 1;
(*e0) += (w&1);//e-direction
if(xLen >= yLen) d = (y_end - y_beg + 1) + (xLen - x_end - 1);
else d = (y_beg + 1) + (x_end - x_beg + 1);
(*e1) = d;
(*e1) <<= 1;
(*e1) += 1;
(*e1) <<= 1;
(*e1) += (w&1);//s-direction
(*e1) <<= 1;
(*e1) += (v&1);//e-direction
}
}
uint32_t up_contain(kv_u_trans_t *ta, hc_links* link, uint8_t *uc_idx, asg_t *sg, kvec_t_u64_warp *buf)
{
hc_edge *he = NULL, *ht = NULL, *hx = NULL;
uint64_t t_d = (uint64_t)-1, hd;
uint32_t qn, tn, qs, qe, ts, te, rev, is_c;
u_trans_t *a = NULL, *p = NULL;
asg_arc_t t;
uint32_t i, k, st, occ, n, m;
long long r_qs, r_qe, r_ts, r_te;
int r;
for (k = 0, buf->a.n = 0; k < ta->idx.n; k++)
{
if((uc_idx[k]&2)&&(!(uc_idx[k]&1)))///contain others
{
if(link->a.a[k].e.n == 0)
{
uc_idx[k] -= 2;
continue;
}
a = u_trans_a(*ta, k);
n = u_trans_n(*ta, k);
for (st = 0, i = 1; i <= n; ++i)
{
if (i == n || a[i].tn != a[st].tn)
{
for (m = st, p = &(a[st]); m < i; m++)
{
if(a[m].nw > p->nw) p = &(a[m]);
}
if(p->f == RC_2)///dis-connected
{
rev = p->rev;
qn = p->qn;
qs = p->qs;
qe = p->qe - 1;
if(rev)
{
tn = p->tn;
ts = sg->seq[tn].len - (p->te - 1) - 1;
te = sg->seq[tn].len - p->ts - 1;
}
else
{
tn = p->tn;
ts = p->ts;
te = p->te - 1;
}
classify_hap_overlap(qs, qe, sg->seq[qn].len, ts, te, sg->seq[tn].len,
&r_qs, &r_qe, &r_ts, &r_te);
qs = r_qs; qe = r_qe + 1;
if(rev)
{
ts = sg->seq[tn].len - r_te - 1;
te = sg->seq[tn].len - r_ts - 1 + 1;
}
else
{
ts = r_ts; te = r_te + 1;
}
r = get_trans_ug_arch(qn, qs, qe, sg->seq[qn].len,
tn, ts, te, sg->seq[tn].len, rev, &t);
if(r == MA_HT_TCONT)//q contains t
{
hd = tn; hd <<= 32; hd |= qn;
kv_push(uint64_t, buf->a, hd);
///qn->tn
he = get_hc_edge(link, qn, tn, 0);
if(!he)
{
push_hc_edge(&(link->a.a[qn]), tn, 0, 0, &t_d);
he = get_hc_edge(link, qn, tn, 0);
}
hd = (te - ts) + qs;
if(hd < he->dis)
{
he->dis = hd << 1;
he->dis += 1;
he->dis <<= 1;
he->dis += 0;//s-direction
he->dis <<= 1;
he->dis += rev;//e-direction
}
///tn->qn
he = get_hc_edge(link, tn, qn, 0);
if(!he)
{
push_hc_edge(&(link->a.a[tn]), qn, 0, 0, &t_d);
he = get_hc_edge(link, tn, qn, 0);
}
hd = (te - ts) + sg->seq[qn].len - qe;
if(hd < he->dis)
{
he->dis = hd << 1;
he->dis += 1;
he->dis <<= 1;
he->dis += 0;//s-direction
he->dis <<= 1;
he->dis += rev;//e-direction
}
}
}
st = i;
}
}
uc_idx[k] -= 2;
}
}
uint64_t e0, e1;
for (k = 0; k < buf->a.n; k++)
{
qn = buf->a.a[k] >> 32;
tn = (uint32_t)buf->a.a[k];
he = get_hc_edge(link, tn, qn, 0); //tn contains qn
for (i = 0; i < link->a.a[tn].e.n; i++)
{
if(link->a.a[tn].e.a[i].del) continue;
if(link->a.a[tn].e.a[i].uID == qn) continue;
ht = &(link->a.a[tn].e.a[i]);
if(ht->dis == (uint64_t)-1) continue;
if((he->dis&(uint64_t)2) == (ht->dis&(uint64_t)2))///s in same direction
{
push_LCA_edges(he->dis>>3, ht->dis>>3, sg->seq[he->uID].len, sg->seq[ht->uID].len,
he->dis&1, ht->dis&1, &e0, &e1);
///forward
hx = get_hc_edge(link, he->uID, ht->uID, 0);
if(!hx)
{
push_hc_edge(&(link->a.a[he->uID]), ht->uID, 0, 0, &t_d);
hx = get_hc_edge(link, he->uID, ht->uID, 0);
}
if ((e0>>3) < (hx->dis>>3)) hx->dis = e0;
///backward
hx = get_hc_edge(link, ht->uID, he->uID, 0);
if(!hx)
{
push_hc_edge(&(link->a.a[ht->uID]), he->uID, 0, 0, &t_d);
hx = get_hc_edge(link, ht->uID, he->uID, 0);
}
if ((e1>>3) < (hx->dis>>3)) hx->dis = e1;
}
else
{
push_LCA_edges_rev(he, ht, sg->seq[he->uID].len, sg->seq[ht->uID].len,
sg->seq[tn].len, he->dis&1, ht->dis&1, &e0, &e1);
///forward
hx = get_hc_edge(link, he->uID, ht->uID, 0);
if(!hx)
{
push_hc_edge(&(link->a.a[he->uID]), ht->uID, 0, 0, &t_d);
hx = get_hc_edge(link, he->uID, ht->uID, 0);
}
if ((e0>>3) < (hx->dis>>3)) hx->dis = e0;
///backward
hx = get_hc_edge(link, ht->uID, he->uID, 0);
if(!hx)
{
push_hc_edge(&(link->a.a[ht->uID]), he->uID, 0, 0, &t_d);
hx = get_hc_edge(link, ht->uID, he->uID, 0);
}
if ((e1>>3) < (hx->dis>>3)) hx->dis = e1;
}
}
}
for (k = 0, occ = 0; k < ta->idx.n; k++)
{
if((uc_idx[k]&1) && (uc_idx[k]&2))
{
is_c = 0;
a = u_trans_a(*ta, k);
n = u_trans_n(*ta, k);
for (st = 0, i = 1; i <= n; ++i)
{
if (i == n || a[i].tn != a[st].tn)
{
for (m = st, p = &(a[st]); m < i; m++)
{
if(a[m].nw > p->nw) p = &(a[m]);
}
if(p->f == RC_2)///dis-connected
{
rev = p->rev;
qn = p->qn;
qs = p->qs;
qe = p->qe - 1;
if(rev)
{
tn = p->tn;
ts = sg->seq[tn].len - (p->te - 1) - 1;
te = sg->seq[tn].len - p->ts - 1;
}
else
{
tn = p->tn;
ts = p->ts;
te = p->te - 1;
}
classify_hap_overlap(qs, qe, sg->seq[qn].len, ts, te, sg->seq[tn].len,
&r_qs, &r_qe, &r_ts, &r_te);
qs = r_qs; qe = r_qe + 1;
if(rev)
{
ts = sg->seq[tn].len - r_te - 1;
te = sg->seq[tn].len - r_ts - 1 + 1;
}
else
{
ts = r_ts; te = r_te + 1;
}
r = get_trans_ug_arch(qn, qs, qe, sg->seq[qn].len,
tn, ts, te, sg->seq[tn].len, rev, &t);
if(r == MA_HT_QCONT && (uc_idx[tn]&2))//t contains q
{
is_c = 1;
}
}
st = i;
}
}
if(is_c == 0) uc_idx[k] -= 1;
}
if(uc_idx[k]&2) occ++;
}
return occ;
}
void print_u_trans_t(u_trans_t *p)
{
fprintf(stderr, "q-utg%.6ul\tqs(%u)\tqe(%u)\tt-utg%.6ul\tts(%u)\tte(%u)\trev(%u)\tw(%f)\n", p->qn+1, p->qs, p->qe, p->tn+1, p->ts, p->te, p->rev, p->nw);
}
void update_containment_distance(asg_t *sg, kv_u_trans_t *ta, hc_links* link)
{
uint8_t *uc_idx = NULL;
CALLOC(uc_idx, sg->n_seq);
u_trans_t *a = NULL, *p = NULL;
uint32_t i, k, st, n, m;
uint32_t qn, tn, qs, qe, ts, te, rev;
asg_arc_t t;
long long r_qs, r_qe, r_ts, r_te;
int r;
for (k = 0; k < ta->idx.n; k++)
{
a = u_trans_a(*ta, k);
n = u_trans_n(*ta, k);
for (st = 0, i = 1; i <= n; ++i)
{
if (i == n || a[i].tn != a[st].tn)
{
for (m = st, p = &(a[st]); m < i; m++)
{
if(a[m].nw > p->nw) p = &(a[m]);
}
if(p->f == RC_2)///dis-connected
{
rev = p->rev;
qn = p->qn;
qs = p->qs;
qe = p->qe - 1;
if(rev)
{
tn = p->tn;
ts = sg->seq[tn].len - (p->te - 1) - 1;
te = sg->seq[tn].len - p->ts - 1;
}
else
{
tn = p->tn;
ts = p->ts;
te = p->te - 1;
}
classify_hap_overlap(qs, qe, sg->seq[qn].len, ts, te, sg->seq[tn].len,
&r_qs, &r_qe, &r_ts, &r_te);
qs = r_qs; qe = r_qe + 1;
if(rev)
{
ts = sg->seq[tn].len - r_te - 1;
te = sg->seq[tn].len - r_ts - 1 + 1;
}
else
{
ts = r_ts; te = r_te + 1;
}
r = get_trans_ug_arch(qn, qs, qe, sg->seq[qn].len,
tn, ts, te, sg->seq[tn].len, rev, &t);
if(r == MA_HT_QCONT) uc_idx[qn] |= 1;
else if(r == MA_HT_TCONT) uc_idx[qn] |= 2;
// if(r < 0) print_u_trans_t(p);
}
st = i;
}
}
}
kvec_t_u64_warp buf; kv_init(buf.a);
while(up_contain(ta, link, uc_idx, sg, &buf))
{
if(buf.a.n != 0) continue;
for (k = 0; k < ta->idx.n; k++)
{
if((uc_idx[k]&1) && (uc_idx[k]&2))
{
uc_idx[k] = 2;
break;
}
}
}
kv_destroy(buf.a);
}
void collect_hc_links(const ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, MT* M)
{
double index_time = yak_realtime();
uint64_t k, i, shif = 64 - idx->uID_bits, beg, end, t_d;
for (k = 0; k < hits->a.n; ++k)
{
beg = ((hits->a.a[k].s<<1)>>shif);
end = ((hits->a.a[k].e<<1)>>shif);
if(beg == end) continue;
if(IF_HOM(beg, *bub)) continue;
if(IF_HOM(end, *bub)) continue;
t_d = (uint64_t)-1;
push_hc_edge(&(link->a.a[beg]), end, 0, 0, &t_d);
push_hc_edge(&(link->a.a[end]), beg, 0, 0, &t_d);
}
asg_t *copy_sg = copy_read_graph(idx->ug->g);
update_ug_by_trans(copy_sg, &(idx->t_ch->k_trans));
all_pair_shortest_path(copy_sg, link, M);
fill_utg_distance_multi(copy_sg, link, M, bub);
update_containment_distance(copy_sg, &(idx->t_ch->k_trans), link);
asg_destroy(copy_sg);
fprintf(stderr, "[M::%s::%.3f] ==> Hi-C linkages have been counted\n", __func__, yak_realtime()-index_time);
return;
index_time = yak_realtime();
for (k = 0; k < link->enzymes.n; k++)
{
link->enzymes.a[k] = 0;
for (i = 0; i < (uint64_t)asm_opt.hic_enzymes->n; i++)
{
link->enzymes.a[k] += get_enzyme_occ(idx->ug->u.a[k].s, idx->ug->u.a[k].len,
asm_opt.hic_enzymes->a[i], asm_opt.hic_enzymes->l[i]);
}
}
fprintf(stderr, "[M::%s::%.3f] ==> Enzymes have been counted\n", __func__, yak_realtime()-index_time);
}
void update_dis_connected_gfa(asg_t *sg, hc_links *link, MT *M)
{
uint32_t i, m, v, nv, x, y;
asg_arc_t *av = NULL;
kvec_t(uint32_t) stack; kv_init(stack);
uint32_t *flag = NULL; MALLOC(flag, sg->n_seq);
uint64_t *group = NULL; MALLOC(group, sg->n_seq);
for (i = 0; i < link->a.n; i++)
{
for (m = 0; m < link->a.a[i].e.n; m++)
{
if(link->a.a[i].e.a[m].dis == (uint64_t)-1)
{
if(link->a.a[i].e.a[m].is_cc != 0)
{
fprintf(stderr, "ERROR 1\n");
}
}
if(link->a.a[i].e.a[m].occ == (uint64_t)-1)
{
if(link->a.a[i].e.a[m].is_cc != 0 || link->a.a[i].e.a[m].dis == (uint64_t)-1)
{
fprintf(stderr, "ERROR 2\n");
}
}
}
}
memset(flag, -1, sg->n_seq*sizeof(uint32_t));
// connected componets
for (i = 0; i < sg->n_seq; ++i) {
if (flag[i] != (uint32_t)-1) continue;
stack.n = 0;
kv_push(uint32_t, stack, i);
while (stack.n > 0) {
stack.n--;
flag[stack.a[stack.n]] = i;///group id
v = (stack.a[stack.n])<<1;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (m = 0; m < nv; ++m) {
if (flag[av[m].v>>1] != (uint32_t)-1) continue;
kv_push(uint32_t, stack, av[m].v>>1);
}
v++;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (m = 0; m < nv; ++m) {
if (flag[av[m].v>>1] != (uint32_t)-1) continue;
kv_push(uint32_t, stack, av[m].v>>1);
}
}
}
kv_destroy(stack);
// precalculate the size of each group
for (i = 0; i < sg->n_seq; ++i)
group[i] = (uint64_t)flag[i] << 32 | i;
radix_sort_hc64(group, group + sg->n_seq);
for (i = 1, x = y = 0; i <= sg->n_seq; ++i) {
if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32)) {
uint32_t j;
for (j = x; j < i; ++j)
group[j] = (uint64_t)y << 32 | (uint32_t)group[j];///(group id)|first element in this group
++y, x = i;
}
}
memset(flag, 0, sg->n_seq*sizeof(uint32_t));
for (i = 1, x = y = 0; i <= sg->n_seq; ++i)
{
if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32))
{
x = i;
}
}
free(flag);
}
void append_tig_link(uint64_t *cc, uint32_t cc_off, uint32_t cc_size, hc_links *link, asg_t *sg, kvec_t_u32_warp *buf)
{
uint32_t i, k, id, tig_occ, b_cc_occ, *tig, *b_cc, qn, tn;
uint64_t t_d = (uint64_t)-1;
hc_edge *p = NULL;
for (i = 0; i < cc_size; ++i) ///how many nodes
{
id = (uint32_t)cc[cc_off + i];///node id
for (k = 0; k < link->a.a[id].e.n; k++)
{
if(link->a.a[id].e.a[k].is_cc == 0) break;
}
if(k < link->a.a[id].e.n) break;
}
if(i >= cc_size) return;
buf->a.n = 0; tig_occ = 0;
for (i = 0; i < cc_size; ++i) ///how many nodes
{
id = (uint32_t)cc[cc_off + i];///node id
if(asg_arc_n(sg, (id<<1)) == 0 || asg_arc_n(sg, ((id<<1)+1)) == 0)///tig
{
kv_push(uint32_t, buf->a, id);
tig_occ++;
}
}
if(tig_occ == 0) return;
b_cc_occ = 0;
for (i = 0; i < cc_size; ++i) ///how many nodes
{
id = (uint32_t)cc[cc_off + i];///node id
if(link->a.a[id].e.n == 0) continue;
for (k = 0; k < link->a.a[id].e.n; k++)
{
if(link->a.a[id].e.a[k].is_cc == 0) break;
}
if(k < link->a.a[id].e.n)///disconnected
{
kv_push(uint32_t, buf->a, id);
b_cc_occ++;
}
}
if(b_cc_occ == 0) return;
tig = buf->a.a;
b_cc = buf->a.a + tig_occ;
for (i = 0; i < tig_occ; i++)
{
qn = tig[i];
for (k = 0; k < b_cc_occ; k++)
{
tn = b_cc[k];
if(qn == tn) continue;
p = get_hc_edge(link, qn, tn, 0);
if(p) continue;
t_d = (uint64_t)-1;
p = push_hc_edge(&(link->a.a[qn]), tn, 0, 0, &t_d);
p->is_cc = 0; p->occ = (uint64_t)-1;
p = push_hc_edge(&(link->a.a[tn]), qn, 0, 0, &t_d);
p->is_cc = 0; p->occ = (uint64_t)-1;
}
}
}
void update_ug_by_tigs(asg_t *sg, hc_links *link)
{
uint32_t i, m, v, nv, x, y, qn, tn;
asg_arc_t *av = NULL;
kvec_t(uint32_t) stack; kv_init(stack);
uint32_t *flag = NULL; MALLOC(flag, sg->n_seq);
uint64_t *group = NULL; MALLOC(group, sg->n_seq);
kvec_t_u32_warp buf; kv_init(buf.a);
memset(flag, -1, sg->n_seq*sizeof(uint32_t));
// connected componets
for (i = 0; i < sg->n_seq; ++i) {
if (flag[i] != (uint32_t)-1) continue;
stack.n = 0;
kv_push(uint32_t, stack, i);
while (stack.n > 0) {
stack.n--;
flag[stack.a[stack.n]] = i;///group id
v = (stack.a[stack.n])<<1;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (m = 0; m < nv; ++m) {
if (flag[av[m].v>>1] != (uint32_t)-1) continue;
kv_push(uint32_t, stack, av[m].v>>1);
}
v++;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (m = 0; m < nv; ++m) {
if (flag[av[m].v>>1] != (uint32_t)-1) continue;
kv_push(uint32_t, stack, av[m].v>>1);
}
}
}
kv_destroy(stack);
// precalculate the size of each group
for (i = 0; i < sg->n_seq; ++i)
group[i] = (uint64_t)flag[i] << 32 | i;
radix_sort_hc64(group, group + sg->n_seq);
for (i = 1, x = y = 0; i <= sg->n_seq; ++i) {
if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32)) {
uint32_t j;
for (j = x; j < i; ++j)
group[j] = (uint64_t)y << 32 | (uint32_t)group[j];///(group id)|first element in this group
++y, x = i;
}
}
for (i = 0; i < link->a.n; i++)
{
qn = i;
for (m = 0; m < link->a.a[i].e.n; m++)
{
link->a.a[i].e.a[m].occ = 0;
link->a.a[i].e.a[m].is_cc = 0;
tn = link->a.a[i].e.a[m].uID;
if((group[qn]>>32) == (group[tn]>>32))
{
link->a.a[i].e.a[m].is_cc = 1;
}
}
}
for (i = 1, x = 0; i <= sg->n_seq; ++i)
{
if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32))
{
append_tig_link(group, x, i - x, link, sg, &buf);
x = i;
}
}
free(flag); kv_destroy(buf.a);
}
void measure_distance(const ma_ug_t* ug, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, kv_u_trans_t *ta)
{
// double index_time = yak_realtime();
MT M;
init_MT(&M, ug->g->n_seq<<1);
uint64_t uID_bits;
for (uID_bits=1; (uint64_t)(1<<uID_bits)<(uint64_t)ug->u.n; uID_bits++);
uint64_t k, i, shif = 64 - uID_bits, beg, end, t_d;
if(hits)
{
for (k = 0; k < hits->a.n; ++k)
{
beg = ((hits->a.a[k].s<<1)>>shif);
end = ((hits->a.a[k].e<<1)>>shif);
if(beg == end) continue;
if(IF_HOM(beg, *bub)) continue;
if(IF_HOM(end, *bub)) continue;
t_d = (uint64_t)-1;
push_hc_edge(&(link->a.a[beg]), end, 0, 0, &t_d);
push_hc_edge(&(link->a.a[end]), beg, 0, 0, &t_d);
}
}
else
{
for (k = 0; k < ug->g->n_seq; ++k)
{
if(IF_HOM(k, *bub)) continue;
for (i = 0; i < ug->g->n_seq; ++i)
{
if(i == k || IF_HOM(i, *bub)) continue;
t_d = (uint64_t)-1;
push_hc_edge(&(link->a.a[i]), k, 0, 0, &t_d);
push_hc_edge(&(link->a.a[k]), i, 0, 0, &t_d);
}
}
}
asg_t *copy_sg = copy_read_graph(ug->g);
update_ug_by_trans(copy_sg, ta);
// update_ug_by_tigs(copy_sg, link);
all_pair_shortest_path(copy_sg, link, &M);
fill_utg_distance_multi(copy_sg, link, &M, bub);
update_containment_distance(copy_sg, ta, link);
// update_dis_connected_gfa(copy_sg, link, &M);
asg_destroy(copy_sg);
destory_MT(&M);
// fprintf(stderr, "[M::%s::%.3f] ==> Hi-C linkages have been counted\n", __func__, yak_realtime()-index_time);
return;
}
void set_reverse_links(uint32_t* bub, uint32_t n, kvec_t_u32_warp* reach, uint32_t root, hc_links* link)
{
uint64_t i, k, d = RC_0;
uint32_t v;
for (i = 0; i < n; i++)
{
v = bub[i]>>1;
if(v == root) continue;
for (k = 0; k < reach->a.n; k++)
{
if(v == reach->a.a[k]) break;
}
///if(k == reach->a.n && reach->a.n > 0)
if(k == reach->a.n)
{
push_hc_edge(&(link->a.a[root]), v, 1, 1, &d);
push_hc_edge(&(link->a.a[v]), root, 1, 1, &d);
}
}
}
void collect_hc_reverse_links(hc_links* link, ma_ug_t* ug, bubble_type* bub)
{
uint64_t i, j, k, d = RC_0, m, pre;
uint32_t beg, sink, n, v, *a = NULL;
kvec_t_u32_warp stack, result;
hc_edge *e = NULL;
kv_init(stack.a); kv_init(result.a);
///clean all reverse overlaps within bubbles
///might be wrong
for (i = 0; i < bub->f_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
v = a[k]>>1;
for (j = 0; j < link->a.a[v].f.n; j++)
{
if(link->a.a[v].f.a[j].del) continue;
e = get_hc_edge(link, link->a.a[v].f.a[j].uID, v, 1);
e->del = 1;
}
link->a.a[v].f.n = 0;
}
v = beg>>1;
if(IF_HOM(v, *bub))
{
for (j = 0; j < link->a.a[v].f.n; j++)
{
if(link->a.a[v].f.a[j].del) continue;
e = get_hc_edge(link, link->a.a[v].f.a[j].uID, v, 1);
e->del = 1;
}
link->a.a[v].f.n = 0;
}
v = sink>>1;
if(IF_HOM(v, *bub))
{
for (j = 0; j < link->a.a[v].f.n; j++)
{
if(link->a.a[v].f.a[j].del) continue;
e = get_hc_edge(link, link->a.a[v].f.a[j].uID, v, 1);
e->del = 1;
}
link->a.a[v].f.n = 0;
}
}
for (i = 0; i < bub->f_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
if(n == 2)
{
push_hc_edge(&(link->a.a[a[0]>>1]), a[1]>>1, 1, 1, &d);
push_hc_edge(&(link->a.a[a[1]>>1]), a[0]>>1, 1, 1, &d);
continue;
}
///for complex bubbles, shouldn't have any assumption
///if(i >= bub->s_bub) continue;
beg = beg>>1; sink = sink>>1;
for (k = 0; k < n; k++)
{
v = a[k]>>1;
dfs_bubble(ug->g, &stack, &result, v, beg, sink);
set_reverse_links(a, n, &result, v, link);
}
}
uint8_t* vis_flag = NULL;
MALLOC(vis_flag, ug->g->n_seq*2);
///for broken bubbles
for (i = bub->f_bub; i < bub->f_bub + bub->b_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
v = a[k];
dfs_bubble_broken(ug->g, &stack, &result, vis_flag, ug->g->n_seq*2, v, beg, sink);
set_reverse_links(a, n, &result, v>>1, link);
}
}
kv_destroy(stack.a); kv_destroy(result.a); free(vis_flag);
for (i = 0; i < link->a.n; i++)
{
for (k = m = 0; k < link->a.a[i].f.n; k++)
{
if(link->a.a[i].f.a[k].del) continue;
link->a.a[i].f.a[m] = link->a.a[i].f.a[k];
m++;
}
link->a.a[i].f.n = m;
radix_sort_hc_edge_u(link->a.a[i].f.a, link->a.a[i].f.a + link->a.a[i].f.n);
for (k = m = 0, pre = (uint64_t)-1; k < link->a.a[i].f.n; k++)
{
if(link->a.a[i].f.a[k].del) continue;
if(link->a.a[i].f.a[k].uID == pre)
{
if(link->a.a[i].f.a[k].dis == RC_0) link->a.a[i].f.a[m-1].dis = RC_0;
continue;
}
pre = link->a.a[i].f.a[k].uID;
link->a.a[i].f.a[m] = link->a.a[i].f.a[k];
m++;
}
link->a.a[i].f.n = m;
radix_sort_hc_edge_d(link->a.a[i].f.a, link->a.a[i].f.a + link->a.a[i].f.n);
}
// hc_edge *e = NULL;
// for (i = 0; i < link->a.n; i++)
// {
// for (k = 0; k < link->a.a[i].f.n; k++)
// {
// if(link->a.a[i].f.a[k].del) continue;
// e = get_hc_edge(link, link->a.a[i].f.a[k].uID, i, 1);
// if(e == NULL) fprintf(stderr, "ERROR\n");
// }
// }
}
void write_hc_links(hc_links* link, const char *fn)
{
uint64_t k;
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.hic.link.bin", fn);
FILE* fp = fopen(buf, "w");
fwrite(&link->a.n, sizeof(link->a.n), 1, fp);
for (k = 0; k < link->a.n; k++)
{
fwrite(&link->a.a[k].e.n, sizeof(link->a.a[k].e.n), 1, fp);
fwrite(link->a.a[k].e.a, sizeof(hc_edge), link->a.a[k].e.n, fp);
fwrite(&link->a.a[k].f.n, sizeof(link->a.a[k].f.n), 1, fp);
fwrite(link->a.a[k].f.a, sizeof(hc_edge), link->a.a[k].f.n, fp);
}
fwrite(&link->enzymes.n, sizeof(link->enzymes.n), 1, fp);
fwrite(link->enzymes.a, sizeof(uint64_t), link->enzymes.n, fp);
fclose(fp);
free(buf);
fprintf(stderr, "[M::%s::] ==> Hi-C linkages have been written\n", __func__);
}
int load_hc_links(hc_links* link, const char *fn)
{
uint64_t k, flag = 0;
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.hic.link.bin", fn);
FILE* fp = NULL;
fp = fopen(buf, "r");
if(!fp)
{
free(buf);
return 0;
}
kv_init(link->a);
flag += fread(&link->a.n, sizeof(link->a.n), 1, fp);
link->a.m = link->a.n; CALLOC(link->a.a, link->a.n);
for (k = 0; k < link->a.n; k++)
{
flag += fread(&link->a.a[k].e.n, sizeof(link->a.a[k].e.n), 1, fp);
link->a.a[k].e.m = link->a.a[k].e.n; MALLOC(link->a.a[k].e.a, link->a.a[k].e.n);
flag += fread(link->a.a[k].e.a, sizeof(hc_edge), link->a.a[k].e.n, fp);
flag += fread(&link->a.a[k].f.n, sizeof(link->a.a[k].f.n), 1, fp);
link->a.a[k].f.m = link->a.a[k].f.n; MALLOC(link->a.a[k].f.a, link->a.a[k].f.n);
flag += fread(link->a.a[k].f.a, sizeof(hc_edge), link->a.a[k].f.n, fp);
}
kv_init(link->enzymes);
flag += fread(&link->enzymes.n, sizeof(link->enzymes.n), 1, fp);
link->enzymes.m = link->enzymes.n; MALLOC(link->enzymes.a, link->enzymes.n);
flag += fread(link->enzymes.a, sizeof(uint64_t), link->enzymes.n, fp);
fclose(fp);
free(buf);
fprintf(stderr, "[M::%s::] ==> Hi-C linkages have been loaded\n", __func__);
return 1;
}
void write_hc_hits(kvec_pe_hit* hits, const char *fn)
{
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.hic.lk.bin", fn);
FILE* fp = fopen(buf, "w");
fwrite(&hits->a.n, sizeof(hits->a.n), 1, fp);
fwrite(hits->a.a, sizeof(pe_hit), hits->a.n, fp);
fclose(fp);
free(buf);
}
void write_hc_hits_v14(kvec_pe_hit_hap* i_hits, const char *fn)
{
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.v14.hic.lk.bin", fn);
FILE* fp = fopen(buf, "w");
kvec_pe_hit hits;
kv_init(hits.a);
uint64_t i, m_u = (uint64_t)-1, m_m = (uint64_t)-1;
pe_hit* p = NULL;
for (i = 0; i < i_hits->n; i++)
{
if(i_hits->a[i].occ1 == 1 && i_hits->a[i].occ2 == 1)
{
kv_pushp(pe_hit, hits.a, &p);
p->id = i_hits->a[i].id;
p->s = i_hits->a[i].a[0];
p->e = i_hits->a[i].a[1];
m_u = i;
}
else
{
if(m_m == (uint64_t)-1) m_m = i;
}
}
fprintf(stderr, "m_u: %lu, m_m: %lu, n_u: %lu\n", m_u, m_m, i_hits->n_u);
fwrite(&hits.a.n, sizeof(hits.a.n), 1, fp);
fwrite(hits.a.a, sizeof(pe_hit), hits.a.n, fp);
kv_destroy(hits.a);
fclose(fp);
free(buf);
exit(1);
}
#define pe_hit_hap_id_key(x) ((x).id)
KRADIX_SORT_INIT(pe_hit_hap_id, pe_hit_hap, pe_hit_hap_id_key, member_size(pe_hit_hap, id))
#define pe_hit_id_key(x) ((x).id)
KRADIX_SORT_INIT(pe_hit_id, pe_hit, pe_hit_id_key, member_size(pe_hit, id))
void debug_hc_hits_v14(kvec_pe_hit_hap* i_hits, const char *fn, const ha_ug_index* idx)
{
uint64_t flag = 0;
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.v14.hic.lk.bin", fn);
kvec_pe_hit hits;
kv_init(hits.a);
FILE* fp = NULL;
fp = fopen(buf, "r");
kv_init(hits.a);
flag += fread(&hits.a.n, sizeof(hits.a.n), 1, fp);
hits.a.m = hits.a.n; MALLOC(hits.a.a, hits.a.n);
flag += fread(hits.a.a, sizeof(pe_hit), hits.a.n, fp);
radix_sort_pe_hit_id(hits.a.a, hits.a.a + hits.a.n);
radix_sort_pe_hit_hap_id(i_hits->a, i_hits->a + i_hits->n_u);
fprintf(stderr, "i_hits->n_u: %lu, hits.a.n: %lu\n", (uint64_t)i_hits->n_u, (uint64_t)hits.a.n);
uint64_t i, k;
uint64_t i_beg_utg, i_beg_pos, i_beg_rev;
uint64_t i_end_utg, i_end_pos, i_end_rev;
uint64_t k_beg_utg, k_beg_pos, k_beg_rev;
uint64_t k_end_utg, k_end_pos, k_end_rev;
uint64_t i_id, k_id;
uint64_t same_occ = 0, diff_occ = 0, miss_occ = 0;
for (i = 0, k = 0; i < i_hits->n_u; i++)
{
i_beg_rev = get_pe_s(i_hits->a[i])>>63;
i_beg_utg = ((get_pe_s(i_hits->a[i])<<1)>>(64 - idx->uID_bits));
i_beg_pos = get_pe_s(i_hits->a[i]) & idx->pos_mode;
i_end_rev = get_pe_e(i_hits->a[i])>>63;
i_end_utg = ((get_pe_e(i_hits->a[i])<<1)>>(64 - idx->uID_bits));
i_end_pos = get_pe_e(i_hits->a[i]) & idx->pos_mode;
i_id = i_hits->a[i].id;
for (; k < hits.a.n; k++)
{
k_beg_rev = hits.a.a[k].s>>63;
k_beg_utg = ((hits.a.a[k].s<<1)>>(64 - idx->uID_bits));
k_beg_pos = hits.a.a[k].s & idx->pos_mode;
k_end_rev = hits.a.a[k].e>>63;
k_end_utg = ((hits.a.a[k].e<<1)>>(64 - idx->uID_bits));
k_end_pos = hits.a.a[k].e & idx->pos_mode;
k_id = hits.a.a[k].id;
if(k_id > i_id)
{
miss_occ++;
fprintf(stderr, "\n[MISS]rid=%lu\n", i_id);
fprintf(stderr, "********v0.15********\n");
fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n",
i_beg_rev, i_beg_utg, i_beg_pos);
fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n",
i_end_rev, i_end_utg, i_end_pos);
break;
}
if(k_id == i_id)
{
if(get_pe_s(i_hits->a[i]) == hits.a.a[k].s && get_pe_e(i_hits->a[i]) == hits.a.a[k].e)
{
same_occ++;
// fprintf(stderr, "\n[SAME]rid=%lu\n", i_id);
// fprintf(stderr, "********v0.15********\n");
// fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n",
// i_beg_rev, i_beg_utg, i_beg_pos);
// fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n",
// i_end_rev, i_end_utg, i_end_pos);
// fprintf(stderr, "********v0.14********\n");
// fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n",
// k_beg_rev, k_beg_utg, k_beg_pos);
// fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n",
// k_end_rev, k_end_utg, k_end_pos);
}
else
{
diff_occ++;
fprintf(stderr, "\n[DIFF]rid=%lu\n", i_id);
fprintf(stderr, "********v0.15********\n");
fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n",
i_beg_rev, i_beg_utg, i_beg_pos);
fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n",
i_end_rev, i_end_utg, i_end_pos);
fprintf(stderr, "********v0.14********\n");
fprintf(stderr, "beg_rev: %lu, beg_utg: %lu, beg_pos: %lu\n",
k_beg_rev, k_beg_utg, k_beg_pos);
fprintf(stderr, "end_rev: %lu, end_utg: %lu, end_pos: %lu\n",
k_end_rev, k_end_utg, k_end_pos);
}
break;
}
}
}
fprintf(stderr, "same_occ: %lu, diff_occ: %lu, miss_occ: %lu", same_occ, diff_occ, miss_occ);
kv_destroy(hits.a);
fclose(fp);
free(buf);
exit(1);
}
int load_hc_hits(kvec_pe_hit* hits, const char *fn)
{
uint64_t flag = 0;
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.hic.lk.bin", fn);
FILE* fp = NULL;
fp = fopen(buf, "r");
if(!fp) return 0;
kv_init(hits->a);
flag += fread(&hits->a.n, sizeof(hits->a.n), 1, fp);
hits->a.m = hits->a.n; MALLOC(hits->a.a, hits->a.n);
flag += fread(hits->a.a, sizeof(pe_hit), hits->a.n, fp);
fclose(fp);
free(buf);
// fprintf(stderr, "[M::%s::] ==> Hi-C linkages have been loaded\n", __func__);
return 1;
}
inline int get_phase_status(H_partition* hap, uint32_t uID)
{
int d = -2;
if(hap->hap[uID] & hap->m[0]) d = 1;
if(hap->hap[uID] & hap->m[1]) d = -1;
if(hap->hap[uID] & hap->m[2]) d = 0;
return d;
}
inline uint32_t get_phase_group(H_partition* hap, uint32_t uID)
{
return hap->hap[uID]>>hap->label_shift;
}
void print_hc_links(hc_links* link, int dir, H_partition* hap)
{
uint64_t i, k;
if(dir == 0)
{
double f_w, r_w;
for (i = 0; i < link->a.n; ++i)
{
f_w = r_w = 0;
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
fprintf(stderr, "s-utg%.6dl(%c)\tCLU:%d:%u\td-utg%.6dl(%c)\tCLU:%d:%u\t%lu\t%c\t%f\te\n",
(int)(i+1), "01"[!!(link->a.a[i].e.a[k].dis&(uint64_t)2)],
get_phase_status(hap, i), hap->hap[i]>>3,
(int)(link->a.a[i].e.a[k].uID+1), "01"[!!(link->a.a[i].e.a[k].dis&(uint64_t)1)],
get_phase_status(hap, link->a.a[i].e.a[k].uID), hap->hap[link->a.a[i].e.a[k].uID]>>3,
link->a.a[i].e.a[k].dis == (uint64_t)-1? (uint64_t)-1 : link->a.a[i].e.a[k].dis>>3,
"fb"[!!(link->a.a[i].e.a[k].dis&(uint64_t)4)], link->a.a[i].e.a[k].weight);
if(get_phase_status(hap, i) == get_phase_status(hap, link->a.a[i].e.a[k].uID))
{
f_w += link->a.a[i].e.a[k].weight;
}
else
{
r_w += link->a.a[i].e.a[k].weight;
}
}
// fprintf(stderr, "self-utg%.6dl\tFW:%f\tRW:%f\tRT:%f\n**************************************************\n",
// (int)(i+1), f_w, r_w, (f_w+r_w) != 0? r_w/(f_w+r_w):0);
}
}
if(dir == 1)
{
for (i = 0; i < link->a.n; ++i)
{
for (k = 0; k < link->a.a[i].f.n; k++)
{
if(link->a.a[i].f.a[k].del) continue;
fprintf(stderr, "s-utg%.6d\td-utg%.6d\t%lu\te\n",
(int)(i+1), (int)(link->a.a[i].f.a[k].uID+1), link->a.a[i].f.a[k].dis);
}
}
}
}
void normalize_hc_links(hc_links* link)
{
uint64_t i, k;
for (i = 0; i < link->a.n; ++i)
{
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
link->a.a[i].e.a[k].weight *= 100;
link->a.a[i].e.a[k].weight /= (double)(MIN(link->enzymes.a[i], link->enzymes.a[link->a.a[i].e.a[k].uID]));
///link->a.a[i].e.a[k].weight /= (double)(link->enzymes.a[i] + link->enzymes.a[link->a.a[i].e.a[k].uID]);
}
}
}
hc_edge* get_rGraph_edge(min_cut_t* x, uint64_t src, uint64_t dest)
{
if(src >= x->rGraph.n) return NULL;
uint64_t i;
for (i = 0; i < x->rGraph.a[src].n; i++)
{
if(x->rGraph.a[src].a[i].del) continue;
if(x->rGraph.a[src].a[i].uID == dest) return &(x->rGraph.a[src].a[i]);
}
return NULL;
}
void init_min_cut_t(min_cut_t* x, hc_links* link, const bubble_type* bub, const ma_ug_t *ug)
{
uint64_t utg_num = link->a.n, i, k, u, v;
x->n = utg_num;
x->n_e = x->c_e = 0;
kv_malloc(x->rGraphSet, utg_num); x->rGraphSet.n = utg_num;
///must utg_num<<1)
kv_malloc(x->rGraphVis, utg_num); x->rGraphVis.n = utg_num;
kv_malloc(x->utgVis, utg_num); x->utgVis.n = utg_num;
kv_malloc(x->bmerVis, utg_num); x->bmerVis.n = utg_num;
kv_malloc(x->order, utg_num); x->order.n = utg_num;
kv_malloc(x->parent, utg_num); x->parent.n = utg_num;
kv_malloc(x->p_weight, utg_num); x->p_weight.n = utg_num;
///uresolved BUGs, if use kv_resize segfault; if use kv_malloc, work?????
kv_malloc(x->rGraph, utg_num); x->rGraph.n = utg_num;
// kv_init(x->rGraph); kv_resize(hc_edge_warp, x->rGraph, utg_num); x->rGraph.n = utg_num;
x->enzymes = link->enzymes.a;
init_pdq(&(x->pq), utg_num<<1);
//must be utg_num + 2 since we may need to add fake nodes
for (i = 1; (uint64_t)(1<<i) < (utg_num + 2); i++);
x->uID_mode = ((uint64_t)-1) >> (64-i);
x->uID_shift = i;
for (i = 0; i < utg_num; i++)
{
///x->order.a[i] = link->a.a[i].f.n;
///x->order.a[i] = ug->u.a[i].len;
x->order.a[i] = x->enzymes[i];
x->order.a[i] <<= x->uID_shift;
x->order.a[i] |= (uint64_t)(i & x->uID_mode);
x->rGraphSet.a[i] = 0;
x->rGraphVis.a[i] = 0;
x->utgVis.a[i] = 0;
x->bmerVis.a[i] = 0;
x->parent.a[i] = (uint32_t)-1;
///uresolved BUGs, if use kv_resize segfault; if use kv_malloc, work?????
// kv_init(x->rGraph.a[i]); kv_resize(hc_edge, x->rGraph.a[i], link->a.a[i].e.n);
kv_malloc(x->rGraph.a[i], link->a.a[i].e.n);
x->rGraph.a[i].n = link->a.a[i].e.n;
if(x->rGraph.a[i].n)
{
for (k = 0; k < x->rGraph.a[i].n; k++)
{
///kv_push(hc_edge, x->rGraph.a[i], link->a.a[i].e.a[k]);
x->rGraph.a[i].a[k] = link->a.a[i].e.a[k];
x->n_e++;
if((x->rGraph.a[i].a[k].weight == 0) || IF_HOM(x->rGraph.a[i].a[k].uID, *bub)
|| IF_HOM(i, *bub) || (x->rGraph.a[i].a[k].del))
{
x->rGraph.a[i].a[k].del = 1;
x->n_e--;
}
}
}
}
hc_edge *p = NULL;
for (i = 0; i < utg_num; i++)
{
v = i;
for (k = 0; k < link->a.a[v].f.n; k++)
{
if(link->a.a[v].f.a[k].del) continue;
u = link->a.a[v].f.a[k].uID;
p = get_rGraph_edge(x, v, u);
if(p)
{
p->del = 1;
x->n_e--;
}
p = get_rGraph_edge(x, u, v);
if(p)
{
p->del = 1;
x->n_e--;
}
}
}
x->q = kdq_init(uint64_t);
radix_sort_hc64(x->order.a, x->order.a + x->order.n);
x->b_mer = asm_opt.bub_mer_length;
///fprintf(stderr, "[M::%s]\n", __func__);
///exit(0);
}
void destory_min_cut_t(min_cut_t* x)
{
kv_destroy(x->order);
kv_destroy(x->parent);
kv_destroy(x->p_weight);
kv_destroy(x->rGraphSet);
kv_destroy(x->rGraphVis);
kv_destroy(x->utgVis);
kv_destroy(x->bmerVis);
destory_pdq(&(x->pq));
uint64_t i;
for (i = 0; i < x->rGraph.m; i++)
{
kv_destroy(x->rGraph.a[i]);
}
kv_destroy(x->rGraph);
kdq_destroy(uint64_t, x->q);
}
void reset_min_cut_t(min_cut_t* x, hc_links* link)
{
///no need to reset parent[] and q
uint64_t i, j;
///important to have this line
x->bmerVis.n = x->parent.n = x->p_weight.n = x->order.n = x->rGraph.n = x->rGraphVis.n = x->rGraphSet.n = link->a.n;
kdq_clear(x->q);
for (i = 0; i < x->rGraphSet.n; i++)
{
x->rGraphVis.a[i] = 0;
///x->bmerVis.a[i] = 0;
///important to have this line
x->rGraph.a[i].n = link->a.a[i].e.n;
if(x->rGraphSet.a[i] == 0) continue;
for (j = 0; j < x->rGraph.a[i].n; j++)
{
x->rGraph.a[i].a[j].weight = link->a.a[i].e.a[j].weight;
}
x->rGraphSet.a[i] = 0;
}
}
void update_link_by_min_cut_t(min_cut_t* x, hc_links* link)
{
uint64_t i, j;
for (i = 0; i < link->a.n; i++)
{
for (j = 0; j < link->a.a[i].e.n; j++)
{
link->a.a[i].e.a[j].del = x->rGraph.a[i].a[j].del;
}
}
}
uint64_t add_mul_convex(min_cut_t* x, uint64_t* a, uint64_t n)
{
if(n == 0) return (uint64_t)-1;
if(n == 1) return a[0];
kv_push(uint8_t, x->rGraphSet, 0);
kv_push(uint8_t, x->rGraphVis, 0);
kv_push(uint8_t, x->bmerVis, 0);
kv_push(uint32_t, x->parent, 0);
kv_push(double, x->p_weight, 0);
kv_resize(hc_edge_warp, x->rGraph, x->rGraph.n+1);
kv_init(x->rGraph.a[x->rGraph.n]);
uint64_t i, k;
hc_edge t;
for (i = 0; i < n; i++)
{
///t.uID = a[i]; t.del = t.enzyme = t.weight = 0;
t.uID = a[i]; t.del = t.weight = 0;
for (k = 0; k < x->rGraph.a[a[i]].n; k++)
{
if(x->rGraph.a[a[i]].a[k].del) continue;
t.weight += x->rGraph.a[a[i]].a[k].weight;
}
kv_push(hc_edge, x->rGraph.a[x->rGraph.n], t);
t.uID = x->rGraph.n;
kv_push(hc_edge, x->rGraph.a[a[i]], t);
}
x->rGraph.n++;
return x->rGraph.n - 1;
}
void get_s_t(min_cut_t* x, hc_links* link, uint64_t uID, uint64_t* src, uint64_t* dest, kvec_t_u64_warp* buff)
{
buff->a.n = 0; (*src) = (*dest) = (uint64_t)-1;
if(link->a.a[uID].f.n == 0) return;
(*src) = uID;
uint64_t i, n;
for (i = 0, n = 0; i < link->a.a[uID].f.n; i++)
{
if(link->a.a[uID].f.a[i].del) continue;
kv_push(uint64_t, buff->a, link->a.a[uID].f.a[i].uID);
(*dest) = link->a.a[uID].f.a[i].uID;
n++;
}
if(n == 1 || n == 0) return;
(*dest) = add_mul_convex(x, buff->a.a, buff->a.n);
}
uint64_t bfs_flow(uint64_t src, uint64_t dest, min_cut_t* x, kvec_t_u64_warp* buff)
{
uint64_t *p = NULL, v, u, i;
if(dest != (uint64_t)-1) memset(x->rGraphVis.a, 0, x->rGraphVis.n);
kdq_push(uint64_t, x->q, src);
if(buff) kv_push(uint64_t, buff->a, src);
x->rGraphVis.a[src] = 1;
x->parent.a[src] = (uint32_t)-1;
while (1)
{
p = kdq_shift(uint64_t, x->q);
if(!p) break;
v = *p;
if(v == dest) return 1;
for (i = 0; i < x->rGraph.a[v].n; i++)
{
if(x->rGraph.a[v].a[i].del) continue;
if(x->rGraph.a[v].a[i].weight == 0) continue;
u = x->rGraph.a[v].a[i].uID;
if(x->rGraphVis.a[u]) continue;
if(!x->bmerVis.a[u]) continue;
x->parent.a[u] = v;
x->p_weight.a[u] = x->rGraph.a[v].a[i].weight;
kdq_push(uint64_t, x->q, u);
if(buff) kv_push(uint64_t, buff->a, u);
///set u or v to be 1? doesn't matter
x->rGraphVis.a[u] = 1;
}
}
return 0;
}
uint64_t maxFlow(uint64_t src, uint64_t dest, min_cut_t* x)
{
double flow = 0, max_flow = 0;
uint64_t v, u;
hc_edge *p;
while (bfs_flow(src, dest, x, NULL))
{
kdq_clear(x->q);
flow = DBL_MAX;
for (v = dest; v != src; v = x->parent.a[v])
{
flow = MIN(flow, x->p_weight.a[v]);
}
/*******************************for debug************************************/
// if(src == 26818) fprintf(stderr, "***********flow: %f*********\n", flow);
/*******************************for debug************************************/
for (v = dest; v != src; v = x->parent.a[v])
{
u = x->parent.a[v];
p = get_rGraph_edge(x, u, v);
/*******************************for debug************************************/
// if(src == 26818) fprintf(stderr, "utg%.6lul (%f)\n", u+1, p->weight);
/*******************************for debug************************************/
p->weight -= flow;
p = get_rGraph_edge(x, v, u);
p->weight += flow;
x->rGraphSet.a[u] = x->rGraphSet.a[v] = 1;
}
max_flow += flow;
}
return (max_flow != 0);
}
uint64_t print_path(uint64_t src, uint64_t dest, min_cut_t* x)
{
double flow = 0, max_flow = 0;
uint64_t v, u;
hc_edge *p;
if(bfs_flow(src, dest, x, NULL))
{
kdq_clear(x->q);
flow = DBL_MAX;
for (v = dest; v != src; v = x->parent.a[v])
{
flow = MIN(flow, x->p_weight.a[v]);
}
/*******************************for debug************************************/
fprintf(stderr, "***********flow: %f*********\n", flow);
/*******************************for debug************************************/
for (v = dest; v != src; v = x->parent.a[v])
{
u = x->parent.a[v];
p = get_rGraph_edge(x, u, v);
/*******************************for debug************************************/
fprintf(stderr, "utg%.6lul (%f)\n", u+1, p->weight);
/*******************************for debug************************************/
}
max_flow += flow;
}
return (max_flow != 0);
}
void print_src_dest(uint64_t src, min_cut_t* x, const char* command)
{
uint64_t i;
fprintf(stderr, "********************\n%s\n", command);
if(src >= x->n)
{
for (i = 0; i < x->rGraph.a[src].n; i++)
{
if(x->rGraph.a[src].a[i].del) continue;
fprintf(stderr, "utg%.6ul\n", x->rGraph.a[src].a[i].uID + 1);
}
}
else
{
fprintf(stderr, "utg%.6lul\n", src+1);
}
fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!\n");
}
void print_debug_rGraph(min_cut_t* x)
{
fprintf(stderr, "******rGraph******\n");
uint64_t i, j, u;
for (i = 0; i < x->rGraphVis.n; i++)
{
if(!x->bmerVis.a[i]) continue;
for (j = 0; j < x->rGraph.a[i].n; j++)
{
if(x->rGraph.a[i].a[j].del) continue;
u = x->rGraph.a[i].a[j].uID;
if(!x->bmerVis.a[u]) continue;
fprintf(stderr, "***utg%.6lul\tutg%.6lul\t%f\n", i+1, u+1, x->rGraph.a[i].a[j].weight);
}
}
fprintf(stderr, "******rGraph******\n");
}
void graph_cut(uint64_t src, uint64_t dest, min_cut_t* x)
{
/*******************************for debug************************************/
///if(src == 45179) print_debug_rGraph(x);
/*******************************for debug************************************/
if(maxFlow(src, dest, x))
{
///in the last time bfs of maxFlow, rGraphVis has already been set
uint64_t i, j, v, u;
hc_edge *p;
/*******************************for debug************************************/
if(src == 45179)
///if(src == 26818)
{
///print_debug_rGraph(x);
print_src_dest(src, x, "src utg:");
print_src_dest(dest, x, "dest utg:");
}
/*******************************for debug************************************/
for (i = 0; i < x->rGraphVis.n; i++)
{
if(x->rGraphVis.a[i] == 0) continue;
if(!x->bmerVis.a[i]) continue;
v = i;
for (j = 0; j < x->rGraph.a[i].n; j++)
{
if(x->rGraph.a[i].a[j].del) continue;
u = x->rGraph.a[i].a[j].uID;
if(x->rGraphVis.a[u]) continue;
if(!x->bmerVis.a[u]) continue;
/*******************************for debug************************************/
if(src == 45179) fprintf(stderr, "utg%.6lul\tutg%.6lul\t%f\n", v+1, u+1, x->rGraph.a[i].a[j].weight);
/*******************************for debug************************************/
///delete <v, u>
x->rGraph.a[i].a[j].del = 1;
///delete <u, v>
p = get_rGraph_edge(x, u, v);
p->del = 1;
x->c_e += 2;
}
}
/*******************************for debug************************************/
///if(src == 45179 || src == 31635)
// if(src == 26818)
// {
// fprintf(stderr, "hahahaha\n");
// print_path(26818, 1143, x);
// }
/*******************************for debug************************************/
}
/*******************************for debug************************************/
///if(src == 45179 || src == 31635)
// {
// print_src_dest(src, x, "++++++src utg:");
// uint64_t m;
// for (m = 0; m < x->rGraph.a[src].n; m++)
// {
// if(x->rGraph.a[src].a[m].del) continue;
// fprintf(stderr, "src(utg%.6dl, enz:%lu)\tdes(utg%.6dl, enz:%lu)\t%f\n",
// (int)(src+1), x->enzymes[src],
// (int)(x->rGraph.a[src].a[m].uID+1), x->enzymes[x->rGraph.a[src].a[m].uID],
// x->rGraph.a[src].a[m].weight);
// }
// }
/*******************************for debug************************************/
}
void check_connective(min_cut_t* x, hc_links* link)
{
double index_time = yak_realtime();
kvec_t_u64_warp buff;
kv_init(buff.a);
uint64_t i, k, uID;
for (i = 0; i < x->n; i++)
{
uID = x->order.a[i] & x->uID_mode;
if(link->a.a[uID].f.n == 0) continue;
for (k = 0; k < link->a.a[uID].f.n; k++)
{
if(link->a.a[uID].f.a[k].del) continue;
if(x->utgVis.a[link->a.a[uID].f.a[k].uID] == 0) break;
}
if(k == link->a.a[uID].f.n) continue;
reset_min_cut_t(x, link);
get_s_t(x, link, uID, &(x->src), &(x->dest), &buff);
bfs_flow(x->src, x->dest, x, NULL);
x->utgVis.a[uID] = 1;
}
//reset x.utgVis
memset(x->utgVis.a, 0, x->utgVis.n);
kv_destroy(buff.a);
fprintf(stderr, "[M::%s::%.3f] \n", __func__, yak_realtime()-index_time);
}
void get_Connected_Components(min_cut_t* x)
{
double index_time = yak_realtime();
uint64_t i, j, k = 0, uID, e;
kvec_t_u64_warp buff;
kv_init(buff.a);
while (1)
{
for (i = 0; i < x->n; i++)
{
uID = x->order.a[i] & x->uID_mode;
if(x->rGraphVis.a[uID] == 0) break;
}
if(i < x->n)
{
e = buff.a.n = 0;
bfs_flow(uID, (uint64_t)-1, x, &buff);
for (i = 0; i < buff.a.n; i++)
{
for (j = 0; j < x->rGraph.a[buff.a.a[i]].n; j++)
{
if(x->rGraph.a[buff.a.a[i]].a[j].del == 0) e++;
}
}
e >>= 1;
if(buff.a.n > 1)
{
fprintf(stderr, "(%lu) Component: # nodes: %lu, # edges: %lu\n",
k, (uint64_t)buff.a.n, e);
}
k++;
}
else
{
break;
}
}
kv_destroy(buff.a);
fprintf(stderr, "[M::%s::%.3f] # Connected Components: %lu\n",
__func__, yak_realtime()-index_time, k);
}
void print_rGraph(min_cut_t* x)
{
uint64_t i, k;
for (i = 0; i < x->rGraph.n; ++i)
{
for (k = 0; k < x->rGraph.a[i].n; k++)
{
if(x->rGraph.a[i].a[k].del) continue;
fprintf(stderr, "src(utg%.6dl, enz:%lu)\tdes(utg%.6dl, enz:%lu)\t%f\n",
(int)(i+1), x->enzymes[i],
(int)(x->rGraph.a[i].a[k].uID+1), x->enzymes[x->rGraph.a[i].a[k].uID],
x->rGraph.a[i].a[k].weight);
}
}
}
int select_large_node(const ma_ug_t *ug, min_cut_t* x,
uint64_t src, uint64_t dest, uint64_t utg_thres, int weight_thres)
{
if(src >= ug->u.n || dest >= ug->u.n) return 0;
if(ug->u.a[src].n < utg_thres || ug->u.a[dest].n < utg_thres) return 0;
uint64_t k;
for (k = 0; k < x->rGraph.a[src].n; k++)
{
if(x->rGraph.a[src].a[k].del) continue;
if(x->rGraph.a[src].a[k].weight >= weight_thres) break;
}
if(k == x->rGraph.a[src].n) return 0;
src = dest;
for (k = 0; k < x->rGraph.a[src].n; k++)
{
if(x->rGraph.a[src].a[k].del) continue;
if(x->rGraph.a[src].a[k].weight >= weight_thres) break;
}
if(k == x->rGraph.a[src].n) return 0;
return 1;
}
uint64_t inline set_dv(uint64_t v, uint64_t dis)
{
dis <<= 32; dis |= v;
return dis;
}
uint64_t select_bmer(uint32_t src, uint64_t k, const bubble_type* bub, min_cut_t* x, uint32_t bub_only)
{
uint32_t beg, sink, n, *a;
uint32_t v, d, u, i, nv, b_mer_d, j;
asg_t *sg = bub->ug->g;
uint64_t *p = NULL;
asg_arc_t *av = NULL;
memset(x->rGraphVis.a, 0, x->rGraphVis.n);
kdq_push(uint64_t, x->q, set_dv(src , 0));
b_mer_d = 0;
x->rGraphVis.a[src] = 1;
x->bmerVis.a[src] = 1;
while (1)
{
p = kdq_shift(uint64_t, x->q);
if(!p) break;
v = (uint32_t)(*p); d = ((uint64_t)(*p))>>32;
v = v<<1;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
u = av[i].v>>1;
if(x->rGraphVis.a[u]) continue;
x->rGraphVis.a[u] = 1;
if(IF_HOM(u, *bub))
{
if(d < k) kdq_push(uint64_t, x->q, set_dv(u, d+1));
}
else
{
kdq_push(uint64_t, x->q, set_dv(u , d));
b_mer_d = d;
if(IF_BUB(u, *bub) && x->bmerVis.a[u] == 0)
{
get_bubbles((bubble_type*)bub, bub->index[u], &beg, &sink, &a, &n, NULL);
for (j = 0; j < n; j++) x->bmerVis.a[(a[j]>>1)] = 1;
}
//must be here
if(bub_only == 0) x->bmerVis.a[u] = 1;
}
}
v = v + 1;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
u = av[i].v>>1;
if(x->rGraphVis.a[u]) continue;
x->rGraphVis.a[u] = 1;
if(IF_HOM(u, *bub))
{
if(d < k) kdq_push(uint64_t, x->q, set_dv(u, d+1));
}
else
{
kdq_push(uint64_t, x->q, set_dv(u , d));
b_mer_d = d;
if(IF_BUB(u, *bub) && x->bmerVis.a[u] == 0)
{
get_bubbles((bubble_type*)bub, bub->index[u], &beg, &sink, &a, &n, NULL);
for (j = 0; j < n; j++) x->bmerVis.a[(a[j]>>1)] = 1;
}
//must be here
if(bub_only == 0) x->bmerVis.a[u] = 1;
}
}
}
return b_mer_d;
}
void select_bmer_distance(uint32_t src, uint64_t k, const bubble_type* bub, min_cut_t* x,
uint32_t bub_only, uint32_t bub_extend)
{
uint32_t beg, sink, n, *a;
asg_t *sg = bub->ug->g;
uint64_t v, u, i, j, nv, w, first = 1;
asg_arc_t *av = NULL;
reset_pdq(&(x->pq));
x->bmerVis.a[src>>1] = 1;
x->pq.dis.a[src] = 0;
push_pdq(&(x->pq), src, 0);
while (pdq_cnt(x->pq) > 0)
{
pop_pdq(&(x->pq), &v, &w);
x->pq.vis.a[v] = 1;
if(x->pq.dis.a[v] > k) break;
///fprintf(stderr, "******utg%.6dl, dis: %lu\n", (int)((v>>1)+1), x->pq.dis.a[v]);
if(IF_BUB(v>>1, *bub))
{
if(bub_extend && x->bmerVis.a[v>>1] == 0)
{
get_bubbles((bubble_type*)bub, bub->index[v>>1], &beg, &sink, &a, &n, NULL);
for (j = 0; j < n; j++) x->bmerVis.a[(a[j]>>1)] = 1;
}
x->bmerVis.a[v>>1] = 1;
}
if(IF_HET(v>>1, *bub) && bub_only == 0) x->bmerVis.a[v>>1] = 1;
av = asg_arc_a(sg, v);
nv = asg_arc_n(sg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
u = av[i].v;
w = (uint32_t)av[i].ul;
if(first) w = 0;
if(x->pq.vis.a[u] == 0 && x->pq.dis.a[u] > x->pq.dis.a[v] + w)
{
x->pq.dis.a[u] = x->pq.dis.a[v] + w;
push_pdq(&(x->pq), u, x->pq.dis.a[u]);
}
}
first = 0;
}
}
void get_bmer_unitgs(min_cut_t* x, const bubble_type* bub, uint64_t k, uint64_t src)
{
uint32_t beg, sink, n, *a;
if(!IF_BUB(src, *bub)) return;
get_bubbles((bubble_type*)bub, bub->index[src], &beg, &sink, &a, &n, NULL);
memset(x->bmerVis.a, 0, x->bmerVis.n);
///select_bmer(src, k, bub, x, 1);
select_bmer_distance(beg^1, k, bub, x, 1, 1);
select_bmer_distance(sink^1, k, bub, x, 1, 1);
}
min_cut_t* clean_hap(hc_links* link, bubble_type* bub, const ma_ug_t *ug)
{
double index_time = yak_realtime();
min_cut_t* x; CALLOC(x, 1);
kvec_t_u64_warp buff;
kv_init(buff.a);
init_min_cut_t(x, link, (const bubble_type*)bub, ug);
// get_Connected_Components(&x);
// check_connective(&x, link);
// print_rGraph(&x);
long long i;
uint64_t k, uID;
///for (i = 0; (uint64_t)i < x.n; i++)
for (i = x->n - 1; i >= 0; i--)
{
uID = x->order.a[i] & x->uID_mode;
///fprintf(stderr, "uID: %lu, f.n: %lu\n", uID, (uint64_t)link->a.a[uID].f.n);
if(link->a.a[uID].f.n == 0) continue;
for (k = 0; k < link->a.a[uID].f.n; k++)
{
if(link->a.a[uID].f.a[k].del) continue;
if(x->utgVis.a[link->a.a[uID].f.a[k].uID] == 0) break;
}
///fprintf(stderr, "k: %lu\n", k);
if(k == link->a.a[uID].f.n) continue;
reset_min_cut_t(x, link);
///fprintf(stderr, "reset\n");
get_s_t(x, link, uID, &(x->src), &(x->dest), &buff);
///fprintf(stderr, "x.src: %lu, x.dest: %lu\n", x.src, x.dest);
///Note: should only consider edges betweem bubbles, ignore edges to homo untigs
/*******************************for debug************************************/
///if(!select_large_node(ug, &x, x.src, x.dest, 10, 0)) continue;
///if(uID != 26818) continue;
//if(uID != 45179) continue;
///memset(x.bmerVis.a, 1, x.bmerVis.n);
get_bmer_unitgs(x, bub, x->b_mer, x->src);
x->bmerVis.a[x->src] = x->bmerVis.a[x->dest] = 1;
/*******************************for debug************************************/
graph_cut(x->src, x->dest, x);
///fprintf(stderr, "graph_cut\n");
x->utgVis.a[uID] = 1;
///exit(0);
}
reset_min_cut_t(x, link);
fprintf(stderr, "[M::%s::%.3f] # edges: %lu, # cutted edges: %lu\n",
__func__, yak_realtime()-index_time, x->n_e, x->c_e);
update_link_by_min_cut_t(x, link);
///destory_min_cut_t(x);
kv_destroy(buff.a);
return x;
}
void init_G_partition(G_partition* x, uint64_t n_utg)
{
uint64_t i;
kv_init(*x);
MALLOC(x->index, n_utg);
for (i = 0; i < n_utg; i++)
{
x->index[i] = (uint32_t)-1;
}
}
void reset_G_partition(G_partition* x, uint64_t n_utg)
{
uint64_t i;
x->n = 0;
for (i = 0; i < n_utg; i++)
{
x->index[i] = (uint32_t)-1;
}
}
void destory_G_partition(G_partition* x)
{
uint64_t i;
for (i = 0; i < x->n; i++)
{
kv_destroy(x->a[i].a);
}
kv_destroy(*x);
free(x->index);
}
double get_hc_weight(uint32_t query, uint32_t v0, uint32_t root, bub_p_t_warp *b, min_cut_t* x)
{
if(v0 == root) return 0;
uint32_t v, u;
hc_edge *p = NULL;
double weight = 0;
v = v0;
do {
u = b->a[v].p; // u->v
p = get_rGraph_edge(x, query>>1, v>>1);
if(p) weight += p->weight;
v = u;
} while (v != root);
return weight;
}
void set_path(bub_p_t_warp *b, uint32_t root, uint8_t* flag, uint8_t label)
{
uint32_t v, u;
///v is the sink of this bubble
v = b->S.a[0];
do {
u = b->a[v].p; // u->v
flag[v>>1] |= label;
v = u;
} while (v != root);
flag[b->S.a[0]>>1] = 0;
}
uint64_t trace_phase_path(ma_ug_t *ug, uint32_t s, uint32_t d, bub_p_t_warp *b, min_cut_t* x, uint8_t* flag, uint8_t label)
{
asg_t *g = ug->g;
if(g->seq[s>>1].del) return 0; // already deleted
if(get_real_length(g, s, NULL)<2) return 0;
uint32_t i, n_pending, is_first, to_replace, cur_nc, cur_uc, cur_ac, n_tips, tip_end, n_pop;
double cur_nh, cur_rate, max_rate;
///S saves nodes with all incoming edges visited
b->S.n = b->T.n = b->b.n = b->e.n = 0;
///for each node, b->a saves all related information
b->a[s].d = b->a[s].nc = b->a[s].ac = b->a[s].uc = 0; b->a[s].nh = 0;
///b->S is the nodes with all incoming edges visited
kv_push(uint32_t, b->S, s);
n_pop = n_tips = n_pending = 0;
tip_end = (uint32_t)-1;
is_first = 1;
do {
///v is a node that all incoming edges have been visited
///d is the distance from v0 to v
uint32_t v = kv_pop(b->S);
uint32_t d = b->a[v].d, nc = b->a[v].nc, uc = b->a[v].uc, ac = b->a[v].ac;
double nh = b->a[v].nh;
uint32_t nv = asg_arc_n(g, v);
asg_arc_t *av = asg_arc_a(g, v);
for (i = 0; i < nv; ++i) {
uint32_t w = av[i].v, l = (uint32_t)av[i].ul; // v->w with length l, not overlap length
bub_p_t *t = &b->a[w];
//got a circle
if ((w>>1) == (s>>1)) goto pop_reset;
//important when poping at long untig graph
if(is_first) l = 0;
if (av[i].del) continue;
///push the edge
kv_push(uint32_t, b->e, (g->idx[v]>>32) + i);
if (t->s == 0)
{ // this vertex has never been visited
kv_push(uint32_t, b->b, w); // save it for revert
///t->p is the parent node of
///t->s = 1 means w has been visited
///d is len(v0->v), l is len(v->w), so t->d is len(v0->w)
t->p = v, t->s = 1, t->d = d + l, t->nc = nc + ug->u.a[(w>>1)].n;
t->r = get_real_length(g, w^1, NULL);
/**need fix**/
t->nh = nh + get_hc_weight(w, v, s, b, x);
t->ac = ac + (flag[(w>>1)] == 0? ug->u.a[(w>>1)].n : 0);
t->uc = uc + (flag[(w>>1)] != 0? ug->u.a[(w>>1)].n : 0);
++n_pending;
}
else {
to_replace = 0;
cur_nc = nc + ug->u.a[(w>>1)].n;
/**need fix**/
cur_nh = nh + get_hc_weight(w, v, s, b, x);
cur_ac = ac + (flag[(w>>1)] == 0? ug->u.a[(w>>1)].n : 0);
cur_uc = uc + (flag[(w>>1)] != 0? ug->u.a[(w>>1)].n : 0);
cur_rate = ((double)(cur_ac)/(double)(cur_ac+cur_uc));
max_rate = ((double)(t->ac)/(double)(t->ac+t->uc));
if(cur_rate > max_rate)
{
to_replace = 1;
}
else if(cur_rate == max_rate)
{
if(cur_nh > t->nh)
{
to_replace = 1;
}
else if(cur_nh == t->nh)
{
if(cur_nc > t->nc)
{
to_replace = 1;
}
else if(cur_nc == t->nc)
{
if(d + l > t->d)
{
to_replace = 1;
}
}
}
}
if(to_replace)
{
t->p = v;
t->nc = cur_nc;
t->nh = cur_nh;
t->ac = cur_ac;
t->uc = cur_uc;
}
if (d + l < t->d) t->d = d + l; // update dist
}
if (--(t->r) == 0) {
uint32_t x = get_real_length(g, w, NULL);
if(x > 0)
{
kv_push(uint32_t, b->S, w);
}
else
{
///at most one tip
if(n_tips != 0) goto pop_reset;
n_tips++;
tip_end = w;
}
--n_pending;
}
}
is_first = 0;
if(n_tips == 1)
{
if(tip_end != (uint32_t)-1 && n_pending == 0 && b->S.n == 0)
{
///sink is b.S.a[0]
kv_push(uint32_t, b->S, tip_end);
break;
}
else
{
goto pop_reset;
}
}
if (i < nv || b->S.n == 0) goto pop_reset;
}while (b->S.n > 1 || n_pending);
n_pop = 1;
/**need fix**/
set_path(b, s, flag, label);
pop_reset:
for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
bub_p_t *t = &b->a[b->b.a[i]];
t->p = t->d = t->nc = t->ac = t->uc = t->r = t->s = 0;
t->nh = 0;
}
return n_pop;
}
inline void get_phased_block(G_partition* x, bubble_type* bub, uint64_t id,
uint32_t* beg, uint32_t* sink, uint32_t** h0, uint32_t* h0_n, uint32_t** h1, uint32_t* h1_n,
uint32_t* phased, uint32_t* bub_id)
{
if(bub && beg && sink && bub_id)
{
(*bub_id) = (*beg) = (*sink) = (uint32_t)-1;
if(x->a[id].a.n > 0)
{
(*bub_id) = bub->index[x->a[id].a.a[0]];
if(IF_BUB(x->a[id].a.a[0], *bub))
{
(*beg) = bub->list.a[bub->num.a[(*bub_id)]];
(*sink) = bub->list.a[bub->num.a[(*bub_id)] + 1];
}
}
}
(*h0) = x->a[id].a.a;
(*h0_n) = x->a[id].h[0];
(*h1) = x->a[id].a.a + x->a[id].h[0];
(*h1_n) = x->a[id].h[1];
if(phased) (*phased) = x->a[id].full_bub;
if((*h0_n) == 0) (*h0) = NULL;
if((*h1_n) == 0) (*h1) = NULL;
}
double get_co_weight(uint32_t *query, uint32_t query_n, uint32_t *target, uint32_t target_n, min_cut_t* m)
{
double weight = 0;
hc_edge *p = NULL;
uint32_t i, k;
for (i = 0; i < query_n; i++)
{
for (k = 0; k < target_n; k++)
{
p = get_rGraph_edge(m, query[i], target[k]);
if(p) weight += p->weight;
}
}
return weight;
}
void phase_bubble(uint64_t bid, bub_p_t_warp *b, bubble_type* bub, uint8_t* flag, const ma_ug_t *ug,
min_cut_t* m, hc_links* link, G_partition* x)
{
#define HAP1_LAB 1
#define HAP2_LAB 2
partition_warp* res = NULL;
kv_pushp(partition_warp, *x, &res);
memset(flag, 0, ug->g->n_seq);
uint32_t beg, sink, n, *a, i, k;
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
res->full_bub = 0;
trace_phase_path((ma_ug_t *)ug, beg, sink, b, m, flag, HAP1_LAB);
trace_phase_path((ma_ug_t *)ug, beg, sink, b, m, flag, HAP2_LAB);
kv_init(res->a);
for (i = 0; i < ug->g->n_seq; i++)
{
if(flag[i] & (uint8_t)HAP1_LAB) kv_push(uint32_t, res->a, i);
}
res->h[0] = res->a.n;
for (i = 0; i < ug->g->n_seq; i++)
{
if(flag[i] & (uint8_t)HAP2_LAB) kv_push(uint32_t, res->a, i);
}
res->h[1] = res->a.n - res->h[0];
if(n == 2) res->full_bub = 1;
if(res->full_bub == 0)
{
double self = 0, intersec = 0;
uint32_t *h0 = NULL, *h1 = NULL;
h0 = res->a.a; h1 = res->a.a + res->h[0];
self += get_co_weight(h0, res->h[0], h0, res->h[0], m);
self += get_co_weight(h1, res->h[1], h1, res->h[1], m);
intersec += get_co_weight(h0, res->h[0], h1, res->h[1], m);
intersec = intersec * 2;
if(self > intersec) res->full_bub = 1;
}
if(res->full_bub == 0)
{
res->a.n = 0;
uint32_t v, u = 0, uv, k_n, pre_n = x->n;
hc_linkeage* t = NULL;
x->n--;
for (i = 0; i < n; i++)
{
v = a[i]>>1;
t = &(link->a.a[v]);
for (k = k_n = 0; k < t->f.n; k++)
{
if(t->f.a[k].del) continue;
k_n++;
u = t->f.a[k].uID;
}
if(k_n != 1) continue;
t = &(link->a.a[u]);
for (k = k_n = 0; k < t->f.n; k++)
{
if(t->f.a[k].del) continue;
k_n++;
uv = t->f.a[k].uID;
}
if(k_n != 1) continue;
if(uv != v) continue;
///avoid dups
for (k = 0; k < i; k++)
{
if((a[k]>>1) == u) break;
}
if(k < i) continue;
kv_pushp(partition_warp, *x, &res);
if(x->n > pre_n) kv_init(res->a);
res->full_bub = 0;
res->h[0] = res->h[1] = 1;
kv_push(uint32_t, res->a, v);
kv_push(uint32_t, res->a, u);
for (k = 0; k < res->a.n; k++)
{
x->index[res->a.a[k]] = x->n-1;
}
}
}
else
{
for (k = 0; k < res->a.n; k++)
{
x->index[res->a.a[k]] = x->n-1;
}
}
/*******************************for debug************************************/
// for (i = 0; i < ug->g->n_seq; i++)
// {
// if(flag[i] & (uint8_t)3)
// {
// uint32_t k;
// for (k = 0; k < n; k++)
// {
// if((a[k]>>1) == i)
// {
// break;
// }
// }
// if(k == n) fprintf(stderr, "ERROR5\n");
// }
// }
/*******************************for debug************************************/
}
void print_phased_bubble(G_partition* x, bubble_type* bub, uint32_t utg_n)
{
uint64_t i, k;
uint32_t beg = 0, sink = 0, h0_n, h1_n, *h0, *h1, full_bub = 0, bubID = 0;
for (i = 0; i < x->n; i++)
{
get_phased_block(x, bub, i, &beg, &sink, &h0, &h0_n, &h1, &h1_n, &full_bub, &bubID);
fprintf(stderr, "\n[%lu]\tbeg:utg%.6ul\tsink:utg%.6ul\tphased=%u\n", i, (beg>>1)+1, (sink>>1)+1, full_bub);
for (k = 0; k < h0_n; k++)
{
fprintf(stderr, "(0) utg%.6ul\n", h0[k] + 1);
}
for (k = 0; k < h1_n; k++)
{
fprintf(stderr, "(1) utg%.6ul\n", h1[k] + 1);
}
uint32_t n, *a;
get_bubbles(bub, bubID, &beg, &sink, &a, &n, NULL);
if(n > 2) fprintf(stderr, "complex\n");
}
/*******************************for debug************************************/
for (i = 0; i < utg_n; i++)
{
if(x->index[i] == (uint32_t)-1) continue;
partition_warp* p = &(x->a[x->index[i]]);
for (k = 0; k < p->a.n; k++)
{
if(p->a.a[k] != i) break;
}
if(k == p->a.n) fprintf(stderr, "ERROR\n");
}
/*******************************for debug************************************/
}
G_partition* clean_bubbles(hc_links* link, bubble_type* bub, min_cut_t* m, const ma_ug_t *ug)
{
double index_time = yak_realtime();
uint64_t i;
bub_p_t_warp b;
memset(&b, 0, sizeof(bub_p_t_warp));
CALLOC(b.a, ug->g->n_seq*2);
uint8_t* flag = NULL;
CALLOC(flag, ug->g->n_seq);
G_partition* x; CALLOC(x, 1);
init_G_partition(x, ug->g->n_seq);
for (i = 0; i < bub->f_bub; i++)
{
phase_bubble(i, &b, bub, flag, ug, m, link, x);
}
free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
free(flag);
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
///print_phased_bubble(x, bub, ug->g->n_seq);
return x;
}
uint64_t get_hic_distance(pe_hit* hit, hc_links* link, const ha_ug_index* idx)
{
uint64_t s_uid, s_dir, e_uid, e_dir, u_dis, k;
long long s_pos, e_pos;
s_uid = ((hit->s<<1)>>(64 - idx->uID_bits)); s_pos = hit->s & idx->pos_mode;
e_uid = ((hit->e<<1)>>(64 - idx->uID_bits)); e_pos = hit->e & idx->pos_mode;
if(s_uid == e_uid) return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
hc_linkeage* t = &(link->a.a[s_uid]);
for (k = 0; k < t->e.n; k++)
{
if(t->e.a[k].del || t->e.a[k].uID != e_uid) continue;
s_dir = (!!(t->e.a[k].dis&(uint64_t)2));
e_dir = (!!(t->e.a[k].dis&(uint64_t)1));
u_dis = (t->e.a[k].dis ==(uint64_t)-1? (uint64_t)-1 : t->e.a[k].dis>>3);
// if(s_uid == 24684 && s_pos == 124953 && e_uid == 16950 && e_pos == 93039)
// {
// fprintf(stderr, "*****************s_dir: %lu, e_dir: %lu, u_dis: %lu\n", s_dir, e_dir, u_dis);
// }
if(u_dis == (uint64_t)-1) return (uint64_t)-1;
if(s_dir == 1) s_pos = (long long)idx->ug->g->seq[s_uid].len - s_pos - 1;
if(e_dir == 1) e_pos = (long long)idx->ug->g->seq[e_uid].len - e_pos - 1;
e_pos = e_pos + u_dis - (long long)idx->ug->g->seq[e_uid].len;
return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
}
return (uint64_t)-1;
}
hc_edge* get_hc_edge(hc_links* link, uint64_t src, uint64_t dest, uint64_t dir)
{
if(src >= link->a.n) return NULL;
uint64_t i, n;
hc_edge* a = NULL;
if(dir == 0)
{
n = link->a.a[src].e.n;
a = link->a.a[src].e.a;
}
else
{
n = link->a.a[src].f.n;
a = link->a.a[src].f.a;
}
for (i = 0; i < n; i++)
{
if(a[i].del) continue;
if(a[i].uID == dest) return &(a[i]);
}
return NULL;
}
inline double get_trans(const ha_ug_index* idx, uint64_t x)
{
return idx->a*(x/idx->frac) + idx->b;
}
inline double get_trans_weight_advance(const ha_ug_index* idx, uint64_t x, trans_idx* dis)
{
long double rate = 0;
if(x == (uint64_t)-1) x = dis->med;
if(x < dis->max)
{
uint64_t i;
for (i = 0; i < dis->n; i++)
{
if(x < dis->a[i].end && x >= dis->a[i].beg) break;
}
if(i < dis->n)
{
rate = ((double)(dis->a[i].cnt_1))/((double)(dis->a[i].cnt_0 + dis->a[i].cnt_1));
}
else
{
rate = get_trans(idx, x);
}
}
else
{
rate = get_trans(idx, x);
}
if(rate < 0) rate = 0;
rate += OFFSET_RATE;
if(rate > 0.5) rate = 0.5;
rate -= OFFSET_SECOND_RATE; //[OFFSET_RATE - OFFSET_SECOND_RATE, 0.5 - OFFSET_SECOND_RATE]
long double w = logl((1/rate)-1)*SCALL;
if(w < OFFSET_RATE_MIN_W) w = OFFSET_RATE_MIN_W;
if(w > OFFSET_RATE_MAX_W) w = OFFSET_RATE_MAX_W;
return w;
}
void LeastSquare_advance(trans_idx* dis, ha_ug_index* idx, uint64_t med)
{
#define SCAL_RATE 1000
long double t1=0, t2=0, t3=0, t4=0, x, y;
uint64_t i, m, ava_size;
for (i = m = 0; i < dis->n; i++)
{
x = ((double)(dis->a[i].beg + dis->a[i].end))/2;
y = ((double)(dis->a[i].cnt_1))/((double)(dis->a[i].cnt_0 + dis->a[i].cnt_1));
if(dis->a[i].beg >= med) break;
t1 += x*x;
t2 += x;
t3 += x*y;
t4 += y;
m++;
}
if(i < dis->n)
{
uint64_t beg, end, cnt_0, cnt_1;
for (beg = dis->a[i].beg, end = dis->a[i].end, cnt_0 = cnt_1 = 0; i < dis->n; i++)
{
cnt_0 += dis->a[i].cnt_0;
cnt_1 += dis->a[i].cnt_1;
beg = MIN(beg, dis->a[i].beg);
end = MAX(end, dis->a[i].end);
}
x = ((double)(beg + end))/2;
y = ((double)(cnt_1))/((double)(cnt_0 + cnt_1));
t1 += x*x;
t2 += x;
t3 += x*y;
t4 += y;
m++;
}
if(t2 > t4)
{
idx->frac = t2/t4;
if(idx->frac > SCAL_RATE) idx->frac = idx->frac / SCAL_RATE;
if(idx->frac < 1) idx->frac = 1;
}
ava_size = m;
t1 /= (idx->frac*idx->frac);
t2 /= idx->frac;
t3 /= idx->frac;
if((t1*ava_size - t2*t2) != 0)
{
idx->a = (t3*ava_size - t2*t4) / (t1*ava_size - t2*t2);
}
if((t1*ava_size - t2*t2) != 0)
{
idx->b = (t1*t4 - t2*t3) / (t1*ava_size - t2*t2);
}
}
void weight_edges_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, trans_idx* dis)
{
uint64_t k, i, shif = 64 - idx->uID_bits, beg, end, t_d;
hc_edge *e1 = NULL, *e2 = NULL;
long double weight;
for (i = 0; i < link->a.n; i++)
{
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
link->a.a[i].e.a[k].weight = 0;
}
}
for (k = 0; k < hits->a.n; ++k)
{
beg = ((hits->a.a[k].s<<1)>>shif);
end = ((hits->a.a[k].e<<1)>>shif);
if(beg == end) continue;
if(IF_HOM(beg, *bub)) continue;
if(IF_HOM(end, *bub)) continue;
t_d = get_hic_distance(&(hits->a.a[k]), link, idx);
if(t_d == (uint64_t)-1) continue;
e1 = get_hc_edge(link, beg, end, 0);
e2 = get_hc_edge(link, end, beg, 0);
if(e1 == NULL || e2 == NULL) continue;
weight = 1;
if(dis)
{
weight = get_trans_weight_advance(idx, t_d, dis);
}
e1->weight += weight; e1->occ++;
e2->weight += weight; e2->occ++;
}
}
void get_bub_id(bubble_type* bub, uint32_t root, uint64_t* id0, uint64_t* id1, uint32_t check_het)
{
if(id0) (*id0) = (uint64_t)-1;
if(id1) (*id1) = (uint64_t)-1;
uint64_t b_id0 = (uint64_t)-1, b_id1 = (uint64_t)-1;
uint32_t beg, sink;
if((bub->b_s_idx.a[root]&0xffffffff) != 0xffffffff)
{
b_id0 = bub->b_s_idx.a[root]&0xffffffff;
if(check_het)
{
get_bubbles(bub, b_id0, &beg, &sink, NULL, NULL, NULL);
if(IF_HET(beg>>1, *bub) && IF_HET(sink>>1, *bub)) b_id0 = (uint64_t)-1;
}
}
if((bub->b_s_idx.a[root]&0xffffffff00000000) != 0xffffffff00000000)
{
b_id1 = bub->b_s_idx.a[root]&0xffffffff00000000; b_id1 >>= 32;
if(check_het)
{
get_bubbles(bub, b_id1, &beg, &sink, NULL, NULL, NULL);
if(IF_HET(beg>>1, *bub) && IF_HET(sink>>1, *bub)) b_id1 = (uint64_t)-1;
}
}
if(b_id0 == (uint64_t)-1 && b_id1 != (uint64_t)-1)
{
b_id0 = b_id1;
b_id1 = (uint64_t)-1;
}
if(id0) (*id0) = b_id0;
if(id1) (*id1) = b_id1;
}
///return how many bubbles linked by this node
uint32_t connect_bub_occ(bubble_type* bub, uint32_t root_id, uint32_t check_het)
{
uint64_t id0, id1, occ = 2;
get_bub_id(bub, root_id, &id0, &id1, check_het);
if(id0 == (uint64_t)-1) occ--;
if(id1 == (uint64_t)-1) occ--;
return occ;
}
///x_0 and x_1 are the ids of unitigs;
///x_0_b_id and x_1_b_id are the ids of bubble graph;
int ma_2_bub_arc(bubble_type* bub, uint32_t x_0, uint32_t* x_0_b_id, uint32_t x_1, uint32_t* x_1_b_id,
asg_arc_t *p, uint32_t check_het)
{
uint64_t id0, ori_0, id1, ori_1, tmp_id;
uint32_t beg, sink, n, *a, x;
uint32_t beg_0, sink_0, beg_1, sink_1;
if(x_0_b_id) id0 = (*x_0_b_id);
if(x_1_b_id) id1 = (*x_1_b_id);
if((x_0 != (uint32_t)-1) && (x_1 != (uint32_t)-1))
{
if(((x_0>>1) == (x_1>>1)))
{
if(x_0_b_id == NULL && x_1_b_id == NULL)
{
get_bub_id(bub, x_0>>1, &id0, &id1, check_het);
}
get_bubbles(bub, id0, &beg_0, &sink_0, &a, &n, NULL);
get_bubbles(bub, id1, &beg_1, &sink_1, &a, &n, NULL);
ori_0 = (uint64_t)-1;
if(x_0 == (beg_0^1))
{
ori_0 = 1;
}
else if(x_0 == (sink_0^1))
{
ori_0 = 0;
}
else if(x_0 == (beg_1^1))
{
ori_0 = 1+2;
}
else if(x_0 == (sink_1^1))
{
ori_0 = 0+2;
}
else
{
fprintf(stderr, "error 0\n");
return 0;
}
ori_1 = (uint64_t)-1;
if(x_1 == (beg_0^1))
{
ori_1 = 1;
}
else if(x_1 == (sink_0^1))
{
ori_1 = 0;
}
else if(x_1 == (beg_1^1))
{
ori_1 = 1 + 2;
}
else if(x_1 == (sink_1^1))
{
ori_1 = 0 + 2;
}
else
{
fprintf(stderr, "error 1\n");
return 0;
}
if((((ori_0>>1)^(ori_1>>1))&1) != 1)
{
fprintf(stderr, "error 10\n");
fprintf(stderr, "x_0: %u, id0: %lu, beg_0: %u, sink_0: %u, ori_0: %lu\n",
x_0, id0, beg_0, sink_0, ori_0);
fprintf(stderr, "x_1: %u, id1: %lu, beg_1: %u, sink_1: %u, ori_1: %lu\n",
x_1, id1, beg_1, sink_1, ori_1);
return 0;
}
if(ori_0 & 2)
{
tmp_id = id0; id0 = id1; id1 = tmp_id;
}
ori_0 &= 1; ori_1 &= 1; ori_1 ^= 1;
p->ul = (id0<<1) | ori_0; p->ul <<= 32; p->ul += 0;
p->v = (id1<<1) | ori_1;
p->ol = 0; p->del = 0; p->el = p->no_l_indel = p->strong = 1;
}
else
{
if(x_0_b_id == NULL) get_bub_id(bub, x_0>>1, &id0, NULL, check_het);
if(x_1_b_id == NULL) get_bub_id(bub, x_1>>1, &id1, NULL, check_het);
get_bubbles(bub, id0, &beg, &sink, &a, &n, NULL);
ori_0 = (uint64_t)-1;
if(x_0 == (beg^1))
{
ori_0 = 1;
}
else if(x_0 == (sink^1))
{
ori_0 = 0;
}
else
{
fprintf(stderr, "error 0\n");
return 0;
}
get_bubbles(bub, id1, &beg, &sink, &a, &n, NULL);
ori_1 = (uint64_t)-1;
if(x_1 == (beg^1))
{
ori_1 = 1;
}
else if(x_1 == (sink^1))
{
ori_1 = 0;
}
else
{
fprintf(stderr, "error 1\n");
return 0;
}
ori_0 &= 1; ori_1 &= 1; ori_1 ^= 1;
p->ul = (id0<<1) | ori_0; p->ul <<= 32; p->ul += 0;
p->v = (id1<<1) | ori_1;
p->ol = 0; p->del = 0; p->el = p->no_l_indel = p->strong = 1;
}
}
else
{
x = (uint32_t)-1;
if(x_0 != (uint32_t)-1) x = x_0;
if(x_1 != (uint32_t)-1) x = x_1;
if(x == (uint32_t)-1) return 0;
if(x_0_b_id == NULL && x_1_b_id == NULL)
{
get_bub_id(bub, x>>1, &id0, &id1, check_het);
}
if(id0 != (uint64_t)-1)
{
get_bubbles(bub, id0, &beg, &sink, &a, &n, NULL);
if(x == (beg^1))
{
return 1;
}
else if(x == (sink^1))
{
return 1;
}
return 0;
}
if(id1 != (uint64_t)-1)
{
get_bubbles(bub, id1, &beg, &sink, &a, &n, NULL);
if(x == (beg^1))
{
return 1;
}
else if(x == (sink^1))
{
return 1;
}
return 0;
}
}
return 1;
}
#define arc_first(g, v) ((g)->arc[(g)->idx[(v)]>>32])
#define arc_cnt(g, v) ((uint32_t)(g)->idx[(v)])
void debug_bub_utg(bubble_type* bub, ma_ug_t *bug, asg_t *bsg, uint32_t check_het)
{
uint32_t i, k, rId, rId_next, ori, ori_next, root, beg, end;
uint64_t id0, id1;
ma_utg_t *u = NULL;
asg_arc_t *t = NULL;
for (i = 0; i < bug->u.n; i++)
{
u = &(bug->u.a[i]);
if(u->n == 0) continue;
for (k = 0; k < u->n; k++)
{
if(k+1 >= u->n) continue;
rId = u->a[k]>>33;
ori = u->a[k]>>32&1;
get_bubbles(bub, rId, ori == 1?&root:NULL, ori == 0?&root:NULL, NULL, NULL, NULL);
t = &(arc_first(bsg, u->a[k]>>32));
get_bub_id(bub, root>>1, &id0, &id1, check_het);
if(id0 == (uint64_t)-1 || (t->el == 1 && id1 == (uint64_t)-1) || (t->el == 0 && id1 != (uint64_t)-1))
{
fprintf(stderr, "sbsbsb0sbsbsb-utg%.6d, check_het: %u\n", (int)((root>>1)+1), check_het);
fprintf(stderr, "id0: %lu, id1: %lu, t->el: %u\n", id0, id1, t->el);
continue;
}
///fprintf(stderr, "aaaaaaaa10aaaaaaaa-utg%.6d\n", (int)((root>>1)+1));
rId_next = u->a[k+1]>>33;
ori_next = u->a[k+1]>>32&1;
get_bubbles(bub, rId, &beg, &end, NULL, NULL, NULL);
if(ori == 1)
{
if(root != beg) fprintf(stderr, "sbsbsb1sbsbsb, root: %u, beg: %u, end: %u\n", root, beg, end);
}
else
{
if(root != end) fprintf(stderr, "sbsbsb2sbsbsb, root: %u, beg: %u, end: %u\n", root, beg, end);
}
if(t->el == 1)
{
get_bubbles(bub, rId_next, &beg, &end, NULL, NULL, NULL);
if(ori_next == 0)
{
if(root != (beg^1)) fprintf(stderr, "sbsbsb3sbsbsb, root: %u, beg: %u, end: %u\n", root, beg, end);
}
else
{
if(root != (end^1)) fprintf(stderr, "sbsbsb4sbsbsb, root: %u, beg: %u, end: %u\n", root, beg, end);
}
}
}
}
fprintf(stderr, "[M::%s]\n", __func__);
}
///just change the hap status of beg/sink, but they are are still at a chain of bubble
///might be ok
inline void set_bub_idx(bubble_type* bub, ma_utg_t *bu, asg_t *untig_sg, int beg_idx, int end_idx,
uint32_t is_to_hom, uint32_t check_het)
{
int k;
uint32_t rId, ori, root;
uint64_t id0, id1, len0, len1;
for (k = beg_idx; k <= end_idx; k++)
{
rId = bu->a[k]>>33;
ori = bu->a[k]>>32&1;
get_bubbles(bub, rId, ori == 1?&root:NULL, ori == 0?&root:NULL, NULL, NULL, NULL);
if(is_to_hom && IF_HOM(root>>1, *bub)) continue;
if(!is_to_hom && IF_HET(root>>1, *bub)) continue;
get_bub_id(bub, root>>1, &id0, &id1, check_het);
if(id0 == (uint64_t)-1 || id1 == (uint64_t)-1) continue;
get_bubbles(bub, id0, NULL, NULL, NULL, NULL, &len0);
get_bubbles(bub, id1, NULL, NULL, NULL, NULL, &len1);
if(is_to_hom)
{
if(untig_sg->seq[root>>1].len > (MIN(len0, len1)*3)) continue;
bub->index[root>>1] = (uint32_t)-1;
}
else
{
bub->index[root>>1] = bub->f_bub+1;
}
}
}
void determine_bub_idx(bubble_type* bub, ma_utg_t *bu, asg_t *untig_sg, uint64_t pLen,
uint64_t rLEN, uint64_t r_hetLen, int beg_idx, int end_idx, uint32_t check_het)
{
if(beg_idx > end_idx) return;
uint64_t r_homLen = rLEN - r_hetLen;
///pLen: total length, rLEN: beg/sink length
if(pLen > 0 && rLEN > 0 && r_hetLen > 0 && rLEN < pLen*0.5 && r_hetLen < rLEN * 0.2) ///set het to hom
{
set_bub_idx(bub, bu, untig_sg, beg_idx, end_idx, 1, bub->check_het);
}
else if(pLen > 0 && rLEN > 0 && r_homLen > 0 && rLEN > pLen*0.9 && r_homLen < rLEN * 0.1) ///set hom to het
{
set_bub_idx(bub, bu, untig_sg, beg_idx, end_idx, 0, bub->check_het);
}
}
void detect_bub_graph(bubble_type* bub, asg_t *untig_sg)
{
asg_t *bg = bub->b_g;
ma_ug_t *ug = NULL;
ug = ma_ug_gen(bub->b_g);
///debug_bub_utg(bub, ug, bg, bub->check_het);
uint32_t i, k, rId, ori, root, r_root;
int beg_idx, end_idx;
uint64_t pLen, rLEN, r_hetLen;
ma_utg_t *u = NULL;
asg_arc_t *t = NULL;
for (i = 0; i < ug->u.n; i++)
{
u = &(ug->u.a[i]);
if(u->n == 0) continue;
for (k = pLen = rLEN = r_hetLen = beg_idx = 0, end_idx = -1; k < u->n; k++)
{
rId = u->a[k]>>33;
ori = u->a[k]>>32&1;
get_bubbles(bub, rId, ori == 1?&root:&r_root, ori == 0?&root:&r_root, NULL, NULL, NULL);
t = NULL;
if(k+1 < u->n) t = &(arc_first(bg, u->a[k]>>32));
pLen += bg->seq[rId].len;///path length in bubble
if(end_idx < beg_idx) ///first bubble
{
pLen += untig_sg->seq[r_root>>1].len;
rLEN += untig_sg->seq[r_root>>1].len;
if(IF_HET(r_root>>1, *bub)) r_hetLen += untig_sg->seq[r_root>>1].len;
}
if(t)
{
if(t->el == 0)
{
if(end_idx >= beg_idx)
{
pLen += untig_sg->seq[root>>1].len;
rLEN += untig_sg->seq[root>>1].len;
if(IF_HET(root>>1, *bub)) r_hetLen += untig_sg->seq[root>>1].len;
determine_bub_idx(bub, u, untig_sg, pLen, rLEN, r_hetLen, beg_idx, end_idx, bub->check_het);
}
pLen = rLEN = r_hetLen = 0;
beg_idx = k + 1; end_idx = k;
}
else
{
pLen += t->ol;
rLEN += t->ol;
if(IF_HET(root>>1, *bub)) r_hetLen += t->ol;
end_idx = k;
}
}
}
if(end_idx >= beg_idx)
{
pLen += untig_sg->seq[root>>1].len;
rLEN += untig_sg->seq[root>>1].len;
if(IF_HET(root>>1, *bub)) r_hetLen += untig_sg->seq[root>>1].len;
determine_bub_idx(bub, u, untig_sg, pLen, rLEN, r_hetLen, beg_idx, end_idx, bub->check_het);
}
}
ma_ug_destroy(ug);
}
void get_bub_graph(ma_ug_t* ug, bubble_type* bub)
{
asg_t *sg = ug->g;
asg_arc_t t, *p = NULL;
pdq pq;
init_pdq(&pq, sg->n_seq<<1);
uint32_t n_vtx = sg->n_seq<<1, v, k;
uint32_t *pre = NULL; MALLOC(pre, n_vtx);
uint32_t pre_id, adjecent, bub_occ;
asg_t *bub_g = asg_init();
for (v = 0; v < bub->f_bub; v++)
{
uint64_t pathbase;
uint32_t beg, sink;
get_bubbles(bub, v, &beg, &sink, NULL, NULL, &pathbase);
asg_seq_set(bub_g, v, pathbase, (bub->check_het && IF_HET(beg>>1, *bub) && IF_HET(sink>>1, *bub))?1:0);
bub_g->seq[v].c = PRIMARY_LABLE;
}
//check all unitigs
for (v = 0; v < n_vtx; ++v)
{
if(sg->seq[v>>1].del) continue;
if(bub->b_s_idx.a[v>>1] == (uint64_t)-1) continue; ///if (v>>1) is not a beg or sink of bubbles
bub_occ = connect_bub_occ(bub, v>>1, bub->check_het);
if(bub_occ == 0) continue;
if(bub_occ == 2)
{
if(ma_2_bub_arc(bub, v, NULL, v^1, NULL, &t, bub->check_het))
{
t.ol = sg->seq[v>>1].len;
p = asg_arc_pushp(bub_g);
*p = t;
}
continue;
}
if(ma_2_bub_arc(bub, v, NULL, (uint32_t)-1, NULL, &t, bub->check_het) == 0) continue;
get_shortest_path(v, &pq, sg, pre);
for (k = 0; k < pq.dis.n; k++)
{
if(pq.dis.a[k] == (uint64_t)-1) continue;
if(bub->b_s_idx.a[k>>1] == (uint64_t)-1) continue;
if(connect_bub_occ(bub, k>>1, bub->check_het) == 0) continue;
if((k>>1) == (v>>1)) continue;
pre_id = pre[k];
adjecent = 0;
while (pre_id != v)
{
if(connect_bub_occ(bub, pre_id>>1, bub->check_het) > 0)
{
adjecent = 1;
break;
}
pre_id = pre[pre_id];
}
if(adjecent == 0)
{
if(ma_2_bub_arc(bub, v, NULL, k^1, NULL, &t, bub->check_het))
{
t.el = 0; t.ol = pq.dis.a[k] + sg->seq[k>>1].len;
p = asg_arc_pushp(bub_g);
*p = t;
}
}
}
}
free(pre);
destory_pdq(&pq);
asg_cleanup(bub_g);
bub_g->r_seq = bub_g->n_seq;
bub->b_g = bub_g;
}
void print_bubble_chain(bubble_type* bub, const char* command)
{
ma_ug_t *ug = NULL;
ug = ma_ug_gen(bub->b_g);
uint32_t i, k, j, rId, beg, sink, *a, n;
ma_utg_t *u = NULL;
asg_arc_t *t = NULL;
for (i = 0; i < ug->u.n; i++)
{
u = &(ug->u.a[i]);
if(u->n == 0) continue;
fprintf(stderr,"\n%s: chain-%u\n", command, i);
for (k = 0; k < u->n; k++)
{
rId = u->a[k]>>33;
get_bubbles(bub, rId, &beg, &sink, &a, &n, NULL);
t = NULL;
if(k+1 < u->n) t = &(arc_first(bub->b_g, u->a[k]>>32));
fprintf(stderr, "[utg%.6dl, utg%.6dl] el=%u no_long_indel=%u, rId=%u, nv: %u, nv^: %u\n",
(int)((beg>>1)+1), (int)((sink>>1)+1), t?t->el:16, t?t->no_l_indel:16, rId, arc_cnt(bub->b_g, u->a[k]>>32), arc_cnt(bub->b_g, (u->a[k]>>32)^1));
// if((u->a[k]>>33) == 9658)
// {
// asg_arc_t *av;
// uint32_t nv, nv_i;
// av = asg_arc_a(bub->b_g, u->a[k]>>32);
// nv = asg_arc_n(bub->b_g, u->a[k]>>32);
// for (nv_i = 0; nv_i < nv; nv_i++)
// {
// if(av[nv_i].del) continue;
// fprintf(stderr, "v--->%u\n", av[nv_i].v>>1);
// }
// av = asg_arc_a(bub->b_g, (u->a[k]>>32)^1);
// nv = asg_arc_n(bub->b_g, (u->a[k]>>32)^1);
// for (nv_i = 0; nv_i < nv; nv_i++)
// {
// if(av[nv_i].del) continue;
// fprintf(stderr, "v^1--->%u\n", av[nv_i].v>>1);
// }
// }
if(bub->b_g->seq[rId].c == HAP_LABLE)
{
for (j = 0; j < n; j++)
{
fprintf(stderr, ">>>utg%.6dl\n", (int)((a[j]>>1)+1));
}
}
}
}
ma_ug_destroy(ug);
}
int is_simple_broken_bubble(ma_ug_t *unitig_ug, uint32_t x, uint32_t beg, uint32_t sink, uint32_t* new_het)
{
uint32_t nv, v = (uint32_t)-1, u_s = (uint32_t)-1, u_e = (uint32_t)-1, i;
asg_arc_t *av = NULL;
(*new_het) = (uint32_t)-1;
if((asg_arc_n(unitig_ug->g, x) == 1)
&& (asg_arc_n(unitig_ug->g, x^1) == 0))
{
v = x;
}
if((asg_arc_n(unitig_ug->g, x^1) == 1)
&& (asg_arc_n(unitig_ug->g, x) == 0))
{
v = x^1;
}
if(v == (uint32_t)-1) return 0;
av = asg_arc_a(unitig_ug->g, v);
nv = asg_arc_n(unitig_ug->g, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
if((av[i].v>>1) == (beg>>1)) u_s = beg, u_e = sink;
if((av[i].v>>1) == (sink>>1)) u_s = sink, u_e = beg;
}
if(u_s == (uint32_t)-1 || u_e == (uint32_t)-1) return 0;
av = asg_arc_a(unitig_ug->g, u_s);
nv = asg_arc_n(unitig_ug->g, u_s);
if(nv != 2) return 0;
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
if(av[i].v == (v^1)) continue;
if(av[i].v == (u_e^1))
{
(*new_het) = u_e;
return 1;
}
}
return 0;
}
int double_check_broken_bubble(asg_t *g, kvec_t_u32_warp* broken, uint32_t beg, uint32_t sink,
uint8_t* vis_flag, uint32_t vis_flag_n, kvec_t_u32_warp* stack, asg_t *bsg, asg_arc_t *p_t)
{
uint32_t cur, ncur, i, n, pre, occ;
radix_sort_u32(broken->a.a, broken->a.a + broken->a.n);
for (i = n = 0, pre = (uint32_t)-1; i < broken->a.n; i++)
{
if((broken->a.a[i]>>1) == (pre>>1)) continue;
pre = broken->a.a[i];
broken->a.a[n] = pre;
n++;
}
broken->a.n = n;
asg_arc_t *acur = NULL;
memset(vis_flag, 0, vis_flag_n);
stack->a.n = 0;
kv_push(uint32_t, stack->a, beg);
occ = 0;
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(vis_flag[cur] == 0 && vis_flag[cur^1] == 0) occ++;
if(vis_flag[cur] == 0 && cur != (beg^1) && (sink == (uint32_t)-1 || cur != (sink^1)))
{
vis_flag[cur] = 1;
ncur = asg_arc_n(g, cur);
acur = asg_arc_a(g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(vis_flag[acur[i].v]) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
vis_flag[cur] = 1;
cur^=1;
if(vis_flag[cur] == 0 && cur != (beg^1) && (sink == (uint32_t)-1 || cur != (sink^1)))
{
vis_flag[cur] = 1;
ncur = asg_arc_n(g, cur);
acur = asg_arc_a(g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(vis_flag[acur[i].v]) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
vis_flag[cur] = 1;
}
n = broken->a.n;
if(beg != (uint32_t)-1) n++;
if(sink != (uint32_t)-1) n++;
if(occ > n)
{
///fprintf(stderr, "\n+++++sb+++++beg-utg%.6ul, sink-utg%.6ul, occ: %u, n: %u\n", (beg>>1)+1, (sink>>1)+1, occ, n);
if(bsg && p_t && beg != (uint32_t)-1 && sink != (uint32_t)-1)
{
p_t->del = 1;
asg_arc_del(bsg, (p_t->v)^1, (p_t->ul>>32)^1, 1);
}
/*******************************for debug************************************/
// memset(vis_flag, 0, vis_flag_n);
// stack->a.n = 0;
// kv_push(uint32_t, stack->a, beg);
// occ = 0;
// while (stack->a.n > 0)
// {
// occ++;
// stack->a.n--;
// cur = stack->a.a[stack->a.n];
// fprintf(stderr, "cur-utg%.6ul\n", (cur>>1)+1);
// vis_flag[cur] = 1;
// if(cur == (beg^1) || cur == (sink^1)) continue;
// ncur = asg_arc_n(g, cur);
// acur = asg_arc_a(g, cur);
// for (i = 0; i < ncur; i++)
// {
// if(acur[i].del) continue;
// if(vis_flag[acur[i].v]) continue;
// kv_push(uint32_t, stack->a, acur[i].v);
// }
// cur^=1;
// if(vis_flag[cur]) continue;
// vis_flag[cur] = 1;
// if(cur == (beg^1) || cur == (sink^1)) continue;
// ncur = asg_arc_n(g, cur);
// acur = asg_arc_a(g, cur);
// for (i = 0; i < ncur; i++)
// {
// if(acur[i].del) continue;
// if(vis_flag[acur[i].v]) continue;
// kv_push(uint32_t, stack->a, acur[i].v);
// }
// }
// for (i = 0; i < broken->a.n; i++)
// {
// fprintf(stderr, "*****cur-utg%.6ul\n", (broken->a.a[i]>>1)+1);
// }
/*******************************for debug************************************/
return 0;
}
return 1;
}
int is_local_simple_circle(asg_t *g, uint32_t v)
{
if(asg_arc_n(g, v) != asg_arc_n(g, v^1)) return 0;
if(asg_arc_n(g, v) == 1) v = arc_first(g, v).v;
if(asg_arc_n(g, v) != asg_arc_n(g, v^1)) return 0;
if(asg_arc_n(g, v) != 2) return 0;
uint32_t ncur, i, u;
asg_arc_t *acur = NULL;
ncur = asg_arc_n(g, v);
acur = asg_arc_a(g, v);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
u = acur[i].v;
if(asg_arc_n(g, u) != 1 || asg_arc_n(g, u^1) != 1) continue;
if(arc_first(g, u).v != v) continue;
return 1;
}
return 0;
}
///actually not useful, and may have bug when one bubble at multipe chains
void update_bub_b_s_idx(bubble_type* bub)
{
memset(bub->b_s_idx.a, -1, bub->b_s_idx.n * sizeof(uint64_t));
uint32_t i, v, beg, sink, n_bub = bub->num.n - 1;
for (i = 0; i < n_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, NULL, NULL, NULL);
if(beg != (uint32_t)-1)
{
v = beg>>1;
if(bub->b_s_idx.a[v] == (uint64_t)-1)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
else if((bub->b_s_idx.a[v] & 0xffffffff00000000) == 0xffffffff00000000)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
}
if(sink != (uint32_t)-1)
{
v = sink>>1;
if(bub->b_s_idx.a[v] == (uint64_t)-1)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
else if((bub->b_s_idx.a[v] & 0xffffffff00000000) == 0xffffffff00000000)
{
bub->b_s_idx.a[v] <<= 32;
bub->b_s_idx.a[v] |= i;
}
}
}
}
void update_bubble_graph(kvec_t_u32_warp* broken, uint32_t beg, uint32_t beg_bub_id,
uint32_t sink, uint32_t sink_bub_id, bubble_type* bub, kvec_asg_arc_t_warp* edges, asg_t *bsg,
asg_arc_t *p_t, uint8_t *bsg_idx, ma_ug_t *unitig_ug, uint64_t* occ_thres, uint64_t is_b_bub)
{
uint32_t i, pre, n, bub_id, v;
uint64_t occ;
asg_arc_t t_f, t_r;
radix_sort_u32(broken->a.a, broken->a.a + broken->a.n);
for (i = n = occ = 0, pre = (uint32_t)-1; i < broken->a.n; i++)
{
if((broken->a.a[i]>>1) == (pre>>1)) continue;
if(IF_HOM((broken->a.a[i]>>1), *bub))
{
if(is_local_simple_circle(unitig_ug->g, broken->a.a[i]))
{
bub->index[broken->a.a[i]>>1] = bub->f_bub+1;
}
else
{
continue;
}
}
pre = broken->a.a[i];
broken->a.a[n] = pre;
occ += unitig_ug->u.a[broken->a.a[n]>>1].n;
n++;
}
broken->a.n = n;
///if(broken->a.n == 0) return;
if(broken->a.n == 1)
{
///fprintf(stderr, "+++++sb+++++utg%.6ul\n", (broken->a.a[0]>>1)+1);
if(beg != (uint32_t)-1 && sink != (uint32_t)-1 &&
is_simple_broken_bubble(unitig_ug, broken->a.a[0], beg, sink, &v))
{
if((v>>1) != (broken->a.a[0]>>1))
{
///fprintf(stderr, "-----sb-----utg%.6ul\n", (v>>1)+1);
kv_push(uint32_t, broken->a, v);
occ += unitig_ug->u.a[v>>1].n;
if(occ_thres && occ > (*occ_thres)) return;
bub->index[v>>1] = bub->f_bub+1; ///set to het
}
}
}
if(occ_thres && occ > (*occ_thres)) return;
/********************push graph node********************/
bub_id = bub->b_g->n_seq;
asg_seq_set(bub->b_g, bub_id, 0, 0);
bub->b_g->seq[bub_id].c = HAP_LABLE;
if(is_b_bub) bub->b_bub++;
/********************push graph node********************/
/********************push bubble********************/
kv_push(uint32_t, bub->num, bub->list.n);
kv_push(uint64_t, bub->pathLen, 0);
kv_push(uint32_t, bub->list, beg);
kv_push(uint32_t, bub->list, sink);
for (i = 0; i < broken->a.n; i++)
{
kv_push(uint32_t, bub->list, broken->a.a[i]);
if(bsg_idx) bsg_idx[broken->a.a[i]>>1] = 1;
}
/********************push bubble********************/
if(beg != (uint32_t)-1) ///beg_bub_id ----> bub_id
{
if(ma_2_bub_arc(bub, beg, &beg_bub_id, beg^1, &bub_id, &t_f, bub->check_het) &&
ma_2_bub_arc(bub, beg^1, &bub_id, beg, &beg_bub_id, &t_r, bub->check_het))
{
t_f.el = 0; t_f.no_l_indel = 0; t_f.del = 0;
kv_push(asg_arc_t, edges->a, t_f);
t_r.el = 0; t_r.no_l_indel = 0; t_r.del = 0;
kv_push(asg_arc_t, edges->a, t_r);
}
}
if(sink != (uint32_t)-1) ///bub_id ----> sink_bub_id
{
if(ma_2_bub_arc(bub, sink^1, &bub_id, sink, &sink_bub_id, &t_f, bub->check_het) &&
ma_2_bub_arc(bub, sink, &sink_bub_id, sink^1, &bub_id, &t_r, bub->check_het))
{
t_f.el = 0; t_f.no_l_indel = 0; t_f.del = 0;
kv_push(asg_arc_t, edges->a, t_f);
t_r.el = 0; t_r.no_l_indel = 0; t_r.del = 0;
kv_push(asg_arc_t, edges->a, t_r);
}
}
if(beg != (uint32_t)-1 && sink != (uint32_t)-1 && p_t)
{
p_t->del = 1;
asg_arc_del(bsg, (p_t->v)^1, (p_t->ul>>32)^1, 1);
}
}
void get_related_bub_nodes(kvec_t_u32_warp* broken, bubble_type* bub, pdq* pq, asg_t *unitig_g,
uint32_t *pre, uint32_t src, uint32_t dest, uint8_t *bsg_idx)
{
uint32_t j_i, pre_id, adjecent;
src ^= 1;
get_shortest_path(src, pq, unitig_g, pre);
for (j_i = 0; j_i < pq->dis.n; j_i++)
{
if(pq->dis.a[j_i] == (uint64_t)-1) continue;
///if(IF_HOM(j_i>>1, *bub)) continue;
if((j_i>>1) == (src>>1)) continue;
if((dest != (uint32_t)-1) && ((j_i>>1) == (dest>>1))) continue;
pre_id = pre[j_i];
adjecent = 0;
while (pre_id != src)
{
if(((dest != (uint32_t)-1) && ((pre_id>>1) == (dest>>1)))
|| ((pre_id>>1) == (src>>1)))
{
adjecent = 1;
break;
}
pre_id = pre[pre_id];
}
if(adjecent == 0)
{
if(broken->a.n == 0 || (broken->a.n > 0 && (j_i>>1) != (broken->a.a[broken->a.n - 1]>>1)))
{
if(bsg_idx && bsg_idx[(j_i>>1)])
{
broken->a.n = 0;
return;
}
kv_push(uint32_t, broken->a, j_i);
}
}
}
}
uint64_t calculate_chain_weight(ma_utg_t *u, bubble_type* bub, ma_ug_t *unitig_ug, chain_w_type* x)
{
x->b_occ = x->g_occ = 0;
uint32_t i, j, *a, n;
uint64_t occ, occ_n, thres;
for (i = occ = occ_n = 0; i < u->n; i++)
{
if(bub->b_g->seq[u->a[i]>>33].c != HAP_LABLE)
{
get_bubbles(bub, u->a[i]>>33, NULL, NULL, &a, &n, NULL);
for (j = 0; j < n; j++)
{
occ += unitig_ug->u.a[a[j]>>1].n;
}
occ_n++;
}
}
thres = (uint64_t)-1;
if(occ_n > 0) thres = (occ*6)/occ_n;
for (i = 0; i < u->n; i++)
{
occ = 0;
get_bubbles(bub, u->a[i]>>33, NULL, NULL, &a, &n, NULL);
for (j = 0; j < n; j++)
{
occ += unitig_ug->u.a[a[j]>>1].n;
}
if(bub->b_g->seq[u->a[i]>>33].c != HAP_LABLE || occ < thres)
{
x->g_occ += occ;
}
else
{
x->b_occ += occ;
}
}
return thres;
}
int cmp_chain_weight(const void * a, const void * b)
{
if((*(chain_w_type*)a).del != (*(chain_w_type*)b).del)
{
return (*(chain_w_type*)a).del > (*(chain_w_type*)b).del? 1 : -1;
}
else
{
long long a_occ = (*(chain_w_type*)a).g_occ - (*(chain_w_type*)a).b_occ;
long long b_occ = (*(chain_w_type*)b).g_occ - (*(chain_w_type*)b).b_occ;
if(a_occ != b_occ)
{
return a_occ > b_occ? -1 : 1;
}
else
{
return 0;
}
}
}
void resolve_bubble_chain_tangle_back(ma_ug_t* ug, bubble_type* bub, hc_links* link)
{
ma_ug_t *copy_ug = copy_untig_graph(bub->b_ug);
asg_arc_t *av = NULL;
uint32_t i, j, k, v, w, w1, w2, nw1, nw2, nv, occ_e_1, occ_e_2, occ_c;
ma_ug_t *bub_ug = copy_ug;
///ma_utg_t *u = NULL;
buf_t b; memset(&b, 0, sizeof(buf_t));
kvec_t_u32_warp stack, result;
kv_init(stack.a); kv_init(result.a);
uint8_t *vis = NULL; CALLOC(vis, ug->g->n_seq<<1);
uint8_t *is_vis = NULL; CALLOC(is_vis, ug->g->n_seq<<1);
kvec_t(uint64_t) occ_idx; kv_init(occ_idx); uint64_t tmp, *p = NULL;
for (k = occ_idx.n = 0; k < bub_ug->g->n_seq; k++)
{
v = (k<<1);
av = asg_arc_a(bub_ug->g, v);
nv = asg_arc_n(bub_ug->g, v);
for (i = 0, w = (uint32_t)-1, nw1 = 0; i < nv; i++)
{
if(av[i].del) continue;
nw1++;
if((av[i].v>>1) == (v>>1)) continue;
if(w != (uint32_t)-1) break;
w = av[i].v;
}
if(i < nv) continue;
w1 = w;
v = (k<<1)+1;
av = asg_arc_a(bub_ug->g, v);
nv = asg_arc_n(bub_ug->g, v);
for (i = 0, w = (uint32_t)-1, nw2 = 0; i < nv; i++)
{
if(av[i].del) continue;
nw2++;
if((av[i].v>>1) == (v>>1)) continue;
if(w != (uint32_t)-1) break;
w = av[i].v;
}
if(i < nv) continue;
w2 = w;
if(nw1 <= 1 && nw2 <= 1) continue;
if(w1 == (uint32_t)-1 && w2 == (uint32_t)-1) continue;
if(w1 != (uint32_t)-1) w1 ^=1;
if(w2 != (uint32_t)-1) w2 ^=1;
if(w1 != (uint32_t)-1)
{
w = (uint32_t)-1;
if(w2 != (uint32_t)-1) w = w2^1;
av = asg_arc_a(bub_ug->g, w1);
nv = asg_arc_n(bub_ug->g, w1);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
if((av[i].v>>1) == k) continue;
if(av[i].v == w) continue;
break;
}
if(i < nv) continue;
}
if(w2 != (uint32_t)-1)
{
w = (uint32_t)-1;
if(w1 != (uint32_t)-1) w = w1^1;
av = asg_arc_a(bub_ug->g, w2);
nv = asg_arc_n(bub_ug->g, w2);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
if((av[i].v>>1) == k) continue;
if(av[i].v == w) continue;
break;
}
if(i < nv) continue;
}
if(w1 == (uint32_t)-1 && w2 != (uint32_t)-1) w1 = w2;
if(w1 == w2) w2 = (uint32_t)-1;
occ_c = occ_e_1 = occ_e_2 = (uint32_t)-1;
set_b_utg_weight_flag(bub, &b, k<<1, NULL, 0, &occ_c);
if(w1 != (uint32_t)-1) set_b_utg_weight_flag(bub, &b, w1^1, NULL, 0, &occ_e_1);
if(w2 != (uint32_t)-1) set_b_utg_weight_flag(bub, &b, w2^1, NULL, 0, &occ_e_2);
fprintf(stderr, "\n>>>>>>k=btg%.6ul (n=%u), w1=btg%.6ul (n=%u), w2=utg%.6ul (n=%u)\n", k+1, occ_c,
(w1>>1)+1, occ_e_1, (w2>>1)+1, occ_e_2);
if(occ_c*5 >= occ_e_1) continue;
if(occ_c*5 >= occ_e_2) continue;
if(occ_c*10 >= (occ_e_1 + occ_e_2)) continue;
kv_pushp(uint64_t, occ_idx, &p);
(*p) = occ_e_1 + occ_e_2 - occ_c;
(*p) <<= 32; (*p) += k;
fprintf(stderr, "passed\n");
}
radix_sort_hc64(occ_idx.a, occ_idx.a + occ_idx.n);
for (k = 0; k < occ_idx.n; ++k)
{
tmp = occ_idx.a[k];
occ_idx.a[k] = occ_idx.a[occ_idx.n - k - 1];
occ_idx.a[occ_idx.n - k - 1] = tmp;
}
for (j = 0; j < occ_idx.n; j++)
{
k = (uint32_t)occ_idx.a[j];
v = (k<<1);
av = asg_arc_a(bub_ug->g, v);
nv = asg_arc_n(bub_ug->g, v);
for (i = 0, w = (uint32_t)-1, nw1 = 0; i < nv; i++)
{
if(av[i].del) continue;
nw1++;
if((av[i].v>>1) == (v>>1)) continue;
if(w != (uint32_t)-1) break;
w = av[i].v;
}
if(i < nv) continue;
w1 = w;
v = (k<<1)+1;
av = asg_arc_a(bub_ug->g, v);
nv = asg_arc_n(bub_ug->g, v);
for (i = 0, w = (uint32_t)-1, nw2 = 0; i < nv; i++)
{
if(av[i].del) continue;
nw2++;
if((av[i].v>>1) == (v>>1)) continue;
if(w != (uint32_t)-1) break;
w = av[i].v;
}
if(i < nv) continue;
w2 = w;
if(nw1 <= 1 && nw2 <= 1) continue;
if(w1 == (uint32_t)-1 && w2 == (uint32_t)-1) continue;
if(w1 != (uint32_t)-1) w1 ^=1;
if(w2 != (uint32_t)-1) w2 ^=1;
}
free(vis); free(is_vis); free(b.b.a); kv_destroy(occ_idx); kv_destroy(stack.a); kv_destroy(result.a);
ma_ug_destroy(copy_ug);
}
uint32_t get_btg_occ(bubble_type* bub, uint32_t v)
{
ma_ug_t *bub_ug = bub->b_ug;
ma_utg_t *u = NULL;
uint32_t k_i, k_j, *a = NULL, n, tan_occ = 0;
u = &(bub_ug->u.a[v]);
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
tan_occ += bub->ug->u.a[a[k_j]>>1].n;
}
}
return tan_occ;
}
int check_bubble_tangle(bubble_type* bub, ma_ug_t* ug, uint32_t beg, uint32_t sink,
double side_rate, double total_rate, uint32_t beg_occ, uint32_t sink_occ,
uint8_t* is_vis, kvec_t_u32_warp* stack, kvec_t_u32_warp* res, uint8_t* chain_flag,
uint32_t* extra_check)
{
if(extra_check) (*extra_check) = 1;
uint32_t cur, tan_occ = 0, ncur, i, no_first = 0;
asg_arc_t *acur = NULL;
memset(is_vis, 0, ug->g->n_seq<<1);
stack->a.n = 0;
kv_push(uint32_t, stack->a, beg);
if(res) res->a.n = 0;
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(no_first && cur == beg) return 0;
if(sink != (uint32_t)-1 && cur == sink) return 0;
if(is_vis[cur] == 0 && is_vis[cur^1] == 0)
{
if((cur>>1) != (beg>>1) && (sink == (uint32_t)-1 || (cur>>1) != (sink>>1)))
{
if(res) kv_push(uint32_t, res->a, cur);
if(chain_flag && chain_flag[cur>>1] != 0 && extra_check)
{
(*extra_check) = 0;
}
if(bub)
{
tan_occ += get_btg_occ(bub, cur>>1);
if(tan_occ*side_rate >= beg_occ) return 0;
if(sink != (uint32_t)-1 && (tan_occ*side_rate >= sink_occ)) return 0;
if(tan_occ*total_rate >= (beg_occ + ((sink != (uint32_t)-1)?sink_occ : 0))) return 0;
}
}
}
if(is_vis[cur] == 0 && cur != (beg^1) && (sink == (uint32_t)-1 || cur != (sink^1)))
{
is_vis[cur] = 1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(acur[i].v == beg) return 0;
if(sink != (uint32_t)-1 && acur[i].v == sink) return 0;
if(is_vis[acur[i].v]) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
is_vis[cur] = 1;
cur^=1;
if(is_vis[cur] == 0 && cur != (beg^1) && (sink == (uint32_t)-1 || cur != (sink^1)))
{
is_vis[cur] = 1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(acur[i].v == beg) return 0;
if(sink != (uint32_t)-1 && acur[i].v == sink) return 0;
if(is_vis[acur[i].v]) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
is_vis[cur] = 1;
no_first = 1;
}
if(bub)
{
if(tan_occ*side_rate >= beg_occ) return 0;
if(sink != (uint32_t)-1 && (tan_occ*side_rate >= sink_occ)) return 0;
if(tan_occ*total_rate >= (beg_occ + ((sink != (uint32_t)-1)?sink_occ : 0))) return 0;
}
return 1;
}
int find_bubble_tangle(bubble_type* bub, ma_ug_t* ug, uint8_t* is_vis, uint8_t* is_vis2,
uint32_t v, double side_rate, double total_rate, kvec_t_u32_warp* stack,
kvec_t_u32_warp* stack2, kvec_t_u32_warp* res_btg, kvec_t_u32_warp* res_utg, uint8_t* chain_flag,
uint32_t* r_b_utg_beg, uint32_t* r_b_utg_sink, uint32_t* r_b_tg_beg, uint32_t* r_b_tg_sink,
uint32_t* r_utg_beg, uint32_t* r_utg_sink)
{
(*r_b_utg_beg) = (*r_b_utg_sink) = (*r_b_tg_beg) = (*r_b_tg_sink) = (*r_utg_beg) = (*r_utg_sink) = (uint32_t)-1;
ma_ug_t *bub_ug = bub->b_ug;
ma_utg_t *u = NULL;
uint32_t tan_occ = 0, cur, ncur, i, k, no_root = 0, v_occ, c_occ, utg_occ, w, btg_beg, btg_sink, utg_beg, utg_sink, is_t, extra_check;
stack->a.n = 0;
asg_arc_t *acur = NULL;
memset(is_vis, 0, bub_ug->g->n_seq<<1);
stack->a.n = 0;
kv_push(uint32_t, stack->a, v);
v_occ = get_btg_occ(bub, v>>1);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(is_vis[cur]) continue;
c_occ = 0;
if(no_root && cur == v) return 0;
if(no_root && is_vis[cur] == 0 && is_vis[cur^1] == 0)
{
c_occ = get_btg_occ(bub, cur>>1);
///assume v_occ is the beg node, c_occ is the end node, which means tan_occ cannot be too large
if((tan_occ*side_rate) < c_occ && (tan_occ*total_rate) < (c_occ + v_occ))
{
if(check_bubble_tangle(bub, bub->b_ug, v, cur^1, side_rate, total_rate, v_occ, c_occ,
is_vis2, stack2, NULL, NULL, NULL))
{
check_bubble_tangle(bub, bub->b_ug, v, cur^1, side_rate, total_rate, v_occ, c_occ,
is_vis2, stack2, res_btg, NULL, NULL);
for (k = 0; k < res_btg->a.n; k++)
{
set_b_utg_weight_flag(bub, NULL, res_btg->a.a[k], chain_flag, 0, NULL);
}
btg_beg = v; btg_sink = cur^1;///b_utg id
u = &(bub_ug->u.a[btg_beg>>1]);
if((btg_beg&1)==1)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&w:NULL,
(((u->a[0]>>32)&1)^1) == 0?&w:NULL, NULL, NULL, NULL);
(*r_b_tg_beg) = u->a[0]>>32;
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&w:NULL,
((u->a[u->n-1]>>32)&1) == 0?&w:NULL, NULL, NULL, NULL);
(*r_b_tg_beg) = u->a[u->n-1]>>32;
}
utg_beg = w^1; ///ug id
u = &(bub_ug->u.a[btg_sink>>1]);
if((btg_sink&1)==1)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&w:NULL,
(((u->a[0]>>32)&1)^1) == 0?&w:NULL, NULL, NULL, NULL);
(*r_b_tg_sink) = u->a[0]>>32;
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&w:NULL,
((u->a[u->n-1]>>32)&1) == 0?&w:NULL, NULL, NULL, NULL);
(*r_b_tg_sink) = u->a[u->n-1]>>32;
}
utg_sink = w^1; ///ug id
is_t = check_bubble_tangle(NULL, ug, utg_beg, utg_sink, side_rate, total_rate,
(uint32_t)-1, (uint32_t)-1, is_vis2, stack2, res_utg, chain_flag, &extra_check);
if(is_t == 1 && extra_check == 0)
{
for (k = utg_occ = 0; k < res_utg->a.n; k++)
{
if(IF_HOM((res_utg->a.a[k]>>1), *bub)) continue;
utg_occ += ug->u.a[res_utg->a.a[k]>>1].n;
}
if(utg_occ*total_rate >= (v_occ+c_occ)) is_t = 0;
}
for (k = 0; k < res_btg->a.n; k++)
{
set_b_utg_weight_flag(bub, NULL, res_btg->a.a[k], chain_flag, 1, NULL);
}
if(is_t)
{
(*r_b_utg_beg) = btg_beg;
(*r_b_utg_sink) = btg_sink;
(*r_utg_beg) = utg_beg;
(*r_utg_sink) = utg_sink;
return is_t;
}
}
}
}
is_vis[cur] = 1;
if(cur != (v^1))
{
ncur = asg_arc_n(bub_ug->g, cur);
acur = asg_arc_a(bub_ug->g, cur);
for (i = 0; i < ncur; i++)
{
if(acur[i].del) continue;
if(acur[i].v == v) return 0;
if(is_vis[acur[i].v]) continue;
kv_push(uint32_t, stack->a, acur[i].v);
}
}
if(no_root) tan_occ += c_occ;
if((tan_occ*side_rate) >= v_occ) return 0;
no_root = 1;
}
if(tan_occ*side_rate >= v_occ) return 0;
if(tan_occ*total_rate >= v_occ) return 0;
//let one end as a tangle
if(check_bubble_tangle(bub, bub->b_ug, v, (uint32_t)-1, side_rate, total_rate, v_occ, (uint32_t)-1,
is_vis2, stack2, res_btg, NULL, NULL) == 0)
{
return 0;
}
for (k = 0; k < res_btg->a.n; k++)
{
set_b_utg_weight_flag(bub, NULL, res_btg->a.a[k], chain_flag, 0, NULL);
}
btg_beg = v;
u = &(bub_ug->u.a[btg_beg>>1]);
if((btg_beg&1)==1)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&w:NULL,
(((u->a[0]>>32)&1)^1) == 0?&w:NULL, NULL, NULL, NULL);
(*r_b_tg_beg) = u->a[0]>>32;
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&w:NULL,
((u->a[u->n-1]>>32)&1) == 0?&w:NULL, NULL, NULL, NULL);
(*r_b_tg_beg) = u->a[u->n-1]>>32;
}
utg_beg = w^1;
is_t = check_bubble_tangle(NULL, ug, utg_beg, (uint32_t)-1, side_rate, total_rate,
(uint32_t)-1, (uint32_t)-1, is_vis2, stack2, res_utg, chain_flag, &extra_check);
if(is_t == 1 && extra_check == 0)
{
for (k = utg_occ = 0; k < res_utg->a.n; k++)
{
if(IF_HOM((res_utg->a.a[k]>>1), *bub)) continue;
utg_occ += ug->u.a[res_utg->a.a[k]>>1].n;
}
if(utg_occ*total_rate >= v_occ) is_t = 0;
}
for (k = 0; k < res_btg->a.n; k++)
{
set_b_utg_weight_flag(bub, NULL, res_btg->a.a[k], chain_flag, 1, NULL);
}
if(is_t)
{
(*r_b_utg_beg) = btg_beg;
(*r_utg_beg) = utg_beg;
}
return is_t;
}
uint32_t get_utg_end_from_btg(bubble_type* bub, ma_ug_t *bub_ug, uint32_t v)
{
ma_utg_t *u = &(bub_ug->u.a[v>>1]);
if((v&1)==1)
{
return (u->a[0]>>32)^1;
}
else
{
return u->a[u->n-1]>>32;
}
}
void drop_g_edges_by_utg(bubble_type* bub, asg_t *bsg, ma_ug_t *bub_ug, kvec_t_u32_warp* res_btg,
uint32_t b_utg_beg, uint32_t b_utg_sink)
{
uint32_t i, k, v, root, nv;
asg_arc_t *av = NULL;
if(b_utg_beg != (uint32_t)-1)
{
root = b_utg_beg;
v = get_utg_end_from_btg(bub, bub_ug, root);
nv = asg_arc_n(bsg, v);
av = asg_arc_a(bsg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
av[i].del = 1;
asg_arc_del(bsg, (av[i].v)^1, (av[i].ul>>32)^1, 1);
}
}
if(b_utg_sink != (uint32_t)-1)
{
root = b_utg_sink;
v = get_utg_end_from_btg(bub, bub_ug, root);
nv = asg_arc_n(bsg, v);
av = asg_arc_a(bsg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
av[i].del = 1;
asg_arc_del(bsg, (av[i].v)^1, (av[i].ul>>32)^1, 1);
}
}
if(res_btg == NULL) return;
for (k = 0; k < res_btg->a.n; k++)
{
root = res_btg->a.a[k];
v = get_utg_end_from_btg(bub, bub_ug, root);
nv = asg_arc_n(bsg, v);
av = asg_arc_a(bsg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
av[i].del = 1;
asg_arc_del(bsg, (av[i].v)^1, (av[i].ul>>32)^1, 1);
}
root = res_btg->a.a[k]^1;
v = get_utg_end_from_btg(bub, bub_ug, root);
nv = asg_arc_n(bsg, v);
av = asg_arc_a(bsg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
av[i].del = 1;
asg_arc_del(bsg, (av[i].v)^1, (av[i].ul>>32)^1, 1);
}
}
}
void debug_tangle_bubble(bubble_type* bub, long long beg_idx, long long end_idx, const char* command)
{
// long long beg_idx = (long long)bub->b_g->n_seq - bub->tangle_bub;
// long long end_idx = (long long)bub->b_g->n_seq - 1;
long long i, j, k;
ma_utg_t *u = NULL;
uint32_t beg_utg, sink_utg, *a = NULL, n, btg_left, ori_left, btg_right, ori_right, root_0, root_1;
for (i = beg_idx; i <= end_idx; i++)
{
get_bubbles(bub, i, &beg_utg, &sink_utg, &a, &n, NULL);
fprintf(stderr, "\n(%lld) %s: beg=utg%.6ul, sink=utg%.6ul, n: %u\n", i, command, (beg_utg>>1)+1, (sink_utg>>1)+1, n);
for (k = 0; k < n; k++)
{
fprintf(stderr, "mid=utg%.6ul\n", (a[k]>>1)+1);
}
for (j = 0; j < bub->b_ug->g->n_seq; j++)
{
u = &(bub->b_ug->u.a[j]);
if(u->n) continue;
for (k = 0; k < u->n; k++)
{
if((long long)(u->a[k]>>33) != i) continue;
fprintf(stderr, "is the %lld-th bubble at btg%.6lldl\n", k, j+1);
if(k > 0)
{
btg_left = u->a[k-1]>>33;
ori_left = u->a[k-1]>>32&1;
get_bubbles(bub, btg_left, ori_left == 1?&root_0:NULL, ori_left == 0?&root_0:NULL, NULL, NULL, NULL);
fprintf(stderr, "left-utg%.6ul\n", (ori_left>>1)+1);
}
if(k + 1 < u->n)
{
btg_right = u->a[k+1]>>33;
ori_right = (u->a[k+1]>>32&1)^1;
get_bubbles(bub, btg_right, ori_right == 1?&root_1:NULL, ori_right == 0?&root_1:NULL, NULL, NULL, NULL);
fprintf(stderr, "right-utg%.6ul\n", (ori_right>>1)+1);
}
}
}
}
}
uint32_t print_b_utg_occ(bubble_type* bub, uint32_t v)
{
ma_ug_t *bub_ug = bub->b_ug;
ma_utg_t *u = NULL;
uint32_t k_i, k_j, *a = NULL, n, tan_occ = 0, beg, sink;
u = &(bub_ug->u.a[v]);
fprintf(stderr, "\nstart: %u-th bubble-utg-start (# bubbles: %u)\n", v, (uint32_t)u->n);
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, &beg, &sink, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
tan_occ += bub->ug->u.a[a[k_j]>>1].n;
}
fprintf(stderr, "bid: %lu, n: %u, beg-utg%.6dl(%u), sink-utg%.6dl(%u)\n", u->a[k_i]>>33, n, (beg>>1)+1, beg&1, (sink>>1)+1, sink&1);
}
fprintf(stderr, "end: %u-th bubble-utg-end\n\n", v);
return tan_occ;
}
void update_bsg(asg_t *bsg, kvec_asg_arc_t_warp* edges)
{
asg_arc_t *t = NULL;
uint32_t k, l, i, convex, max_i;
long long max, nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
for (k = 0; k < edges->a.n; k++)
{
t = asg_arc_pushp(bsg);
*t = edges->a.a[k];
}
bsg->is_srt = 0; free(bsg->idx); bsg->idx = 0;
asg_cleanup(bsg);
radix_sort_asg_e(edges->a.a, edges->a.a + edges->a.n);
for (k = 1, l = 0; k <= edges->a.n; ++k)
{
if (k == edges->a.n || (edges->a.a[k].ul>>32) != (edges->a.a[l].ul>>32))
{
if(k - l > 1)
{
for (i = l, max = -1, max_i = (uint32_t)-1; i < k; i++)
{
get_unitig(bsg, NULL, edges->a.a[i].v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen,
&max_stop_baseLen, 1, NULL);
if(max < nodeLen) max = nodeLen, max_i = i;
}
///fprintf(stderr, "k - l: %u, max_i: %u\n", k - l, max_i);
for (i = l; i < k; i++)
{
// fprintf(stderr, "i: %u, +t->ul>>32: %lu, t->v: %u\n",
// i, edges->a.a[i].ul>>32, edges->a.a[i].v);
if(i == max_i) continue;
asg_arc_del(bsg, (edges->a.a[i].ul>>32), (edges->a.a[i].v), 1);
asg_arc_del(bsg, (edges->a.a[i].v)^1, (edges->a.a[i].ul>>32)^1, 1);
///edges->a.a[i].del = 1;
}
}
l = k;
}
}
asg_cleanup(bsg);
}
void resolve_bubble_chain_tangle(ma_ug_t* ug, bubble_type* bub)
{
// double index_time = yak_realtime();
ma_ug_t *bub_ug = bub->b_ug;
asg_t *bsg = bub->b_g;
uint32_t k, i, v, n_vx, new_bub;
n_vx = MAX((MAX(ug->g->n_seq<<1, bub->b_ug->g->n_seq<<1)), bub->b_g->n_seq<<1);
buf_t b; memset(&b, 0, sizeof(buf_t));
kvec_t_u32_warp stack, stack2, res_btg, res_utg;
kv_init(stack.a); kv_init(stack2.a); kv_init(res_btg.a); kv_init(res_utg.a);
kvec_asg_arc_t_warp edges; kv_init(edges.a);
uint8_t *is_vis = NULL; CALLOC(is_vis, n_vx);
uint8_t *is_vis2 = NULL; CALLOC(is_vis2, n_vx);
uint8_t *is_used = NULL; CALLOC(is_used, n_vx);
uint8_t *chain_flag = NULL; CALLOC(chain_flag, n_vx);
kvec_t(uint64_t) occ_idx; kv_init(occ_idx); uint64_t tmp, *p = NULL;
double side_rate = 2.5, total_rate = 8;
uint32_t b_utg_beg, b_utg_sink, b_tg_beg, b_tg_sink, utg_beg, utg_sink;
while(1)
{
occ_idx.n = 0; edges.a.n = 0;
if(n_vx < (uint32_t)(MAX((MAX(ug->g->n_seq<<1, bub->b_ug->g->n_seq<<1)), bub->b_g->n_seq<<1)))
{
n_vx = MAX((MAX(ug->g->n_seq<<1, bub->b_ug->g->n_seq<<1)), bub->b_g->n_seq<<1);
is_vis = (uint8_t*)realloc(is_vis, n_vx);
is_vis2 = (uint8_t*)realloc(is_vis2, n_vx);
is_used = (uint8_t*)realloc(is_used, n_vx);
chain_flag = (uint8_t*)realloc(chain_flag, n_vx);
}
memset(is_vis, 0, n_vx);
memset(is_vis2, 0, n_vx);
memset(is_used, 0, n_vx);
memset(chain_flag, 0, n_vx);
if(bub->num.n > 0) bub->num.n--;
new_bub = bub->b_g->n_seq;
//label all unitigs in bubble chain
for (k = 0; k < bub_ug->g->n_seq; k++)
{
kv_pushp(uint64_t, occ_idx, &p);
(*p) = get_btg_occ(bub, k);
(*p) <<= 32; (*p) += k;
set_b_utg_weight_flag(bub, NULL, k<<1, chain_flag, 1, NULL);
}
radix_sort_hc64(occ_idx.a, occ_idx.a + occ_idx.n);
for (k = 0; k < occ_idx.n>>1; ++k)
{
tmp = occ_idx.a[k];
occ_idx.a[k] = occ_idx.a[occ_idx.n - k - 1];
occ_idx.a[occ_idx.n - k - 1] = tmp;
}
for (k = 0; k < bub_ug->g->n_seq; k++)
{
v = ((uint32_t)(occ_idx.a[k]))<<1;
if(is_used[v] == 0 && asg_arc_n(bub_ug->g, v) > 0)
{
if(find_bubble_tangle(bub, ug, is_vis, is_vis2, v, side_rate, total_rate, &stack, &stack2,
&res_btg, &res_utg, chain_flag, &b_utg_beg, &b_utg_sink, &b_tg_beg, &b_tg_sink,
&utg_beg, &utg_sink))
{
if(utg_beg != (uint32_t)-1 && (!IF_HOM(utg_beg>>1, *bub)))
{
kv_push(uint32_t, res_utg.a, utg_beg);
}
if(utg_sink != (uint32_t)-1 && (!IF_HOM(utg_sink>>1, *bub)))
{
kv_push(uint32_t, res_utg.a, utg_sink);
}
for (i = 0; i < res_btg.a.n; i++)
{
is_used[res_btg.a.a[i]] = 1;
is_used[res_btg.a.a[i]^1] = 1;
}
if(b_utg_beg != (uint32_t)-1) is_used[b_utg_beg] = 1;
if(b_utg_sink != (uint32_t)-1) is_used[b_utg_sink] = 1;
if(b_tg_beg != (uint32_t)-1) b_tg_beg>>=1;
if(b_tg_sink != (uint32_t)-1) b_tg_sink>>=1;
update_bubble_graph(&res_utg, utg_beg, b_tg_beg, utg_sink, b_tg_sink,
bub, &edges, bsg, NULL, NULL, ug, NULL, 0);
drop_g_edges_by_utg(bub, bsg, bub_ug, &res_btg, b_utg_beg, b_utg_sink);
}
}
v ^= 1;
if(is_used[v] == 0 && asg_arc_n(bub_ug->g, v) > 0)
{
if(find_bubble_tangle(bub, ug, is_vis, is_vis2, v, side_rate, total_rate, &stack, &stack2,
&res_btg, &res_utg, chain_flag, &b_utg_beg, &b_utg_sink, &b_tg_beg, &b_tg_sink,
&utg_beg, &utg_sink))
{
if(utg_beg != (uint32_t)-1 && (!IF_HOM(utg_beg>>1, *bub)))
{
kv_push(uint32_t, res_utg.a, utg_beg);
}
if(utg_sink != (uint32_t)-1 && (!IF_HOM(utg_sink>>1, *bub)))
{
kv_push(uint32_t, res_utg.a, utg_sink);
}
for (i = 0; i < res_btg.a.n; i++)
{
is_used[res_btg.a.a[i]] = 1;
is_used[res_btg.a.a[i]^1] = 1;
}
if(b_utg_beg != (uint32_t)-1) is_used[b_utg_beg] = 1;
if(b_utg_sink != (uint32_t)-1) is_used[b_utg_sink] = 1;
if(b_tg_beg != (uint32_t)-1) b_tg_beg>>=1;
if(b_tg_sink != (uint32_t)-1) b_tg_sink>>=1;
/*******************************for debug************************************/
// if(utg_beg == (utg_sink^1))
// {
// print_b_utg_occ(bub, b_utg_beg>>1);
// print_b_utg_occ(bub, b_utg_sink>>1);
// print_b_utg_occ(bub, 42);
// ///print_debug_bubble_graph(bub, ug, asm_opt.output_file_name);
// }
/*******************************for debug************************************/
update_bubble_graph(&res_utg, utg_beg, b_tg_beg, utg_sink, b_tg_sink, bub, &edges, bsg, NULL, NULL, ug, NULL, 0);
drop_g_edges_by_utg(bub, bsg, bub_ug, &res_btg, b_utg_beg, b_utg_sink);
///fprintf(stderr, "->>>>>>beg=btg%.6ul, sink=btg%.6ul\n", (b_utg_beg>>1)+1, (b_utg_sink>>1)+1);
}
}
}
kv_push(uint32_t, bub->num, bub->list.n);
new_bub = bub->b_g->n_seq - new_bub;
bub->tangle_bub += new_bub;
///actually not useful, and may have bug when one bubble at multipe chains
if(new_bub) update_bub_b_s_idx(bub);
update_bsg(bsg, &edges);
ma_ug_destroy(bub_ug);
bub_ug = ma_ug_gen(bub->b_g);
bub->b_ug = bub_ug;
///fprintf(stderr, "new_bub: %u, bub->tangle_bub: %lu\n", new_bub, bub->tangle_bub);
if(new_bub == 0) break;
}
kv_destroy(bub->chain_weight);
ma_utg_t *u = NULL;
bub_ug = bub->b_ug;
kv_malloc(bub->chain_weight, bub_ug->u.n); bub->chain_weight.n = bub_ug->u.n;
for (i = 0; i < bub_ug->u.n; i++)
{
u = &(bub_ug->u.a[i]);
bub->chain_weight.a[i].id = i;
// if(u->n <= 1) ///not a chain
// {
// bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
// bub->chain_weight.a[i].del = 1;
// }
// else
{
bub->chain_weight.a[i].del = 0;
calculate_chain_weight(u, bub, ug, &(bub->chain_weight.a[i]));
}
}
qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);
///debug_tangle_bubble(bub);
free(is_vis); free(is_vis2); free(is_used); free(chain_flag); free(b.b.a);
kv_destroy(occ_idx); kv_destroy(stack.a); kv_destroy(stack2.a);
kv_destroy(res_btg.a); kv_destroy(res_utg.a); kv_destroy(edges.a);
///print_debug_bubble_graph(bub, ug, asm_opt.output_file_name);
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
void update_bubble_chain(ma_ug_t* ug, bubble_type* bub, uint32_t is_middle, uint32_t is_end)
{
// double index_time = yak_realtime();
if(bub->b_ug) ma_ug_destroy(bub->b_ug);
if(bub->chain_weight.a) kv_destroy(bub->chain_weight);
kvec_t_u32_warp broken;
kv_init(broken.a);
kvec_asg_arc_t_warp edges;
kv_init(edges.a);
ma_utg_t *u = NULL;
asg_arc_t *t = NULL;
asg_t *sg = ug->g;
pdq pq;
init_pdq(&pq, sg->n_seq<<1);
asg_t *bsg = bub->b_g;
ma_ug_t *bub_ug = NULL;
bub_ug = ma_ug_gen(bub->b_g);
uint32_t i, j, k_i, rId_0, ori_0, root_0, rId_1, ori_1, root_1, n_vtx = sg->n_seq<<1, new_bub;
uint32_t *pre = NULL; MALLOC(pre, n_vtx);
uint8_t* vis_flag = NULL; MALLOC(vis_flag, ug->g->n_seq*2);
kvec_t_u32_warp stack; kv_init(stack.a);
///chain_w_type x;
///uint64_t end_thres;
uint8_t *bsg_idx = NULL; CALLOC(bsg_idx, n_vtx>>1);
for (i = 0; i < bub_ug->u.n; i++)
{
u = &(bub_ug->u.a[i]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
uint32_t *a, n;
get_bubbles(bub, u->a[k_i]>>33, &root_0, &root_1, &a, &n, NULL);
for (j = 0; j < n; j++)
{
bsg_idx[a[j]>>1] = 1;
}
bsg_idx[root_0>>1] = 1;
bsg_idx[root_1>>1] = 1;
}
}
if(bub->num.n > 0) bub->num.n--;
new_bub = bub->b_g->n_seq;
for (i = 0; i < bub_ug->u.n; i++)
{
u = &(bub_ug->u.a[i]);
if(u->n == 0) continue;
///end_thres = calculate_chain_weight(u, bub, ug, &x);
if(is_middle)
{
for (k_i = 0; k_i < u->n; k_i++)
{
if(k_i+1 >= u->n) continue;
///note: must igore .del here, since bsg might be changed
t = &(arc_first(bsg, u->a[k_i]>>32));
if(t->el == 1) continue;
rId_0 = u->a[k_i]>>33;
ori_0 = u->a[k_i]>>32&1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
rId_1 = u->a[k_i+1]>>33;
ori_1 = (u->a[k_i+1]>>32&1)^1;
get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);
broken.a.n = 0;
get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_0, root_1, NULL);
get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_1, root_0, NULL);
///no need to cut the edge, we still have chance to flip by chain
if(double_check_broken_bubble(ug->g, &broken, root_0^1, root_1^1, vis_flag,
ug->g->n_seq*2, &stack, NULL, NULL/**bsg, t**/) == 0)
{
continue;
}
if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, broken.a, root_0);
if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, broken.a, root_1);
if(broken.a.n > 0)
{
update_bubble_graph(&broken, root_0^1, rId_0, root_1^1, rId_1, bub, &edges, bsg, t, bsg_idx, ug, NULL, 1);
}
}
}
if(is_end)
{
if(u->n >0 && arc_cnt(bub_ug->g, (i<<1)+1) == 0)
{
rId_0 = u->a[0]>>33;
ori_0 = (u->a[0]>>32&1)^1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
broken.a.n = 0;
get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_0, (uint32_t)-1, NULL);
if(double_check_broken_bubble(ug->g, &broken, root_0^1, (uint32_t)-1, vis_flag,
ug->g->n_seq*2, &stack, NULL, NULL))
{
if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, broken.a, root_0);
if(broken.a.n > 0)
{
///fprintf(stderr, "root_0: utg%.6ul, broken.a.n: %u\n", (root_0>>1)+1, (uint32_t)broken.a.n);
update_bubble_graph(&broken, root_0^1, rId_0, (uint32_t)-1, (uint32_t)-1, bub, &edges, bsg, NULL, bsg_idx, ug, NULL, 0);
}
}
}
if(u->n >0 && arc_cnt(bub_ug->g, i<<1) == 0)
{
rId_1 = u->a[u->n-1]>>33;
ori_1 = u->a[u->n-1]>>32&1;
get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);
broken.a.n = 0;
get_related_bub_nodes(&broken, bub, &pq, sg, pre, root_1, (uint32_t)-1, bsg_idx);
if(double_check_broken_bubble(ug->g, &broken, root_1^1, (uint32_t)-1, vis_flag,
ug->g->n_seq*2, &stack, NULL, NULL))
{
if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, broken.a, root_1);
if(broken.a.n > 0)
{
///fprintf(stderr, "root_1: utg%.6ul, broken.a.n: %u\n", (root_1>>1)+1, (uint32_t)broken.a.n);
update_bubble_graph(&broken, (uint32_t)-1, (uint32_t)-1, root_1^1, rId_1, bub, &edges, bsg, NULL, bsg_idx, ug, NULL, 0);
}
}
}
}
}
kv_push(uint32_t, bub->num, bub->list.n);
new_bub = bub->b_g->n_seq - new_bub;
if(is_end) bub->b_end_bub += new_bub;
///actually not useful, and may have bug when one bubble at multipe chains
if(new_bub) update_bub_b_s_idx(bub);
for (i = 0; i < edges.a.n; i++)
{
t = asg_arc_pushp(bsg);
*t = edges.a.a[i];
}
bsg->is_srt = 0; free(bsg->idx); bsg->idx = 0;
asg_cleanup(bsg);
ma_ug_destroy(bub_ug);
destory_pdq(&pq);
free(pre);
kv_destroy(broken.a);
kv_destroy(edges.a);
free(bsg_idx);
kv_destroy(stack.a);
free(vis_flag);
bub->b_ug = ma_ug_gen(bub->b_g);
bub_ug = bub->b_ug;
kv_malloc(bub->chain_weight, bub_ug->u.n); bub->chain_weight.n = bub_ug->u.n;
for (i = 0; i < bub_ug->u.n; i++)
{
u = &(bub_ug->u.a[i]);
bub->chain_weight.a[i].id = i;
// if(u->n <= 1) ///not a chain
// {
// bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
// bub->chain_weight.a[i].del = 1;
// }
// else
{
bub->chain_weight.a[i].del = 0;
calculate_chain_weight(u, bub, ug, &(bub->chain_weight.a[i]));
}
}
qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);
/**
uint32_t d_v, d_u, v;
for (i = 0; i < bsg->n_arc; i++)
{
d_v = (uint32_t)(bsg->arc[i].ul>>32);
d_u = bsg->arc[i].v;
for (v = 0; v < bsg->n_arc; v++)
{
if(((bsg->arc[v].ul>>32) == (d_u^1)) && (bsg->arc[v].v == (d_v^1))) break;
}
if(v == bsg->n_arc)
{
fprintf(stderr, "hahaha, el: %u, ul>>33: %lu, ul&1: %lu, v>>1: %u, v&1: %u\n",
bsg->arc[i].el, bsg->arc[i].ul>>33, (bsg->arc[i].ul>>32)&1, bsg->arc[i].v>>1, bsg->arc[i].v&1);
}
// else
// {
// fprintf(stderr, "hehehe, el: %u, ul>>33: %lu, ul&1: %lu, v>>1: %u, v&1: %u\n",
// bsg->arc[i].el, bsg->arc[i].ul>>33, (bsg->arc[i].ul>>32)&1, bsg->arc[i].v>>1, bsg->arc[i].v&1);
// }
}
asg_arc_t *av = NULL, *au = NULL;
uint32_t nv, nu;
for (v = 0; v < (uint32_t)(bsg->n_seq<<1); v++)
{
av = asg_arc_a(bsg, v);
nv = asg_arc_n(bsg, v);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
au = asg_arc_a(bsg, av[i].v^1);
nu = asg_arc_n(bsg, av[i].v^1);
for (k_i = 0; k_i < nu; k_i++)
{
if(au[k_i].del) continue;
if(au[k_i].v == (v^1)) break;
}
if(k_i == nu) fprintf(stderr, "hahaha: v: %u, u: %u\n", v, av[i].v);
}
}
**/
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
void set_b_utg_weight_flag(bubble_type* bub, buf_t* b, uint32_t v, uint8_t* vis_flag, uint32_t flag, uint32_t* occ)
{
ma_ug_t *bub_ug = bub->b_ug;
long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
ma_utg_t *u = NULL;
uint32_t convex, k, k_i, k_j, *a, n, beg, sink;
if(b)
{
b->b.n = 0;
get_unitig(bub_ug->g, NULL, v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen,
&max_stop_baseLen, 1, b);
}
if(occ) (*occ) = 0;
for (k = 0; k < (b?b->b.n:1); k++)
{
u = &(bub_ug->u.a[b?(b->b.a[k]>>1):(v>>1)]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, &beg, &sink, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
if(vis_flag) vis_flag[a[k_j]>>1] = flag;
if(occ) (*occ) += bub->ug->u.a[a[k_j]>>1].n;
}
if(beg != (uint32_t)-1 && vis_flag) vis_flag[beg>>1] = flag;
if(sink != (uint32_t)-1 && vis_flag) vis_flag[sink>>1] = flag;
}
}
}
void set_b_utg_weight_flag_xor(bubble_type* bub, ma_ug_t *bub_ug, buf_t* b, uint32_t v, uint8_t* vis_flag, uint32_t flag, uint32_t* occ)
{
long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
ma_utg_t *u = NULL;
uint32_t convex, k, k_i, k_j, *a, n, beg, sink;
if(b)
{
b->b.n = 0;
get_unitig(bub_ug->g, NULL, v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen,
&max_stop_baseLen, 1, b);
}
if(occ) (*occ) = 0;
for (k = 0; k < (b?b->b.n:1); k++)
{
u = &(bub_ug->u.a[b?(b->b.a[k]>>1):(v>>1)]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, &beg, &sink, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
if(vis_flag) vis_flag[a[k_j]>>1] ^= flag;
if(occ) (*occ) += bub->ug->u.a[a[k_j]>>1].n;
}
if(beg != (uint32_t)-1 && vis_flag) vis_flag[beg>>1] ^= flag;
if(sink != (uint32_t)-1 && vis_flag) vis_flag[sink>>1] ^= flag;
}
}
}
double dfs_weight(uint32_t v, uint8_t* vis_flag, uint8_t* is_vis, hc_links* link,
kvec_t_u32_warp* stack, kvec_t_u32_warp* result, uint32_t e_flag, uint32_t ava_flag,
uint32_t* link_occ)
{
uint32_t cur, i, next = (uint32_t)-1;
stack->a.n = 0;
kv_push(uint32_t, stack->a, v);
double w = 0;
if(link_occ) (*link_occ) = 0;
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(is_vis[cur]) continue;
is_vis[cur] = 1;
if(cur!=v && vis_flag[cur] != ava_flag) continue;
for (i = 0; i < link->a.a[cur].e.n; i++)
{
if(link->a.a[cur].e.a[i].del) continue;
next = link->a.a[cur].e.a[i].uID;
///if(vis_flag[next] == e_flag)
if(vis_flag[next]&e_flag)
{
w += link->a.a[cur].e.a[i].weight;
if(link_occ) (*link_occ) += link->a.a[cur].e.a[i].occ;
continue;
}
if(is_vis[next]) continue;
if(vis_flag[next] != ava_flag) continue;
kv_push(uint32_t, stack->a, next);
}
}
return w;
}
void if_conflict_utg(uint32_t root, uint32_t* aim_0, uint32_t* aim_1, ma_ug_t* ug, uint8_t* vis_flag,
uint8_t* is_vis_2, uint32_t ava_flag, kvec_t_u32_warp* stack)
{
uint32_t n_vx = ug->g->n_seq<<1, k, cur, ncur;
asg_arc_t *acur = NULL;
memset(is_vis_2, 0, n_vx);
stack->a.n = 0;
kv_push(uint32_t, stack->a, root);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(is_vis_2[cur]) continue;
is_vis_2[cur] = 1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k = 0; k < ncur; k++)
{
if(acur[k].del) continue;
if(is_vis_2[acur[k].v]) continue;
if(vis_flag[acur[k].v>>1] != 0 && vis_flag[acur[k].v>>1] != ava_flag)
{
if(aim_0 && (acur[k].v>>1) == (*aim_0)) continue;
if(aim_1 && (acur[k].v>>1) == (*aim_1)) continue;
break;
}
kv_push(uint32_t, stack->a, acur[k].v);
}
if(k < ncur) return;
}
for (k = 0; k < n_vx; k++)
{
if(is_vis_2[k] && vis_flag[k>>1] == 0)
{
///fprintf(stderr, "******************k=utg%.6ul, vis_flag: %u\n", (k>>1)+1, vis_flag[k>>1]);
vis_flag[k>>1] = ava_flag;
}
}
}
double get_chain_weight(bubble_type* bub, ma_ug_t *bub_ug, buf_t* b, uint32_t v, uint32_t convex_source, hc_links* link,
uint8_t* vis_flag, uint8_t* is_vis, ma_ug_t* ug, kvec_t_u32_warp* stack, kvec_t_u32_warp* result,
uint32_t e_flag, uint32_t ava_flag, kvec_t_u32_warp* res_utg, uint32_t* link_occ)
{
long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
ma_utg_t *u = NULL;
uint32_t convex, k, k_i, k_j, *a, n, beg, sink, uID, root, cur, ncur, n_vx = ug->g->n_seq<<1, occ;
asg_arc_t *acur = NULL;
double w = 0;
b->b.n = 0;
get_unitig(bub_ug->g, NULL, v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen,
&max_stop_baseLen, 1, b);
memset(is_vis, 0, n_vx);
for (k = 0; k < b->b.n; k++)
{
u = &(bub_ug->u.a[b->b.a[k]>>1]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, &beg, &sink, &a, &n, NULL);
for(k_j = 0; k_j < n; k_j++) is_vis[a[k_j]] = is_vis[a[k_j]^1] = 1;
if(beg != (uint32_t)-1) is_vis[beg] = is_vis[beg^1] = 1;
if(sink != (uint32_t)-1) is_vis[sink] = is_vis[sink^1] = 1;
}
}
u = &(bub_ug->u.a[v>>1]);
if((v&1)==0)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&root:NULL,
(((u->a[0]>>32)&1)^1) == 0?&root:NULL, NULL, NULL, NULL);
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&root:NULL,
((u->a[u->n-1]>>32)&1) == 0?&root:NULL, NULL, NULL, NULL);
}
root ^= 1;
///fprintf(stderr, "root=utg%.6dl\n", (root>>1)+1);
is_vis[root] = 0;
stack->a.n = 0;
kv_push(uint32_t, stack->a, root);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(is_vis[cur]) continue;
is_vis[cur] = 1;
if(vis_flag[cur>>1] == 0) vis_flag[cur>>1] = ava_flag;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k = 0; k < ncur; k++)
{
if(acur[k].del) continue;
if(is_vis[acur[k].v]) continue;
if(vis_flag[acur[k].v>>1] != 0 && vis_flag[acur[k].v>>1] != ava_flag) continue;
kv_push(uint32_t, stack->a, acur[k].v);
}
}
uint32_t aim_0, aim_1, root_source;
aim_0 = root>>1;
u = &(bub_ug->u.a[convex_source>>1]);
if((convex_source&1)==1)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&root_source:NULL,
(((u->a[0]>>32)&1)^1) == 0?&root_source:NULL, NULL, NULL, NULL);
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&root_source:NULL,
((u->a[u->n-1]>>32)&1) == 0?&root_source:NULL, NULL, NULL, NULL);
}
root_source ^= 1;
aim_1 = root_source>>1;
///fprintf(stderr, "aim_0=utg%.6ul, aim_1=utg%.6ul\n", aim_0+1, aim_1+1);
cur = root_source;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k_i = 0; k_i < ncur; k_i++)
{
if(acur[k_i].del) continue;
if(vis_flag[acur[k_i].v>>1] != 0) continue;
if_conflict_utg(acur[k_i].v, &aim_0, &aim_1, ug, vis_flag, is_vis, ava_flag, stack);
}
for (k = 0; k < ug->g->n_seq; k++)
{
if(vis_flag[k] == ava_flag)
{
cur = k<<1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k_i = 0; k_i < ncur; k_i++)
{
if(acur[k_i].del) continue;
if(vis_flag[acur[k_i].v>>1] != 0) continue;
if_conflict_utg(acur[k_i].v, &aim_0, &aim_1, ug, vis_flag, is_vis, ava_flag, stack);
}
cur = (k<<1)+1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k_i = 0; k_i < ncur; k_i++)
{
if(acur[k_i].del) continue;
if(vis_flag[acur[k_i].v>>1] != 0) continue;
if_conflict_utg(acur[k_i].v, &aim_0, &aim_1, ug, vis_flag, is_vis, ava_flag, stack);
}
}
}
memset(is_vis, 0, n_vx);
if(link_occ) (*link_occ) = 0;
for (k = result->a.n = 0, w = 0; k < b->b.n; k++)
{
u = &(bub_ug->u.a[b->b.a[k]>>1]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
w += dfs_weight(uID, vis_flag, is_vis, link, stack, result, e_flag, ava_flag, &occ);
if(link_occ) (*link_occ) += occ;
}
}
}
for (k = 0; k < ug->g->n_seq; k++)
{
if(vis_flag[k] == ava_flag)
{
vis_flag[k] = 0;
if(res_utg && (!IF_HOM(k, *bub)))
{
kv_push(uint32_t, res_utg->a, k<<1);
}
}
}
return w;
}
int double_check_bub_branch(asg_arc_t *t, ma_ug_t *bs_ug, double *e_w, uint32_t *e_occ, double cutoff, uint32_t max_w_occ)
{
uint32_t v = t->v^1, w = (t->ul>>32)^1, i, nv, rv, max_i, w_i, *a_occ = NULL;
asg_arc_t *av = NULL;
double *aw = NULL, max_w = cutoff - 1, w_w = 1;
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
aw = (&e_w[bs_ug->g->idx[v]>>32]);
a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
if(nv <= 1) return 1;
for (i = rv = 0, max_i = w_i = (uint32_t)-1; i < nv; i++)
{
if(av[i].del) continue;
rv++;
if(av[i].v == w)
{
w_i = i;
w_w = aw[i];
continue;
}
if(max_i == (uint32_t)-1)
{
max_i = i;
max_w = aw[i];
}
else if(max_w < aw[i])
{
max_i = i;
max_w = aw[i];
}
}
if(rv <= 1) return 1; ///must be here
if(max_i == (uint32_t)-1 || w_i == (uint32_t)-1) return 0;
///if(max_w <= max_w_cutoff) return 0; //must be <=
if(a_occ[max_i] <= max_w_occ) return 0; //must be <=
if(w_w*cutoff < max_w) return 1;
return 0;
}
void clean_bubble_chain_by_HiC(ma_ug_t* ug, hc_links* link, bubble_type* bub)
{
double index_time = yak_realtime();
ma_ug_t *bs_ug = bub->b_ug;
uint32_t v, u, i, m, max_i, nv, rv, n_vx, root, flag_pri = 1, flag_aux = 2, flag_ava = 4, occ;
double w, cutoff = 2/**, max_w_cutoff = MAX(MIN(100*OFFSET_RATE_MIN_W, OFFSET_RATE_MAX_W/100), OFFSET_RATE_MIN_W)**/;
uint32_t max_w_occ = 4;
asg_arc_t *av = NULL;
n_vx = bs_ug->g->n_seq << 1;
uint8_t *vis = NULL; CALLOC(vis, ug->g->n_seq<<1);
uint8_t *is_vis = NULL; CALLOC(is_vis, ug->g->n_seq<<1);
uint8_t *is_used = NULL; CALLOC(is_used, n_vx);
uint8_t *dedup = NULL; CALLOC(dedup, ug->g->n_seq<<1);
buf_t b; memset(&b, 0, sizeof(buf_t));
kvec_t_u32_warp stack, result, res_utg;
kv_init(stack.a); kv_init(result.a); kv_init(res_utg.a);
double *e_w = NULL; MALLOC(e_w, bs_ug->g->n_arc);
uint32_t *e_occ = NULL, *a_occ = NULL; CALLOC(e_occ, bs_ug->g->n_arc);
double *aw = NULL, max_w = 0;
kvec_asg_arc_t_warp edges; kv_init(edges.a);
ma_ug_t *back_bs_ug = copy_untig_graph(bs_ug);
for (i = 0; i < bs_ug->g->n_arc; i++)///weight of bs_ug's edges
{
e_w[i] = -1;
}
for (i = 0; i < bs_ug->g->n_seq; i++)///init all chain with flag_aux
{
set_b_utg_weight_flag(bub, &b, i<<1, vis, flag_aux, NULL);
}
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
aw = (&e_w[bs_ug->g->idx[v]>>32]);
a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
if(nv <= 1 || get_real_length(bs_ug->g, v, NULL) <= 1) continue;
set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
///fprintf(stderr, "\n******pri>btg%.6dl\n", (v>>1)+1);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
//fprintf(stderr, "aux>btg%.6dl\n", (av[i].v>>1)+1);
w = get_chain_weight(bub, bs_ug, &b, av[i].v, v, link, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, NULL, &occ);
///fprintf(stderr, "aux>btg%.6dl, w: %f\n", (av[i].v>>1)+1, w);
aw[i] = w;
a_occ[i] = occ;
}
set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
}
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
aw = (&e_w[bs_ug->g->idx[v]>>32]);
a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
if(nv <= 1 || get_real_length(bs_ug->g, v, NULL) <= 1) continue;
for (i = rv = 0, max_i = (uint32_t)-1; i < nv; i++)
{
if(av[i].del) continue;
if(max_i == (uint32_t)-1)
{
max_i = i;
max_w = aw[i];
}
else if(max_w < aw[i])
{
max_i = i;
max_w = aw[i];
}
rv++;
}
if(max_i == (uint32_t)-1) continue;
///if(max_w <= max_w_cutoff) continue; //must be <=
if(a_occ[max_i] <= max_w_occ) continue; //must be <=
if(rv < 2) continue;
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
if(i == max_i) continue;
///if((av[i].v>>1) == (v>>1) && aw[i] <= max_w_cutoff) continue; ///might be not reasonable
if((av[i].v>>1) == (v>>1) && a_occ[i] <= max_w_occ) continue; ///might be not reasonable
if(aw[i]*cutoff < max_w && double_check_bub_branch(&av[i], bs_ug, e_w, e_occ, cutoff, max_w_occ))
{
av[i].del = 1; asg_arc_del(bs_ug->g, (av[i].v)^1, (av[i].ul>>32)^1, 1);
}
}
}
uint32_t rId_0, ori_0, rId_1, ori_1, root_0, root_1, new_bub;
if(bub->num.n > 0) bub->num.n--;
new_bub = bub->b_g->n_seq;
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
rv = get_real_length(bs_ug->g, v, NULL);
if(nv == rv) continue;
if(rv != 1 || nv <= 1) continue;
get_real_length(bs_ug->g, v, &u);
u ^= 1;
if(get_real_length(bs_ug->g, u, NULL) != 1) continue;
drop_g_edges_by_utg(bub, bub->b_g, bs_ug, NULL, v, u);
if(is_used[v] || is_used[u]) continue;
is_used[v] = is_used[u] = 1;
root = get_utg_end_from_btg(bub, bs_ug, v);
rId_0 = root>>1;
ori_0 = root&1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
root = get_utg_end_from_btg(bub, bs_ug, u);
rId_1 = root>>1;
ori_1 = root&1;
get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);
res_utg.a.n = 0;
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, v^1, vis, flag_pri, NULL);
get_chain_weight(bub, back_bs_ug, &b, u^1, v, link, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, v^1, vis, flag_pri, NULL);
for (i = 0; i < res_utg.a.n; i++) dedup[res_utg.a.a[i]>>1] |= 1;
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, u^1, vis, flag_pri, NULL);
get_chain_weight(bub, back_bs_ug, &b, v^1, u, link, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, u^1, vis, flag_pri, NULL);
for (; i < res_utg.a.n; i++) dedup[res_utg.a.a[i]>>1] |= 2;
for (i = m = 0; i < res_utg.a.n; i++)
{
if(dedup[res_utg.a.a[i]>>1] == 3)
{
res_utg.a.a[m] = res_utg.a.a[i];
m++;
}
dedup[res_utg.a.a[i]>>1] = 0;
}
res_utg.a.n = m;
// fprintf(stderr, "res_utg.a.n: %u, m: %u, beg-utg%.6ul, sink-utg%.6ul\n",
// res_utg.a.n, m, (root_0>>1)+1, (root_1>>1)+1);
if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, res_utg.a, root_0);
if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, res_utg.a, root_1);
update_bubble_graph(&res_utg, root_0^1, rId_0, root_1^1, rId_1, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);
///fprintf(stderr, "\n******src-btg%.6ul------>dest-btg%.6ul\n", (v>>1)+1, (u>>1)+1);
}
kv_push(uint32_t, bub->num, bub->list.n);
new_bub = bub->b_g->n_seq - new_bub;
bub->cross_bub += new_bub;
///actually not useful, and may have bug when one bubble at multipe chains
if(new_bub) update_bub_b_s_idx(bub);
///debug_tangle_bubble(bub, bub->b_g->n_seq - bub->cross_bub, bub->b_g->n_seq - 1, "Cross-tangle");
update_bsg(bub->b_g, &edges);
ma_ug_destroy(bs_ug);
bs_ug = ma_ug_gen(bub->b_g);
bub->b_ug = bs_ug;
kv_destroy(bub->chain_weight);
ma_utg_t *u_x = NULL;
bs_ug = bub->b_ug;
kv_malloc(bub->chain_weight, bs_ug->u.n); bub->chain_weight.n = bs_ug->u.n;
for (i = 0; i < bs_ug->u.n; i++)
{
u_x = &(bs_ug->u.a[i]);
bub->chain_weight.a[i].id = i;
// if(u->n <= 1) ///not a chain
// {
// bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
// bub->chain_weight.a[i].del = 1;
// }
// else
{
bub->chain_weight.a[i].del = 0;
calculate_chain_weight(u_x, bub, ug, &(bub->chain_weight.a[i]));
}
}
qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);
free(vis); free(is_vis); free(is_used); free(dedup); free(b.b.a); free(e_w); free(e_occ);
kv_destroy(stack.a); kv_destroy(result.a); kv_destroy(res_utg.a); kv_destroy(edges.a);
ma_ug_destroy(back_bs_ug);
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
void append_boundary_chain(ma_ug_t* ug, hc_links* link, bubble_type* bub)
{
double index_time = yak_realtime();
ma_ug_t *bs_ug = bub->b_ug;
uint32_t v, u, i, k, beg_idx, m, nv, n_vx, flag_pri = 1, flag_aux = 2, flag_ava = 4;
uint32_t root, rId_0, ori_0, root_0, new_bub;
asg_arc_t *av = NULL;
n_vx = bs_ug->g->n_seq << 1;
uint8_t *vis = NULL; CALLOC(vis, ug->g->n_seq<<1);
uint8_t *is_vis = NULL; CALLOC(is_vis, ug->g->n_seq<<1);
uint8_t *is_used = NULL; CALLOC(is_used, n_vx);
uint8_t *dedup = NULL; CALLOC(dedup, ug->g->n_seq<<1);
buf_t b; memset(&b, 0, sizeof(buf_t));
kvec_t_u32_warp stack, result, res_utg;
kv_init(stack.a); kv_init(result.a); kv_init(res_utg.a);
kvec_asg_arc_t_warp edges; kv_init(edges.a);
for (i = 0; i < bs_ug->g->n_seq; i++)
{
set_b_utg_weight_flag(bub, &b, i<<1, vis, flag_aux, NULL);
}
if(bub->num.n > 0) bub->num.n--;
new_bub = bub->b_g->n_seq;
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
if(nv == 0 || get_real_length(bs_ug->g, v, NULL) == 0) continue;
res_utg.a.n = 0;
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
u = av[i].v^1;
/**
beg_idx = res_utg.a.n;
set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
get_chain_weight(bub, bs_ug, &b, u^1, v, link, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
for (k = m = beg_idx; k < res_utg.a.n; k++)
{
if(dedup[res_utg.a.a[k]>>1] != 0) continue;
dedup[res_utg.a.a[k]>>1] = 1;
res_utg.a.a[m] = res_utg.a.a[k];
m++;
}
res_utg.a.n = m;
**/
beg_idx = res_utg.a.n;
set_b_utg_weight_flag_xor(bub, bs_ug, &b, u^1, vis, flag_pri, NULL);
get_chain_weight(bub, bs_ug, &b, v^1, u, link, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, bs_ug, &b, u^1, vis, flag_pri, NULL);
for (k = m = beg_idx; k < res_utg.a.n; k++)
{
if(dedup[res_utg.a.a[k]>>1] != 0) continue;
dedup[res_utg.a.a[k]>>1] = 1;
res_utg.a.a[m] = res_utg.a.a[k];
m++;
}
res_utg.a.n = m;
}
for (k = 0; k < res_utg.a.n; k++) dedup[res_utg.a.a[k]>>1] = 0;
/*******************************for debug************************************/
// for (i = 0; i < res_utg.a.n; i++)
// {
// for (k = 0; k < res_utg.a.n; k++)
// {
// if(k == i) continue;
// if((res_utg.a.a[i]>>1) == (res_utg.a.a[k]>>1)) fprintf(stderr, "ERROR\n");
// }
// }
/*******************************for debug************************************/
root = get_utg_end_from_btg(bub, bs_ug, v);
rId_0 = root>>1;
ori_0 = root&1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
if(root_0 != (uint32_t)-1 && (!IF_HOM(root_0>>1, *bub))) kv_push(uint32_t, res_utg.a, root_0);
if(v&1)
{
update_bubble_graph(&res_utg, root_0^1, rId_0, (uint32_t)-1, (uint32_t)-1, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);
}
else
{
update_bubble_graph(&res_utg, (uint32_t)-1, (uint32_t)-1, root_0^1, rId_0, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);
}
}
kv_push(uint32_t, bub->num, bub->list.n);
new_bub = bub->b_g->n_seq - new_bub;
bub->mess_bub += new_bub;
///actually not useful, and may have bug when one bubble at multipe chains
if(new_bub) update_bub_b_s_idx(bub);
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
if(nv == 0 || get_real_length(bs_ug->g, v, NULL) == 0) continue;
drop_g_edges_by_utg(bub, bub->b_g, bs_ug, NULL, v, (uint32_t)-1);
}
update_bsg(bub->b_g, &edges);
ma_ug_destroy(bs_ug);
bs_ug = ma_ug_gen(bub->b_g);
bub->b_ug = bs_ug;
kv_destroy(bub->chain_weight);
ma_utg_t *u_x = NULL;
bs_ug = bub->b_ug;
kv_malloc(bub->chain_weight, bs_ug->u.n); bub->chain_weight.n = bs_ug->u.n;
for (i = 0; i < bs_ug->u.n; i++)
{
u_x = &(bs_ug->u.a[i]);
bub->chain_weight.a[i].id = i;
// if(u->n <= 1) ///not a chain
// {
// bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
// bub->chain_weight.a[i].del = 1;
// }
// else
{
bub->chain_weight.a[i].del = 0;
calculate_chain_weight(u_x, bub, ug, &(bub->chain_weight.a[i]));
}
}
qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);
free(vis); free(is_vis); free(is_used); free(dedup); free(b.b.a);
kv_destroy(stack.a); kv_destroy(result.a); kv_destroy(res_utg.a);
kv_destroy(edges.a);
/*******************************for debug************************************/
// for (v = 0; v < (uint32_t)(bs_ug->g->n_seq<<1); v++)
// {
// if(asg_arc_n(bs_ug->g, v) > 0) fprintf(stderr, "ERROR, btg%.6ul\n", (v>>1)+1);
// ma_utg_t *utg = &(bs_ug->u.a[v>>1]);
// for (i = 0; i < utg->n; i++)
// {
// if((utg->a[i]>>33) >=
// (bub->f_bub + bub->b_bub + bub->b_end_bub + bub->tangle_bub + bub->cross_bub))
// {
// if(i != 0 && i != utg->n - 1) fprintf(stderr, "ERROR, btg%.6ul, i: %u\n", (v>>1)+1, i);
// }
// }
// }
/*******************************for debug************************************/
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
int cmp_chain_hic_w_weight(const void * a, const void * b)
{
if((*(chain_hic_w_type*)a).w != (*(chain_hic_w_type*)b).w)
{
return (*(chain_hic_w_type*)a).w > (*(chain_hic_w_type*)b).w? -1 : 1;
}
else
{
return 0;
}
}
#define is_useful_bub(ID, B) (((ID)>=((B).f_bub + (B).b_bub + (B).b_end_bub + (B).tangle_bub + (B).cross_bub))\
&& ((ID)<((B).f_bub + (B).b_bub + (B).b_end_bub + (B).tangle_bub + (B).cross_bub + (B).mess_bub)))
void init_chain_hic_warp(ma_ug_t* ug, hc_links* link, bubble_type* bub, chain_hic_warp* c_w)
{
ma_ug_t *bs_ug = bub->b_ug;
uint32_t *a = NULL, n, occ, i, k_i, k_j, k_k, uID, is_del, m, bub_mess;
double w;
ma_utg_t *u_x = NULL;
kv_init((*c_w));
kv_malloc((*c_w), bs_ug->u.n);
(*c_w).n = bs_ug->u.n;
(*c_w).max_bub_id = 0;
(*c_w).u_n = ug->u.n;
(*c_w).chain_idx = NULL;
MALLOC((*c_w).chain_idx, ug->u.n);
memset((*c_w).chain_idx, -1, sizeof(uint32_t)*ug->u.n);
for (i = bub_mess = 0; i < bs_ug->u.n; i++)
{
u_x = &(bs_ug->u.a[i]);
(*c_w).a[i].id = i;
(*c_w).a[i].w = 0;
(*c_w).a[i].occ = 0;
(*c_w).a[i].u = NULL;
for (k_i = 0, w = 0, occ = 0; k_i < u_x->n; k_i++)
{
if(is_useful_bub(u_x->a[k_i]>>33, *bub))
{
bub_mess++;
continue;
}
get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
occ += ug->u.a[uID].n;
for (k_k = 0; k_k < link->a.a[uID].e.n; k_k++)
{
if(link->a.a[uID].e.a[k_k].del) continue;
w += link->a.a[uID].e.a[k_k].weight;
}
}
}
(*c_w).a[i].w = w;
(*c_w).a[i].occ = occ;
}
if(bub_mess != bub->mess_bub) fprintf(stderr, "ERROR\n");
///fprintf(stderr, "bub_mess: %u, bub->mess_bub: %lu\n", bub_mess, bub->mess_bub);
for (i = 0; i < bs_ug->u.n; i++)
{
u_x = &(bs_ug->u.a[i]);
for (k_i = 0; k_i < u_x->n; k_i++)
{
if(is_useful_bub(u_x->a[k_i]>>33, *bub))
{
continue;
}
get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
if((*c_w).chain_idx[uID] == (uint32_t)-1)
{
(*c_w).chain_idx[uID] = i;
}
else
{
if((*c_w).a[i].occ > (*c_w).a[(*c_w).chain_idx[uID]].occ)
{
(*c_w).chain_idx[uID] = i;
}
}
}
}
}
for (i = m = 0; i < (*c_w).n; i++)
{
u_x = &(bs_ug->u.a[(*c_w).a[i].id]);
is_del = 1;
for (k_i = 0; k_i < u_x->n; k_i++)
{
if(is_useful_bub(u_x->a[k_i]>>33, *bub))
{
continue;
}
get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
if((*c_w).chain_idx[uID] == (*c_w).a[i].id)
{
is_del = 0;
break;
}
}
if(is_del == 0) break;
}
if(is_del == 0)
{
(*c_w).a[m] = (*c_w).a[i];
m++;
}
}
///fprintf(stderr, "# chain: %u, # pre chain: %u\n", m, (uint32_t)(*c_w).n);
(*c_w).n = m;
for (i = 0; i < (*c_w).n; i++)
{
u_x = &(bs_ug->u.a[(*c_w).a[i].id]);
CALLOC((*c_w).a[i].u, 1);
for (k_i = (*c_w).a[i].u->n = 0; k_i < u_x->n; k_i++)
{
if(is_useful_bub(u_x->a[k_i]>>33, *bub)) continue;
(*c_w).a[i].u->n++;
}
(*c_w).a[i].u->m = (*c_w).a[i].u->n;
MALLOC((*c_w).a[i].u->a, (*c_w).a[i].u->m);
for (k_i = (*c_w).a[i].u->n = 0; k_i < u_x->n; k_i++)
{
if(is_useful_bub(u_x->a[k_i]>>33, *bub)) continue;
(*c_w).a[i].u->a[(*c_w).a[i].u->n] = u_x->a[k_i];
(*c_w).a[i].u->n++;
}
}
(*c_w).max_bub_id = (*c_w).n;
if(bub->num.n > 0) bub->num.n--;
chain_hic_w_type* p = NULL;
for (i = 0; i < ug->u.n; i++)
{
uID = i;
if(IF_HOM(uID, *bub)) continue;
if((*c_w).chain_idx[uID] == (uint32_t)-1)
{
kv_pushp(chain_hic_w_type, (*c_w), &p);
CALLOC(p->u, 1);
p->u->n = p->u->m = 1;
MALLOC(p->u->a, p->u->m);
p->u->a[0] = (bub->pathLen.n)<<33;
/********************push bubble********************/
kv_push(uint32_t, bub->num, bub->list.n);
kv_push(uint64_t, bub->pathLen, 0);
kv_push(uint32_t, bub->list, uID<<1);
kv_push(uint32_t, bub->list, uID<<1);
kv_push(uint32_t, bub->list, uID<<1);
/********************push bubble********************/
p->occ = ug->u.a[uID].n;
p->w = 0;
for (k_k = 0; k_k < link->a.a[uID].e.n; k_k++)
{
if(link->a.a[uID].e.a[k_k].del) continue;
p->w += link->a.a[uID].e.a[k_k].weight;
}
p->id = (*c_w).n - 1;
(*c_w).chain_idx[uID] = p->id;
}
}
kv_push(uint32_t, bub->num, bub->list.n);
memset((*c_w).chain_idx, -1, sizeof(uint32_t)*ug->u.n);
for (i = 0; i < (*c_w).n; i++)
{
(*c_w).a[i].id = i;
u_x = (*c_w).a[i].u;
for (k_i = 0; k_i < u_x->n; k_i++)
{
get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
if((*c_w).chain_idx[uID] == (uint32_t)-1)
{
(*c_w).chain_idx[uID] = (*c_w).a[i].id;
}
else
{
if((*c_w).a[i].occ > (*c_w).a[(*c_w).chain_idx[uID]].occ)
{
(*c_w).chain_idx[uID] = (*c_w).a[i].id;
}
}
}
}
}
/**
uint32_t rId_0, ori_0, root_0, rId_1, ori_1, root_1;
for (i = 0; i < (*c_w).n; i++)
{
(*c_w).a[i].l_d = (*c_w).a[i].r_d = (uint64_t)-1;
u_x = (*c_w).a[i].u;
if(u_x->n == 0) continue;
rId_0 = u_x->a[0]>>33;
ori_0 = (u_x->a[0]>>32&1)^1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
root_0 ^= 1;
}
**/
///fprintf(stderr, "# chain: %u, # c_w.max_bub_id: %u\n", (uint32_t)(*c_w).n, (*c_w).max_bub_id);
///qsort((*c_w).a, (*c_w).n, sizeof(chain_hic_w_type), cmp_chain_hic_w_weight);
}
void destory_chain_hic_warp(chain_hic_warp* c_w)
{
uint32_t i;
for (i = 0; i < c_w->n; i++)
{
free(c_w->a[i].u->a);
free(c_w->a[i].u);
}
kv_destroy((*c_w));
free((*c_w).chain_idx);
}
void build_bub_graph(ma_ug_t* ug, bubble_type* bub)
{
bub->check_het = 0;
get_bub_graph(ug, bub); ///just create nodes/edges from f_bub
detect_bub_graph(bub, ug->g);
asg_destroy(bub->b_g);
bub->check_het = 1;
get_bub_graph(ug, bub);
///print_bubble_chain(bub, "first round");
// detect_bub_graph(bub, ug->g, 1);
update_bubble_chain(ug, bub, 1, 0);
///print_bubble_chain(bub, "second round");
update_bubble_chain(ug, bub, 0, 1);
resolve_bubble_chain_tangle(ug, bub);
}
void get_forward_distance(uint32_t src, uint32_t dest, asg_t *sg, hc_links* link, MT* M)
{
hc_edge *e = NULL;
e = get_hc_edge(link, src, dest, 0);
if(e == NULL) return;
uint32_t v, j;
uint64_t d[2], db[2], q_u, min, min_i, min_b;
e->dis = (uint64_t)-1;
for (v = ((uint64_t)(src)<<1); v < ((uint64_t)(src+1)<<1); v++)
{
d[0] = d[1] = db[0] = db[1] = (uint64_t)-1;
for (j = 0; j < M->matrix.a[v].a.n; j++)
{
q_u = M->matrix.a[v].a.a[j] >> M->uID_shift;
if((q_u>>1) == dest) d[q_u&1] = (M->matrix.a[v].a.a[j] & M->dis_mode) + sg->seq[q_u>>1].len;
if((q_u>>1) > dest) break;///just for speeding up, doesn't affect results
}
min = min_i = min_b = (uint64_t)-1;
if(e->dis != (uint64_t)-1) min = e->dis >> 3;
if(d[0] < min) min = d[0], min_i = 0, min_b = 0;
if(d[1] < min) min = d[1], min_i = 1, min_b = 0;
if(min_i != (uint64_t)-1 && min != (uint64_t)-1)
{
e->dis = min<<1;
e->dis += min_b;
e->dis <<=1;
e->dis += v&1;
e->dis <<=1;
e->dis += min_i;
}
}
// fprintf(stderr, "%s\t%s\tdis(%lu)\n", e->dis == (uint64_t)-1? "unreach cur": "**reach cur",
// ((e->dis>>2)&1)?"back":"forw", e->dis>>3);
}
int get_trans_rate_function_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub,
H_partition* hap, int8_t *s, trans_idx* dis)
{
kvec_t(uint64_t) buf;
kv_init(buf);
uint64_t beg, end, cnt[2];
uint64_t k, i, t_d, r_idx, f_idx, med = (uint64_t)-1;
int beg_status, end_status;
buf.n = 0;
for (k = 0; k < hits->a.n; ++k)
{
beg = ((hits->a.a[k].s<<1)>>(64 - idx->uID_bits));
end = ((hits->a.a[k].e<<1)>>(64 - idx->uID_bits));
if(IF_HOM(beg, *bub)) continue;
if(IF_HOM(end, *bub)) continue;
t_d = get_hic_distance(&(hits->a.a[k]), link, idx);
if(t_d == (uint64_t)-1) continue;
if(beg == end)
{
t_d = (t_d << 1);
}
else
{
beg_status = (hap? get_phase_status(hap, beg):s[beg]);
if(beg_status != 1 && beg_status != -1) continue;
end_status = (hap? get_phase_status(hap, end):s[end]);
if(end_status != 1 && end_status != -1) continue;
if(beg_status != end_status)
{
t_d = (t_d << 1) + 1;
}
else
{
t_d = (t_d << 1);
}
}
kv_push(uint64_t, buf, t_d);
}
///might have bias, we may not use right linkage larger than trans rc linkage
radix_sort_hc64(buf.a, buf.a+buf.n);
for (k = 0, r_idx = f_idx = (uint64_t)-1; k < buf.n; k++)
{
if((buf.a[k]&1) == 0) r_idx = k;
if((buf.a[k]&1) == 1) f_idx = k;
}
buf.n = MIN(r_idx, f_idx);
trans_p_t* p = NULL;
dis->n = 0;
uint64_t bin_size = MIN(2250, buf.n>>8), m;
i = 0;
while (i < buf.n)
{
kv_pushp(trans_p_t, *dis, &p);
p->beg = i;
cnt[0] = cnt[1] = 0;
k = MIN(i+bin_size, buf.n);
for (; i < k; i++)
{
cnt[buf.a[i]&1]++;
}
p->end = i;
p->cnt_0 = cnt[0];
p->cnt_1 = cnt[1];
}
i = m = 0; med = (uint64_t)-1;
while(i < dis->n)
{
if(dis->a[i].cnt_0 > 0 && dis->a[i].cnt_1 > 0)
{
dis->a[m] = dis->a[i];
m++;
i++;
continue;
}
if(med == (uint64_t)-1) med = buf.a[dis->a[i].beg]>>1;
k = i; cnt[0] = cnt[1] = 0;
for (; i < dis->n; i++)
{
cnt[0] += dis->a[i].cnt_0;
cnt[1] += dis->a[i].cnt_1;
if(cnt[0] > 0 && cnt[1] > 0) break;
}
if(i < dis->n)
{
dis->a[m].cnt_0 = cnt[0];
dis->a[m].cnt_1 = cnt[1];
dis->a[m].beg = dis->a[k].beg;
dis->a[m].end = dis->a[i].end;
m++;
i++;
continue;
}
cnt[0] -= dis->a[k].cnt_0;
cnt[1] -= dis->a[k].cnt_1;
while (1)
{
cnt[0] += dis->a[k].cnt_0;
cnt[1] += dis->a[k].cnt_1;
if(cnt[0] > 0 && cnt[1] > 0) break;
if(k == 0)
{
k = (uint64_t)-1;
break;
}
k--;
}
if(k != (uint64_t)-1)
{
dis->a[m].cnt_0 = cnt[0];
dis->a[m].cnt_1 = cnt[1];
dis->a[m].end = dis->a[i-1].end;
continue;
}
m = 0;
break;
}
dis->n = m;
if(dis->n == 0)
{
kv_destroy(buf);
return 0;
}
for (i = 0; i < dis->n; i++)
{
dis->a[i].beg = buf.a[dis->a[i].beg]>>1;
dis->a[i].end = (buf.a[dis->a[i].end-1]>>1);
}
for (i = 0; i < dis->n - 1; i++)
{
dis->a[i].end += ((dis->a[i+1].beg - dis->a[i].end)/2);
dis->a[i+1].beg = dis->a[i].end;
}
// for (i = 0; i < dis->n; i++)
// {
// if(i > 0 && dis->a[i].beg != dis->a[i-1].end) fprintf(stderr, "ERROR: dis->a[i].beg: %lu, dis->a[i-1].end: %lu\n", dis->a[i].beg, dis->a[i-1].end);
// fprintf(stderr, "beg: %lu, end: %lu, cnt_0: %lu, cnt_1: %lu, error_rate: %f\n",
// dis->a[i].beg, dis->a[i].end, dis->a[i].cnt_0, dis->a[i].cnt_1, (double)(dis->a[i].cnt_1)/(double)(dis->a[i].cnt_1 + dis->a[i].cnt_0));
// }
LeastSquare_advance(dis, idx, med);
// fprintf(stderr, "idx->a: %f, idx->b: %f, idx->frac: %f, med: %lu\n",
// (double)idx->a, (double)idx->b, (double)idx->frac, med);
dis->max = dis->a[dis->n-1].end;
if(idx->a < 0) idx->a = 0;
if(idx->a == 0)
{
idx->b = MAX((((double)(dis->a[dis->n-1].cnt_1))/((double)(dis->a[dis->n-1].cnt_0 + dis->a[dis->n-1].cnt_1))), idx->b);
}
if(idx->b < 0 && get_trans(idx, dis->max) < 0)
{
idx->b = ((double)(dis->a[dis->n-1].cnt_1))/((double)(dis->a[dis->n-1].cnt_0 + dis->a[dis->n-1].cnt_1));
}
// fprintf(stderr, "idx->a: %f, idx->b: %f, idx->frac: %f, med: %lu\n",
// (double)idx->a, (double)idx->b, (double)idx->frac, med);
buf.n = 0;
for (k = 0; k < hits->a.n; ++k)
{
beg = ((hits->a.a[k].s<<1)>>(64 - idx->uID_bits));
end = ((hits->a.a[k].e<<1)>>(64 - idx->uID_bits));
if(IF_HOM(beg, *bub)) continue;
if(IF_HOM(end, *bub)) continue;
if(beg == end) continue;
t_d = get_hic_distance(&(hits->a.a[k]), link, idx);
if(t_d == (uint64_t)-1) continue;
kv_push(uint64_t, buf, t_d);
}
///might have bias, we may not use right linkage larger than trans rc linkage
radix_sort_hc64(buf.a, buf.a+buf.n);
if(buf.n == 0)
{
dis->med = 0;
}
else
{
dis->med = ((buf.n&1)?buf.a[buf.n>>1]:((buf.a[buf.n>>1]+buf.a[(buf.n>>1)-1])/2));
}
// fprintf(stderr, "dis->med: %lu\n", dis->med);
kv_destroy(buf);
return 1;
}
void init_hic_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, H_partition* hap, uint32_t ignore_dis)
{
uint64_t k, i, m, is_comples_weight = 0;
trans_idx dis;
kv_init(dis);
if(bub->round_id > 0 && ignore_dis == 0)
{
is_comples_weight = get_trans_rate_function_advance(idx, hits, link, bub, hap, NULL, &dis);
}
hc_edge *e = NULL;
for (i = 0; i < link->a.n; i++)
{
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
if(link->a.a[i].e.a[k].dis == (uint64_t)-1)
{
e = get_hc_edge(link, link->a.a[i].e.a[k].uID, i, 0);
if(!e) fprintf(stderr, "ERROR\n");
e->del = link->a.a[i].e.a[k].del = 1;
}
}
}
for (i = 0; i < link->a.n; i++)
{
for (k = m = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
link->a.a[i].e.a[m] = link->a.a[i].e.a[k];
link->a.a[i].e.a[m].weight = 0;
link->a.a[i].e.a[m].occ = 0;
m++;
}
link->a.a[i].e.n = m;
}
weight_edges_advance(idx, hits, link, bub, is_comples_weight == 1? &dis : NULL);
for (i = 0; i < link->a.n; i++)
{
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
if(link->a.a[i].e.a[k].weight <= 0)
{
e = get_hc_edge(link, link->a.a[i].e.a[k].uID, i, 0);
e->del = link->a.a[i].e.a[k].del = 1;
}
}
}
for (i = 0; i < link->a.n; i++)
{
for (k = m = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
link->a.a[i].e.a[m] = link->a.a[i].e.a[k];
m++;
}
link->a.a[i].e.n = m;
}
kv_destroy(dis);
}
#define is_hap_set(i, Hap) (!!((Hap).hap[(i)]&((Hap).m[0]|(Hap).m[1]|(Hap).m[2])))
#define is_hap_set_label(i, Hap, label) (is_hap_set((i), (Hap))&&((Hap).hap[(i)]>>(Hap).label_shift)==((label)>>(Hap).label_shift))
double get_path_weight(uint32_t query, uint32_t v0, uint32_t root, bub_p_t_warp *b, hc_links* x)
{
if(v0 == root) return 0;
uint32_t v, u;
hc_edge *p = NULL;
double weight = 0;
v = v0;
do {
u = b->a[v].p; // u->v
p = get_hc_edge(x, query>>1, v>>1, 0);
if(p) weight += p->weight;
v = u;
} while (v != root);
return weight;
}
uint32_t get_related_weight(uint32_t x, H_partition* hap, double* w0, double* w1, uint32_t* hap_label)
{
(*w0) = (*w1) = 0;
if(x >= hap->link->a.n) return 0;
uint32_t i, a_n = hap->link->a.a[x].e.n, occ;
hc_edge* a = hap->link->a.a[x].e.a;
for (i = occ = 0; i < a_n; i++)
{
if(a[i].del) continue;
if(hap_label && (!is_hap_set_label(a[i].uID, *hap, *hap_label))) continue;
if(is_hap_set(a[i].uID, *hap)) occ++;
if((hap->hap[a[i].uID] & hap->m[0])) (*w0)+= a[i].weight;
if((hap->hap[a[i].uID] & hap->m[1])) (*w1)+= a[i].weight;
}
return occ;
}
void set_path_hap(bub_p_t_warp *b, uint32_t root, H_partition* hap, uint32_t max_hap_label)
{
uint32_t v, u, label;
double w0 = 0, w1 = 0, cur_w0, cur_w1;
///v is the sink of this bubble
v = b->S.a[0];
do {
u = b->a[v].p; // u->v
if(v != b->S.a[0])
{
get_related_weight(v>>1, hap, &cur_w0, &cur_w1, &max_hap_label);
w0 += cur_w0; w1 += cur_w1;
}
v = u;
} while (v != root);
if(w0 > w1)
{
label = max_hap_label | hap->m[0];
b->exist_hap_label = hap->m[0];
}
else if(w0 < w1)
{
label = max_hap_label | hap->m[1];
b->exist_hap_label = hap->m[1];
}
else
{
if(b->exist_hap_label == (uint32_t)-1)
{
label = max_hap_label | hap->m[0];
b->exist_hap_label = hap->m[0];
}
else
{
if(b->exist_hap_label == hap->m[0])
{
label = max_hap_label | hap->m[1];
b->exist_hap_label = hap->m[1];
}
else
{
label = max_hap_label | hap->m[0];
b->exist_hap_label = hap->m[0];
}
}
}
v = b->S.a[0];
do {
u = b->a[v].p; // u->v
if(v != b->S.a[0]) hap->hap[v>>1] |= label;
v = u;
} while (v != root);
}
uint64_t get_phase_path(ma_ug_t *ug, uint32_t s, uint32_t d, bub_p_t_warp *b, H_partition* hap, uint32_t max_hap_label)
{
asg_t *g = ug->g;
if(g->seq[s>>1].del) return 0; // already deleted
if(get_real_length(g, s, NULL)<2) return 0;
uint32_t i, n_pending, is_first, to_replace, cur_nc, cur_uc, cur_ac, n_tips, tip_end, n_pop;
double cur_nh, cur_w0, cur_w1, cur_rate, max_rate, cur_weight, max_weight;
///S saves nodes with all incoming edges visited
b->S.n = b->T.n = b->b.n = b->e.n = 0;
///for each node, b->a saves all related information
b->a[s].d = b->a[s].nc = b->a[s].ac = b->a[s].uc = 0; b->a[s].nh = b->a[s].w[0] = b->a[s].w[1] = 0;
///b->S is the nodes with all incoming edges visited
kv_push(uint32_t, b->S, s);
n_pop = n_tips = n_pending = 0;
tip_end = (uint32_t)-1;
is_first = 1;
do {
///v is a node that all incoming edges have been visited
///d is the distance from v0 to v
uint32_t v = kv_pop(b->S);
uint32_t d = b->a[v].d, nc = b->a[v].nc, uc = b->a[v].uc, ac = b->a[v].ac;
double nh = b->a[v].nh;
double nw_0 = b->a[v].w[0], nw_1 = b->a[v].w[1];
uint32_t nv = asg_arc_n(g, v);
asg_arc_t *av = asg_arc_a(g, v);
for (i = 0; i < nv; ++i) {
uint32_t w = av[i].v, l = (uint32_t)av[i].ul; // v->w with length l, not overlap length
bub_p_t *t = &b->a[w];
//got a circle
if ((w>>1) == (s>>1)) goto pop_reset;
//important when poping at long untig graph
if(is_first) l = 0;
if (av[i].del) continue;
///push the edge
kv_push(uint32_t, b->e, (g->idx[v]>>32) + i);
if (t->s == 0)
{ // this vertex has never been visited
kv_push(uint32_t, b->b, w); // save it for revert
///t->p is the parent node of
///t->s = 1 means w has been visited
///d is len(v0->v), l is len(v->w), so t->d is len(v0->w)
t->p = v, t->s = 1, t->d = d + l, t->nc = nc + ug->u.a[(w>>1)].n;
t->r = get_real_length(g, w^1, NULL);
/**need fix**/
t->nh = nh + get_path_weight(w, v, s, b, hap->link);
get_related_weight(w>>1, hap, &(t->w[0]), &(t->w[1]), &max_hap_label);
t->w[0] += nw_0; t->w[1] += nw_1;
t->ac = ac + ((!is_hap_set_label(w>>1, *hap, max_hap_label))?ug->u.a[(w>>1)].n : 0);
t->uc = uc + ((is_hap_set_label(w>>1, *hap, max_hap_label))?ug->u.a[(w>>1)].n : 0);
++n_pending;
}
else {
to_replace = 0;
cur_nc = nc + ug->u.a[(w>>1)].n;
/**need fix**/
cur_nh = nh + get_path_weight(w, v, s, b, hap->link);
get_related_weight(w>>1, hap, &cur_w0, &cur_w1, &max_hap_label);
cur_w0 += nw_0; cur_w1 += nw_1;
cur_weight = cur_nh + MAX(cur_w0, cur_w1) - MIN(cur_w0, cur_w1);
max_weight = t->nh + MAX(t->w[0], t->w[1]) - MIN(t->w[0], t->w[1]);
cur_ac = ac + ((!is_hap_set_label(w>>1, *hap, max_hap_label))?ug->u.a[(w>>1)].n : 0);;
cur_uc = uc + ((is_hap_set_label(w>>1, *hap, max_hap_label))?ug->u.a[(w>>1)].n : 0);
cur_rate = ((double)(cur_ac)/(double)(cur_ac+cur_uc));
max_rate = ((double)(t->ac)/(double)(t->ac+t->uc));
if(cur_rate > max_rate)
{
to_replace = 1;
}
else if(cur_rate == max_rate)
{
///if(cur_nh > t->nh)
if(cur_weight > max_weight)
{
to_replace = 1;
}
else if(cur_weight == max_weight)///(cur_nh == t->nh)
{
if(cur_nc > t->nc)
{
to_replace = 1;
}
else if(cur_nc == t->nc)
{
if(d + l > t->d)
{
to_replace = 1;
}
}
}
}
if(to_replace)
{
t->p = v;
t->nc = cur_nc;
t->nh = cur_nh;
t->ac = cur_ac;
t->uc = cur_uc;
t->w[0] = cur_w0;
t->w[1] = cur_w1;
}
if (d + l < t->d) t->d = d + l; // update dist
}
if (--(t->r) == 0) {
uint32_t x = get_real_length(g, w, NULL);
if(x > 0)
{
kv_push(uint32_t, b->S, w);
}
else
{
///at most one tip
if(n_tips != 0) goto pop_reset;
n_tips++;
tip_end = w;
}
--n_pending;
}
}
is_first = 0;
if(n_tips == 1)
{
if(tip_end != (uint32_t)-1 && n_pending == 0 && b->S.n == 0)
{
///sink is b.S.a[0]
kv_push(uint32_t, b->S, tip_end);
break;
}
else
{
goto pop_reset;
}
}
if (i < nv || b->S.n == 0) goto pop_reset;
}while (b->S.n > 1 || n_pending);
n_pop = 1;
/**need fix**/
set_path_hap(b, s, hap, max_hap_label);
pop_reset:
for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
bub_p_t *t = &b->a[b->b.a[i]];
t->p = t->d = t->nc = t->ac = t->uc = t->r = t->s = 0;
t->nh = t->w[0] = t->w[1] = 0;
}
return n_pop;
}
uint32_t get_weightest_hap_label_from_uid(uint64_t x, H_partition* hap, uint8_t* hap_label_flag,
uint32_t* max_hap_label, double* max_hap_weight)
{
(*max_hap_label) = (uint32_t)-1;
kv_resize(double, hap->label_buffer, (hap->label>>hap->label_shift)+1);
hap->label_buffer.n = (hap->label>>hap->label_shift)+1;
uint32_t i, is_set_ava, is_unset_ava, a_n;
hc_edge* a = NULL;
for (i = 0; i < hap->label_buffer.n; i++)
{
hap->label_buffer.a[i] = 0;
}
is_set_ava = is_unset_ava = 0;
a_n = hap->link->a.a[x].e.n;
a = hap->link->a.a[x].e.a;
for (i = 0; i < a_n; i++)
{
if(a[i].del) continue;
if(is_hap_set(a[i].uID, *hap))
{
if(hap_label_flag && hap_label_flag[hap->hap[a[i].uID]] == 0) continue;
hap->label_buffer.a[hap->hap[a[i].uID]>>hap->label_shift] += a[i].weight;
is_set_ava = 1;
}
is_unset_ava = 1;
}
if(hap_label_flag && is_set_ava == 0) return 0;
if(is_unset_ava == 0) return 0;
if(is_set_ava == 0 && is_unset_ava > 0)
{
hap->label += hap->label_add;
(*max_hap_label) = hap->label;
return 1;
}
double max_weight;
uint32_t max_i;
for (i = 0, max_weight = -1, max_i = (uint32_t)-1; i < hap->label_buffer.n; i++)
{
if(hap->label_buffer.a[i] > max_weight)
{
max_weight = hap->label_buffer.a[i];
max_i = i;
}
}
(*max_hap_label) = max_i<<hap->label_shift;
if(max_hap_weight) (*max_hap_weight) = max_weight;
return 1;
}
uint32_t get_weightest_hap_label_from_bubble(uint64_t bid, H_partition* hap, bubble_type* bub,
uint8_t* hap_label_flag, uint32_t* max_hap_label, double* max_hap_weight)
{
(*max_hap_label) = (uint32_t)-1;
kv_resize(double, hap->label_buffer, (hap->label>>hap->label_shift)+1);
hap->label_buffer.n = (hap->label>>hap->label_shift)+1;
uint32_t i, m, is_set_ava, is_unset_ava, a_n, *x_a, x_n, x;
hc_edge* a = NULL;
for (i = 0; i < hap->label_buffer.n; i++)
{
hap->label_buffer.a[i] = 0;
}
///bid might be bubble or non-bubble
get_bubbles(bub, bid, NULL, NULL, &x_a, &x_n, NULL);
for (m = is_set_ava = is_unset_ava = 0; m < x_n; m++)
{
///x is uid
x = x_a[m]>>1;
a_n = hap->link->a.a[x].e.n;
a = hap->link->a.a[x].e.a;
for (i = 0; i < a_n; i++)
{
if(a[i].del) continue;
if(is_hap_set(a[i].uID, *hap))
{
if(hap_label_flag && hap_label_flag[hap->hap[a[i].uID]] == 0) continue; ///not at current chain
hap->label_buffer.a[hap->hap[a[i].uID]>>hap->label_shift] += a[i].weight;
is_set_ava = 1;
}
is_unset_ava = 1;
}
}
if(hap_label_flag && is_set_ava == 0) return 0; ///no connection in current chain
if(is_unset_ava == 0) return 0; ///no any connection
if(is_set_ava == 0 && is_unset_ava > 0) ///update hap->label
{
hap->label += hap->label_add;
(*max_hap_label) = hap->label;
return 1;
}
double max_weight;
uint32_t max_i;
for (i = 0, max_weight = -1, max_i = (uint32_t)-1; i < hap->label_buffer.n; i++)
{
if(hap->label_buffer.a[i] > max_weight)
{
max_weight = hap->label_buffer.a[i];
max_i = i;
}
}
(*max_hap_label) = max_i<<hap->label_shift;
if(max_hap_weight) (*max_hap_weight) = max_weight;
return 1;
}
uint32_t get_available_com(H_partition* hap, bubble_type* bub, ma_ug_t *ug, uint32_t check_self, uint32_t check_others,
uint8_t* hap_label_flag, uint32_t* max_hap_label)
{
hc_links* link = hap->link;
uint32_t beg, sink, n, *a, i, j, k, uID, max_bub_i, max_non_bub_i, max_i, is_ava;
uint32_t hap_label, max_bub_label = (uint32_t)-1, max_non_bub_label = (uint32_t)-1;
double w, max_bub_w, max_non_bub_w;
max_i = (uint32_t)-1;
for (i = 0, max_bub_w = -1, max_bub_i = (uint32_t)-1; i < bub->f_bub/**bub->s_bub**/; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
for (j = 0, w = 0; j < n; j++)
{
uID = a[j]>>1;
if(check_self && is_hap_set(uID, *hap)) break;
}
if(j != n) continue;
is_ava = 0;
hap_label = (uint32_t)-1;
if(check_others)
{
if(get_weightest_hap_label_from_bubble(i, hap, bub,
hap_label_flag, &hap_label, &w)>0)
{
is_ava = 1;
}
}
else
{
for (j = 0, w = 0, is_ava = 0; j < n; j++)
{
uID = a[j]>>1;
for (k = 0; k < link->a.a[uID].e.n; k++)
{
if(link->a.a[uID].e.a[k].del) continue;
w += link->a.a[uID].e.a[k].weight;
is_ava = 1;
}
}
}
if(is_ava == 0) continue;
if(w > max_bub_w)
{
max_bub_w = w;
max_bub_i = i;
max_bub_label = hap_label;
}
}
for (i = 0, max_non_bub_w = -1, max_non_bub_i = (uint32_t)-1; i < ug->u.n; i++)
{
if(IF_HET(i, *bub)/** || (bub->index[i] >= bub->s_bub && bub->index[i] < bub->f_bub)**/)
{
uID = i;
is_ava = 0;
if(check_self && is_hap_set(uID, *hap)) continue;
hap_label = (uint32_t)-1;
if(check_others)
{
if(get_weightest_hap_label_from_uid(uID, hap, hap_label_flag, &hap_label, &w)>0)
{
is_ava = 1;
}
}
else
{
for (k = 0, w = 0, is_ava = 0; k < link->a.a[uID].e.n; k++)
{
if(link->a.a[uID].e.a[k].del) continue;
w += link->a.a[uID].e.a[k].weight;
is_ava = 1;
}
}
if(is_ava == 0) continue;
if(w > max_non_bub_w)
{
max_non_bub_w = w;
max_non_bub_i = i;
max_non_bub_label = hap_label;
}
}
}
if(max_bub_i != (uint32_t)-1 && max_non_bub_i != (uint32_t)-1)
{
if(max_non_bub_w > max_bub_w)
{
max_i = (max_non_bub_i << 1) + 1;
w = max_non_bub_w;
(*max_hap_label) = max_non_bub_label;
}
else
{
max_i = (max_bub_i << 1);
w = max_bub_w;
(*max_hap_label) = max_bub_label;
}
}
else if(max_bub_i != (uint32_t)-1)
{
max_i = (max_bub_i << 1);
w = max_bub_w;
(*max_hap_label) = max_bub_label;
}
else if(max_non_bub_i != (uint32_t)-1)
{
max_i = (max_non_bub_i << 1) + 1;
w = max_non_bub_w;
(*max_hap_label) = max_non_bub_label;
}
if(max_i == (uint32_t)-1)
{
for (i = 0, max_non_bub_w = -1, max_non_bub_i = (uint32_t)-1; i < ug->u.n; i++)
{
///if(bub->index[i] < bub->s_bub)
if(IF_BUB(i, *bub))
{
uID = i;
is_ava = 0;
if(check_self && is_hap_set(uID, *hap)) continue;
hap_label = (uint32_t)-1;
if(check_others)
{
if(get_weightest_hap_label_from_uid(uID, hap, hap_label_flag, &hap_label, &w)>0)
{
is_ava = 1;
}
}
else
{
for (k = 0, w = 0, is_ava = 0; k < link->a.a[uID].e.n; k++)
{
if(link->a.a[uID].e.a[k].del) continue;
w += link->a.a[uID].e.a[k].weight;
is_ava = 1;
}
}
if(is_ava == 0) continue;
if(w > max_non_bub_w)
{
max_non_bub_w = w;
max_non_bub_i = i;
max_non_bub_label = hap_label;
}
}
}
if(max_non_bub_i != (uint32_t)-1)
{
max_i = (max_non_bub_i << 1) + 1;
w = max_non_bub_w;
(*max_hap_label) = max_non_bub_label;
}
}
// if(max_i == (uint32_t)-1)
// {
// fprintf(stderr, "-Cannot find!\n");
// }
// else if(max_i & 1)
// {
// fprintf(stderr, "-utg-%uth, phasing ID: %u, w: %f, max_bub_i: %u, max_bub_w: %f, max_non_bub_i: %u, max_non_bub_w: %f\n",
// max_i>>1, hap->label>>3, w, max_bub_i, max_bub_w, max_non_bub_i, max_non_bub_w);
// }
// else
// {
// fprintf(stderr, "-bubble-%uth, phasing ID: %u, w: %f, max_bub_i: %u, max_bub_w: %f, max_non_bub_i: %u, max_non_bub_w: %f\n",
// max_i>>1, hap->label>>3, w, max_bub_i, max_bub_w, max_non_bub_i, max_non_bub_w);
// }
return max_i;
}
void reset_ambiguous_label(H_partition* hap, uint8_t* hap_label_flag, uint32_t uID)
{
uint32_t hap_label = (uint32_t)-1;
if(get_weightest_hap_label_from_uid(uID, hap, hap_label_flag, &hap_label, NULL)>0)
{
double cur_w0, cur_w1;
get_related_weight(uID, hap, &cur_w0, &cur_w1, &hap_label);
if(cur_w0 >= cur_w1)
{
hap->hap[uID] |= (hap_label | hap->m[0]);
}
else
{
hap->hap[uID] |= (hap_label | hap->m[1]);
}
}
}
uint32_t get_unset_com(H_partition* hap, bubble_type* bub, ma_ug_t *ug, uint8_t* hap_label_flag, uint32_t* max_hap_label)
{
uint32_t max_i = get_available_com(hap, bub, ug, 1, 1, hap_label_flag, max_hap_label);
if(max_i == (uint32_t)-1)
{
max_i = get_available_com(hap, bub, ug, 1, 0, hap_label_flag, max_hap_label);
if(max_i != (uint32_t)-1)
{
hap->label += hap->label_add;
(*max_hap_label) = hap->label;
}
}
return max_i;
}
void phase_com(H_partition* hap, ma_ug_t *ug, bub_p_t_warp* b, bubble_type* bub, uint32_t bid, uint32_t max_hap_label)
{
if((bid & 1) == 0) ///bubble
{
uint32_t beg = (uint32_t)-1, sink = (uint32_t)-1, n, *a;
get_bubbles(bub, bid>>1, &beg, &sink, &a, &n, NULL);
///fprintf(stderr, "+bubble-%uth, beg: %u, sink: %u, phasing ID: %u\n", bid>>1, beg>>1, sink>>1, hap->label>>3);
b->exist_hap_label = (uint32_t)-1;
get_phase_path(ug, beg, sink, b, hap, max_hap_label);
get_phase_path(ug, beg, sink, b, hap, max_hap_label);
///fprintf(stderr, "-bubble-%uth, beg: %u, sink: %u, phasing ID: %u\n", bid>>1, beg>>1, sink>>1, hap->label>>3);
}
else
{
double cur_w0, cur_w1;
get_related_weight(bid>>1, hap, &cur_w0, &cur_w1, &max_hap_label);
///fprintf(stderr, "utg-%uth, phasing ID: %u\n", bid>>1, hap->label>>3);
if(cur_w0 >= cur_w1)
{
hap->hap[bid>>1] |= (max_hap_label | hap->m[0]);
}
else
{
hap->hap[bid>>1] |= (max_hap_label | hap->m[1]);
}
}
}
double get_cluster_weight(H_partition* hap, hc_links* link, uint32_t *h, uint32_t h_n)
{
int o_d = 0;
double weight = 0;
uint32_t j, k, m;
for (j = 0, weight = 0; j < h_n; j++)
{
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
if(link->a.a[h[j]].e.a[k].del) continue;
for (m = 0; m < h_n; m++)
{
if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
}
if(m < h_n) continue;
o_d = get_phase_status(hap, link->a.a[h[j]].e.a[k].uID);
if(o_d < -1) continue;
///if(o_d < -1) fprintf(stderr, "ERROR\n");
weight += (o_d*link->a.a[h[j]].e.a[k].weight);
}
}
return weight;
}
double get_cluster_inner_weight(H_partition* hap, hc_links* link, uint32_t *h0, uint32_t h0_n,
uint32_t *h1, uint32_t h1_n)
{
double weight = 0;
uint32_t j, k, m;
for (j = 0, weight = 0; j < h0_n; j++)
{
for (k = 0; k < link->a.a[h0[j]].e.n; k++)
{
if(link->a.a[h0[j]].e.a[k].del) continue;
for (m = 0; m < h1_n; m++)
{
if(h1[m] == link->a.a[h0[j]].e.a[k].uID) break;
}
if(m == h1_n) continue;
weight += link->a.a[h0[j]].e.a[k].weight;
}
}
return weight * 2;
}
void update_partition_flag(H_partition* h, G_partition* g_p, hc_links* link, uint32_t id)
{
uint32_t k, *h0, h0_n, *h1, h1_n, uID, flag = 0;
int status;
get_phased_block(g_p, NULL, id, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
status = g_p->a[id].status[0];
if(status == 1) flag = h->m[0];
else if(status == -1) flag = h->m[1];
else if(status == 0) flag = h->m[2];
else if(status == -2) flag = 0;
for (k = 0; k < h0_n; k++)
{
uID = h0[k];
h->hap[uID] >>= 3;
h->hap[uID] <<= 3;
h->hap[uID] |= flag;
}
status = g_p->a[id].status[1];
if(status == 1) flag = h->m[0];
else if(status == -1) flag = h->m[1];
else if(status == 0) flag = h->m[2];
else if(status == -2) flag = 0;
for (k = 0; k < h1_n; k++)
{
uID = h1[k];
h->hap[uID] >>= 3;
h->hap[uID] <<= 3;
h->hap[uID] |= flag;
}
}
void update_partition_flag_debug(H_partition* h, G_partition* g_p, hc_links* link, uint32_t id)
{
uint32_t k, *h0, h0_n, *h1, h1_n, uID, flag = 0;
int status;
get_phased_block(g_p, NULL, id, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
status = g_p->a[id].status[0];
if(status == 1) flag = h->m[0];
else if(status == -1) flag = h->m[1];
else if(status == 0) flag = h->m[2];
else if(status == -2) flag = 0;
for (k = 0; k < h0_n; k++)
{
uID = h0[k];
if(flag != (h->hap[uID]&7)) fprintf(stderr, "h0, id: %u, uID: %u, pre_flag: %u, cur_flag: %u\n", id, uID, (h->hap[uID]&7), flag);
h->hap[uID] >>= 3;
h->hap[uID] <<= 3;
h->hap[uID] |= flag;
}
status = g_p->a[id].status[1];
if(status == 1) flag = h->m[0];
else if(status == -1) flag = h->m[1];
else if(status == 0) flag = h->m[2];
else if(status == -2) flag = 0;
for (k = 0; k < h1_n; k++)
{
uID = h1[k];
if(flag != (h->hap[uID]&7)) fprintf(stderr, "h1, id: %u, uID: %u, pre_flag: %u, cur_flag: %u\n", id, uID, (h->hap[uID]&7), flag);
h->hap[uID] >>= 3;
h->hap[uID] <<= 3;
h->hap[uID] |= flag;
}
}
void print_contig_partition(H_partition* hap, const char* debug)
{
uint32_t i;
int status;
for (i = 0; i < hap->n; i++)
{
status = get_phase_status(hap, i);
fprintf(stderr, "%s\tutg%.6d\tP:%u\tHG:A:%d\n", debug, (int)(i+1), hap->hap[i]>>3, status);
}
}
void adjust_contig_partition(H_partition* hap, hc_links* link)
{
double index_time = yak_realtime();
uint32_t i, k, *h0, h0_n, *h1, h1_n;
uint32_t h0_status[4], h1_status[4], h0_status_max;
int h0_h, h1_h;
for (i = 0; i < hap->g_p.n; i++)
{
get_phased_block(&(hap->g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
hap->g_p.a[i].status[0] = hap->g_p.a[i].status[1] = -2;
hap->g_p.a[i].weight[0] = hap->g_p.a[i].weight[1] = hap->g_p.a[i].weight_convex = 0;
h0_status[0] = h0_status[1] = h0_status[2] = h0_status[3] = 0;
for (k = 0; k < h0_n; k++)
{
h0_status[get_phase_status(hap, h0[k])+2]++;
}
hap->g_p.a[i].weight[0] = get_cluster_weight(hap, link, h0, h0_n);
if(h1_n == 0)
{
if(h0_status[0] == h0_n) ///unset, flag = -2
{
hap->g_p.a[i].status[0] = -2;
}
else
{
if(h0_status[1] > 0 || h0_status[3] > 0) ///phased flag = 1/-1
{
h0_status[0] = h0_status[2] = 0;
h0_h = -2;
h0_status_max = 0;
for (k = 0; k < 4; k++)
{
if(h0_status[k] > h0_status_max)
{
h0_status_max = h0_status[k];
h0_h = (int)(k) - 2;
}
}
hap->g_p.a[i].status[0] = h0_h;
}
else if(h0_status[2] > 0) ///hom flag
{
hap->g_p.a[i].status[0] = 0;
}
else //unset flag
{
hap->g_p.a[i].status[0] = -2;
}
}
}
else
{
hap->g_p.a[i].weight[1] = get_cluster_weight( hap, link, h1, h1_n);
h1_status[0] = h1_status[1] = h1_status[2] = h1_status[3] = 0;
for (k = 0; k < h1_n; k++)
{
h1_status[get_phase_status(hap, h1[k])+2]++;
}
h0_h = h1_h = 0;
for (k = 0; k < 4; k++)
{
if(h0_status[k] == h0_n) h0_h = (int)(k) - 2;
if(h1_status[k] == h1_n) h1_h = (int)(k) - 2;
}
if(h0_h * h1_h == -1)
{
hap->g_p.a[i].status[0] = h0_h;
hap->g_p.a[i].status[1] = h1_h;
}
else
{
if(hap->g_p.a[i].weight[0] >= hap->g_p.a[i].weight[1])
{
hap->g_p.a[i].status[0] = 1;
hap->g_p.a[i].status[1] = -1;
}
else
{
hap->g_p.a[i].status[0] = -1;
hap->g_p.a[i].status[1] = 1;
}
}
}
hap->g_p.a[i].weight_convex = get_cluster_inner_weight(hap, link, h0, h0_n, h1, h1_n);
update_partition_flag(hap, &(hap->g_p), link, i);
///update_partition_flag_debug(hap, &(hap->g_p), link, i);
}
for (i = 0; i < hap->g_p.n; i++)
{
get_phased_block(&(hap->g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
hap->g_p.a[i].weight[0] = get_cluster_weight(hap, link, h0, h0_n);
hap->g_p.a[i].weight[1] = get_cluster_weight(hap, link, h1, h1_n);
hap->g_p.a[i].weight_convex = get_cluster_inner_weight(hap, link, h0, h0_n, h1, h1_n);
}
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
uint32_t get_weightest_uid(uint32_t* a, uint32_t n, H_partition* hap, uint8_t* hap_label_flag,
uint32_t* max_hap_label)
{
double cur_w0, cur_w1, max_weight;
uint32_t j, max_i, is_ava, hap_label;
for (j = is_ava = 0, max_i = (uint32_t)-1; j < n; j++)
{
if(is_hap_set(a[j]>>1, *hap)) ///avoid repeat phasing
{
continue;
}
get_weightest_hap_label_from_uid(a[j]>>1, hap, hap_label_flag, &hap_label, NULL);
if(hap_label == (uint32_t)-1)
{
continue;
}
if(get_related_weight(a[j]>>1, hap, &cur_w0, &cur_w1, &hap_label) > 0)
{
if(max_i == (uint32_t)-1)
{
max_i = j;
max_weight = cur_w0 + cur_w1;
(*max_hap_label) = hap_label;
}
else if((cur_w0 + cur_w1) > max_weight)
{
max_i = j;
max_weight = cur_w0 + cur_w1;
(*max_hap_label) = hap_label;
}
is_ava++;
}
}
///no useful unitig
if(is_ava == 0)
{
for (j = is_ava = 0, max_i = (uint32_t)-1; j < n; j++)
{
if(is_hap_set(a[j]>>1, *hap))
{
continue;
}
if(get_weightest_hap_label_from_uid(a[j]>>1, hap, NULL, &hap_label, NULL)==0) continue;
if(get_related_weight(a[j]>>1, hap, &cur_w0, &cur_w1, &hap_label) > 0)
{
if(max_i == (uint32_t)-1)
{
max_i = j;
max_weight = cur_w0 + cur_w1;
(*max_hap_label) = hap_label;
}
else if((cur_w0 + cur_w1) > max_weight)
{
max_i = j;
max_weight = cur_w0 + cur_w1;
(*max_hap_label) = hap_label;
}
is_ava++;
}
}
}
if(max_i == (uint32_t)-1) return max_i;
return a[max_i]>>1;
}
void get_weightest_hap_label_from_chain(ma_utg_t *u, H_partition* hap, bubble_type* bub,
uint32_t* max_hap_label, uint32_t* max_bid_idx, uint32_t* is_forward_first)
{
(*max_hap_label) = (uint32_t)-1;
if(max_bid_idx) (*max_bid_idx) = 0;
if(is_forward_first) (*is_forward_first) = 1;
if(u->n == 0) return;
kv_resize(double, hap->label_buffer, (hap->label>>hap->label_shift)+1);///how many group
hap->label_buffer.n = (hap->label>>hap->label_shift)+1;
uint32_t i, k, m, is_ava, a_n, *x_a, x_n, x;
uint64_t bid;
hc_edge* a = NULL;
for (i = 0; i < hap->label_buffer.n; i++)
{
hap->label_buffer.a[i] = 0;///count weight for each group
}
for (k = is_ava = 0; k < u->n; k++)
{
bid = u->a[k]>>33;
///bid might be bubble or non-bubble
get_bubbles(bub, bid, NULL, NULL, &x_a, &x_n, NULL);
for (m = 0; m < x_n; m++)
{
///x is uid
x = x_a[m]>>1;
a_n = hap->link->a.a[x].e.n;
a = hap->link->a.a[x].e.a;
for (i = 0; i < a_n; i++)
{
if(a[i].del) continue;
if(is_hap_set(a[i].uID, *hap))
{
hap->label_buffer.a[hap->hap[a[i].uID]>>hap->label_shift] += a[i].weight;
is_ava = 1;
}
}
}
}
if(is_ava == 0) return; ///totally new chain
double max_weight;
uint32_t max_i;
///select the best exsiting group to u
for (i = 0, max_weight = -1, max_i = (uint32_t)-1; i < hap->label_buffer.n; i++)
{
if(hap->label_buffer.a[i] > max_weight)
{
max_weight = hap->label_buffer.a[i];
max_i = i;
}
}
(*max_hap_label) = max_i<<hap->label_shift;
if(max_bid_idx)
{
double current_weight, tot_w = 0, half_w = 0;
for (k = 0, max_weight = -1, max_i = (uint32_t)-1; k < u->n; k++)
{
bid = u->a[k]>>33;
///bid might be bubble or non-bubble
get_bubbles(bub, bid, NULL, NULL, &x_a, &x_n, NULL);
for (m = 0, current_weight = 0; m < x_n; m++)
{
x = x_a[m]>>1;
a_n = hap->link->a.a[x].e.n;
a = hap->link->a.a[x].e.a;
for (i = 0; i < a_n; i++)
{
if(a[i].del) continue;
if(is_hap_set_label(a[i].uID, *hap, *max_hap_label))
{
current_weight += a[i].weight;
}
}
}
if(current_weight > max_weight) /// the weight of each bubble
{
max_weight = current_weight;
max_i = k;
half_w = 0;
}
tot_w += current_weight;
half_w += current_weight;
}
(*max_bid_idx) = max_i;
if(is_forward_first)
{
if(half_w >= (tot_w - half_w))
{
(*is_forward_first) = 1;
}
else
{
(*is_forward_first) = 0;
}
}
}
return;
}
void phase_bubble_chain_dir(H_partition* hap, ma_ug_t *ug, bub_p_t_warp* b, bubble_type* bub,
ma_utg_t *u, uint8_t* hap_label_flag, uint32_t beg_idx, uint32_t end_idx, uint32_t is_forward)
{
uint32_t i, j, beg, sink, *a, n, max_hap_label, max_uid;
uint64_t bid;
double cur_w0, cur_w1;
for (i = beg_idx; i <= end_idx; i++)
{
bid = is_forward? u->a[i]>>33:u->a[u->n-i-1]>>33;
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
if(bub->b_g->seq[bid].c != HAP_LABLE/** && bid < bub->s_bub**/) ///simple bubble
{
for (j = 0; j < n; j++) ///avoiding repeat phasing
{
if(is_hap_set(a[j]>>1, *hap)) break;
}
if(j < n) goto complete;
///get current max_hap_label from current chain
get_weightest_hap_label_from_bubble(bid, hap, bub, hap_label_flag, &max_hap_label, NULL);
///three levels:
///1. has setted weight with same hap label (using current max_hap_label)
///2. has setted weight but with different hap labels (using max max_hap_label from current weight)
///3. has unsetted weight (add hap->hap_label)
///4. skip, do nothing
if(max_hap_label == (uint32_t)-1 &&
get_weightest_hap_label_from_bubble(bid, hap, bub, NULL, &max_hap_label, NULL) == 0)
{
goto complete;
}
///phase bubble
b->exist_hap_label = (uint32_t)-1;
get_phase_path(ug, beg, sink, b, hap, max_hap_label);
get_phase_path(ug, beg, sink, b, hap, max_hap_label);
for (j = 0; j < n; j++) ///set bubble as visited
{
hap_label_flag[a[j]>>1] = 1;
}
}
else
{
///select unitig with highest related weight at one time
while (1)
{
max_uid = get_weightest_uid(a, n, hap, hap_label_flag, &max_hap_label);
if(max_uid == (uint32_t)-1) break;
get_related_weight(max_uid, hap, &cur_w0, &cur_w1, &max_hap_label);
if(cur_w0 >= cur_w1)
{
hap->hap[max_uid] |= (max_hap_label | hap->m[0]);
}
else
{
hap->hap[max_uid] |= (max_hap_label | hap->m[1]);
}
hap_label_flag[max_uid] = 1;
}
}
complete:;
}
}
///ignore unitigs wihci have already been labeled in current chain (might happen)
void phase_bubble_chain(H_partition* hap, ma_ug_t *ug, bub_p_t_warp* b, bubble_type* bub,
uint8_t* hap_label_flag, uint32_t chain_id)
{
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
if(u->n == 0) return;
uint32_t is_forward = 1, i, max_hap_label, max_bid_idx;
memset(hap_label_flag, 0, ug->g->n_seq);
get_weightest_hap_label_from_chain(u, hap, bub, &max_hap_label, &max_bid_idx, &is_forward);
if(max_hap_label != (uint32_t)-1) ///means this is not a new chain
{
for (i = 0; i < hap->n; i++)
{
if(is_hap_set_label(i, *hap, max_hap_label)) hap_label_flag[i] = 1;
}
}
if(max_hap_label == (uint32_t)-1) ///a totally new chain
{
phase_bubble_chain_dir(hap, ug, b, bub, u, hap_label_flag, 0, u->n - 1, 1);
}
else
{
if(max_bid_idx == 0)
{
phase_bubble_chain_dir(hap, ug, b, bub, u, hap_label_flag, 0, u->n - 1, 1);
}
else
{
if(is_forward)
{
phase_bubble_chain_dir(hap, ug, b, bub, u, hap_label_flag, max_bid_idx, u->n - 1, 1);
phase_bubble_chain_dir(hap, ug, b, bub, u, hap_label_flag, 0, max_bid_idx-1, 0);
}
else
{
phase_bubble_chain_dir(hap, ug, b, bub, u, hap_label_flag, 0, max_bid_idx-1, 0);
phase_bubble_chain_dir(hap, ug, b, bub, u, hap_label_flag, max_bid_idx, u->n - 1, 1);
}
}
}
}
uint32_t if_flip(H_partition* h, G_partition* g_p, hc_links* link,
bubble_type* bub, uint32_t gid)
{
double weight = 0;
if(h->lock[gid]) return 0;
if(g_p->a[gid].h[0] > 0 && (g_p->a[gid].status[0] == 1 || g_p->a[gid].status[0] == -1))
{
weight += (g_p->a[gid].weight[0] * g_p->a[gid].status[0]);
}
if(g_p->a[gid].h[1] > 0 && (g_p->a[gid].status[1] == 1 || g_p->a[gid].status[1] == -1))
{
weight += (g_p->a[gid].weight[1] * g_p->a[gid].status[1]);
}
weight += g_p->a[gid].weight_convex*2;
if(weight >= 0) return 0;
return 1;
}
void flip_unitig(G_partition* g_p, hc_links* link, bubble_type* bub, uint32_t id);
uint32_t phasing_improvement(H_partition* h, G_partition* g_p, ha_ug_index* idx, bubble_type* bub, hc_links* link);
uint32_t get_max_unitig(H_partition* h, G_partition* g_p, hc_links* link, bubble_type* bub);
double get_cluster_weight_debug(G_partition* g_p, hc_links* link, uint32_t *h, uint32_t h_n);
void debug_flip(G_partition* g_p, hc_links* link, bubble_type* bub, uint32_t id)
{
fprintf(stderr, "33333333333\n");
uint32_t *h0, h0_n, *h1, h1_n, k, wrong;
double hw0, hw1;
for (k = wrong = 0; k < g_p->n; k++)
{
hw0 = hw1 = 0;
get_phased_block(g_p, NULL, k, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
if(h0_n >0) hw0 = get_cluster_weight_debug(g_p, link, h0, h0_n);
if(h1_n >0) hw1 = get_cluster_weight_debug(g_p, link, h1, h1_n);
if(hw0 != g_p->a[k].weight[0])
{
if((uint32_t)hw0 != (uint32_t)g_p->a[k].weight[0]) wrong = 1;
fprintf(stderr, "k: %u, ERROR(id: %u): hw0: %f, weight[0]: %f\n", k, id, hw0, g_p->a[k].weight[0]);
}
if(hw1 != g_p->a[k].weight[1])
{
if((uint32_t)hw1 != (uint32_t)g_p->a[k].weight[1]) wrong = 1;
fprintf(stderr, "k: %u, ERROR(id: %u): hw1: %f, weight[1]: %f\n", k, id, hw1, g_p->a[k].weight[1]);
}
if(wrong) break;
}
}
void merge_phase_group_by_chain(H_partition* hap, G_partition* g_p, bubble_type* bub, uint32_t chain_id)
{
uint32_t i, k;
uint32_t beg, sink, *a, n, pre_id, hap_label_id;
uint64_t bid, uid;
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
for (i = 0, pre_id = (uint32_t)-1; i < u->n; i++)
{
// fprintf(stderr, "inner i: %u, u->n: %u\n", i, (uint32_t)u->n);
bid = u->a[i]>>33; ///here is a bubble
// fprintf(stderr, "bid: %lu\n", bid);
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
// fprintf(stderr, "k: %u, n: %u\n", k, n);
uid = a[k]>>1;
// fprintf(stderr, "uid: %lu\n", uid);
if(g_p->index[uid] == (uint32_t)-1) ///mean this unitig doesn't have hap label
{
pre_id = (uint32_t)-1;
continue;
}
hap_label_id = g_p->index[uid]>>1;
// fprintf(stderr, "hap_label_id: %u, hap->n: %lu\n", hap_label_id, hap->n);
if(hap_label_id == pre_id) continue;
pre_id = hap_label_id;
if(hap->lock[hap_label_id] == 1) continue;
if(if_flip(hap, g_p, hap->link, bub, hap_label_id))
{
// fprintf(stderr, "2222222222\n");
flip_unitig(g_p, hap->link, bub, hap_label_id);
///debug_flip(g_p, hap->link, bub, hap_label_id);
}
}
}
}
void print_phase_group(G_partition* g_p, bubble_type* bub, const char* command)
{
uint32_t i, k;
partition_warp *res = NULL;
for (i = 0; i < g_p->n; i++)
{
res = &(g_p->a[i]);
fprintf(stderr, "\n%s: %u-th group: # %d = %u (weight: %f), # %d = %u (weight: %f), inner_weight: %f\n", command, i,
res->status[0], res->h[0], res->weight[0], res->status[1], res->h[1], res->weight[1], res->weight_convex);
for (k = 0; k < res->h[0]; k++)
{
fprintf(stderr, "%d: utg%.6ul\n", res->status[0], int(res->a.a[k]+1));
}
for (; k < res->a.n; k++)
{
fprintf(stderr, "%d: utg%.6ul\n", res->status[1], int(res->a.a[k]+1));
}
}
}
void set_bubble(H_partition* hap, G_partition* g_p, bubble_type* bub, block_phase_type* block,
uint64_t bid)
{
uint32_t beg, sink, k, uid, *a, n, gid;
block->weight = 0;
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
if(g_p->index[uid] == (uint32_t)-1) continue;
gid = g_p->index[uid]>>1;
block->vis.a[gid] = 1;
}
}
uint32_t next_hap_label_id(block_phase_type* b, G_partition* g_p, bubble_type* bub, ma_utg_t *u,
int is_forward, long long* c_bid, long long* c_uid)
{
uint32_t beg, sink, uid, *a, n, gid, pre_gid;
while (1) ///while(b->bid < (long long)u->n)
{
if(is_forward == 1 && b->bid >= (long long)u->n) break;
if(is_forward == 0 && b->bid < 0) break;
get_bubbles(bub, u->a[b->bid]>>33, &beg, &sink, &a, &n, NULL);
while (1) ///while (b->uid < (long long)n)
{
if(is_forward == 1 && b->uid >= (long long)n) break;
if(is_forward == 0 && b->uid < 0) break;
uid = a[b->uid]>>1;
gid = (uint32_t)-1;
if(g_p->index[uid] != (uint32_t)-1)
{
gid = g_p->index[uid]>>1;
}
if(c_bid) (*c_bid) = b->bid;
if(c_uid) (*c_uid) = b->uid;
if(is_forward == 1) b->uid++;
if(is_forward == 0) b->uid--;
if(gid == (uint32_t)-1) continue;
pre_gid = uid = (uint32_t)-1;
if(is_forward == 1 && (b->uid >= 2)) uid = a[b->uid - 2]>>1;
if(is_forward == 0 && (b->uid + 2 < n)) uid = a[b->uid + 2]>>1;
if(uid != (uint32_t)-1 && g_p->index[uid] != (uint32_t)-1) pre_gid = g_p->index[uid]>>1;
if(pre_gid == gid) continue;
return gid;
}
if(is_forward == 1) b->bid++, b->uid = 0;
if(is_forward == 0) b->bid--, b->uid = (long long)n - (long long)1;
}
return (uint32_t)-1;
}
double get_new_weight(G_partition* g_p, uint8_t* flag, hc_links* link, uint32_t gid)
{
double total_weight = 0, weight;
int status, o_d;
uint32_t *h0, h0_n, *h1, h1_n, *h, h_n, j, k, uID;
if(g_p->a[gid].h[0] > 0 && (g_p->a[gid].status[0] == 1 || g_p->a[gid].status[0] == -1))
{
total_weight += (g_p->a[gid].weight[0] * g_p->a[gid].status[0]);
}
if(g_p->a[gid].h[1] > 0 && (g_p->a[gid].status[1] == 1 || g_p->a[gid].status[1] == -1))
{
total_weight += (g_p->a[gid].weight[1] * g_p->a[gid].status[1]);
}
total_weight += g_p->a[gid].weight_convex*2;
get_phased_block(g_p, NULL, gid, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
h = h0; h_n = h0_n; status = g_p->a[gid].status[0];
for (j = 0, weight = 0; j < h_n; j++)
{
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
if(link->a.a[h[j]].e.a[k].del) continue;
uID = link->a.a[h[j]].e.a[k].uID;
if(g_p->index[uID] == (uint32_t)-1) continue;
if(flag[g_p->index[uID]>>1] == 0) continue;
if((g_p->index[uID]>>1) == gid) continue;
o_d = g_p->a[g_p->index[uID]>>1].status[g_p->index[uID]&1];
weight += (status*o_d*link->a.a[h[j]].e.a[k].weight);
}
}
total_weight -= (2*weight);
h = h1; h_n = h1_n; status = g_p->a[gid].status[1];
for (j = 0, weight = 0; j < h_n; j++)
{
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
if(link->a.a[h[j]].e.a[k].del) continue;
uID = link->a.a[h[j]].e.a[k].uID;
if(g_p->index[uID] == (uint32_t)-1) continue;
if(flag[g_p->index[uID]>>1] == 0) continue;
if((g_p->index[uID]>>1) == gid) continue;
o_d = g_p->a[g_p->index[uID]>>1].status[g_p->index[uID]&1];
weight += (status*o_d*link->a.a[h[j]].e.a[k].weight);
}
}
total_weight -= (2*weight);
return total_weight;
}
int identify_best_interval(block_phase_type* i_buf, uint8_t* lock, G_partition* g_p, bubble_type* bub,
ma_utg_t *u, hc_links* link, long long f_bid, long long f_uid, long long* l_bid, long long* l_uid)
{
long long c_bid, c_uid, min_bid, min_uid;
double w = 0, min_w = 1;
uint32_t gid, val = 0;
block_phase_type b;
b.bid = f_bid; b.uid = f_uid;
memset(i_buf->vis.a, 0, g_p->n);
i_buf->weight = min_w = 1; min_bid = min_uid = -1;
(*l_bid) = (*l_uid) = -1;
while (1)
{
gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
if(i_buf->vis.a[gid] == 1) continue;
w += get_new_weight(g_p, i_buf->vis.a, link, gid);
i_buf->vis.a[gid] = 1;
if(lock[gid] == 0) val = 1;
if(val == 0) continue;
if(min_w > w)
{
min_w = w;
min_bid = c_bid;
min_uid = c_uid;
}
}
if(min_w < 0 && min_bid != -1 && min_uid != -1)
{
(*l_bid) = min_bid; (*l_uid) = min_uid;
i_buf->weight = min_w;
///fprintf(stderr, "+min_w: %f, min_bid: %lld, min_uid: %lld\n", min_w, min_bid, min_uid);
}
if(val == 0) return 1;
return 0;
}
void identify_best_interval_debug(block_phase_type* i_buf, G_partition* g_p, bubble_type* bub,
ma_utg_t *u, hc_links* link, long long f_bid, long long f_uid, long long* l_bid, long long* l_uid)
{
long long c_bid, c_uid, min_bid, min_uid;
double w = 0, min_w = 1;
uint32_t gid;
block_phase_type b;
b.bid = f_bid; b.uid = f_uid;
memset(i_buf->vis.a, 0, g_p->n);
min_w = 1; min_bid = min_uid = -1;
(*l_bid) = (*l_uid) = -1;
while (1)
{
gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
if(i_buf->vis.a[gid] == 1) continue;
w += get_new_weight(g_p, i_buf->vis.a, link, gid);
if(f_bid == 689 && f_uid == 1)
{
fprintf(stderr, "gid: %u, w: %f\n", gid, w);
}
if(min_w > w)
{
min_w = w;
min_bid = c_bid;
min_uid = c_uid;
}
i_buf->vis.a[gid] = 1;
}
if(min_w < 0 && min_bid != -1 && min_uid != -1)
{
(*l_bid) = min_bid; (*l_uid) = min_uid;
i_buf->weight = min_w;
b.bid = min_bid; b.uid = min_uid;
gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
fprintf(stderr, "-min_w: %f, f_bid: %lld, f_uid: %lld, min_bid: %lld, min_uid: %lld, gid: %u\n",
min_w, f_bid, f_uid, min_bid, min_uid, gid);
}
}
int flip_block(block_phase_type* i_buf, G_partition* g_p, bubble_type* bub,
ma_utg_t *u, hc_links* link, uint8_t* lock, long long f_bid, long long f_uid, long long l_bid, long long l_uid)
{
long long c_bid = l_bid, c_uid = l_uid;
uint32_t gid, val = 0;
block_phase_type b;
b.bid = f_bid; b.uid = f_uid;
memset(i_buf->vis.a, 0, g_p->n);
val = 0;
while (1)
{
gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
////fprintf(stderr, "+gid: %u\n", gid);
if(gid == (uint32_t)-1) break;
///fprintf(stderr, "lock[gid]: %u\n", lock[gid]);
if(lock[gid] == 0)
{
val = 1;
break;
}
if(c_bid == l_bid && c_uid == l_uid) break;
}
if(val == 0) return 0;
b.bid = f_bid; b.uid = f_uid;
while (1)
{
gid = next_hap_label_id(&b, g_p, bub, u, 1, &c_bid, &c_uid);
///fprintf(stderr, "-gid: %u\n", gid);
if(gid == (uint32_t)-1) break;
///fprintf(stderr, "vis[gid]: %u\n", i_buf->vis.a[gid]);
if(i_buf->vis.a[gid] == 1) continue;
lock[gid] = 1;
i_buf->vis.a[gid] = 1;
// if(f_bid == 689 && f_uid == 1)
// {
// fprintf(stderr, "sssssssssssssssssssss\n");
// print_phase_group(g_p, bub, "Small-1");
// fprintf(stderr, "sbsbsbsb-gid: %u\n", gid);
// }
flip_unitig(g_p, link, bub, gid);
///flip_unitig_debug(g_p, link, bub, gid);
// if(f_bid == 689 && f_uid == 1)
// {
// fprintf(stderr, "sasasasa-gid: %u\n", gid);
// print_phase_group(g_p, bub, "Small-2");
// fprintf(stderr, "eeeeeeeeeeeeeeeeeeeeee\n");
// }
if(c_bid == l_bid && c_uid == l_uid) break;
}
return 1;
}
double get_total_weight(H_partition* h, G_partition* g_p)
{
uint32_t i, k, uID;
hc_links* link = h->link;
int o_d = 0, o_f = 0;
double w, t_w;
for (i = 0, t_w = 0; i < h->n; i++)
{
if(g_p->index[i] == (uint32_t)-1) continue;
o_f = g_p->a[g_p->index[i]>>1].status[g_p->index[i]&1];
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
uID = link->a.a[i].e.a[k].uID;
w = link->a.a[i].e.a[k].weight;
if(g_p->index[uID] == (uint32_t)-1) continue;
o_d = g_p->a[g_p->index[uID]>>1].status[g_p->index[uID]&1];
t_w += (o_f*o_d*w);
}
}
return t_w;
}
void hap_label_fliping(H_partition* hap, G_partition* g_p, bubble_type* bub, hc_links* link, uint32_t chain_id)
{
long long c_bid, c_uid, l_bid, l_uid;
uint32_t gid;
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
hap->b.bid = hap->b.uid = 0;
while (1)
{
gid = next_hap_label_id(&(hap->b), g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
identify_best_interval(&(hap->b), hap->lock, g_p, bub, u, link, c_bid, c_uid, &l_bid, &l_uid);
if(l_bid == -1 || l_uid == -1) continue;
// fprintf(stderr, "\nbefore weight: %f\n", get_total_weight(hap, g_p));
// identify_best_interval_debug(&(hap->b), g_p, bub, u, link, c_bid, c_uid, &l_bid, &l_uid);
if(flip_block(&(hap->b), g_p, bub, u, link, hap->lock, c_bid, c_uid, l_bid, l_uid))
{
///fprintf(stderr, "after weight +: %f\n", get_total_weight(hap, g_p));
hap->b.bid = l_bid;
hap->b.uid = l_uid;
gid = next_hap_label_id(&(hap->b), g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
}
///fprintf(stderr, "after weight -: %f\n", get_total_weight(hap, g_p));
// exit(0);
}
}
typedef struct{
long long min_chain_id;
long long min_f_bid;
long long min_f_uid;
long long min_l_bid;
long long min_l_uid;
long long min_idx;
double min_w;
}block_res_type;
typedef struct{
block_phase_type* x;
uint32_t n_thread;
bubble_type* bub;
uint64_t* chain_idx;///index of each chain
uint64_t chain_idx_n;
uint64_t chain_ele_occ;
block_res_type* res;
H_partition* h;
G_partition* g_p;
}mul_block_phase_type;
uint32_t shift_block_phase_type(ma_utg_t *u, G_partition* g_p, bubble_type* bub,
block_phase_type* b, uint32_t offset)
{
long long c_bid, c_uid;
uint32_t gid, occ = 0;
b->bid = b->uid = 0;
while (1)
{
if(occ == offset) break;
gid = next_hap_label_id(b, g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
occ++;
}
return occ;
}
void get_block_phase_type(uint64_t* chain_idx, G_partition* g_p, bubble_type* bub, uint32_t id, block_phase_type* i_b)
{
uint64_t i;
ma_utg_t *u = NULL;
for (i = 0; i < bub->chain_weight.n; i++)
{
if(id >= chain_idx[i] && id < chain_idx[i+1]) break;
}
u = &(bub->b_ug->u.a[bub->chain_weight.a[i].id]);
shift_block_phase_type(u, g_p, bub, i_b, id - chain_idx[i]);
i_b->chainID = bub->chain_weight.a[i].id;
}
void init_mul_block_phase_type(mul_block_phase_type* x, G_partition* g_p, bubble_type* bub, uint32_t n_thread, H_partition* hap)
{
ma_utg_t *u = NULL;
uint32_t i, n;
block_phase_type b;
x->bub = bub;
x->n_thread = n_thread;
CALLOC(x->res, x->n_thread);
CALLOC(x->x, x->n_thread);
for (i = 0; i < x->n_thread; i++)
{
kv_init(x->x[i].vis);
kv_malloc(x->x[i].vis, hap->n);
x->x[i].vis.n = hap->n;
}
x->chain_idx_n = 0;
MALLOC(x->chain_idx, bub->chain_weight.n+1);
for (i = n = 0; i < bub->chain_weight.n; i++)
{
x->chain_idx[i] = n;
if(bub->chain_weight.a[i].del) continue;
u = &(bub->b_ug->u.a[bub->chain_weight.a[i].id]);
n += shift_block_phase_type(u, g_p, bub, &b, (uint32_t)-1);
x->chain_idx_n++;
}
x->chain_idx[i] = n;///index of chain
x->chain_ele_occ = n;
}
void destory_mul_block_phase_type(mul_block_phase_type* x)
{
uint32_t i;
free(x->res);
free(x->chain_idx);
for (i = 0; i < x->n_thread; i++)
{
kv_destroy(x->x[i].vis);
}
}
void select_max_block_by_utg_multi_thread(H_partition* h, G_partition* g_p, bubble_type* bub,
hc_links* link, block_phase_type* i_b, uint64_t* chain_idx, uint32_t id, block_res_type* res)
{
long long c_bid, c_uid, l_bid, l_uid;
uint32_t gid;
get_block_phase_type(chain_idx, g_p, bub, id, i_b);
ma_utg_t *u = &(bub->b_ug->u.a[i_b->chainID]);
gid = next_hap_label_id(i_b, g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) return;
if(identify_best_interval(i_b, h->lock, g_p, bub, u, link, c_bid, c_uid, &l_bid, &l_uid)) return;
if(l_bid == -1 || l_uid == -1) return;
if((res->min_w > i_b->weight) || (res->min_w == i_b->weight && id < res->min_idx))
{
res->min_w = i_b->weight;
res->min_f_bid = c_bid;
res->min_f_uid = c_uid;
res->min_l_bid = l_bid;
res->min_l_uid = l_uid;
res->min_chain_id = i_b->chainID;
res->min_idx = id;
}
}
static void worker_for_max_block(void *data, long i, int tid) // callback for kt_for()
{
mul_block_phase_type* x = (mul_block_phase_type*)data;
select_max_block_by_utg_multi_thread(x->h, x->g_p, x->bub, x->h->link,
&(x->x[tid]), x->chain_idx, i, &(x->res[tid]));
}
void select_max_block_by_utg_multi_thread_by_chain(H_partition* h, G_partition* g_p, bubble_type* bub,
hc_links* link, block_phase_type* i_b, uint32_t id, block_res_type* res)
{
long long c_bid, c_uid, l_bid, l_uid;
uint32_t gid;
ma_utg_t *u = &(bub->b_ug->u.a[id]);
i_b->bid = i_b->uid = 0; i_b->chainID = id;
while (1)
{
gid = next_hap_label_id(i_b, g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
if(identify_best_interval(i_b, h->lock, g_p, bub, u, link, c_bid, c_uid, &l_bid, &l_uid))
{
break;
}
if(l_bid == -1 || l_uid == -1) continue;
if(res->min_w > i_b->weight)
{
res->min_w = i_b->weight;
res->min_f_bid = c_bid;
res->min_f_uid = c_uid;
res->min_l_bid = l_bid;
res->min_l_uid = l_uid;
res->min_chain_id = i_b->chainID;
res->min_idx = id;
}
}
}
int get_max_block_multi_thread(H_partition* h, G_partition* g_p, bubble_type* bub, mul_block_phase_type* x,
long long* min_u, long long* min_f_bid, long long* min_f_uid, long long* min_l_bid, long long* min_l_uid,
double* min_w)
{
uint32_t i;
(*min_w) = 1;
(*min_u) = (*min_f_bid) = (*min_f_uid) = (*min_l_bid) = (*min_l_uid) = -1;
for (i = 0; i < x->n_thread; i++)
{
x->res[i].min_chain_id = x->res[i].min_f_bid = x->res[i].min_f_uid = -1;
x->res[i].min_l_bid = x->res[i].min_l_uid = x->res[i].min_idx = -1;
x->res[i].min_w = 1;
}
x->g_p = g_p;
x->h = h;
kt_for(x->n_thread, worker_for_max_block, x, x->chain_ele_occ);
///kt_for(x->n_thread, worker_for_max_block_by_chain, x, x->chain_idx_n);
long long min_idx = -1;
for (i = 0; i < x->n_thread; i++)
{
if(x->res[i].min_chain_id == -1) continue;
if(x->res[i].min_f_bid == -1 || x->res[i].min_f_uid == -1) continue;
if(x->res[i].min_l_bid == -1 || x->res[i].min_l_uid == -1) continue;
if(((*min_w) > x->res[i].min_w) || ((*min_w) == x->res[i].min_w && x->res[i].min_idx < min_idx))
{
(*min_w) = x->res[i].min_w;
(*min_u) = x->res[i].min_chain_id;
(*min_f_bid) = x->res[i].min_f_bid;
(*min_f_uid) = x->res[i].min_f_uid;
(*min_l_bid) = x->res[i].min_l_bid;
(*min_l_uid) = x->res[i].min_l_uid;
min_idx = x->res[i].min_idx;
}
}
if((*min_u) != -1 && (*min_f_bid) != -1 && (*min_f_uid) != -1 && (*min_l_bid) != -1 && (*min_l_uid) != -1)
{
return 1;
}
return 0;
}
void select_max_block_by_utg(H_partition* hap, G_partition* g_p, bubble_type* bub, hc_links* link, uint32_t chain_id,
long long* min_f_bid, long long* min_f_uid, long long* min_l_bid, long long* min_l_uid, double* min_w)
{
long long c_bid, c_uid, l_bid, l_uid;
uint32_t gid;
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
(*min_w) = 1;
hap->b.bid = hap->b.uid = 0;
(*min_f_bid) = (*min_f_uid) = (*min_l_bid) = (*min_l_uid) = -1;
while (1)
{
gid = next_hap_label_id(&(hap->b), g_p, bub, u, 1, &c_bid, &c_uid);
if(gid == (uint32_t)-1) break;
if(identify_best_interval(&(hap->b), hap->lock, g_p, bub, u, link, c_bid, c_uid, &l_bid, &l_uid))
{
break;
}
if(l_bid == -1 || l_uid == -1) continue;
if((*min_w) > hap->b.weight)
{
(*min_w) = hap->b.weight;
(*min_f_bid) = c_bid;
(*min_f_uid) = c_uid;
(*min_l_bid) = l_bid;
(*min_l_uid) = l_uid;
}
}
}
int get_max_block(H_partition* h, G_partition* g_p, bubble_type* bub, long long* min_u,
long long* min_f_bid, long long* min_f_uid, long long* min_l_bid, long long* min_l_uid,
double* min_w)
{
uint32_t i;
long long f_bid, f_uid, l_bid, l_uid;
double w;
(*min_w) = 1;
(*min_u) = (*min_f_bid) = (*min_f_uid) = (*min_l_bid) = (*min_l_uid) = -1;
for (i = 0; i < bub->chain_weight.n; i++)
{
if(bub->chain_weight.a[i].del) continue;
select_max_block_by_utg(h, g_p, bub, h->link, bub->chain_weight.a[i].id,
&f_bid, &f_uid, &l_bid, &l_uid, &w);
if(f_bid == -1 || f_uid == -1 || l_bid == -1 || l_uid == -1) continue;
if((*min_w) > w)
{
(*min_w) = w;
(*min_u) = bub->chain_weight.a[i].id;
(*min_f_bid) = f_bid;
(*min_f_uid) = f_uid;
(*min_l_bid) = l_bid;
(*min_l_uid) = l_uid;
}
}
if((*min_u) != -1 && (*min_f_bid) != -1 && (*min_f_uid) != -1 && (*min_l_bid) != -1 && (*min_l_uid) != -1)
{
return 1;
}
return 0;
}
void phasing_improvement_by_block(H_partition* h, G_partition* g_p, bubble_type* bub, mul_block_phase_type* x)
{
long long min_u, min_f_bid, min_f_uid, min_l_bid, min_l_uid;
double min_w;
memset(h->lock, 0, sizeof(uint8_t)*h->n);
while(get_max_block_multi_thread(h, g_p, bub, x, &min_u, &min_f_bid, &min_f_uid, &min_l_bid, &min_l_uid, &min_w))
///while(get_max_block(h, g_p, bub, &min_u, &min_f_bid, &min_f_uid, &min_l_bid, &min_l_uid, &min_w))
{
///fprintf(stderr, "\nmin_w: %f, min_u: %lld, min_f_bid: %lld, min_f_uid: %lld, min_l_bid: %lld, min_l_uid: %lld\n", min_w, min_u, min_f_bid, min_f_uid, min_l_bid, min_l_uid);
///fprintf(stderr, "before weight: %f\n", get_total_weight(h, g_p));
flip_block(&(h->b), g_p, bub, &(bub->b_ug->u.a[min_u]), h->link, h->lock, min_f_bid,
min_f_uid, min_l_bid, min_l_uid);
///fprintf(stderr, "after weight: %f\n", get_total_weight(h, g_p));
}
}
void flip_by_chain(H_partition* h, G_partition* g_p, bubble_type* bub)
{
uint32_t i;
memset(h->lock, 0, sizeof(uint8_t)*h->n);
for (i = 0; i < bub->chain_weight.n; i++)
{
if(bub->chain_weight.a[i].del) continue;
merge_phase_group_by_chain(h, g_p, bub, bub->chain_weight.a[i].id);
}
double pre_w = get_total_weight(h, g_p), current_w;
uint32_t round = 0;
while (1)
{
memset(h->lock, 0, sizeof(uint8_t)*h->n);
while (1)
{
i = get_max_unitig(h, g_p, h->link, bub);
if(i == (uint32_t)-1) break;
h->lock[i] = 1;
flip_unitig(g_p, h->link, bub, i);
}
current_w = get_total_weight(h, g_p);
///fprintf(stderr, "[M::%s::round %u, pre_w: %f, current_w: %f]\n", __func__, round, pre_w, current_w);
if(ceil(current_w) <= ceil(pre_w)) break;
round++;
pre_w = current_w;
}
///print_phase_group(g_p, bub, "Large-pre");
///fprintf(stderr, "[M::%s::round %u, before block flipping: %f]\n", __func__, round, get_total_weight(h, g_p));
mul_block_phase_type b_x;
init_mul_block_phase_type(&b_x, g_p, bub, asm_opt.thread_num, h);
pre_w = get_total_weight(h, g_p);
while (1)
{
phasing_improvement_by_block(h, g_p, bub, &b_x);
current_w = get_total_weight(h, g_p);
///fprintf(stderr, "[M::%s::round %u, after block flipping: %f]\n", __func__, round, get_total_weight(h, g_p));
///debug_flip(g_p, h->link, bub, 0);
if(ceil(current_w) <= ceil(pre_w)) break;
round++;
pre_w = current_w;
}
destory_mul_block_phase_type(&b_x);
for (i = 0; i < g_p->n; i++)
{
update_partition_flag(h, g_p, h->link, i);
}
}
void flip_by_node(H_partition* h, G_partition* g_p, bubble_type* bub)
{
uint32_t i;
memset(h->lock, 0, sizeof(uint8_t)*h->n);
double pre_w = get_total_weight(h, g_p), current_w;
uint32_t round = 0;
while (1)
{
memset(h->lock, 0, sizeof(uint8_t)*h->n);
while (1)
{
i = get_max_unitig(h, g_p, h->link, bub);
if(i == (uint32_t)-1) break;
h->lock[i] = 1;
flip_unitig(g_p, h->link, bub, i);
}
current_w = get_total_weight(h, g_p);
///fprintf(stderr, "[M::%s::round %u, pre_w: %f, current_w: %f]\n", __func__, round, pre_w, current_w);
if(ceil(current_w) <= ceil(pre_w)) break;
round++;
pre_w = current_w;
}
///fprintf(stderr, "[M::%s::round %u, before block flipping: %f]\n", __func__, round, get_total_weight(h, g_p));
for (i = 0; i < g_p->n; i++)
{
update_partition_flag(h, g_p, h->link, i);
}
}
void link_phase_group(H_partition* hap, bubble_type* bub)
{
double index_time = yak_realtime();
uint32_t i, k, n = (hap->label>>hap->label_shift)+1, *h0, h0_n, *h1, h1_n;;
init_G_partition(&(hap->group_g_p), hap->n);
partition_warp *res = NULL;
for (i = 0; i < n; i++)///how many haplotype group
{
kv_pushp(partition_warp, hap->group_g_p, &res);
kv_init(res->a);
res->full_bub = 0;
res->h[0] = res->h[1] = 0;
res->status[0] = 1; res->status[1] = -1;
res->weight[0] = res->weight[1] = res->weight_convex = 0;
///all unitigs
for (k = 0; k < hap->n; k++)
{
if(get_phase_group(hap, k) == i && get_phase_status(hap, k) == 1)
{
kv_push(uint32_t, res->a, k);
res->h[0]++;
}
}
for (k = 0; k < hap->n; k++)
{
if(get_phase_group(hap, k) == i && get_phase_status(hap, k) == -1)
{
kv_push(uint32_t, res->a, k);
res->h[1]++;
}
}
for (k = 0; k < res->h[0]; k++)
{
///if(hap->group_g_p.index[res->a.a[k]] != (uint32_t)-1) fprintf(stderr, "ERROR---00\n");
hap->group_g_p.index[res->a.a[k]] = hap->group_g_p.n-1;
hap->group_g_p.index[res->a.a[k]] = hap->group_g_p.index[res->a.a[k]] << 1;
}
for (; k < res->a.n; k++)
{
///if(hap->group_g_p.index[res->a.a[k]] != (uint32_t)-1) fprintf(stderr, "ERROR---11\n");
hap->group_g_p.index[res->a.a[k]] = hap->group_g_p.n-1;
hap->group_g_p.index[res->a.a[k]] = (hap->group_g_p.index[res->a.a[k]] << 1) + 1;
}
get_phased_block(&(hap->group_g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
if(h0_n >0) res->weight[0] = get_cluster_weight(hap, hap->link, h0, h0_n);
if(h1_n >0) res->weight[1] = get_cluster_weight(hap, hap->link, h1, h1_n);
res->weight_convex = get_cluster_inner_weight(hap, hap->link, h0, h0_n, h1, h1_n);
}
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
// for (i = 0; i < n; i++)
// {
// double w0 = 0, w1 = 0;
// res = &(hap->group_g_p.a[i]);
// fprintf(stderr, "%u-th group: # %d = %u, # %d = %u\n", i,
// res->status[0], res->h[0], res->status[1], res->h[1]);
// get_phased_block(&(hap->group_g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
// if(h0_n >0) w0 = get_cluster_weight_debug(&(hap->group_g_p), hap->link, h0, h0_n);
// if(h1_n >0) w1 = get_cluster_weight_debug(&(hap->group_g_p), hap->link, h1, h1_n);
// if(w0 != res->weight[0]) fprintf(stderr, "i: %u, ERROR: w0: %f, weight[0]: %f\n", i, w0, res->weight[0]);
// if(w1 != res->weight[1]) fprintf(stderr, "i: %u, ERROR: w1: %f, weight[1]: %f\n", i, w1, res->weight[1]);
// for (k = 0; k < res->h[0]; k++)
// {
// fprintf(stderr, "%d: utg%.6ul\n", res->status[0], int(res->a.a[k]+1));
// }
// for (; k < res->a.n; k++)
// {
// fprintf(stderr, "%d: utg%.6ul\n", res->status[1], int(res->a.a[k]+1));
// }
// }
/*******************************for debug************************************/
// for (i = 0; i < hap->n; i++)
// {
// if(hap->link->a.a[i].e.n == 0) continue;
// if(get_phase_status(hap, i) == -2)
// {
// fprintf(stderr, "ERROR+++: i: %u, group: %u, bub->index: %u\n", i, get_phase_group(hap, i), bub->index[i]);
// for (k = 0; k < hap->link->a.a[i].e.n; k++)
// {
// fprintf(stderr, "k: %u, uID: %u, weight: %f, del: %u\n", k, hap->link->a.a[i].e.a[k].uID,
// hap->link->a.a[i].e.a[k].weight, hap->link->a.a[i].e.a[k].del);
// }
// }
// }
/*******************************for debug************************************/
flip_by_chain(hap, &(hap->group_g_p), bub);
///print_phase_group(&(hap->group_g_p), bub, "Large");
}
void print_chain_phasing(H_partition* hap, ma_ug_t *ug, bubble_type* bub, uint32_t chain_id)
{
uint32_t i, k;
uint32_t beg, sink, *a, n;
uint64_t bid, uid;
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
fprintf(stderr, "\n**********chain_id: %u**********\n", chain_id);
for (i = 0; i < u->n; i++)
{
bid = u->a[i]>>33;
fprintf(stderr, "(%u) chain_id: %u, u->n: %u, bid: %u\n", i, chain_id, (uint32_t)u->n, i);
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
fprintf(stderr, "utg%.6ul, hap: %u, group: %u, stats: %d\n", (int)(uid+1), hap->hap[uid],
get_phase_group(hap, uid), get_phase_status(hap, uid));
}
}
}
int graph_bipartiteness(uint32_t* b_a, uint32_t b_a_n, uint8_t *color, hc_links* link, kvec_t_u32_warp* stack)
{
if(b_a_n == 0) return 0;
uint32_t i, uID, cur, occ = 0, sucess = 0, c;
for (i = 0; i < b_a_n; i++) color[b_a[i]>>1] = 8;
stack->a.n = 0;
kv_push(uint32_t, stack->a, b_a[0]>>1);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if((color[cur] & 1) == 0) occ++;
color[cur] |= 1;
for (i = 0; i < link->a.a[cur].f.n; i++)
{
if(link->a.a[cur].f.a[i].del) continue;
if(link->a.a[cur].f.a[i].dis != RC_0) continue;
uID = link->a.a[cur].f.a[i].uID;
if((color[uID] & 8) == 0) continue;
if((color[uID] & 1) == 1) continue;
kv_push(uint32_t, stack->a, uID);
}
}
if(occ != b_a_n) goto Failed;
sucess = 1;
for (i = 0; i < b_a_n; i++) color[b_a[i]>>1] = 8;
stack->a.n = 0;
kv_push(uint32_t, stack->a, b_a[0]>>1);
color[b_a[0]>>1] |= 2;///colored
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
color[cur] |= 1;
c = color[cur] & 4; ///get color
for (i = 0; i < link->a.a[cur].f.n; i++)
{
if(link->a.a[cur].f.a[i].del) continue;
if(link->a.a[cur].f.a[i].dis != RC_0) continue;
uID = link->a.a[cur].f.a[i].uID;
if((color[uID] & 8) == 0) continue;
if((color[uID] & 2) && ((color[uID] & 4) == c)) break; ///conflict
if((color[uID] & 1) == 1) continue;
kv_push(uint32_t, stack->a, uID);
color[uID] |= 2; color[uID] |= (c^4);
}
if(i != link->a.a[cur].f.n)
{
sucess = -1;
break;
}
}
Failed:
if(sucess != 1)
{
for (i = 0; i < b_a_n; i++) color[b_a[i]>>1] = 0;
}
return sucess;
}
void assign_per_unitig_G_partition(G_partition* g_p, uint64_t hap_n, hc_links* link, bubble_type* bub,
uint32_t bubble_first)
{
double index_time = yak_realtime();
reset_G_partition(g_p, hap_n);
partition_warp* res = NULL;
hc_edge *a = NULL;
uint32_t i, a_n, v, u, uv = (uint32_t)-1, k, k_n, k_nv, k_nu, beg, sink, *b_a = NULL, b_a_n;
if(bubble_first)
{
int c;
kvec_t_u32_warp stack; kv_init(stack.a);
uint8_t *color = NULL; CALLOC(color, hap_n);
uint32_t n_bub = bub->f_bub + bub->b_bub;
for (i = 0; i < n_bub; i++)
{
get_bubbles(bub, i, &beg, &sink, &b_a, &b_a_n, NULL);
if(b_a_n == 2 && i < bub->f_bub)
{
continue;
}
///full bubble do not overlap with any others
///broken bubbles might be, but should do nothing
c = graph_bipartiteness(b_a, b_a_n, color, link, &stack);
if(c == 0)
{
fprintf(stderr, "too good: s-utg%.6ul && e-utg%.6ul && %s\n",(beg>>1)+1, (sink>>1)+1, b_a_n != 4? "abnormal" : "normal");
}
if(c == -1)
{
fprintf(stderr, "too bad: s-utg%.6ul && e-utg%.6ul\n",(beg>>1)+1, (sink>>1)+1);
}
if(c == 1)
{
fprintf(stderr, "\nprefect=%u: s-utg%.6ul && e-utg%.6ul\n", b_a_n, (beg>>1)+1, (sink>>1)+1);
for (k = 0; k < b_a_n; k++)
{
if((color[b_a[k]>>1] & 2) == 0) fprintf(stderr, "ERROR\n");
if((color[b_a[k]>>1] & 4) == 0) fprintf(stderr, "0: utg%.6ul\n", (b_a[k]>>1)+1);
}
for (k = 0; k < b_a_n; k++)
{
if((color[b_a[k]>>1] & 2) == 0) fprintf(stderr, "ERROR\n");
if((color[b_a[k]>>1] & 4) != 0) fprintf(stderr, "1: utg%.6ul\n", (b_a[k]>>1)+1);
}
for (k = 0; k < b_a_n; k++) color[b_a[k]>>1] = 0;
}
}
free(color);
kv_destroy(stack.a);
}
for (i = 0; i < hap_n; i++)
{
v = i;
a = link->a.a[v].f.a;
a_n = link->a.a[v].f.n;
for (k = k_n = 0; k < a_n; k++)
{
if(a[k].del) continue;
if(a[k].dis != RC_0) break;
u = a[k].uID;
k_n++;
}
if(k_n != 1)
{
u = (uint32_t)-1;
goto push_uv;
}
a = link->a.a[u].f.a;
a_n = link->a.a[u].f.n;
for (k = k_n = 0; k < a_n; k++)
{
if(a[k].del) continue;
if(a[k].dis != RC_0) break;
uv = a[k].uID;
k_n++;
}
if(k_n != 1 || uv != v)
{
u = (uint32_t)-1;
goto push_uv;
}
push_uv:
k_nv = 0;k_nu = 0;
// not such easy. need to deal with here very carefully
// if(g_p->index[v] != (uint32_t)-1) continue;
// if(u != (uint32_t)-1 && g_p->index[u] != (uint32_t)-1) u = (uint32_t)-1;
a = link->a.a[v].e.a;
a_n = link->a.a[v].e.n;
for (k = 0; k < a_n; k++)
{
if(a[k].del) continue;
k_nv++;
}
if(u != (uint32_t)-1)
{
a = link->a.a[u].e.a;
a_n = link->a.a[u].e.n;
for (k = 0; k < a_n; k++)
{
if(a[k].del) continue;
k_nu++;
}
}
if(k_nv == 0) continue;
if(k_nv > 0 && k_nu > 0 && v > u) continue;
kv_pushp(partition_warp, *g_p, &res);
kv_init(res->a);
res->full_bub = 0;
res->h[0] = 1; res->h[1] = 0;
kv_push(uint32_t, res->a, v);
if(u != (uint32_t)-1)
{
res->h[1] = 1;
kv_push(uint32_t, res->a, u);
}
for (k = 0; k < res->h[0]; k++)
{
g_p->index[res->a.a[k]] = g_p->n-1;
g_p->index[res->a.a[k]] = g_p->index[res->a.a[k]] << 1;
}
for (; k < res->a.n; k++)
{
g_p->index[res->a.a[k]] = g_p->n-1;
g_p->index[res->a.a[k]] = (g_p->index[res->a.a[k]] << 1) + 1;
}
}
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
typedef struct {
double weight;
uint64_t p_id, beg_idx, end_idx;
uint8_t used;
}bub_sort_type;
typedef struct {
bub_sort_type* a;
size_t n, m;
}bub_sort_vec;
double get_specific_weight_by_chain(uint64_t* ids, uint64_t beg_idx, uint64_t end_idx, uint64_t p_id,
hc_links* link, uint8_t* vis, uint8_t flag)
{
uint64_t x, k;
uint32_t uid;
double w;
for (x = beg_idx, w = 0; x <= end_idx; x++)
{
uid = (uint32_t)((uint32_t)ids[x])>>1;
for (k = 0; k < link->a.a[uid].e.n; k++)
{
if(link->a.a[uid].e.a[k].del) continue;
if(vis[link->a.a[uid].e.a[k].uID] != flag) continue;
w += link->a.a[uid].e.a[k].weight;
}
}
return w;
}
int cmp_bubble_ele_by_chain(const void * a, const void * b)
{
if((*(bub_sort_type*)a).weight == (*(bub_sort_type*)b).weight)
{
return (*(bub_sort_type*)a).weight > (*(bub_sort_type*)b).weight? -1 : 1;
}
return 0;
}
uint32_t get_max_hap_g(bub_sort_vec* w_stack, uint32_t* require_iso)
{
uint32_t k, max_idx = (uint32_t)-1;
double max_w;
for (k = require_iso? (*require_iso)+1 : 0, max_idx = (uint32_t)-1; k < w_stack->n; k++)
{
if(w_stack->a[k].used) continue;
if(!require_iso)
{
if(w_stack->a[k].p_id == (uint32_t)-1) continue;
if((max_idx == (uint32_t)-1) || (max_idx != (uint32_t)-1 && max_w < w_stack->a[k].weight))
{
max_w = w_stack->a[k].weight;
max_idx = k;
}
}
else
{
if(w_stack->a[k].p_id != (uint32_t)-1) continue;
return k;
}
}
if(require_iso && (*require_iso) != 0)
{
for (k = 0; k < w_stack->n; k++)
{
if(w_stack->a[k].used) continue;
if(w_stack->a[k].p_id != (uint32_t)-1) continue;
return k;
}
}
return max_idx;
}
void update_bub_sort_vec(uint64_t* ids, bub_sort_vec* w_stack, uint32_t max_idx, hc_links* link,
uint32_t* set_hap)
{
w_stack->a[max_idx].used = 1;
uint64_t i, k;
uint32_t uid, pid_idx;
for (i = w_stack->a[max_idx].beg_idx; i <= w_stack->a[max_idx].end_idx; i++)
{
uid = (uint32_t)((uint32_t)ids[i])>>1;
for (k = 0; k < link->a.a[uid].e.n; k++)
{
if(link->a.a[uid].e.a[k].del) continue;
pid_idx = set_hap[link->a.a[uid].e.a[k].uID];
if(pid_idx == (uint32_t)-1) continue;
if(w_stack->a[pid_idx].used) continue;
w_stack->a[pid_idx].weight += link->a.a[uid].e.a[k].weight;
}
}
}
void sort_bubble_ele_by_chain(G_partition* g_p, hc_links* link, bubble_type* bub, kvec_t_u64_warp* stack,
bub_sort_vec* w_stack, uint8_t* vis, uint32_t* set_hap, uint32_t n_utg, uint32_t chain_id)
{
uint32_t max_idx, i, k, j, m, beg, sink, *a, n, flag_cur = 3, flag_right = 2, flag_left = 1, flag_unset = 0;
uint64_t bid, uid, pid, pre_pid;
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
bub_sort_type *p = NULL;
memset(vis, flag_unset, n_utg);
for (i = 0; i < u->n; i++)
{
bid = u->a[i]>>33;
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
vis[uid] = flag_right;
}
}
for (i = 0; i < u->n; i++)
{
stack->a.n = 0; w_stack->n = 0;
bid = u->a[i]>>33;
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
pid = g_p->index[uid];
if(pid != (uint32_t)-1) pid >>= 1;
kv_push(uint64_t, stack->a, (pid<<32)|a[k]);
vis[uid] = flag_cur;
}
radix_sort_hc64(stack->a.a, stack->a.a + stack->a.n);///sort is to dedup pid
for (k = 0, pre_pid = (uint64_t)-1; k < stack->a.n; k++)
{
if((stack->a.a[k]>>32) == pre_pid) continue;
if(w_stack->n > 0) w_stack->a[w_stack->n-1].end_idx = k - 1;
pre_pid = stack->a.a[k]>>32;
kv_pushp(bub_sort_type, *w_stack, &p);
p->weight = 0;
p->p_id = pre_pid;
p->beg_idx = k;
p->end_idx = (uint64_t)-1;
p->used = 0;
}
if(w_stack->n > 0) w_stack->a[w_stack->n-1].end_idx = k - 1;
///get each hap id
for (k = 0; k < w_stack->n; k++)
{
w_stack->a[k].weight += get_specific_weight_by_chain(stack->a.a, w_stack->a[k].beg_idx, w_stack->a[k].end_idx, w_stack->a[k].p_id,
link, vis, flag_left);
w_stack->a[k].weight -= get_specific_weight_by_chain(stack->a.a, w_stack->a[k].beg_idx, w_stack->a[k].end_idx, w_stack->a[k].p_id,
link, vis, flag_right);
for (j = w_stack->a[k].beg_idx; j <= w_stack->a[k].end_idx; j++)
{
set_hap[((uint32_t)stack->a.a[j])>>1] = k;
}
}
m = 0;
while ((max_idx = get_max_hap_g(w_stack, NULL)) != (uint32_t)-1)
{
for (j = w_stack->a[max_idx].beg_idx; j <= w_stack->a[max_idx].end_idx; j++)
{
a[m] = (uint32_t)stack->a.a[j];
m++;
}
update_bub_sort_vec(stack->a.a, w_stack, max_idx, link, set_hap);
}
while ((max_idx = get_max_hap_g(w_stack, &max_idx)) != (uint32_t)-1)
{
for (j = w_stack->a[max_idx].beg_idx; j <= w_stack->a[max_idx].end_idx; j++)
{
a[m] = (uint32_t)stack->a.a[j];
m++;
}
update_bub_sort_vec(stack->a.a, w_stack, max_idx, link, set_hap);
}
/**
qsort(w_stack->a, w_stack->n, sizeof(bub_sort_type), cmp_bubble_ele_by_chain);
m = 0;
for (k = 0; k < w_stack->n; k++)
{
if(w_stack->a[k].p_id == (uint32_t)-1) continue;
for (j = w_stack->a[k].beg_idx; j <= w_stack->a[k].end_idx; j++)
{
a[m] = (uint32_t)stack->a.a[j];
m++;
}
}
for (k = 0; k < w_stack->n; k++)
{
if(w_stack->a[k].p_id != (uint32_t)-1) continue;
for (j = w_stack->a[k].beg_idx; j <= w_stack->a[k].end_idx; j++)
{
a[m] = (uint32_t)stack->a.a[j];
m++;
}
}
**/
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
vis[uid] = flag_left;
set_hap[uid] = (uint32_t)-1;
}
}
}
void sort_bubble_ele(G_partition* g_p, hc_links* link, bubble_type* bub, uint32_t n_utg)
{
double index_time = yak_realtime();
kvec_t_u64_warp stack; kv_init(stack.a);
bub_sort_vec w_stack; kv_init(w_stack);
uint8_t* vis = NULL; MALLOC(vis, n_utg);
uint32_t* set_hap = NULL; MALLOC(set_hap, n_utg); memset(set_hap, -1, sizeof(uint32_t)*n_utg);
uint32_t i;
for (i = 0; i < bub->chain_weight.n; i++)
{
if(bub->chain_weight.a[i].del) continue;
sort_bubble_ele_by_chain(g_p, link, bub, &stack, &w_stack, vis, set_hap, n_utg, bub->chain_weight.a[i].id);
}
kv_destroy(stack.a); kv_destroy(w_stack); free(vis); free(set_hap);
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
uint32_t init_contig_partition(H_partition* hap, ha_ug_index* idx, bubble_type* bub, hc_links* link)
{
///hc_links* link = idx->link;
ma_ug_t *ug = idx->ug;
bub_p_t_warp b;
memset(&b, 0, sizeof(bub_p_t_warp));
CALLOC(b.a, ug->g->n_seq*2);
uint32_t i, nv = ug->g->n_seq * 2, max_i, max_hap_label;
for (i = 0; i < nv; i++)
{
b.a[i].w[0] = b.a[i].w[1] = b.a[i].nh = 0;
b.a[i].p =b.a[i].d = b.a[i].nc = b.a[i].uc = b.a[i].ac = b.a[i].r = b.a[i].s = 0;
}
uint8_t* hap_label_flag = NULL;
CALLOC(hap_label_flag, ug->g->n_seq);
hap->n = ug->u.n;
MALLOC(hap->hap, hap->n);
memset(hap->hap, 0, hap->n*sizeof(uint32_t));
MALLOC(hap->lock, hap->n);
memset(hap->lock, 0, hap->n);
hap->m[0] = 1; hap->m[1] = 2; hap->m[2] = 4;
hap->link = link;
hap->label = 0;
hap->label_add = 8;//1000, for hap group
for(hap->label_shift=1; (uint64_t)(1<<hap->label_shift)<(uint64_t)hap->label_add; hap->label_shift++);
kv_init(hap->label_buffer);
kv_init(hap->b.vis); kv_malloc(hap->b.vis, hap->n); hap->b.vis.n = hap->n;
///sorted by weight
for (i = 0; i < bub->chain_weight.n; i++)
{
if(bub->chain_weight.a[i].del) continue;
phase_bubble_chain(hap, ug, &b, bub, hap_label_flag, bub->chain_weight.a[i].id);
///print_chain_phasing(hap, ug, bub, bub->chain_weight.a[i].id);
}
memset(hap_label_flag, 1, ug->g->n_seq);
while (1)
{
max_i = get_unset_com(hap, bub, ug, hap_label_flag, &max_hap_label);
if(max_i == (uint32_t)-1) break;
phase_com(hap, ug, &b, bub, max_i, max_hap_label);
}
for (i = 0; i < hap->n; i++)
{
if((hap->hap[i]&hap->m[0])&&(hap->hap[i]&hap->m[1]))
{
hap->hap[i] >>= hap->label_shift;
hap->hap[i] <<= hap->label_shift;
hap->hap[i] |= hap->m[2];
reset_ambiguous_label(hap, hap_label_flag, i);
}
}
free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
init_G_partition(&(hap->g_p), hap->n);
link_phase_group(hap, bub);
assign_per_unitig_G_partition(&(hap->g_p), hap->n, link, bub, 0);///warp unitigs
adjust_contig_partition(hap, link);
update_bubble_chain(ug, bub, 0, 1);
resolve_bubble_chain_tangle(ug, bub);
clean_bubble_chain_by_HiC(ug, link, bub);
append_boundary_chain(ug, link, bub);
sort_bubble_ele(&(hap->g_p), link, bub, hap->n);
free(hap_label_flag);
return 1;
}
double get_path_phasing_weight(uint32_t query, uint32_t v0, uint32_t root, bub_p_t_warp *b, kv_u_trans_t *ta)
{
if(v0 == root) return 0;
uint32_t v, u;
u_trans_t *p = NULL;
double nw = 0;
v = v0;
do {
u = b->a[v].p; // u->v
get_u_trans_spec(ta, query>>1, v>>1, &p, NULL);
if(p && (!p->del)) nw += p->nw;
v = u;
} while (v != root);
return nw;
}
void get_related_phasing_weight(uint32_t x, kv_u_trans_t *ta, double* w0, double* w1, int8_t *s)
{
(*w0) = (*w1) = 0;
if(x >= ta->idx.n) return;
uint32_t e_n, k;
u_trans_t* e = u_trans_a(*ta, x);
e_n = u_trans_n(*ta, x);
for (k = 0; k < e_n; k++)
{
if(e[k].del) continue;
if(s[e[k].tn] > 0) (*w0) += e[k].nw;
else if(s[e[k].tn] < 0) (*w1) += e[k].nw;
}
}
void set_phase_path(bub_p_t_warp *b, uint32_t root, kv_u_trans_t *ta, ps_t *s)
{
int8_t f;
uint32_t v, u;
double z[2], cur_w[2];
z[0] = z[1] = 0;
v = b->S.a[0];
do {
u = b->a[v].p; // u->v
if(v != b->S.a[0])
{
get_related_phasing_weight(v>>1, ta, &cur_w[0], &cur_w[1], s->s);
z[0] += cur_w[0]; z[1] += cur_w[1];
}
v = u;
} while (v != root);
if(z[0] - z[1] < 0)
{
f = 1;
}
else if(z[0] - z[1] > 0)
{
f = -1;
}
else
{
s->xs = kr_splitmix64(s->xs);
f = s->xs&1? 1 : -1;
}
v = b->S.a[0];
do {
u = b->a[v].p; // u->v
if(v != b->S.a[0]) s->s[v>>1] = f;
v = u;
} while (v != root);
}
uint32_t bub_phase(ma_ug_t *ug, uint32_t beg, uint32_t end, bub_p_t_warp *b, kv_u_trans_t *ta, ps_t *s)
{
asg_t *g = ug->g;
if(g->seq[beg>>1].del) return 0; // already deleted
if(get_real_length(g, beg, NULL)<2) return 0;
uint32_t i, is_end, n_pending, to_replace, cur_nc, cur_uc, cur_ac, n_tips, tip_end, n_pop;
double cur_nh, cur_w0, cur_w1, cur_rate, max_rate, cur_weight, min_weight;
///S saves nodes with all incoming edges visited
b->S.n = b->T.n = b->b.n = b->e.n = 0;
///for each node, b->a saves all related information
b->a[beg].d = b->a[beg].nc = b->a[beg].ac = b->a[beg].uc = 0;
b->a[beg].nh = b->a[beg].w[0] = b->a[beg].w[1] = 0;
b->a[beg].p = (uint32_t)-1;
///b->S is the nodes with all incoming edges visited
kv_push(uint32_t, b->S, beg);
n_pop = n_tips = n_pending = 0;
tip_end = (uint32_t)-1;
do {
///v is a node that all incoming edges have been visited
///d is the distance from v0 to v
uint32_t v = kv_pop(b->S);
uint32_t d = b->a[v].d, nc = b->a[v].nc, uc = b->a[v].uc, ac = b->a[v].ac;
double nh = b->a[v].nh;///path weight
double nw_0 = b->a[v].w[0], nw_1 = b->a[v].w[1];///weight to haplotype 1/2
uint32_t nv = asg_arc_n(g, v);
asg_arc_t *av = asg_arc_a(g, v);
for (i = 0; i < nv; ++i) {
uint32_t w = av[i].v, l = (uint32_t)av[i].ul; // v->w with length l, not overlap length
bub_p_t *t = &b->a[w];
is_end = 0;
if((w>>1) == (end>>1)) is_end = 1;
//got a circle
if ((w>>1) == (beg>>1)) goto pop_reset;
if (av[i].del) continue;
///push the edge
kv_push(uint32_t, b->e, (g->idx[v]>>32) + i);
if (t->s == 0)
{ // this vertex has never been visited
kv_push(uint32_t, b->b, w); // save it for revert
///t->p is the parent node of
///t->s = 1 means w has been visited
///d is len(v0->v), l is len(v->w), so t->d is len(v0->w)
t->p = v, t->s = 1, t->d = d + l;
t->r = get_real_length(g, w^1, NULL);
if(is_end == 0)
{
t->nc = nc + ug->u.a[(w>>1)].n;
t->nh = nh + get_path_phasing_weight(w, v, beg, b, ta);
get_related_phasing_weight(w>>1, ta, &(t->w[0]), &(t->w[1]), s->s);
t->w[0] += nw_0; t->w[1] += nw_1;
t->ac = ac + ((s->s[w>>1] == 0)? ug->u.a[(w>>1)].n : 0);
t->uc = uc + ((s->s[w>>1] != 0)? ug->u.a[(w>>1)].n : 0);
}
++n_pending;
}
else {
to_replace = 0;
if(is_end)
{
cur_nc = nc; cur_nh = nh;
cur_w0 = nw_0; cur_w1= nw_1;
cur_ac = ac; cur_uc = uc;
}
else
{
cur_nc = nc + ug->u.a[(w>>1)].n;
cur_nh = nh + get_path_phasing_weight(w, v, beg, b, ta);
get_related_phasing_weight(w>>1, ta, &cur_w0, &cur_w1, s->s);
cur_w0 += nw_0; cur_w1 += nw_1;
cur_ac = ac + ((s->s[w>>1] == 0)? ug->u.a[(w>>1)].n : 0);
cur_uc = uc + ((s->s[w>>1] != 0)? ug->u.a[(w>>1)].n : 0);
}
cur_weight = cur_nh + MIN(cur_w0, cur_w1) - MAX(cur_w0, cur_w1);
min_weight = t->nh + MIN(t->w[0], t->w[1]) - MAX(t->w[0], t->w[1]);
cur_rate = ((cur_ac+cur_uc == 0)? -1 : ((double)(cur_ac)/(double)(cur_ac+cur_uc)));
max_rate = ((t->ac+t->uc == 0)? -1 : ((double)(t->ac)/(double)(t->ac+t->uc)));
if(cur_rate > max_rate)
{
to_replace = 1;
}
else if(cur_rate == max_rate)
{
if(cur_weight < min_weight)
{
to_replace = 1;
}
else if(cur_weight == min_weight)
{
if(cur_nc > t->nc)
{
to_replace = 1;
}
else if(cur_nc == t->nc)
{
if(d + l > t->d)
{
to_replace = 1;
}
}
}
}
if(to_replace)
{
t->p = v;
t->nc = cur_nc;
t->nh = cur_nh;
t->ac = cur_ac;
t->uc = cur_uc;
t->w[0] = cur_w0;
t->w[1] = cur_w1;
}
if (d + l < t->d) t->d = d + l; // update dist
}
if (--(t->r) == 0) {
uint32_t x = get_real_length(g, w, NULL);
if(x > 0)
{
kv_push(uint32_t, b->S, w);
}
else
{
///at most one tip
if(n_tips != 0) goto pop_reset;
n_tips++;
tip_end = w;
}
--n_pending;
}
}
if(n_tips == 1)
{
if(tip_end != (uint32_t)-1 && n_pending == 0 && b->S.n == 0)
{
///sink is b.S.a[0]
kv_push(uint32_t, b->S, tip_end);
break;
}
else
{
goto pop_reset;
}
}
if (i < nv || b->S.n == 0) goto pop_reset;
}while (b->S.n > 1 || n_pending);
n_pop = 1;
/**need fix**/
set_phase_path(b, beg, ta, s);
pop_reset:
for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
bub_p_t *t = &b->a[b->b.a[i]];
t->p = t->d = t->nc = t->ac = t->uc = t->r = t->s = 0;
t->nh = t->w[0] = t->w[1] = 0;
}
return n_pop;
}
uint32_t get_weightest_node(kv_u_trans_t *ta, bubble_type* bub, ma_ug_t* ug, int8_t *s, uint8_t *vis)
{
double w_a, w_n, max_w_a, max_w_n;
uint32_t i, occ, k, m, v, *a = NULL, a_n, e_n, max_w_a_i, max_w_n_i;
u_trans_t *e = NULL;
max_w_a = max_w_n = -1; max_w_a_i = max_w_n_i = (uint32_t)-1;
for (i = 0; i < bub->f_bub; i++)
{
get_bubbles(bub, i, NULL, NULL, &a, &a_n, NULL);
if(vis[i]) continue;
for (k = 0, w_a = w_n = 0; k < a_n; k++)
{
v = a[k]>>1;
if(s[v] != 0) break;
e = u_trans_a(*ta, v);
e_n = u_trans_n(*ta, v);
for (m = 0; m < e_n; m++)
{
if(s[e[m].tn] != 0)
{
w_a += (e[m].nw>=0?e[m].nw:-e[m].nw);
}
else
{
w_n += (e[m].nw>=0?e[m].nw:-e[m].nw);
}
}
}
if(k >= a_n && a_n > 0)//unset whole bubble
{
if(w_a > max_w_a)
{
max_w_a_i = i<<1;
max_w_a = w_a;
}
if(w_n > max_w_n)
{
max_w_n_i = i<<1;
max_w_n = w_n;
}
}
else
{
for (k = occ = 0; k < a_n; k++)
{
v = a[k]>>1;
if(s[v] != 0)
{
occ++;
continue;
}
e = u_trans_a(*ta, v);
e_n = u_trans_n(*ta, v);
for (m = 0, w_a = w_n = 0; m < e_n; m++)
{
if(s[e[m].tn] != 0)
{
w_a += (e[m].nw>=0?e[m].nw:-e[m].nw);
}
else
{
w_n += (e[m].nw>=0?e[m].nw:-e[m].nw);
}
}
if(w_a > max_w_a)
{
max_w_a_i = (v<<1)+1;
max_w_a = w_a;
}
if(w_n > max_w_n)
{
max_w_n_i = (v<<1)+1;
max_w_n = w_n;
}
}
if(occ == a_n) vis[i] = 1;
}
}
for (i = 0; i < ug->g->n_seq; i++)
{
if(s[i] != 0 || (IF_BUB(i, *bub))) continue;
v = i;
e = u_trans_a(*ta, v);
e_n = u_trans_n(*ta, v);
for (m = 0, w_a = w_n = 0; m < e_n; m++)
{
if(s[e[m].tn] != 0)
{
w_a += (e[m].nw>=0?e[m].nw:-e[m].nw);
}
else
{
w_n += (e[m].nw>=0?e[m].nw:-e[m].nw);
}
}
if(w_a > max_w_a)
{
max_w_a_i = (i<<1)+1;
max_w_a = w_a;
}
if(w_n > max_w_n)
{
max_w_n_i = (i<<1)+1;
max_w_n = w_n;
}
}
if(max_w_a_i != (uint32_t)-1) return max_w_a_i;
return max_w_n_i;
}
void init_phase(ha_ug_index* idx, kv_u_trans_t *ta, bubble_type* bub, ps_t *st)
{
double index_time = yak_realtime();
uint8_t *vis = NULL; CALLOC(vis, idx->ug->g->n_seq);
bub_p_t_warp b; memset(&b, 0, sizeof(bub_p_t_warp));
CALLOC(b.a, idx->ug->g->n_seq*2);
uint32_t i, k, *a = NULL, n, beg, end;
memset(st->s, 0, sizeof(int8_t)*idx->ug->g->n_seq);
double z[2];
u_trans_t *e = NULL;
uint32_t e_n;
while(1)
{
i = get_weightest_node(ta, bub, idx->ug, st->s, vis);
if(i == (uint32_t)-1) break;
if(i&1)
{
i>>=1;
z[0] = z[1] = 0;
e = u_trans_a(*ta, i);
e_n = u_trans_n(*ta, i);
for (k = 0; k < e_n; k++)
{
if(e[k].del) continue;
if(st->s[e[k].tn] > 0) z[0] += e[k].nw;
else if(st->s[e[k].tn] < 0) z[1] += e[k].nw;
}
if(z[0] - z[1] < 0)
{
st->s[i] = 1;
}
else if(z[0] - z[1] > 0)
{
st->s[i] = -1;
}
else
{
st->xs = kr_splitmix64(st->xs);
st->s[i] = st->xs&1? 1 : -1;
}
}
else
{
i>>=1;
get_bubbles(bub, i, &beg, &end, &a, &n, NULL);
bub_phase(idx->ug, beg, end, &b, ta, st);
bub_phase(idx->ug, beg, end, &b, ta, st);
}
}
free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
free(vis);
for (i = 0; i < idx->ug->g->n_seq; i++)
{
if(st->s[i] == 0) fprintf(stderr, "ERROR\n");
if(u_trans_n(*ta, i) == 0) st->s[i] = 0;
}
fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
double dfs_weight_hic(uint32_t v, uint8_t* vis_flag, uint8_t* is_vis, kv_u_trans_t *ta,
kvec_t_u32_warp* stack, kvec_t_u32_warp* result, uint32_t e_flag, uint32_t ava_flag, uint32_t* link_occ)
{
u_trans_t *e = NULL;
uint32_t cur, i, next = (uint32_t)-1, e_n;
stack->a.n = 0;
kv_push(uint32_t, stack->a, v);
double w = 0;
if(link_occ) (*link_occ) = 0;
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(is_vis[cur]) continue;
is_vis[cur] = 1;
if(cur!=v && vis_flag[cur] != ava_flag) continue;
e = u_trans_a(*ta, cur); e_n = u_trans_n(*ta, cur);
for (i = 0; i < e_n; i++)
{
if(e[i].del) continue;
next = e[i].tn;
if(vis_flag[next]&e_flag)
{
w += (e[i].nw >= 0? e[i].nw : -e[i].nw);
if(link_occ) (*link_occ) += e[i].occ;
continue;
}
if(is_vis[next]) continue;
if(vis_flag[next] != ava_flag) continue;
kv_push(uint32_t, stack->a, next);
}
}
return w;
}
double get_chain_weight_hic(bubble_type* bub, ma_ug_t *bub_ug, buf_t* b, uint32_t v, uint32_t convex_source,
kv_u_trans_t *ta, uint8_t* vis_flag, uint8_t* is_vis, ma_ug_t* ug, kvec_t_u32_warp* stack,
kvec_t_u32_warp* result, uint32_t e_flag, uint32_t ava_flag, kvec_t_u32_warp* res_utg, uint32_t* link_occ)
{
long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
ma_utg_t *u = NULL;
uint32_t convex, k, k_i, k_j, *a, n, beg, sink, uID, root, cur, ncur, n_vx = ug->g->n_seq<<1, occ;
asg_arc_t *acur = NULL;
double w = 0;
b->b.n = 0;
get_unitig(bub_ug->g, NULL, v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen,
&max_stop_baseLen, 1, b);
memset(is_vis, 0, n_vx);
for (k = 0; k < b->b.n; k++)
{
u = &(bub_ug->u.a[b->b.a[k]>>1]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, &beg, &sink, &a, &n, NULL);
for(k_j = 0; k_j < n; k_j++) is_vis[a[k_j]] = is_vis[a[k_j]^1] = 1;
if(beg != (uint32_t)-1) is_vis[beg] = is_vis[beg^1] = 1;
if(sink != (uint32_t)-1) is_vis[sink] = is_vis[sink^1] = 1;
}
}
u = &(bub_ug->u.a[v>>1]);
if((v&1)==0)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&root:NULL,
(((u->a[0]>>32)&1)^1) == 0?&root:NULL, NULL, NULL, NULL);
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&root:NULL,
((u->a[u->n-1]>>32)&1) == 0?&root:NULL, NULL, NULL, NULL);
}
root ^= 1;
///fprintf(stderr, "root=utg%.6dl\n", (root>>1)+1);
is_vis[root] = 0;
stack->a.n = 0;
kv_push(uint32_t, stack->a, root);
while (stack->a.n > 0)
{
stack->a.n--;
cur = stack->a.a[stack->a.n];
if(is_vis[cur]) continue;
is_vis[cur] = 1;
if(vis_flag[cur>>1] == 0) vis_flag[cur>>1] = ava_flag;///unitig not in any chain
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k = 0; k < ncur; k++)
{
if(acur[k].del) continue;
if(is_vis[acur[k].v]) continue;
if(vis_flag[acur[k].v>>1] != 0 && vis_flag[acur[k].v>>1] != ava_flag) continue;
kv_push(uint32_t, stack->a, acur[k].v);
}
}
///vis_flag keeps isloated nodes
uint32_t aim_0, aim_1, root_source;
aim_0 = root>>1;
u = &(bub_ug->u.a[convex_source>>1]);
if((convex_source&1)==1)
{
get_bubbles(bub, (u->a[0]>>32)>>1, (((u->a[0]>>32)&1)^1)==1?&root_source:NULL,
(((u->a[0]>>32)&1)^1) == 0?&root_source:NULL, NULL, NULL, NULL);
}
else
{
get_bubbles(bub, (u->a[u->n-1]>>32)>>1, ((u->a[u->n-1]>>32)&1)==1?&root_source:NULL,
((u->a[u->n-1]>>32)&1) == 0?&root_source:NULL, NULL, NULL, NULL);
}
root_source ^= 1;
aim_1 = root_source>>1;
///fprintf(stderr, "aim_0=utg%.6ul, aim_1=utg%.6ul\n", aim_0+1, aim_1+1);
cur = root_source;///scan nodes that cannot be reached from root but can be reached from root_source
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k_i = 0; k_i < ncur; k_i++)
{
if(acur[k_i].del) continue;
if(vis_flag[acur[k_i].v>>1] != 0) continue;///skip nodes that are already reachable
if_conflict_utg(acur[k_i].v, &aim_0, &aim_1, ug, vis_flag, is_vis, ava_flag, stack);
}
for (k = 0; k < ug->g->n_seq; k++)
{
if(vis_flag[k] == ava_flag)
{
cur = k<<1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k_i = 0; k_i < ncur; k_i++)
{
if(acur[k_i].del) continue;
if(vis_flag[acur[k_i].v>>1] != 0) continue;
if_conflict_utg(acur[k_i].v, &aim_0, &aim_1, ug, vis_flag, is_vis, ava_flag, stack);
}
cur = (k<<1)+1;
ncur = asg_arc_n(ug->g, cur);
acur = asg_arc_a(ug->g, cur);
for (k_i = 0; k_i < ncur; k_i++)
{
if(acur[k_i].del) continue;
if(vis_flag[acur[k_i].v>>1] != 0) continue;
if_conflict_utg(acur[k_i].v, &aim_0, &aim_1, ug, vis_flag, is_vis, ava_flag, stack);
}
}
}
memset(is_vis, 0, n_vx);
if(link_occ) (*link_occ) = 0;
for (k = result->a.n = 0, w = 0; k < b->b.n; k++)
{
u = &(bub_ug->u.a[b->b.a[k]>>1]);
if(u->n == 0) continue;
for (k_i = 0; k_i < u->n; k_i++)
{
get_bubbles(bub, u->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
w += dfs_weight_hic(uID, vis_flag, is_vis, ta, stack, result, e_flag, ava_flag, &occ);
if(link_occ) (*link_occ) += occ;
}
}
}
for (k = 0; k < ug->g->n_seq; k++)
{
if(vis_flag[k] == ava_flag)
{
vis_flag[k] = 0;
if(res_utg && (!IF_HOM(k, *bub)))
{
kv_push(uint32_t, res_utg->a, k<<1);
}
}
}
return w;
}
void clean_bubble_chain_by_hic(ma_ug_t* ug, kv_u_trans_t *ta, bubble_type* bub)
{
// double index_time = yak_realtime();
ma_ug_t *bs_ug = bub->b_ug;
uint32_t v, u, i, m, max_i, nv, rv, n_vx, root, flag_pri = 1, flag_aux = 2, flag_ava = 4, occ;
double w, cutoff = 2;
uint32_t max_w_occ = 4;
asg_arc_t *av = NULL;
n_vx = bs_ug->g->n_seq << 1;
uint8_t *vis = NULL; CALLOC(vis, ug->g->n_seq<<1);
uint8_t *is_vis = NULL; CALLOC(is_vis, ug->g->n_seq<<1);
uint8_t *is_used = NULL; CALLOC(is_used, n_vx);
uint8_t *dedup = NULL; CALLOC(dedup, ug->g->n_seq<<1);
buf_t b; memset(&b, 0, sizeof(buf_t));
kvec_t_u32_warp stack, result, res_utg;
kv_init(stack.a); kv_init(result.a); kv_init(res_utg.a);
double *e_w = NULL; MALLOC(e_w, bs_ug->g->n_arc);
uint32_t *e_occ = NULL, *a_occ = NULL; CALLOC(e_occ, bs_ug->g->n_arc);
double *aw = NULL, max_w = 0;
kvec_asg_arc_t_warp edges; kv_init(edges.a);
ma_ug_t *back_bs_ug = copy_untig_graph(bs_ug);
for (i = 0; i < bs_ug->g->n_arc; i++)///weight of bs_ug's edges
{
e_w[i] = -1;
}
for (i = 0; i < bs_ug->g->n_seq; i++)///init all chain with flag_aux
{
set_b_utg_weight_flag(bub, &b, i<<1, vis, flag_aux, NULL);
}
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
aw = (&e_w[bs_ug->g->idx[v]>>32]);
a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
if(nv <= 1 || get_real_length(bs_ug->g, v, NULL) <= 1) continue;
set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
w = get_chain_weight_hic(bub, bs_ug, &b, av[i].v, v, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, NULL, &occ);
aw[i] = w;
a_occ[i] = occ;
}
set_b_utg_weight_flag_xor(bub, bs_ug, &b, v^1, vis, flag_pri, NULL);
}
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
aw = (&e_w[bs_ug->g->idx[v]>>32]);
a_occ = (&e_occ[bs_ug->g->idx[v]>>32]);
if(nv <= 1 || get_real_length(bs_ug->g, v, NULL) <= 1) continue;
for (i = rv = 0, max_i = (uint32_t)-1; i < nv; i++)
{
if(av[i].del) continue;
if(max_i == (uint32_t)-1)
{
max_i = i;
max_w = aw[i];
}
else if(max_w < aw[i])
{
max_i = i;
max_w = aw[i];
}
rv++;
}
if(max_i == (uint32_t)-1) continue;
///if(max_w <= max_w_cutoff) continue; //must be <=
if(a_occ[max_i] <= max_w_occ) continue; //must be <=
if(rv < 2) continue;
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
if(i == max_i) continue;
///if((av[i].v>>1) == (v>>1) && aw[i] <= max_w_cutoff) continue; ///might be not reasonable
if((av[i].v>>1) == (v>>1) && a_occ[i] <= max_w_occ) continue; ///might be not reasonable
if(aw[i]*cutoff < max_w && double_check_bub_branch(&av[i], bs_ug, e_w, e_occ, cutoff, max_w_occ))
{
av[i].del = 1; asg_arc_del(bs_ug->g, (av[i].v)^1, (av[i].ul>>32)^1, 1);
}
}
}
uint32_t rId_0, ori_0, rId_1, ori_1, root_0, root_1, new_bub;
if(bub->num.n > 0) bub->num.n--;
new_bub = bub->b_g->n_seq;
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
rv = get_real_length(bs_ug->g, v, NULL);
if(nv == rv) continue;
if(rv != 1 || nv <= 1) continue;
get_real_length(bs_ug->g, v, &u);
u ^= 1;
if(get_real_length(bs_ug->g, u, NULL) != 1) continue;
drop_g_edges_by_utg(bub, bub->b_g, bs_ug, NULL, v, u);
if(is_used[v] || is_used[u]) continue;
is_used[v] = is_used[u] = 1;
root = get_utg_end_from_btg(bub, bs_ug, v);
rId_0 = root>>1;
ori_0 = root&1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
root = get_utg_end_from_btg(bub, bs_ug, u);
rId_1 = root>>1;
ori_1 = root&1;
get_bubbles(bub, rId_1, ori_1 == 1?&root_1:NULL, ori_1 == 0?&root_1:NULL, NULL, NULL, NULL);
res_utg.a.n = 0;
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, v^1, vis, flag_pri, NULL);
get_chain_weight_hic(bub, back_bs_ug, &b, u^1, v, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, v^1, vis, flag_pri, NULL);
for (i = 0; i < res_utg.a.n; i++) dedup[res_utg.a.a[i]>>1] |= 1;
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, u^1, vis, flag_pri, NULL);
get_chain_weight_hic(bub, back_bs_ug, &b, v^1, u, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, back_bs_ug, &b, u^1, vis, flag_pri, NULL);
for (; i < res_utg.a.n; i++) dedup[res_utg.a.a[i]>>1] |= 2;
for (i = m = 0; i < res_utg.a.n; i++)
{
if(dedup[res_utg.a.a[i]>>1] == 3)
{
res_utg.a.a[m] = res_utg.a.a[i];
m++;
}
dedup[res_utg.a.a[i]>>1] = 0;
}
res_utg.a.n = m;
// fprintf(stderr, "res_utg.a.n: %u, m: %u, beg-utg%.6ul, sink-utg%.6ul\n",
// res_utg.a.n, m, (root_0>>1)+1, (root_1>>1)+1);
if(!IF_HOM(root_0>>1, *bub)) kv_push(uint32_t, res_utg.a, root_0);
if(!IF_HOM(root_1>>1, *bub)) kv_push(uint32_t, res_utg.a, root_1);
update_bubble_graph(&res_utg, root_0^1, rId_0, root_1^1, rId_1, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);
///fprintf(stderr, "\n******src-btg%.6ul------>dest-btg%.6ul\n", (v>>1)+1, (u>>1)+1);
}
kv_push(uint32_t, bub->num, bub->list.n);
new_bub = bub->b_g->n_seq - new_bub;
bub->cross_bub += new_bub;
///actually not useful, and may have bug when one bubble at multipe chains
if(new_bub) update_bub_b_s_idx(bub);
///debug_tangle_bubble(bub, bub->b_g->n_seq - bub->cross_bub, bub->b_g->n_seq - 1, "Cross-tangle");
update_bsg(bub->b_g, &edges);
ma_ug_destroy(bs_ug);
bs_ug = ma_ug_gen(bub->b_g);
bub->b_ug = bs_ug;
kv_destroy(bub->chain_weight);
ma_utg_t *u_x = NULL;
bs_ug = bub->b_ug;
kv_malloc(bub->chain_weight, bs_ug->u.n); bub->chain_weight.n = bs_ug->u.n;
for (i = 0; i < bs_ug->u.n; i++)
{
u_x = &(bs_ug->u.a[i]);
bub->chain_weight.a[i].id = i;
// if(u->n <= 1) ///not a chain
// {
// bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
// bub->chain_weight.a[i].del = 1;
// }
// else
{
bub->chain_weight.a[i].del = 0;
calculate_chain_weight(u_x, bub, ug, &(bub->chain_weight.a[i]));
}
}
qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);
free(vis); free(is_vis); free(is_used); free(dedup); free(b.b.a); free(e_w); free(e_occ);
kv_destroy(stack.a); kv_destroy(result.a); kv_destroy(res_utg.a); kv_destroy(edges.a);
ma_ug_destroy(back_bs_ug);
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
void append_boundary_chain_hic(ma_ug_t* ug, kv_u_trans_t *ta, bubble_type* bub)
{
// double index_time = yak_realtime();
ma_ug_t *bs_ug = bub->b_ug;
uint32_t v, u, i, k, beg_idx, m, nv, n_vx, flag_pri = 1, flag_aux = 2, flag_ava = 4;
uint32_t root, rId_0, ori_0, root_0, new_bub;
asg_arc_t *av = NULL;
n_vx = bs_ug->g->n_seq << 1;
uint8_t *vis = NULL; CALLOC(vis, ug->g->n_seq<<1);
uint8_t *is_vis = NULL; CALLOC(is_vis, ug->g->n_seq<<1);
uint8_t *is_used = NULL; CALLOC(is_used, n_vx);
uint8_t *dedup = NULL; CALLOC(dedup, ug->g->n_seq<<1);
buf_t b; memset(&b, 0, sizeof(buf_t));
kvec_t_u32_warp stack, result, res_utg;
kv_init(stack.a); kv_init(result.a); kv_init(res_utg.a);
kvec_asg_arc_t_warp edges; kv_init(edges.a);
for (i = 0; i < bs_ug->g->n_seq; i++)
{
set_b_utg_weight_flag(bub, &b, i<<1, vis, flag_aux, NULL);
}
if(bub->num.n > 0) bub->num.n--;
new_bub = bub->b_g->n_seq;
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
if(nv == 0 || get_real_length(bs_ug->g, v, NULL) == 0) continue;
res_utg.a.n = 0;
for (i = 0; i < nv; i++)
{
if(av[i].del) continue;
u = av[i].v^1;
beg_idx = res_utg.a.n;
set_b_utg_weight_flag_xor(bub, bs_ug, &b, u^1, vis, flag_pri, NULL);
get_chain_weight_hic(bub, bs_ug, &b, v^1, u, ta, vis, is_vis, ug, &stack, &result, flag_pri, flag_ava, &res_utg, NULL);
set_b_utg_weight_flag_xor(bub, bs_ug, &b, u^1, vis, flag_pri, NULL);
for (k = m = beg_idx; k < res_utg.a.n; k++)
{
if(dedup[res_utg.a.a[k]>>1] != 0) continue;
dedup[res_utg.a.a[k]>>1] = 1;
res_utg.a.a[m] = res_utg.a.a[k];
m++;
}
res_utg.a.n = m;
}
for (k = 0; k < res_utg.a.n; k++) dedup[res_utg.a.a[k]>>1] = 0;
root = get_utg_end_from_btg(bub, bs_ug, v);
rId_0 = root>>1;
ori_0 = root&1;
get_bubbles(bub, rId_0, ori_0 == 1?&root_0:NULL, ori_0 == 0?&root_0:NULL, NULL, NULL, NULL);
if(root_0 != (uint32_t)-1 && (!IF_HOM(root_0>>1, *bub))) kv_push(uint32_t, res_utg.a, root_0);
if(v&1)
{
update_bubble_graph(&res_utg, root_0^1, rId_0, (uint32_t)-1, (uint32_t)-1, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);
}
else
{
update_bubble_graph(&res_utg, (uint32_t)-1, (uint32_t)-1, root_0^1, rId_0, bub, &edges, bub->b_g, NULL, NULL, ug, NULL, 0);
}
}
kv_push(uint32_t, bub->num, bub->list.n);
new_bub = bub->b_g->n_seq - new_bub;
bub->mess_bub += new_bub;
///actually not useful, and may have bug when one bubble at multipe chains
if(new_bub) update_bub_b_s_idx(bub);
for (v = 0; v < n_vx; v++)
{
av = asg_arc_a(bs_ug->g, v);
nv = asg_arc_n(bs_ug->g, v);
if(nv == 0 || get_real_length(bs_ug->g, v, NULL) == 0) continue;
drop_g_edges_by_utg(bub, bub->b_g, bs_ug, NULL, v, (uint32_t)-1);
}
update_bsg(bub->b_g, &edges);
ma_ug_destroy(bs_ug);
bs_ug = ma_ug_gen(bub->b_g);
bub->b_ug = bs_ug;
kv_destroy(bub->chain_weight);
ma_utg_t *u_x = NULL;
bs_ug = bub->b_ug;
kv_malloc(bub->chain_weight, bs_ug->u.n); bub->chain_weight.n = bs_ug->u.n;
for (i = 0; i < bs_ug->u.n; i++)
{
u_x = &(bs_ug->u.a[i]);
bub->chain_weight.a[i].id = i;
// if(u->n <= 1) ///not a chain
// {
// bub->chain_weight.a[i].b_occ = bub->chain_weight.a[i].g_occ = 0;
// bub->chain_weight.a[i].del = 1;
// }
// else
{
bub->chain_weight.a[i].del = 0;
calculate_chain_weight(u_x, bub, ug, &(bub->chain_weight.a[i]));
}
}
qsort(bub->chain_weight.a, bub->chain_weight.n, sizeof(chain_w_type), cmp_chain_weight);
free(vis); free(is_vis); free(is_used); free(dedup); free(b.b.a);
kv_destroy(stack.a); kv_destroy(result.a); kv_destroy(res_utg.a);
kv_destroy(edges.a);
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
double get_specific_hic_weight_by_chain(uint32_t uid, kv_u_trans_t *ta, uint8_t* vis, uint8_t flag)
{
u_trans_t *e = u_trans_a(*ta, uid);
uint64_t k, e_n = u_trans_n(*ta, uid);
double w = 0;
for (k = 0; k < e_n; k++)
{
if(e[k].del) continue;
if(vis[e[k].tn] != flag) continue;
w += (e[k].nw>=0?e[k].nw:-e[k].nw);
}
return w;
}
void update_bubble_weight(bub_sort_vec* w_stack, uint32_t idx, kv_u_trans_t *ta, uint8_t* vis, uint32_t flag_cur)
{
w_stack->a[idx].used = 1;
uint32_t k, m, uid = w_stack->a[idx].p_id>>1;
u_trans_t *e = u_trans_a(*ta, uid);
uint32_t e_n = u_trans_n(*ta, uid);
for (k = 0; k < e_n; k++)
{
if(e[k].del) continue;
if(vis[e[k].tn] != flag_cur) continue;
for (m = 0; m < w_stack->n; m++)
{
if(e[k].tn == (w_stack->a[m].p_id>>1)) break;
}
if(m >= w_stack->n) continue;
if(w_stack->a[m].used) continue;
w_stack->a[m].weight += (e[k].nw>=0?e[k].nw:-e[k].nw);
}
}
void reorder_bubbble_chain(kv_u_trans_t *ta, bubble_type* bub, bub_sort_vec* w_stack,
uint8_t* vis, uint32_t n_utg, uint32_t chain_id)
{
uint32_t i, k, m, max_idx, flag_cur = 3, flag_right = 2, flag_left = 1, flag_unset = 0, *a, n;
uint64_t bid, uid;
ma_utg_t *u = &(bub->b_ug->u.a[chain_id]);
memset(vis, flag_unset, n_utg);
for (i = 0; i < u->n; i++)
{
bid = u->a[i]>>33;
get_bubbles(bub, bid, NULL, NULL, &a, &n, NULL);
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
vis[uid] = flag_right;
}
}
for (i = 0; i < u->n; i++)
{
w_stack->n = 0;
bid = u->a[i]>>33;
get_bubbles(bub, bid, NULL, NULL, &a, &n, NULL);
kv_resize(bub_sort_type, *w_stack, n);
w_stack->n = n;
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
vis[uid] = flag_cur;
w_stack->a[k].p_id = a[k];
w_stack->a[k].weight = 0;
w_stack->a[k].used = 0;
}
for (k = 0; k < w_stack->n; k++)
{
w_stack->a[k].weight += get_specific_hic_weight_by_chain(w_stack->a[k].p_id>>1,
ta, vis, flag_left);
w_stack->a[k].weight -= get_specific_hic_weight_by_chain(w_stack->a[k].p_id>>1,
ta, vis, flag_right);
}
m = 0;
while ((max_idx = get_max_hap_g(w_stack, NULL)) != (uint32_t)-1)
{
a[m] = w_stack->a[max_idx].p_id;
m++;
update_bubble_weight(w_stack, max_idx, ta, vis, flag_cur);
}
while ((max_idx = get_max_hap_g(w_stack, &max_idx)) != (uint32_t)-1)
{
a[m] = w_stack->a[max_idx].p_id;
m++;
update_bubble_weight(w_stack, max_idx, ta, vis, flag_cur);
}
if(m != n) fprintf(stderr, "ERROR\n");
for (k = 0; k < n; k++)
{
uid = a[k]>>1;
vis[uid] = flag_left;
}
}
}
void reorder_bubbles(bubble_type* bub, kv_u_trans_t *ta, uint32_t n_utg)
{
// double index_time = yak_realtime();
uint8_t* vis = NULL; MALLOC(vis, n_utg);
bub_sort_vec w_stack; kv_init(w_stack);
uint32_t i;
for (i = 0; i < bub->chain_weight.n; i++)
{
if(bub->chain_weight.a[i].del) continue;
reorder_bubbble_chain(ta, bub, &w_stack, vis, n_utg, bub->chain_weight.a[i].id);
}
free(vis); kv_destroy(w_stack);
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
void update_trans_g(ha_ug_index* idx, kv_u_trans_t *ta, bubble_type* bub)
{
// double index_time = yak_realtime();
// update_bubble_chain(idx->ug, bub, 0, 1);
// resolve_bubble_chain_tangle(idx->ug, bub);
clean_bubble_chain_by_hic(idx->ug, ta, bub);
// print_debug_bubble_graph(bub, idx->ug, "bub-2");
// append_boundary_chain_hic(idx->ug, ta, bub);
// fprintf(stderr, "s_bub: %lu, f_bub: %lu, b_bub: %lu, b_end_bub: %lu, tangle_bub: %lu, cross_bub: %lu, mess_bub: %lu\n",
// bub->s_bub, bub->f_bub, bub->b_bub, bub->b_end_bub, bub->tangle_bub, bub->cross_bub, bub->mess_bub);
///reorder_bubbles(bub, ta, idx->ug->g->n_seq);
// fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}
uint32_t get_max_unitig(H_partition* h, G_partition* g_p, hc_links* link, bubble_type* bub)
{
double min, weight;
uint32_t i, min_i;
for (i = 0, min = 1, min_i = (uint32_t)-1; i < g_p->n; i++)
{
if(h->lock[i]) continue;
weight = 0;
if(g_p->a[i].h[0] > 0 && (g_p->a[i].status[0] == 1 || g_p->a[i].status[0] == -1))
{
weight += (g_p->a[i].weight[0] * g_p->a[i].status[0]);
}
if(g_p->a[i].h[1] > 0 && (g_p->a[i].status[1] == 1 || g_p->a[i].status[1] == -1))
{
weight += (g_p->a[i].weight[1] * g_p->a[i].status[1]);
}
weight += g_p->a[i].weight_convex*2;
if(weight >= 0) continue;
if(weight < min)
{
min = weight;
min_i = i;
}
}
///fprintf(stderr, "*****************min: %f\n", min);
return min_i;
}
double get_cluster_weight_debug(G_partition* g_p, hc_links* link, uint32_t *h, uint32_t h_n)
{
int o_d = 0;
double weight = 0;
uint32_t j, k, m, uID;
for (j = 0, weight = 0; j < h_n; j++)
{
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
if(link->a.a[h[j]].e.a[k].del) continue;
for (m = 0; m < h_n; m++)
{
if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
}
if(m < h_n) continue;
uID = link->a.a[h[j]].e.a[k].uID;
///o_d = get_phase_status(hap, link->a.a[h[j]].e.a[k].uID);
o_d = g_p->a[g_p->index[uID]>>1].status[g_p->index[uID]&1];
///if(o_d < -1) fprintf(stderr, "ERROR\n");
weight += (o_d*link->a.a[h[j]].e.a[k].weight);
}
}
return weight;
}
void flip_unitig(G_partition* g_p, hc_links* link, bubble_type* bub, uint32_t id)
{
if(g_p->a[id].h[0] > 0 && g_p->a[id].status[0] != 1 && g_p->a[id].status[0] != -1) return;
if(g_p->a[id].h[1] > 0 && g_p->a[id].status[1] != 1 && g_p->a[id].status[1] != -1) return;
uint32_t k, j, m, *h0, h0_n, *h1, h1_n, uID, *h = NULL, h_n;
int status;
double weight;
get_phased_block(g_p, NULL, id, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
// fprintf(stderr, "h0_n: %u, h1_n: %u\n", h0_n, h1_n);
if(h0_n > 0)
{
status = g_p->a[id].status[0];
// fprintf(stderr, "+status: %d\n", status);
h = h0; h_n = h0_n;
for (j = 0; j < h_n; j++)
{
// fprintf(stderr, "+j: %u, h_n: %u\n", j, h_n);
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
// fprintf(stderr, "+k: %u, e_n: %u\n", k, (uint32_t)link->a.a[h[j]].e.n);
if(link->a.a[h[j]].e.a[k].del) continue;
for (m = 0; m < h_n; m++)
{
if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
}
// fprintf(stderr, "+m: %u, h_n: %u\n", m, h_n);
if(m < h_n) continue;
uID = link->a.a[h[j]].e.a[k].uID;
weight = link->a.a[h[j]].e.a[k].weight;
if(g_p->index[uID] == (uint32_t)-1) continue;
g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1] -= (2*status*weight);
}
}
g_p->a[id].status[0] *= -1;
}
// fprintf(stderr, "hehehe\n");
if(h1_n > 0)
{
status = g_p->a[id].status[1];
// fprintf(stderr, "-status: %d\n", status);
h = h1; h_n = h1_n;
for (j = 0; j < h_n; j++)
{
// fprintf(stderr, "-j: %u, h_n: %u\n", j, h_n);
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
// fprintf(stderr, "-k: %u, e_n: %u\n", k, (uint32_t)link->a.a[h[j]].e.n);
if(link->a.a[h[j]].e.a[k].del) continue;
for (m = 0; m < h_n; m++)
{
if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
}
// fprintf(stderr, "-m: %u, h_n: %u\n", m, h_n);
if(m < h_n) continue;
uID = link->a.a[h[j]].e.a[k].uID;
// fprintf(stderr, "-uID: %u\n", uID);
weight = link->a.a[h[j]].e.a[k].weight;
if(g_p->index[uID] == (uint32_t)-1) continue;
g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1] -= (2*status*weight);
}
}
g_p->a[id].status[1] *= -1;
}
}
void flip_unitig_debug(G_partition* g_p, hc_links* link, bubble_type* bub, uint32_t id)
{
if(g_p->a[id].h[0] > 0 && g_p->a[id].status[0] != 1 && g_p->a[id].status[0] != -1) return;
if(g_p->a[id].h[1] > 0 && g_p->a[id].status[1] != 1 && g_p->a[id].status[1] != -1) return;
uint32_t k, j, m, *h0, h0_n, *h1, h1_n, uID, *h = NULL, h_n;
int status;
double weight;
get_phased_block(g_p, NULL, id, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
// fprintf(stderr, "h0_n: %u, h1_n: %u\n", h0_n, h1_n);
if(h0_n > 0)
{
status = g_p->a[id].status[0];
// fprintf(stderr, "+status: %d\n", status);
h = h0; h_n = h0_n;
for (j = 0; j < h_n; j++)
{
// fprintf(stderr, "+j: %u, h_n: %u\n", j, h_n);
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
// fprintf(stderr, "+k: %u, e_n: %u\n", k, (uint32_t)link->a.a[h[j]].e.n);
if(link->a.a[h[j]].e.a[k].del) continue;
for (m = 0; m < h_n; m++)
{
if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
}
// fprintf(stderr, "+m: %u, h_n: %u\n", m, h_n);
if(m < h_n) continue;
uID = link->a.a[h[j]].e.a[k].uID;
weight = link->a.a[h[j]].e.a[k].weight;
if(g_p->index[uID] == (uint32_t)-1) continue;
if(id == 19675)
{
fprintf(stderr, "+uID+: %u, e-weight: %f, g_p->index[uID]>>1: %u, status[0]: %d, pre_uID_weight: %f\n",
uID, weight, g_p->index[uID]>>1, status, g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
}
g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1] -= (2*status*weight);
if(id == 19675)
{
fprintf(stderr, "+uID+: %u, new_uID_weight: %f\n", uID,
g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
}
}
}
g_p->a[id].status[0] *= -1;
}
// fprintf(stderr, "hehehe\n");
if(h1_n > 0)
{
status = g_p->a[id].status[1];
// fprintf(stderr, "-status: %d\n", status);
h = h1; h_n = h1_n;
for (j = 0; j < h_n; j++)
{
// fprintf(stderr, "-j: %u, h_n: %u\n", j, h_n);
for (k = 0; k < link->a.a[h[j]].e.n; k++)
{
// fprintf(stderr, "-k: %u, e_n: %u\n", k, (uint32_t)link->a.a[h[j]].e.n);
if(link->a.a[h[j]].e.a[k].del) continue;
for (m = 0; m < h_n; m++)
{
if(h[m] == link->a.a[h[j]].e.a[k].uID) break;
}
// fprintf(stderr, "-m: %u, h_n: %u\n", m, h_n);
if(m < h_n) continue;
uID = link->a.a[h[j]].e.a[k].uID;
// fprintf(stderr, "-uID: %u\n", uID);
weight = link->a.a[h[j]].e.a[k].weight;
if(g_p->index[uID] == (uint32_t)-1) continue;
if(id == 19675)
{
fprintf(stderr, "-uID-: %u, e-weight: %f, g_p->index[uID]>>1: %u, status[1]: %d, pre_uID_weight: %f\n",
uID, weight, g_p->index[uID]>>1, status, g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
}
g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1] -= (2*status*weight);
if(id == 19675)
{
fprintf(stderr, "-uID-: %u, new_uID_weight: %f\n", uID,
g_p->a[g_p->index[uID]>>1].weight[g_p->index[uID]&1]);
}
}
}
g_p->a[id].status[1] *= -1;
}
}
uint32_t phasing_improvement(H_partition* h, G_partition* g_p, ha_ug_index* idx, bubble_type* bub, hc_links* link)
{
uint32_t i, occ = 0, round = 0;
double pre_w, pre_total, current_w;
mul_block_phase_type b_x;
init_mul_block_phase_type(&b_x, g_p, bub, asm_opt.thread_num, h);
///double index_time = yak_realtime();
while(1)
{
pre_w = get_total_weight(h, g_p);
pre_total = pre_w;
while (1)
{
memset(h->lock, 0, sizeof(uint8_t)*g_p->n);
while (1)
{
i = get_max_unitig(h, g_p, link, bub);
if(i == (uint32_t)-1) break;
h->lock[i] = 1;
flip_unitig(g_p, link, bub, i);
occ++;
}
current_w = get_total_weight(h, g_p);
///fprintf(stderr, "[M::%s::round single %u, pre_w: %f, current_w: %f]\n", __func__, round, pre_w, current_w);
if(ceil(current_w) <= ceil(pre_w)) break;
round++;
pre_w = current_w;
}
pre_w = get_total_weight(h, g_p);
round = 0;
while (1)
{
///fprintf(stderr, "[M::%s::round block %u, h->n: %lu]\n", __func__, round, h->n);
phasing_improvement_by_block(h, g_p, bub, &b_x);
current_w = get_total_weight(h, g_p);
///fprintf(stderr, "[M::%s::round block %u, pre_w: %f, current_w: %f]\n", __func__, round, pre_w, current_w);
if(ceil(current_w) <= ceil(pre_w)) break;
round++;
pre_w = current_w;
}
if(ceil(current_w) <= ceil(pre_total)) break;
}
destory_mul_block_phase_type(&b_x);
///fprintf(stderr, "[M::%s:Flipping time:%.3f]\n", __func__, yak_realtime()-index_time);
for (i = 0; i < g_p->n; i++)
{
update_partition_flag(h, g_p, link, i);
}
///print_phase_group(g_p, bub, "Small");
// double w0 = 0, w1 = 0;
// uint32_t *h0, h0_n, *h1, h1_n;
// get_phased_block(g_p, NULL, 2973, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
// w0 = get_cluster_weight_debug(g_p, h->link, h0, h0_n);
// w1 = get_cluster_weight_debug(g_p, h->link, h1, h1_n);
// fprintf(stderr, "debug-w0: %f, g_p->a[2973].weight[0]: %f\n", w0, g_p->a[2973].weight[0]);
// fprintf(stderr, "debug-w1: %f, g_p->a[2973].weight[1]: %f\n", w1, g_p->a[2973].weight[1]);
return !!occ;
}
void destory_contig_partition(H_partition* hap)
{
free(hap->lock);
free(hap->hap);
destory_G_partition(&(hap->g_p));
destory_G_partition(&(hap->group_g_p));
kv_destroy(hap->label_buffer);
kv_destroy(hap->b.vis);
}
void label_unitigs(G_partition* g_p, ma_ug_t* ug)
{
memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads * sizeof(uint8_t));
uint32_t i, k, j, *h0, h0_n, *h1, h1_n, uID, *h = NULL, h_n, flag = AMBIGU;
int status;
ma_utg_t *u = NULL;
for (i = 0; i < g_p->n; i++)
{
if(g_p->a[i].h[0] > 0 && g_p->a[i].status[0] != 1 && g_p->a[i].status[0] != -1) continue;
if(g_p->a[i].h[1] > 0 && g_p->a[i].status[1] != 1 && g_p->a[i].status[1] != -1) continue;
get_phased_block(g_p, NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
status = g_p->a[i].status[0];
h = h0; h_n = h0_n;
if(status == 1)
{
flag = FATHER;
}
else if (status == -1)
{
flag = MOTHER;
}
for (j = 0; j < h_n; j++)
{
uID = h[j];
u = &ug->u.a[uID];
if(u->m == 0) continue;
for (k = 0; k < u->n; k++)
{
R_INF.trio_flag[u->a[k]>>33] = flag;
}
}
status = g_p->a[i].status[1];
h = h1; h_n = h1_n;
if(status == 1)
{
flag = FATHER;
}
else if (status == -1)
{
flag = MOTHER;
}
for (j = 0; j < h_n; j++)
{
uID = h[j];
u = &ug->u.a[uID];
if(u->m == 0) continue;
for (k = 0; k < u->n; k++)
{
R_INF.trio_flag[u->a[k]>>33] = flag;
}
}
}
uint64_t occ = 0;
for (i = 0; i < ug->u.n; i++)
{
occ += ug->u.a[i].n;
}
///fprintf(stderr, "# reads: %lu\n", occ);
for (i = occ = 0; i < R_INF.total_reads; i++)
{
if(R_INF.trio_flag[i] == FATHER) occ++;
}
///fprintf(stderr, "# Father reads: %lu\n", occ);
for (i = occ = 0; i < R_INF.total_reads; i++)
{
if(R_INF.trio_flag[i] == MOTHER) occ++;
}
///fprintf(stderr, "# Mother reads: %lu\n", occ);
}
void label_unitigs_sm(int8_t *s, ma_ug_t* ug)
{
memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads * sizeof(uint8_t));
uint32_t i, k, flag = AMBIGU;
ma_utg_t *u = NULL;
for (i = 0; i < ug->g->n_seq; i++)
{
if(ug->g->seq[i].del || s[i] == 0) continue;
flag = (s[i] > 0? FATHER:MOTHER);
u = &ug->u.a[i];
if(u->m == 0) continue;
for (k = 0; k < u->n; k++)
{
R_INF.trio_flag[u->a[k]>>33] = flag;
}
}
}
void print_bubble_graph(bubble_type* bub, ma_ug_t* ug, const char* prefix, FILE *fp)
{
uint32_t i, k, *a, n, beg, sink, x;
asg_t *b_g = bub->b_g;
char name[32];
for (i = 0; i < b_g->n_seq; i++)
{
get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
sprintf(name, "%s%.6d%c", prefix, i, "fb"[i<bub->f_bub?0:1]);
fprintf(stderr, "S\t%s\t*\tLN:i:%d\n", name, n);
if(beg != (uint32_t)-1) fprintf(stderr, "A\tutg%.6d%c\t%s\n", (beg>>1)+1, "lc"[ug->u.a[(beg>>1)].circ], "beg");
if(sink != (uint32_t)-1) fprintf(stderr, "A\tutg%.6d%c\t%s\n", (sink>>1)+1, "lc"[ug->u.a[(sink>>1)].circ], "sink");
for (k = 0; k < n; k++)
{
x = a[k]>>1;
fprintf(stderr, "A\tutg%.6d%c\t%s\n", x+1, "lc"[ug->u.a[x].circ], "mid");
}
}
asg_arc_t* au = NULL;
uint32_t nu, u, v;
for (i = 0; i < b_g->n_seq; i++)
{
u = i<<1;
au = asg_arc_a(b_g, u);
nu = asg_arc_n(b_g, u);
for (k = 0; k < nu; k++)
{
if(au[k].del) continue;
v = au[k].v;
fprintf(stderr, "L\t%s%.6d%c\t%c\t%s%.6d%c\t%c\t%dM\tL1:i:%d\n",
prefix, u>>1, "fb"[(u>>1)<bub->f_bub?0:1], "+-"[u&1],
prefix, v>>1, "fb"[(v>>1)<bub->f_bub?0:1], "+-"[v&1], 0, 0);
asg_arc_t* av = asg_arc_a(b_g, v^1);
uint32_t nv = asg_arc_n(b_g, v^1), m;
for (m = 0; m < nv; m++)
{
if(av[m].del) continue;
if(av[m].v == (u^1)) break;
}
if(m == nv) fprintf(stderr, "sb1sb, nv: %u, nu: %u\n", nv, nu);
}
u = (i<<1) + 1;
au = asg_arc_a(ug->g, u);
nu = asg_arc_n(ug->g, u);
for (k = 0; k < nu; k++)
{
if(au[k].del) continue;
v = au[k].v;
fprintf(stderr, "L\t%s%.6d%c\t%c\t%s%.6d%c\t%c\t%dM\tL1:i:%d\n",
prefix, u>>1, "fb"[(u>>1)<bub->f_bub?0:1], "+-"[u&1],
prefix, v>>1, "fb"[(v>>1)<bub->f_bub?0:1], "+-"[v&1], 0, 0);
asg_arc_t* av = asg_arc_a(b_g, v^1);
uint32_t nv = asg_arc_n(b_g, v^1), m;
for (m = 0; m < nv; m++)
{
if(av[m].del) continue;
if(av[m].v == (u^1)) break;
}
if(m == nv) fprintf(stderr, "sb2sb, nv: %u, nu: %u\n", nv, nu);
}
}
}
void print_bubble_utg(bubble_type* bub, ma_ug_t* unitig_ug, const char* prefix, FILE *fp)
{
uint32_t i, k, *a, n, beg, sink, x, occ;
ma_ug_t *b_ug = bub->b_ug;
char name[32];
for (i = 0; i < b_ug->u.n; i++)
{
ma_utg_t *p = &b_ug->u.a[i];
if(p->n == 0) continue;
for (k = occ = 0; k < p->n; k++)
{
x = p->a[k]>>33;
get_bubbles(bub, x, &beg, &sink, &a, &n, NULL);
occ += n;
}
sprintf(name, "%s%.6d%c", prefix, i + 1, "lc"[p->circ]);
fprintf(fp, "S\t%s\t*\tLN:i:%u\n", name, occ);
for (k = 0; k < p->n; k++)
{
x = p->a[k]>>33;
get_bubbles(bub, x, &beg, &sink, &a, &n, NULL);
if(beg != (uint32_t)-1) fprintf(fp, "A\tutg%.6d%c\t%u\t%s\n", (beg>>1)+1, "lc"[unitig_ug->u.a[(beg>>1)].circ], n, "beg");
if(sink != (uint32_t)-1) fprintf(fp, "A\tutg%.6d%c\t%u\t%s\n", (sink>>1)+1, "lc"[unitig_ug->u.a[(sink>>1)].circ], n, "sink");
}
}
asg_arc_t* au = NULL;
uint32_t nu, u, v, j;
for (i = 0; i < b_ug->u.n; ++i) {
if(b_ug->u.a[i].m == 0) continue;
if(b_ug->u.a[i].circ)
{
fprintf(fp, "L\t%s%.6dc\t+\t%s%.6dc\t+\t%dM\tL1:i:%d\n",
prefix, i+1, prefix, i+1, 0, 0);
fprintf(fp, "L\t%s%.6dc\t-\t%s%.6dc\t-\t%dM\tL1:i:%d\n",
prefix, i+1, prefix, i+1, 0, 0);
}
u = i<<1;
au = asg_arc_a(b_ug->g, u);
nu = asg_arc_n(b_ug->g, u);
for (j = 0; j < nu; j++)
{
if(au[j].del) continue;
v = au[j].v;
fprintf(fp, "L\t%s%.6d%c\t%c\t%s%.6d%c\t%c\t%dM\tL1:i:%d\n",
prefix, (u>>1)+1, "lc"[b_ug->u.a[u>>1].circ], "+-"[u&1],
prefix, (v>>1)+1, "lc"[b_ug->u.a[v>>1].circ], "+-"[v&1], 0, 0);
}
u = (i<<1) + 1;
au = asg_arc_a(b_ug->g, u);
nu = asg_arc_n(b_ug->g, u);
for (j = 0; j < nu; j++)
{
if(au[j].del) continue;
v = au[j].v;
fprintf(fp, "L\t%s%.6d%c\t%c\t%s%.6d%c\t%c\t%dM\tL1:i:%d\n",
prefix, (u>>1)+1, "lc"[b_ug->u.a[u>>1].circ], "+-"[u&1],
prefix, (v>>1)+1, "lc"[b_ug->u.a[v>>1].circ], "+-"[v&1], 0, 0);
}
}
}
void print_debug_bubble_graph(bubble_type* bub, ma_ug_t* ug, const char *fn)
{
char *buf = (char*)calloc(strlen(fn) + 25, 1);
sprintf(buf, "%s.bub.gfa", fn);
FILE* fp = fopen(buf, "w");
print_bubble_utg(bub, ug, "btg", fp);
fclose(fp);
free(buf);
}
void print_bubble_chain(bubble_type* bub)
{
uint32_t m, i, k;
uint32_t beg, sink, *a = NULL, n;
uint64_t bid;
ma_utg_t *u = NULL;
for (m = 0; m < bub->chain_weight.n; m++)
{
if(bub->chain_weight.a[m].del) continue;
u = &(bub->b_ug->u.a[bub->chain_weight.a[m].id]);
fprintf(stderr, "\nChain_id=%lu\n", bub->chain_weight.a[m].id);
for (i = 0; i < u->n; i++)
{
bid = u->a[i]>>33;
get_bubbles(bub, bid, &beg, &sink, &a, &n, NULL);
fprintf(stderr, "btg%.6lu%c, beg-utg%.6ul, sink-utg%.6ul\n",
bid, "fb"[bid<bub->f_bub?0:1], (beg>>1)+1, (sink>>1)+1);
for (k = 0; k < n; k++)
{
if(k != 0 && (k%5)==0) fprintf(stderr, "\n");
fprintf(stderr, "m-utg%.6ul\t", (a[k]>>1)+1);
}
fprintf(stderr, "\n");
}
}
}
void init_contig_H_partition(bubble_type* bub, ha_ug_index* idx, H_partition* hap)
{
uint32_t i, k_i, k_j, uID, *a = NULL, n, *h0, h0_n, *h1, h1_n;
destory_G_partition(&(hap->group_g_p)); memset(&(hap->group_g_p), 0, sizeof(G_partition));
init_G_partition(&(hap->group_g_p), hap->n);
partition_warp *res = NULL;
ma_utg_t *u_x = NULL;
chain_hic_warp *c_w = &(bub->c_w);
for (i = 0; i < bub->c_w.n; i++)
{
kv_pushp(partition_warp, hap->group_g_p, &res);
kv_init(res->a);
res->full_bub = 0;
res->h[0] = res->h[1] = 0;
res->status[0] = 1; res->status[1] = -1;
res->weight[0] = res->weight[1] = res->weight_convex = 0;
u_x = (*c_w).a[(*c_w).a[i].id].u;
for (k_i = 0; k_i < u_x->n; k_i++)
{
get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
if((*c_w).chain_idx[uID] != (*c_w).a[i].id) continue;
if(get_phase_status(hap, uID)==1)
{
kv_push(uint32_t, res->a, uID);
res->h[0]++;
}
}
}
for (k_i = 0; k_i < u_x->n; k_i++)
{
get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
for (k_j = 0; k_j < n; k_j++)
{
uID = a[k_j]>>1;
if((*c_w).chain_idx[uID] != (*c_w).a[i].id) continue;
if(get_phase_status(hap, uID)==-1)
{
kv_push(uint32_t, res->a, uID);
res->h[1]++;
}
}
}
for (k_i = 0; k_i < res->h[0]; k_i++)
{
///if(hap->group_g_p.index[res->a.a[k_i]] != (uint32_t)-1) fprintf(stderr, "ERROR---00\n");
hap->group_g_p.index[res->a.a[k_i]] = hap->group_g_p.n-1;
hap->group_g_p.index[res->a.a[k_i]] = hap->group_g_p.index[res->a.a[k_i]] << 1;
}
for (; k_i < res->a.n; k_i++)
{
///if(hap->group_g_p.index[res->a.a[k_i]] != (uint32_t)-1) fprintf(stderr, "ERROR---11\n");
hap->group_g_p.index[res->a.a[k_i]] = hap->group_g_p.n-1;
hap->group_g_p.index[res->a.a[k_i]] = (hap->group_g_p.index[res->a.a[k_i]] << 1) + 1;
}
get_phased_block(&(hap->group_g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
if(h0_n >0) res->weight[0] = get_cluster_weight(hap, hap->link, h0, h0_n);
if(h1_n >0) res->weight[1] = get_cluster_weight(hap, hap->link, h1, h1_n);
res->weight_convex = get_cluster_inner_weight(hap, hap->link, h0, h0_n, h1, h1_n);
}
flip_by_node(hap, &(hap->group_g_p), bub);
label_unitigs(&(hap->group_g_p), idx->ug);
}
void reset_H_partition(H_partition* hap, uint32_t is_init)
{
if(!is_init)
{
hap->n = 0;
free(hap->lock);
free(hap->hap);
hap->m[0] = hap->m[1] = hap->m[2] = (uint32_t)-1;
hap->label = hap->label_add = hap->label_shift = (uint32_t)-1;
destory_G_partition(&(hap->g_p)); memset(&(hap->g_p), 0, sizeof(G_partition));
destory_G_partition(&(hap->group_g_p)); memset(&(hap->group_g_p), 0, sizeof(G_partition));
kv_destroy(hap->label_buffer); kv_init(hap->label_buffer);
kv_destroy(hap->b.vis); kv_init(hap->b.vis); memset(&(hap->b), 0, sizeof(block_phase_type));
}
memset(hap, 0, sizeof(H_partition));
}
int alignment_worker_pipeline(sldat_t* sl, const enzyme *fn1, const enzyme *fn2)
{
double index_time = yak_realtime();
int i;
for (i = 0; i < fn1->n && i < fn2->n; i++)
{
gzFile fp1, fp2;
if ((fp1 = gzopen(fn1->a[i], "r")) == 0) return 0;
if ((fp2 = gzopen(fn2->a[i], "r")) == 0) return 0;
sl->ks1 = kseq_init(fp1);
sl->ks2 = kseq_init(fp2);
kt_pipeline(3, worker_pipeline, sl, 3);
kseq_destroy(sl->ks1);
kseq_destroy(sl->ks2);
gzclose(fp1);
gzclose(fp2);
}
fprintf(stderr, "[M::%s::%.3f] ==> Qualification\n", __func__, yak_realtime()-index_time);
dedup_hits(&(sl->hits));
return 1;
}
void debug_gfa_space(ma_ug_t* ug, trans_chain* t_ch, kv_u_trans_t *ref)
{
bubble_type bub;
memset(&bub, 0, sizeof(bubble_type));
bub.round_id = 0; bub.n_round = 2;
identify_bubbles(ug, &bub, t_ch->is_r_het, ref);
hc_links link;
init_hc_links(&link, ug->g->n_seq, t_ch);
measure_distance(ug, NULL, &link, &bub, &(t_ch->k_trans));
// uint32_t i, k;
// for (i = 0; i < link.a.n; ++i)
// {
// for (k = 0; k < link.a.a[i].e.n; k++)
// {
// if(link.a.a[i].e.a[k].del || link.a.a[i].e.a[k].dis == (uint64_t)-1) continue;
// fprintf(stderr, "s-utg%.6dl\td-utg%.6dl\t%lu\n",
// (int)(i+1), (int)(link.a.a[i].e.a[k].uID+1),
// link.a.a[i].e.a[k].dis == (uint64_t)-1? (uint64_t)-1 : link.a.a[i].e.a[k].dis>>3);
// }
// }
destory_bubbles(&bub);
destory_hc_links(&link);
}
void idx_hc_links(kvec_pe_hit* hits, ha_ug_index* idx, bubble_type* bub)
{
uint64_t k, l;
uint32_t qn, tn;
kv_resize(uint64_t, hits->idx, idx->ug->g->n_seq);
hits->idx.n = idx->ug->g->n_seq;
memset(hits->idx.a, 0, hits->idx.n*sizeof(uint64_t));
kv_resize(uint64_t, hits->occ, idx->ug->g->n_seq);
hits->occ.n = idx->ug->g->n_seq;
memset(hits->occ.a, 0, hits->occ.n*sizeof(uint64_t));
radix_sort_pe_hit_idx_an1(hits->a.a, hits->a.a + hits->a.n);
for (k = 1, l = 0; k <= hits->a.n; ++k)
{
if (k == hits->a.n ||
((hits->a.a[k].s<<1)>>(64 - idx->uID_bits)) != ((hits->a.a[l].s<<1)>>(64 - idx->uID_bits)))
{
if (k - l > 1) radix_sort_pe_hit_idx_an2(hits->a.a + l, hits->a.a + k);
hits->idx.a[((hits->a.a[l].s<<1)>>(64 - idx->uID_bits))]
= (uint64_t)l << 32 | (k - l);
for (; l < k; l++)
{
qn = ((hits->a.a[l].s<<1)>>(64 - idx->uID_bits));
tn = ((hits->a.a[l].e<<1)>>(64 - idx->uID_bits));
if(IF_HOM(qn, *bub)) continue;
if(IF_HOM(tn, *bub)) continue;
hits->occ.a[qn]++;
hits->occ.a[tn]++;
}
l = k;
}
}
}
inline uint32_t trans_checking_pass(bubble_type* bub, kv_u_trans_t *ref, uint32_t x, uint32_t y)
{
if(u_trans_n(*ref, x) == 0 || u_trans_n(*ref, y) == 0) return 0;
u_trans_t *a = NULL;
uint32_t n, i, f[2], qn, tn;
qn = x; tn = y;
a = u_trans_a(*ref, qn); n = u_trans_n(*ref, qn);
for (i = 0, f[0] = f[1] = 0; i < n; i++)
{
if(a[i].del) continue;
if(a[i].f == RC_2) continue;
if(IF_HOM(a[i].tn, *bub)) continue;
f[(a[i].tn == tn && a[i].f != RC_2)]++;
}
if(f[0] != 0) return 0;
if(f[1] == 0) return 0;
qn = y; tn = x;
a = u_trans_a(*ref, qn); n = u_trans_n(*ref, qn);
for (i = 0, f[0] = f[1] = 0; i < n; i++)
{
if(a[i].del) continue;
if(IF_HOM(a[i].tn, *bub)) continue;
f[(a[i].tn == tn && a[i].f != RC_2)]++;
}
if(f[0] != 0) return 0;
if(f[1] == 0) return 0;
fprintf(stderr, "M::%s::s-utg%.6ul<----->d-utg%.6ul\n", __func__, x+1, y+1);
return 1;
}
void weight_kv_u_trans(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub,
kv_u_trans_t *ta, trans_idx* dis)
{
uint64_t k, i, shif = 64 - idx->uID_bits, beg, end, t_d;
u_trans_t *e1 = NULL, *e2 = NULL;
long double weight;
u_trans_t *p = NULL;
for (i = 0, ta->idx.n = ta->n = 0; i < link->a.n; i++)
{
for (k = 0; k < link->a.a[i].e.n; k++)
{
if(link->a.a[i].e.a[k].del) continue;
if(IF_HOM(i, *bub)) continue;
if(IF_HOM(link->a.a[i].e.a[k].uID, *bub)) continue;
if(i == link->a.a[i].e.a[k].uID) continue;
kv_pushp(u_trans_t, *ta, &p);
memset(p, 0, sizeof(u_trans_t));
p->qn = i; p->tn = link->a.a[i].e.a[k].uID;
p->nw = 0; p->occ = 0;
}
}
kt_u_trans_t_idx(ta, idx->ug->g->n_seq);
for (k = 0; k < hits->a.n; ++k)
{
beg = ((hits->a.a[k].s<<1)>>shif);
end = ((hits->a.a[k].e<<1)>>shif);
if(beg == end) continue;
if(IF_HOM(beg, *bub)) continue;
if(IF_HOM(end, *bub)) continue;
t_d = get_hic_distance(&(hits->a.a[k]), link, idx);
if(t_d == (uint64_t)-1) continue;
get_u_trans_spec(ta, beg, end, &e1, NULL);
get_u_trans_spec(ta, end, beg, &e2, NULL);
if(e1 == NULL || e2 == NULL) continue;
weight = 1;
if(dis) weight = get_trans_weight_advance(idx, t_d, dis);
e1->nw -= weight; e1->occ++;
e2->nw -= weight; e2->occ++;
}
}
void interpr_hit(ha_ug_index* idx, uint64_t x, uint32_t rLen, uint32_t *uid, uint32_t *beg, uint32_t *end)
{
if(uid) (*uid) = ((x<<1)>>(64 - idx->uID_bits));
uint32_t rev = (x>>63);
long long ref_p = x & idx->pos_mode;
long long p_beg, p_end;
if(rev)
{
p_end = ref_p;
p_beg = p_end + 1 - rLen;
}
else
{
p_beg = ref_p;
p_end = p_beg + rLen - 1;
}
if(p_beg < 0) p_beg = 0;
if(p_end < 0) p_end = 0;
if(beg) (*beg) = p_beg;
if(end) (*end) = p_end + 1;
}
double get_interval_weight(ha_ug_index* idx, hc_links* link, trans_idx* dis,
pe_hit *hits, uint32_t occ, uint32_t qid, uint32_t qs, uint32_t qe, uint32_t tid, uint32_t ts, uint32_t te)
{
int64_t s_idx = 0, e_idx = (int64_t)occ - 1, m_idx = 0;
uint32_t m_uid = (uint32_t)-1;
while (s_idx <= e_idx)
{
m_idx = s_idx + (e_idx - s_idx)/2;
m_uid = ((hits[m_idx].e<<1)>>(64 - idx->uID_bits));
if (m_uid == tid)
break;
if (m_uid < tid)
s_idx = m_idx + 1;
else
e_idx = m_idx - 1;
}
if(m_uid != tid) return 0;
uint32_t k, s_uid, s_beg, s_end, e_uid, e_beg, e_end;
uint64_t t_d;
double w, weight;
w = 0;
for (k = m_idx; k < occ; k++)///all hits of qid
{
interpr_hit(idx, hits[k].s, hits[k].len>>32, &s_uid, &s_beg, &s_end);
if(s_uid != qid) continue;
if(!(qs <= s_beg && qe >= s_end)) continue;
interpr_hit(idx, hits[k].e, (uint32_t)hits[k].len, &e_uid, &e_beg, &e_end);
if(e_uid != tid) break;
if(!(ts <= e_beg && te >= e_end)) continue;
t_d = get_hic_distance(&hits[k], link, idx);
if(t_d == (uint64_t)-1) continue;
weight = 1;
if(dis) weight = get_trans_weight_advance(idx, t_d, dis);
w += weight;
}
for (m_idx -= 1; m_idx >= 0; m_idx--)
{
k = m_idx;
interpr_hit(idx, hits[k].s, hits[k].len>>32, &s_uid, &s_beg, &s_end);
if(s_uid != qid) continue;
if(!(qs <= s_beg && qe >= s_end)) continue;
interpr_hit(idx, hits[k].e, (uint32_t)hits[k].len, &e_uid, &e_beg, &e_end);
if(e_uid != tid) break;
if(!(ts <= e_beg && te >= e_end)) continue;
t_d = get_hic_distance(&hits[k], link, idx);
if(t_d == (uint64_t)-1) continue;
weight = 1;
if(dis) weight = get_trans_weight_advance(idx, t_d, dis);
w += weight;
}
return w;
}
double get_hits_weight(ha_ug_index* idx, bubble_type* bub, kvec_pe_hit* hits, hc_links* link, trans_idx* dis,
u_trans_t *t_a, uint32_t t_n, uint32_t qid, kv_u_trans_t *ta_idx)
{
/****************************may have bugs********************************/
///need to record self hits
///if(u_trans_n(*ta_idx, qid) == 0) return 0;///no hit bridging qid
/****************************may have bugs********************************/
uint32_t k, i, x_n, y;
u_trans_t *x_a = NULL;
double occ_q, occ_t;
double w, i_w;
for (k = 0, w = 0; k < t_n; k++)
{
if(IF_HOM(qid, *bub)) continue;
if(IF_HOM(t_a[k].tn, *bub)) continue;
/****************************may have bugs********************************/
if(qid != t_a[k].tn)
{
x_n = u_trans_n(*ta_idx, qid); x_a = u_trans_a(*ta_idx, qid); y = t_a[k].tn;
if(u_trans_n(*ta_idx, t_a[k].tn) < x_n)
{
x_n = u_trans_n(*ta_idx, t_a[k].tn); x_a = u_trans_a(*ta_idx, t_a[k].tn); y = qid;
}
if(x_n == 0) continue;
for (i = 0; i < x_n; i++)
{
if(x_a[i].tn == y) break;
}
if(i >= x_n) continue; ///no hit bridging tn and qid
}
/****************************may have bugs********************************/
occ_q = hits->occ.a[qid];
occ_t = hits->occ.a[t_a[k].tn] * ((double)(t_a[k].te - t_a[k].ts) / (double)(idx->ug->g->seq[t_a[k].tn].len));
if(occ_t < 1) occ_t = 1;
///q--->t hits
i_w = get_interval_weight(idx, link, dis, hits->a.a + (hits->idx.a[qid]>>32),
(uint32_t)(hits->idx.a[qid]), qid, 0, idx->ug->g->seq[qid].len, t_a[k].tn,
t_a[k].ts, t_a[k].te);
if(i_w != 0) i_w /= (MIN(occ_q, occ_t));
w += i_w;
if(t_a[k].tn == qid) continue;
///t--->q hits
i_w = get_interval_weight(idx, link, dis, hits->a.a + (hits->idx.a[t_a[k].tn]>>32),
(uint32_t)(hits->idx.a[t_a[k].tn]), t_a[k].tn, t_a[k].ts, t_a[k].te,
qid, 0, idx->ug->g->seq[qid].len);
if(i_w != 0) i_w /= (MIN(occ_q, occ_t));
w += i_w;
}
return w;
}
void adjust_weight_kv_u_trans(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub,
kv_u_trans_t *ta, kv_u_trans_t *ref, trans_idx* dis)
{
u_trans_t *a = NULL, *p = NULL;
uint32_t n, k, i, m, qn, tn;
uint8_t *vis = NULL; CALLOC(vis, idx->ug->g->n_seq);
double w;
for (i = m = 0; i < ta->n; i++)
{
if(ta->a[i].del) continue;
if(IF_HOM(ta->a[i].qn, *bub)) continue;
if(IF_HOM(ta->a[i].tn, *bub)) continue;
ta->a[m] = ta->a[i];
if(ta->a[m].nw != 0)
{
ta->a[m].nw /= (double)(MIN(hits->occ.a[ta->a[m].qn], hits->occ.a[ta->a[m].tn]));
}
/*******************************for debug************************************/
// trans_checking_pass(bub, ref, ta->a[i].qn, ta->a[i].tn);
// if(trans_checking_pass(bub, ref, ta->a[i].qn, ta->a[i].tn)) ta->a[m].nw = 0;
/*******************************for debug************************************/
m++;
}
ta->n = m;
for (k = 0; k < ta->idx.n; k++)///all nodes
{
if(IF_HOM(k, *bub)) continue;
a = u_trans_a(*ta, k);
n = u_trans_n(*ta, k);
///for each pair qn, tn
///count hic pairs between (qn, tn^) and (qn^1, tn)
for (i = 0, vis[k] = 1; i < n; i++)
{
vis[a[i].tn] = 1;
if(a[i].qn == a[i].tn) continue;
if(IF_HOM(a[i].qn, *bub)) continue;
if(IF_HOM(a[i].tn, *bub)) continue;
///(qn, tn^)
a[i].nw += get_hits_weight(idx, bub, hits, link, dis,
u_trans_a(*ref, a[i].tn), u_trans_n(*ref, a[i].tn), a[i].qn, ta);
///(qn^1, tn)
a[i].nw += get_hits_weight(idx, bub, hits, link, dis,
u_trans_a(*ref, a[i].qn), u_trans_n(*ref, a[i].qn), a[i].tn, ta);
}
for (i = 0; i < ta->idx.n; i++)///all edges
{
qn = k; tn = i; w = 0;
if(IF_HOM(qn, *bub)) continue;
if(IF_HOM(tn, *bub)) continue;
if(vis[tn]) continue;
if(qn == tn) continue;
///(qn, tn^)
w += get_hits_weight(idx, bub, hits, link, dis,
u_trans_a(*ref, tn), u_trans_n(*ref, tn), qn, ta);
///(qn^1, tn)
w += get_hits_weight(idx, bub, hits, link, dis,
u_trans_a(*ref, qn), u_trans_n(*ref, qn), tn, ta);
if(w == 0) continue;
kv_pushp(u_trans_t, *ta, &p);
memset(p, 0, sizeof(u_trans_t));///extra edges
p->nw = w; p->qn = qn; p->tn = tn;
}
// for (i = 0; i < u_trans_n(*ref, k); i++)///only trans edges
// {
// qn = k; tn = (u_trans_a(*ref, k))[i].tn; w = 0;
// if(IF_HOM(qn, *bub)) continue;
// if(IF_HOM(tn, *bub)) continue;
// if(vis[tn]) continue;
// if(qn == tn) continue;
// ///(qn, tn^)
// w += get_hits_weight(idx, hits, link, dis,
// u_trans_a(*ref, tn), u_trans_n(*ref, tn), qn, ta);
// ///(qn^1, tn)
// w += get_hits_weight(idx, hits, link, dis,
// u_trans_a(*ref, qn), u_trans_n(*ref, qn), tn, ta);
// if(w == 0) continue;
// kv_pushp(u_trans_t, *ta, &p);
// memset(p, 0, sizeof(u_trans_t));///extra edges
// p->nw = w; p->qn = qn; p->tn = tn;
// }
for (i = 0, vis[k] = 0; i < n; i++) vis[a[i].tn] = 0;
}
// fprintf(stderr, "------ta->n=%u\n", (uint32_t)ta->n);
for (i = m = 0; i < ta->n; i++)
{
if(ta->a[i].nw == 0 || ta->a[i].del) continue;
ta->a[m] = ta->a[i];
m++;
}
ta->n = m;
free(vis);
kt_u_trans_t_idx(ta, idx->ug->g->n_seq);
}
inline uint32_t get_trans_interval_weight(ha_ug_index* idx, hc_links* link, bubble_type* bub,
trans_idx* dis, pe_hit *hit, uint32_t hit_n, uint32_t qn, uint32_t qs, uint32_t qe, uint32_t tn,
uint32_t ts, uint32_t te, double *w_a)
{
uint32_t i, s_uid, s_beg, s_end, e_uid, e_beg, e_end, found;
uint64_t t_d;
double weight;
(*w_a) = 0; found = 0;
for (i = 0; i < hit_n; i++)///all hits already have the same qn and tn
{
interpr_hit(idx, hit[i].s, hit[i].len>>32, &s_uid, &s_beg, &s_end);
if(s_uid != qn) continue;
if(!(qs <= s_beg && qe >= s_end)) continue;
interpr_hit(idx, hit[i].e, (uint32_t)hit[i].len, &e_uid, &e_beg, &e_end);
if(e_uid != tn) continue;
if(!(ts <= e_beg && te >= e_end)) continue;
t_d = get_hic_distance(&hit[i], link, idx);
if(t_d == (uint64_t)-1) continue;
weight = 1;
if(dis) weight = get_trans_weight_advance(idx, t_d, dis);
(*w_a) += weight;
found = 1;
}
return found;
}
void append_trans_hits(ha_ug_index* idx, hc_links* link, bubble_type* bub,
trans_idx* dis, pe_hit *hit, uint32_t hit_n, uint64_t *hit_occ, kv_u_trans_t *ref,
kv_u_trans_t *res, uint32_t qn, uint32_t tn)
{
u_trans_t *r_a = NULL, *p = NULL, *q = NULL;
uint32_t r_n, i;
uint64_t occ_q, occ_t;
double w;
///qn -> tn^
{
r_a = u_trans_a(*ref, tn);
r_n = u_trans_n(*ref, tn);
for (i = 0; i < r_n; i++)
{
if(IF_HOM(r_a[i].tn, *bub)) continue;
if(r_a[i].tn == qn) continue;
if(!get_trans_interval_weight(idx, link, bub, dis, hit, hit_n,
qn, 0, idx->ug->g->seq[qn].len, tn, r_a[i].qs, r_a[i].qe, &w))
{
continue;
}
occ_q = hit_occ[qn];
occ_t = (hit_occ[tn] * ((double)(r_a[i].qe - r_a[i].qs)/(double)(idx->ug->g->seq[tn].len))) + 0.5;
if(occ_t < 1) occ_t = 1;
kv_pushp(u_trans_t, *res, &p);
memset(p, 0, sizeof(u_trans_t));
p->qn = qn; p->tn = r_a[i].tn;
p->nw = w;
p->occ = MIN(occ_q, occ_t);
kv_pushp(u_trans_t, *res, &q);
(*q) = (*p); q->qn = p->tn; q->tn = p->qn;
}
}
if(qn == tn) return;
///tn -> qn^
{
r_a = u_trans_a(*ref, qn);
r_n = u_trans_n(*ref, qn);
for (i = 0; i < r_n; i++)
{
if(IF_HOM(r_a[i].tn, *bub)) continue;
if(r_a[i].tn == tn) continue;
if(!get_trans_interval_weight(idx, link, bub, dis, hit, hit_n,
qn, r_a[i].qs, r_a[i].qe, tn, 0, idx->ug->g->seq[tn].len, &w))
{
continue;
}
occ_q = (hit_occ[qn] * ((double)(r_a[i].qe - r_a[i].qs)/(double)(idx->ug->g->seq[qn].len))) + 0.5;
occ_t = hit_occ[tn];
if(occ_q < 1) occ_q = 1;
kv_pushp(u_trans_t, *res, &p);
memset(p, 0, sizeof(u_trans_t));
p->qn = tn; p->tn = r_a[i].tn;
p->nw = w;
p->occ = MIN(occ_q, occ_t);
kv_pushp(u_trans_t, *res, &q);
(*q) = (*p); q->qn = p->tn; q->tn = p->qn;
}
}
}
double merge_u_trans_list(u_trans_t* a, uint32_t a_n)
{
radix_sort_u_trans_occ(a, a + a_n);
uint32_t k, l, i;
double weight, w = 0;
for (k = 1, l = 0; k <= a_n; ++k)
{
if (k == a_n || a[k].occ != a[l].occ)
{
for (i = l, weight = 0; i < k; i++)
{
weight += a[i].nw;
}
w += (weight/(double)(a[l].occ));
l = k;
}
}
return w;
}
void adjust_weight_kv_u_trans_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub,
kv_u_trans_t *ta, kv_u_trans_t *ref, trans_idx* dis)
{
double index_time = yak_realtime();
uint32_t k, l, m, h_occ;
uint64_t shif = 64 - idx->uID_bits, qn, tn;
double w;
pe_hit *h_a = NULL;
for (k = m = 0; k < ta->n; k++)
{
if(ta->a[k].nw == 0) continue;
ta->a[k].occ = MIN(hits->occ.a[ta->a[k].qn], hits->occ.a[ta->a[k].tn]);
if(ta->a[k].occ == 0) continue;
ta->a[m] = ta->a[k];
m++;
}
ta->n = m;
for (qn = 0; qn < hits->idx.n; qn++)
{
if(IF_HOM(qn, *bub)) continue;
h_a = hits->a.a + (hits->idx.a[qn]>>32);
h_occ = (uint32_t)(hits->idx.a[qn]);
for (k = 1, l = 0; k <= h_occ; ++k) ///same qn
{
if (k == h_occ || ((h_a[k].e<<1)>>shif) != ((h_a[l].e<<1)>>shif)) //same qn and tn
{
tn = ((h_a[l].e<<1)>>shif);
if(!IF_HOM(tn, *bub))
{
append_trans_hits(idx, link, bub, dis, h_a+l, k-l, hits->occ.a, ref, ta, qn, tn);
}
l = k;
}
}
}
radix_sort_u_trans_m(ta->a, ta->a + ta->n);
for (k = 1, l = 0, m = 0; k <= ta->n; ++k)
{
if (k == ta->n || (ta->a[k].qn != ta->a[l].qn || ta->a[k].tn != ta->a[l].tn))
{
w = merge_u_trans_list(ta->a + l, k - l);
if(w != 0)
{
ta->a[m] = ta->a[l];
ta->a[m].nw = w;
ta->a[m].occ = 0;
m++;
}
l = k;
}
}
ta->n = m;
kt_u_trans_t_idx(ta, idx->ug->g->n_seq);
fprintf(stderr, "[M::%s::%.3f] \n", __func__, yak_realtime()-index_time);
}
void print_kv_weight(kv_u_trans_t *ta)
{
uint32_t i;
u_trans_t *e = NULL;
fprintf(stderr, "*********ta->n: %u\n", (uint32_t)ta->n);
for (i = 0; i < ta->n; i++)
{
fprintf(stderr, "+qn(%u)->tn(%u): %f\n", ta->a[i].qn, ta->a[i].tn, ta->a[i].nw);
get_u_trans_spec(ta, ta->a[i].tn, ta->a[i].qn, &e, NULL);
if(e)
{
fprintf(stderr, "-tn(%u)->qn(%u): %f\n", e->qn, e->tn, e->nw);
}
else
{
fprintf(stderr, "ERROR");
}
}
}
void renew_kv_u_trans(kv_u_trans_t *ta, hc_links *lk, kvec_pe_hit* hits, kv_u_trans_t *ref,
ha_ug_index* idx, bubble_type* bub, int8_t *s, uint32_t ignore_dis)
{
uint64_t k, i, m, is_comples_weight = 0;
trans_idx dis;
kv_init(dis);
if(bub->round_id > 0 && ignore_dis == 0)
{
is_comples_weight = get_trans_rate_function_advance(idx, hits, lk, bub, NULL, s, &dis);
}
for (i = 0; i < lk->a.n; i++)
{
for (k = m = 0; k < lk->a.a[i].e.n; k++)
{
if(lk->a.a[i].e.a[k].del) continue;
lk->a.a[i].e.a[m] = lk->a.a[i].e.a[k];
lk->a.a[i].e.a[m].weight = 0;
lk->a.a[i].e.a[m].occ = 0;
m++;
}
lk->a.a[i].e.n = m;
}
if(hits->idx.n == 0) idx_hc_links(hits, idx, bub);
weight_kv_u_trans(idx, hits, lk, bub, ta, is_comples_weight == 1? &dis : NULL);
// adjust_weight_kv_u_trans(idx, hits, lk, bub, ta, ref, is_comples_weight == 1? &dis : NULL);
adjust_weight_kv_u_trans_advance(idx, hits, lk, bub, ta, ref, is_comples_weight == 1? &dis : NULL);
kv_destroy(dis);
// print_kv_weight(ta);
}
void print_kv_u_trans(kv_u_trans_t *ta, hc_links* lk, int8_t *s)
{
uint32_t i;
u_trans_t *p = NULL;
hc_edge *e = NULL;
for (i = 0; i < ta->n; i++)
{
p = &(ta->a[i]);
e = get_hc_edge(lk, p->qn, p->tn, 0);
fprintf(stderr, "s-utg%.6ul\tS(%d)\td-utg%.6ul\tS(%d)\trev(%u)\td(%lld)\ttw(%f)\n",
p->qn+1, s[p->qn], p->tn+1, s[p->tn], p->rev,
(e == NULL || e->dis == (uint64_t)-1)? -1 : (long long)(e->dis>>3), p->nw);
}
}
ps_t* init_ps_t(uint64_t seed, uint64_t n)
{
ps_t *s = NULL; CALLOC(s, 1);
s->xs = seed;
CALLOC(s->s, n);
return s;
}
void destory_ps_t(ps_t **s)
{
free((*s)->s);
free((*s));
}
void verbose_het_stat(bubble_type *bub)
{
uint64_t i, hetBase = 0, homBase = 0;
for (i = 0; i < bub->ug->g->n_seq; i++)
{
if(IF_HOM(i, *bub)) homBase += bub->ug->g->seq[i].len;
else hetBase += bub->ug->g->seq[i].len;
}
fprintf(stderr, "[M::stat] # heterozygous bases: %lu; # homozygous bases: %lu\n", hetBase, homBase);
}
int hic_short_align(const enzyme *fn1, const enzyme *fn2, ha_ug_index* idx)
{
double index_time = yak_realtime();
sldat_t sl;
kvec_hc_edge back_hc_edge;
kv_init(back_hc_edge.a);
sl.idx = idx;
sl.t_ch = idx->t_ch;
sl.chunk_size = 20000000;
sl.n_thread = asm_opt.thread_num;
sl.total_base = sl.total_pair = 0;
idx->hap_cnt = asm_opt.hap_occ;
kv_init(sl.hits.a); kv_init(sl.hits.idx); kv_init(sl.hits.occ);
if(!load_hc_hits(&sl.hits, asm_opt.output_file_name))
{
alignment_worker_pipeline(&sl, fn1, fn2);
write_hc_hits(&sl.hits, asm_opt.output_file_name);
}
///debug_hc_hits_v14(&sl.hits, asm_opt.output_file_name, sl.idx);
////dedup_hits(&(sl.hits), sl.idx);
///write_hc_hits_v14(&sl.hits, asm_opt.output_file_name);
hc_links link;
init_hc_links(&link, idx->ug->g->n_seq, idx->t_ch);
///H_partition hap;
bubble_type bub;
kv_u_trans_t k_trans;
kv_init(k_trans); kv_init(k_trans.idx);
ps_t *s = init_ps_t(11, idx->ug->g->n_seq);
mb_nodes_t u;
kv_init(u.bid); kv_init(u.idx); kv_init(u.u);
memset(&bub, 0, sizeof(bubble_type));
bub.round_id = 0; bub.n_round = asm_opt.n_weight;
for (bub.round_id = 0; bub.round_id < bub.n_round; bub.round_id++)
{
identify_bubbles(idx->ug, &bub, idx->t_ch->is_r_het, &(idx->t_ch->k_trans));
if(bub.round_id == 0)
{
measure_distance(idx->ug, &sl.hits, &link, &bub, &(idx->t_ch->k_trans));
}
renew_kv_u_trans(&k_trans, &link, &sl.hits, &(idx->t_ch->k_trans), idx, &bub, s->s, 0);
// if(bub.round_id == 0) init_phase(idx, &k_trans, &bub, s);
update_trans_g(idx, &k_trans, &bub);
/*******************************for debug************************************/
mc_solve(NULL, NULL, &k_trans, idx->ug, idx->read_g, 0.8, R_INF.trio_flag,
(bub.round_id == 0? 1 : 0), s->s, 1, /**&bub**/NULL, &(idx->t_ch->k_trans));
/*******************************for debug************************************/
label_unitigs_sm(s->s, idx->ug);
/**
init_hic_advance((ha_ug_index*)sl.idx, &sl.hits, &link, &bub, &hap, 0);
reset_H_partition(&hap, (bub.round_id == 0? 1 : 0));
init_contig_partition(&hap, idx, &bub, &link);
phasing_improvement(&hap, &(hap.g_p), idx, &bub, &link);
label_unitigs(&(hap.g_p), idx->ug);
**/
}
verbose_het_stat(&bub);
///print_hc_links(&link, 0, &hap);
// print_kv_u_trans(&k_trans, &link, s->s);
///print_bubbles(idx->ug, &bub, sl.hits.a.n?&sl.hits:NULL, idx->link, idx);
///print_hits(idx, &sl.hits, fn1);
///print_debug_bubble_graph(&bub, idx->ug, asm_opt.output_file_name);
// print_bubble_chain(&bub);
// destory_contig_partition(&hap);
kv_destroy(back_hc_edge.a);
kv_destroy(sl.hits.a);
kv_destroy(sl.hits.idx);
kv_destroy(sl.hits.occ);
destory_hc_links(&link);
kv_destroy(k_trans);
kv_destroy(k_trans.idx);
destory_ps_t(&s);
kv_destroy(u.bid); kv_destroy(u.idx); kv_destroy(u.u);
return 1;
print_bubbles(idx->ug, &bub, sl.hits.a.n?&sl.hits:NULL, &link, idx);
collect_hc_reverse_links(&link, idx->ug, &bub);
normalize_hc_links(&link);
min_cut_t* cut = clean_hap(&link, &bub, idx->ug);
///print_bubbles(idx->ug, &bub, NULL, &link, idx);
G_partition* gp = clean_bubbles(&link, &bub, cut, idx->ug);
///print_hc_links(&link);
destory_min_cut_t(cut); free(cut);
destory_G_partition(gp); free(gp);
destory_bubbles(&bub);
fprintf(stderr, "[M::%s::%.3f] processed %lu pairs; %lu bases\n", __func__, yak_realtime()-index_time, sl.total_pair, sl.total_base);
return 1;
}
void hic_analysis(ma_ug_t *ug, asg_t* read_g, trans_chain* t_ch)
{
ug_index = NULL;
int exist = (asm_opt.load_index_from_disk?
load_hc_pt_index(&ug_index, asm_opt.output_file_name) : 0);
if(exist == 0) ug_index = build_unitig_index(ug, asm_opt.hic_mer_length);
if(exist == 0) write_hc_pt_index(ug_index, asm_opt.output_file_name);
ug_index->ug = ug;
ug_index->read_g = read_g;
ug_index->t_ch = t_ch;
///test_unitig_index(ug_index, ug);
hic_short_align(asm_opt.hic_reads[0], asm_opt.hic_reads[1], ug_index);
destory_hc_pt_index(ug_index);
}
typedef struct{
//[uID_start, uID_end)
uint64_t uID_start;
uint64_t uID_end;
uint64_t u_n;
uint64_t r_n;
uint64_t* r_idx;
} bench_utg;
typedef struct{
uint64_t s, e;
}homo_interval;
typedef struct{
kvec_t(bench_utg) ug_idx;
uint64_t uID_bits;
uint64_t pos_mode;
hc_links link;
kvec_t(homo_interval) regions;
}bench_idx;
uint64_t* set_bench_idx(ma_ug_t *ug, asg_t* read_g, uint64_t uID_start, uint64_t uID_end, uint64_t uID_bits, uint64_t r_n)
{
uint64_t *idx = (uint64_t*)malloc(sizeof(uint64_t)*r_n), i, k;
memset(idx, -1, sizeof(uint64_t)*r_n);
uint64_t rId, ori, start, l;
ma_utg_t *u = NULL;
for (i = uID_start; i < uID_end; i++)
{
u = &(ug->u.a[i]);
if(u->n == 0) continue;
for (k = l = 0; k < u->n; k++)
{
rId = u->a[k]>>33;
ori = u->a[k]>>32&1;
start = l;
l += (uint32_t)u->a[k];
if(idx[rId] != (uint64_t)-1)
{
idx[rId] = (uint64_t)-1;
}
else
{
idx[rId] = (ori<<63) + ((i<<(64-uID_bits))>>1) + start;
if(ori) idx[rId] = idx[rId] + read_g->seq[rId].len - 1;
}
}
}
return idx;
}
void get_r_utg_bench(uint64_t index, bench_idx* idx, ma_ug_t *ug)
{
bench_utg* a_list = idx->ug_idx.a;
uint64_t a_n = idx->ug_idx.n;
bench_utg *x = &(a_list[index]), *y = NULL;
uint64_t i, k, t, rev, x_uid, y_uid, y_pos, x_pos, d;
uint64_t rId, ori;
ma_utg_t *u = NULL;
for (i = x->uID_start; i < x->uID_end; i++)
{
u = &(ug->u.a[i]);
x_uid = i;
if(u->n == 0) continue;
for (k = 0; k < u->n; k++)
{
rId = u->a[k]>>33;
ori = u->a[k]>>32&1;
if(x->r_idx[rId] == (uint64_t)-1) continue;
x_pos = x->r_idx[rId] & idx->pos_mode;
for (t = 0; t < a_n; t++)
{
if(t == index) continue;
y = &(a_list[t]);
if(y->r_idx[rId] == (uint64_t)-1) continue;
rev = 0;
if((y->r_idx[rId]>>63) != ori) rev = 1;
y_uid = (y->r_idx[rId]<<1)>>(64 - idx->uID_bits);
y_pos = y->r_idx[rId] & idx->pos_mode;
if(rev) y_pos = ug->u.a[y_uid].len - y_pos - 1;
///if(ori) x_pos = ug->u.a[x_uid].len - x_pos - 1, y_pos = ug->u.a[y_uid].len - y_pos - 1;
d = MAX(x_pos, y_pos) - MIN(x_pos, y_pos);
d = (d<<2) + (rev<<1);
if(y_pos > x_pos) d = d + 1;
push_hc_edge(&(idx->link.a.a[x_uid]), y_uid, 1, 0, &d);
if(x_pos != y_pos) d = d ^ 1;
push_hc_edge(&(idx->link.a.a[y_uid]), x_uid, 1, 0, &d);
}
}
}
}
void hap_ID(bench_idx* idx, uint64_t ID, uint64_t* hapID, uint64_t* uID)
{
uint64_t i;
(*hapID) = (*uID) = (uint64_t)-1;
for (i = 0; i < idx->ug_idx.n; i++)
{
if(ID >= idx->ug_idx.a[i].uID_start && ID < idx->ug_idx.a[i].uID_end)
{
(*hapID) = i;
(*uID) = ID - idx->ug_idx.a[i].uID_start;
return;
}
}
return;
}
void print_bench_idx(bench_idx* idx, ma_ug_t *ug)
{
uint64_t i, k, s_uID, s_hapID, d_uID, d_hapID;
long long x[2] = {1, -1};
for (i = 0; i < idx->link.a.n; i++)
{
for (k = 0; k < idx->link.a.a[i].e.n; k++)
{
if(idx->link.a.a[i].e.a[k].del) continue;
hap_ID(idx, i, &s_hapID, &s_uID);
hap_ID(idx, idx->link.a.a[i].e.a[k].uID, &d_hapID, &d_uID);
fprintf(stderr, "s-hap%lu-utg%.6d\td-hap%lu-utg%.6d\t%c\t%lld\n",
s_hapID, (int)(s_uID+1), d_hapID, (int)(d_uID+1),
"+-"[!!(idx->link.a.a[i].e.a[k].dis&(uint64_t)2)],
((long long)(idx->link.a.a[i].e.a[k].dis>>2))*x[idx->link.a.a[i].e.a[k].dis&(uint64_t)1]);
}
}
}
uint64_t get_hic_distance_bench_hap(pe_hit_hap* hit, hc_links* link, bench_idx* idx, ma_ug_t *ug, uint64_t* is_trans)
{
(*is_trans) = (uint64_t)-1;
uint64_t s_uid, e_uid;
long long s_pos, e_pos;
s_uid = ((get_pe_s(*hit)<<1)>>(64 - idx->uID_bits)); s_pos = get_pe_s(*hit) & idx->pos_mode;
e_uid = ((get_pe_e(*hit)<<1)>>(64 - idx->uID_bits)); e_pos = get_pe_e(*hit) & idx->pos_mode;
if(s_uid == e_uid)
{
(*is_trans) = 0;
return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
}
uint64_t s_i, e_i, k, ori;
for (s_i = 0; s_i < idx->ug_idx.n; s_i++)
{
if(s_uid >= idx->ug_idx.a[s_i].uID_start && s_uid < idx->ug_idx.a[s_i].uID_end) break;
}
for (e_i = 0; e_i < idx->ug_idx.n; e_i++)
{
if(e_uid >= idx->ug_idx.a[e_i].uID_start && e_uid < idx->ug_idx.a[e_i].uID_end) break;
}
if(s_i == idx->ug_idx.n || e_i == idx->ug_idx.n) return (uint64_t)-1;
if(s_i == e_i)
{
(*is_trans) = 0;
return (uint64_t)-1;
}
(*is_trans) = 1;
hc_linkeage* t = &(link->a.a[s_uid]);
long long m_x[2] = {1, -1}, dis;
for (k = 0; k < t->e.n; k++)
{
if(t->e.a[k].del || t->e.a[k].uID != e_uid) continue;
ori = !!(t->e.a[k].dis & (uint64_t)2);
dis = (long long)(t->e.a[k].dis>>2) * m_x[t->e.a[k].dis & (uint64_t)1];
if(ori) e_pos = ug->u.a[e_uid].len - e_pos - 1;
e_pos = e_pos + dis;
return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
}
return (uint64_t)-1;
}
uint64_t get_hic_distance_bench(pe_hit* hit, hc_links* link, bench_idx* idx, ma_ug_t *ug, uint64_t* is_trans)
{
(*is_trans) = (uint64_t)-1;
uint64_t s_uid, e_uid;
long long s_pos, e_pos;
s_uid = ((hit->s<<1)>>(64 - idx->uID_bits)); s_pos = hit->s & idx->pos_mode;
e_uid = ((hit->e<<1)>>(64 - idx->uID_bits)); e_pos = hit->e & idx->pos_mode;
if(s_uid == e_uid)
{
(*is_trans) = 0;
return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
}
uint64_t s_i, e_i, k, ori;
for (s_i = 0; s_i < idx->ug_idx.n; s_i++)
{
if(s_uid >= idx->ug_idx.a[s_i].uID_start && s_uid < idx->ug_idx.a[s_i].uID_end) break;
}
for (e_i = 0; e_i < idx->ug_idx.n; e_i++)
{
if(e_uid >= idx->ug_idx.a[e_i].uID_start && e_uid < idx->ug_idx.a[e_i].uID_end) break;
}
if(s_i == idx->ug_idx.n || e_i == idx->ug_idx.n) return (uint64_t)-1;
if(s_i == e_i)
{
(*is_trans) = 0;
return (uint64_t)-1;
}
(*is_trans) = 1;
hc_linkeage* t = &(link->a.a[s_uid]);
long long m_x[2] = {1, -1}, dis;
for (k = 0; k < t->e.n; k++)
{
if(t->e.a[k].del || t->e.a[k].uID != e_uid) continue;
ori = !!(t->e.a[k].dis & (uint64_t)2);
dis = (long long)(t->e.a[k].dis>>2) * m_x[t->e.a[k].dis & (uint64_t)1];
if(ori) e_pos = ug->u.a[e_uid].len - e_pos - 1;
e_pos = e_pos + dis;
return MAX(s_pos, e_pos) - MIN(s_pos, e_pos);
}
return (uint64_t)-1;
}
void init_bench_idx(bench_idx* idx, asg_t* read_g, ma_ug_t *ug)
{
uint64_t i, occ;
kv_init(idx->ug_idx);
kv_init(idx->regions);
kv_malloc(idx->ug_idx, ug->occ.n); idx->ug_idx.n = ug->occ.n;
for (idx->uID_bits = 1; (uint64_t)(1<<idx->uID_bits)<(uint64_t)ug->u.n; idx->uID_bits++);
idx->pos_mode = ((uint64_t)-1)>>(idx->uID_bits+1);
for (i = occ = 0; i < ug->occ.n; i++)
{
idx->ug_idx.a[i].uID_start = occ;
occ += ug->occ.a[i];
idx->ug_idx.a[i].uID_end = occ;
idx->ug_idx.a[i].u_n = ug->occ.a[i];
idx->ug_idx.a[i].r_n = read_g->n_seq;
idx->ug_idx.a[i].r_idx
= set_bench_idx(ug, read_g, idx->ug_idx.a[i].uID_start, idx->ug_idx.a[i].uID_end,
idx->uID_bits, idx->ug_idx.a[i].r_n);
}
init_hc_links(&(idx->link), ug->u.n, NULL);
for (i = 0; i < idx->ug_idx.n; i++)
{
get_r_utg_bench(i, idx, ug);
}
}
void evaluate_bench_idx_hap(bench_idx* idx, kvec_pe_hit_hap* hits, ma_ug_t *ug)
{
uint64_t k, distance, is_trans, trans[2];
kvec_t(uint64_t) buf;
kv_init(buf);
for (k = trans[0] = trans[1] = 0; k < hits->n_u; ++k)
{
distance = get_hic_distance_bench_hap(&(hits->a[k]), &(idx->link), idx, ug, &is_trans);
if(is_trans != (uint64_t)-1) trans[is_trans]++;
if(distance == (uint64_t)-1 || is_trans == (uint64_t)-1) continue;
distance = (distance << 1) + is_trans;
kv_push(uint64_t, buf, distance);
}
radix_sort_hc64(buf.a, buf.a+buf.n);
for (k = 0; k < buf.n; k++)
{
fprintf(stderr, "%lu\t%lu\n", buf.a[k]>>1, buf.a[k]&1);
}
/**
uint64_t up_dis = buf.a[(uint64_t)(buf.n*0.99)]>>1, step = 7240;
uint64_t step_s = 0, step_e = step, cnt[2];
for (k = cnt[0] = cnt[1] = 0; k < buf.n; k++)
{
if(step_s > up_dis) step_e = (buf.a[buf.n-1]>>1) + 1;
if((buf.a[k]>>1) < step_e && (buf.a[k]>>1) >= step_s)
{
cnt[buf.a[k]&1]++;
}
if((buf.a[k]>>1) >= step_e)
{
while (!((buf.a[k]>>1) < step_e && (buf.a[k]>>1) >= step_s))
{
fprintf(stderr, "i: %lu, step_s: %lu, step_e: %lu, cnt[0]: %lu, cnt[1]: %lu, rate: %f\n",
step_s/step, step_s, step_e, cnt[0], cnt[1], ((double)cnt[1])/(double)(cnt[0] + cnt[1]));
step_s += step;
step_e += step;
cnt[0] = cnt[1] = 0;
}
}
}
if(cnt[0] > 0 || cnt[1] > 0)
{
fprintf(stderr, "i: %lu, step_s: %lu, step_e: %lu, cnt[0]: %lu, cnt[1]: %lu, rate: %f\n",
step_s/step, step_s, step_e, cnt[0], cnt[1], ((double)cnt[1])/(double)(cnt[0] + cnt[1]));
}
**/
kv_destroy(buf);
}
void evaluate_bench_idx(bench_idx* idx, kvec_pe_hit* hits, ma_ug_t *ug)
{
uint64_t k, distance, is_trans, trans[2];
kvec_t(uint64_t) buf;
kv_init(buf);
for (k = trans[0] = trans[1] = 0; k < hits->a.n; ++k)
{
distance = get_hic_distance_bench(&(hits->a.a[k]), &(idx->link), idx, ug, &is_trans);
if(is_trans != (uint64_t)-1) trans[is_trans]++;
if(distance == (uint64_t)-1 || is_trans == (uint64_t)-1) continue;
distance = (distance << 1) + is_trans;
kv_push(uint64_t, buf, distance);
}
radix_sort_hc64(buf.a, buf.a+buf.n);
for (k = 0; k < buf.n; k++)
{
fprintf(stderr, "%lu\t%lu\n", buf.a[k]>>1, buf.a[k]&1);
}
/**
uint64_t up_dis = buf.a[(uint64_t)(buf.n*0.99)]>>1, step = 7240;
uint64_t step_s = 0, step_e = step, cnt[2];
for (k = cnt[0] = cnt[1] = 0; k < buf.n; k++)
{
if(step_s > up_dis) step_e = (buf.a[buf.n-1]>>1) + 1;
if((buf.a[k]>>1) < step_e && (buf.a[k]>>1) >= step_s)
{
cnt[buf.a[k]&1]++;
}
if((buf.a[k]>>1) >= step_e)
{
while (!((buf.a[k]>>1) < step_e && (buf.a[k]>>1) >= step_s))
{
fprintf(stderr, "i: %lu, step_s: %lu, step_e: %lu, cnt[0]: %lu, cnt[1]: %lu, rate: %f\n",
step_s/step, step_s, step_e, cnt[0], cnt[1], ((double)cnt[1])/(double)(cnt[0] + cnt[1]));
step_s += step;
step_e += step;
cnt[0] = cnt[1] = 0;
}
}
}
if(cnt[0] > 0 || cnt[1] > 0)
{
fprintf(stderr, "i: %lu, step_s: %lu, step_e: %lu, cnt[0]: %lu, cnt[1]: %lu, rate: %f\n",
step_s/step, step_s, step_e, cnt[0], cnt[1], ((double)cnt[1])/(double)(cnt[0] + cnt[1]));
}
**/
kv_destroy(buf);
}
void destory_bench_idx(bench_idx* idx)
{
uint64_t i;
for (i = 0; i < idx->ug_idx.n; i++)
{
free(idx->ug_idx.a[i].r_idx);
}
kv_destroy(idx->ug_idx);
kv_destroy(idx->regions);
destory_hc_links(&(idx->link));
}
int hic_short_align_bench(const enzyme *fn1, const enzyme *fn2, const char *output_file_name, ha_ug_index* idx)
{
double index_time = yak_realtime();
sldat_t sl;
sl.idx = idx;
///sl.link = NULL;
sl.chunk_size = 20000000;
sl.n_thread = asm_opt.thread_num;
sl.total_base = sl.total_pair = 0;
idx->hap_cnt = asm_opt.hap_occ;
kv_init(sl.hits.a);
fprintf(stderr, "u.n: %d, uID_bits: %lu, pos_bits: %lu\n", (uint32_t)idx->ug->u.n, idx->uID_bits, idx->pos_bits);
if(!load_hc_hits(&sl.hits, output_file_name))
{
// kt_pipeline(3, worker_pipeline, &sl, 3);
// dedup_hits(&sl.hits);
alignment_worker_pipeline(&sl, fn1, fn2);
write_hc_hits(&sl.hits, output_file_name);
}
bench_idx bench;
init_bench_idx(&bench, idx->read_g, idx->ug);
///print_bench_idx(&bench, idx->ug);
evaluate_bench_idx(&bench, &sl.hits, idx->ug);
destory_bench_idx(&bench);
kv_destroy(sl.hits.a);
fprintf(stderr, "[M::%s::%.3f] processed %lu pairs; %lu bases\n", __func__, yak_realtime()-index_time, sl.total_pair, sl.total_base);
return 1;
}
void hic_benchmark(ma_ug_t *ug, asg_t* read_g)
{
char *output_file_name = (char*)calloc(strlen(asm_opt.output_file_name) + 25, 1);
sprintf(output_file_name, "%s.bench", asm_opt.output_file_name);
ug_index = NULL;
int exist = load_hc_pt_index(&ug_index, output_file_name);
if(exist == 0) ug_index = build_unitig_index(ug, asm_opt.hic_mer_length);
if(exist == 0) write_hc_pt_index(ug_index, output_file_name);
ug_index->ug = ug;
ug_index->read_g = read_g;
hic_short_align_bench(asm_opt.hic_reads[0], asm_opt.hic_reads[1], output_file_name, ug_index);
free(output_file_name);
} | [
"hcheng@jimmy.harvard.edu"
] | hcheng@jimmy.harvard.edu |
71832c768c42a3b220f480ee35dcfe069ef9a148 | f06394eb49f055ce3a51c93eb56249350d64ddbb | /tests/generation-tests/kdm/core/KDMRelationship.hpp | eea6b41564c4e2da0d4a2e1aa578c4fcf0d5b3bf | [] | no_license | happyj/e4c | a3c6eb523cf1d346a73b138c45a6cdfc83766710 | 59646a43d50749ddfc983e9a1f3a3c70fc5eb218 | refs/heads/master | 2020-03-26T05:15:09.814976 | 2014-02-22T11:20:12 | 2014-02-22T11:20:12 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 880 | hpp |
#ifndef EMF_CPP_KDM_CORE_KDMRELATIONSHIP__HPP
#define EMF_CPP_KDM_CORE_KDMRELATIONSHIP__HPP
#include <kdm/core/fwd.hpp>
#include <kdm/core/meta.hpp>
#include <kdm/core/ModelElement.hpp>
#include <e4c/mapping.hpp>
namespace kdm
{
namespace core
{
class KDMRelationship : public virtual ::kdm::core::ModelElement
{
public:
typedef KDMRelationship_ptr ptr_type;
virtual ~KDMRelationship();
kdm::core::KDMEntity_ptr getTo();
kdm::core::KDMEntity_ptr getFrom();
/*PROTECTED REGION ID(kdm::core::KDMRelationship public) START*/
/*PROTECTED REGION END*/
protected:
KDMRelationship();
friend class CorePackage;
virtual ecore::EClass_ptr eClassImpl() const;
/*PROTECTED REGION ID(kdm::core::KDMRelationship protected) START*/
/*PROTECTED REGION END*/
};
} // core
} // kdm
#endif // EMF_CPP_KDM_CORE_KDMRELATIONSHIP__HPP
| [
"andres@senac.es"
] | andres@senac.es |
487f9be73540fa67339e5e9d0368206134cc87dd | 7a2a9ef8a1cb493d5391b5a5578befbd14d4a99f | /ZorkRoger/Entity.cpp | ed1b7a8ba0ba2432e79c6a56d96314c0b4e0da23 | [] | no_license | RogerNogue/ZorkRoger | 0ee82a73752e40d18a23d682d8c336943cc5b2f3 | 1bbff9703f5fd4d73d845648a3bb35ac73ae8f3f | refs/heads/master | 2020-03-21T08:38:58.545245 | 2018-06-25T16:33:47 | 2018-06-25T16:33:47 | 138,356,223 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 222 | cpp | #include "Entity.h"
Entity::Entity(string namep, string descriptionp, vector<Entity*> containsp)
{
name = namep;
description = descriptionp;
contains = containsp;
}
Entity::~Entity()
{
}
void Entity::Update() {
} | [
"rogernogueb@gmail.com"
] | rogernogueb@gmail.com |
7b49a66a4527bb93e2eec7d142ed873184f0d938 | 7ad527bad3bd0d7eb94d1d8a0fe08df67aa26c3e | /软件学院/高级语言程序设计(C++)/答案/ch08solutions/Ex08_13/ex08_13.cpp | c4f7a1a79cad796b9f28ab912a3f3076d0122fff | [] | no_license | SCUTMSC/SCUT-Course | 67e67ac494aef7fc73de17f61b7fab8450f17952 | 90f884a9032e951ebc9421cc88ca807b9ec211da | refs/heads/master | 2020-07-16T22:22:53.359477 | 2019-09-07T08:28:09 | 2019-09-07T08:28:09 | 205,880,291 | 10 | 6 | null | null | null | null | UTF-8 | C++ | false | false | 1,618 | cpp | // Ex. 8.13: ex08_13.cpp
// What does this program do?
#include <iostream>
using namespace std;
void mystery1( char *, const char * ); // prototype
int main()
{
char string1[ 80 ];
char string2[ 80 ];
cout << "Enter two strings: ";
cin >> string1 >> string2;
mystery1( string1, string2 );
cout << string1 << endl;
} // end main
// What does this function do?
void mystery1( char *s1, const char *s2 )
{
while ( *s1 != '\0' )
s1++;
for ( ; *s1 = *s2; s1++, s2++ )
; // empty statement
} // end function mystery1
/**************************************************************************
* (C) Copyright 1992-2010 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
| [
"LotteWong21@gmail.com"
] | LotteWong21@gmail.com |
991f5a2de7edd27ef9c731f5c4b96f2bf3354c0c | 7bb34b9837b6304ceac6ab45ce482b570526ed3c | /external/webkit/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp | b7b94c4d269443bc4163163d352fd642aa4f5425 | [
"LGPL-2.0-only",
"BSD-2-Clause",
"LGPL-2.1-only",
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"GPL-2.0-only",
"LicenseRef-scancode-other-copyleft",
"Apache-2.0"
] | permissive | ghsecuritylab/android_platform_sony_nicki | 7533bca5c13d32a8d2a42696344cc10249bd2fd8 | 526381be7808e5202d7865aa10303cb5d249388a | refs/heads/master | 2021-02-28T20:27:31.390188 | 2013-10-15T07:57:51 | 2013-10-15T07:57:51 | 245,730,217 | 0 | 0 | Apache-2.0 | 2020-03-08T00:59:27 | 2020-03-08T00:59:26 | null | UTF-8 | C++ | false | false | 17,209 | cpp | /*
* Copyright (c) 2010, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(ACCELERATED_2D_CANVAS)
#include "SharedGraphicsContext3D.h"
#include "AffineTransform.h"
#include "BicubicShader.h"
#include "Color.h"
#include "ConvolutionShader.h"
#include "DrawingBuffer.h"
#include "Extensions3D.h"
#include "FloatRect.h"
#include "IntSize.h"
#include "LoopBlinnSolidFillShader.h"
#include "SolidFillShader.h"
#include "TexShader.h"
#if ENABLE(SKIA_GPU)
#include "GrContext.h"
// Limit the number of textures we hold in the bitmap->texture cache.
static const int maxTextureCacheCount = 512;
// Limit the bytes allocated toward textures in the bitmap->texture cache.
static const size_t maxTextureCacheBytes = 50 * 1024 * 1024;
#endif
#include <wtf/OwnArrayPtr.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
// static
PassRefPtr<SharedGraphicsContext3D> SharedGraphicsContext3D::create(HostWindow* hostWindow)
{
GraphicsContext3D::Attributes attr;
attr.depth = false;
attr.stencil = true;
attr.antialias = useLoopBlinnForPathRendering();
attr.canRecoverFromContextLoss = false; // Canvas contexts can not handle lost contexts.
RefPtr<GraphicsContext3D> context = GraphicsContext3D::create(attr, hostWindow);
if (!context)
return 0;
OwnPtr<SolidFillShader> solidFillShader = SolidFillShader::create(context.get());
if (!solidFillShader)
return 0;
OwnPtr<TexShader> texShader = TexShader::create(context.get());
if (!texShader)
return 0;
OwnPtr<BicubicShader> bicubicShader = BicubicShader::create(context.get());
if (!bicubicShader)
return 0;
OwnArrayPtr<OwnPtr<ConvolutionShader> > convolutionShaders = adoptArrayPtr(new OwnPtr<ConvolutionShader>[cMaxKernelWidth]);
for (int i = 0; i < cMaxKernelWidth; ++i) {
convolutionShaders[i] = ConvolutionShader::create(context.get(), i + 1);
if (!convolutionShaders[i])
return 0;
}
return adoptRef(new SharedGraphicsContext3D(context.release(), solidFillShader.release(), texShader.release(), bicubicShader.release(), convolutionShaders.release()));
}
SharedGraphicsContext3D::SharedGraphicsContext3D(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<SolidFillShader> solidFillShader, PassOwnPtr<TexShader> texShader, PassOwnPtr<BicubicShader> bicubicShader, PassOwnArrayPtr<OwnPtr<ConvolutionShader> > convolutionShaders)
: m_context(context)
, m_bgraSupported(false)
, m_quadVertices(0)
, m_solidFillShader(solidFillShader)
, m_texShader(texShader)
, m_bicubicShader(bicubicShader)
, m_convolutionShaders(convolutionShaders)
, m_oesStandardDerivativesSupported(false)
#if ENABLE(SKIA_GPU)
, m_grContext(0)
#endif
{
allContexts()->add(this);
Extensions3D* extensions = m_context->getExtensions();
m_bgraSupported = extensions->supports("GL_EXT_texture_format_BGRA8888") && extensions->supports("GL_EXT_read_format_bgra");
if (m_bgraSupported) {
extensions->ensureEnabled("GL_EXT_texture_format_BGRA8888");
extensions->ensureEnabled("GL_EXT_read_format_bgra");
}
m_oesStandardDerivativesSupported = extensions->supports("GL_OES_standard_derivatives");
if (m_oesStandardDerivativesSupported)
extensions->ensureEnabled("GL_OES_standard_derivatives");
}
SharedGraphicsContext3D::~SharedGraphicsContext3D()
{
m_context->deleteBuffer(m_quadVertices);
allContexts()->remove(this);
#if ENABLE(SKIA_GPU)
GrSafeUnref(m_grContext);
#endif
}
void SharedGraphicsContext3D::makeContextCurrent()
{
m_context->makeContextCurrent();
}
void SharedGraphicsContext3D::scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height)
{
m_context->scissor(x, y, width, height);
}
void SharedGraphicsContext3D::enable(GC3Denum capacity)
{
m_context->enable(capacity);
}
void SharedGraphicsContext3D::disable(GC3Denum capacity)
{
m_context->disable(capacity);
}
void SharedGraphicsContext3D::clearColor(const Color& color)
{
float rgba[4];
color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
m_context->clearColor(rgba[0], rgba[1], rgba[2], rgba[3]);
}
void SharedGraphicsContext3D::clear(GC3Dbitfield mask)
{
m_context->clear(mask);
}
void SharedGraphicsContext3D::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count)
{
m_context->drawArrays(mode, first, count);
}
GC3Denum SharedGraphicsContext3D::getError()
{
return m_context->getError();
}
void SharedGraphicsContext3D::getIntegerv(GC3Denum pname, GC3Dint* value)
{
m_context->getIntegerv(pname, value);
}
void SharedGraphicsContext3D::flush()
{
m_context->flush();
}
Platform3DObject SharedGraphicsContext3D::createBuffer()
{
return m_context->createBuffer();
}
Platform3DObject SharedGraphicsContext3D::createFramebuffer()
{
return m_context->createFramebuffer();
}
Platform3DObject SharedGraphicsContext3D::createTexture()
{
return m_context->createTexture();
}
void SharedGraphicsContext3D::deleteFramebuffer(Platform3DObject framebuffer)
{
m_context->deleteFramebuffer(framebuffer);
}
void SharedGraphicsContext3D::deleteTexture(Platform3DObject texture)
{
m_context->deleteTexture(texture);
}
void SharedGraphicsContext3D::framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject texture, GC3Dint level)
{
m_context->framebufferTexture2D(target, attachment, textarget, texture, level);
}
void SharedGraphicsContext3D::texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param)
{
m_context->texParameteri(target, pname, param);
}
bool SharedGraphicsContext3D::texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels)
{
if (!pixels)
return m_context->texImage2DResourceSafe(target, level, internalformat, width, height, border, format, type);
return m_context->texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
void SharedGraphicsContext3D::texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels)
{
m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
void SharedGraphicsContext3D::readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
{
m_context->readPixels(x, y, width, height, format, type, data);
}
bool SharedGraphicsContext3D::supportsBGRA()
{
return m_bgraSupported;
}
Texture* SharedGraphicsContext3D::createTexture(NativeImagePtr ptr, Texture::Format format, int width, int height)
{
RefPtr<Texture> texture = m_textures.get(ptr);
if (texture)
return texture.get();
texture = Texture::create(m_context.get(), format, width, height);
Texture* t = texture.get();
m_textures.set(ptr, texture);
return t;
}
Texture* SharedGraphicsContext3D::getTexture(NativeImagePtr ptr)
{
RefPtr<Texture> texture = m_textures.get(ptr);
return texture ? texture.get() : 0;
}
void SharedGraphicsContext3D::removeTextureFor(NativeImagePtr ptr)
{
TextureHashMap::iterator it = m_textures.find(ptr);
if (it != m_textures.end())
m_textures.remove(it);
}
// static
void SharedGraphicsContext3D::removeTexturesFor(NativeImagePtr ptr)
{
for (HashSet<SharedGraphicsContext3D*>::iterator it = allContexts()->begin(); it != allContexts()->end(); ++it)
(*it)->removeTextureFor(ptr);
}
// static
HashSet<SharedGraphicsContext3D*>* SharedGraphicsContext3D::allContexts()
{
DEFINE_STATIC_LOCAL(HashSet<SharedGraphicsContext3D*>, allContextsSet, ());
return &allContextsSet;
}
PassRefPtr<Texture> SharedGraphicsContext3D::createTexture(Texture::Format format, int width, int height)
{
return Texture::create(m_context.get(), format, width, height);
}
void SharedGraphicsContext3D::applyCompositeOperator(CompositeOperator op)
{
switch (op) {
case CompositeClear:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO);
break;
case CompositeCopy:
m_context->disable(GraphicsContext3D::BLEND);
break;
case CompositeSourceOver:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositeSourceIn:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ZERO);
break;
case CompositeSourceOut:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ZERO);
break;
case CompositeSourceAtop:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositeDestinationOver:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE);
break;
case CompositeDestinationIn:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::SRC_ALPHA);
break;
case CompositeDestinationOut:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositeDestinationAtop:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::SRC_ALPHA);
break;
case CompositeXOR:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositePlusDarker:
case CompositeHighlight:
// unsupported
m_context->disable(GraphicsContext3D::BLEND);
break;
case CompositePlusLighter:
m_context->enable(GraphicsContext3D::BLEND);
m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE);
break;
}
}
void SharedGraphicsContext3D::enableStencil(bool enable)
{
if (enable)
m_context->enable(GraphicsContext3D::STENCIL_TEST);
else
m_context->disable(GraphicsContext3D::STENCIL_TEST);
}
void SharedGraphicsContext3D::useQuadVertices()
{
if (!m_quadVertices) {
float vertices[] = { 0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f };
m_quadVertices = m_context->createBuffer();
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(vertices), vertices, GraphicsContext3D::STATIC_DRAW);
} else {
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
}
}
void SharedGraphicsContext3D::setActiveTexture(GC3Denum textureUnit)
{
m_context->activeTexture(textureUnit);
}
void SharedGraphicsContext3D::bindBuffer(GC3Denum target, Platform3DObject buffer)
{
m_context->bindBuffer(target, buffer);
}
void SharedGraphicsContext3D::bindTexture(GC3Denum target, Platform3DObject texture)
{
m_context->bindTexture(target, texture);
}
void SharedGraphicsContext3D::bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage)
{
m_context->bufferData(target, size, usage);
}
void SharedGraphicsContext3D::bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage)
{
m_context->bufferData(target, size, data, usage);
}
void SharedGraphicsContext3D::bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data)
{
m_context->bufferSubData(target, offset, size, data);
}
void SharedGraphicsContext3D::useFillSolidProgram(const AffineTransform& transform, const Color& color)
{
m_solidFillShader->use(transform, color);
}
void SharedGraphicsContext3D::useTextureProgram(const AffineTransform& transform, const AffineTransform& texTransform, float alpha)
{
m_texShader->use(transform, texTransform, 0, alpha);
}
void SharedGraphicsContext3D::useBicubicProgram(const AffineTransform& transform, const AffineTransform& texTransform, const float coefficients[16], const float imageIncrement[2], float alpha)
{
m_bicubicShader->use(transform, texTransform, coefficients, imageIncrement, alpha);
}
void SharedGraphicsContext3D::useConvolutionProgram(const AffineTransform& transform, const AffineTransform& texTransform, const float* kernel, int kernelWidth, float imageIncrement[2])
{
ASSERT(kernelWidth >= 1 && kernelWidth <= cMaxKernelWidth);
m_convolutionShaders[kernelWidth - 1]->use(transform, texTransform, kernel, kernelWidth, imageIncrement);
}
void SharedGraphicsContext3D::bindFramebuffer(Platform3DObject framebuffer)
{
m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, framebuffer);
}
void SharedGraphicsContext3D::setViewport(const IntSize& size)
{
m_context->viewport(0, 0, size.width(), size.height());
}
bool SharedGraphicsContext3D::paintsIntoCanvasBuffer() const
{
return m_context->paintsIntoCanvasBuffer();
}
bool SharedGraphicsContext3D::useLoopBlinnForPathRendering()
{
return false;
}
void SharedGraphicsContext3D::useLoopBlinnInteriorProgram(unsigned vertexOffset, const AffineTransform& transform, const Color& color)
{
if (!m_loopBlinnInteriorShader) {
m_loopBlinnInteriorShader = LoopBlinnSolidFillShader::create(m_context.get(),
LoopBlinnShader::Interior,
Shader::NotAntialiased);
}
ASSERT(m_loopBlinnInteriorShader);
m_loopBlinnInteriorShader->use(vertexOffset, 0, transform, color);
}
void SharedGraphicsContext3D::useLoopBlinnExteriorProgram(unsigned vertexOffset, unsigned klmOffset, const AffineTransform& transform, const Color& color)
{
if (!m_loopBlinnExteriorShader) {
m_loopBlinnExteriorShader = LoopBlinnSolidFillShader::create(m_context.get(),
LoopBlinnShader::Exterior,
m_oesStandardDerivativesSupported ? Shader::Antialiased : Shader::NotAntialiased);
}
ASSERT(m_loopBlinnExteriorShader);
m_loopBlinnExteriorShader->use(vertexOffset, klmOffset, transform, color);
}
DrawingBuffer* SharedGraphicsContext3D::getOffscreenBuffer(unsigned index, const IntSize& size)
{
if (index >= m_offscreenBuffers.size())
m_offscreenBuffers.resize(index + 1);
if (!m_offscreenBuffers[index])
m_offscreenBuffers[index] = m_context->createDrawingBuffer(size);
if (size.width() != m_offscreenBuffers[index]->size().width()
|| size.height() != m_offscreenBuffers[index]->size().height())
m_offscreenBuffers[index]->reset(size);
return m_offscreenBuffers[index].get();
}
#if ENABLE(SKIA_GPU)
GrContext* SharedGraphicsContext3D::grContext()
{
if (!m_grContext) {
m_grContext = GrContext::CreateGLShaderContext();
m_grContext->setTextureCacheLimits(maxTextureCacheCount, maxTextureCacheBytes);
}
return m_grContext;
}
#endif
} // namespace WebCore
#endif
| [
"gahlotpercy@gmail.com"
] | gahlotpercy@gmail.com |
a2f8b540205ecd97d5f0e2f22d873fcb1241bb61 | d5bd189957a5f1c881f91f7673864812bc9f6227 | /Stacks-and-Queues-of-Lists/SingleLinkedListQueue.h | 78691dcd8a7e223fec201230e7617fdb28be2ec1 | [] | no_license | rala8730/data-structures | f9fa9a9b095baa263c0aeaf4418bb5340c3452a7 | be3b5237f5af2b5322283360dd3ee1f5707e22e9 | refs/heads/master | 2021-01-12T08:54:40.251261 | 2016-12-29T05:55:13 | 2016-12-29T05:55:13 | 76,715,470 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 490 | h | #ifndef SINGLELINKEDLISTQUEUE_H
#define SINGLELINKEDLISTQUEUE_H
#include "SingleNode.h"
class SingleLinkedListQueue
{
public:
SingleLinkedListQueue();
~SingleLinkedListQueue();
bool PrintAndTraverse();
void Enqueue_Queue(int a);
bool Dequeue_Queue();
private:
SingleNode *head;//pointer
SingleNode *tail;//pointer
int top;//head
int bottom;//tail
int max_Queue;
};
#endif // SINGLELINKEDLISTQUEUE_H
| [
"rala8730@colorado.edu"
] | rala8730@colorado.edu |
c1df786a72df2b49033b1bdba3f2bffbb27ee88a | be828b1b3f165603a66e6c9cdb336cf874be827b | /src/application.cpp | 0d7b51bdcbce987a4be024add80214a159656a94 | [] | no_license | aalex/proto-toonloop | f4689f5be385b424f38b726e1aada09df748bcdb | 09a9155b307715277983f91a16da93e8c7e47dbd | refs/heads/master | 2021-01-10T20:09:49.486865 | 2010-07-12T14:45:00 | 2010-07-12T14:45:00 | 766,506 | 1 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,246 | cpp | #include "application.h"
#include "gui.h"
#include "pipeline.h"
#include "pipeline.h"
#include <iostream>
#include <gtk/gtk.h>
Application* Application::instance_ = 0;
Application::Application()
{}
void Application::run()
{
std::cout << "Running toonloop\n";
start_gui();
start_pipeline();
//get_pipeline().set_drawing_area(get_gui().get_drawing_area());
gtk_main();
}
Pipeline& Application::get_pipeline()
{
return *pipeline_;
}
Gui& Application::get_gui()
{
return *gui_;
}
Application& Application::get_instance()
{
if (!instance_)
instance_ = new Application();
return *instance_;
}
void Application::start_gui()
{
std::cout << "Starting GUI." << std::endl;
gui_ = std::tr1::shared_ptr<Gui>(new Gui());
}
void Application::start_pipeline()
{
std::cout << "Starting pipeline." << std::endl;
pipeline_ = std::tr1::shared_ptr<Pipeline>(new Pipeline());
}
// delete the instance, not sure how safe this is
void Application::reset()
{
std::cout << "Resetting the application" << std::endl;
delete instance_;
instance_ = 0;
}
void Application::quit()
{
std::cout << "Quitting the application." << std::endl;
get_pipeline().stop();
gtk_main_quit();
}
| [
"alexandre@quessy.net"
] | alexandre@quessy.net |
2bd710df6a0e3e817fc5562cead7c427c7b8fd82 | 2b674dfad4f0c58d064421136a24301182e10920 | /include/blaze-2.4/blaze/math/adaptors/LowerMatrix.h | 2b175afa53644ea306abd80485b8a25a54679080 | [
"BSD-3-Clause"
] | permissive | adityaramesh/blaze_benchmark | 6f57352a4d3f2de9a2b35956c2f2f31e7834c018 | 91a9bf4500fcc0e4c5ff435e80026e216deb5ad7 | refs/heads/master | 2020-04-10T01:41:42.341292 | 2015-08-26T14:06:30 | 2015-08-26T14:06:30 | 41,381,938 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 30,034 | h | //=================================================================================================
/*!
// \file blaze/math/adaptors/LowerMatrix.h
// \brief Header file for the implementation of a lower matrix adaptor
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_LOWERMATRIX_H_
#define _BLAZE_MATH_ADAPTORS_LOWERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/adaptors/lowermatrix/BaseTemplate.h>
#include <blaze/math/adaptors/lowermatrix/Dense.h>
#include <blaze/math/adaptors/lowermatrix/Sparse.h>
#include <blaze/math/Forward.h>
#include <blaze/math/traits/AddTrait.h>
#include <blaze/math/traits/ColumnTrait.h>
#include <blaze/math/traits/DerestrictTrait.h>
#include <blaze/math/traits/DivTrait.h>
#include <blaze/math/traits/MathTrait.h>
#include <blaze/math/traits/MultTrait.h>
#include <blaze/math/traits/RowTrait.h>
#include <blaze/math/traits/SubmatrixTrait.h>
#include <blaze/math/traits/SubTrait.h>
#include <blaze/math/typetraits/HasConstDataAccess.h>
#include <blaze/math/typetraits/Columns.h>
#include <blaze/math/typetraits/IsAdaptor.h>
#include <blaze/math/typetraits/IsLower.h>
#include <blaze/math/typetraits/IsResizable.h>
#include <blaze/math/typetraits/IsRestricted.h>
#include <blaze/math/typetraits/IsSquare.h>
#include <blaze/math/typetraits/RemoveAdaptor.h>
#include <blaze/math/typetraits/Rows.h>
#include <blaze/util/constraints/Numeric.h>
namespace blaze {
//=================================================================================================
//
// LOWERMATRIX OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name LowerMatrix operators */
//@{
template< typename MT, bool SO, bool DF >
inline void reset( LowerMatrix<MT,SO,DF>& m );
template< typename MT, bool SO, bool DF >
inline void reset( LowerMatrix<MT,SO,DF>& m, size_t i );
template< typename MT, bool SO, bool DF >
inline void clear( LowerMatrix<MT,SO,DF>& m );
template< typename MT, bool SO, bool DF >
inline bool isDefault( const LowerMatrix<MT,SO,DF>& m );
template< typename MT, bool SO, bool DF >
inline void swap( LowerMatrix<MT,SO,DF>& a, LowerMatrix<MT,SO,DF>& b ) /* throw() */;
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Resetting the given lower matrix.
// \ingroup lower_matrix
//
// \param m The lower matrix to be resetted.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void reset( LowerMatrix<MT,SO,DF>& m )
{
m.reset();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Resetting the specified row/column of the given lower matrix.
// \ingroup lower_matrix
//
// \param m The lower matrix to be resetted.
// \param i The index of the row/column to be resetted.
// \return void
//
// This function resets the values in the specified row/column of the given lower matrix to their
// default value. In case the given matrix is a \a rowMajor matrix the function resets the values
// in row \a i, if it is a \a columnMajor matrix the function resets the values in column \a i.
// Note that the capacity of the row/column remains unchanged.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void reset( LowerMatrix<MT,SO,DF>& m, size_t i )
{
m.reset( i );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Clearing the given lower matrix.
// \ingroup lower_matrix
//
// \param m The lower matrix to be cleared.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void clear( LowerMatrix<MT,SO,DF>& m )
{
m.clear();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the given lower matrix is in default state.
// \ingroup lower_matrix
//
// \param m The lower matrix to be tested for its default state.
// \return \a true in case the given matrix is component-wise zero, \a false otherwise.
//
// This function checks whether the matrix is in default state. For instance, in case the
// matrix is instantiated for a built-in integral or floating point data type, the function
// returns \a true in case all matrix elements are 0 and \a false in case any matrix element
// is not 0. The following example demonstrates the use of the \a isDefault function:
\code
blaze::LowerMatrix<int> A;
// ... Resizing and initialization
if( isDefault( A ) ) { ... }
\endcode
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline bool isDefault( const LowerMatrix<MT,SO,DF>& m )
{
return isDefault( m.matrix_ );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Swapping the contents of two matrices.
// \ingroup lower_matrix
//
// \param a The first matrix to be swapped.
// \param b The second matrix to be swapped.
// \return void
// \exception no-throw guarantee.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void swap( LowerMatrix<MT,SO,DF>& a, LowerMatrix<MT,SO,DF>& b ) /* throw() */
{
a.swap( b );
}
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Returns a reference to the instance without the access restrictions to the upper part.
// \ingroup math_shims
//
// \param m The lower matrix to be derestricted.
// \return Reference to the matrix without access restrictions.
//
// This function returns a reference to the given lower matrix instance that has no access
// restrictions to the upper part of the matrix.\n
// This function must \b NOT be called explicitly! It is used internally for the performance
// optimized evaluation of expression templates. Calling this function explicitly might result
// in the violation of invariants, erroneous results and/or in compilation errors.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline MT& derestrict( LowerMatrix<MT,SO,DF>& m )
{
return m.matrix_;
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ROWS SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct Rows< LowerMatrix<MT,SO,DF> > : public Rows<MT>
{};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// COLUMNS SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct Columns< LowerMatrix<MT,SO,DF> > : public Columns<MT>
{};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ISSQUARE SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct IsSquare< LowerMatrix<MT,SO,DF> > : public TrueType
{
enum { value = 1 };
typedef TrueType Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ISLOWER SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct IsLower< LowerMatrix<MT,SO,DF> > : public TrueType
{
enum { value = 1 };
typedef TrueType Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ISADAPTOR SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct IsAdaptor< LowerMatrix<MT,SO,DF> > : public TrueType
{
enum { value = 1 };
typedef TrueType Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ISRESTRICTED SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct IsRestricted< LowerMatrix<MT,SO,DF> > : public TrueType
{
enum { value = 1 };
typedef TrueType Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// HASCONSTDATAACCESS SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO >
struct HasConstDataAccess< LowerMatrix<MT,SO,true> > : public TrueType
{
enum { value = 1 };
typedef TrueType Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ISRESIZABLE SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct IsResizable< LowerMatrix<MT,SO,DF> > : public IsResizable<MT>::Type
{
enum { value = IsResizable<MT>::value };
typedef typename IsResizable<MT>::Type Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// REMOVEADAPTOR SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct RemoveAdaptor< LowerMatrix<MT,SO,DF> >
{
typedef MT Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// DERESTRICTTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct DerestrictTrait< LowerMatrix<MT,SO,DF> >
{
typedef MT& Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ADDTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO1, bool DF, typename T, size_t M, size_t N, bool SO2 >
struct AddTrait< LowerMatrix<MT,SO1,DF>, StaticMatrix<T,M,N,SO2> >
{
typedef typename AddTrait< MT, StaticMatrix<T,M,N,SO2> >::Type Type;
};
template< typename T, size_t M, size_t N, bool SO1, typename MT, bool SO2, bool DF >
struct AddTrait< StaticMatrix<T,M,N,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename AddTrait< StaticMatrix<T,M,N,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, size_t M, size_t N, bool SO2 >
struct AddTrait< LowerMatrix<MT,SO1,DF>, HybridMatrix<T,M,N,SO2> >
{
typedef typename AddTrait< MT, HybridMatrix<T,M,N,SO2> >::Type Type;
};
template< typename T, size_t M, size_t N, bool SO1, typename MT, bool SO2, bool DF >
struct AddTrait< HybridMatrix<T,M,N,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename AddTrait< HybridMatrix<T,M,N,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, bool SO2 >
struct AddTrait< LowerMatrix<MT,SO1,DF>, DynamicMatrix<T,SO2> >
{
typedef typename AddTrait< MT, DynamicMatrix<T,SO2> >::Type Type;
};
template< typename T, bool SO1, typename MT, bool SO2, bool DF >
struct AddTrait< DynamicMatrix<T,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename AddTrait< DynamicMatrix<T,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, bool SO2 >
struct AddTrait< LowerMatrix<MT,SO1,DF>, CompressedMatrix<T,SO2> >
{
typedef typename AddTrait< MT, CompressedMatrix<T,SO2> >::Type Type;
};
template< typename T, bool SO1, typename MT, bool SO2, bool DF >
struct AddTrait< CompressedMatrix<T,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename AddTrait< CompressedMatrix<T,SO1>, MT >::Type Type;
};
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2, bool NF >
struct AddTrait< LowerMatrix<MT1,SO1,DF1>, SymmetricMatrix<MT2,SO2,DF2,NF> >
{
typedef typename AddTrait<MT1,MT2>::Type Type;
};
template< typename MT1, bool SO1, bool DF1, bool NF, typename MT2, bool SO2, bool DF2 >
struct AddTrait< SymmetricMatrix<MT1,SO1,DF1,NF>, LowerMatrix<MT2,SO2,DF2> >
{
typedef typename AddTrait<MT1,MT2>::Type Type;
};
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2 >
struct AddTrait< LowerMatrix<MT1,SO1,DF1>, LowerMatrix<MT2,SO2,DF2> >
{
typedef LowerMatrix< typename AddTrait<MT1,MT2>::Type > Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// SUBTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO1, bool DF, typename T, size_t M, size_t N, bool SO2 >
struct SubTrait< LowerMatrix<MT,SO1,DF>, StaticMatrix<T,M,N,SO2> >
{
typedef typename SubTrait< MT, StaticMatrix<T,M,N,SO2> >::Type Type;
};
template< typename T, size_t M, size_t N, bool SO1, typename MT, bool SO2, bool DF >
struct SubTrait< StaticMatrix<T,M,N,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename SubTrait< StaticMatrix<T,M,N,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, size_t M, size_t N, bool SO2 >
struct SubTrait< LowerMatrix<MT,SO1,DF>, HybridMatrix<T,M,N,SO2> >
{
typedef typename SubTrait< MT, HybridMatrix<T,M,N,SO2> >::Type Type;
};
template< typename T, size_t M, size_t N, bool SO1, typename MT, bool SO2, bool DF >
struct SubTrait< HybridMatrix<T,M,N,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename SubTrait< HybridMatrix<T,M,N,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, bool SO2 >
struct SubTrait< LowerMatrix<MT,SO1,DF>, DynamicMatrix<T,SO2> >
{
typedef typename SubTrait< MT, DynamicMatrix<T,SO2> >::Type Type;
};
template< typename T, bool SO1, typename MT, bool SO2, bool DF >
struct SubTrait< DynamicMatrix<T,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename SubTrait< DynamicMatrix<T,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, bool SO2 >
struct SubTrait< LowerMatrix<MT,SO1,DF>, CompressedMatrix<T,SO2> >
{
typedef typename SubTrait< MT, CompressedMatrix<T,SO2> >::Type Type;
};
template< typename T, bool SO1, typename MT, bool SO2, bool DF >
struct SubTrait< CompressedMatrix<T,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename SubTrait< CompressedMatrix<T,SO1>, MT >::Type Type;
};
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2, bool NF >
struct SubTrait< LowerMatrix<MT1,SO1,DF1>, SymmetricMatrix<MT2,SO2,DF2,NF> >
{
typedef typename SubTrait<MT1,MT2>::Type Type;
};
template< typename MT1, bool SO1, bool DF1, bool NF, typename MT2, bool SO2, bool DF2 >
struct SubTrait< SymmetricMatrix<MT1,SO1,DF1,NF>, LowerMatrix<MT2,SO2,DF2> >
{
typedef typename SubTrait<MT1,MT2>::Type Type;
};
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2 >
struct SubTrait< LowerMatrix<MT1,SO1,DF1>, LowerMatrix<MT2,SO2,DF2> >
{
typedef LowerMatrix< typename SubTrait<MT1,MT2>::Type > Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MULTTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF, typename T >
struct MultTrait< LowerMatrix<MT,SO,DF>, T >
{
typedef LowerMatrix< typename MultTrait<MT,T>::Type > Type;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( T );
};
template< typename T, typename MT, bool SO, bool DF >
struct MultTrait< T, LowerMatrix<MT,SO,DF> >
{
typedef LowerMatrix< typename MultTrait<T,MT>::Type > Type;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( T );
};
template< typename MT, bool SO, bool DF, typename T, size_t N >
struct MultTrait< LowerMatrix<MT,SO,DF>, StaticVector<T,N,false> >
{
typedef typename MultTrait< MT, StaticVector<T,N,false> >::Type Type;
};
template< typename T, size_t N, typename MT, bool SO, bool DF >
struct MultTrait< StaticVector<T,N,true>, LowerMatrix<MT,SO,DF> >
{
typedef typename MultTrait< StaticVector<T,N,true>, MT >::Type Type;
};
template< typename MT, bool SO, bool DF, typename T, size_t N >
struct MultTrait< LowerMatrix<MT,SO,DF>, HybridVector<T,N,false> >
{
typedef typename MultTrait< MT, HybridVector<T,N,false> >::Type Type;
};
template< typename T, size_t N, typename MT, bool SO, bool DF >
struct MultTrait< HybridVector<T,N,true>, LowerMatrix<MT,SO,DF> >
{
typedef typename MultTrait< HybridVector<T,N,true>, MT >::Type Type;
};
template< typename MT, bool SO, bool DF, typename T >
struct MultTrait< LowerMatrix<MT,SO,DF>, DynamicVector<T,false> >
{
typedef typename MultTrait< MT, DynamicVector<T,false> >::Type Type;
};
template< typename T, typename MT, bool SO, bool DF >
struct MultTrait< DynamicVector<T,true>, LowerMatrix<MT,SO,DF> >
{
typedef typename MultTrait< DynamicVector<T,true>, MT >::Type Type;
};
template< typename MT, bool SO, bool DF, typename T >
struct MultTrait< LowerMatrix<MT,SO,DF>, CompressedVector<T,false> >
{
typedef typename MultTrait< MT, CompressedVector<T,false> >::Type Type;
};
template< typename T, typename MT, bool SO, bool DF >
struct MultTrait< CompressedVector<T,true>, LowerMatrix<MT,SO,DF> >
{
typedef typename MultTrait< CompressedVector<T,true>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, size_t M, size_t N, bool SO2 >
struct MultTrait< LowerMatrix<MT,SO1,DF>, StaticMatrix<T,M,N,SO2> >
{
typedef typename MultTrait< MT, StaticMatrix<T,M,N,SO2> >::Type Type;
};
template< typename T, size_t M, size_t N, bool SO1, typename MT, bool SO2, bool DF >
struct MultTrait< StaticMatrix<T,M,N,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename MultTrait< StaticMatrix<T,M,N,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, size_t M, size_t N, bool SO2 >
struct MultTrait< LowerMatrix<MT,SO1,DF>, HybridMatrix<T,M,N,SO2> >
{
typedef typename MultTrait< MT, HybridMatrix<T,M,N,SO2> >::Type Type;
};
template< typename T, size_t M, size_t N, bool SO1, typename MT, bool SO2, bool DF >
struct MultTrait< HybridMatrix<T,M,N,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename MultTrait< HybridMatrix<T,M,N,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, bool SO2 >
struct MultTrait< LowerMatrix<MT,SO1,DF>, DynamicMatrix<T,SO2> >
{
typedef typename MultTrait< MT, DynamicMatrix<T,SO2> >::Type Type;
};
template< typename T, bool SO1, typename MT, bool SO2, bool DF >
struct MultTrait< DynamicMatrix<T,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename MultTrait< DynamicMatrix<T,SO1>, MT >::Type Type;
};
template< typename MT, bool SO1, bool DF, typename T, bool SO2 >
struct MultTrait< LowerMatrix<MT,SO1,DF>, CompressedMatrix<T,SO2> >
{
typedef typename MultTrait< MT, CompressedMatrix<T,SO2> >::Type Type;
};
template< typename T, bool SO1, typename MT, bool SO2, bool DF >
struct MultTrait< CompressedMatrix<T,SO1>, LowerMatrix<MT,SO2,DF> >
{
typedef typename MultTrait< CompressedMatrix<T,SO1>, MT >::Type Type;
};
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2, bool NF >
struct MultTrait< LowerMatrix<MT1,SO1,DF1>, SymmetricMatrix<MT2,SO2,DF2,NF> >
{
typedef typename MultTrait<MT1,MT2>::Type Type;
};
template< typename MT1, bool SO1, bool DF1, bool NF, typename MT2, bool SO2, bool DF2 >
struct MultTrait< SymmetricMatrix<MT1,SO1,DF1,NF>, LowerMatrix<MT2,SO2,DF2> >
{
typedef typename MultTrait<MT1,MT2>::Type Type;
};
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2 >
struct MultTrait< LowerMatrix<MT1,SO1,DF1>, LowerMatrix<MT2,SO2,DF2> >
{
typedef LowerMatrix< typename MultTrait<MT1,MT2>::Type > Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// DIVTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF, typename T >
struct DivTrait< LowerMatrix<MT,SO,DF>, T >
{
typedef LowerMatrix< typename DivTrait<MT,T>::Type > Type;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( T );
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MATHTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT1, bool SO1, bool DF1, typename MT2, bool SO2, bool DF2 >
struct MathTrait< LowerMatrix<MT1,SO1,DF1>, LowerMatrix<MT2,SO2,DF2> >
{
typedef LowerMatrix< typename MathTrait<MT1,MT2>::HighType > HighType;
typedef LowerMatrix< typename MathTrait<MT1,MT2>::LowType > LowType;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// SUBMATRIXTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct SubmatrixTrait< LowerMatrix<MT,SO,DF> >
{
typedef typename SubmatrixTrait<MT>::Type Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// ROWTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct RowTrait< LowerMatrix<MT,SO,DF> >
{
typedef typename RowTrait<MT>::Type Type;
};
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// COLUMNTRAIT SPECIALIZATIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
template< typename MT, bool SO, bool DF >
struct ColumnTrait< LowerMatrix<MT,SO,DF> >
{
typedef typename ColumnTrait<MT>::Type Type;
};
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif
| [
"_@adityaramesh.com"
] | _@adityaramesh.com |
299aa313ccbc79ce6bd7b4bdd01a8cd9f996011c | 2cf7d5dc08c2b5cec15a8427df561262c64a2373 | /cpp_pointers_and_arrays.cpp | c36027421405634daf8e0edbef607a773b463aae | [] | no_license | costaafm/cpp | 794210e40a9995aec5ce2753edd8542b54c6a018 | c616bf4211c900a56124aeb2ae27d5da48c227e9 | refs/heads/master | 2020-05-18T11:52:53.577729 | 2016-02-15T23:32:11 | 2016-02-15T23:32:11 | 32,004,657 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 392 | cpp | #include <iostream>
using namespace std;
int main() {
float a[5];
// Inserting data using pointer notation
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; ++i) {
cin >> *(a+i) ;
}
// Displaying data using pointer notation
cout << "Displaying data: " << endl;
for (int i = 0; i < 5; ++i) {
cout << *(a+i) << endl ;
}
return 0;
} | [
"costaafm@gmail.com"
] | costaafm@gmail.com |
c32f9d1bab86c8206598c3b0e23358ef1b945737 | 669416def364d10c1a3cef35fe8906ebcce6fc65 | /src/asset/asset_types.h | 36b666dede34123965918ef86a9223a456a0138b | [
"MIT"
] | permissive | v3n/altertum | ae18c49886aac01405f0b17cc5f05a2a074a70a1 | 1561405d1dc6ceb19d1a1f57e4fef8b13296d185 | refs/heads/master | 2020-04-06T07:00:44.408133 | 2016-04-09T10:10:02 | 2016-04-09T10:10:02 | 41,336,589 | 6 | 3 | null | 2015-12-10T10:11:48 | 2015-08-25T01:48:12 | C++ | UTF-8 | C++ | false | false | 1,299 | h | /*
* Copyright (c) 2015 Jonathan Howard
* License: https://github.com/v3n/altertum/blob/master/LICENSE
*/
#pragma once
#include <bgfx/bgfx.h>
#include "math/math_types.h"
namespace altertum
{
/**
* Enum class declarations
*/
struct AssetTypes
{ enum {
ASSET_UNKNOWN /** used internally */
, ASSET_AUDIO /** audio **/
, ASSET_MESH /** mesh **/
, ASSET_TEXTURE /** texture **/
, ASSET_SCRIPT /** script **/
, ASSET_REGISTRY /** registry file */
, ASSET_PACKAGE /** packaged assets */
// ...
, SIZE
}; };
/**
* static mesh data, base for model.
*/
struct Mesh
{
// struct SubMesh
// {
// unsigned start;
// unsigned length;
// };
bgfx::Memory * vertices;
bgfx::Memory * indices;
bgfx::VertexDecl ms_decl;
bgfx::VertexBufferHandle vertex_buffer;
bgfx::IndexBufferHandle index_buffer;
uint32_t vertex_stride;
uint32_t indices_offset;
uint32_t vertices_count;
uint32_t indices_count;
// unsigned n_submeshed;
// SubMesh submeshes[ALTERTUM_MAX_SUBMESHES];
};
struct Joint
{
Matrix4 g_pose;
Matrix4 l_pose;
};
struct Texture
{
bgfx::Memory uv;
bgfx::TextureHandle texture;
};
} // namespace altertum
| [
"j@hovverd.com"
] | j@hovverd.com |
e591bcc70b0aa3ccab05785595d7c74357c34113 | a400d9c1c08d99f1cb7a7aeec4f530096902f15e | /frag_set.h | ffd19775edfe9ef6678fd530daa53e221d50e897 | [] | no_license | christang/alignment-algos | 7c147a9109ce6a2a97a095e9c40e27d0f955575b | 39f279223cfb3423d73a645434350f4ab331d205 | refs/heads/master | 2021-01-22T23:20:59.891361 | 2014-06-23T20:41:29 | 2014-06-23T20:44:15 | 21,139,671 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 1,721 | h | #ifndef _FRAGSET
#define _FRAGSET
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include "ssss_shared_defs.h"
#include "sse_frag_set.h"
using namespace std;
//class Ali_Dist;
class Frag_Set {
private:
// DATA
vector<SSE_Frag_Set> Frag_Columns; // holds all fragments!
string query_seq, templ_seq;
int num_sses;
int query_len, templ_len;
bool verbose;
public:
// DATA
// FUNCTIONS
Frag_Set();
~Frag_Set();
// operators
vector<Ali_Frag*> operator-( Frag_Set& );
// general
void clear_all();
void add_column( SSE_Frag_Set );
void set_num_sses();
void activate_terminal_caps();
void initialize_all_zscores();
void seed_all_columns( int );
void count_frag_children();
float activate_next_best_available_frag();
bool an_available_frag_exists();
vector<Ali_Frag*> get_active_frags( int );
vector<Ali_Frag*> get_available_frags( int );
vector<Ali_Frag*> export_all_frags();
bool frags_in_order( int, int, int, int );
bool frags_in_order( Ali_Frag*, Ali_Frag* );
// region-focused
vector<Ali_Frag*> get_active_frags_in_region( int, int, int, int );
vector<Ali_Frag*> get_available_frags_in_region( int, int, int, int );
// access
inline SSE_Frag_Set* get_col( int i ) { return &Frag_Columns[i]; }
int num_frags_in_sse( int );
Ali_Frag* get_frag( Frag_ID );
Ali_Frag* get_frag( int, int );
inline void set_verbose( bool b ) { verbose = b; }
// debugging
// void print_Active_Frags_matrix() const;
// void print_Available_Frags_matrix() const;
void print_all_frags();
void print_all_sses();
void print_all_frag_connections();
void report_statistics();
// void pause();
};
#endif //_FRAGSET
| [
"chris.l.tang@gmail.com"
] | chris.l.tang@gmail.com |
cf42f685679d711edad42e60b7412e5f1bf1fe91 | 225b9a9ce807b669f5da0224b374bbf496d0bc70 | /其他/二进制拆分-分组-分类/ioihomework183.cpp | ef2e01030fd971dbe063305412c3ddb3a2be4fba | [] | no_license | Kewth/OJStudy | 2ed55f9802d430fc65647d8931c028b974935c03 | 153708467133338a19d5537408750b4732d6a976 | refs/heads/master | 2022-08-15T06:18:48.271942 | 2022-07-25T02:18:20 | 2022-07-25T02:18:20 | 172,679,963 | 6 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 24 | cpp | ../../ioihomework183.cpp | [
"Kewth.K.D@outlook.com"
] | Kewth.K.D@outlook.com |
21bc9fc454c39b9c603f8a9381c983a2aac74b2b | 881839ead7febb2fd37b4b1d18be78556c84c95b | /code/Examples/UI/Supervisor/Supervisor.cpp | 1d50c44dd79415ef27dd84967cc5a5de2ce085a8 | [] | no_license | majthehero/glitchFXdev | 9d48ece15ef3c70b7932b5ed126b960d897e7b62 | e6ad32338966f308e13ce0811266d170f649e637 | refs/heads/master | 2021-06-30T09:06:01.409219 | 2020-08-17T13:12:52 | 2020-08-17T13:12:52 | 93,853,401 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 29,648 | cpp | /*******************************************************************/
/* */
/* ADOBE CONFIDENTIAL */
/* _ _ _ _ _ _ _ _ _ _ _ _ _ */
/* */
/* Copyright 2007 Adobe Systems Incorporated */
/* All Rights Reserved. */
/* */
/* NOTICE: All information contained herein is, and remains the */
/* property of Adobe Systems Incorporated and its suppliers, if */
/* any. The intellectual and technical concepts contained */
/* herein are proprietary to Adobe Systems Incorporated and its */
/* suppliers and may be covered by U.S. and Foreign Patents, */
/* patents in process, and are protected by trade secret or */
/* copyright law. Dissemination of this information or */
/* reproduction of this material is strictly forbidden unless */
/* prior written permission is obtained from Adobe Systems */
/* Incorporated. */
/* */
/*******************************************************************/
/*
Supervisor.cpp
Part of the Adobe After Effects SDK.
Copyright 2007 Adobe Systems Incorporated.
All Rights Reserved.
This plug-in demonstrates parameter supervision.
Revision History
Version Change Engineer Date
======= ====== ======== ======
1.0 created bbb 9/1/00
1.1 updated for 16bpc bbb 2/14/01
1.2 added use of START_COLLAPSED_FLAG, bbb 9/1/01
fixed a supervision logic bug or two...
1.3 Fixed usage of initializedB flag bbb 1/1/02
2.0 Bumped version number higher to bbb 2/20/03
reflect a bunch of changes. Adding
lots of comments.
3.0 Replaced param supervision with whizzy bbb 5/7/03
new DynamicStreamSuite calls.
4.0 I am so SMRT! I am so SMRT1 S-M-R-T! bbb 10/4/06
No, wait...S-M-A-R-T!
5.0 Premiere Pro compatibility zal 2/20/08
5.1 Better param supervision logic zal 5/28/09
5.2 Demonstrate renaming choices in popup param zal 6/2/09
5.5 64-bit zal 2/2/10
5.6 Demonstrate HaveInputsChangedOverTimeSpan zal 4/20/11
5.7 Demonstrate changing param values zal 6/22/11
Improved supervision logic, code cleanup
*/
#include "Supervisor.h"
static PF_Err
About (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
PF_AppPersonalTextInfo personal_info;
AEFX_CLR_STRUCT(personal_info);
ERR(suites.AppSuite4()->PF_GetPersonalInfo(&personal_info));
if (!err) {
suites.ANSICallbacksSuite1()->sprintf( out_data->return_msg,
"%s\r%s\r%s, v%d.%d\r\r%s",
STR(StrID_Name),
personal_info.name,
personal_info.serial_str,
MAJOR_VERSION,
MINOR_VERSION,
STR(StrID_Description));
}
return err;
}
static void
GetPresetColorValue(
A_long flavor,
PF_Pixel *scratchP)
{
switch (flavor) {
case FLAVOR_CHOCOLATE:
scratchP->red = 136;
scratchP->green = 83;
scratchP->blue = 51;
break;
case FLAVOR_STRAWBERRY:
scratchP->red = 232;
scratchP->green = 21;
scratchP->blue = 84;
break;
case FLAVOR_SHERBET:
scratchP->red = 255;
scratchP->green = 128;
scratchP->blue = 0;
break;
default:
break;
}
scratchP->alpha = 0;
}
static PF_Err
GlobalSetup (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
PF_Handle globH = NULL;
my_global_dataP globP = NULL;
AEGP_SuiteHandler suites(in_data->pica_basicP);
out_data->my_version = PF_VERSION( MAJOR_VERSION,
MINOR_VERSION,
BUG_VERSION,
STAGE_VERSION,
BUILD_VERSION);
out_data->out_flags = PF_OutFlag_PIX_INDEPENDENT |
PF_OutFlag_SEND_UPDATE_PARAMS_UI |
PF_OutFlag_USE_OUTPUT_EXTENT |
PF_OutFlag_DEEP_COLOR_AWARE |
PF_OutFlag_WIDE_TIME_INPUT;
// This new outflag, added in 5.5, makes After Effects
// honor the initial state of the parameter's (in our case,
// the parameter group's) collapsed flag.
out_data->out_flags2 = PF_OutFlag2_PARAM_GROUP_START_COLLAPSED_FLAG |
PF_OutFlag2_FLOAT_COLOR_AWARE |
PF_OutFlag2_SUPPORTS_SMART_RENDER |
PF_OutFlag2_DOESNT_NEED_EMPTY_PIXELS |
PF_OutFlag2_AUTOMATIC_WIDE_TIME_INPUT;
// This looks more complex than it is. Basically, this
// code allocates a handle, and (if successful) sets a
// sentinel value for later use, and gets an ID for using
// AEGP calls. It then stores those value in in_data->global_data.
globH = suites.HandleSuite1()->host_new_handle(sizeof(my_global_data));
if (globH) {
globP = reinterpret_cast<my_global_dataP>(suites.HandleSuite1()->host_lock_handle(globH));
if (globP) {
globP->initializedB = TRUE;
if (in_data->appl_id != 'PrMr') {
// This is only needed for the AEGP suites, which Premiere Pro doesn't support
ERR(suites.UtilitySuite3()->AEGP_RegisterWithAEGP(NULL, STR(StrID_Name), &globP->my_id));
}
if (!err){
out_data->global_data = globH;
}
}
suites.HandleSuite1()->host_unlock_handle(globH);
} else {
err = PF_Err_INTERNAL_STRUCT_DAMAGED;
}
return err;
}
static PF_Err
SequenceSetdown (
PF_InData *in_data,
PF_OutData *out_data)
{
PF_Err err = PF_Err_NONE;
if (in_data->sequence_data){
AEGP_SuiteHandler suites(in_data->pica_basicP);
suites.HandleSuite1()->host_dispose_handle(in_data->sequence_data);
}
return err;
}
static PF_Err
SequenceSetup (
PF_InData *in_data,
PF_OutData *out_data)
{
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
err = SequenceSetdown(in_data, out_data);
if (!err){
PF_Handle seq_dataH = suites.HandleSuite1()->host_new_handle(sizeof(my_sequence_data));
if (seq_dataH){
my_sequence_dataP seqP = static_cast<my_sequence_dataP>(suites.HandleSuite1()->host_lock_handle(seq_dataH));
if (seqP){
if (in_data->appl_id != 'PrMr')
{
ERR(suites.ParamUtilsSuite3()->PF_GetCurrentState( in_data->effect_ref,
SUPER_SLIDER,
NULL,
NULL,
&seqP->state));
}
seqP->advanced_modeB = FALSE;
out_data->sequence_data = seq_dataH;
suites.HandleSuite1()->host_unlock_handle(seq_dataH);
}
} else { // whoa, we couldn't allocate sequence data; bail!
err = PF_Err_OUT_OF_MEMORY;
}
}
return err;
}
static PF_Err
ParamsSetup(
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output)
{
PF_Err err = PF_Err_NONE;
PF_ParamDef def;
AEFX_CLR_STRUCT(def);
def.flags = PF_ParamFlag_SUPERVISE |
PF_ParamFlag_CANNOT_TIME_VARY |
PF_ParamFlag_CANNOT_INTERP;
def.ui_flags = PF_PUI_STD_CONTROL_ONLY;
// Defaults to "Basic"
PF_ADD_POPUP( STR(StrID_ModeName),
MODE_SIZE,
MODE_BASIC,
STR(StrID_ModeChoices),
SUPER_MODE_DISK_ID);
AEFX_CLR_STRUCT(def);
def.flags = PF_ParamFlag_SUPERVISE |
PF_ParamFlag_CANNOT_INTERP;
PF_ADD_POPUP( STR(StrID_FlavorName),
FLAVOR_SIZE,
FLAVOR_CHOCOLATE,
STR(StrID_FlavorChoices),
SUPER_FLAVOR_DISK_ID);
AEFX_CLR_STRUCT(def);
PF_Pixel temp;
GetPresetColorValue(FLAVOR_CHOCOLATE, &temp);
PF_ADD_COLOR( STR(StrID_ColorName),
temp.red,
temp.green,
temp.blue,
SUPER_COLOR_DISK_ID);
AEFX_CLR_STRUCT(def);
PF_ADD_FIXED( STR(StrID_SliderName),
0,
100,
0,
100,
28,
1,
1,
PF_ParamFlag_EXCLUDE_FROM_HAVE_INPUTS_CHANGED,
SUPER_SLIDER_DISK_ID);
AEFX_CLR_STRUCT(def);
def.flags |= PF_ParamFlag_SUPERVISE |
PF_ParamFlag_CANNOT_TIME_VARY;
def.ui_flags = PF_PUI_STD_CONTROL_ONLY;
PF_ADD_CHECKBOX(STR(StrID_CheckboxName),
STR(StrID_CheckboxCaption),
FALSE,
0,
SUPER_CHECKBOX_DISK_ID);
AEFX_CLR_STRUCT(def);
out_data->num_params = SUPER_NUM_PARAMS;
return err;
}
static PF_Err
PixelFunc8 (
void *refcon,
A_long xL,
A_long yL,
PF_Pixel8 *inP,
PF_Pixel8 *outP)
{
prerender_stuff* stuffP = reinterpret_cast<prerender_stuff*>(refcon);
A_short tempS = 0;
if (stuffP){
tempS = (A_short)(inP->red + stuffP->color.red * (PF_FpShort)PF_MAX_CHAN8 / 2);
if (tempS > PF_MAX_CHAN8){
outP->red = PF_MAX_CHAN8;
} else {
outP->red = tempS;
}
tempS = (A_short)(inP->green + stuffP->color.green * PF_MAX_CHAN8 / 2);
if (tempS > PF_MAX_CHAN8){
outP->green = PF_MAX_CHAN8;
} else {
outP->green = tempS;
}
tempS = (A_short)(inP->blue + stuffP->color.blue * PF_MAX_CHAN8 / 2);
if (tempS > PF_MAX_CHAN8){
outP->blue = PF_MAX_CHAN8;
} else {
outP->blue = tempS;
}
outP->alpha = inP->alpha;
}
return PF_Err_NONE;
}
static PF_Err
PixelFunc16(
void *refcon,
A_long xL,
A_long yL,
PF_Pixel16 *inP,
PF_Pixel16 *outP)
{
prerender_stuff* stuffP = reinterpret_cast<prerender_stuff*>(refcon);
A_long tempL = 0;
if (stuffP){
tempL = (A_long)(inP->red + stuffP->color.red * PF_MAX_CHAN16 / 2);
if (tempL > PF_MAX_CHAN16){
outP->red = PF_MAX_CHAN16;
} else {
outP->red = tempL;
}
tempL = (A_long)(inP->green + stuffP->color.green * PF_MAX_CHAN16 / 2);
if (tempL > PF_MAX_CHAN16){
outP->green = PF_MAX_CHAN16;
} else {
outP->green = tempL;
}
tempL = (A_long)(inP->blue + stuffP->color.blue * PF_MAX_CHAN16 / 2);
if (tempL > PF_MAX_CHAN16){
outP->blue = PF_MAX_CHAN16;
} else {
outP->blue = tempL;
}
outP->alpha = inP->alpha;
}
return PF_Err_NONE;
}
static PF_Err
PixelFuncFloat(
void *refcon,
A_long xL,
A_long yL,
PF_PixelFloat *inP,
PF_PixelFloat *outP)
{
prerender_stuff* stuffP = reinterpret_cast<prerender_stuff*>(refcon);
if (stuffP){
outP->red = ((inP->red + (stuffP->color.red)) / 2);
outP->green = ((inP->green + (stuffP->color.green)) / 2);
outP->blue = ((inP->blue + (stuffP->color.blue)) / 2);
outP->alpha = inP->alpha;
}
return PF_Err_NONE;
}
static PF_Err
MakeParamCopy(
PF_ParamDef *actual[], /* >> */
PF_ParamDef copy[]) /* << */
{
for (A_short iS = 0; iS < SUPER_NUM_PARAMS; ++iS) {
AEFX_CLR_STRUCT(copy[iS]); // clean params are important!
}
copy[SUPER_INPUT] = *actual[SUPER_INPUT];
copy[SUPER_MODE] = *actual[SUPER_MODE];
copy[SUPER_FLAVOR] = *actual[SUPER_FLAVOR];
copy[SUPER_COLOR] = *actual[SUPER_COLOR];
copy[SUPER_SLIDER] = *actual[SUPER_SLIDER];
copy[SUPER_CHECKBOX] = *actual[SUPER_CHECKBOX];
return PF_Err_NONE;
}
static PF_Err
UserChangedParam(
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *outputP,
const PF_UserChangedParamExtra *which_hitP)
{
PF_Err err = PF_Err_NONE;
if (which_hitP->param_index == SUPER_CHECKBOX)
{
// If checkbox is checked, change slider value to 50 and flip checkbox back off
if (params[SUPER_CHECKBOX]->u.bd.value == TRUE) {
params[SUPER_SLIDER]->u.sd.value = INT2FIX(50);
params[SUPER_SLIDER]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
params[SUPER_CHECKBOX]->u.bd.value = FALSE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_CHECKBOX,
params[SUPER_CHECKBOX]));
}
}
return err;
}
static PF_Err
UpdateParameterUI(
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *outputP)
{
PF_Err err = PF_Err_NONE,
err2 = PF_Err_NONE;
my_global_dataP globP = reinterpret_cast<my_global_dataP>(DH(out_data->global_data));
my_sequence_dataP seqP = reinterpret_cast<my_sequence_dataP>(DH(out_data->sequence_data));
AEGP_StreamRefH flavor_streamH = NULL,
color_streamH = NULL,
slider_streamH = NULL,
checkbox_streamH = NULL;
PF_ParamType param_type;
PF_ParamDefUnion param_union;
A_Boolean hide_themB = FALSE;
AEGP_EffectRefH meH = NULL;
AEGP_SuiteHandler suites(in_data->pica_basicP);
// Before we can change the enabled/disabled state of parameters,
// we need to make a copy (remember, parts of those passed into us
// are read-only).
PF_ParamDef param_copy[SUPER_NUM_PARAMS];
ERR(MakeParamCopy(params, param_copy));
// Toggle enable/disabled state of flavor param
if (!err &&
(MODE_BASIC == params[SUPER_MODE]->u.pd.value)) {
param_copy[SUPER_FLAVOR].param_type = PF_Param_POPUP;
param_copy[SUPER_FLAVOR].ui_flags &= ~PF_PUI_DISABLED;
strcpy(param_copy[SUPER_FLAVOR].name, STR(StrID_FlavorName));
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_FLAVOR,
¶m_copy[SUPER_FLAVOR]));
} else if (!err &&
(MODE_ADVANCED == params[SUPER_MODE]->u.pd.value) &&
(!(param_copy[SUPER_FLAVOR].ui_flags & PF_PUI_DISABLED))) {
param_copy[SUPER_FLAVOR].param_type = PF_Param_POPUP;
param_copy[SUPER_FLAVOR].ui_flags |= PF_PUI_DISABLED;
strcpy(param_copy[SUPER_FLAVOR].name, STR(StrID_FlavorNameDisabled));
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_FLAVOR,
¶m_copy[SUPER_FLAVOR]));
}
if (in_data->appl_id != 'PrMr') {
if (params[SUPER_MODE]->u.pd.value == MODE_ADVANCED) {
seqP->advanced_modeB = TRUE;
} else {
seqP->advanced_modeB = FALSE;
hide_themB = TRUE;
}
// Twirl open the slider param
param_copy[SUPER_SLIDER].param_type = PF_Param_FIX_SLIDER;
param_copy[SUPER_SLIDER].flags &= ~PF_ParamFlag_COLLAPSE_TWIRLY;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_SLIDER,
¶m_copy[SUPER_SLIDER]));
// Changing visibility of params in AE is handled through stream suites
ERR(suites.PFInterfaceSuite1()->AEGP_GetNewEffectForEffect(globP->my_id, in_data->effect_ref, &meH));
ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(globP->my_id, meH, SUPER_FLAVOR, &flavor_streamH));
ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(globP->my_id, meH, SUPER_COLOR, &color_streamH));
ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(globP->my_id, meH, SUPER_SLIDER, &slider_streamH));
ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(globP->my_id, meH, SUPER_CHECKBOX, &checkbox_streamH));
// Toggle visibility of parameters
ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(color_streamH, AEGP_DynStreamFlag_HIDDEN, FALSE, hide_themB));
ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(slider_streamH, AEGP_DynStreamFlag_HIDDEN, FALSE, hide_themB));
ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(checkbox_streamH, AEGP_DynStreamFlag_HIDDEN, FALSE, hide_themB));
// Change popup menu items
ERR(suites.EffectSuite3()->AEGP_GetEffectParamUnionByIndex(globP->my_id, meH, SUPER_FLAVOR_DISK_ID, ¶m_type, ¶m_union));
if (param_type == PF_Param_POPUP)
{
strcpy((char*)param_union.pd.u.namesptr, GetStringPtr(StrID_FlavorChoicesChanged));
}
if (meH){
ERR2(suites.EffectSuite2()->AEGP_DisposeEffect(meH));
}
if (flavor_streamH){
ERR2(suites.StreamSuite2()->AEGP_DisposeStream(flavor_streamH));
}
if (color_streamH){
ERR2(suites.StreamSuite2()->AEGP_DisposeStream(color_streamH));
}
if (slider_streamH){
ERR2(suites.StreamSuite2()->AEGP_DisposeStream(slider_streamH));
}
if (checkbox_streamH){
ERR2(suites.StreamSuite2()->AEGP_DisposeStream(checkbox_streamH));
}
if (!err){
out_data->out_flags |= PF_OutFlag_FORCE_RERENDER;
}
// Demonstrate using PF_AreStatesIdentical to check whether a parameter has changed
PF_State new_state;
A_Boolean something_changedB = FALSE;
ERR(suites.ParamUtilsSuite3()->PF_GetCurrentState( in_data->effect_ref,
SUPER_SLIDER,
NULL,
NULL,
&new_state));
ERR(suites.ParamUtilsSuite3()->PF_AreStatesIdentical( in_data->effect_ref,
&seqP->state,
&new_state,
&something_changedB));
if (something_changedB || !globP->initializedB) {
// If something changed (or it's the first time we're being called),
// get the new state and store it in our sequence data
ERR(suites.ParamUtilsSuite3()->PF_GetCurrentState( in_data->effect_ref,
SUPER_SLIDER,
NULL,
NULL,
&seqP->state));
}
} else { // Premiere Pro doesn't support the stream suites, but uses a UI flag instead
// If our global data is present...
if (!err && globP) {
// Test all parameters except layers for changes
// If the mode is currently Basic, hide the advanced-only params
if (!err && (MODE_BASIC == params[SUPER_MODE]->u.pd.value)) {
if (!err) {
param_copy[SUPER_COLOR].ui_flags |= PF_PUI_INVISIBLE;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_COLOR,
¶m_copy[SUPER_COLOR]));
}
if (!err) {
param_copy[SUPER_SLIDER].ui_flags |= PF_PUI_INVISIBLE;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_SLIDER,
¶m_copy[SUPER_SLIDER]));
}
if (!err) {
param_copy[SUPER_CHECKBOX].ui_flags |= PF_PUI_INVISIBLE;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_CHECKBOX,
¶m_copy[SUPER_CHECKBOX]));
}
} else {
// Since we're in advanced mode, show the advanced-only params
if (!err) {
param_copy[SUPER_COLOR].ui_flags &= ~PF_PUI_INVISIBLE;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_COLOR,
¶m_copy[SUPER_COLOR]));
}
if (!err && (param_copy[SUPER_SLIDER].ui_flags & PF_PUI_INVISIBLE)) {
// Note: As of Premiere Pro CS5.5, this is currently not honored
param_copy[SUPER_SLIDER].flags &= ~PF_ParamFlag_COLLAPSE_TWIRLY;
param_copy[SUPER_SLIDER].ui_flags &= ~PF_PUI_INVISIBLE;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_SLIDER,
¶m_copy[SUPER_SLIDER]));
}
if (!err && (param_copy[SUPER_CHECKBOX].ui_flags & PF_PUI_INVISIBLE)) {
param_copy[SUPER_CHECKBOX].ui_flags &= ~PF_PUI_INVISIBLE;
ERR(suites.ParamUtilsSuite3()->PF_UpdateParamUI(in_data->effect_ref,
SUPER_CHECKBOX,
¶m_copy[SUPER_CHECKBOX]));
}
if (err) { // <--- Note: not !err, err!
strcpy(out_data->return_msg, STR(StrID_GeneralError));
out_data->out_flags = PF_OutFlag_DISPLAY_ERROR_MESSAGE;
}
else {
globP->initializedB = TRUE; // set our cheesy first time indicator
}
}
}
if (!err) {
globP->initializedB = TRUE;
}
out_data->out_flags |= PF_OutFlag_REFRESH_UI |
PF_OutFlag_FORCE_RERENDER;
}
return err;
}
static PF_Err
GlobalSetdown(
PF_InData *in_data)
{
AEGP_SuiteHandler suites(in_data->pica_basicP);
if (in_data->global_data) {
suites.HandleSuite1()->host_dispose_handle(in_data->global_data);
}
return PF_Err_NONE;
}
static PF_Err
Render16(
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output,
PF_Pixel8 *scratchP)
{
AEGP_SuiteHandler suites(in_data->pica_basicP);
register PF_Pixel16 scratch16;
scratch16.red = CONVERT8TO16(scratchP->red);
scratch16.green = CONVERT8TO16(scratchP->green);
scratch16.blue = CONVERT8TO16(scratchP->blue);
scratch16.alpha = CONVERT8TO16(scratchP->alpha);
return suites.Iterate16Suite1()->iterate( in_data,
0,
(output->extent_hint.bottom - output->extent_hint.top),
¶ms[SUPER_INPUT]->u.ld,
&output->extent_hint,
(void*)&scratch16,
PixelFunc16,
output);
}
static PF_Err
Render8(
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output,
PF_Pixel8 *scratchP)
{
AEGP_SuiteHandler suites(in_data->pica_basicP);
prerender_stuff stuff;
stuff.color.red = (PF_FpShort)scratchP->red / PF_MAX_CHAN8;
stuff.color.green = (PF_FpShort)scratchP->green / PF_MAX_CHAN8;
stuff.color.blue = (PF_FpShort)scratchP->blue / PF_MAX_CHAN8;
stuff.color.alpha = (PF_FpShort)scratchP->alpha / PF_MAX_CHAN8;
return suites.Iterate8Suite1()->iterate(in_data,
0,
(output->extent_hint.bottom - output->extent_hint.top),
¶ms[SUPER_INPUT]->u.ld,
&output->extent_hint,
(void*)&stuff,
PixelFunc8,
output);
}
static PF_Err
Render( PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output)
{
PF_Err err = PF_Err_NONE;
register PF_Pixel scratch8;
// If we're in Basic mode, use a preset.
// Otherwise, use the value of our color param.
if (MODE_BASIC == params[SUPER_MODE]->u.pd.value) {
GetPresetColorValue(params[SUPER_FLAVOR]->u.pd.value, &scratch8);
} else {
scratch8 = params[SUPER_COLOR]->u.cd.value;
}
PF_Boolean deepB = PF_WORLD_IS_DEEP(output);
if (deepB){
ERR(Render16(in_data,
out_data,
params,
output,
&scratch8));
} else {
ERR(Render8(in_data,
out_data,
params,
output,
&scratch8));
}
return err;
}
static PF_Err
PreRender(
PF_InData *in_data,
PF_OutData *out_data,
PF_PreRenderExtra *extraP)
{
PF_Err err = PF_Err_NONE;
PF_RenderRequest req = extraP->input->output_request;
PF_CheckoutResult in_result;
AEGP_SuiteHandler suites(in_data->pica_basicP);
PF_Handle infoH = suites.HandleSuite1()->host_new_handle(sizeof(prerender_stuff));
prerender_stuff *stuffP = NULL;
if (infoH){
stuffP = reinterpret_cast<prerender_stuff*>(suites.HandleSuite1()->host_lock_handle(infoH));
if (stuffP){
extraP->output->pre_render_data = infoH;
/*
Let's investigate our input parameters, and save ourselves
a few clues for rendering later. Because pre-render gets
called A LOT, it's best to put checkouts you'll always need
in SmartRender(). Because smart pre-computing of what you'll
actually NEED can save time, it's best to check conditionals
here in pre-render.
*/
AEFX_CLR_STRUCT(in_result);
if (!err){
req.preserve_rgb_of_zero_alpha = FALSE;
ERR(extraP->cb->checkout_layer( in_data->effect_ref,
SUPER_INPUT,
SUPER_INPUT,
&req,
in_data->current_time,
in_data->time_step,
in_data->time_scale,
&in_result));
if (!err){
UnionLRect(&in_result.result_rect, &extraP->output->result_rect);
UnionLRect(&in_result.max_result_rect, &extraP->output->max_result_rect);
}
}
suites.HandleSuite1()->host_unlock_handle(infoH);
}
}
return err;
}
static PF_Err
SmartRender(
PF_InData *in_data,
PF_OutData *out_data,
PF_SmartRenderExtra *extraP)
{
PF_Err err = PF_Err_NONE,
err2 = PF_Err_NONE;
PF_EffectWorld *inputP = NULL,
*outputP = NULL;
PF_PixelFormat format = PF_PixelFormat_INVALID;
PF_WorldSuite2 *wsP = NULL;
my_sequence_dataP seqP = reinterpret_cast<my_sequence_dataP>(DH(in_data->sequence_data));
AEGP_SuiteHandler suites(in_data->pica_basicP);
// Why the old way? Because AEGP_SuiteHandler has a collision with
// AEGPWorldSuite2 and PF_WorldSuite2. That, and I'm too lazy
// don't want to fiddle with a utility class shared by N effects,
// where N approaches "a laughable amount of testing change for
// questionable benefit".
ERR(AEFX_AcquireSuite( in_data,
out_data,
kPFWorldSuite,
kPFWorldSuiteVersion2,
STR(StrID_Err_LoadSuite),
(void**)&wsP));
if (!err && wsP && seqP){
prerender_stuff *stuffP = reinterpret_cast<prerender_stuff*>(suites.HandleSuite1()->host_lock_handle(reinterpret_cast<PF_Handle>(extraP->input->pre_render_data)));
if (stuffP){
// checkout input & output buffers.
ERR((extraP->cb->checkout_layer_pixels( in_data->effect_ref, SUPER_INPUT, &inputP)));
ERR(extraP->cb->checkout_output(in_data->effect_ref, &outputP));
// determine requested output depth
ERR(wsP->PF_GetPixelFormat(outputP, &format));
if (seqP->advanced_modeB){
PF_ParamDef color_param;
AEFX_CLR_STRUCT(color_param);
ERR(PF_CHECKOUT_PARAM( in_data,
SUPER_COLOR,
in_data->current_time,
in_data->time_step,
in_data->time_scale,
&color_param));
ERR(suites.ColorParamSuite1()->PF_GetFloatingPointColorFromColorDef(in_data->effect_ref, &color_param, &stuffP->color));
ERR2(PF_CHECKIN_PARAM(in_data, &color_param));
} else {
// Basic mode
PF_ParamDef flavor_param;
PF_Pixel8 lo_rent_color;
AEFX_CLR_STRUCT(lo_rent_color);
AEFX_CLR_STRUCT(flavor_param);
ERR(PF_CHECKOUT_PARAM( in_data,
SUPER_FLAVOR,
in_data->current_time,
in_data->time_step,
in_data->time_scale,
&flavor_param));
if (!err){
GetPresetColorValue(flavor_param.u.pd.value, &lo_rent_color);
// Rounding slop? Yes! But hey, whaddayawant, they're 0-255 presets...
stuffP->color.red = (PF_FpShort)lo_rent_color.red / PF_MAX_CHAN8;
stuffP->color.green = (PF_FpShort)lo_rent_color.green / PF_MAX_CHAN8;
stuffP->color.blue = (PF_FpShort)lo_rent_color.blue / PF_MAX_CHAN8;
stuffP->color.alpha = (PF_FpShort)lo_rent_color.alpha / PF_MAX_CHAN8;
}
ERR2(PF_CHECKIN_PARAM(in_data, &flavor_param));
}
switch (format) {
case PF_PixelFormat_ARGB128:
ERR(suites.IterateFloatSuite1()->iterate( in_data,
0,
(outputP->extent_hint.bottom - outputP->extent_hint.top),
inputP,
&outputP->extent_hint,
(void*)stuffP,
PixelFuncFloat,
outputP));
break;
case PF_PixelFormat_ARGB64:
ERR(suites.Iterate16Suite1()->iterate( in_data,
0,
(outputP->extent_hint.bottom - outputP->extent_hint.top),
inputP,
&outputP->extent_hint,
(void*)stuffP,
PixelFunc16,
outputP));
break;
case PF_PixelFormat_ARGB32:
ERR(suites.Iterate8Suite1()->iterate( in_data,
0,
(outputP->extent_hint.bottom - outputP->extent_hint.top),
inputP,
&outputP->extent_hint,
(void*)stuffP,
PixelFunc8,
outputP));
break;
default:
err = PF_Err_INTERNAL_STRUCT_DAMAGED;
break;
}
ERR2(extraP->cb->checkin_layer_pixels(in_data->effect_ref, SUPER_INPUT));
}
suites.HandleSuite1()->host_unlock_handle(reinterpret_cast<PF_Handle>(extraP->input->pre_render_data));
}
ERR2(AEFX_ReleaseSuite( in_data,
out_data,
kPFWorldSuite,
kPFWorldSuiteVersion2,
STR(StrID_Err_FreeSuite)));
return err;
}
DllExport PF_Err
EntryPointFunc(
PF_Cmd cmd,
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output,
void *extra )
{
PF_Err err = PF_Err_NONE;
try {
switch (cmd) {
case PF_Cmd_ABOUT:
err = About(in_data,
out_data,
params,
output);
break;
case PF_Cmd_GLOBAL_SETUP:
err = GlobalSetup( in_data,
out_data,
params,
output);
break;
case PF_Cmd_GLOBAL_SETDOWN:
err = GlobalSetdown(in_data);
break;
case PF_Cmd_PARAMS_SETUP:
err = ParamsSetup( in_data,
out_data,
params,
output);
break;
case PF_Cmd_SEQUENCE_SETUP:
err = SequenceSetup(in_data,out_data);
break;
case PF_Cmd_SEQUENCE_SETDOWN:
err = SequenceSetdown(in_data,out_data);
break;
case PF_Cmd_SEQUENCE_RESETUP:
err = SequenceSetup(in_data,out_data);
break;
case PF_Cmd_RENDER:
err = Render( in_data,
out_data,
params,
output);
break;
case PF_Cmd_SMART_RENDER:
err = SmartRender( in_data,
out_data,
reinterpret_cast<PF_SmartRenderExtra*>(extra));
break;
case PF_Cmd_SMART_PRE_RENDER:
err = PreRender( in_data,
out_data,
reinterpret_cast<PF_PreRenderExtra*>(extra));
break;
case PF_Cmd_USER_CHANGED_PARAM:
err = UserChangedParam( in_data,
out_data,
params,
output,
reinterpret_cast<const PF_UserChangedParamExtra *>(extra));
break;
// Handling this selector will ensure that the UI will be properly initialized,
// even before the user starts changing parameters to trigger PF_Cmd_USER_CHANGED_PARAM
case PF_Cmd_UPDATE_PARAMS_UI:
err = UpdateParameterUI( in_data,
out_data,
params,
output);
default:
break;
}
}
catch(PF_Err &thrown_err){
err = PF_Err_INTERNAL_STRUCT_DAMAGED;
}
return err;
}
| [
"maj.smerkol@gmail.com"
] | maj.smerkol@gmail.com |
ab7f35060536ecf0fef2d9290980739a3773ea56 | 4d9f53d2e98983bf30392f0abc9c4e88fed645f3 | /CS470.skel/moc_Threshold.cpp | 3b2f8dec4912892469c3f885e311a14843fb75dd | [] | no_license | shirongzheng/CSC470-Image-Processing | ad9512469604f350f07c4207a50e4f4ee3fa46fa | dabe548ffb39250f117c0928b8cea6dcd24b9d4f | refs/heads/master | 2020-04-14T00:49:17.072850 | 2019-04-24T19:08:39 | 2019-04-24T19:08:39 | 163,543,287 | 0 | 2 | null | null | null | null | UTF-8 | C++ | false | false | 3,384 | cpp | /****************************************************************************
** Meta object code from reading C++ file 'Threshold.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.11.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "Threshold.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'Threshold.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.11.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_Threshold_t {
QByteArrayData data[3];
char stringdata0[21];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_Threshold_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_Threshold_t qt_meta_stringdata_Threshold = {
{
QT_MOC_LITERAL(0, 0, 9), // "Threshold"
QT_MOC_LITERAL(1, 10, 9), // "changeThr"
QT_MOC_LITERAL(2, 20, 0) // ""
},
"Threshold\0changeThr\0"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_Threshold[] = {
// content:
7, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 1, 19, 2, 0x09 /* Protected */,
// slots: parameters
QMetaType::Void, QMetaType::Int, 2,
0 // eod
};
void Threshold::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Threshold *_t = static_cast<Threshold *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->changeThr((*reinterpret_cast< int(*)>(_a[1]))); break;
default: ;
}
}
}
QT_INIT_METAOBJECT const QMetaObject Threshold::staticMetaObject = {
{ &ImageFilter::staticMetaObject, qt_meta_stringdata_Threshold.data,
qt_meta_data_Threshold, qt_static_metacall, nullptr, nullptr}
};
const QMetaObject *Threshold::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *Threshold::qt_metacast(const char *_clname)
{
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_Threshold.stringdata0))
return static_cast<void*>(this);
return ImageFilter::qt_metacast(_clname);
}
int Threshold::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = ImageFilter::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
QT_WARNING_POP
QT_END_MOC_NAMESPACE
| [
"shirongzheng1027@gmail.com"
] | shirongzheng1027@gmail.com |
5dbdb2e96a4b03763e927ad528132ed5429334a8 | cd175f088c679f586d50e49d1b1a50dc0bfca810 | /carro/main.cpp | ab4f882d6d231b75d2fea2d9baa2e6ee5de8cb5d | [] | no_license | mxdsxn/tec-prog | fb2bf03eafc4bf0230cf84f09895e75fc26d4eeb | 2a8f3a1cd29ecc86bf932e965ca82c96597f3b03 | refs/heads/main | 2023-04-11T12:10:59.906969 | 2021-04-19T03:07:37 | 2021-04-19T03:07:37 | 347,669,530 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 185 | cpp | #include "./carro.hpp"
int main()
{
Carro *uno = new Carro(14.5, 50);
uno->abastecer(40);
uno->andar(14.5);
uno->abastecer(301);
uno->andar(145);
uno->andar(1999);
return 1;
} | [
"madson.santana@dextra-sw.com"
] | madson.santana@dextra-sw.com |
611bb045f9e09b52362cd0bab5727a85e5f1fd3a | 4ad5fe75cbf08fae361a9171b88d6fa2ba06c8cc | /UTK/include/main.h | 686d7ed1d1173d50e7c0b1f8d3eb6a17cd35c1c1 | [] | no_license | aleshkashell/UTK | 7fa7ddc2555fbd9e8f03bd0e409aa4b7c6c16aa7 | d43106e22a9ce367e93188e9ecdcbd64b8612b65 | refs/heads/master | 2021-01-22T18:08:21.371549 | 2018-11-16T07:56:13 | 2018-11-16T07:56:13 | 100,747,371 | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 156 | h | #ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
#include <wx/wx.h>
class myApp : public wxApp
{
virtual bool OnInit();
};
#endif // MAIN_H_INCLUDED
| [
"aleshkashell@gmail.com"
] | aleshkashell@gmail.com |
ffec33cf2a5821cd61d0ef708d736b3b6808ed67 | ab4156ca699182a749105ece73d26ecd66f4ff1d | /performance/threads_spsc_ring_buffer.cpp | 51a7a7261a854637988ea0c3c5498081c9c9dead | [
"MIT"
] | permissive | firebirdtools/CppCommon | 4c6057224f46c798960bf7d6751e5fff63afca58 | ad96c6739da0cb2c5b7144b2ff5e66249c9eb462 | refs/heads/master | 2020-04-13T19:56:52.219898 | 2018-12-21T19:51:31 | 2018-12-21T19:51:31 | null | 0 | 0 | null | null | null | null | UTF-8 | C++ | false | false | 2,747 | cpp | //
// Created by Ivan Shynkarenka on 16.01.2016
//
#include "benchmark/cppbenchmark.h"
#include "threads/spsc_ring_buffer.h"
#include <functional>
#include <thread>
using namespace CppCommon;
const uint64_t bytes_to_produce = 100000000;
const int item_size_from = 4;
const int item_size_to = 4096;
const auto settings = CppBenchmark::Settings().ParamRange(item_size_from, item_size_to, [](int from, int to, int& result) { int r = result; result *= 2; return r; });
template<uint64_t N>
void produce_consume(CppBenchmark::Context& context, const std::function<void()>& wait_strategy)
{
const int item_size = context.x();
const uint64_t items_to_produce = bytes_to_produce / item_size;
uint64_t crc = 0;
// Create single producer / single consumer wait-free ring buffer
SPSCRingBuffer buffer(N);
// Start consumer thread
auto consumer = std::thread([&buffer, &wait_strategy, item_size, items_to_produce, &crc]()
{
// Use big items buffer to enable items batching
uint8_t* items = new uint8_t[N];
for (uint64_t i = 0; i < items_to_produce;)
{
// Dequeue using the given waiting strategy
size_t size;
while (!buffer.Dequeue(items, size = N))
wait_strategy();
// Emulate consuming
for (uint64_t j = 0; j < size; ++j)
crc += items[j];
// Increase the items counter
i += size / item_size;
}
// Delete items buffer
delete[] items;
});
// Start producer thread
auto producer = std::thread([&buffer, &wait_strategy, item_size, items_to_produce, &consumer]()
{
uint8_t item[item_size_to];
for (uint64_t i = 0; i < items_to_produce; ++i)
{
// Emulate producing
for (int j = 0; j < item_size; ++j)
item[j] = (uint8_t)j;
// Enqueue using the given waiting strategy
while (!buffer.Enqueue(item, item_size))
wait_strategy();
}
// Wait for the consumer thread
consumer.join();
});
// Wait for the producer thread
producer.join();
// Update benchmark metrics
context.metrics().AddOperations(items_to_produce - 1);
context.metrics().AddItems(items_to_produce);
context.metrics().AddBytes(items_to_produce * item_size);
context.metrics().SetCustom("SPSCRingBuffer.capacity", N);
context.metrics().SetCustom("CRC", crc);
}
BENCHMARK("SPSCRingBuffer<SpinWait>", settings)
{
produce_consume<1048576>(context, []{});
}
BENCHMARK("SPSCRingBuffer<YieldWait>", settings)
{
produce_consume<1048576>(context, []{ std::this_thread::yield(); });
}
BENCHMARK_MAIN()
| [
"chronoxor@gmail.com"
] | chronoxor@gmail.com |
56161c4a84d56f5a34f02e5d647cdd92c17c7d14 | 02670ff229133a84cf4820c9e8cd057c86bd174d | /LinkedList.cpp | 0d327a41bb1141552ad4b0a560fb30a7d1cc6d8f | [] | no_license | travisvalenti/linkedlist | ba14461cb22d8aabc67de6f86e3fc4bc49314a26 | 5056b17bf4f3cc45c15e35d9163dcd669bf23b11 | refs/heads/master | 2020-03-28T17:28:37.145590 | 2018-09-14T13:25:26 | 2018-09-14T13:25:26 | 148,793,349 | 0 | 0 | null | 2018-09-14T13:35:46 | 2018-09-14T13:35:46 | null | UTF-8 | C++ | false | false | 3,931 | cpp | //Course: SENG1120
//Coded by: Tom Williams
//Student Number: 3282012
#include <string>
#include <iostream>
#include "LinkedList.h"
// Constructors
LinkedList::LinkedList()
{
Node *head = nullptr;
Node *tail = nullptr;
ncount = 0;
}
// Empty Destructor
LinkedList::~LinkedList(){}
// Getters
Node* LinkedList::getHead()
{
return head;
}
Node* LinkedList::getTail()
{
return tail;
}
// Adders
void LinkedList::addFirst(Node* firstNode)
{
head = firstNode;
tail = firstNode;
}
void LinkedList::addToHead(Student student)
{
Node* newNode = (Node*) malloc(sizeof(Node));
*newNode = Node(student);
if(head == nullptr)
{
//if the head is nullptr, the list must be empty. So set the first Node
addFirst(newNode);
} else {
head->setPrev(newNode);
newNode->setNext(head);
head = newNode;
}
ncount += 1;
}
void LinkedList::addToTail(Student student)
{
Node* newNode = (Node*) malloc(sizeof(Node));
*newNode = Node(student);
if(tail == nullptr)
{
//if the tail is nullptr, the list must be empty. So set the first Node
addFirst(newNode);
} else {
newNode->setPrev(tail);
tail->setNext(newNode);
tail = newNode;
}
ncount += 1;
}
LinkedList* CloneList(LinkedList* CopyList, Node* curr, Student data)
{
if(CopyList == nullptr)
{
}
//{
// copy = new LinkedList();
//}
//if(curr != nullptr)
//{
// data.set_name(curr->getStudent()->get_name());
// data.set_score(curr->getStudent()->get_score());
// copy->addToTail(&data);
// curr = curr->getNext();
// Clone(copy, curr, data);
//}
return CopyList;
}
void LinkedList::concatenate(LinkedList second)
{
//using the standard style of linked list concatenation
this->tail->setNext(second.getHead());
second.getHead()->setPrev(this->tail);
}
// Removers
void LinkedList::deleteNode(Node *newNode)
{
Node* curr = newNode;
if(curr == head)
{
head = curr->getNext();
if(curr == tail)
{
tail = nullptr;
}
else
{
curr->getNext()->setPrev(nullptr);
}
}
else if(curr == tail)
{
tail = curr->getPrev();
curr->getPrev()->setNext(nullptr);
}
curr->~Node();
}
void LinkedList::remove(std::string Name)
{
Node* curr = findName(Name);
if(curr != nullptr)
{
deleteNode(curr);
}
}
void LinkedList::empty()
{
if(head != nullptr)
{
deleteNode(head);
empty();
}
}
// Sorters
Node* LinkedList::findName(std::string Name)
{
Node* curr = head;
while(curr->getStudent()->get_name() != Name)
{
curr = curr->getNext();
if(curr->getNext() == nullptr &&
curr->getStudent()->get_name() != Name)
{
return nullptr;
}
}
return curr;
}
void LinkedList::sortName()
{
}
void LinkedList::order()
{
this->sortName();
}
// Misc.
double LinkedList::sumList(Node* curr)
{
if ( curr != nullptr )
return curr->getStudent()->get_score() + sumList(curr->getNext());
else
return 0;
}
double LinkedList::calcAverage()
{
return sumList(head)/ncount;
}
int LinkedList::count(std::string searchName)
{
Node* curr = head;
int num = 0;
while(curr->getNext() != nullptr)
{
if(curr->getStudent()->get_name() == searchName)
{
num += 1;
}
}
return num;
}
// Overloaders
LinkedList& LinkedList::operator+=(LinkedList& rhs)
{
this->concatenate(rhs);
}
std::ostream& operator<<(std::ostream& os, LinkedList& dl)
{
Node* curr = dl.getHead();
while(curr != nullptr)
{
os << curr << " ";
curr = curr->getNext();
}
return os;
}
| [
"aeduscreative@gmail.com"
] | aeduscreative@gmail.com |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.